Skip to content

Commit 5343165

Browse files
committed
Installing default libraries after first installation.
1 parent 264a1f7 commit 5343165

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
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/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")) {
107-
this.indexName = "Default";
109+
this.indexName = Defaults.DEFAULT;
108110
} else {
109111
this.indexName = fileName.replaceAll("(?i)"+Pattern.quote("library_"), "").replaceAll("(?i)"+Pattern.quote("_index.json"), "");
110112
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
import java.io.FileReader;
2020
import java.io.IOException;
2121
import java.io.InputStream;
22-
import java.io.InputStreamReader;
2322
import java.io.Reader;
2423
import java.net.HttpURLConnection;
2524
import java.net.MalformedURLException;
2625
import java.net.URL;
27-
import java.nio.charset.Charset;
2826
import java.nio.file.Files;
2927
import java.nio.file.Path;
3028
import java.nio.file.Paths;
@@ -36,8 +34,6 @@
3634
import java.util.Map;
3735
import java.util.Set;
3836

39-
import javax.net.ssl.HttpsURLConnection;
40-
4137
import org.apache.commons.compress.archivers.ArchiveEntry;
4238
import org.apache.commons.compress.archivers.ArchiveInputStream;
4339
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -93,7 +89,7 @@ public static void startup_Pluging(IProgressMonitor monitor) {
9389
loadJsons(ConfigurationPreferences.getUpdateJasonFilesFlag());
9490
List<Board> allBoards = getInstalledBoards();
9591
if (allBoards.isEmpty()) { // If boards are installed do nothing
96-
// InstallDefaultLibraries(monitor);
92+
InstallDefaultLibraries(monitor);
9793
MyMultiStatus mstatus = new MyMultiStatus("Failed to configer Sloeber"); //$NON-NLS-1$
9894

9995
// Downnload sample programs
@@ -126,16 +122,18 @@ public static void startup_Pluging(IProgressMonitor monitor) {
126122

127123
}
128124

129-
/* private static void InstallDefaultLibraries(IProgressMonitor monitor) {
130-
LibraryIndex libindex = getLibraryIndex();
125+
private static void InstallDefaultLibraries(IProgressMonitor monitor) {
126+
LibraryIndex libindex = getLibraryIndex(Defaults.DEFAULT);
127+
if (libindex == null)
128+
return;
131129

132130
for (String library : Defaults.INSTALLED_LIBRARIES) {
133131
Library toInstalLib = libindex.getLatestLibrary(library);
134132
if (toInstalLib != null) {
135133
toInstalLib.install(monitor);
136134
}
137135
}
138-
}*/
136+
}
139137

140138
/**
141139
* Given a platform description in a json file download and install all
@@ -260,7 +258,6 @@ static private void loadLibrary(File jsonFile) {
260258
try (Reader reader = new FileReader(jsonFile)) {
261259
LibraryIndex index = new Gson().fromJson(reader, LibraryIndex.class);
262260
index.resolve();
263-
// index.setOwners(null);
264261
index.setJsonFile(jsonFile);
265262
libraryIndices.add(index);
266263
} catch (Exception e) {
@@ -283,6 +280,15 @@ static public List<LibraryIndex> getLibraryIndices() {
283280
}
284281
return libraryIndices;
285282
}
283+
284+
static public LibraryIndex getLibraryIndex(String name) {
285+
for (LibraryIndex index : getLibraryIndices()) {
286+
if (index.getName().equals(name)) {
287+
return index;
288+
}
289+
}
290+
return null;
291+
}
286292

287293
static public Board getBoard(String boardName, String platformName, String packageName) {
288294
for (PackageIndex index : getPackageIndices()) {

0 commit comments

Comments
 (0)