Skip to content

Commit 1026418

Browse files
author
jantje
committed
#585 adding the core functionality
1 parent a0ca8bd commit 1026418

File tree

6 files changed

+251
-217
lines changed

6 files changed

+251
-217
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.osgi.service.prefs.Preferences;
4343

4444
import cc.arduino.packages.discoverers.SloeberNetworkDiscovery;
45+
import io.sloeber.core.api.PackageManager;
4546
import io.sloeber.core.common.Common;
4647
import io.sloeber.core.common.ConfigurationPreferences;
4748
import io.sloeber.core.common.Const;
@@ -216,7 +217,7 @@ private static void initializeImportantVariables() {
216217
InstancePreferences.setPrivateLibraryPaths(InstancePreferences.getPrivateLibraryPaths());
217218
InstancePreferences.setPrivateHardwarePaths(InstancePreferences.getPrivateHardwarePaths());
218219
InstancePreferences.setAutomaticallyImportLibraries(InstancePreferences.getAutomaticallyImportLibraries());
219-
ConfigurationPreferences.setJsonURLs(ConfigurationPreferences.getJsonURLs());
220+
PackageManager.setJsonURLs(PackageManager.getJsonURLs());
220221
}
221222

222223
private void runPluginCoreStartInstantiatorJob() {

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

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.sloeber.core.api;
22

33
import static io.sloeber.core.Messages.*;
4+
import static io.sloeber.core.common.ConfigurationPreferences.*;
45
import static io.sloeber.core.common.Const.*;
56
import static java.nio.file.StandardCopyOption.*;
67

@@ -27,6 +28,7 @@
2728
import java.util.TreeSet;
2829

2930
import org.apache.commons.io.FileUtils;
31+
import org.eclipse.cdt.core.parser.util.StringUtil;
3032
import org.eclipse.core.runtime.IPath;
3133
import org.eclipse.core.runtime.IProgressMonitor;
3234
import org.eclipse.core.runtime.IStatus;
@@ -59,6 +61,15 @@
5961
*
6062
*/
6163
public class PackageManager {
64+
private static String stringSplitter = "\n";//$NON-NLS-1$
65+
private static final String KEY_MANAGER_JSON_URLS_V3 = "Arduino Manager board Urls"; //$NON-NLS-1$
66+
private static final String KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL = "https://downloads.arduino.cc/libraries/library_index.json"; //$NON-NLS-1$
67+
private static final String KEY_MANAGER_JSON_URLS = "Manager jsons"; //$NON-NLS-1$
68+
private static final String DEFAULT_JSON_URLS = "https://downloads.arduino.cc/packages/package_index.json\n" //$NON-NLS-1$
69+
+ "https://raw.githubusercontent.com/jantje/hardware/master/package_jantje_index.json\n" //$NON-NLS-1$
70+
+ "https://raw.githubusercontent.com/jantje/ArduinoLibraries/master/library_jantje_index.json\n" //$NON-NLS-1$
71+
+ "https://arduino.esp8266.com/stable/package_esp8266com_index.json\n" //$NON-NLS-1$
72+
+ KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL;
6273

6374

6475
protected static List<PackageIndex> packageIndices;
@@ -120,10 +131,10 @@ static private BoardDescription getNewestBoardIDFromBoardsManager(String jsonFil
120131
}
121132

122133
public static void addPackageURLs(HashSet<String> packageUrlsToAdd, boolean forceDownload) {
123-
HashSet<String> originalJsonUrls = new HashSet<>(Arrays.asList(ConfigurationPreferences.getJsonURLList()));
134+
HashSet<String> originalJsonUrls = new HashSet<>(Arrays.asList(getJsonURLList()));
124135
packageUrlsToAdd.addAll(originalJsonUrls);
125136

126-
ConfigurationPreferences.setJsonURLs(packageUrlsToAdd);
137+
setJsonURLs(packageUrlsToAdd);
127138
loadJsons(forceDownload);
128139
}
129140

@@ -132,7 +143,7 @@ public static void setPackageURLs(HashSet<String> packageUrls, boolean forceDown
132143
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception()));
133144
return;
134145
}
135-
ConfigurationPreferences.setJsonURLs(packageUrls);
146+
setJsonURLs(packageUrls);
136147
loadJsons(forceDownload);
137148
}
138149

@@ -641,7 +652,7 @@ protected static synchronized void loadJsons(boolean forceDownload) {
641652
packageIndices = new ArrayList<>();
642653
LibraryManager.flushIndices();
643654

644-
String[] jsonUrls = ConfigurationPreferences.getJsonURLList();
655+
String[] jsonUrls = getJsonURLList();
645656
for (String jsonUrl : jsonUrls) {
646657
if (!jsonUrl.trim().isEmpty()) // skip empty lines
647658
loadJson(jsonUrl, forceDownload);
@@ -812,10 +823,50 @@ protected static void mySafeCopy(URL url, File localFile, boolean report_error)
812823
}
813824
}
814825

815-
public static String[] getJsonURLList() {
816-
return ConfigurationPreferences.getJsonURLList();
826+
public static String getDefaultJsonURLs() {
827+
return DEFAULT_JSON_URLS;
828+
}
829+
830+
public static String getJsonUrlsKey() {
831+
return KEY_MANAGER_JSON_URLS;
832+
}
833+
834+
public static void setJsonURLs(String urls) {
835+
setString(KEY_MANAGER_JSON_URLS, urls);
836+
}
837+
838+
private static void saveJsonURLs(String urls[]) {
839+
setString(KEY_MANAGER_JSON_URLS, StringUtil.join(urls, stringSplitter));
840+
}
841+
842+
public static void setJsonURLs(HashSet<String> urls) {
843+
setString(KEY_MANAGER_JSON_URLS, StringUtil.join(urls, stringSplitter));
817844
}
818845

846+
public static String[] getJsonURLList() {
847+
return getJsonURLs().replace("\r", new String()).split(stringSplitter); //$NON-NLS-1$
848+
}
849+
850+
public static String getJsonURLs() {
851+
// I added some code here to get easier from V3 to V4
852+
// the library json url is now managed as the boards url's so it also
853+
// needs to be added to the json url's
854+
// this is doen in the default but people who have installed other
855+
// boards or do not move to the default (which is by default)
856+
// wil not see libraries
857+
// to fix this I changed the storage name and if the new storage name is
858+
// empty I read the ol one and add the lib
859+
String ret = getString(KEY_MANAGER_JSON_URLS, DEFAULT_JSON_URLS);
860+
if (DEFAULT_JSON_URLS.equals(ret)) {
861+
ret = getString(KEY_MANAGER_JSON_URLS_V3, DEFAULT_JSON_URLS);
862+
if (!DEFAULT_JSON_URLS.equals(ret)) {
863+
ret += System.lineSeparator() + KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL;
864+
setString(KEY_MANAGER_JSON_URLS, ret);
865+
removeKey(KEY_MANAGER_JSON_URLS_V3);
866+
}
867+
}
868+
return ret;
869+
}
819870
/**
820871
* Completely replace the list with jsons with a new list
821872
*
@@ -844,7 +895,7 @@ public static void setJsonURLs(String[] newJsonUrls) {
844895
}
845896
}
846897
// save to configurationsettings before calling LoadIndices
847-
ConfigurationPreferences.setJsonURLs(newJsonUrls);
898+
saveJsonURLs(newJsonUrls);
848899
// reload the indices (this will remove all potential remaining
849900
// references
850901
// existing files do not need to be refreshed as they have been
@@ -853,9 +904,7 @@ public static void setJsonURLs(String[] newJsonUrls) {
853904
loadJsons(false);
854905
}
855906

856-
public static String getDefaultURLs() {
857-
return ConfigurationPreferences.getDefaultJsonURLs();
858-
}
907+
859908

860909
public static void removeAllInstalledPlatforms() {
861910
if (!isReady()) {

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package io.sloeber.core.api;
22

3+
import static io.sloeber.core.common.ConfigurationPreferences.*;
4+
import static io.sloeber.core.common.Const.*;
5+
6+
import java.util.HashSet;
7+
8+
import org.eclipse.cdt.core.parser.util.StringUtil;
9+
310
import cc.arduino.packages.discoverers.SloeberNetworkDiscovery;
411
import io.sloeber.core.common.ConfigurationPreferences;
512
import io.sloeber.core.common.InstancePreferences;
@@ -11,6 +18,10 @@
1118
*
1219
*/
1320
public class Preferences {
21+
private static String stringSplitter = "\n";//$NON-NLS-1$
22+
private static final String KEY_DISCONNECT_SERIAL_TAGETS = "Target names that require serial disconnect to run";//$NON-NLS-1$
23+
private static final String DEFAULT_DISCONNECT_SERIAL_TARGETS = "BurnBootLoader\nuploadWithBuild\nuploadWithoutBuild\nuploadWithProgrammerWithBuild\nuploadWithProgrammerWithoutBuild"; //$NON-NLS-1$
24+
1425
public static void setAutoImportLibraries(boolean booleanValue) {
1526
InstancePreferences.setAutomaticallyImportLibraries(booleanValue);
1627

@@ -64,4 +75,28 @@ public static void setUseBonjour(boolean newFlag) {
6475
}
6576
}
6677

78+
public static String getDefaultDisconnectSerialTargets() {
79+
return DEFAULT_DISCONNECT_SERIAL_TARGETS;
80+
}
81+
82+
public static String[] getDisconnectSerialTargetsList() {
83+
return getDisconnectSerialTargets().split(stringSplitter);
84+
}
85+
86+
public static String getDisconnectSerialTargets() {
87+
return getString(KEY_DISCONNECT_SERIAL_TAGETS, DEFAULT_DISCONNECT_SERIAL_TARGETS).replace("\r", EMPTY);//$NON-NLS-1$
88+
}
89+
90+
public static void setDisconnectSerialTargets(String targets) {
91+
setString(KEY_DISCONNECT_SERIAL_TAGETS, targets);
92+
}
93+
94+
public static void setDisconnectSerialTargets(String targets[]) {
95+
setString(KEY_DISCONNECT_SERIAL_TAGETS, StringUtil.join(targets, stringSplitter));
96+
}
97+
98+
public static void setDisconnectSerialTargets(HashSet<String> targets) {
99+
setString(KEY_DISCONNECT_SERIAL_TAGETS, StringUtil.join(targets, stringSplitter));
100+
}
101+
67102
}

0 commit comments

Comments
 (0)