Skip to content

Commit ae4f0c0

Browse files
Federico Fissoresandeepmistry
Federico Fissore
authored andcommitted
If a package is already defined, don't replace it with the one found (for example) in sketchbook/hardware, but merge their contents. Fixes arduino#3851
1 parent 64765e5 commit ae4f0c0

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

arduino-core/src/processing/app/BaseNoGui.java

+41-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.logging.Logger;
3535

3636
import static processing.app.I18n.tr;
37+
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
3738

3839
public class BaseNoGui {
3940

@@ -674,32 +675,67 @@ static public boolean isSanitaryName(String name) {
674675
}
675676

676677
static protected void loadHardware(File folder) {
677-
if (!folder.isDirectory()) return;
678+
if (!folder.isDirectory()) {
679+
return;
680+
}
678681

679682
String list[] = folder.list(new OnlyDirs());
680683

681684
// if a bad folder or something like that, this might come back null
682-
if (list == null) return;
685+
if (list == null) {
686+
return;
687+
}
683688

684689
// alphabetize list, since it's not always alpha order
685690
// replaced hella slow bubble sort with this feller for 0093
686691
Arrays.sort(list, String.CASE_INSENSITIVE_ORDER);
687692

688693
for (String target : list) {
689694
// Skip reserved 'tools' folder.
690-
if (target.equals("tools"))
695+
if (target.equals("tools")) {
691696
continue;
697+
}
692698
File subfolder = new File(folder, target);
693-
699+
700+
TargetPackage targetPackage;
701+
if (packages.containsKey(target)) {
702+
targetPackage = packages.get(target);
703+
} else {
704+
targetPackage = new LegacyTargetPackage(target);
705+
}
694706
try {
695-
packages.put(target, new LegacyTargetPackage(target, subfolder));
707+
loadTargetPackage(targetPackage, subfolder);
696708
} catch (TargetPlatformException e) {
697709
System.out.println("WARNING: Error loading hardware folder " + new File(folder, target));
698710
System.out.println(" " + e.getMessage());
699711
}
700712
}
701713
}
702714

715+
private static void loadTargetPackage(TargetPackage targetPackage, File _folder) throws TargetPlatformException {
716+
File[] folders = _folder.listFiles(ONLY_DIRS);
717+
if (folders == null) {
718+
return;
719+
}
720+
721+
for (File subFolder : folders) {
722+
if (!subFolder.exists() || !subFolder.canRead()) {
723+
continue;
724+
}
725+
String arch = subFolder.getName();
726+
try {
727+
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, targetPackage);
728+
targetPackage.getPlatforms().put(arch, platform);
729+
} catch (TargetPlatformException e) {
730+
System.err.println(e.getMessage());
731+
}
732+
}
733+
734+
if (targetPackage.getPlatforms().size() == 0) {
735+
throw new TargetPlatformException(I18n.format(tr("No valid hardware definitions found in folder {0}."), _folder.getName()));
736+
}
737+
}
738+
703739
/**
704740
* Grab the contents of a file as a string.
705741
*/

arduino-core/src/processing/app/debug/LegacyTargetPackage.java

+4-32
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,18 @@
2020
*/
2121
package processing.app.debug;
2222

23-
import static processing.app.I18n.tr;
24-
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
25-
26-
import java.io.File;
2723
import java.util.Collection;
2824
import java.util.LinkedHashMap;
2925
import java.util.Map;
3026

31-
import processing.app.I18n;
32-
3327
public class LegacyTargetPackage implements TargetPackage {
3428

35-
private String id;
36-
private Map<String, TargetPlatform> platforms;
29+
private final String id;
30+
private final Map<String, TargetPlatform> platforms;
3731

38-
public LegacyTargetPackage(String _id, File _folder) throws TargetPlatformException {
32+
public LegacyTargetPackage(String _id) {
3933
id = _id;
40-
platforms = new LinkedHashMap<String, TargetPlatform>();
41-
42-
File[] folders = _folder.listFiles(ONLY_DIRS);
43-
if (folders == null)
44-
return;
45-
46-
for (File subFolder : folders) {
47-
if (!subFolder.exists() || !subFolder.canRead())
48-
continue;
49-
String arch = subFolder.getName();
50-
try {
51-
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, this);
52-
platforms.put(arch, platform);
53-
} catch (TargetPlatformException e) {
54-
System.err.println(e.getMessage());
55-
}
56-
}
57-
58-
if (platforms.size() == 0) {
59-
throw new TargetPlatformException(I18n
60-
.format(tr("No valid hardware definitions found in folder {0}."),
61-
_folder.getName()));
62-
}
34+
platforms = new LinkedHashMap<>();
6335
}
6436

6537
@Override

0 commit comments

Comments
 (0)