mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
If a package is already defined, don't replace it with the one found (for example) in sketchbook/hardware, but merge their contents. Fixes #3851
This commit is contained in:
parent
469bc4ad6e
commit
b82aebd99a
@ -34,6 +34,7 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
|
||||
|
||||
public class BaseNoGui {
|
||||
|
||||
@ -674,12 +675,16 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static protected void loadHardware(File folder) {
|
||||
if (!folder.isDirectory()) return;
|
||||
if (!folder.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String list[] = folder.list(new OnlyDirs());
|
||||
|
||||
// if a bad folder or something like that, this might come back null
|
||||
if (list == null) return;
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// alphabetize list, since it's not always alpha order
|
||||
// replaced hella slow bubble sort with this feller for 0093
|
||||
@ -687,12 +692,19 @@ public class BaseNoGui {
|
||||
|
||||
for (String target : list) {
|
||||
// Skip reserved 'tools' folder.
|
||||
if (target.equals("tools"))
|
||||
if (target.equals("tools")) {
|
||||
continue;
|
||||
}
|
||||
File subfolder = new File(folder, target);
|
||||
|
||||
|
||||
TargetPackage targetPackage;
|
||||
if (packages.containsKey(target)) {
|
||||
targetPackage = packages.get(target);
|
||||
} else {
|
||||
targetPackage = new LegacyTargetPackage(target);
|
||||
}
|
||||
try {
|
||||
packages.put(target, new LegacyTargetPackage(target, subfolder));
|
||||
loadTargetPackage(targetPackage, subfolder);
|
||||
} catch (TargetPlatformException e) {
|
||||
System.out.println("WARNING: Error loading hardware folder " + new File(folder, target));
|
||||
System.out.println(" " + e.getMessage());
|
||||
@ -700,6 +712,30 @@ public class BaseNoGui {
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadTargetPackage(TargetPackage targetPackage, File _folder) throws TargetPlatformException {
|
||||
File[] folders = _folder.listFiles(ONLY_DIRS);
|
||||
if (folders == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (File subFolder : folders) {
|
||||
if (!subFolder.exists() || !subFolder.canRead()) {
|
||||
continue;
|
||||
}
|
||||
String arch = subFolder.getName();
|
||||
try {
|
||||
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, targetPackage);
|
||||
targetPackage.getPlatforms().put(arch, platform);
|
||||
} catch (TargetPlatformException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (targetPackage.getPlatforms().size() == 0) {
|
||||
throw new TargetPlatformException(I18n.format(tr("No valid hardware definitions found in folder {0}."), _folder.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the contents of a file as a string.
|
||||
*/
|
||||
|
@ -20,46 +20,18 @@
|
||||
*/
|
||||
package processing.app.debug;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.I18n;
|
||||
|
||||
public class LegacyTargetPackage implements TargetPackage {
|
||||
|
||||
private String id;
|
||||
private Map<String, TargetPlatform> platforms;
|
||||
private final String id;
|
||||
private final Map<String, TargetPlatform> platforms;
|
||||
|
||||
public LegacyTargetPackage(String _id, File _folder) throws TargetPlatformException {
|
||||
public LegacyTargetPackage(String _id) {
|
||||
id = _id;
|
||||
platforms = new LinkedHashMap<String, TargetPlatform>();
|
||||
|
||||
File[] folders = _folder.listFiles(ONLY_DIRS);
|
||||
if (folders == null)
|
||||
return;
|
||||
|
||||
for (File subFolder : folders) {
|
||||
if (!subFolder.exists() || !subFolder.canRead())
|
||||
continue;
|
||||
String arch = subFolder.getName();
|
||||
try {
|
||||
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, this);
|
||||
platforms.put(arch, platform);
|
||||
} catch (TargetPlatformException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (platforms.size() == 0) {
|
||||
throw new TargetPlatformException(I18n
|
||||
.format(tr("No valid hardware definitions found in folder {0}."),
|
||||
_folder.getName()));
|
||||
}
|
||||
platforms = new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user