mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
Moved install-related fields out of DownloadableContribution
Those fields have a slightly different meaning on each object that extends DownloadableContribution and having them grouped in DownloadableContribution only increase confusion in change of a (very) tiny code reuse. Moreover: - the `readOnly` field has been renamed to `builtIn` - predicates have been replaced by lambdas - DownloadableContributionBuiltInAtTheBottomComparator has been replaced with a singleton instance
This commit is contained in:
parent
0042a30c81
commit
b3d01d8281
@ -29,9 +29,6 @@
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.contributions.filters.BuiltInPredicate;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.packages.ContributedPackage;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import processing.app.Base;
|
||||
import processing.app.BaseNoGui;
|
||||
@ -39,8 +36,8 @@ import processing.app.I18n;
|
||||
import processing.app.PreferencesData;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
@ -67,13 +64,21 @@ public class BuiltInCoreIsNewerCheck implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ContributedPlatform> contributedPlatforms = BaseNoGui.indexer.getPackages().stream().map(ContributedPackage::getPlatforms).flatMap(Collection::stream).collect(Collectors.toList());
|
||||
List<ContributedPlatform> contributedPlatforms = BaseNoGui.indexer
|
||||
.getPackages().stream() //
|
||||
.map(pack -> pack.getPlatforms()) //
|
||||
.flatMap(platfs -> platfs.stream()) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<ContributedPlatform> installedBuiltInPlatforms = contributedPlatforms.stream().filter(new InstalledPredicate()).filter(new BuiltInPredicate()).collect(Collectors.toList());
|
||||
if (installedBuiltInPlatforms.size() != 1) {
|
||||
Optional<ContributedPlatform> mayInstalledBuiltIn = contributedPlatforms
|
||||
.stream() //
|
||||
.filter(p -> p.isInstalled()) //
|
||||
.filter(p -> p.isBuiltIn()) //
|
||||
.findFirst();
|
||||
if (!mayInstalledBuiltIn.isPresent()) {
|
||||
return;
|
||||
}
|
||||
final ContributedPlatform installedBuiltIn = installedBuiltInPlatforms.get(0);
|
||||
final ContributedPlatform installedBuiltIn = mayInstalledBuiltIn.get();
|
||||
|
||||
ContributedPlatform installedNotBuiltIn = BaseNoGui.indexer.getInstalled(installedBuiltIn.getParentPackage().getName(), installedBuiltIn.getArchitecture());
|
||||
if (installedNotBuiltIn == null) {
|
||||
|
@ -34,8 +34,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.packages.ContributedPackage;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
|
||||
@ -72,10 +70,9 @@ public class ContributedPlatformReleases {
|
||||
|
||||
public ContributedPlatform getInstalled() {
|
||||
List<ContributedPlatform> installedReleases = releases.stream()
|
||||
.filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collections
|
||||
.sort(installedReleases,
|
||||
new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
.filter(p -> p.isInstalled()) //
|
||||
.collect(Collectors.toList());
|
||||
Collections.sort(installedReleases, ContributedPlatform.BUILTIN_AS_LAST);
|
||||
|
||||
if (installedReleases.isEmpty()) {
|
||||
return null;
|
||||
|
@ -42,8 +42,6 @@ import javax.swing.JTable;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContributionVersionComparator;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.filters.BuiltInPredicate;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.ui.InstallerTableCell;
|
||||
import cc.arduino.utils.ReverseComparator;
|
||||
@ -86,11 +84,13 @@ public class ContributedPlatformTableCellEditor extends InstallerTableCell {
|
||||
final ContributedPlatform installed = value.getInstalled();
|
||||
|
||||
List<ContributedPlatform> releases = new LinkedList<>(value.releases);
|
||||
List<ContributedPlatform> uninstalledReleases = releases.stream()
|
||||
.filter(new InstalledPredicate().negate()).collect(Collectors.toList());
|
||||
List<ContributedPlatform> uninstalledReleases = releases.stream() //
|
||||
.filter(p -> !p.isInstalled()) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<ContributedPlatform> installedBuiltIn = releases.stream()
|
||||
.filter(new InstalledPredicate()).filter(new BuiltInPredicate())
|
||||
List<ContributedPlatform> installedBuiltIn = releases.stream() //
|
||||
.filter(p -> p.isInstalled()) //
|
||||
.filter(p -> p.isBuiltIn()) //
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (installed != null && !installedBuiltIn.contains(installed)) {
|
||||
|
@ -170,7 +170,7 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
|
||||
upgradable = false;
|
||||
} else {
|
||||
installable = false;
|
||||
removable = !installed.isReadOnly() && !hasBuiltInRelease;
|
||||
removable = !installed.isBuiltIn() && !hasBuiltInRelease;
|
||||
upgradable = new DownloadableContributionVersionComparator()
|
||||
.compare(selected, installed) > 0;
|
||||
}
|
||||
@ -187,7 +187,7 @@ public class ContributedPlatformTableCellJPanel extends JPanel {
|
||||
|
||||
String desc = "<html><body>";
|
||||
desc += "<b>" + selected.getName() + "</b>";
|
||||
if (installed != null && installed.isReadOnly()) {
|
||||
if (installed != null && installed.isBuiltIn()) {
|
||||
desc += " Built-In ";
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
@Override
|
||||
protected void onInstall(ContributedPlatform selected,
|
||||
ContributedPlatform installed) {
|
||||
if (selected.isReadOnly()) {
|
||||
if (selected.isBuiltIn()) {
|
||||
onRemovePressed(installed, false);
|
||||
} else {
|
||||
onInstallPressed(selected, installed);
|
||||
@ -166,7 +166,7 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
List<String> errors = new LinkedList<>();
|
||||
try {
|
||||
setProgressVisible(true, tr("Installing..."));
|
||||
if (platformToRemove != null && !platformToRemove.isReadOnly()) {
|
||||
if (platformToRemove != null && !platformToRemove.isBuiltIn()) {
|
||||
errors.addAll(installer.remove(platformToRemove));
|
||||
}
|
||||
errors.addAll(installer.install(platformToInstall, this::setProgress));
|
||||
|
@ -320,11 +320,11 @@ public class Base {
|
||||
|
||||
ContributedPlatform installed = indexer.getInstalled(boardToInstallParts[0], boardToInstallParts[1]);
|
||||
|
||||
if (!selected.isReadOnly()) {
|
||||
if (!selected.isBuiltIn()) {
|
||||
contributionInstaller.install(selected, progressListener);
|
||||
}
|
||||
|
||||
if (installed != null && !installed.isReadOnly()) {
|
||||
if (installed != null && !installed.isBuiltIn()) {
|
||||
contributionInstaller.remove(installed);
|
||||
}
|
||||
|
||||
|
@ -35,13 +35,6 @@ import java.io.File;
|
||||
|
||||
public abstract class DownloadableContribution {
|
||||
|
||||
// XXX: maybe installed fields should not be here but in UserLibrary and ContributedPlatform?
|
||||
private boolean installed;
|
||||
private File installedFolder;
|
||||
|
||||
private boolean downloaded;
|
||||
private File downloadedFile;
|
||||
|
||||
public abstract String getUrl();
|
||||
|
||||
public abstract String getVersion();
|
||||
@ -52,6 +45,8 @@ public abstract class DownloadableContribution {
|
||||
|
||||
public abstract String getArchiveFileName();
|
||||
|
||||
private boolean downloaded;
|
||||
|
||||
public boolean isDownloaded() {
|
||||
return downloaded;
|
||||
}
|
||||
@ -60,6 +55,8 @@ public abstract class DownloadableContribution {
|
||||
this.downloaded = downloaded;
|
||||
}
|
||||
|
||||
private File downloadedFile;
|
||||
|
||||
public File getDownloadedFile() {
|
||||
return downloadedFile;
|
||||
}
|
||||
@ -68,32 +65,6 @@ public abstract class DownloadableContribution {
|
||||
this.downloadedFile = downloadedFile;
|
||||
}
|
||||
|
||||
public boolean isInstalled() {
|
||||
return installed;
|
||||
}
|
||||
|
||||
public void setInstalled(boolean installed) {
|
||||
this.installed = installed;
|
||||
}
|
||||
|
||||
public File getInstalledFolder() {
|
||||
return installedFolder;
|
||||
}
|
||||
|
||||
public void setInstalledFolder(File installedFolder) {
|
||||
this.installedFolder = installedFolder;
|
||||
}
|
||||
|
||||
private boolean readOnly;
|
||||
|
||||
public boolean isReadOnly() {
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
public void setReadOnly(boolean readOnly) {
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
public String getParsedVersion() {
|
||||
Version version = VersionHelper.valueOf(getVersion());
|
||||
if (version == null) {
|
||||
@ -101,13 +72,4 @@ public abstract class DownloadableContribution {
|
||||
}
|
||||
return version.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String res = "";
|
||||
if (installed) {
|
||||
res += "installed on " + installedFolder.getAbsolutePath() + " (" + getSize() + " bytes)";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class BuiltInPredicate implements Predicate<DownloadableContribution> {
|
||||
|
||||
@Override
|
||||
public boolean test(DownloadableContribution input) {
|
||||
return input.isReadOnly();
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class InstalledPredicate implements Predicate<DownloadableContribution> {
|
||||
|
||||
@Override
|
||||
public boolean test(DownloadableContribution input) {
|
||||
return input.isInstalled();
|
||||
}
|
||||
|
||||
}
|
@ -32,6 +32,7 @@ package cc.arduino.contributions.packages;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class ContributedPlatform extends DownloadableContribution {
|
||||
@ -53,6 +54,42 @@ public abstract class ContributedPlatform extends DownloadableContribution {
|
||||
|
||||
public abstract ContributedHelp getHelp();
|
||||
|
||||
private boolean installed;
|
||||
|
||||
public boolean isInstalled() {
|
||||
return installed;
|
||||
}
|
||||
|
||||
public void setInstalled(boolean installed) {
|
||||
this.installed = installed;
|
||||
}
|
||||
|
||||
private File installedFolder;
|
||||
|
||||
public File getInstalledFolder() {
|
||||
return installedFolder;
|
||||
}
|
||||
|
||||
public void setInstalledFolder(File installedFolder) {
|
||||
this.installedFolder = installedFolder;
|
||||
}
|
||||
|
||||
private boolean builtIn;
|
||||
|
||||
public boolean isBuiltIn() {
|
||||
return builtIn;
|
||||
}
|
||||
|
||||
public void setBuiltIn(boolean builtIn) {
|
||||
this.builtIn = builtIn;
|
||||
}
|
||||
|
||||
public static final Comparator<ContributedPlatform> BUILTIN_AS_LAST = (x, y) -> {
|
||||
int px = x.isBuiltIn() ? 1 : -1;
|
||||
int py = y.isBuiltIn() ? 1 : -1;
|
||||
return py - px;
|
||||
};
|
||||
|
||||
private Map<ContributedToolReference, ContributedTool> resolvedToolReferences;
|
||||
|
||||
private ContributedPackage parentPackage;
|
||||
|
@ -32,6 +32,7 @@ package cc.arduino.contributions.packages;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import processing.app.Platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ContributedTool {
|
||||
@ -42,6 +43,36 @@ public abstract class ContributedTool {
|
||||
|
||||
public abstract List<HostDependentDownloadableContribution> getSystems();
|
||||
|
||||
private boolean installed;
|
||||
|
||||
public boolean isInstalled() {
|
||||
return installed;
|
||||
}
|
||||
|
||||
public void setInstalled(boolean installed) {
|
||||
this.installed = installed;
|
||||
}
|
||||
|
||||
private File installedFolder;
|
||||
|
||||
public File getInstalledFolder() {
|
||||
return installedFolder;
|
||||
}
|
||||
|
||||
public void setInstalledFolder(File installedFolder) {
|
||||
this.installedFolder = installedFolder;
|
||||
}
|
||||
|
||||
private boolean builtIn;
|
||||
|
||||
public boolean isBuiltIn() {
|
||||
return builtIn;
|
||||
}
|
||||
|
||||
public void setBuiltIn(boolean builtIn) {
|
||||
this.builtIn = builtIn;
|
||||
}
|
||||
|
||||
private ContributedPackage contributedPackage;
|
||||
|
||||
public ContributedPackage getPackage() {
|
||||
|
@ -85,7 +85,7 @@ public class ContributionInstaller {
|
||||
throw new Exception(format(tr("Tool {0} is not available for your operating system."), tool.getName()));
|
||||
}
|
||||
// Download the tool if it's not installed or it's a built-in tool
|
||||
if (!downloadable.isInstalled() || downloadable.isReadOnly()) {
|
||||
if (!tool.isInstalled() || tool.isBuiltIn()) {
|
||||
tools.add(tool);
|
||||
}
|
||||
}
|
||||
@ -121,11 +121,11 @@ public class ContributionInstaller {
|
||||
// once everything is successfully unpacked. If the operation fails remove
|
||||
// all the temporary folders and abort installation.
|
||||
|
||||
List<Map.Entry<ContributedToolReference, ContributedTool>> resolvedToolReferences = contributedPlatform.getResolvedToolReferences().entrySet()
|
||||
.stream()
|
||||
.filter((entry) -> !entry.getValue().getDownloadableContribution(platform).isInstalled()
|
||||
|| entry.getValue().getDownloadableContribution(platform).isReadOnly())
|
||||
.collect(Collectors.toList());
|
||||
List<Map.Entry<ContributedToolReference, ContributedTool>> resolvedToolReferences = contributedPlatform
|
||||
.getResolvedToolReferences().entrySet().stream()
|
||||
.filter((entry) -> !entry.getValue().isInstalled()
|
||||
|| entry.getValue().isBuiltIn())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
int i = 1;
|
||||
for (Map.Entry<ContributedToolReference, ContributedTool> entry : resolvedToolReferences) {
|
||||
@ -133,10 +133,11 @@ public class ContributionInstaller {
|
||||
progressListener.onProgress(progress);
|
||||
i++;
|
||||
ContributedTool tool = entry.getValue();
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution(platform);
|
||||
Path destFolder = Paths.get(BaseNoGui.indexer.getPackagesFolder().getAbsolutePath(), entry.getKey().getPackager(), "tools", tool.getName(), tool.getVersion());
|
||||
|
||||
Files.createDirectories(destFolder);
|
||||
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution(platform);
|
||||
assert toolContrib.getDownloadedFile() != null;
|
||||
new ArchiveExtractor(platform).extract(toolContrib.getDownloadedFile(), destFolder.toFile(), 1);
|
||||
try {
|
||||
@ -144,8 +145,8 @@ public class ContributionInstaller {
|
||||
} catch (IOException e) {
|
||||
errors.add(tr("Error running post install script"));
|
||||
}
|
||||
toolContrib.setInstalled(true);
|
||||
toolContrib.setInstalledFolder(destFolder.toFile());
|
||||
tool.setInstalled(true);
|
||||
tool.setInstalledFolder(destFolder.toFile());
|
||||
progress.stepDone();
|
||||
}
|
||||
|
||||
@ -234,7 +235,7 @@ public class ContributionInstaller {
|
||||
}
|
||||
|
||||
public synchronized List<String> remove(ContributedPlatform contributedPlatform) {
|
||||
if (contributedPlatform == null || contributedPlatform.isReadOnly()) {
|
||||
if (contributedPlatform == null || contributedPlatform.isBuiltIn()) {
|
||||
return new LinkedList<>();
|
||||
}
|
||||
List<String> errors = new LinkedList<>();
|
||||
@ -251,15 +252,14 @@ public class ContributionInstaller {
|
||||
continue;
|
||||
|
||||
// Do not remove built-in tools
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution(platform);
|
||||
if (toolContrib.isReadOnly())
|
||||
if (tool.isBuiltIn())
|
||||
continue;
|
||||
|
||||
// Ok, delete the tool
|
||||
File destFolder = toolContrib.getInstalledFolder();
|
||||
File destFolder = tool.getInstalledFolder();
|
||||
FileUtils.recursiveDelete(destFolder);
|
||||
toolContrib.setInstalled(false);
|
||||
toolContrib.setInstalledFolder(null);
|
||||
tool.setInstalled(false);
|
||||
tool.setInstalledFolder(null);
|
||||
|
||||
// We removed the version folder (.../tools/TOOL_NAME/VERSION)
|
||||
// now try to remove the containing TOOL_NAME folder
|
||||
|
@ -29,9 +29,7 @@
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
||||
import cc.arduino.contributions.filters.DownloadableContributionWithVersionPredicate;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.packages.filters.PlatformArchitecturePredicate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -84,7 +82,9 @@ public abstract class ContributionsIndex {
|
||||
}
|
||||
|
||||
public List<ContributedPlatform> getInstalledPlatforms() {
|
||||
return getPlatforms().stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
return getPlatforms().stream() //
|
||||
.filter(p -> p.isInstalled()) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ContributedPlatform getInstalledPlatform(String packageName, String platformArch) {
|
||||
@ -92,8 +92,10 @@ public abstract class ContributionsIndex {
|
||||
if (platforms == null) {
|
||||
return null;
|
||||
}
|
||||
List<ContributedPlatform> installedPlatforms = platforms.stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collections.sort(installedPlatforms, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
List<ContributedPlatform> installedPlatforms = platforms.stream() //
|
||||
.filter(p -> p.isInstalled()) //
|
||||
.collect(Collectors.toList());
|
||||
Collections.sort(installedPlatforms, ContributedPlatform.BUILTIN_AS_LAST);
|
||||
|
||||
if (installedPlatforms.isEmpty()) {
|
||||
return null;
|
||||
|
@ -31,11 +31,8 @@ package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.Constants;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
||||
import cc.arduino.contributions.SignatureVerificationFailedException;
|
||||
import cc.arduino.contributions.SignatureVerifier;
|
||||
import cc.arduino.contributions.filters.BuiltInPredicate;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
@ -240,9 +237,9 @@ public class ContributionsIndexer {
|
||||
PreferencesMap toolsVersion = new PreferencesMap(versionsFile).subTree(pack.getName());
|
||||
for (String name : toolsVersion.keySet()) {
|
||||
String version = toolsVersion.get(name);
|
||||
DownloadableContribution tool = syncToolWithFilesystem(pack, toolFolder, name, version);
|
||||
ContributedTool tool = syncToolWithFilesystem(pack, toolFolder, name, version);
|
||||
if (tool != null)
|
||||
tool.setReadOnly(true);
|
||||
tool.setBuiltIn(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,7 +252,7 @@ public class ContributionsIndexer {
|
||||
String version = new PreferencesMap(platformTxt).get("version");
|
||||
ContributedPlatform p = syncHardwareWithFilesystem(pack, platformFolder, platformFolder.getName(), version);
|
||||
if (p != null) {
|
||||
p.setReadOnly(true);
|
||||
p.setBuiltIn(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -301,7 +298,7 @@ public class ContributionsIndexer {
|
||||
}
|
||||
}
|
||||
|
||||
private DownloadableContribution syncToolWithFilesystem(ContributedPackage pack, File installationFolder, String toolName, String version) {
|
||||
private ContributedTool syncToolWithFilesystem(ContributedPackage pack, File installationFolder, String toolName, String version) {
|
||||
ContributedTool tool = pack.findTool(toolName, version);
|
||||
if (tool == null) {
|
||||
tool = pack.findResolvedTool(toolName, version);
|
||||
@ -314,17 +311,17 @@ public class ContributionsIndexer {
|
||||
System.err.println(tool + " seems to have no downloadable contributions for your operating system, but it is installed in\n" + installationFolder);
|
||||
return null;
|
||||
}
|
||||
contrib.setInstalled(true);
|
||||
contrib.setInstalledFolder(installationFolder);
|
||||
contrib.setReadOnly(false);
|
||||
return contrib;
|
||||
tool.setInstalled(true);
|
||||
tool.setInstalledFolder(installationFolder);
|
||||
tool.setBuiltIn(false);
|
||||
return tool;
|
||||
}
|
||||
|
||||
private ContributedPlatform syncHardwareWithFilesystem(ContributedPackage pack, File installationFolder, String architecture, String version) {
|
||||
ContributedPlatform p = pack.findPlatform(architecture, version);
|
||||
if (p != null) {
|
||||
p.setInstalled(true);
|
||||
p.setReadOnly(false);
|
||||
p.setBuiltIn(false);
|
||||
p.setInstalledFolder(installationFolder);
|
||||
}
|
||||
return p;
|
||||
@ -345,8 +342,10 @@ public class ContributionsIndexer {
|
||||
for (ContributedPackage aPackage : index.getPackages()) {
|
||||
ContributedTargetPackage targetPackage = new ContributedTargetPackage(aPackage.getName());
|
||||
|
||||
List<ContributedPlatform> platforms = aPackage.getPlatforms().stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collections.sort(platforms, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
List<ContributedPlatform> platforms = aPackage.getPlatforms().stream() //
|
||||
.filter(p -> p.isInstalled()) //
|
||||
.collect(Collectors.toList());
|
||||
Collections.sort(platforms, ContributedPlatform.BUILTIN_AS_LAST);
|
||||
|
||||
for (ContributedPlatform p : platforms) {
|
||||
String arch = p.getArchitecture();
|
||||
@ -381,7 +380,7 @@ public class ContributionsIndexer {
|
||||
if (platformToIgnore.equals(p)) {
|
||||
continue;
|
||||
}
|
||||
if (!p.isInstalled() || p.isReadOnly()) {
|
||||
if (!p.isInstalled() || p.isBuiltIn()) {
|
||||
continue;
|
||||
}
|
||||
for (ContributedTool requiredTool : p.getResolvedTools()) {
|
||||
@ -399,12 +398,16 @@ public class ContributionsIndexer {
|
||||
return tools;
|
||||
}
|
||||
for (ContributedPackage pack : index.getPackages()) {
|
||||
Collection<ContributedPlatform> platforms = pack.getPlatforms().stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collection<ContributedPlatform> platforms = pack.getPlatforms().stream() //
|
||||
.filter(p -> p.isInstalled()) //
|
||||
.collect(Collectors.toList());
|
||||
Map<String, List<ContributedPlatform>> platformsByName = platforms.stream().collect(Collectors.groupingBy(ContributedPlatform::getName));
|
||||
|
||||
platformsByName.forEach((platformName, platformsWithName) -> {
|
||||
if (platformsWithName.size() > 1) {
|
||||
platformsWithName = platformsWithName.stream().filter(new BuiltInPredicate().negate()).collect(Collectors.toList());
|
||||
platformsWithName = platformsWithName.stream() //
|
||||
.filter(p -> !p.isBuiltIn()) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
for (ContributedPlatform p : platformsWithName) {
|
||||
tools.addAll(p.getResolvedTools());
|
||||
|
@ -183,7 +183,7 @@ public class BaseNoGui {
|
||||
|
||||
String prefix = "runtime.tools.";
|
||||
for (ContributedTool tool : requiredTools) {
|
||||
File folder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
|
||||
File folder = tool.getInstalledFolder();
|
||||
if (folder == null) {
|
||||
continue;
|
||||
}
|
||||
@ -693,7 +693,7 @@ public class BaseNoGui {
|
||||
|
||||
Map<String, String> latestVersions = new HashMap<>();
|
||||
for (ContributedTool tool : installedTools) {
|
||||
File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
|
||||
File installedFolder = tool.getInstalledFolder();
|
||||
String toolPath;
|
||||
if (installedFolder != null) {
|
||||
toolPath = installedFolder.getAbsolutePath();
|
||||
|
Loading…
x
Reference in New Issue
Block a user