Skip to content

Commit 187fc86

Browse files
author
jantje
committed
Added method to remove all "old platforms"
understand old platforms as platforms for which a newer version is installed. This is currently only used for the unit testing. I don't see any other real usage for now
1 parent 7471b83 commit 187fc86

File tree

6 files changed

+44
-30
lines changed

6 files changed

+44
-30
lines changed

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

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.util.TreeMap;
1212
import java.util.TreeSet;
1313

14-
import org.eclipse.core.runtime.CoreException;
1514
import org.eclipse.core.runtime.IPath;
1615
import org.eclipse.core.runtime.IProgressMonitor;
1716
import org.eclipse.core.runtime.IStatus;
@@ -53,10 +52,10 @@ public static String getUpdateJasonFilesKey() {
5352
}
5453

5554
/**
56-
* Gets the board id based on the information provided. If
57-
* jsonFileName="local" the board is assumend not to be installed by the
55+
* Gets the board descriptor based on the information provided. If
56+
* jsonFileName="local" the board is assumed not to be installed by the
5857
* boards manager. Otherwise the boardsmanager is queried to find the board
59-
* ID. In this case the latest installed board will be returned
58+
* descriptor. In this case the latest installed board will be returned
6059
*
6160
* @param jsonFileName
6261
* equals to "local" or the name of the json file used by the
@@ -75,7 +74,7 @@ public static String getUpdateJasonFilesKey() {
7574
* boards.txt file)
7675
* @return The class BoardDescriptor or null
7776
*/
78-
static public BoardDescriptor getBoardID(String jsonFileName, String packageName, String platformName,
77+
static public BoardDescriptor getBoardDescriptor(String jsonFileName, String packageName, String platformName,
7978
String boardID, Map<String, String> options) {
8079
if (jsonFileName.equals("local")) { //$NON-NLS-1$
8180
return BoardDescriptor.makeBoardDescriptor(new File(packageName), boardID, options);
@@ -87,22 +86,18 @@ static private BoardDescriptor getNewestBoardIDFromBoardsManager(String jsonFile
8786
String platformName, String boardID, Map<String, String> options) {
8887

8988
List<Board> boards = null;
90-
try {
91-
Package thePackage = Manager.getPackage(jsonFileName, packageName);
92-
if (thePackage == null) {
93-
// fail("failed to find package:" + this.mPackageName);
94-
return null;
95-
}
96-
ArduinoPlatform platform = thePackage.getLatestPlatform(platformName);
97-
if (platform == null) {
98-
// fail("failed to find platform " + this.mPlatform + " in
99-
// package:" + this.mPackageName);
100-
return null;
101-
}
102-
boards = platform.getBoards();
103-
} catch (CoreException e1) {
104-
e1.printStackTrace();
89+
Package thePackage = Manager.getPackage(jsonFileName, packageName);
90+
if (thePackage == null) {
91+
// fail("failed to find package:" + this.mPackageName);
92+
return null;
10593
}
94+
ArduinoPlatform platform = thePackage.getLatestPlatform(platformName);
95+
if (platform == null) {
96+
// fail("failed to find platform " + this.mPlatform + " in
97+
// package:" + this.mPackageName);
98+
return null;
99+
}
100+
boards = platform.getBoards();
106101
if (boards == null) {
107102
// fail("No boards found");
108103
return null;
@@ -161,8 +156,8 @@ public static void setBoardsPackageURL(String[] newBoardJsonUrls) {
161156
Manager.setBoardsPackageURL(newBoardJsonUrls);
162157
}
163158

164-
public static String getBoardsPackageURLs() {
165-
return Manager.getBoardsPackageURLs();
159+
public static String getDefaultBoardsPackageURLs() {
160+
return Manager.getDefaultBoardsPackageURLs();
166161
}
167162

168163
public static boolean isReady() {
@@ -694,7 +689,7 @@ public static String getPrivateHardwarePathsString() {
694689
*
695690
* @return
696691
*/
697-
public static Set<String> getAllManuNames() {
692+
public static Set<String> getAllMenuNames() {
698693
Set<String> ret = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
699694
String[] boardFiles = getAllBoardsFiles();
700695
for (String curBoardFile : boardFiles) {
@@ -714,4 +709,12 @@ public static TreeMap<String, String> getAllmenus() {
714709
return ret;
715710
}
716711

712+
/**
713+
* Remove all packages that have a more recent version
714+
*/
715+
public static void onlyKeepLatestPlatforms() {
716+
Manager.onlyKeepLatestPlatforms();
717+
718+
}
719+
717720
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
@SuppressWarnings("nls")
1010
public class Const {
1111
// java stuff so I do not have to add all the time $NON-NLS-1$
12-
public static final String EMPTY_STRING = "";
1312
public static final String DOT = ".";
1413
public static final String SLACH = "/";
1514
public static final String COLON = ":";
@@ -78,9 +77,6 @@ public class Const {
7877
public static final String ENV_KEY_JANTJE_PLATFORM_FILE = ENV_KEY_JANTJE_START + "PLATFORM_FILE";
7978
public static final String ENV_KEY_JANTJE_CORE_REFERENCED_PLATFORM = ERASE_START + ENV_KEY_JANTJE_START
8079
+ "CORE.REFERENCED.PLATFORM"; //$NON-NLS-1$
81-
public static final String ENV_KEY_JANTJE_UPLOAD_PORT = ENV_KEY_JANTJE_START + "COM_PORT";
82-
public static final String ENV_KEY_JANTJE_BOARD_NAME = ENV_KEY_JANTJE_START + "BOARD_NAME";
83-
public static final String ENV_KEY_JANTJE_PROJECT_NAME = ENV_KEY_JANTJE_START + "PROJECT_NAME";
8480

8581
public static final String ENV_KEY_JANTJE_ADDITIONAL_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "EXTRA.COMPILE";
8682
public static final String ENV_KEY_JANTJE_ADDITIONAL_C_COMPILE_OPTIONS = ENV_KEY_JANTJE_START + "EXTRA.C.COMPILE";

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,4 +902,11 @@ private static void myCopy(URL url, File localFile) {
902902
}
903903
}
904904

905+
public static void onlyKeepLatestPlatforms() {
906+
List<Package> allPackages = getPackages();
907+
for (Package curPackage : allPackages) {
908+
curPackage.onlyKeepLatestPlatforms();
909+
}
910+
}
911+
905912
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,13 @@ public int compareTo(Package other) {
163163
return this.name.compareTo(other.name);
164164
}
165165

166+
public void onlyKeepLatestPlatforms() {
167+
Collection<ArduinoPlatform> latestPlatforms = getLatestPlatforms();
168+
for (ArduinoPlatform curplatform : this.platforms) {
169+
if (!latestPlatforms.contains(curplatform)) {
170+
curplatform.remove(null);
171+
}
172+
}
173+
}
174+
166175
}

io.sloeber.core/src/io/sloeber/core/tools/uploaders/SSHUpload.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import cc.arduino.packages.ssh.SSHPwdSetup;
2121
import io.sloeber.core.api.PasswordManager;
2222
import io.sloeber.core.common.Common;
23-
import io.sloeber.core.common.Const;
2423

2524
public class SSHUpload implements IRealUpload {
2625

@@ -87,7 +86,7 @@ public boolean uploadUsingPreferences(IFile hexFile, boolean usingProgrammer, IP
8786

8887
} catch (JSchException e) {
8988
String message = e.getMessage();
90-
String errormessage = Const.EMPTY_STRING;
89+
String errormessage = new String();
9190
if (Messages.Upload_auth_cancel.equals(message) || Messages.Upload_auth_fail.equals(message)) {
9291
errormessage = new String(Messages.Upload_error_auth_fail) + this.myHost;
9392
// TODO add to ask if if the user wants to remove the password

io.sloeber.ui/src/io/sloeber/ui/preferences/ThirdPartyHardwareSelectionPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public boolean performOk() {
4444
@Override
4545
protected void performDefaults() {
4646
super.performDefaults();
47-
this.urlsText.setText(BoardsManager.getBoardsPackageURLs());
47+
this.urlsText.setText(BoardsManager.getDefaultBoardsPackageURLs());
4848
}
4949

5050
@Override

0 commit comments

Comments
 (0)