From 5309e5a68caa8dd8f1f35f7e3c46d7ebf70a89fc Mon Sep 17 00:00:00 2001 From: jantje Date: Mon, 18 Sep 2017 18:12:05 +0200 Subject: [PATCH 01/10] basic implementation --- .../io/sloeber/core/api/LibraryManager.java | 15 +++++++++ .../sloeber/core/managers/LibraryIndex.java | 10 ++++++ .../src/io/sloeber/core/tools/Libraries.java | 31 ++++++++++++++++--- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java index ccb9db69e..0538614fb 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java +++ b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java @@ -351,4 +351,19 @@ public static void removeAllLibs() { } } + /** + * Searches for all libraries that can be installed but are not yet installed. + * A library is considered installed when 1 version of the library is installed. + * + * @return a map of all instalable libraries + */ + public static Map getAllInstallableLibraries() { + Map ret = new HashMap<>(); + for (LibraryIndex libraryIndex : libraryIndices) { + ret.putAll(libraryIndex.getLatestInstallableLibraries()); + } + + return ret; + } + } \ No newline at end of file diff --git a/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java b/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java index 0f7d6c7dd..f4213f75e 100644 --- a/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java +++ b/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java @@ -7,6 +7,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.regex.Pattern; @@ -93,6 +94,15 @@ public Map getLatestLibraries() { return this.latestLibs; } + public Map getLatestInstallableLibraries() { + Map ret = new HashMap<>(); + for (Entry curLibrary : this.latestLibs.entrySet()) { + if (getInstalledLibrary(curLibrary.getKey())==null) { + ret.put(curLibrary.getKey(), curLibrary.getValue()); + } + } + return ret; + } public Collection getLibraries(String category) { Set categoryLibs = this.categories.get(category); if (categoryLibs == null) { diff --git a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java index ece57000c..cfc204e19 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java @@ -30,11 +30,13 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import io.sloeber.core.InternalBoardDescriptor; import io.sloeber.core.api.BoardDescriptor; +import io.sloeber.core.api.LibraryManager; import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.core.common.Const; @@ -390,15 +392,34 @@ public static void checkLibraries(IProject affectedProject) { UnresolvedIncludedHeaders.add(entry.getValue()); } } - Map availableLibs = getAllInstalledLibraries(configurationDescription); UnresolvedIncludedHeaders.removeAll(alreadyAddedLibs); - availableLibs.keySet().retainAll(UnresolvedIncludedHeaders); - if (!availableLibs.isEmpty()) { + + //Check if there are libraries that are not found in the installed libraries + Map installedLibs = getAllInstalledLibraries(configurationDescription); + Set uninstalledIncludedHeaders=new TreeSet<>(UnresolvedIncludedHeaders); + uninstalledIncludedHeaders.removeAll(installedLibs.keySet()); + if(!uninstalledIncludedHeaders.isEmpty()) { + //some libraries may need to be installed + Map availableLibs = LibraryManager.getAllInstallableLibraries(); + availableLibs.keySet().retainAll(uninstalledIncludedHeaders); + if(!availableLibs.isEmpty()) { + //We now know which libraries to install + //TODO for now I just install but there should be some user + //interaction + for (Entry curLib : availableLibs.entrySet()) { + curLib.getValue().install(new NullProgressMonitor()); + } + } + } + + installedLibs = getAllInstalledLibraries(configurationDescription); + installedLibs.keySet().retainAll(UnresolvedIncludedHeaders); + if (!installedLibs.isEmpty()) { // there are possible libraries to add Common.log(new Status(IStatus.INFO, Const.CORE_PLUGIN_ID, "list of libraries to add to project " //$NON-NLS-1$ - + affectedProject.getName() + ": " + availableLibs.keySet().toString())); //$NON-NLS-1$ - addLibrariesToProject(affectedProject, configurationDescription, availableLibs); + + affectedProject.getName() + ": " + installedLibs.keySet().toString())); //$NON-NLS-1$ + addLibrariesToProject(affectedProject, configurationDescription, installedLibs); try { mngr.setProjectDescription(affectedProject, projectDescription, true, null); } catch (CoreException e) { From 39711111ae8f7f3f4bd18ad3f3a156532f2ea2e7 Mon Sep 17 00:00:00 2001 From: jantje Date: Mon, 18 Sep 2017 22:48:30 +0200 Subject: [PATCH 02/10] performance improvements instead of looking for all installable libraries I only look for the once I need. --- .../io/sloeber/core/api/LibraryManager.java | 12 +++++++ .../src/io/sloeber/core/managers/Library.java | 27 ++++++++++++++-- .../sloeber/core/managers/LibraryIndex.java | 32 ++++++++++++++++++- .../src/io/sloeber/core/tools/Libraries.java | 11 +++++-- 4 files changed, 76 insertions(+), 6 deletions(-) diff --git a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java index 0538614fb..780e0fcef 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java +++ b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java @@ -366,4 +366,16 @@ public static Map getAllInstallableLib return ret; } + public static Map getLatestInstallableLibraries( + Set libnames) { + Set remainingLibNames=new TreeSet<>(libnames); + Map ret = new HashMap<>(); + for (LibraryIndex libraryIndex : libraryIndices) { + ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames)); + remainingLibNames.removeAll(ret.keySet()); + } + + return ret; + } + } \ No newline at end of file diff --git a/io.sloeber.core/src/io/sloeber/core/managers/Library.java b/io.sloeber.core/src/io/sloeber/core/managers/Library.java index 717033daf..db44c99d3 100644 --- a/io.sloeber.core/src/io/sloeber/core/managers/Library.java +++ b/io.sloeber.core/src/io/sloeber/core/managers/Library.java @@ -17,6 +17,7 @@ import org.eclipse.core.runtime.Status; import io.sloeber.core.Activator; +import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.core.tools.FileModifiers; @@ -159,6 +160,26 @@ public boolean isInstalled() { return getInstallPath().toFile().exists(); } + /** + * checks if any version of this library is installed. Can popup a window if + * there is something wrong with the folder structure + * + * @return false if any version is installed. true in case of error and in case + * no version is installed + */ + public boolean isAVersionInstalled() { + if (!getInstallPath().getParent().toFile().exists()) { + return false; + } + if (getInstallPath().getParent().toFile().isFile()) { + // something is wrong here + Common.log(new Status(IStatus.ERROR, Activator.getId(), + getInstallPath().getParent() + " is a file but it should be a directory.")); //$NON-NLS-1$ + return false; + } + return getInstallPath().getParent().toFile().list().length > 0; + } + public IStatus install(IProgressMonitor monitor) { monitor.setTaskName("Downloading and installing " + getName() + " library."); //$NON-NLS-1$ //$NON-NLS-2$ if (isInstalled()) { @@ -215,9 +236,9 @@ public int compareTo(Library other) { } /** - * delete the library This will delete all installed versions of the - * library. Normally only 1 version can be installed so deleting all - * versions should be delete 1 version + * delete the library This will delete all installed versions of the library. + * Normally only 1 version can be installed so deleting all versions should be + * delete 1 version * * @param monitor * @return Status.OK_STATUS if delete is successful otherwise IStatus.ERROR diff --git a/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java b/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java index f4213f75e..a4599312d 100644 --- a/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java +++ b/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java @@ -94,15 +94,23 @@ public Map getLatestLibraries() { return this.latestLibs; } + /** + * get all the latest versions of alll libraries that can be installed but are + * not yet installed To do so I find all latest libraries and I remove the once + * that are installed. + * + * @return + */ public Map getLatestInstallableLibraries() { Map ret = new HashMap<>(); for (Entry curLibrary : this.latestLibs.entrySet()) { - if (getInstalledLibrary(curLibrary.getKey())==null) { + if (!curLibrary.getValue().isAVersionInstalled()) { ret.put(curLibrary.getKey(), curLibrary.getValue()); } } return ret; } + public Collection getLibraries(String category) { Set categoryLibs = this.categories.get(category); if (categoryLibs == null) { @@ -131,4 +139,26 @@ public void setJsonFile(File packageFile) { public String getName() { return this.jsonFileName; } + + /** + * get all the latest versions of alll the libraries provided that can be + * installed but are not yet installed To do so I find all latest libraries and + * I remove the once that are installed. + * + * @return + */ + public Map getLatestInstallableLibraries(Set libNames) { + Map ret = new HashMap<>(); + if (libNames.isEmpty()) { + return ret; + } + for (Entry curLibrary : this.latestLibs.entrySet()) { + if (libNames.contains(curLibrary.getKey())) { + if (!curLibrary.getValue().isAVersionInstalled()) { + ret.put(curLibrary.getKey(), curLibrary.getValue()); + } + } + } + return ret; + } } diff --git a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java index cfc204e19..941ce77ca 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java @@ -401,8 +401,9 @@ public static void checkLibraries(IProject affectedProject) { uninstalledIncludedHeaders.removeAll(installedLibs.keySet()); if(!uninstalledIncludedHeaders.isEmpty()) { //some libraries may need to be installed - Map availableLibs = LibraryManager.getAllInstallableLibraries(); - availableLibs.keySet().retainAll(uninstalledIncludedHeaders); + + Map availableLibs=LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders); + if(!availableLibs.isEmpty()) { //We now know which libraries to install //TODO for now I just install but there should be some user @@ -421,7 +422,13 @@ public static void checkLibraries(IProject affectedProject) { + affectedProject.getName() + ": " + installedLibs.keySet().toString())); //$NON-NLS-1$ addLibrariesToProject(affectedProject, configurationDescription, installedLibs); try { + //TODO remove this logging code if this code is not causing the disrupts + long startTime = System.nanoTime(); mngr.setProjectDescription(affectedProject, projectDescription, true, null); + long duration = (System.nanoTime() - startTime)/ 1000000; //in miliseconds + if (duration>45000) { + Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,"setProjectDescription took "+duration+" miliseconds!!!")); //$NON-NLS-1$ //$NON-NLS-2$ + } } catch (CoreException e) { // this can fail because the project may already // be From d2c8b4de8654b2a6af0215d4db8224150e2d824b Mon Sep 17 00:00:00 2001 From: jantje Date: Tue, 26 Sep 2017 15:29:23 +0200 Subject: [PATCH 03/10] add canique board --- io.sloeber.core/src/jUnit/CreateAndCompile.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/io.sloeber.core/src/jUnit/CreateAndCompile.java b/io.sloeber.core/src/jUnit/CreateAndCompile.java index 2c6485db8..2f7678174 100644 --- a/io.sloeber.core/src/jUnit/CreateAndCompile.java +++ b/io.sloeber.core/src/jUnit/CreateAndCompile.java @@ -138,7 +138,8 @@ public static void installAdditionalBoards() { "https://www.mattairtech.com/software/arduino/package_MattairTech_index.json", "https://zevero.github.io/avr_boot/package_zevero_avr_boot_index.json", "https://udooboard.github.io/arduino-board-package/package_udoo_index.json", - "http://fpgalibre.sf.net/Lattuino/package_lattuino_index.json" }; + "http://fpgalibre.sf.net/Lattuino/package_lattuino_index.json" , + "https://resources.canique.com/ide/package_canique_index.json"}; BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true); BoardsManager.referenceLocallInstallation(Shared.getTeensyPlatform()); if (reinstall_boards_and_libraries) { From d49130ccf2be48096f6ec551ff855cd00f387a00 Mon Sep 17 00:00:00 2001 From: jantje Date: Tue, 26 Sep 2017 15:30:18 +0200 Subject: [PATCH 04/10] adding a install handler --- .../core/api/IInstallLibraryHandler.java | 35 +++++++++++++++++++ .../io/sloeber/core/api/LibraryManager.java | 32 +++++++++++------ .../core/core/DefaultInstallHandler.java | 22 ++++++++++++ .../src/io/sloeber/core/tools/Libraries.java | 8 +++-- 4 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java create mode 100644 io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java diff --git a/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java b/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java new file mode 100644 index 000000000..49401d457 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java @@ -0,0 +1,35 @@ +package io.sloeber.core.api; + +import java.util.Map; + +import io.sloeber.core.managers.Library; + +/** + * this interface is to allow the ui to handle the automatic installation + * of libraries. + * If you do not register your implementation of this interface there will be + * no automatic install of libraries + * + * registering your inmplementation is done in the library manager + * + * @author jan + * + */ + +public interface IInstallLibraryHandler { + /** + * The core will call this method to find out if you want to install + * the libraries automatically or not + * + * @return true if you want libraries to beinstalled automatically + */ + abstract boolean autoInstall(); + /** + * given the set of proposed libraries to install + * let the user decide on what to install + * @param proposedLibsToInstall the libraries Sloeber proposes to install + * + * @return The libraries the user wants to install + */ + abstract Map selectLibrariesToInstall(Map proposedLibsToInstall); +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java index 780e0fcef..0c4e9b793 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java +++ b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java @@ -26,6 +26,7 @@ import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.core.common.InstancePreferences; +import io.sloeber.core.core.DefaultInstallHandler; import io.sloeber.core.managers.Library; import io.sloeber.core.managers.LibraryIndex; import io.sloeber.core.managers.Manager; @@ -34,6 +35,7 @@ public class LibraryManager { static private List libraryIndices; + private static IInstallLibraryHandler myInstallLibraryHandler = new DefaultInstallHandler(); static public List getLibraryIndices() { if (libraryIndices == null) { @@ -237,6 +239,7 @@ public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor, public static String getPrivateLibraryPathsString() { return InstancePreferences.getPrivateLibraryPathsString(); } + public static void setPrivateLibraryPaths(String[] libraryPaths) { InstancePreferences.setPrivateLibraryPaths(libraryPaths); @@ -296,9 +299,9 @@ static public void loadJson(File jsonFile) { } /** - * Install the latest version of all the libraries belonging to this - * category If a earlier version is installed this version will be removed - * before installation of the newer version + * Install the latest version of all the libraries belonging to this category If + * a earlier version is installed this version will be removed before + * installation of the newer version * * @param category */ @@ -352,30 +355,37 @@ public static void removeAllLibs() { } /** - * Searches for all libraries that can be installed but are not yet installed. - * A library is considered installed when 1 version of the library is installed. + * Searches for all libraries that can be installed but are not yet installed. A + * library is considered installed when 1 version of the library is installed. * * @return a map of all instalable libraries */ public static Map getAllInstallableLibraries() { Map ret = new HashMap<>(); for (LibraryIndex libraryIndex : libraryIndices) { - ret.putAll(libraryIndex.getLatestInstallableLibraries()); + ret.putAll(libraryIndex.getLatestInstallableLibraries()); } return ret; } - public static Map getLatestInstallableLibraries( - Set libnames) { - Set remainingLibNames=new TreeSet<>(libnames); + public static Map getLatestInstallableLibraries(Set libnames) { + Set remainingLibNames = new TreeSet<>(libnames); Map ret = new HashMap<>(); for (LibraryIndex libraryIndex : libraryIndices) { - ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames)); - remainingLibNames.removeAll(ret.keySet()); + ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames)); + remainingLibNames.removeAll(ret.keySet()); } return ret; } + public static void registerInstallLibraryHandler(IInstallLibraryHandler installLibraryHandler) { + myInstallLibraryHandler = installLibraryHandler; + } + + public static IInstallLibraryHandler getInstallLibraryHandler() { + return myInstallLibraryHandler; + } + } \ No newline at end of file diff --git a/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java b/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java new file mode 100644 index 000000000..737636871 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java @@ -0,0 +1,22 @@ +package io.sloeber.core.core; + +import java.util.Map; + +import io.sloeber.core.api.IInstallLibraryHandler; +import io.sloeber.core.managers.Library; + +public class DefaultInstallHandler implements IInstallLibraryHandler { + + @Override + public boolean autoInstall() { + return false; + } + + + @Override + public Map selectLibrariesToInstall(Map proposedLibsToInstall) { + + return proposedLibsToInstall; + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java index 941ce77ca..adaa09121 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java @@ -36,6 +36,7 @@ import io.sloeber.core.InternalBoardDescriptor; import io.sloeber.core.api.BoardDescriptor; +import io.sloeber.core.api.IInstallLibraryHandler; import io.sloeber.core.api.LibraryManager; import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; @@ -394,7 +395,8 @@ public static void checkLibraries(IProject affectedProject) { } UnresolvedIncludedHeaders.removeAll(alreadyAddedLibs); - + IInstallLibraryHandler installHandler =LibraryManager.getInstallLibraryHandler(); + if (installHandler.autoInstall()) { //Check if there are libraries that are not found in the installed libraries Map installedLibs = getAllInstalledLibraries(configurationDescription); Set uninstalledIncludedHeaders=new TreeSet<>(UnresolvedIncludedHeaders); @@ -408,13 +410,15 @@ public static void checkLibraries(IProject affectedProject) { //We now know which libraries to install //TODO for now I just install but there should be some user //interaction + availableLibs=installHandler.selectLibrariesToInstall(availableLibs); for (Entry curLib : availableLibs.entrySet()) { curLib.getValue().install(new NullProgressMonitor()); } } } + } - installedLibs = getAllInstalledLibraries(configurationDescription); + Map installedLibs = getAllInstalledLibraries(configurationDescription); installedLibs.keySet().retainAll(UnresolvedIncludedHeaders); if (!installedLibs.isEmpty()) { // there are possible libraries to add From b70f4e44c71a00eec1934be4a643e46330a7e115 Mon Sep 17 00:00:00 2001 From: jantje Date: Mon, 9 Oct 2017 23:35:03 +0200 Subject: [PATCH 05/10] didn't know how to merge the move --- io.sloeber.core/src/jUnit/CreateAndCompile.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 io.sloeber.core/src/jUnit/CreateAndCompile.java diff --git a/io.sloeber.core/src/jUnit/CreateAndCompile.java b/io.sloeber.core/src/jUnit/CreateAndCompile.java deleted file mode 100644 index e69de29bb..000000000 From 1fb2d8d3240f4855c04d78dc21074a154500dadd Mon Sep 17 00:00:00 2001 From: jantje Date: Tue, 10 Oct 2017 00:35:45 +0200 Subject: [PATCH 06/10] Adding librarydescriptor to api class --- .../core/api/IInstallLibraryHandler.java | 4 +--- .../sloeber/core/api/LibraryDescriptor.java | 17 ++++++++++++++ .../io/sloeber/core/api/LibraryManager.java | 19 +++++++++++----- .../core/core/DefaultInstallHandler.java | 4 ++-- .../sloeber/core/managers/LibraryIndex.java | 19 +++++++++++----- .../src/io/sloeber/core/tools/Libraries.java | 7 +++--- .../ui/listeners/MyLibraryInstallHandler.java | 22 +++++++++++++++++++ 7 files changed, 73 insertions(+), 19 deletions(-) create mode 100644 io.sloeber.core/src/io/sloeber/core/api/LibraryDescriptor.java create mode 100644 io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java diff --git a/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java b/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java index 49401d457..67ba31e46 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java +++ b/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java @@ -2,8 +2,6 @@ import java.util.Map; -import io.sloeber.core.managers.Library; - /** * this interface is to allow the ui to handle the automatic installation * of libraries. @@ -31,5 +29,5 @@ public interface IInstallLibraryHandler { * * @return The libraries the user wants to install */ - abstract Map selectLibrariesToInstall(Map proposedLibsToInstall); + abstract Map selectLibrariesToInstall(Map proposedLibsToInstall); } diff --git a/io.sloeber.core/src/io/sloeber/core/api/LibraryDescriptor.java b/io.sloeber.core/src/io/sloeber/core/api/LibraryDescriptor.java new file mode 100644 index 000000000..efe8a2402 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/LibraryDescriptor.java @@ -0,0 +1,17 @@ +package io.sloeber.core.api; + +import io.sloeber.core.managers.Library; + +public class LibraryDescriptor { + private Library library=null; + + public LibraryDescriptor(Library value) { + this.library=value; + } + + public Library toLibrary() { + // TODO Auto-generated method stub + return this.library; + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java index 699836ccf..f1454f60a 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java +++ b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java @@ -32,7 +32,16 @@ import io.sloeber.core.managers.Manager; import io.sloeber.core.managers.Messages; import io.sloeber.core.tools.Version; - +/** + * This class is the main entry point for libraries. + * It handles + * private libraries + * hardware libraries + * installed libraries + * + * @author jan + * + */ public class LibraryManager { static private List libraryIndices; private static IInstallLibraryHandler myInstallLibraryHandler = new DefaultInstallHandler(); @@ -360,8 +369,8 @@ public static void removeAllLibs() { * * @return a map of all instalable libraries */ - public static Map getAllInstallableLibraries() { - Map ret = new HashMap<>(); + public static Map getAllInstallableLibraries() { + Map ret = new HashMap<>(); for (LibraryIndex libraryIndex : libraryIndices) { ret.putAll(libraryIndex.getLatestInstallableLibraries()); } @@ -369,9 +378,9 @@ public static Map getAllInstallableLib return ret; } - public static Map getLatestInstallableLibraries(Set libnames) { + public static Map getLatestInstallableLibraries(Set libnames) { Set remainingLibNames = new TreeSet<>(libnames); - Map ret = new HashMap<>(); + Map ret = new HashMap<>(); for (LibraryIndex libraryIndex : libraryIndices) { ret.putAll(libraryIndex.getLatestInstallableLibraries(remainingLibNames)); remainingLibNames.removeAll(ret.keySet()); diff --git a/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java b/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java index 737636871..985ec95c4 100644 --- a/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java +++ b/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java @@ -3,7 +3,7 @@ import java.util.Map; import io.sloeber.core.api.IInstallLibraryHandler; -import io.sloeber.core.managers.Library; +import io.sloeber.core.api.LibraryDescriptor; public class DefaultInstallHandler implements IInstallLibraryHandler { @@ -14,7 +14,7 @@ public boolean autoInstall() { @Override - public Map selectLibrariesToInstall(Map proposedLibsToInstall) { + public Map selectLibrariesToInstall(Map proposedLibsToInstall) { return proposedLibsToInstall; } diff --git a/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java b/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java index a4599312d..a612602dc 100644 --- a/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java +++ b/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java @@ -12,8 +12,15 @@ import java.util.regex.Pattern; import io.sloeber.core.api.Defaults; +import io.sloeber.core.api.LibraryDescriptor; import io.sloeber.core.tools.Version; +/** + * This class represents a json file that references libraries + * + * @author jan + * + */ public class LibraryIndex { private String jsonFileName; private List libraries; @@ -101,11 +108,11 @@ public Map getLatestLibraries() { * * @return */ - public Map getLatestInstallableLibraries() { - Map ret = new HashMap<>(); + public Map getLatestInstallableLibraries() { + Map ret = new HashMap<>(); for (Entry curLibrary : this.latestLibs.entrySet()) { if (!curLibrary.getValue().isAVersionInstalled()) { - ret.put(curLibrary.getKey(), curLibrary.getValue()); + ret.put(curLibrary.getKey(),new LibraryDescriptor( curLibrary.getValue())); } } return ret; @@ -147,15 +154,15 @@ public String getName() { * * @return */ - public Map getLatestInstallableLibraries(Set libNames) { - Map ret = new HashMap<>(); + public Map getLatestInstallableLibraries(Set libNames) { + Map ret = new HashMap<>(); if (libNames.isEmpty()) { return ret; } for (Entry curLibrary : this.latestLibs.entrySet()) { if (libNames.contains(curLibrary.getKey())) { if (!curLibrary.getValue().isAVersionInstalled()) { - ret.put(curLibrary.getKey(), curLibrary.getValue()); + ret.put(curLibrary.getKey(), new LibraryDescriptor(curLibrary.getValue())); } } } diff --git a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java index adaa09121..b2320d19c 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java @@ -37,6 +37,7 @@ import io.sloeber.core.InternalBoardDescriptor; import io.sloeber.core.api.BoardDescriptor; import io.sloeber.core.api.IInstallLibraryHandler; +import io.sloeber.core.api.LibraryDescriptor; import io.sloeber.core.api.LibraryManager; import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; @@ -404,15 +405,15 @@ public static void checkLibraries(IProject affectedProject) { if(!uninstalledIncludedHeaders.isEmpty()) { //some libraries may need to be installed - Map availableLibs=LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders); + Map availableLibs=LibraryManager.getLatestInstallableLibraries(uninstalledIncludedHeaders); if(!availableLibs.isEmpty()) { //We now know which libraries to install //TODO for now I just install but there should be some user //interaction availableLibs=installHandler.selectLibrariesToInstall(availableLibs); - for (Entry curLib : availableLibs.entrySet()) { - curLib.getValue().install(new NullProgressMonitor()); + for (Entry curLib : availableLibs.entrySet()) { + curLib.getValue().toLibrary().install(new NullProgressMonitor()); } } } diff --git a/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java b/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java new file mode 100644 index 000000000..7b444424a --- /dev/null +++ b/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java @@ -0,0 +1,22 @@ +package io.sloeber.ui.listeners; + +import java.util.Map; + +import io.sloeber.core.api.IInstallLibraryHandler; +import io.sloeber.core.api.LibraryDescriptor; + +public class MyLibraryInstallHandler implements IInstallLibraryHandler { + + @Override + public boolean autoInstall() { + // TODO Auto-generated method stub + return true; + } + + @Override + public Map selectLibrariesToInstall(Map proposedLibsToInstall) { + // TODO Auto-generated method stub + return proposedLibsToInstall; + } + +} From 950f2aaa0fdf02a67bbca9d4fcecbd6aa47730a7 Mon Sep 17 00:00:00 2001 From: jantje Date: Tue, 10 Oct 2017 00:36:28 +0200 Subject: [PATCH 07/10] registering the myLibraryInstallHandler Still dummy class accepting all proposals --- io.sloeber.ui/src/io/sloeber/ui/Activator.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/io.sloeber.ui/src/io/sloeber/ui/Activator.java b/io.sloeber.ui/src/io/sloeber/ui/Activator.java index ac9e58ca7..bbb3ba389 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/Activator.java +++ b/io.sloeber.ui/src/io/sloeber/ui/Activator.java @@ -10,14 +10,16 @@ import org.eclipse.ui.statushandlers.StatusManager; import org.osgi.framework.BundleContext; +import io.sloeber.core.api.LibraryManager; import io.sloeber.ui.helpers.MyPreferences; +import io.sloeber.ui.listeners.MyLibraryInstallHandler; import io.sloeber.ui.listeners.ProjectExplorerListener; /** * generated code - * + * * @author Jan Baeyens - * + * */ public class Activator extends AbstractUIPlugin { @@ -39,6 +41,7 @@ private static void runGUIRegistration() { @Override public IStatus runInUIThread(IProgressMonitor monitor) { ProjectExplorerListener.registerListener(); + LibraryManager.registerInstallLibraryHandler(new MyLibraryInstallHandler());; return Status.OK_STATUS; } @@ -58,7 +61,7 @@ public static BundleContext getContext() { /** * Logs the status information - * + * * @param status * the status information to log */ @@ -83,7 +86,7 @@ private static void initializeImportantVariables() { /** * Returns an image descriptor for the image file at the given plug-in * relative path - * + * * @param path * the path * @return the image descriptor From 3f4efcb9ca35bf713aa13f8762d2d1eb51722021 Mon Sep 17 00:00:00 2001 From: jantje Date: Tue, 10 Oct 2017 00:36:41 +0200 Subject: [PATCH 08/10] Added some comments --- io.sloeber.core/src/io/sloeber/core/managers/Library.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/io.sloeber.core/src/io/sloeber/core/managers/Library.java b/io.sloeber.core/src/io/sloeber/core/managers/Library.java index db44c99d3..c31d048ec 100644 --- a/io.sloeber.core/src/io/sloeber/core/managers/Library.java +++ b/io.sloeber.core/src/io/sloeber/core/managers/Library.java @@ -21,6 +21,12 @@ import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.core.tools.FileModifiers; +/** + * This class represents an entry ina a library json file + * + * @author jan + * + */ public class Library implements Comparable { private String name; From b94c8556e20795efca8821554910d6e23ec12386 Mon Sep 17 00:00:00 2001 From: jantje Date: Wed, 11 Oct 2017 00:32:49 +0200 Subject: [PATCH 09/10] For #841 --- io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java b/io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java index d1188ee7a..b8f4acc3b 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java +++ b/io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java @@ -263,7 +263,7 @@ private void ParseSection(Map boardInfo) { String refArchitecture = valueSplit[1]; String refVersion = valueSplit[2]; String actualValue = valueSplit[3]; - this.myUploadTool = actualValue; + this.myBoardsCore = actualValue; this.myReferencedCorePlatformPath = Manager.getPlatformInstallPath(refVendor, refArchitecture, refVersion); if (this.myReferencedCorePlatformPath == null) { @@ -296,7 +296,7 @@ private void ParseSection(Map boardInfo) { String refArchitecture = valueSplit[1]; String refVersion = valueSplit[2]; String actualValue = valueSplit[3]; - this.myUploadTool = actualValue; + this.myBoardsVariant = actualValue; this.myReferencedBoardVariantPlatformPath = Manager.getPlatformInstallPath(refVendor, refArchitecture, refVersion); if (this.myReferencedBoardVariantPlatformPath == null) { From a7cbff82eb3328d4f1594eed7363e6a9679872ea Mon Sep 17 00:00:00 2001 From: jantje Date: Wed, 11 Oct 2017 01:07:14 +0200 Subject: [PATCH 10/10] Adding the gui part for #679 --- io.sloeber.ui/src/io/sloeber/ui/Messages.java | 1 + .../ui/listeners/MyLibraryInstallHandler.java | 3 ++- io.sloeber.ui/src/io/sloeber/ui/messages.properties | 1 + .../io/sloeber/ui/preferences/PreferencePage.java | 13 +++++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/io.sloeber.ui/src/io/sloeber/ui/Messages.java b/io.sloeber.ui/src/io/sloeber/ui/Messages.java index bc93caa2e..249e57f43 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/Messages.java +++ b/io.sloeber.ui/src/io/sloeber/ui/Messages.java @@ -26,6 +26,7 @@ public class Messages extends NLS { public static String ui_open_serial_with_monitor; public static String ui_build_before_upload; public static String ui_auto_import_libraries; + public static String ui_auto_install_libraries; public static String ui_import_arduino_libraries_in_project; public static String ui_import_arduino_libraries_in_project_help; diff --git a/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java b/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java index 7b444424a..e4f97282f 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java +++ b/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java @@ -4,13 +4,14 @@ import io.sloeber.core.api.IInstallLibraryHandler; import io.sloeber.core.api.LibraryDescriptor; +import io.sloeber.ui.preferences.PreferencePage; public class MyLibraryInstallHandler implements IInstallLibraryHandler { @Override public boolean autoInstall() { // TODO Auto-generated method stub - return true; + return PreferencePage.getAutomaticallyInstallLibrariesOption(); } @Override diff --git a/io.sloeber.ui/src/io/sloeber/ui/messages.properties b/io.sloeber.ui/src/io/sloeber/ui/messages.properties index 390ec13f7..355f88913 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/messages.properties +++ b/io.sloeber.ui/src/io/sloeber/ui/messages.properties @@ -21,6 +21,7 @@ ui_ask_every_upload=Ask every upload ui_build_before_upload=Build before upload? ui_open_serial_with_monitor=Open serial connections when opening the serial monitor? ui_auto_import_libraries=Automatically import libraries based on includes? +ui_auto_install_libraries=Automatically install missing libraries based on includes? ui_import_arduino_libraries_in_project=Import Arduino libraries ui_import_arduino_libraries_in_project_help=Use this page to select the libraries to import to project: ui_import_no_arduino_project_help=As no project is selected it is not possible to import a source folder diff --git a/io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java b/io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java index ac4afaa39..15ce8c590 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java +++ b/io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java @@ -40,6 +40,7 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe private static final String TRUE = "TRUE"; //$NON-NLS-1$ private static final String FALSE = "FALSE"; //$NON-NLS-1$ private static final String KEY_AUTO_IMPORT_LIBRARIES = "Gui entry for import libraries"; //$NON-NLS-1$ + private static final String KEY_AUTO_INSTALL_LIBRARIES = "Gui entry for install libraries"; //$NON-NLS-1$ private static final String KEY_PRAGMA_ONCE_HEADERS = "Gui entry for add pragma once"; //$NON-NLS-1$ private static final String KEY_PRIVATE_HARDWARE_PATHS = "Gui entry for private hardware paths"; //$NON-NLS-1$ private static final String KEY_PRIVATE_LIBRARY_PATHS = "Gui entry for private library paths"; //$NON-NLS-1$ @@ -50,6 +51,7 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe private ComboFieldEditor buildBeforeUploadOptionEditor; private BooleanFieldEditor openSerialMonitorOpensSerialsOptionEditor; private BooleanFieldEditor automaticallyImportLibrariesOptionEditor; + private BooleanFieldEditor automaticallyInstallLibrariesOptionEditor; private BooleanFieldEditor useArduinoToolchainSelectionEditor; private BooleanFieldEditor pragmaOnceHeaderOptionEditor; private BooleanFieldEditor cleanSerialMonitorAfterUploadEditor; @@ -63,6 +65,7 @@ public PreferencePage() { preferences.setDefault(MyPreferences.KEY_OPEN_SERIAL_WITH_MONITOR, MyPreferences.DEFAULT_OPEN_SERIAL_WITH_MONITOR); preferences.setDefault(KEY_AUTO_IMPORT_LIBRARIES, true); + preferences.setDefault(KEY_AUTO_INSTALL_LIBRARIES, true); preferences.setDefault(KEY_PRAGMA_ONCE_HEADERS, true); preferences.setDefault(KEY_PRIVATE_HARDWARE_PATHS, Defaults.getPrivateHardwarePath()); preferences.setDefault(KEY_PRIVATE_LIBRARY_PATHS, Defaults.getPrivateLibraryPath()); @@ -167,6 +170,9 @@ protected void createFieldEditors() { this.automaticallyImportLibrariesOptionEditor = new BooleanFieldEditor(KEY_AUTO_IMPORT_LIBRARIES, Messages.ui_auto_import_libraries, BooleanFieldEditor.DEFAULT, parent); addField(this.automaticallyImportLibrariesOptionEditor); + this.automaticallyInstallLibrariesOptionEditor = new BooleanFieldEditor(KEY_AUTO_INSTALL_LIBRARIES, + Messages.ui_auto_install_libraries, BooleanFieldEditor.DEFAULT, parent); + addField(this.automaticallyInstallLibrariesOptionEditor); this.pragmaOnceHeaderOptionEditor = new BooleanFieldEditor(KEY_PRAGMA_ONCE_HEADERS, Messages.ui_pragma_once_headers, BooleanFieldEditor.DEFAULT, parent); @@ -213,4 +219,11 @@ private static void createLine(Composite parent, int ncol) { line.setLayoutData(gridData); } + public static boolean getAutomaticallyInstallLibrariesOption() { + ScopedPreferenceStore preferences = new ScopedPreferenceStore(InstanceScope.INSTANCE, + MyPreferences.NODE_ARDUINO); + preferences.setDefault(KEY_AUTO_INSTALL_LIBRARIES, true); + return preferences.getBoolean(KEY_AUTO_INSTALL_LIBRARIES); + } + }