mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Bundled core is again inside the hardware folder.
Fixed a handful of glitches when dealing with multiple installed cores
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class DownloadableContributionBuiltInAtTheBottomComparator implements Comparator<DownloadableContribution> {
|
||||
@Override
|
||||
public int compare(DownloadableContribution p1, DownloadableContribution p2) {
|
||||
if (p1.isReadOnly() == p2.isReadOnly()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return p1.isReadOnly() ? 1 : -1;
|
||||
}
|
||||
}
|
@ -47,8 +47,8 @@ public class VersionComparator implements Comparator<String> {
|
||||
if (b == null)
|
||||
return 1;
|
||||
|
||||
Version versionA = valueOf(a);
|
||||
Version versionB = valueOf(b);
|
||||
Version versionA = VersionHelper.valueOf(a);
|
||||
Version versionB = VersionHelper.valueOf(b);
|
||||
|
||||
return versionA.compareTo(versionB);
|
||||
}
|
||||
@ -65,26 +65,10 @@ public class VersionComparator implements Comparator<String> {
|
||||
return true;
|
||||
}
|
||||
|
||||
Version versionA = valueOf(a);
|
||||
Version versionB = valueOf(b);
|
||||
Version versionA = VersionHelper.valueOf(a);
|
||||
Version versionB = VersionHelper.valueOf(b);
|
||||
|
||||
return versionA.greaterThan(versionB);
|
||||
}
|
||||
|
||||
private Version valueOf(String ver) {
|
||||
if (ver.endsWith("b")) {
|
||||
ver = ver.substring(0, ver.lastIndexOf("b")) + ".1";
|
||||
}
|
||||
String[] verParts = ver.split("\\.");
|
||||
if (verParts.length < 3) {
|
||||
if (verParts.length == 2) {
|
||||
return Version.forIntegers(Integer.valueOf(verParts[0]), Integer.valueOf(verParts[1]));
|
||||
} else {
|
||||
return Version.forIntegers(Integer.valueOf(verParts[0]));
|
||||
}
|
||||
} else {
|
||||
return Version.valueOf(ver);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
23
arduino-core/src/cc/arduino/contributions/VersionHelper.java
Normal file
23
arduino-core/src/cc/arduino/contributions/VersionHelper.java
Normal file
@ -0,0 +1,23 @@
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import com.github.zafarkhaja.semver.Version;
|
||||
|
||||
public class VersionHelper {
|
||||
|
||||
public static Version valueOf(String ver) {
|
||||
if (ver == null) {
|
||||
return null;
|
||||
}
|
||||
String[] verParts = ver.split("\\.");
|
||||
if (verParts.length < 3) {
|
||||
if (verParts.length == 2) {
|
||||
return Version.forIntegers(Integer.valueOf(verParts[0]), Integer.valueOf(verParts[1]));
|
||||
} else {
|
||||
return Version.forIntegers(Integer.valueOf(verParts[0]));
|
||||
}
|
||||
} else {
|
||||
return Version.valueOf(ver);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class BuiltInPredicate implements Predicate<DownloadableContribution> {
|
||||
|
||||
@Override
|
||||
public boolean apply(DownloadableContribution input) {
|
||||
return input.isReadOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof BuiltInPredicate;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class InstalledPredicate implements Predicate<DownloadableContribution> {
|
||||
@Override
|
||||
public boolean apply(DownloadableContribution input) {
|
||||
return input.isInstalled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof DownloadableContribution;
|
||||
}
|
||||
|
||||
}
|
@ -40,8 +40,6 @@ public abstract class ContributedLibrary extends DownloadableContribution {
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract String getVersion();
|
||||
|
||||
public abstract String getMaintainer();
|
||||
|
||||
public abstract String getAuthor();
|
||||
@ -64,16 +62,6 @@ public abstract class ContributedLibrary extends DownloadableContribution {
|
||||
|
||||
public abstract List<ContributedLibraryReference> getRequires();
|
||||
|
||||
private boolean readOnly;
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly) {
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public static final Comparator<ContributedLibrary> CASE_INSENSITIVE_ORDER = new Comparator<ContributedLibrary>() {
|
||||
@Override
|
||||
public int compare(ContributedLibrary o1, ContributedLibrary o2) {
|
||||
|
@ -37,8 +37,6 @@ public abstract class ContributedPlatform extends DownloadableContribution {
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract String getVersion();
|
||||
|
||||
public abstract String getCategory();
|
||||
|
||||
public abstract String getArchitecture();
|
||||
|
@ -73,6 +73,11 @@ public class ContributedTargetPackage implements TargetPackage {
|
||||
return platforms.get(platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlatform(TargetPlatform platform) {
|
||||
return platforms.containsKey(platform.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TargetPackage: " + getId();
|
||||
|
@ -28,21 +28,27 @@
|
||||
*/
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
||||
import cc.arduino.contributions.filters.BuiltInPredicate;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.debug.TargetPlatformException;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
|
||||
|
||||
@ -102,7 +108,47 @@ public class ContributionsIndexer {
|
||||
index = mapper.readValue(indexIn, ContributionsIndex.class);
|
||||
}
|
||||
|
||||
public void syncWithFilesystem() {
|
||||
public void syncWithFilesystem(File hardwareFolder) throws IOException {
|
||||
syncBuiltInHardwareFolder(hardwareFolder);
|
||||
|
||||
syncLocalPackagesFolder();
|
||||
}
|
||||
|
||||
public void syncBuiltInHardwareFolder(File hardwareFolder) throws IOException {
|
||||
for (File folder : hardwareFolder.listFiles(ONLY_DIRS)) {
|
||||
ContributedPackage pack = index.findPackage(folder.getName());
|
||||
if (pack != null) {
|
||||
syncBuiltInPackageWithFilesystem(pack, folder);
|
||||
|
||||
File toolsFolder = new File(hardwareFolder, "tools");
|
||||
if (toolsFolder.isDirectory()) {
|
||||
for (File toolFolder : toolsFolder.listFiles(ONLY_DIRS)) {
|
||||
File builtInToolsMetadata = new File(toolFolder, "builtin_tools_versions.txt");
|
||||
if (builtInToolsMetadata.isFile()) {
|
||||
PreferencesMap toolsMetadata = new PreferencesMap(builtInToolsMetadata).subTree(pack.getName());
|
||||
for (Map.Entry<String, String> toolMetadata : toolsMetadata.entrySet()) {
|
||||
syncToolWithFilesystem(pack, toolFolder, toolMetadata.getKey(), toolMetadata.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void syncBuiltInPackageWithFilesystem(ContributedPackage pack, File hardwareFolder) throws IOException {
|
||||
// Scan all hardware folders and mark as installed all the tools found.
|
||||
for (File platformFolder : hardwareFolder.listFiles(ONLY_DIRS)) {
|
||||
File platformTxt = new File(platformFolder, "platform.txt");
|
||||
String version = new PreferencesMap(platformTxt).get("version");
|
||||
ContributedPlatform platform = syncHardwareWithFilesystem(pack, platformFolder, platformFolder.getName(), version);
|
||||
if (platform != null) {
|
||||
platform.setReadOnly(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void syncLocalPackagesFolder() {
|
||||
if (!packagesFolder.isDirectory())
|
||||
return;
|
||||
|
||||
@ -110,8 +156,9 @@ public class ContributionsIndexer {
|
||||
// platforms found.
|
||||
for (File folder : packagesFolder.listFiles(ONLY_DIRS)) {
|
||||
ContributedPackage pack = index.findPackage(folder.getName());
|
||||
if (pack != null)
|
||||
if (pack != null) {
|
||||
syncPackageWithFilesystem(pack, folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,8 +167,9 @@ public class ContributionsIndexer {
|
||||
File hardwareFolder = new File(root, "hardware");
|
||||
if (hardwareFolder.isDirectory()) {
|
||||
for (File platformFolder : hardwareFolder.listFiles(ONLY_DIRS)) {
|
||||
for (File versionFolder : platformFolder.listFiles(ONLY_DIRS))
|
||||
syncHardwareWithFilesystem(pack, platformFolder, versionFolder);
|
||||
for (File versionFolder : platformFolder.listFiles(ONLY_DIRS)) {
|
||||
syncHardwareWithFilesystem(pack, versionFolder, platformFolder.getName(), versionFolder.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,39 +177,35 @@ public class ContributionsIndexer {
|
||||
File toolsFolder = new File(root, "tools");
|
||||
if (toolsFolder.isDirectory()) {
|
||||
for (File toolFolder : toolsFolder.listFiles(ONLY_DIRS)) {
|
||||
for (File versionFolder : toolFolder.listFiles(ONLY_DIRS))
|
||||
syncToolWithFilesystem(pack, toolFolder, versionFolder);
|
||||
for (File versionFolder : toolFolder.listFiles(ONLY_DIRS)) {
|
||||
syncToolWithFilesystem(pack, versionFolder, toolFolder.getName(), versionFolder.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void syncToolWithFilesystem(ContributedPackage pack, File toolFolder,
|
||||
File versionFolder) {
|
||||
ContributedTool tool = pack.findTool(toolFolder.getName(),
|
||||
versionFolder.getName());
|
||||
if (tool == null)
|
||||
private void syncToolWithFilesystem(ContributedPackage pack, File installationFolder, String toolName, String version) {
|
||||
ContributedTool tool = pack.findTool(toolName, version);
|
||||
if (tool == null) {
|
||||
return;
|
||||
}
|
||||
DownloadableContribution contrib = tool.getDownloadableContribution();
|
||||
if (contrib == null) {
|
||||
System.err.println(tool +
|
||||
" seems to have no downloadable contributions for your " +
|
||||
"operating system, but it is installed in\n" + versionFolder);
|
||||
System.err.println(tool + " seems to have no downloadable contributions for your operating system, but it is installed in\n" + installationFolder);
|
||||
return;
|
||||
}
|
||||
contrib.setInstalled(true);
|
||||
contrib.setInstalledFolder(versionFolder);
|
||||
contrib.setInstalledFolder(installationFolder);
|
||||
}
|
||||
|
||||
private void syncHardwareWithFilesystem(ContributedPackage pack,
|
||||
File platformFolder,
|
||||
File versionFolder) {
|
||||
String architecture = platformFolder.getName();
|
||||
String version = versionFolder.getName();
|
||||
private ContributedPlatform syncHardwareWithFilesystem(ContributedPackage pack, File installationFolder, String architecture, String version) {
|
||||
ContributedPlatform platform = pack.findPlatform(architecture, version);
|
||||
if (platform != null) {
|
||||
platform.setInstalled(true);
|
||||
platform.setInstalledFolder(versionFolder);
|
||||
platform.setReadOnly(false);
|
||||
platform.setInstalledFolder(installationFolder);
|
||||
}
|
||||
return platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -170,28 +214,29 @@ public class ContributionsIndexer {
|
||||
}
|
||||
|
||||
public List<TargetPackage> createTargetPackages() throws TargetPlatformException {
|
||||
List<TargetPackage> res = new ArrayList<TargetPackage>();
|
||||
List<TargetPackage> packages = new ArrayList<TargetPackage>();
|
||||
|
||||
for (ContributedPackage pack : index.getPackages()) {
|
||||
ContributedTargetPackage targetPackage;
|
||||
targetPackage = new ContributedTargetPackage(pack.getName());
|
||||
for (ContributedPackage aPackage : index.getPackages()) {
|
||||
ContributedTargetPackage targetPackage = new ContributedTargetPackage(aPackage.getName());
|
||||
|
||||
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||
if (!platform.isInstalled())
|
||||
continue;
|
||||
List<ContributedPlatform> platforms = new LinkedList<ContributedPlatform>(Collections2.filter(aPackage.getPlatforms(), new InstalledPredicate()));
|
||||
Collections.sort(platforms, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
|
||||
for (ContributedPlatform platform : platforms) {
|
||||
String arch = platform.getArchitecture();
|
||||
File folder = platform.getInstalledFolder();
|
||||
|
||||
TargetPlatform targetPlatform;
|
||||
targetPlatform = new ContributedTargetPlatform(arch, folder, targetPackage, index);
|
||||
targetPackage.addPlatform(targetPlatform);
|
||||
TargetPlatform targetPlatform = new ContributedTargetPlatform(arch, folder, targetPackage, index);
|
||||
if (!targetPackage.hasPlatform(targetPlatform)) {
|
||||
targetPackage.addPlatform(targetPlatform);
|
||||
}
|
||||
}
|
||||
|
||||
if (targetPackage.hasPlatforms())
|
||||
res.add(targetPackage);
|
||||
if (targetPackage.hasPlatforms()) {
|
||||
packages.add(targetPackage);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return packages;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,11 +262,21 @@ public class ContributionsIndexer {
|
||||
public Set<ContributedTool> getInstalledTools() {
|
||||
Set<ContributedTool> tools = new HashSet<ContributedTool>();
|
||||
for (ContributedPackage pack : index.getPackages()) {
|
||||
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||
if (!platform.isInstalled())
|
||||
continue;
|
||||
for (ContributedTool tool : platform.getResolvedTools()) {
|
||||
tools.add(tool);
|
||||
Collection<ContributedPlatform> platforms = Collections2.filter(pack.getPlatforms(), new InstalledPredicate());
|
||||
ImmutableListMultimap<String, ContributedPlatform> platformsByName = Multimaps.index(platforms, new Function<ContributedPlatform, String>() {
|
||||
@Override
|
||||
public String apply(ContributedPlatform contributedPlatform) {
|
||||
return contributedPlatform.getName();
|
||||
}
|
||||
});
|
||||
|
||||
for (Map.Entry<String, Collection<ContributedPlatform>> entry : platformsByName.asMap().entrySet()) {
|
||||
Collection<ContributedPlatform> platformsWithName = entry.getValue();
|
||||
if (platformsWithName.size() > 1) {
|
||||
platformsWithName = Collections2.filter(platformsWithName, Predicates.not(new BuiltInPredicate()));
|
||||
}
|
||||
for (ContributedPlatform platform : platformsWithName) {
|
||||
tools.addAll(platform.getResolvedTools());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,8 @@ public abstract class DownloadableContribution {
|
||||
|
||||
public abstract String getUrl();
|
||||
|
||||
public abstract String getVersion();
|
||||
|
||||
public abstract String getChecksum();
|
||||
|
||||
public abstract long getSize();
|
||||
@ -78,6 +80,16 @@ public abstract class DownloadableContribution {
|
||||
this.installedFolder = installedFolder;
|
||||
}
|
||||
|
||||
private boolean readOnly;
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly) {
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = "";
|
||||
|
@ -578,12 +578,11 @@ public class BaseNoGui {
|
||||
static public void initPackages() throws Exception {
|
||||
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
||||
File indexFile = indexer.getIndexFile();
|
||||
File avrCoreFolder = FileUtils.newFile(indexFile.getParentFile(), "packages", "arduino", "hardware", "avr");
|
||||
if (!indexFile.isFile() || !(avrCoreFolder.exists() && avrCoreFolder.isDirectory())) {
|
||||
File distFile = findDefaultPackageFile();
|
||||
if (distFile != null) {
|
||||
new ArchiveExtractor(getPlatform()).extract(distFile, BaseNoGui.getSettingsFolder(), 0, true);
|
||||
} else if (!indexFile.isFile()) {
|
||||
if (!indexFile.isFile()) {
|
||||
File defaultPackageJsonFile = new File(getContentFile("dist"), "package_index.json");
|
||||
if (defaultPackageJsonFile.isFile()) {
|
||||
FileUtils.copyFile(defaultPackageJsonFile, indexFile);
|
||||
} else {
|
||||
// Otherwise create an empty packages index
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
@ -598,7 +597,7 @@ public class BaseNoGui {
|
||||
}
|
||||
}
|
||||
indexer.parseIndex();
|
||||
indexer.syncWithFilesystem();
|
||||
indexer.syncWithFilesystem(getHardwareFolder());
|
||||
|
||||
packages = new HashMap<String, TargetPackage>();
|
||||
loadHardware(getHardwareFolder());
|
||||
@ -626,18 +625,6 @@ public class BaseNoGui {
|
||||
librariesIndexer.parseIndex();
|
||||
}
|
||||
|
||||
private static File findDefaultPackageFile() {
|
||||
File distFolder = getContentFile("dist");
|
||||
if (!distFolder.exists()) {
|
||||
return null;
|
||||
}
|
||||
File[] files = distFolder.listFiles(new OnlyFilesWithExtension("tar.bz2", "zip", "tar.gz", "tar"));
|
||||
if (files.length > 1) {
|
||||
throw new IllegalStateException("More than one file in " + distFolder);
|
||||
}
|
||||
return files[0];
|
||||
}
|
||||
|
||||
static protected void initPlatform() {
|
||||
try {
|
||||
Class<?> platformClass = Class.forName("processing.app.Platform");
|
||||
@ -697,7 +684,7 @@ public class BaseNoGui {
|
||||
try {
|
||||
packages.put(target, new LegacyTargetPackage(target, subfolder));
|
||||
} catch (TargetPlatformException e) {
|
||||
System.out.println("WARNING: Error loading hardware folder " + target);
|
||||
System.out.println("WARNING: Error loading hardware folder " + new File(folder, target));
|
||||
System.out.println(" " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@ -777,12 +764,9 @@ public class BaseNoGui {
|
||||
PreferencesData.removeAllKeysWithPrefix(prefix);
|
||||
|
||||
for (ContributedTool tool : indexer.getInstalledTools()) {
|
||||
String path = tool.getDownloadableContribution().getInstalledFolder()
|
||||
.getAbsolutePath();
|
||||
String toolId = tool.getName();
|
||||
PreferencesData.set(prefix + toolId + ".path", path);
|
||||
toolId += "-" + tool.getVersion();
|
||||
PreferencesData.set(prefix + toolId + ".path", path);
|
||||
String path = tool.getDownloadableContribution().getInstalledFolder().getAbsolutePath();
|
||||
PreferencesData.set(prefix + tool.getName() + ".path", path);
|
||||
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,11 @@ public class LegacyTargetPackage implements TargetPackage {
|
||||
return platforms.get(platform);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlatform(TargetPlatform platform) {
|
||||
return platforms.containsKey(platform.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
|
@ -25,12 +25,13 @@ import java.util.Map;
|
||||
|
||||
public interface TargetPackage {
|
||||
|
||||
public String getId();
|
||||
|
||||
public Map<String, TargetPlatform> getPlatforms();
|
||||
String getId();
|
||||
|
||||
public Collection<TargetPlatform> platforms();
|
||||
Map<String, TargetPlatform> getPlatforms();
|
||||
|
||||
public TargetPlatform get(String platform);
|
||||
|
||||
Collection<TargetPlatform> platforms();
|
||||
|
||||
TargetPlatform get(String platform);
|
||||
|
||||
boolean hasPlatform(TargetPlatform platform);
|
||||
}
|
||||
|
Reference in New Issue
Block a user