Skip to content

Commit 4e5016e

Browse files
author
jantje
committed
#521 cleaner split gui versus implementation and added more boards
1 parent a7a8b93 commit 4e5016e

File tree

9 files changed

+339
-131
lines changed

9 files changed

+339
-131
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/common/ConfigurationPreferences.java

+41-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Paths;
1010
import java.util.Collection;
1111
import java.util.Enumeration;
12+
import java.util.HashSet;
1213
import java.util.TreeSet;
1314

1415
import org.eclipse.cdt.core.parser.util.StringUtil;
@@ -37,16 +38,25 @@ public class ConfigurationPreferences {
3738
private static final String POST_PROCESSING_PLATFORM_TXT = "post_processing_platform.txt"; //$NON-NLS-1$
3839
private static final String PRE_PROCESSING_BOARDS_TXT = "pre_processing_boards.txt"; //$NON-NLS-1$
3940
private static final String POST_PROCESSING_BOARDS_TXT = "post_processing_boards.txt"; //$NON-NLS-1$
41+
private static final String KEY_UPDATE_JASONS = "Update jsons files"; //$NON-NLS-1$
42+
private static final String KEY_MANAGER_JSON_URLS = "Arduino Manager board Urls"; //$NON-NLS-1$
43+
private static final String DEFAULT_JSON_URLS = "http://downloads.arduino.cc/packages/package_index.json" //$NON-NLS-1$
44+
+ System.lineSeparator() + "http://arduino.esp8266.com/stable/package_esp8266com_index.json"; //$NON-NLS-1$
4045

4146
private ConfigurationPreferences() {
4247
}
4348

44-
private static String getGlobalString(String key, String defaultValue) {
49+
private static String getString(String key, String defaultValue) {
4550
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(Const.NODE_ARDUINO);
4651
return myScope.get(key, defaultValue);
4752
}
4853

49-
private static void setGlobalString(String key, String value) {
54+
private static boolean getBoolean(String key, boolean defaultValue) {
55+
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(Const.NODE_ARDUINO);
56+
return myScope.getBoolean(key, defaultValue);
57+
}
58+
59+
private static void setString(String key, String value) {
5060
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(Const.NODE_ARDUINO);
5161
myScope.put(key, value);
5262
try {
@@ -65,7 +75,7 @@ public static Path getInstallationPath() {
6575
return new Path(pathName);
6676
}
6777
}
68-
String storedValue = getGlobalString(KEY_MANAGER_DOWNLOAD_LOCATION, Const.EMPTY_STRING);
78+
String storedValue = getString(KEY_MANAGER_DOWNLOAD_LOCATION, Const.EMPTY_STRING);
6979
if (storedValue.isEmpty()) {
7080
try {
7181
URL resolvedUrl = Platform.getInstallLocation().getURL();
@@ -121,27 +131,47 @@ public static File getPostProcessingBoardsFile() {
121131
return getInstallationPath().append(POST_PROCESSING_BOARDS_TXT).toFile();
122132
}
123133

124-
public static String getPackageURLs() {
125-
return getGlobalString(Const.KEY_MANAGER_JSON_URLS, Defaults.JSON_URLS);
134+
public static String getBoardsPackageURLs() {
135+
return getString(KEY_MANAGER_JSON_URLS, DEFAULT_JSON_URLS);
136+
}
137+
138+
public static String getDefaultBoardsPackageURLs() {
139+
return DEFAULT_JSON_URLS;
140+
}
141+
142+
public static String[] getBoardsPackageURLList() {
143+
return getBoardsPackageURLs().replaceAll(Const.RETURN, Const.EMPTY_STRING).split(stringSplitter);
126144
}
127145

128-
public static String[] getPackageURLList() {
129-
return getPackageURLs().replaceAll(Const.RETURN, Const.EMPTY_STRING).split(stringSplitter);
146+
public static String getBoardsPackageKey() {
147+
return KEY_MANAGER_JSON_URLS;
130148
}
131149

132-
public static void setPackageURLs(String urls) {
133-
setGlobalString(Const.KEY_MANAGER_JSON_URLS, urls);
150+
public static void setBoardsPackageURLs(String urls) {
151+
setString(KEY_MANAGER_JSON_URLS, urls);
134152
}
135153

136-
public static void setPackageURLs(String urls[]) {
137-
setGlobalString(Const.KEY_MANAGER_JSON_URLS, StringUtil.join(urls, stringSplitter));
154+
public static void setBoardsPackageURLs(String urls[]) {
155+
setString(KEY_MANAGER_JSON_URLS, StringUtil.join(urls, stringSplitter));
156+
}
157+
158+
public static void setBoardsPackageURLs(HashSet<String> urls) {
159+
setString(KEY_MANAGER_JSON_URLS, StringUtil.join(urls, stringSplitter));
138160
}
139161

140162
public static Path getPathExtensionPath() {
141163
return new Path(getInstallationPath().append("tools/make").toString()); //$NON-NLS-1$
142164

143165
}
144166

167+
public static String getUpdateJasonFilesKey() {
168+
return KEY_UPDATE_JASONS;
169+
}
170+
171+
public static boolean getUpdateJasonFilesValue() {
172+
return getBoolean(KEY_UPDATE_JASONS, false);
173+
}
174+
145175
private static String systemHash = null;
146176

147177
/**

it.baeyens.arduino.common/src/it/baeyens/arduino/common/Const.java

-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public class Const {
6262
public static final String KEY_PRIVATE_LIBRARY_PATHS = "Private Library Path";
6363
public static final String KEY_PRIVATE_HARDWARE_PATHS = "Private hardware Path";
6464

65-
public static final String KEY_MANAGER_JSON_URLS = "Arduino Manager board Urls";
66-
6765
// properties keys
6866
public static final String KEY_LAST_USED_BOARD = "Board";
6967
public static final String KEY_LAST_USED_COM_PORT = "Upload port";
@@ -72,7 +70,6 @@ public class Const {
7270
public static final String KEY_LAST_USED_BOARD_MENU_OPTIONS = "Board custom option selections";
7371

7472
public static final String KEY_LAST_USED_EXAMPLES = "Last used Examples";
75-
public static final String KEY_UPDATE_JASONS = "Update jsons files";
7673

7774
// Serial monitor keys
7875
public static final String KEY_SERIAL_RATE = "Serial monitor last selected rate";

it.baeyens.arduino.common/src/it/baeyens/arduino/common/Defaults.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
public class Defaults {
88
public static final boolean OPEN_SERIAL_WITH_MONITOR = true;
99
public static final boolean AUTO_IMPORT_LIBRARIES = true;
10-
public static final String JSON_URLS = "http://downloads.arduino.cc/packages/package_index.json"
11-
+ System.lineSeparator() + "http://arduino.esp8266.com/stable/package_esp8266com_index.json";
10+
1211
public static final String LIBRARIES_URL = "http://downloads.arduino.cc/libraries/library_index.json";
1312
public static final String EXAMPLE_PACKAGE = "examples_Arduino_1_6_7.zip";
1413
public static final String EXAMPLES_URL = "http://eclipse.baeyens.it/download/" + EXAMPLE_PACKAGE;
1514
public static final String PLATFORM_NAME = "Arduino AVR Boards";
1615
public static final String[] INSTALLED_LIBRARIES = new String[] { "Ethernet", "Firmata", "GSM", "Keyboard",
1716
"LiquidCrystal", "Mouse", "SD", "Servo", "Stepper", "TFT", "WiFi" };
1817

19-
private Defaults () {}
18+
private Defaults() {
19+
}
2020

2121
/**
2222
* Arduino has the default libraries in the user home directory in subfolder

it.baeyens.arduino.common/src/it/baeyens/arduino/common/InstancePreferences.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
public class InstancePreferences extends Const {
2121

2222
private static boolean mIsConfigured = false;
23-
private static final String KEY_CLEAN_MONITOR_AFTER_UPLOAD = "Clean Serial Monitor after upload";
24-
private static final String KEY_LAST_USED_SCOPE_FILTER_MENU_OPTION = "Board scope filter on off";
23+
private static final String KEY_CLEAN_MONITOR_AFTER_UPLOAD = "Clean Serial Monitor after upload"; //$NON-NLS-1$
24+
private static final String KEY_LAST_USED_SCOPE_FILTER_MENU_OPTION = "Board scope filter on off"; //$NON-NLS-1$
2525

2626
public static boolean getOpenSerialWithMonitor() {
2727
return getGlobalBoolean(KEY_OPEN_SERIAL_WITH_MONITOR, Defaults.OPEN_SERIAL_WITH_MONITOR);

it.baeyens.arduino.core/src/io/sloeber/core/api/BoardsManager.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
import java.io.File;
44
import java.util.Collection;
5+
import java.util.HashSet;
56
import java.util.List;
67
import java.util.Map;
8+
import java.util.Set;
79

810
import org.eclipse.core.runtime.CoreException;
911
import org.eclipse.core.runtime.NullProgressMonitor;
1012

13+
import it.baeyens.arduino.common.ConfigurationPreferences;
1114
import it.baeyens.arduino.common.InstancePreferences;
1215
import it.baeyens.arduino.managers.ArduinoPlatform;
1316
import it.baeyens.arduino.managers.Board;
@@ -23,6 +26,11 @@
2326
*
2427
*/
2528
public class BoardsManager {
29+
30+
public static String getUpdateJasonFilesKey() {
31+
return ConfigurationPreferences.getUpdateJasonFilesKey();
32+
}
33+
2634
/**
2735
* Gets the board id based on the information provided. If
2836
* jsonFileName="local" the board is assumend not to be installed by the
@@ -92,8 +100,12 @@ static private BoardDescriptor getNewestBoardIDFromBoardsManager(String jsonFile
92100
return null;
93101
}
94102

95-
public static void addPackageURLs(String[] packageUrlsToAdd) {
96-
Manager.addPackageURLs(packageUrlsToAdd);
103+
public static void addPackageURLs(HashSet<String> packageUrlsToAdd, boolean forceDownload) {
104+
Manager.addPackageURLs(packageUrlsToAdd, forceDownload);
105+
}
106+
107+
public static void removePackageURLs(Set<String> packageUrlsToRemove) {
108+
Manager.removeBoardsPackageURLs(packageUrlsToRemove);
97109

98110
}
99111

@@ -123,4 +135,16 @@ public static void referenceLocallInstallation(String newHardwarePath) {
123135
InstancePreferences.setPrivateHardwarePaths(newPaths);
124136
}
125137

138+
public static String[] getBoardsPackageURLList() {
139+
return Manager.getBoardsPackageURLList();
140+
}
141+
142+
public static void setBoardsPackageURL(String[] newBoardJsonUrls) {
143+
Manager.setBoardsPackageURL(newBoardJsonUrls);
144+
}
145+
146+
public static String getBoardsPackageURLs() {
147+
return Manager.getBoardsPackageURLs();
148+
}
149+
126150
}

it.baeyens.arduino.core/src/it/baeyens/arduino/managers/Manager.java

+81-15
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
import java.nio.file.Paths;
2828
import java.nio.file.StandardCopyOption;
2929
import java.util.ArrayList;
30+
import java.util.Arrays;
3031
import java.util.HashMap;
32+
import java.util.HashSet;
3133
import java.util.List;
3234
import java.util.Map;
35+
import java.util.Set;
3336

3437
import org.apache.commons.compress.archivers.ArchiveEntry;
3538
import org.apache.commons.compress.archivers.ArchiveInputStream;
@@ -61,17 +64,13 @@ public class Manager {
6164
private Manager() {
6265
}
6366

64-
public static void addPackageURLs(String packageUrlsToAdd[]) {
65-
String[] originalBoardUrls = ConfigurationPreferences.getPackageURLList();
67+
public static void addPackageURLs(HashSet<String> packageUrlsToAdd, boolean forceDownload) {
68+
HashSet<String> originalBoardUrls = new HashSet<>(
69+
Arrays.asList(ConfigurationPreferences.getBoardsPackageURLList()));
70+
packageUrlsToAdd.addAll(originalBoardUrls);
6671

67-
String[] newBoardsUrls = new String[packageUrlsToAdd.length + originalBoardUrls.length];
68-
System.arraycopy(packageUrlsToAdd, 0, newBoardsUrls, 0, packageUrlsToAdd.length);
69-
System.arraycopy(originalBoardUrls, 0, newBoardsUrls, packageUrlsToAdd.length, originalBoardUrls.length);
70-
ConfigurationPreferences.setPackageURLs(newBoardsUrls);
71-
72-
if (packageIndices != null) {
73-
loadIndices();
74-
}
72+
ConfigurationPreferences.setBoardsPackageURLs(packageUrlsToAdd);
73+
loadIndices(forceDownload);
7574

7675
}
7776

@@ -82,7 +81,7 @@ public static void addPackageURLs(String packageUrlsToAdd[]) {
8281
* @param monitor
8382
*/
8483
public static void startup_Pluging(IProgressMonitor monitor) {
85-
loadIndices();
84+
loadIndices(ConfigurationPreferences.getUpdateJasonFilesValue());
8685
try {
8786
List<Board> allBoards = getInstalledBoards();
8887
if (allBoards.isEmpty()) { // we test for boards
@@ -172,11 +171,11 @@ static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean force
172171

173172
}
174173

175-
static public void loadIndices() {
176-
String[] boardUrls = ConfigurationPreferences.getPackageURLList();
174+
static private void loadIndices(boolean forceDownload) {
175+
String[] boardUrls = ConfigurationPreferences.getBoardsPackageURLList();
177176
packageIndices = new ArrayList<>(boardUrls.length);
178177
for (String boardUrl : boardUrls) {
179-
loadPackageIndex(boardUrl, false);
178+
loadPackageIndex(boardUrl, forceDownload);
180179
}
181180

182181
loadLibraryIndex(false);
@@ -245,7 +244,7 @@ static private void loadPackageIndex(String url, boolean forceDownload) {
245244

246245
static public List<PackageIndex> getPackageIndices() {
247246
if (packageIndices == null) {
248-
String[] boardUrls = ConfigurationPreferences.getPackageURLList();
247+
String[] boardUrls = ConfigurationPreferences.getBoardsPackageURLList();
249248
packageIndices = new ArrayList<>(boardUrls.length);
250249
for (String boardUrl : boardUrls) {
251250
loadPackageIndex(boardUrl, false);
@@ -772,4 +771,71 @@ public static int compareVersions(String version1, String version2) {
772771
return 0;
773772
}
774773

774+
/**
775+
* This method removes the json files from disk and removes memory
776+
* references to these files or their content
777+
*
778+
* @param packageUrlsToRemove
779+
*/
780+
public static void removeBoardsPackageURLs(Set<String> packageUrlsToRemove) {
781+
// remove the files from memory
782+
Set<String> activeBoardUrls = new HashSet<>(Arrays.asList(ConfigurationPreferences.getBoardsPackageURLList()));
783+
784+
activeBoardUrls.removeAll(packageUrlsToRemove);
785+
786+
ConfigurationPreferences.setBoardsPackageURLs(activeBoardUrls.toArray(null));
787+
788+
// remove the files from disk
789+
for (String curJson : packageUrlsToRemove) {
790+
File localFile = getLocalFileName(curJson);
791+
if (localFile.exists()) {
792+
localFile.delete();
793+
}
794+
}
795+
796+
// reload the indices (this will remove all potential remaining
797+
// references
798+
// existing files do not need to be refreshed as they have been
799+
// refreshed at startup
800+
loadIndices(false);
801+
802+
}
803+
804+
public static String[] getBoardsPackageURLList() {
805+
return ConfigurationPreferences.getBoardsPackageURLList();
806+
}
807+
808+
/**
809+
* Completely replace the list with jsons with a new list
810+
*
811+
* @param newBoardJsonUrls
812+
*/
813+
public static void setBoardsPackageURL(String[] newBoardJsonUrls) {
814+
815+
String curJsons[] = getBoardsPackageURLList();
816+
HashSet<String> origJsons = new HashSet<>(Arrays.asList(curJsons));
817+
HashSet<String> currentSelectedJsons = new HashSet<>(Arrays.asList(newBoardJsonUrls));
818+
currentSelectedJsons.removeAll(origJsons);
819+
// remove the files from disk which were in the old lst but not in the
820+
// new one
821+
for (String curJson : currentSelectedJsons) {
822+
File localFile = getLocalFileName(curJson);
823+
if (localFile.exists()) {
824+
localFile.delete();
825+
}
826+
}
827+
// save to configurationsettings before calling LoadIndices
828+
ConfigurationPreferences.setBoardsPackageURLs(newBoardJsonUrls);
829+
// reload the indices (this will remove all potential remaining
830+
// references
831+
// existing files do not need to be refreshed as they have been
832+
// refreshed at startup
833+
// new files will be added
834+
loadIndices(false);
835+
}
836+
837+
public static String getBoardsPackageURLs() {
838+
return ConfigurationPreferences.getDefaultBoardsPackageURLs();
839+
}
840+
775841
}

it.baeyens.arduino.core/src/it/baeyens/arduino/ui/Activator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static void initializeImportantVariables() {
128128
InstancePreferences.setOpenSerialWithMonitor(InstancePreferences.getOpenSerialWithMonitor());
129129
InstancePreferences.setAutomaticallyIncludeLibraries(InstancePreferences.getAutomaticallyIncludeLibraries());
130130
InstancePreferences.setCleanSerialMonitorAfterUpload(InstancePreferences.getCleanSerialMonitorAfterUpload());
131-
ConfigurationPreferences.setPackageURLs(ConfigurationPreferences.getPackageURLs());
131+
ConfigurationPreferences.setBoardsPackageURLs(ConfigurationPreferences.getBoardsPackageURLs());
132132
}
133133

134134
private void runPluginCoreStartInstantiatorJob() {

0 commit comments

Comments
 (0)