1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

CLI: board manager install latest if version is not specified

This commit is contained in:
Federico Fissore 2015-04-08 15:35:03 +02:00
parent 09255254d7
commit dd3f9fe66c
8 changed files with 47 additions and 47 deletions

View File

@ -29,16 +29,15 @@
package cc.arduino.contributions.libraries.ui;
import cc.arduino.contributions.VersionComparator;
import cc.arduino.contributions.VersionHelper;
import cc.arduino.contributions.filters.BuiltInPredicate;
import cc.arduino.contributions.filters.InstalledPredicate;
import cc.arduino.contributions.libraries.ContributedLibrary;
import cc.arduino.contributions.libraries.ContributedLibraryComparator;
import cc.arduino.contributions.filters.BuiltInPredicate;
import cc.arduino.contributions.libraries.filters.OnlyUpstreamReleasePredicate;
import cc.arduino.contributions.packages.DownloadableContribution;
import cc.arduino.contributions.DownloadableContributionVersionComparator;
import cc.arduino.contributions.ui.InstallerTableCell;
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
import cc.arduino.utils.ReverseComparator;
import com.github.zafarkhaja.semver.Version;
import com.google.common.base.Function;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
@ -257,7 +256,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
uninstalledReleases.addAll(installedBuiltIn);
}
Collections.sort(uninstalledReleases, new ReverseComparator<ContributedLibrary>(new ContributedLibraryComparator()));
Collections.sort(uninstalledReleases, new ReverseComparator<DownloadableContribution>(new DownloadableContributionVersionComparator()));
downgradeChooser.removeAllItems();
downgradeChooser.addItem(_("Select version"));
@ -265,10 +264,11 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
final List<ContributedLibrary> uninstalledPreviousReleases = Lists.newLinkedList();
final List<ContributedLibrary> uninstalledNewerReleases = Lists.newLinkedList();
final VersionComparator versionComparator = new VersionComparator();
Lists.newLinkedList(Lists.transform(uninstalledReleases, new Function<ContributedLibrary, ContributedLibrary>() {
@Override
public ContributedLibrary apply(ContributedLibrary input) {
if (installed == null || VersionComparator.VERSION_COMPARATOR.greaterThan(installed.getParsedVersion(), input.getParsedVersion())) {
if (installed == null || versionComparator.greaterThan(installed.getParsedVersion(), input.getParsedVersion())) {
uninstalledPreviousReleases.add(input);
} else {
uninstalledNewerReleases.add(input);
@ -319,7 +319,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
} else {
installable = false;
removable = !installed.isReadOnly() && !hasBuiltInRelease;
upgradable = new ContributedLibraryComparator().compare(selected, installed) > 0;
upgradable = new DownloadableContributionVersionComparator().compare(selected, installed) > 0;
}
if (installable) {
installButton.setText(_("Install"));

View File

@ -29,12 +29,12 @@
package cc.arduino.contributions.packages.ui;
import cc.arduino.contributions.VersionComparator;
import cc.arduino.contributions.VersionHelper;
import cc.arduino.contributions.filters.InstalledPredicate;
import cc.arduino.contributions.filters.BuiltInPredicate;
import cc.arduino.contributions.packages.ContributedBoard;
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributedPlatformComparator;
import cc.arduino.contributions.packages.DownloadableContribution;
import cc.arduino.contributions.DownloadableContributionVersionComparator;
import cc.arduino.contributions.ui.InstallerTableCell;
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
import cc.arduino.utils.ReverseComparator;
@ -271,7 +271,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
uninstalledReleases.addAll(installedBuiltIn);
}
Collections.sort(uninstalledReleases, new ReverseComparator<ContributedPlatform>(new ContributedPlatformComparator()));
Collections.sort(uninstalledReleases, new ReverseComparator<DownloadableContribution>(new DownloadableContributionVersionComparator()));
downgradeChooser.removeAllItems();
downgradeChooser.addItem(_("Select version"));
@ -279,10 +279,11 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
final java.util.List<ContributedPlatform> uninstalledPreviousReleases = Lists.newLinkedList();
final java.util.List<ContributedPlatform> uninstalledNewerReleases = Lists.newLinkedList();
final VersionComparator versionComparator = new VersionComparator();
Lists.newLinkedList(Lists.transform(uninstalledReleases, new Function<ContributedPlatform, ContributedPlatform>() {
@Override
public ContributedPlatform apply(ContributedPlatform input) {
if (installed == null || VersionComparator.VERSION_COMPARATOR.greaterThan(installed.getParsedVersion(), input.getParsedVersion())) {
if (installed == null || versionComparator.greaterThan(installed.getParsedVersion(), input.getParsedVersion())) {
uninstalledPreviousReleases.add(input);
} else {
uninstalledNewerReleases.add(input);
@ -333,7 +334,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
} else {
installable = false;
removable = !installed.isReadOnly() && !hasBuiltInRelease;
upgradable = new ContributedPlatformComparator().compare(selected, installed) > 0;
upgradable = new DownloadableContributionVersionComparator().compare(selected, installed) > 0;
}
if (installable) {
installButton.setText(_("Install"));

View File

@ -44,10 +44,11 @@ public abstract class FilteredAbstractTableModel<T> extends AbstractTableModel {
protected static <T extends DownloadableContribution> T getLatestOf(List<T> contribs) {
contribs = new LinkedList<T>(contribs);
final VersionComparator versionComparator = new VersionComparator();
Collections.sort(contribs, new Comparator<T>() {
@Override
public int compare(T contrib1, T contrib2) {
return VersionComparator.VERSION_COMPARATOR.compare(contrib1.getParsedVersion(), contrib2.getParsedVersion());
return versionComparator.compare(contrib1.getParsedVersion(), contrib2.getParsedVersion());
}
});

View File

@ -30,6 +30,7 @@ import cc.arduino.contributions.libraries.ui.LibraryManagerUI;
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributionInstaller;
import cc.arduino.contributions.packages.ContributionsIndexer;
import cc.arduino.contributions.DownloadableContributionVersionComparator;
import cc.arduino.contributions.packages.ui.ContributionManagerUI;
import cc.arduino.packages.DiscoveryManager;
import cc.arduino.utils.Progress;
@ -322,7 +323,16 @@ public class Base {
String[] boardToInstallParts = parser.getBoardToInstall().split(":");
ContributedPlatform selected = indexer.getIndex().findPlatform(boardToInstallParts[0], boardToInstallParts[1], VersionHelper.valueOf(boardToInstallParts[2]).toString());
ContributedPlatform selected = null;
if (boardToInstallParts.length == 3) {
selected = indexer.getIndex().findPlatform(boardToInstallParts[0], boardToInstallParts[1], VersionHelper.valueOf(boardToInstallParts[2]).toString());
} else if (boardToInstallParts.length == 2) {
List<ContributedPlatform> platformsByName = indexer.getIndex().findPlatforms(boardToInstallParts[0], boardToInstallParts[1]);
Collections.sort(platformsByName, new DownloadableContributionVersionComparator());
if (!platformsByName.isEmpty()) {
selected = platformsByName.get(platformsByName.size() - 1);
}
}
if (selected == null) {
System.out.println(_("Selected board is not available"));
System.exit(1);

View File

@ -0,0 +1,21 @@
package cc.arduino.contributions;
import cc.arduino.contributions.packages.DownloadableContribution;
import java.util.Comparator;
public class DownloadableContributionVersionComparator implements Comparator<DownloadableContribution> {
private final VersionComparator versionComparator;
public DownloadableContributionVersionComparator() {
versionComparator = new VersionComparator();
}
@Override
public int compare(DownloadableContribution lib1, DownloadableContribution lib2) {
return versionComparator.compare(lib1.getParsedVersion(), lib2.getParsedVersion());
}
}

View File

@ -34,9 +34,6 @@ import java.util.Comparator;
public class VersionComparator implements Comparator<String> {
// An handy pre-instatiated object
public static final VersionComparator VERSION_COMPARATOR = new VersionComparator();
@Override
public int compare(String a, String b) {
// null is always less than any other value

View File

@ -1,15 +0,0 @@
package cc.arduino.contributions.libraries;
import cc.arduino.contributions.VersionComparator;
import java.util.Comparator;
public class ContributedLibraryComparator implements Comparator<ContributedLibrary> {
@Override
public int compare(ContributedLibrary lib1, ContributedLibrary lib2) {
return VersionComparator.VERSION_COMPARATOR.compare(lib1.getParsedVersion(), lib2.getParsedVersion());
}
}

View File

@ -1,15 +0,0 @@
package cc.arduino.contributions.packages;
import cc.arduino.contributions.VersionComparator;
import java.util.Comparator;
public class ContributedPlatformComparator implements Comparator<ContributedPlatform> {
@Override
public int compare(ContributedPlatform lib1, ContributedPlatform lib2) {
return VersionComparator.VERSION_COMPARATOR.compare(lib1.getParsedVersion(), lib2.getParsedVersion());
}
}