Skip to content

Commit 7162fb1

Browse files
committed
Added ability to enter custom json files also for libraries.
Changed library selection, now json file is shown after library name.
1 parent 973d1f2 commit 7162fb1

File tree

15 files changed

+357
-294
lines changed

15 files changed

+357
-294
lines changed

io.sloeber.core/src/io/sloeber/core/Activator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private static void initializeImportantVariables() {
158158
InstancePreferences.setPrivateLibraryPaths(InstancePreferences.getPrivateLibraryPaths());
159159
InstancePreferences.setPrivateHardwarePaths(InstancePreferences.getPrivateHardwarePaths());
160160
InstancePreferences.setAutomaticallyImportLibraries(InstancePreferences.getAutomaticallyImportLibraries());
161-
ConfigurationPreferences.setBoardsPackageURLs(ConfigurationPreferences.getBoardsPackageURLs());
161+
ConfigurationPreferences.setJsonURLs(ConfigurationPreferences.getJsonURLs());
162162
}
163163

164164
private void runPluginCoreStartInstantiatorJob() {

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ static private BoardDescriptor getNewestBoardIDFromBoardsManager(String jsonFile
111111
}
112112

113113
public static void addPackageURLs(HashSet<String> packageUrlsToAdd, boolean forceDownload) {
114-
Manager.addPackageURLs(packageUrlsToAdd, forceDownload);
114+
Manager.addJsonURLs(packageUrlsToAdd, forceDownload);
115115
}
116116

117117
public static void removePackageURLs(Set<String> packageUrlsToRemove) {
118-
Manager.removeBoardsPackageURLs(packageUrlsToRemove);
118+
Manager.removePackageURLs(packageUrlsToRemove);
119119

120120
}
121121

@@ -144,18 +144,6 @@ public static void referenceLocallInstallation(String newHardwarePath) {
144144
InstancePreferences.setPrivateHardwarePaths(newPaths);
145145
}
146146

147-
public static String[] getBoardsPackageURLList() {
148-
return Manager.getBoardsPackageURLList();
149-
}
150-
151-
public static void setBoardsPackageURL(String[] newBoardJsonUrls) {
152-
Manager.setBoardsPackageURL(newBoardJsonUrls);
153-
}
154-
155-
public static String getDefaultBoardsPackageURLs() {
156-
return Manager.getDefaultBoardsPackageURLs();
157-
}
158-
159147
public static boolean isReady() {
160148
return Manager.isReady();
161149
}
@@ -712,10 +700,4 @@ public static void onlyKeepLatestPlatforms() {
712700
Manager.onlyKeepLatestPlatforms();
713701

714702
}
715-
716-
public static void setUpdateJsonFilesFlag(boolean flag) {
717-
ConfigurationPreferences.setUpdateJasonFilesFlag(flag);
718-
719-
}
720-
721703
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
@SuppressWarnings("nls")
99
public class Defaults {
10-
11-
public static final String LIBRARIES_URL = "http://downloads.arduino.cc/libraries/library_index.json";
1210
public static final String EXAMPLE_PACKAGE = "examples_Arduino_1_6_7.zip";
1311
public static final String EXAMPLES_URL = "http://eclipse.baeyens.it/download/" + EXAMPLE_PACKAGE;
1412
public static final String PLATFORM_NAME = "Arduino AVR Boards";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.sloeber.core.api;
2+
3+
import io.sloeber.core.common.ConfigurationPreferences;
4+
import io.sloeber.core.managers.Manager;
5+
6+
public class JsonManager {
7+
public static void setURL(String[] newUrls) {
8+
Manager.setJsonURL(newUrls);
9+
}
10+
11+
public static String[] getURLList() {
12+
return Manager.getJsonURLList();
13+
}
14+
15+
public static void setUpdateJsonFilesFlag(boolean flag) {
16+
ConfigurationPreferences.setUpdateJasonFilesFlag(flag);
17+
}
18+
19+
public static String getDefaultURLs() {
20+
return ConfigurationPreferences.getDefaultJsonURLs();
21+
}
22+
}

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

Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ public Object getParent() {
6363

6464
public class Library implements Comparable<Library>, Node {
6565
private String name;
66+
private String indexName;
6667
private Category category;
6768
protected TreeSet<VersionNumber> versions = new TreeSet<>();
6869
protected String version;
6970
private String tooltip;
7071

71-
public Library(Category category, String name, String tooltip) {
72+
public Library(Category category, String name, String indexName, String tooltip) {
7273
this.category = category;
7374
this.name = name;
7475
this.tooltip = tooltip;
76+
this.indexName = indexName;
7577
}
7678

7779
public Collection<VersionNumber> getVersions() {
@@ -95,6 +97,10 @@ public String getVersion() {
9597
return this.version;
9698
}
9799

100+
public String getIndexName() {
101+
return this.indexName;
102+
}
103+
98104
public void setVersion(String version) {
99105
this.version = version;
100106
}
@@ -121,26 +127,28 @@ public Object getParent() {
121127
}
122128

123129
public LibraryTree() {
124-
LibraryIndex libraryIndex = Manager.getLibraryIndex();
125-
126-
for (String categoryName : libraryIndex.getCategories()) {
127-
Category category = new Category(categoryName);
128-
for (io.sloeber.core.managers.Library library : libraryIndex.getLibraries(categoryName)) {
129-
Library lib = category.libraries.get(library.getName());
130-
if (lib == null) {
131-
StringBuilder builder = new StringBuilder("Architectures:") //$NON-NLS-1$
132-
.append(library.getArchitectures().toString()).append("\n\n") //$NON-NLS-1$
133-
.append(library.getSentence());
134-
lib = new Library(category, library.getName(), builder.toString());
135-
category.libraries.put(lib.getName(), lib);
136-
}
137-
lib.versions.add(new VersionNumber(library.getVersion()));
138-
if (library.isInstalled()) {
139-
lib.version = library.getVersion();
140-
}
141-
}
142-
143-
this.categories.put(category.getName(), category);
130+
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
131+
for (String categoryName : libraryIndex.getCategories()) {
132+
Category category = this.categories.get(categoryName);
133+
if (category == null) {
134+
category = new Category(categoryName);
135+
this.categories.put(category.getName(), category);
136+
}
137+
for (io.sloeber.core.managers.Library library : libraryIndex.getLibraries(categoryName)) {
138+
Library lib = category.libraries.get(library.getName() + " (" + libraryIndex.getName() + ")");
139+
if (lib == null) {
140+
StringBuilder builder = new StringBuilder("Architectures:") //$NON-NLS-1$
141+
.append(library.getArchitectures().toString()).append("\n\n") //$NON-NLS-1$
142+
.append(library.getSentence());
143+
lib = new Library(category, library.getName(), libraryIndex.getName(), builder.toString());
144+
category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib);
145+
}
146+
lib.versions.add(new VersionNumber(library.getVersion()));
147+
if (library.isInstalled()) {
148+
lib.version = library.getVersion();
149+
}
150+
}
151+
}
144152
}
145153
}
146154

@@ -156,32 +164,54 @@ public Collection<Library> getAllLibraries() {
156164
return all;
157165
}
158166

167+
private static LibraryIndex findLibraryIndex(String name) {
168+
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
169+
if (libraryIndex.getName().equals(name))
170+
return libraryIndex;
171+
}
172+
return null;
173+
}
174+
159175
public void reset() {
160-
LibraryIndex libraryIndex = Manager.getLibraryIndex();
161176
for (Library library : this.getAllLibraries()) {
162-
io.sloeber.core.managers.Library installed = libraryIndex.getInstalledLibrary(library.getName());
163-
library.setVersion(installed != null ? installed.getVersion() : null);
177+
LibraryIndex libraryIndex = findLibraryIndex(library.getIndexName());
178+
179+
if (libraryIndex != null) {
180+
io.sloeber.core.managers.Library installed = libraryIndex.getInstalledLibrary(library.getName());
181+
library.setVersion(installed != null ? installed.getVersion() : null);
182+
}
164183
}
165184
}
166185

167186
}
168187

169188
public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor, MultiStatus status) {
170-
for (LibraryTree.Library lib : libs.getAllLibraries()) {
171-
io.sloeber.core.managers.Library toRemove = Manager.getLibraryIndex().getInstalledLibrary(lib.getName());
172-
if (toRemove != null && !toRemove.getVersion().equals(lib.getVersion())) {
173-
status.add(toRemove.remove(monitor));
174-
}
175-
io.sloeber.core.managers.Library toInstall = Manager.getLibraryIndex().getLibrary(lib.getName(),
176-
lib.getVersion());
177-
if (toInstall != null && !toInstall.isInstalled()) {
178-
status.add(toInstall.install(monitor));
179-
}
180-
}
181-
return status;
189+
for (LibraryTree.Library lib : libs.getAllLibraries()) {
190+
LibraryIndex libraryIndex = findLibraryIndex(lib.getIndexName());
191+
192+
if (libraryIndex != null) {
193+
io.sloeber.core.managers.Library toRemove = libraryIndex.getInstalledLibrary(lib.getName());
194+
if (toRemove != null && !toRemove.getVersion().equals(lib.getVersion())) {
195+
status.add(toRemove.remove(monitor));
196+
}
197+
io.sloeber.core.managers.Library toInstall = libraryIndex.getLibrary(lib.getName(), lib.getVersion());
198+
if (toInstall != null && !toInstall.isInstalled()) {
199+
status.add(toInstall.install(monitor));
200+
}
201+
}
202+
}
203+
return status;
182204
}
183205

184-
public static String getPrivateLibraryPathsString() {
206+
private static LibraryIndex findLibraryIndex(String indexName) {
207+
for (LibraryIndex libraryIndex : Manager.getLibraryIndices()) {
208+
if (libraryIndex.getName().equals(indexName))
209+
return libraryIndex;
210+
}
211+
return null;
212+
}
213+
214+
public static String getPrivateLibraryPathsString() {
185215
return InstancePreferences.getPrivateLibraryPathsString();
186216
}
187217

io.sloeber.core/src/io/sloeber/core/common/ConfigurationPreferences.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public class ConfigurationPreferences {
4242
private static final String KEY_UPDATE_JASONS = "Update jsons files"; //$NON-NLS-1$
4343
private static final String KEY_MANAGER_JSON_URLS = "Arduino Manager board Urls"; //$NON-NLS-1$
4444
private static final String DEFAULT_JSON_URLS = "http://downloads.arduino.cc/packages/package_index.json" //$NON-NLS-1$
45-
+ System.lineSeparator() + "http://arduino.esp8266.com/stable/package_esp8266com_index.json"; //$NON-NLS-1$
45+
+ System.lineSeparator() + "http://arduino.esp8266.com/stable/package_esp8266com_index.json" //$NON-NLS-1$
46+
+ System.lineSeparator() + "http://downloads.arduino.cc/libraries/library_index.json"; //$NON-NLS-1$
4647
// preference nodes
4748
public static final String NODE_ARDUINO = Activator.NODE_ARDUINO;
4849

@@ -142,31 +143,31 @@ public static File getPostProcessingBoardsFile() {
142143
return getInstallationPath().append(POST_PROCESSING_BOARDS_TXT).toFile();
143144
}
144145

145-
public static String getBoardsPackageURLs() {
146+
public static String getJsonURLs() {
146147
return getString(KEY_MANAGER_JSON_URLS, DEFAULT_JSON_URLS);
147148
}
148149

149-
public static String getDefaultBoardsPackageURLs() {
150+
public static String getDefaultJsonURLs() {
150151
return DEFAULT_JSON_URLS;
151152
}
152153

153-
public static String[] getBoardsPackageURLList() {
154-
return getBoardsPackageURLs().replace("\r", new String()).split(stringSplitter); //$NON-NLS-1$
154+
public static String[] getJsonURLList() {
155+
return getJsonURLs().replace("\r", new String()).split(stringSplitter); //$NON-NLS-1$
155156
}
156157

157-
public static String getBoardsPackageKey() {
158+
public static String getJsonUrlsKey() {
158159
return KEY_MANAGER_JSON_URLS;
159160
}
160161

161-
public static void setBoardsPackageURLs(String urls) {
162+
public static void setJsonURLs(String urls) {
162163
setString(KEY_MANAGER_JSON_URLS, urls);
163164
}
164165

165-
public static void setBoardsPackageURLs(String urls[]) {
166+
public static void setJsonURLs(String urls[]) {
166167
setString(KEY_MANAGER_JSON_URLS, StringUtil.join(urls, stringSplitter));
167168
}
168169

169-
public static void setBoardsPackageURLs(HashSet<String> urls) {
170+
public static void setJsonURLs(HashSet<String> urls) {
170171
setString(KEY_MANAGER_JSON_URLS, StringUtil.join(urls, stringSplitter));
171172
}
172173

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.sloeber.core.managers;
2+
3+
public class Help {
4+
private String online;
5+
6+
public String getOnline() {
7+
return this.online;
8+
}
9+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ public class Library implements Comparable<Library> {
3939
public String getName() {
4040
return this.name;
4141
}
42-
42+
4343
public void setName(String name) {
4444
this.name = name;
4545
}
46+
4647

4748
public String getVersion() {
4849
return this.version;

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package io.sloeber.core.managers;
22

3+
import java.io.File;
34
import java.util.ArrayList;
45
import java.util.Collection;
56
import java.util.HashMap;
67
import java.util.HashSet;
78
import java.util.List;
89
import java.util.Map;
910
import java.util.Set;
11+
import java.util.regex.Pattern;
1012

1113
public class LibraryIndex {
12-
14+
private String indexName;
1315
private List<Library> libraries;
1416

1517
// category name to library name
@@ -99,4 +101,16 @@ public Collection<Library> getLibraries(String category) {
99101
return libs;
100102
}
101103

104+
public void setJsonFile(File packageFile) {
105+
String fileName = packageFile.getName().toLowerCase();
106+
if (fileName.matches("(?i)library_index.json")) {
107+
this.indexName = "Default";
108+
} else {
109+
this.indexName = fileName.replaceAll("(?i)"+Pattern.quote("library_"), "").replaceAll("(?i)"+Pattern.quote("_index.json"), "");
110+
}
111+
}
112+
113+
public String getName() {
114+
return this.indexName;
115+
}
102116
}

0 commit comments

Comments
 (0)