mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 07:15:39 +02:00
Improve robustness of downloads and add license confirmation.
Bad things were happening when the downloads of the tools and sdk failed. Added retries and changed the order of the downloads so that partial downloads aren't registered as complete. Also added license confirmation dialog to make sure the user agrees to the Arduino licenses before installing the tools and sdk. Change-Id: Ie8f4fcd041d8e89195bc7d3551c63fd3270881ef
This commit is contained in:
parent
b5b941ab33
commit
063ab089db
4 changed files with 118 additions and 88 deletions
|
@ -21,7 +21,8 @@ public class ArduinoPreferences {
|
|||
|
||||
private static final String defaultHome = Paths.get(System.getProperty("user.home"), ".arduinocdt").toString(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
private static final String defaultBoardUrls = "http://downloads.arduino.cc/packages/package_index.json" //$NON-NLS-1$
|
||||
+ "\nhttp://arduino.esp8266.com/stable/package_esp8266com_index.json"; //$NON-NLS-1$
|
||||
+ "\r\nhttp://arduino.esp8266.com/stable/package_esp8266com_index.json" //$NON-NLS-1$
|
||||
+ "\r\nhttps://adafruit.github.io/arduino-board-index/package_adafruit_index.json"; //$NON-NLS-1$
|
||||
|
||||
private static IEclipsePreferences getPrefs() {
|
||||
return InstanceScope.INSTANCE.getNode(Activator.getId());
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.io.InputStream;
|
|||
import java.io.Reader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -68,12 +69,14 @@ public class ArduinoManager {
|
|||
public static final String AVR_TOOLCHAIN_ID = "org.eclipse.cdt.arduino.toolChain.avr"; //$NON-NLS-1$
|
||||
|
||||
public static final String LIBRARIES_URL = "http://downloads.arduino.cc/libraries/library_index.json"; //$NON-NLS-1$
|
||||
|
||||
private List<PackageIndex> packageIndices;
|
||||
private LibraryIndex libraryIndex;
|
||||
|
||||
public void loadIndices() {
|
||||
new Job(Messages.ArduinoBoardManager_0) {
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
synchronized (ArduinoManager.this) {
|
||||
String[] boardUrls = ArduinoPreferences.getBoardUrls().split("\n"); //$NON-NLS-1$
|
||||
packageIndices = new ArrayList<>(boardUrls.length);
|
||||
for (String boardUrl : boardUrls) {
|
||||
|
@ -83,6 +86,7 @@ public class ArduinoManager {
|
|||
loadLibraryIndex(true);
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}
|
||||
}.schedule();
|
||||
}
|
||||
|
||||
|
@ -270,12 +274,17 @@ public class ArduinoManager {
|
|||
|
||||
public static IStatus downloadAndInstall(String url, String archiveFileName, Path installPath,
|
||||
IProgressMonitor monitor) {
|
||||
Exception error = null;
|
||||
for (int retries = 3; retries > 0 && !monitor.isCanceled(); --retries) {
|
||||
try {
|
||||
URL dl = new URL(url);
|
||||
Path dlDir = ArduinoPreferences.getArduinoHome().resolve("downloads"); //$NON-NLS-1$
|
||||
Files.createDirectories(dlDir);
|
||||
Path archivePath = dlDir.resolve(archiveFileName);
|
||||
Files.copy(dl.openStream(), archivePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
URLConnection conn = dl.openConnection();
|
||||
conn.setConnectTimeout(10000);
|
||||
conn.setReadTimeout(10000);
|
||||
Files.copy(conn.getInputStream(), archivePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
boolean isWin = Platform.getOS().equals(Platform.OS_WIN32);
|
||||
|
||||
|
@ -303,7 +312,8 @@ public class ArduinoManager {
|
|||
}
|
||||
archiveIn = new ArchiveStreamFactory().createArchiveInputStream(archiver, in);
|
||||
|
||||
for (ArchiveEntry entry = archiveIn.getNextEntry(); entry != null; entry = archiveIn.getNextEntry()) {
|
||||
for (ArchiveEntry entry = archiveIn.getNextEntry(); entry != null; entry = archiveIn
|
||||
.getNextEntry()) {
|
||||
if (entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -345,9 +355,13 @@ public class ArduinoManager {
|
|||
}
|
||||
return Status.OK_STATUS;
|
||||
} catch (IOException | CompressorException | ArchiveException e) {
|
||||
return new Status(IStatus.ERROR, Activator.getId(), "Installing Platform", e);
|
||||
error = e;
|
||||
// retry
|
||||
}
|
||||
}
|
||||
// out of retries
|
||||
return new Status(IStatus.ERROR, Activator.getId(), "Download failed, please try again.", error);
|
||||
}
|
||||
|
||||
private static Set<PosixFilePermission> toPerms(int mode) {
|
||||
Set<PosixFilePermission> perms = new HashSet<>();
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
|
||||
|
@ -225,24 +224,12 @@ public class ArduinoPlatform {
|
|||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
// Download platform archive
|
||||
IStatus status = ArduinoManager.downloadAndInstall(url, archiveFileName, getInstallPath(), monitor);
|
||||
// Install the tools
|
||||
for (ToolDependency toolDep : toolsDependencies) {
|
||||
IStatus status = toolDep.install(monitor);
|
||||
if (!status.isOK()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// Install the tools
|
||||
MultiStatus mstatus = null;
|
||||
for (ToolDependency toolDep : toolsDependencies) {
|
||||
status = toolDep.install(monitor);
|
||||
if (!status.isOK()) {
|
||||
if (mstatus == null) {
|
||||
mstatus = new MultiStatus(status.getPlugin(), status.getCode(), status.getMessage(),
|
||||
status.getException());
|
||||
} else {
|
||||
mstatus.add(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// On Windows install make from bintray
|
||||
|
@ -256,14 +243,20 @@ public class ArduinoPlatform {
|
|||
makePath.toFile().setExecutable(true, false);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
mstatus.add(new Status(IStatus.ERROR, Activator.getId(), "downloading make.exe", e)); //$NON-NLS-1$
|
||||
return new Status(IStatus.ERROR, Activator.getId(), "Download failed, please try again.", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Download platform archive
|
||||
IStatus status = ArduinoManager.downloadAndInstall(url, archiveFileName, getInstallPath(), monitor);
|
||||
if (!status.isOK()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
// Reload the library index to pick up platform libraries
|
||||
ArduinoManager.instance.loadLibraryIndex(false);
|
||||
|
||||
return mstatus != null ? mstatus : Status.OK_STATUS;
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,12 +7,15 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.arduino.ui.internal.preferences;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
|
||||
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
|
||||
|
@ -23,6 +26,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.layout.TableColumnLayout;
|
||||
import org.eclipse.jface.preference.PreferencePage;
|
||||
import org.eclipse.jface.viewers.ColumnWeightData;
|
||||
|
@ -178,6 +182,24 @@ public class ArduinoBoardsPreferencePage extends PreferencePage implements IWork
|
|||
|
||||
@Override
|
||||
public boolean performOk() {
|
||||
File acceptedFile = ArduinoPreferences.getArduinoHome().resolve(".accepted").toFile(); //$NON-NLS-1$
|
||||
if (!acceptedFile.exists()) {
|
||||
String message = "Do you accept the licenses for the Arduino SDK and libraries? "
|
||||
+ "Information on the licenses can be found at arduino.cc web site.";
|
||||
MessageDialog dialog = new MessageDialog(getShell(), "Arduino License", null, message,
|
||||
MessageDialog.QUESTION, new String[] { "Accept", "Decline" }, 0);
|
||||
int rc = dialog.open();
|
||||
if (rc == 0) {
|
||||
try {
|
||||
acceptedFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
new Job("Installing Arduino Board Platforms") {
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
|
|
Loading…
Add table
Reference in a new issue