Bug 480575 - Arduino install and upgrade by platform.
authorDoug Schaefer <dschaefer@qnx.com>
Tue, 1 Dec 2015 21:10:46 +0000 (16:10 -0500)
committerDoug Schaefer <dschaefer@qnx.com>
Tue, 1 Dec 2015 21:15:03 +0000 (16:15 -0500)
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

21 files changed:
toolchains/arduino/org.eclipse.cdt.arduino.core.tests/src/org/eclipse/cdt/arduino/core/tests/BoardManagerTests.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Activator.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/Messages.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoManager.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPackage.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoPlatform.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/ArduinoTool.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/board/LibraryIndex.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/build/ArduinoBuildConfiguration.java
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/messages.properties
toolchains/arduino/org.eclipse.cdt.arduino.core/src/org/eclipse/cdt/arduino/core/internal/remote/ArduinoRemoteConnection.java
toolchains/arduino/org.eclipse.cdt.arduino.ui/plugin.xml
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/Activator.java
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/Messages.java
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/messages.properties
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/preferences/ArduinoBoardsPreferencePage.java
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/preferences/ArduinoPreferencePage.java
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/preferences/PlatformDetailsDialog.java [new file with mode: 0644]
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/project/LibrariesPropertyPage.java
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/ArduinoTargetPropertyPage.java
toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/remote/BoardPropertyControl.java

index d9005b1..cdec38e 100644 (file)
@@ -2,6 +2,7 @@ package org.eclipse.cdt.arduino.core.tests;
 
 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.junit.Test;
 
@@ -9,7 +10,7 @@ public class BoardManagerTests {
 
        @Test
        public void loadPackagesTest() throws Exception {
-               assertNotEquals(0, ArduinoManager.instance.getPackageIndices().size());
+               assertNotEquals(0, Activator.getService(ArduinoManager.class).getPackageIndices().size());
        }
 
 }
index af57b60..342e8b4 100644 (file)
@@ -10,6 +10,7 @@
  *******************************************************************************/
 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.core.runtime.CoreException;
 import org.eclipse.core.runtime.IExtension;
@@ -47,6 +48,7 @@ public class Activator extends Plugin {
 
        public void start(BundleContext bundleContext) throws Exception {
                plugin = this;
+               bundleContext.registerService(ArduinoManager.class, new ArduinoManager(), null);
        }
 
        public void stop(BundleContext bundleContext) throws Exception {
index 78de895..c80f87c 100644 (file)
@@ -19,6 +19,11 @@ public class Messages extends NLS {
        public static String ArduinoLaunchConfigurationDelegate_0;
        public static String ArduinoLaunchConfigurationDelegate_1;
        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;
 
        static {
index 10089e3..5fe77c4 100644 (file)
@@ -20,10 +20,13 @@ import java.io.Reader;
 import java.lang.reflect.Type;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.FileVisitResult;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.nio.file.SimpleFileVisitor;
 import java.nio.file.StandardCopyOption;
+import java.nio.file.attribute.BasicFileAttributes;
 import java.nio.file.attribute.PosixFilePermission;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -60,8 +63,6 @@ import com.google.gson.reflect.TypeToken;
 
 public class ArduinoManager {
 
-       public static final ArduinoManager instance = new ArduinoManager();
-
        // Build tool ids
        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$
@@ -168,23 +169,11 @@ public class ArduinoManager {
                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 {
                List<ArduinoBoard> boards = new ArrayList<>();
                for (PackageIndex index : getPackageIndices()) {
                        for (ArduinoPackage pkg : index.getPackages()) {
-                               for (ArduinoPlatform platform : pkg.getInstalledPlatforms()) {
+                               for (ArduinoPlatform platform : pkg.getInstalledPlatforms().values()) {
                                        boards.addAll(platform.getBoards());
                                }
                        }
@@ -227,7 +216,7 @@ public class ArduinoManager {
                Type stringSet = new TypeToken<Set<String>>() {
                }.getType();
                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()
                                .getPlatform();
@@ -257,9 +246,9 @@ public class ArduinoManager {
                        Activator.log(e);
                }
 
-               new Job("Install libraries") {
+               new Job(Messages.ArduinoManager_0) {
                        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) {
                                        IStatus status = library.install(monitor);
                                        if (!status.isOK()) {
@@ -373,7 +362,52 @@ public class ArduinoManager {
                        }
                }
                // 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) {
@@ -408,4 +442,20 @@ public class ArduinoManager {
                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;
+                       }
+
+               });
+       }
 }
index 39f8329..1d18767 100644 (file)
@@ -7,12 +7,15 @@
  *******************************************************************************/
 package org.eclipse.cdt.arduino.core.internal.board;
 
+import java.nio.file.Path;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
+
 public class ArduinoPackage {
 
        private String name;
@@ -63,79 +66,34 @@ public class ArduinoPackage {
                return Collections.unmodifiableCollection(platforms);
        }
 
+       public Path getInstallPath() {
+               return ArduinoPreferences.getArduinoHome().resolve("packages").resolve(getName()); //$NON-NLS-1$
+       }
+
        /**
         * Only the latest versions of the platforms.
         * 
         * @return latest platforms
         */
-       public Collection<ArduinoPlatform> getLatestPlatforms() {
+       public Map<String, ArduinoPlatform> getAvailablePlatforms() {
                Map<String, ArduinoPlatform> platformMap = new HashMap<>();
                for (ArduinoPlatform platform : platforms) {
                        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);
                        }
                }
-               return Collections.unmodifiableCollection(platformMap.values());
+               return platformMap;
        }
 
-       public Collection<ArduinoPlatform> getInstalledPlatforms() {
+       public Map<String, ArduinoPlatform> getInstalledPlatforms() {
                Map<String, ArduinoPlatform> platformMap = new HashMap<>();
                for (ArduinoPlatform platform : platforms) {
                        if (platform.isInstalled()) {
-                               ArduinoPlatform p = platformMap.get(platform.getName());
-                               if (p == null || compareVersions(platform.getVersion(), p.getVersion()) > 0) {
-                                       platformMap.put(platform.getName(), platform);
-                               }
-                       }
-               }
-               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;
-                               }
+                               platformMap.put(platform.getName(), platform);
                        }
                }
-
-               return 0;
+               return platformMap;
        }
 
        public ArduinoPlatform getPlatform(String name) {
@@ -146,7 +104,7 @@ public class ArduinoPackage {
                                        foundPlatform = platform;
                                } else {
                                        if (platform.isInstalled()
-                                                       && compareVersions(platform.getVersion(), foundPlatform.getVersion()) > 0) {
+                                                       && ArduinoManager.compareVersions(platform.getVersion(), foundPlatform.getVersion()) > 0) {
                                                foundPlatform = platform;
                                        }
                                }
index 4bc524f..313d479 100644 (file)
@@ -30,6 +30,7 @@ import java.util.Properties;
 import org.eclipse.cdt.arduino.core.internal.Activator;
 import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
 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.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -102,15 +103,15 @@ public class ArduinoPlatform {
                return size;
        }
 
-       public List<ArduinoBoard> getBoards() throws CoreException {
+       public List<ArduinoBoard> getBoards() {
                if (isInstalled() && boardsProperties == null) {
                        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$
                                boardProps.load(reader);
                        } 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);
@@ -191,8 +192,27 @@ public class ArduinoPlatform {
        }
 
        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);
+               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() {
@@ -264,7 +284,12 @@ public class ArduinoPlatform {
        public IStatus install(IProgressMonitor monitor) {
                // Check if we're installed already
                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
@@ -278,7 +303,7 @@ public class ArduinoPlatform {
                // On Windows install make from bintray
                if (Platform.getOS().equals(Platform.OS_WIN32)) {
                        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()) {
                                        Files.createDirectories(makePath.getParent());
                                        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);
                                }
                        } 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;
        }
 
+       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
        public int hashCode() {
                final int prime = 31;
index cd3714c..f39f030 100644 (file)
@@ -7,6 +7,8 @@
  *******************************************************************************/
 package org.eclipse.cdt.arduino.core.internal.board;
 
+import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.List;
 import java.util.Properties;
@@ -50,8 +52,26 @@ public class ArduinoTool {
        }
 
        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);
+               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() {
index 75d1b69..4d83992 100644 (file)
@@ -38,7 +38,7 @@ public class LibraryIndex {
 
                        ArduinoLibrary current = latestLibs.get(name);
                        if (current != null) {
-                               if (ArduinoPackage.compareVersions(library.getVersion(), current.getVersion()) > 0) {
+                               if (ArduinoManager.compareVersions(library.getVersion(), current.getVersion()) > 0) {
                                        latestLibs.put(name, library);
                                }
                        } else {
index 4c5aa15..5612708 100644 (file)
@@ -66,6 +66,8 @@ public class ArduinoBuildConfiguration {
 
        private final IBuildConfiguration config;
 
+       private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
+
        private ArduinoBoard board;
        private Properties properties;
 
@@ -233,13 +235,13 @@ public class ArduinoBuildConfiguration {
                        String packageName = settings.get(PACKAGE_NAME, ""); //$NON-NLS-1$
                        String platformName = settings.get(PLATFORM_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) {
                                // 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) {
-                                       List<ArduinoBoard> boards = ArduinoManager.instance.getInstalledBoards();
+                                       List<ArduinoBoard> boards = manager.getInstalledBoards();
                                        if (!boards.isEmpty()) {
                                                board = boards.get(0);
                                        }
@@ -355,7 +357,7 @@ public class ArduinoBuildConfiguration {
 
                // The list of library sources
                List<String> librarySources = new ArrayList<>();
-               for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
+               for (ArduinoLibrary lib : manager.getLibraries(project)) {
                        librarySources.addAll(lib.getSources());
                }
                buildModel.put("libraries_srcs", librarySources); //$NON-NLS-1$
@@ -376,7 +378,7 @@ public class ArduinoBuildConfiguration {
                        }
                        includes += '"' + pathString(include) + '"';
                }
-               for (ArduinoLibrary lib : ArduinoManager.instance.getLibraries(project)) {
+               for (ArduinoLibrary lib : manager.getLibraries(project)) {
                        for (Path include : lib.getIncludePath()) {
                                includes += " -I\"" + pathString(include) + '"'; //$NON-NLS-1$
                        }
@@ -572,7 +574,7 @@ public class ArduinoBuildConfiguration {
                        for (Path include : platform.getIncludePath()) {
                                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 (Path path : lib.getIncludePath()) {
                                        includes += " -I\"" + pathString(path) + '"'; //$NON-NLS-1$
index a4ebc48..17b3d4d 100644 (file)
@@ -13,4 +13,9 @@ ArduinoLaunchConfigurationDelegate_1=No active Arduino remote connection.
 ################################################################################
 ArduinoLaunchConfigurationDelegate_0=Arduino Launch
 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
index 685dd89..f66344b 100644 (file)
@@ -95,7 +95,7 @@ public class ArduinoRemoteConnection
        }
 
        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));
        }
 
index 724bd86..0290e80 100644 (file)
             id="org.eclipse.cdt.arduino.preference.page.boards"
             name="Boards">
       </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
          point="org.eclipse.ui.perspectiveExtensions">
index 11f8406..968997a 100644 (file)
@@ -37,7 +37,7 @@ public class Activator extends AbstractUIPlugin {
                super.start(context);
                plugin = this;
                // Load up the Arduino indices
-               ArduinoManager.instance.loadIndices();
+               getService(ArduinoManager.class).loadIndices();
        }
 
        public void stop(BundleContext context) throws Exception {
index 84d2fe5..4f1e929 100644 (file)
@@ -18,8 +18,28 @@ public class Messages extends NLS {
        public static String NewArduinoTargetWizardPage_4;
        public static String NewArduinoTargetWizardPage_5;
        public static String ArduinoBoardsPreferencePage_desc;
+       public static String LibrariesPropertyPage_0;
+       public static String LibrariesPropertyPage_1;
        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 PlatformDetailsDialog_0;
+       public static String PlatformDetailsDialog_1;
 
        static {
                // initialize resource bundle
index 8221059..61c2cba 100644 (file)
@@ -11,10 +11,29 @@ NewArduinoTargetWizardPage_2=Target name:
 NewArduinoTargetWizardPage_3=
 NewArduinoTargetWizardPage_4=Serial port:
 NewArduinoTargetWizardPage_5=Board type:
-ArduinoBoardsPreferencePage_desc=Select a board you would like to install and click Install and then \
-OK or Apply to install the SDK and Tools for that board. By doing so you agree to the licenses of the \
-libraries and tools. For more information, see http://arduino.cc.
+ArduinoBoardsPreferencePage_desc=NOTE: To install support for an Arduino board, please use the Arduino \
+Platforms preference page to install the platform support for that board.
+LibrariesPropertyPage_0=Name
+LibrariesPropertyPage_1=Description
 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 \
 libraries. For more information, see http://arduino.cc
-ArduinoPreferencePage_desc=Enter URLs for package_index.json files one per line.
\ No newline at end of file
+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.
+PlatformDetailsDialog_0=Platform: 
+PlatformDetailsDialog_1=Supports boards:\n
index f6ddb31..488c7d0 100644 (file)
@@ -7,50 +7,19 @@
  *******************************************************************************/
 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.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.viewers.ColumnWeightData;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 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.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
 
 public class ArduinoBoardsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
 
-       private Table table;
-       private Button installButton;
-       private Set<ArduinoBoard> toInstall = new HashSet<>();
-
        @Override
        public void init(IWorkbench workbench) {
        }
@@ -67,168 +36,7 @@ public class ArduinoBoardsPreferencePage extends PreferencePage implements IWork
                desc.setBackground(parent.getBackground());
                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;
        }
 
-       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;
-       }
-
 }
index 5e321ae..8aaaf4b 100644 (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.board.ArduinoManager;
+import org.eclipse.cdt.arduino.ui.internal.Activator;
 import org.eclipse.cdt.arduino.ui.internal.Messages;
 import org.eclipse.jface.preference.PreferencePage;
 import org.eclipse.swt.SWT;
@@ -53,7 +54,7 @@ public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchP
        @Override
        public boolean performOk() {
                ArduinoPreferences.setBoardUrls(urlsText.getText());
-               ArduinoManager.instance.loadIndices();
+               Activator.getService(ArduinoManager.class).loadIndices();
                return true;
        }
 
diff --git a/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/preferences/PlatformDetailsDialog.java b/toolchains/arduino/org.eclipse.cdt.arduino.ui/src/org/eclipse/cdt/arduino/ui/internal/preferences/PlatformDetailsDialog.java
new file mode 100644 (file)
index 0000000..20037f4
--- /dev/null
@@ -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);
+       }
+
+}
index b98a4e2..efb08ae 100644 (file)
@@ -37,6 +37,8 @@ import org.eclipse.ui.dialogs.PropertyPage;
 
 public class LibrariesPropertyPage extends PropertyPage {
 
+       private static ArduinoManager manager = Activator.getService(ArduinoManager.class);
+
        private class ContentProvider implements ITreeContentProvider {
                private LibraryIndex index;
 
@@ -187,20 +189,20 @@ public class LibrariesPropertyPage extends PropertyPage {
                Tree tree = viewer.getTree();
                tree.setHeaderVisible(true);
                TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
-               column1.setText("Name");
+               column1.setText(Messages.LibrariesPropertyPage_0);
                column1.setWidth(200);
                TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
-               column2.setText("Description");
+               column2.setText(Messages.LibrariesPropertyPage_1);
                column2.setWidth(200);
 
                viewer.setContentProvider(new ContentProvider());
                viewer.setLabelProvider(new LabelProvider());
 
                try {
-                       viewer.setInput(ArduinoManager.instance.getLibraryIndex());
+                       viewer.setInput(manager.getLibraryIndex());
                        // Set the check states for currently selected libraries
                        IProject project = getElement().getAdapter(IProject.class);
-                       Collection<ArduinoLibrary> libraries = ArduinoManager.instance.getLibraries(project);
+                       Collection<ArduinoLibrary> libraries = manager.getLibraries(project);
                        for (ArduinoLibrary lib : libraries) {
                                viewer.setChecked(lib, true);
                        }
@@ -231,7 +233,7 @@ public class LibrariesPropertyPage extends PropertyPage {
                        }
                }
                try {
-                       ArduinoManager.instance.setLibraries(getProject(), libs);
+                       manager.setLibraries(getProject(), libs);
                } catch (CoreException e) {
                        Activator.log(e);
                }
index ca7f611..c614af5 100644 (file)
@@ -76,7 +76,7 @@ public class ArduinoTargetPropertyPage extends PropertyPage implements IWorkbenc
 
                try {
                        ArduinoBoard currentBoard = arduinoRemote.getBoard();
-                       Collection<ArduinoBoard> boardList = ArduinoManager.instance.getBoards();
+                       Collection<ArduinoBoard> boardList = Activator.getService(ArduinoManager.class).getInstalledBoards();
                        boards = new ArduinoBoard[boardList.size()];
                        i = 0;
                        int boardSel = 0;
index 5787ca2..506e012 100644 (file)
@@ -80,7 +80,7 @@ public class BoardPropertyControl extends Composite {
                boardCombo = new Combo(this, SWT.READ_ONLY);
                boardCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
                try {
-                       List<ArduinoBoard> boardList = ArduinoManager.instance.getInstalledBoards();
+                       List<ArduinoBoard> boardList = Activator.getService(ArduinoManager.class).getInstalledBoards();
                        Collections.sort(boardList, new Comparator<ArduinoBoard>() {
                                @Override
                                public int compare(ArduinoBoard o1, ArduinoBoard o2) {