1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-19 22:25:52 +02:00

Bug 480575 - Arduino install and upgrade by platform.

Changes from a Board based install UI to a Platform based one which
is more honestly what it does. Adds support for upgrading platforms.
Also moves the hardware and tools under the platforms directory
to match what the Arduino IDE does.

Change-Id: I1ff4ad1178439dd1e51a7594870596e0cbe34afb
This commit is contained in:
Doug Schaefer 2015-12-01 16:10:46 -05:00
parent af50016436
commit 25bc7a3950
21 changed files with 304 additions and 298 deletions

View file

@ -2,6 +2,7 @@ package org.eclipse.cdt.arduino.core.tests;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager; import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
import org.junit.Test; import org.junit.Test;
@ -9,7 +10,7 @@ public class BoardManagerTests {
@Test @Test
public void loadPackagesTest() throws Exception { public void loadPackagesTest() throws Exception {
assertNotEquals(0, ArduinoManager.instance.getPackageIndices().size()); assertNotEquals(0, Activator.getService(ArduinoManager.class).getPackageIndices().size());
} }
} }

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.core.internal; package org.eclipse.cdt.arduino.core.internal;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleService; import org.eclipse.cdt.arduino.core.internal.console.ArduinoConsoleService;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
@ -47,6 +48,7 @@ public class Activator extends Plugin {
public void start(BundleContext bundleContext) throws Exception { public void start(BundleContext bundleContext) throws Exception {
plugin = this; plugin = this;
bundleContext.registerService(ArduinoManager.class, new ArduinoManager(), null);
} }
public void stop(BundleContext bundleContext) throws Exception { public void stop(BundleContext bundleContext) throws Exception {

View file

@ -19,6 +19,11 @@ public class Messages extends NLS {
public static String ArduinoLaunchConfigurationDelegate_0; public static String ArduinoLaunchConfigurationDelegate_0;
public static String ArduinoLaunchConfigurationDelegate_1; public static String ArduinoLaunchConfigurationDelegate_1;
public static String ArduinoLaunchConfigurationDelegate_2; public static String ArduinoLaunchConfigurationDelegate_2;
public static String ArduinoManager_0;
public static String ArduinoManager_1;
public static String ArduinoManager_2;
public static String ArduinoPlatform_0;
public static String ArduinoPlatform_1;
public static String ArduinoProjectGenerator_0; public static String ArduinoProjectGenerator_0;
static { static {

View file

@ -20,10 +20,13 @@ import java.io.Reader;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.nio.file.FileVisitResult;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.PosixFilePermission; import java.nio.file.attribute.PosixFilePermission;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -60,8 +63,6 @@ import com.google.gson.reflect.TypeToken;
public class ArduinoManager { public class ArduinoManager {
public static final ArduinoManager instance = new ArduinoManager();
// Build tool ids // Build tool ids
public static final String BOARD_OPTION_ID = "org.eclipse.cdt.arduino.option.board"; //$NON-NLS-1$ public static final String BOARD_OPTION_ID = "org.eclipse.cdt.arduino.option.board"; //$NON-NLS-1$
public static final String PLATFORM_OPTION_ID = "org.eclipse.cdt.arduino.option.platform"; //$NON-NLS-1$ public static final String PLATFORM_OPTION_ID = "org.eclipse.cdt.arduino.option.platform"; //$NON-NLS-1$
@ -168,23 +169,11 @@ public class ArduinoManager {
return null; return null;
} }
public List<ArduinoBoard> getBoards() throws CoreException {
List<ArduinoBoard> boards = new ArrayList<>();
for (PackageIndex index : getPackageIndices()) {
for (ArduinoPackage pkg : index.getPackages()) {
for (ArduinoPlatform platform : pkg.getLatestPlatforms()) {
boards.addAll(platform.getBoards());
}
}
}
return boards;
}
public List<ArduinoBoard> getInstalledBoards() throws CoreException { public List<ArduinoBoard> getInstalledBoards() throws CoreException {
List<ArduinoBoard> boards = new ArrayList<>(); List<ArduinoBoard> boards = new ArrayList<>();
for (PackageIndex index : getPackageIndices()) { for (PackageIndex index : getPackageIndices()) {
for (ArduinoPackage pkg : index.getPackages()) { for (ArduinoPackage pkg : index.getPackages()) {
for (ArduinoPlatform platform : pkg.getInstalledPlatforms()) { for (ArduinoPlatform platform : pkg.getInstalledPlatforms().values()) {
boards.addAll(platform.getBoards()); boards.addAll(platform.getBoards());
} }
} }
@ -227,7 +216,7 @@ public class ArduinoManager {
Type stringSet = new TypeToken<Set<String>>() { Type stringSet = new TypeToken<Set<String>>() {
}.getType(); }.getType();
Set<String> libraryNames = new Gson().fromJson(librarySetting, stringSet); Set<String> libraryNames = new Gson().fromJson(librarySetting, stringSet);
LibraryIndex index = ArduinoManager.instance.getLibraryIndex(); LibraryIndex index = Activator.getService(ArduinoManager.class).getLibraryIndex();
ArduinoPlatform platform = project.getActiveBuildConfig().getAdapter(ArduinoBuildConfiguration.class).getBoard() ArduinoPlatform platform = project.getActiveBuildConfig().getAdapter(ArduinoBuildConfiguration.class).getBoard()
.getPlatform(); .getPlatform();
@ -257,9 +246,9 @@ public class ArduinoManager {
Activator.log(e); Activator.log(e);
} }
new Job("Install libraries") { new Job(Messages.ArduinoManager_0) {
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
MultiStatus mstatus = new MultiStatus(Activator.getId(), 0, "Installing libraries", null); MultiStatus mstatus = new MultiStatus(Activator.getId(), 0, Messages.ArduinoManager_1, null);
for (ArduinoLibrary library : libraries) { for (ArduinoLibrary library : libraries) {
IStatus status = library.install(monitor); IStatus status = library.install(monitor);
if (!status.isOK()) { if (!status.isOK()) {
@ -373,7 +362,52 @@ public class ArduinoManager {
} }
} }
// out of retries // out of retries
return new Status(IStatus.ERROR, Activator.getId(), "Download failed, please try again.", error); return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoManager_2, error);
}
public static int compareVersions(String version1, String version2) {
if (version1 == null) {
return version2 == null ? 0 : -1;
}
if (version2 == null) {
return 1;
}
String[] v1 = version1.split("\\."); //$NON-NLS-1$
String[] v2 = version2.split("\\."); //$NON-NLS-1$
for (int i = 0; i < Math.max(v1.length, v2.length); ++i) {
if (v1.length <= i) {
return v2.length < i ? 0 : -1;
}
if (v2.length <= i) {
return 1;
}
try {
int vi1 = Integer.parseInt(v1[i]);
int vi2 = Integer.parseInt(v2[i]);
if (vi1 < vi2) {
return -1;
}
if (vi1 > vi2) {
return 1;
}
} catch (NumberFormatException e) {
// not numbers, do string compares
int c = v1[i].compareTo(v2[i]);
if (c < 0) {
return -1;
}
if (c > 0) {
return 1;
}
}
}
return 0;
} }
private static Set<PosixFilePermission> toPerms(int mode) { private static Set<PosixFilePermission> toPerms(int mode) {
@ -408,4 +442,20 @@ public class ArduinoManager {
return perms; return perms;
} }
public static void recursiveDelete(Path directory) throws IOException {
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
}
} }

View file

@ -7,12 +7,15 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.board; package org.eclipse.cdt.arduino.core.internal.board;
import java.nio.file.Path;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
public class ArduinoPackage { public class ArduinoPackage {
private String name; private String name;
@ -63,79 +66,34 @@ public class ArduinoPackage {
return Collections.unmodifiableCollection(platforms); return Collections.unmodifiableCollection(platforms);
} }
public Path getInstallPath() {
return ArduinoPreferences.getArduinoHome().resolve("packages").resolve(getName()); //$NON-NLS-1$
}
/** /**
* Only the latest versions of the platforms. * Only the latest versions of the platforms.
* *
* @return latest platforms * @return latest platforms
*/ */
public Collection<ArduinoPlatform> getLatestPlatforms() { public Map<String, ArduinoPlatform> getAvailablePlatforms() {
Map<String, ArduinoPlatform> platformMap = new HashMap<>(); Map<String, ArduinoPlatform> platformMap = new HashMap<>();
for (ArduinoPlatform platform : platforms) { for (ArduinoPlatform platform : platforms) {
ArduinoPlatform p = platformMap.get(platform.getName()); ArduinoPlatform p = platformMap.get(platform.getName());
if (p == null || compareVersions(platform.getVersion(), p.getVersion()) > 0) { if (p == null || ArduinoManager.compareVersions(platform.getVersion(), p.getVersion()) > 0) {
platformMap.put(platform.getName(), platform); platformMap.put(platform.getName(), platform);
} }
} }
return Collections.unmodifiableCollection(platformMap.values()); return platformMap;
} }
public Collection<ArduinoPlatform> getInstalledPlatforms() { public Map<String, ArduinoPlatform> getInstalledPlatforms() {
Map<String, ArduinoPlatform> platformMap = new HashMap<>(); Map<String, ArduinoPlatform> platformMap = new HashMap<>();
for (ArduinoPlatform platform : platforms) { for (ArduinoPlatform platform : platforms) {
if (platform.isInstalled()) { if (platform.isInstalled()) {
ArduinoPlatform p = platformMap.get(platform.getName());
if (p == null || compareVersions(platform.getVersion(), p.getVersion()) > 0) {
platformMap.put(platform.getName(), platform); platformMap.put(platform.getName(), platform);
} }
} }
} return platformMap;
return Collections.unmodifiableCollection(platformMap.values());
}
// TODO move somewhere.
public static int compareVersions(String version1, String version2) {
if (version1 == null) {
return version2 == null ? 0 : -1;
}
if (version2 == null) {
return 1;
}
String[] v1 = version1.split("\\."); //$NON-NLS-1$
String[] v2 = version2.split("\\."); //$NON-NLS-1$
for (int i = 0; i < Math.max(v1.length, v2.length); ++i) {
if (v1.length <= i) {
return v2.length < i ? 0 : -1;
}
if (v2.length <= i) {
return 1;
}
try {
int vi1 = Integer.parseInt(v1[i]);
int vi2 = Integer.parseInt(v2[i]);
if (vi1 < vi2) {
return -1;
}
if (vi1 > vi2) {
return 1;
}
} catch (NumberFormatException e) {
// not numbers, do string compares
int c = v1[i].compareTo(v2[i]);
if (c < 0) {
return -1;
}
if (c > 0) {
return 1;
}
}
}
return 0;
} }
public ArduinoPlatform getPlatform(String name) { public ArduinoPlatform getPlatform(String name) {
@ -146,7 +104,7 @@ public class ArduinoPackage {
foundPlatform = platform; foundPlatform = platform;
} else { } else {
if (platform.isInstalled() if (platform.isInstalled()
&& compareVersions(platform.getVersion(), foundPlatform.getVersion()) > 0) { && ArduinoManager.compareVersions(platform.getVersion(), foundPlatform.getVersion()) > 0) {
foundPlatform = platform; foundPlatform = platform;
} }
} }

View file

@ -30,6 +30,7 @@ import java.util.Properties;
import org.eclipse.cdt.arduino.core.internal.Activator; import org.eclipse.cdt.arduino.core.internal.Activator;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties; import org.eclipse.cdt.arduino.core.internal.HierarchicalProperties;
import org.eclipse.cdt.arduino.core.internal.Messages;
import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration; import org.eclipse.cdt.arduino.core.internal.build.ArduinoBuildConfiguration;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -102,15 +103,15 @@ public class ArduinoPlatform {
return size; return size;
} }
public List<ArduinoBoard> getBoards() throws CoreException { public List<ArduinoBoard> getBoards() {
if (isInstalled() && boardsProperties == null) { if (isInstalled() && boardsProperties == null) {
Properties boardProps = new Properties(); Properties boardProps = new Properties();
try (InputStream is = new FileInputStream(getInstallPath().resolve("boards.txt").toFile()); try (InputStream is = new FileInputStream(getInstallPath().resolve("boards.txt").toFile()); //$NON-NLS-1$
Reader reader = new InputStreamReader(is, "UTF-8")) { //$NON-NLS-1$ Reader reader = new InputStreamReader(is, "UTF-8")) { //$NON-NLS-1$
boardProps.load(reader); boardProps.load(reader);
} catch (IOException e) { } catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.getId(), "Loading boards.txt", e)); //$NON-NLS-1$ Activator.log(e);
} }
boardsProperties = new HierarchicalProperties(boardProps); boardsProperties = new HierarchicalProperties(boardProps);
@ -191,8 +192,27 @@ public class ArduinoPlatform {
} }
public Path getInstallPath() { public Path getInstallPath() {
return ArduinoPreferences.getArduinoHome().resolve("hardware").resolve(pkg.getName()).resolve(architecture) //$NON-NLS-1$ // TODO remove migration in Neon
Path oldPath = ArduinoPreferences.getArduinoHome().resolve("hardware").resolve(pkg.getName()) //$NON-NLS-1$
.resolve(architecture).resolve(version);
Path newPath = getPackage().getInstallPath().resolve("hardware").resolve(pkg.getName()).resolve(architecture) //$NON-NLS-1$
.resolve(version); .resolve(version);
if (Files.exists(oldPath)) {
try {
Files.createDirectories(newPath.getParent());
Files.move(oldPath, newPath);
for (Path parent = oldPath.getParent(); parent != null; parent = parent.getParent()) {
if (Files.newDirectoryStream(parent).iterator().hasNext()) {
break;
} else {
Files.delete(parent);
}
}
} catch (IOException e) {
Activator.log(e);
}
}
return newPath;
} }
public List<Path> getIncludePath() { public List<Path> getIncludePath() {
@ -264,7 +284,12 @@ public class ArduinoPlatform {
public IStatus install(IProgressMonitor monitor) { public IStatus install(IProgressMonitor monitor) {
// Check if we're installed already // Check if we're installed already
if (isInstalled()) { if (isInstalled()) {
return Status.OK_STATUS; try {
ArduinoManager.recursiveDelete(getInstallPath());
} catch (IOException e) {
// just log it, shouldn't break the install
Activator.log(e);
}
} }
// Install the tools // Install the tools
@ -278,7 +303,7 @@ public class ArduinoPlatform {
// On Windows install make from bintray // On Windows install make from bintray
if (Platform.getOS().equals(Platform.OS_WIN32)) { if (Platform.getOS().equals(Platform.OS_WIN32)) {
try { try {
Path makePath = ArduinoPreferences.getArduinoHome().resolve("tools/make/make.exe"); //$NON-NLS-1$ Path makePath = ArduinoPreferences.getArduinoHome().resolve("make.exe"); //$NON-NLS-1$
if (!makePath.toFile().exists()) { if (!makePath.toFile().exists()) {
Files.createDirectories(makePath.getParent()); Files.createDirectories(makePath.getParent());
URL makeUrl = new URL("https://bintray.com/artifact/download/cdtdoug/tools/make.exe"); //$NON-NLS-1$ URL makeUrl = new URL("https://bintray.com/artifact/download/cdtdoug/tools/make.exe"); //$NON-NLS-1$
@ -286,7 +311,7 @@ public class ArduinoPlatform {
makePath.toFile().setExecutable(true, false); makePath.toFile().setExecutable(true, false);
} }
} catch (IOException e) { } catch (IOException e) {
return new Status(IStatus.ERROR, Activator.getId(), "Download failed, please try again.", e); return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoPlatform_0, e);
} }
} }
@ -299,6 +324,16 @@ public class ArduinoPlatform {
return Status.OK_STATUS; return Status.OK_STATUS;
} }
public IStatus uninstall(IProgressMonitor monitor) {
try {
ArduinoManager.recursiveDelete(getInstallPath());
// TODO delete tools that aren't needed any more
return Status.OK_STATUS;
} catch (IOException e) {
return new Status(IStatus.ERROR, Activator.getId(), Messages.ArduinoPlatform_1, e);
}
}
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;

View file

@ -7,6 +7,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.core.internal.board; package org.eclipse.cdt.arduino.core.internal.board;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -50,8 +52,26 @@ public class ArduinoTool {
} }
public Path getInstallPath() { public Path getInstallPath() {
return ArduinoPreferences.getArduinoHome().resolve("tools").resolve(pkg.getName()).resolve(name) //$NON-NLS-1$ // TODO remove migration in Neon
Path oldPath = ArduinoPreferences.getArduinoHome().resolve("tools").resolve(pkg.getName()).resolve(name) //$NON-NLS-1$
.resolve(version); .resolve(version);
Path newPath = getPackage().getInstallPath().resolve("tools").resolve(name).resolve(version); //$NON-NLS-1$
if (Files.exists(oldPath)) {
try {
Files.createDirectories(newPath.getParent());
Files.move(oldPath, newPath);
for (Path parent = oldPath.getParent(); parent != null; parent = parent.getParent()) {
if (Files.newDirectoryStream(parent).iterator().hasNext()) {
break;
} else {
Files.delete(parent);
}
}
} catch (IOException e) {
Activator.log(e);
}
}
return newPath;
} }
public boolean isInstalled() { public boolean isInstalled() {

View file

@ -38,7 +38,7 @@ public class LibraryIndex {
ArduinoLibrary current = latestLibs.get(name); ArduinoLibrary current = latestLibs.get(name);
if (current != null) { if (current != null) {
if (ArduinoPackage.compareVersions(library.getVersion(), current.getVersion()) > 0) { if (ArduinoManager.compareVersions(library.getVersion(), current.getVersion()) > 0) {
latestLibs.put(name, library); latestLibs.put(name, library);
} }
} else { } else {

View file

@ -66,6 +66,8 @@ public class ArduinoBuildConfiguration {
private final IBuildConfiguration config; private final IBuildConfiguration config;
private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
private ArduinoBoard board; private ArduinoBoard board;
private Properties properties; private Properties properties;
@ -233,13 +235,13 @@ public class ArduinoBuildConfiguration {
String packageName = settings.get(PACKAGE_NAME, ""); //$NON-NLS-1$ String packageName = settings.get(PACKAGE_NAME, ""); //$NON-NLS-1$
String platformName = settings.get(PLATFORM_NAME, ""); //$NON-NLS-1$ String platformName = settings.get(PLATFORM_NAME, ""); //$NON-NLS-1$
String boardName = settings.get(BOARD_NAME, ""); //$NON-NLS-1$ String boardName = settings.get(BOARD_NAME, ""); //$NON-NLS-1$
board = ArduinoManager.instance.getBoard(boardName, platformName, packageName); board = manager.getBoard(boardName, platformName, packageName);
if (board == null) { if (board == null) {
// Default to Uno or first one we find // Default to Uno or first one we find
board = ArduinoManager.instance.getBoard("Arduino/Genuino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ board = manager.getBoard("Arduino/Genuino Uno", "Arduino AVR Boards", "arduino"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (board == null) { if (board == null) {
List<ArduinoBoard> boards = ArduinoManager.instance.getInstalledBoards(); List<ArduinoBoard> boards = manager.getInstalledBoards();
if (!boards.isEmpty()) { if (!boards.isEmpty()) {
board = boards.get(0); board = boards.get(0);
} }
@ -355,7 +357,7 @@ public class ArduinoBuildConfiguration {
// The list of library sources // The list of library sources
List<String> librarySources = new ArrayList<>(); List<String> librarySources = new ArrayList<>();
for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) { for (ArduinoLibrary lib : manager.getLibraries(project)) {
librarySources.addAll(lib.getSources()); librarySources.addAll(lib.getSources());
} }
buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$ buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$
@ -376,7 +378,7 @@ public class ArduinoBuildConfiguration {
} }
includes += '"' + pathString(include) + '"'; includes += '"' + pathString(include) + '"';
} }
for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) { for (ArduinoLibrary lib : manager.getLibraries(project)) {
for (Path include : lib.getIncludePath()) { for (Path include : lib.getIncludePath()) {
includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$ includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$
} }
@ -572,7 +574,7 @@ public class ArduinoBuildConfiguration {
for (Path include : platform.getIncludePath()) { for (Path include : platform.getIncludePath()) {
includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$ includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$
} }
Collection<ArduinoLibrary> libs = ArduinoManager.instance.getLibraries(config.getProject()); Collection<ArduinoLibrary> libs = manager.getLibraries(config.getProject());
for (ArduinoLibrary lib : libs) { for (ArduinoLibrary lib : libs) {
for (Path path : lib.getIncludePath()) { for (Path path : lib.getIncludePath()) {
includes += " -I\"" + pathString(path) + '"'; //$NON-NLS-1$ includes += " -I\"" + pathString(path) + '"'; //$NON-NLS-1$

View file

@ -13,4 +13,9 @@ ArduinoLaunchConfigurationDelegate_1=No active Arduino remote connection.
################################################################################ ################################################################################
ArduinoLaunchConfigurationDelegate_0=Arduino Launch ArduinoLaunchConfigurationDelegate_0=Arduino Launch
ArduinoLaunchConfigurationDelegate_2=Target has not been selected for Launch Configuration ArduinoLaunchConfigurationDelegate_2=Target has not been selected for Launch Configuration
ArduinoManager_0=Install libraries
ArduinoManager_1=Installing libraries
ArduinoManager_2=Download failed, please try again.
ArduinoPlatform_0=Download failed, please try again.
ArduinoPlatform_1=Uninstall failed.
ArduinoProjectGenerator_0=Write Arduino project file ArduinoProjectGenerator_0=Write Arduino project file

View file

@ -95,7 +95,7 @@ public class ArduinoRemoteConnection
} }
public ArduinoBoard getBoard() throws CoreException { public ArduinoBoard getBoard() throws CoreException {
return ArduinoManager.instance.getBoard(remoteConnection.getAttribute(BOARD_NAME), return Activator.getService(ArduinoManager.class).getBoard(remoteConnection.getAttribute(BOARD_NAME),
remoteConnection.getAttribute(PLATFORM_NAME), remoteConnection.getAttribute(PACKAGE_NAME)); remoteConnection.getAttribute(PLATFORM_NAME), remoteConnection.getAttribute(PACKAGE_NAME));
} }

View file

@ -98,6 +98,12 @@
id="org.eclipse.cdt.arduino.preference.page.boards" id="org.eclipse.cdt.arduino.preference.page.boards"
name="Boards"> name="Boards">
</page> </page>
<page
category="org.eclipse.cdt.arduino.preference.page"
class="org.eclipse.cdt.arduino.ui.internal.preferences.ArduinoPlatformsPreferencePage"
id="org.eclipse.cdt.arduino.ui.page.platforms"
name="Platforms">
</page>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.perspectiveExtensions"> point="org.eclipse.ui.perspectiveExtensions">

View file

@ -37,7 +37,7 @@ public class Activator extends AbstractUIPlugin {
super.start(context); super.start(context);
plugin = this; plugin = this;
// Load up the Arduino indices // Load up the Arduino indices
ArduinoManager.instance.loadIndices(); getService(ArduinoManager.class).loadIndices();
} }
public void stop(BundleContext context) throws Exception { public void stop(BundleContext context) throws Exception {

View file

@ -18,8 +18,28 @@ public class Messages extends NLS {
public static String NewArduinoTargetWizardPage_4; public static String NewArduinoTargetWizardPage_4;
public static String NewArduinoTargetWizardPage_5; public static String NewArduinoTargetWizardPage_5;
public static String ArduinoBoardsPreferencePage_desc; public static String ArduinoBoardsPreferencePage_desc;
public static String LibrariesPropertyPage_0;
public static String LibrariesPropertyPage_1;
public static String LibrariesPropertyPage_desc; public static String LibrariesPropertyPage_desc;
public static String ArduinoPlatformsPreferencePage_0;
public static String ArduinoPlatformsPreferencePage_1;
public static String ArduinoPlatformsPreferencePage_10;
public static String ArduinoPlatformsPreferencePage_11;
public static String ArduinoPlatformsPreferencePage_12;
public static String ArduinoPlatformsPreferencePage_13;
public static String ArduinoPlatformsPreferencePage_14;
public static String ArduinoPlatformsPreferencePage_15;
public static String ArduinoPlatformsPreferencePage_2;
public static String ArduinoPlatformsPreferencePage_3;
public static String ArduinoPlatformsPreferencePage_4;
public static String ArduinoPlatformsPreferencePage_5;
public static String ArduinoPlatformsPreferencePage_6;
public static String ArduinoPlatformsPreferencePage_7;
public static String ArduinoPlatformsPreferencePage_8;
public static String ArduinoPlatformsPreferencePage_9;
public static String ArduinoPreferencePage_desc; public static String ArduinoPreferencePage_desc;
public static String PlatformDetailsDialog_0;
public static String PlatformDetailsDialog_1;
static { static {
// initialize resource bundle // initialize resource bundle

View file

@ -11,10 +11,29 @@ NewArduinoTargetWizardPage_2=Target name:
NewArduinoTargetWizardPage_3= NewArduinoTargetWizardPage_3=
NewArduinoTargetWizardPage_4=Serial port: NewArduinoTargetWizardPage_4=Serial port:
NewArduinoTargetWizardPage_5=Board type: NewArduinoTargetWizardPage_5=Board type:
ArduinoBoardsPreferencePage_desc=Select a board you would like to install and click Install and then \ ArduinoBoardsPreferencePage_desc=NOTE: To install support for an Arduino board, please use the Arduino \
OK or Apply to install the SDK and Tools for that board. By doing so you agree to the licenses of the \ Platforms preference page to install the platform support for that board.
libraries and tools. For more information, see http://arduino.cc. LibrariesPropertyPage_0=Name
LibrariesPropertyPage_1=Description
LibrariesPropertyPage_desc=Select libraries to use in your project and click OK or Apply. \ LibrariesPropertyPage_desc=Select libraries to use in your project and click OK or Apply. \
If necessary the library will be installed. By adding libraries you agree to the licenses of those \ If necessary the library will be installed. By adding libraries you agree to the licenses of those \
libraries. For more information, see http://arduino.cc libraries. For more information, see http://arduino.cc
ArduinoPlatformsPreferencePage_0=Select a platform then click a button to install, uninstall, or find more details about the platform.
ArduinoPlatformsPreferencePage_1=Platform
ArduinoPlatformsPreferencePage_10=Information on the licenses can be found at arduino.cc web site.
ArduinoPlatformsPreferencePage_11=Arduino License
ArduinoPlatformsPreferencePage_12=Accept
ArduinoPlatformsPreferencePage_13=Decline
ArduinoPlatformsPreferencePage_14=Installing Arduino Board Platforms
ArduinoPlatformsPreferencePage_15=Installing Arduino Board Platforms
ArduinoPlatformsPreferencePage_2=Installed
ArduinoPlatformsPreferencePage_3=Available
ArduinoPlatformsPreferencePage_4=Install
ArduinoPlatformsPreferencePage_5=Upgrade
ArduinoPlatformsPreferencePage_6=Details
ArduinoPlatformsPreferencePage_7=Install
ArduinoPlatformsPreferencePage_8=Uninstall
ArduinoPlatformsPreferencePage_9=Do you accept the licenses for the Arduino SDK and libraries?
ArduinoPreferencePage_desc=Enter URLs for package_index.json files one per line. ArduinoPreferencePage_desc=Enter URLs for package_index.json files one per line.
PlatformDetailsDialog_0=Platform:
PlatformDetailsDialog_1=Supports boards:\n

View file

@ -7,50 +7,19 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.ui.internal.preferences; 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;
import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.cdt.arduino.ui.internal.Messages; import org.eclipse.cdt.arduino.ui.internal.Messages;
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.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.IWorkbenchPreferencePage;
public class ArduinoBoardsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { public class ArduinoBoardsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private Table table;
private Button installButton;
private Set<ArduinoBoard> toInstall = new HashSet<>();
@Override @Override
public void init(IWorkbench workbench) { public void init(IWorkbench workbench) {
} }
@ -67,168 +36,7 @@ public class ArduinoBoardsPreferencePage extends PreferencePage implements IWork
desc.setBackground(parent.getBackground()); desc.setBackground(parent.getBackground());
desc.setText(Messages.ArduinoBoardsPreferencePage_desc); desc.setText(Messages.ArduinoBoardsPreferencePage_desc);
Composite comp = new Composite(control, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
comp.setLayout(layout);
comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Composite tableComp = new Composite(comp, SWT.NONE);
tableComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table = new Table(tableComp, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableColumn packageColumn = new TableColumn(table, SWT.LEAD);
packageColumn.setText("Board");
TableColumn platformColumn = new TableColumn(table, SWT.LEAD);
platformColumn.setText("Platform");
TableColumn installedColumn = new TableColumn(table, SWT.LEAD);
installedColumn.setText("Installed");
TableColumnLayout tableLayout = new TableColumnLayout();
tableLayout.setColumnData(packageColumn, new ColumnWeightData(5, 150, true));
tableLayout.setColumnData(platformColumn, new ColumnWeightData(5, 150, true));
tableLayout.setColumnData(installedColumn, new ColumnWeightData(2, 75, true));
tableComp.setLayout(tableLayout);
table.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
updateButtons();
}
});
Composite buttonComp = new Composite(comp, SWT.NONE);
buttonComp.setLayout(new GridLayout());
buttonComp.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false));
installButton = new Button(buttonComp, SWT.PUSH);
installButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
installButton.setText("Install");
installButton.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (TableItem item : table.getSelection()) {
ArduinoBoard board = (ArduinoBoard) item.getData();
toInstall.add(board);
item.setText(2, "selected");
updateButtons();
}
}
});
updateTable();
updateButtons();
return control; return control;
} }
private void updateTable() {
if (table == null || table.isDisposed()) {
return;
}
table.removeAll();
try {
List<ArduinoBoard> boards = ArduinoManager.instance.getBoards();
Collections.sort(boards, new Comparator<ArduinoBoard>() {
public int compare(ArduinoBoard o1, ArduinoBoard o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (ArduinoBoard board : boards) {
TableItem item = new TableItem(table, SWT.NONE);
item.setData(board);
item.setText(0, board.getName());
item.setText(1, board.getPlatform().getName());
String msg;
if (toInstall.contains(board)) {
msg = "selected";
} else {
msg = board.getPlatform().isInstalled() ? "yes" : "no";
}
item.setText(2, msg);
}
} catch (CoreException e) {
Activator.log(e);
}
}
private void updateButtons() {
if (table == null || table.isDisposed()) {
return;
}
boolean enable = false;
for (TableItem item : table.getSelection()) {
ArduinoBoard board = (ArduinoBoard) item.getData();
if (toInstall.contains(board)) {
continue;
}
ArduinoPlatform platform = board.getPlatform();
if (!platform.isInstalled()) {
enable = true;
}
}
installButton.setEnabled(enable);
}
@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) {
Set<ArduinoPlatform> platforms = new HashSet<>();
for (ArduinoBoard board : toInstall) {
platforms.add(board.getPlatform());
}
MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, 0, "Installing Arduino Board Platforms",
null);
for (ArduinoPlatform platform : platforms) {
status.add(platform.install(monitor));
}
toInstall.clear();
if (table != null && !table.isDisposed()) {
table.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
updateTable();
}
});
}
return status;
}
}.schedule();
return true;
}
} }

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.arduino.ui.internal.preferences;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager; import org.eclipse.cdt.arduino.core.internal.board.ArduinoManager;
import org.eclipse.cdt.arduino.ui.internal.Activator;
import org.eclipse.cdt.arduino.ui.internal.Messages; import org.eclipse.cdt.arduino.ui.internal.Messages;
import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -53,7 +54,7 @@ public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchP
@Override @Override
public boolean performOk() { public boolean performOk() {
ArduinoPreferences.setBoardUrls(urlsText.getText()); ArduinoPreferences.setBoardUrls(urlsText.getText());
ArduinoManager.instance.loadIndices(); Activator.getService(ArduinoManager.class).loadIndices();
return true; return true;
} }

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2015 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.cdt.arduino.ui.internal.preferences;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoBoard;
import org.eclipse.cdt.arduino.core.internal.board.ArduinoPlatform;
import org.eclipse.cdt.arduino.ui.internal.Messages;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class PlatformDetailsDialog extends Dialog {
private final ArduinoPlatform platform;
protected PlatformDetailsDialog(Shell parentShell, ArduinoPlatform platform) {
super(parentShell);
setShellStyle(getShellStyle() | SWT.RESIZE);
this.platform = platform;
}
@Override
protected Control createDialogArea(Composite parent) {
Composite control = (Composite) super.createDialogArea(parent);
Text text = new Text(control, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL);
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
StringBuilder str = new StringBuilder();
str.append(Messages.PlatformDetailsDialog_0);
str.append(platform.getName());
str.append('\n');
str.append(Messages.PlatformDetailsDialog_1);
List<ArduinoBoard> boards = platform.getBoards();
Collections.sort(boards, new Comparator<ArduinoBoard>() {
@Override
public int compare(ArduinoBoard o1, ArduinoBoard o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (ArduinoBoard board : platform.getBoards()) {
str.append(" "); //$NON-NLS-1$
str.append(board.getName());
str.append('\n');
}
text.setText(str.toString());
return control;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
}
}

View file

@ -37,6 +37,8 @@ import org.eclipse.ui.dialogs.PropertyPage;
public class LibrariesPropertyPage extends PropertyPage { public class LibrariesPropertyPage extends PropertyPage {
private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
private class ContentProvider implements ITreeContentProvider { private class ContentProvider implements ITreeContentProvider {
private LibraryIndex index; private LibraryIndex index;
@ -187,20 +189,20 @@ public class LibrariesPropertyPage extends PropertyPage {
Tree tree = viewer.getTree(); Tree tree = viewer.getTree();
tree.setHeaderVisible(true); tree.setHeaderVisible(true);
TreeColumn column1 = new TreeColumn(tree, SWT.LEFT); TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
column1.setText("Name"); column1.setText(Messages.LibrariesPropertyPage_0);
column1.setWidth(200); column1.setWidth(200);
TreeColumn column2 = new TreeColumn(tree, SWT.LEFT); TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
column2.setText("Description"); column2.setText(Messages.LibrariesPropertyPage_1);
column2.setWidth(200); column2.setWidth(200);
viewer.setContentProvider(new ContentProvider()); viewer.setContentProvider(new ContentProvider());
viewer.setLabelProvider(new LabelProvider()); viewer.setLabelProvider(new LabelProvider());
try { try {
viewer.setInput(ArduinoManager.instance.getLibraryIndex()); viewer.setInput(manager.getLibraryIndex());
// Set the check states for currently selected libraries // Set the check states for currently selected libraries
IProject project = getElement().getAdapter(IProject.class); IProject project = getElement().getAdapter(IProject.class);
Collection<ArduinoLibrary> libraries = ArduinoManager.instance.getLibraries(project); Collection<ArduinoLibrary> libraries = manager.getLibraries(project);
for (ArduinoLibrary lib : libraries) { for (ArduinoLibrary lib : libraries) {
viewer.setChecked(lib, true); viewer.setChecked(lib, true);
} }
@ -231,7 +233,7 @@ public class LibrariesPropertyPage extends PropertyPage {
} }
} }
try { try {
ArduinoManager.instance.setLibraries(getProject(), libs); manager.setLibraries(getProject(), libs);
} catch (CoreException e) { } catch (CoreException e) {
Activator.log(e); Activator.log(e);
} }

View file

@ -76,7 +76,7 @@ public class ArduinoTargetPropertyPage extends PropertyPage implements IWorkbenc
try { try {
ArduinoBoard currentBoard = arduinoRemote.getBoard(); ArduinoBoard currentBoard = arduinoRemote.getBoard();
Collection<ArduinoBoard> boardList = ArduinoManager.instance.getBoards(); Collection<ArduinoBoard> boardList = Activator.getService(ArduinoManager.class).getInstalledBoards();
boards = new ArduinoBoard[boardList.size()]; boards = new ArduinoBoard[boardList.size()];
i = 0; i = 0;
int boardSel = 0; int boardSel = 0;

View file

@ -80,7 +80,7 @@ public class BoardPropertyControl extends Composite {
boardCombo = new Combo(this, SWT.READ_ONLY); boardCombo = new Combo(this, SWT.READ_ONLY);
boardCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); boardCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
try { try {
List<ArduinoBoard> boardList = ArduinoManager.instance.getInstalledBoards(); List<ArduinoBoard> boardList = Activator.getService(ArduinoManager.class).getInstalledBoards();
Collections.sort(boardList, new Comparator<ArduinoBoard>() { Collections.sort(boardList, new Comparator<ArduinoBoard>() {
@Override @Override
public int compare(ArduinoBoard o1, ArduinoBoard o2) { public int compare(ArduinoBoard o1, ArduinoBoard o2) {