Skip to content

Added librariesDependencies in package_index.json #7642

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected void onInstall(ContributedLibrary selectedLibrary, Optional<Contribute
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
onRemovePressed(mayInstalledLibrary.get());
} else {
onInstallPressed(selectedLibrary, mayInstalledLibrary);
onInstallPressed(selectedLibrary);
}
}

Expand Down Expand Up @@ -212,12 +212,12 @@ protected void onUpdatePressed() {
installerThread.start();
}

public void onInstallPressed(final ContributedLibrary lib, final Optional<ContributedLibrary> mayReplaced) {
public void onInstallPressed(final ContributedLibrary lib) {
clearErrorMessage();
installerThread = new Thread(() -> {
try {
setProgressVisible(true, tr("Installing..."));
installer.install(lib, mayReplaced, this::setProgress);
installer.install(lib, this::setProgress);
onIndexesUpdated();
// TODO: Do a better job in refreshing only the needed element
((LibrariesIndexTableModel) contribModel).update();
Expand Down
8 changes: 4 additions & 4 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ public Base(String[] args) throws Exception {
pdeKeywords = new PdeKeywords();
pdeKeywords.reload();

contributionInstaller = new ContributionInstaller(BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier());
libraryInstaller = new LibraryInstaller(BaseNoGui.getPlatform());
libraryInstaller = new LibraryInstaller();
contributionInstaller = new ContributionInstaller(libraryInstaller, new GPGDetachedSignatureVerifier());

parser.parseArgumentsPhase2();

Expand All @@ -293,7 +293,7 @@ public Base(String[] args) throws Exception {
if (parser.isInstallBoard()) {
ContributionsIndexer indexer = new ContributionsIndexer(
BaseNoGui.getSettingsFolder(), BaseNoGui.getHardwareFolder(),
BaseNoGui.getPlatform(), new GPGDetachedSignatureVerifier());
new GPGDetachedSignatureVerifier());
ProgressListener progressListener = new ConsoleProgressListener();

List<String> downloadedPackageIndexFiles = contributionInstaller.updateIndex(progressListener);
Expand Down Expand Up @@ -366,7 +366,7 @@ public Base(String[] args) throws Exception {
library, mayInstalled.get().getParsedVersion())));
libraryInstaller.remove(mayInstalled.get(), progressListener);
} else {
libraryInstaller.install(selected, mayInstalled, progressListener);
libraryInstaller.install(selected, progressListener);
}
}

Expand Down
11 changes: 0 additions & 11 deletions app/src/processing/app/syntax/SketchTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
Expand All @@ -49,7 +47,6 @@
import org.fife.ui.rtextarea.RTextArea;
import org.fife.ui.rtextarea.RTextAreaUI;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.PreferencesData;

import javax.swing.event.EventListenerList;
Expand All @@ -58,14 +55,6 @@
import javax.swing.text.BadLocationException;
import javax.swing.text.Segment;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.logging.Logger;
import processing.app.helpers.OSUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
package cc.arduino.packages.contributions;

import org.junit.Test;
import processing.app.Platform;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand All @@ -46,19 +45,7 @@ public String getHost() {
}
};

Platform platform = new Platform() {
@Override
public String getOsName() {
return "Mac OS X";
}

@Override
public String getOsArch() {
return "x86_64";
}
};

assertTrue(contribution.isCompatible(platform));
assertTrue(contribution.isCompatible("Mac OS X", "x86_64"));
}

@Test
Expand All @@ -70,19 +57,7 @@ public String getHost() {
}
};

Platform platform = new Platform() {
@Override
public String getOsName() {
return "Linux";
}

@Override
public String getOsArch() {
return "amd64";
}
};

assertFalse(contribution.isCompatible(platform));
assertFalse(contribution.isCompatible("Linux", "amd64"));
}

@Test
Expand All @@ -94,19 +69,7 @@ public String getHost() {
}
};

Platform platform = new Platform() {
@Override
public String getOsName() {
return "Mac OS X";
}

@Override
public String getOsArch() {
return "i686";
}
};

assertFalse(contribution.isCompatible(platform));
assertFalse(contribution.isCompatible("Mac OS X", "i686"));
}

}
3 changes: 3 additions & 0 deletions arduino-core/src/cc/arduino/contributions/VersionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ public static Version valueOf(String ver) {
}
}

public static int compare(String a, String b) {
return valueOf(a).compareTo(valueOf(b));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static processing.app.I18n.tr;
import cc.arduino.contributions.VersionHelper;

public abstract class ContributedLibrary extends DownloadableContribution {

Expand All @@ -63,7 +65,7 @@ public abstract class ContributedLibrary extends DownloadableContribution {

public abstract List<String> getTypes();

public abstract List<ContributedLibraryReference> getRequires();
public abstract List<ContributedLibraryDependency> getRequires();

public abstract List<String> getProvidesIncludes();

Expand Down Expand Up @@ -146,7 +148,7 @@ public String info() {
res += "\n";
res += " requires :\n";
if (getRequires() != null)
for (ContributedLibraryReference r : getRequires()) {
for (ContributedLibraryDependency r : getRequires()) {
res += " " + r;
}
res += "\n";
Expand All @@ -163,22 +165,20 @@ public boolean equals(Object obj) {
return false;
}
ContributedLibrary other = (ContributedLibrary) obj;
String thisVersion = getParsedVersion();
String otherVersion = other.getParsedVersion();

boolean versionEquals = (thisVersion != null && otherVersion != null
&& thisVersion.equals(otherVersion));

// Important: for legacy libs, versions are null. Two legacy libs must
// always pass this test.
if (thisVersion == null && otherVersion == null)
versionEquals = true;
return Objects.equals(getParsedVersion(), other.getParsedVersion()) &&
Objects.equals(getName(), other.getName());
}

String thisName = getName();
String otherName = other.getName();
public boolean isBefore(ContributedLibrary other) {
return VersionHelper.compare(getVersion(), other.getVersion()) < 0;
}

boolean nameEquals = thisName == null || otherName == null || thisName.equals(otherName);
public static ContributedLibrary max(ContributedLibrary x, ContributedLibrary y) {
return x.isBefore(y) ? y : x;
}

return versionEquals && nameEquals;
@Override
public int hashCode() {
return Objects.hash(getParsedVersion(), getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@

package cc.arduino.contributions.libraries;

public abstract class ContributedLibraryReference {
public abstract class ContributedLibraryDependency {

public abstract String getName();

public abstract String getMaintainer();

public abstract String getVersion();

@Override
public String toString() {
return getName() + " " + getVersion() + " (" + getMaintainer() + ")";
return getName() + " " + getVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ public ContributedLibrary find(String name, String version) {
return null;
}

public ContributedLibrary find(ContributedLibraryDependency dep) {
if (dep.getVersion() == null) {
return find(dep.getName()).stream(). //
reduce(ContributedLibrary::max). //
orElseGet(null);
}
return find(dep.getName(), dep.getVersion());
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,18 @@
import cc.arduino.utils.MultiStepProgress;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.Platform;
import processing.app.helpers.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Optional;
import java.util.ArrayList;
import java.util.List;

import static processing.app.I18n.tr;

public class LibraryInstaller {

private final Platform platform;

public LibraryInstaller(Platform platform) {
this.platform = platform;
}

public synchronized void updateIndex(ProgressListener progressListener) throws Exception {
final MultiStepProgress progress = new MultiStepProgress(2);

Expand Down Expand Up @@ -83,23 +77,46 @@ public synchronized void updateIndex(ProgressListener progressListener) throws E
rescanLibraryIndex(progress, progressListener);
}

public synchronized void install(ContributedLibrary lib, Optional<ContributedLibrary> mayReplacedLib, ProgressListener progressListener) throws Exception {
public void install(ContributedLibrary lib, ProgressListener progressListener) throws Exception {
List<ContributedLibrary> libs = new ArrayList<>();
libs.add(lib);
install(libs, progressListener);
}

public synchronized void install(List<ContributedLibrary> libs, ProgressListener progressListener) throws Exception {
MultiStepProgress progress = new MultiStepProgress(3 * libs.size() + 1);
install(libs, progressListener, progress);
}

public synchronized void install(List<ContributedLibrary> libs, ProgressListener progressListener, MultiStepProgress progress) throws Exception {
for (ContributedLibrary lib : libs) {
// Do install library (3 steps)
performInstall(lib, progressListener, progress);
}

// Rescan index (1 step)
rescanLibraryIndex(progress, progressListener);
}

private void performInstall(ContributedLibrary lib, ProgressListener progressListener, MultiStepProgress progress) throws Exception {
if (lib.isLibraryInstalled()) {
progress.stepDone();
progress.stepDone();
progress.stepDone();
System.out.println(I18n.format(tr("Library is already installed: {0}:{1}"), lib.getName(), lib.getParsedVersion()));
return;
}

DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder());

final MultiStepProgress progress = new MultiStepProgress(3);

// Step 1: Download library
try {
downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener);
} catch (InterruptedException e) {
// Download interrupted... just exit
return;
}
progress.stepDone();

// TODO: Extract to temporary folders and move to the final destination only
// once everything is successfully unpacked. If the operation fails remove
Expand All @@ -111,24 +128,25 @@ public synchronized void install(ContributedLibrary lib, Optional<ContributedLib
File libsFolder = BaseNoGui.getSketchbookLibrariesFolder().folder;
File tmpFolder = FileUtils.createTempFolder(libsFolder);
try {
new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1);
new ArchiveExtractor().extract(lib.getDownloadedFile(), tmpFolder, 1);
} catch (Exception e) {
if (tmpFolder.exists())
FileUtils.recursiveDelete(tmpFolder);
}
progress.stepDone();

// Step 3: Remove replaced library and move installed one to the correct location
// TODO: Fix progress bar...
if (mayReplacedLib.isPresent()) {
remove(mayReplacedLib.get(), progressListener);
}
// Step 3: Remove replaced library (if any) and move installed one to the correct location
File destFolder = new File(libsFolder, lib.getName().replaceAll(" ", "_"));
// Check if we are replacing an already installed library
LibrariesIndex index = BaseNoGui.librariesIndexer.getIndex();
for (ContributedLibrary l : index.find(lib.getName())) {
if (l.isLibraryInstalled() && l.getInstalledLibrary().get().getInstalledFolder().equals(destFolder)) {
remove(l, progressListener);
break;
}
}
tmpFolder.renameTo(destFolder);
progress.stepDone();

// Step 4: Rescan index
rescanLibraryIndex(progress, progressListener);
}

public synchronized void remove(ContributedLibrary lib, ProgressListener progressListener) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
package cc.arduino.contributions.packages;

import cc.arduino.contributions.DownloadableContribution;
import cc.arduino.contributions.libraries.ContributedLibraryDependency;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.File;
Expand All @@ -48,6 +50,8 @@ public abstract class ContributedPlatform extends DownloadableContribution {
@Override
public abstract String getChecksum();

public abstract List<ContributedLibraryDependency> getLibrariesDependencies();

public abstract List<ContributedToolReference> getToolsDependencies();

public abstract List<ContributedBoard> getBoards();
Expand Down
Loading