Skip to content

Commit 43d9c6d

Browse files
author
jantje
committed
Handle multiple versions better (use latest) and report the situation
1 parent 36be536 commit 43d9c6d

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

io.sloeber.core/src/io/sloeber/core/tools/Libraries.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,15 @@ public static Map<String, IPath> findAllArduinoManagerLibraries() {
108108

109109
String[] versions = Lib_root.toFile().list();
110110
if (versions != null) {
111-
if (versions.length == 1) {// There can only be 1
111+
if (versions.length == 1) {// There should only be 1
112112
// version of a lib
113113
ret.put(curLib, Lib_root.append(versions[0]));
114+
} else {// If there is more than 1 take the latest and
115+
// drop a warning
116+
int highestVersion = Version.getHighestVersionn(versions);
117+
ret.put(curLib, Lib_root.append(versions[highestVersion]));
118+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,
119+
Messages.MultipleVersionsOfLib.replace("${LIB}", curLib))); //$NON-NLS-1$
114120
}
115121
}
116122
}

io.sloeber.core/src/io/sloeber/core/tools/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
public class Messages extends NLS {
66
private static final String BUNDLE_NAME = "io.sloeber.core.tools.messages"; //$NON-NLS-1$
7+
public static String MultipleVersionsOfLib;
78
public static String Boards_Failed_to_read_boards;
89
public static String Boards_Get_menu_item_name_from_id_did_not_find;
910
public static String Boards_name;

io.sloeber.core/src/io/sloeber/core/tools/Version.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,25 @@ public static int compare(String version1, String version2) {
5555
return 0;
5656
}
5757

58+
/**
59+
* Given a list of version strings returns the index of the highest version
60+
* If the highest version is multiple times in the list the result will
61+
* point to one of those but the result may be different for each call
62+
*
63+
* @param versions
64+
* a string list of version numbers
65+
*
66+
* @return the index to the highest version
67+
*/
68+
public static int getHighestVersionn(String[] versions) {
69+
int returnIndex = 0;
70+
for (int curVersion = 1; curVersion < versions.length; curVersion++) {
71+
if (compare(versions[returnIndex], versions[curVersion]) == -1) {
72+
returnIndex = curVersion;
73+
}
74+
75+
}
76+
return returnIndex;
77+
}
78+
5879
}

io.sloeber.core/src/io/sloeber/core/tools/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ import_lib_failed=Failed to import library
3030
security_login=login
3131
security_password=password
3232
getMenuItemIDFromMenuItemName=getMenuItemIDFromMenuItemName did not find menu item with name "${MENUITEMNAME}" for menu ID "${MENUID}" and for boardID "${BOARDID}"!
33+
MultipleVersionsOfLib=Multiple versions of Library ${LIB} exist on disk. This is not supported.

0 commit comments

Comments
 (0)