Skip to content

Commit 02170b8

Browse files
authored
Merge pull request #729 from martinmikula/master
Fixed installation of defaults libraries after first run
2 parents dcb987f + 00f2cf4 commit 02170b8

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

io.sloeber.core/src/io/sloeber/core/api/Defaults.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Defaults {
1212
public static final String PLATFORM_NAME = "Arduino AVR Boards";
1313
public static final String[] INSTALLED_LIBRARIES = new String[] { "Ethernet", "Firmata", "GSM", "Keyboard",
1414
"LiquidCrystal", "Mouse", "SD", "Servo", "Stepper", "TFT", "WiFi", "CapacitiveSensor" };
15-
private static final String DEFAULT = "Default";
15+
public static final String DEFAULT = "Default";
1616

1717
/**
1818
* Arduino has the default libraries in the user home directory in subfolder

io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public LibraryTree() {
142142
.append(library.getArchitectures().toString()).append("\n\n") //$NON-NLS-1$
143143
.append(library.getSentence());
144144
lib = new Library(category, library.getName(), libraryIndex.getName(), builder.toString());
145-
category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib); //$NON-NLS-1$ //$NON-NLS-2$
145+
category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib); //$NON-NLS-1$//$NON-NLS-2$
146146
}
147147
lib.versions.add(new VersionNumber(library.getVersion()));
148148
if (library.isInstalled()) {

io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.util.Set;
1111
import java.util.regex.Pattern;
1212

13+
import io.sloeber.core.api.Defaults;
14+
1315
public class LibraryIndex {
1416
private String indexName;
1517
private List<Library> libraries;
@@ -104,7 +106,7 @@ public Collection<Library> getLibraries(String category) {
104106
public void setJsonFile(File packageFile) {
105107
String fileName = packageFile.getName().toLowerCase();
106108
if (fileName.matches("(?i)library_index.json")) { //$NON-NLS-1$
107-
this.indexName = "Default"; //$NON-NLS-1$
109+
this.indexName = Defaults.DEFAULT;
108110
} else {
109111
this.indexName = fileName.replaceAll("(?i)" + Pattern.quote("library_"), "") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
110112
.replaceAll("(?i)" + Pattern.quote("_index.json"), ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

io.sloeber.core/src/io/sloeber/core/managers/Manager.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static void startup_Pluging(IProgressMonitor monitor) {
9090
loadJsons(ConfigurationPreferences.getUpdateJasonFilesFlag());
9191
List<Board> allBoards = getInstalledBoards();
9292
if (allBoards.isEmpty()) { // If boards are installed do nothing
93-
// InstallDefaultLibraries(monitor);
93+
InstallDefaultLibraries(monitor);
9494
MyMultiStatus mstatus = new MyMultiStatus("Failed to configer Sloeber"); //$NON-NLS-1$
9595

9696
// Downnload sample programs
@@ -123,14 +123,18 @@ public static void startup_Pluging(IProgressMonitor monitor) {
123123

124124
}
125125

126-
/*
127-
* private static void InstallDefaultLibraries(IProgressMonitor monitor) {
128-
* LibraryIndex libindex = getLibraryIndex();
129-
*
130-
* for (String library : Defaults.INSTALLED_LIBRARIES) { Library toInstalLib
131-
* = libindex.getLatestLibrary(library); if (toInstalLib != null) {
132-
* toInstalLib.install(monitor); } } }
133-
*/
126+
private static void InstallDefaultLibraries(IProgressMonitor monitor) {
127+
LibraryIndex libindex = getLibraryIndex(Defaults.DEFAULT);
128+
if (libindex == null)
129+
return;
130+
131+
for (String library : Defaults.INSTALLED_LIBRARIES) {
132+
Library toInstalLib = libindex.getLatestLibrary(library);
133+
if (toInstalLib != null) {
134+
toInstalLib.install(monitor);
135+
}
136+
}
137+
}
134138

135139
/**
136140
* Given a platform description in a json file download and install all
@@ -230,9 +234,9 @@ static private void loadJson(String url, boolean forceDownload) {
230234
}
231235
}
232236
if (jsonFile.exists()) {
233-
if (jsonFile.getName().startsWith("package_")) { //$NON-NLS-1$
237+
if (jsonFile.getName().toLowerCase().startsWith("package_")) { //$NON-NLS-1$
234238
loadPackage(jsonFile);
235-
} else if (jsonFile.getName().startsWith("library_")) { //$NON-NLS-1$
239+
} else if (jsonFile.getName().toLowerCase().startsWith("library_")) { //$NON-NLS-1$
236240
loadLibrary(jsonFile);
237241
}
238242
}
@@ -255,7 +259,6 @@ static private void loadLibrary(File jsonFile) {
255259
try (Reader reader = new FileReader(jsonFile)) {
256260
LibraryIndex index = new Gson().fromJson(reader, LibraryIndex.class);
257261
index.resolve();
258-
// index.setOwners(null);
259262
index.setJsonFile(jsonFile);
260263
libraryIndices.add(index);
261264
} catch (Exception e) {
@@ -278,6 +281,15 @@ static public List<LibraryIndex> getLibraryIndices() {
278281
}
279282
return libraryIndices;
280283
}
284+
285+
static public LibraryIndex getLibraryIndex(String name) {
286+
for (LibraryIndex index : getLibraryIndices()) {
287+
if (index.getName().equals(name)) {
288+
return index;
289+
}
290+
}
291+
return null;
292+
}
281293

282294
static public Board getBoard(String boardName, String platformName, String packageName) {
283295
for (PackageIndex index : getPackageIndices()) {
@@ -772,7 +784,7 @@ public static int compareVersions(String version1, String version2) {
772784
if (vi1 > vi2) {
773785
return 1;
774786
}
775-
} catch (NumberFormatException e) {
787+
} catch (@SuppressWarnings("unused") NumberFormatException e) {
776788
// not numbers, do string compares
777789
int c = v1[i].compareTo(v2[i]);
778790
if (c < 0) {

0 commit comments

Comments
 (0)