diff --git a/io.sloeber.core/META-INF/MANIFEST.MF b/io.sloeber.core/META-INF/MANIFEST.MF index e5806ea18..b5dfd5f7e 100644 --- a/io.sloeber.core/META-INF/MANIFEST.MF +++ b/io.sloeber.core/META-INF/MANIFEST.MF @@ -32,6 +32,7 @@ Export-Package: cc.arduino.packages;x-internal:=true, cc.arduino.packages.ssh;x-internal:=true, io.sloeber.core;x-friends:="io.sloeber.tests", io.sloeber.core.api, + io.sloeber.core.api.Json, io.sloeber.core.builder;x-internal:=true, io.sloeber.core.common;x-friends:="io.sloeber.tests", io.sloeber.core.communication;x-internal:=true, diff --git a/io.sloeber.core/config/pre_processing_platform_default.txt b/io.sloeber.core/config/pre_processing_platform_default.txt index 898092e57..d2bcbfb9d 100644 --- a/io.sloeber.core/config/pre_processing_platform_default.txt +++ b/io.sloeber.core/config/pre_processing_platform_default.txt @@ -4,7 +4,6 @@ recipe.objcopy.hex.pattern=${recipe.objcopy.bin.pattern} archive_file=arduino.ar archive_file_path=${build.path}/${archive_file} runtime.ide.version=10812 -build.system.path=${referenced.core.path}${DirectoryDelimiter}system serial.port=${com_port} build.project_name=${ProjName} diff --git a/io.sloeber.core/src/io/sloeber/core/Activator.java b/io.sloeber.core/src/io/sloeber/core/Activator.java index 35577dc93..0bed083fb 100644 --- a/io.sloeber.core/src/io/sloeber/core/Activator.java +++ b/io.sloeber.core/src/io/sloeber/core/Activator.java @@ -1,7 +1,6 @@ package io.sloeber.core; import static io.sloeber.core.common.Const.*; -import static io.sloeber.core.managers.InternalPackageManager.*; import static org.eclipse.core.resources.IResource.*; import java.io.File; @@ -42,13 +41,14 @@ import org.osgi.service.prefs.Preferences; import cc.arduino.packages.discoverers.SloeberNetworkDiscovery; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.core.common.InstancePreferences; import io.sloeber.core.listeners.ConfigurationChangeListener; import io.sloeber.core.listeners.IndexerListener; import io.sloeber.core.listeners.resourceChangeListener; +import io.sloeber.core.tools.PackageManager; /** * generated code @@ -207,14 +207,13 @@ private static void initializeImportantVariables() { try { workspace.setDescription(workspaceDesc); } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, e.getMessage(), e)); } // Make sure some important variables are being initialized InstancePreferences.setPrivateLibraryPaths(InstancePreferences.getPrivateLibraryPaths()); InstancePreferences.setPrivateHardwarePaths(InstancePreferences.getPrivateHardwarePaths()); InstancePreferences.setAutomaticallyImportLibraries(InstancePreferences.getAutomaticallyImportLibraries()); - PackageManager.setJsonURLs(PackageManager.getJsonURLs()); + BoardsManager.setJsonURLs(BoardsManager.getJsonURLs()); } private void runPluginCoreStartInstantiatorJob() { @@ -252,7 +251,7 @@ protected IStatus run(IProgressMonitor monitor) { installOtherStuff(); - startup_Pluging(monitor); + BoardsManager.startup_Pluging(monitor); monitor.setTaskName("Done!"); if (InstancePreferences.useBonjour()) { @@ -418,14 +417,14 @@ private static void installOtherStuff() { } if (!localMakePath.append(MAKE_EXE).toFile().exists()) { IProgressMonitor monitor = new NullProgressMonitor(); - Common.log(downloadAndInstall(MAKE_URL, MAKE_ZIP, localMakePath, false, monitor)); + Common.log(PackageManager.downloadAndInstall(MAKE_URL, MAKE_ZIP, localMakePath, false, monitor)); } // Install awk if needed IPath localAwkPath = ConfigurationPreferences.getAwkPath(); if (!localAwkPath.append(AWK_EXE).toFile().exists()) { IProgressMonitor monitor = new NullProgressMonitor(); - Common.log(downloadAndInstall(AWK_URL, AWK_ZIP, localAwkPath, false, monitor)); + Common.log(PackageManager.downloadAndInstall(AWK_URL, AWK_ZIP, localAwkPath, false, monitor)); } } } diff --git a/io.sloeber.core/src/io/sloeber/core/Gson/GsonConverter.java b/io.sloeber.core/src/io/sloeber/core/Gson/GsonConverter.java new file mode 100644 index 000000000..7f797bf60 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/Gson/GsonConverter.java @@ -0,0 +1,40 @@ +package io.sloeber.core.Gson; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import io.sloeber.core.api.VersionNumber; + +public class GsonConverter { + public static String getSafeString(JsonObject jsonObject, String fieldName) { + JsonElement field = jsonObject.get(fieldName); + if (field == null) { + return "no info found in file"; //$NON-NLS-1$ + } + return field.getAsString(); + + } + + public static VersionNumber getSafeVersion(JsonObject jsonObject, String fieldName) { + JsonElement field = jsonObject.get(fieldName); + if (field == null) { + return new VersionNumber("no version number provided"); //$NON-NLS-1$ + } + return new VersionNumber(field.getAsString()); + + } + + public static String getSafeString(JsonObject jsonObject, String fieldName1, String fieldName2) { + JsonElement field = jsonObject.get(fieldName1); + if (field != null) { + field = field.getAsJsonObject().get(fieldName2); + if (field != null) { + return field.getAsString(); + } + } + + return "no info found in file"; //$NON-NLS-1$ + + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java b/io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java index 130d7515b..5b6ce801f 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java +++ b/io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java @@ -22,11 +22,12 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; +import io.sloeber.core.api.Json.ArduinoPlatform; +import io.sloeber.core.api.Json.ArduinoPlatformTooldDependency; +import io.sloeber.core.api.Json.ArduinoPlatformVersion; import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; -import io.sloeber.core.managers.ArduinoPlatform; -import io.sloeber.core.managers.InternalPackageManager; -import io.sloeber.core.tools.Helpers; +import io.sloeber.core.common.Const; import io.sloeber.core.tools.KeyValue; import io.sloeber.core.txt.BoardTxtFile; import io.sloeber.core.txt.KeyValueTree; @@ -35,13 +36,6 @@ import io.sloeber.core.txt.TxtFile; public class BoardDescription { - // Important constants to avoid having to add the class - private static final String VendorArduino = ARDUINO; - - /* - * Some constants - */ - private static final String REFERENCED = "referenced"; //$NON-NLS-1$ private static final String KEY_LAST_USED_BOARD = "Last used Board"; //$NON-NLS-1$ private static final String KEY_LAST_USED_UPLOAD_PORT = "Last Used Upload port"; //$NON-NLS-1$ private static final String KEY_LAST_USED_UPLOAD_PROTOCOL = "last Used upload Protocol"; //$NON-NLS-1$ @@ -51,20 +45,19 @@ public class BoardDescription { private static final String ENV_KEY_SERIAL_DOT_PORT = "serial.port"; //$NON-NLS-1$ private static final String ENV_KEY_SERIAL_PORT_FILE = "serial.port.file"; //$NON-NLS-1$ private static final String ENV_KEY_BUILD_VARIANT_PATH = BUILD + DOT + VARIANT + DOT + PATH; + private static final String ENV_KEY_BUILD_SYSTEM_PATH = BUILD + DOT + SYSTEM + DOT + PATH; private static final String ENV_KEY_BUILD_ACTUAL_CORE_PATH = BUILD + DOT + CORE + DOT + PATH; private static final String ENV_KEY_BUILD_ARCH = BUILD + DOT + "arch"; //$NON-NLS-1$ private static final String ENV_KEY_HARDWARE_PATH = RUNTIME + DOT + HARDWARE + DOT + PATH; private static final String ENV_KEY_PLATFORM_PATH = RUNTIME + DOT + PLATFORM + DOT + PATH; - private static final String ENV_KEY_REFERENCED_CORE_PLATFORM_PATH = REFERENCED + DOT + CORE + DOT + PATH; - private static final String ENV_KEY_REFERENCED_VARIANT_PLATFORM_PATH = REFERENCED + DOT + VARIANT + DOT + PATH; - private static final String ENV_KEY_REFERENCED_UPLOAD_PLATFORM_PATH = REFERENCED + DOT + UPLOAD + PATH; - // preference nodes + // stuff to store last used board + private final String KEY_SLOEBER_PROGRAMMER = "PROGRAMMER.NAME"; //$NON-NLS-1$ + private final String KEY_SLOEBER_BOARD_TXT = "BOARD.TXT"; //$NON-NLS-1$ + private final String KEY_SLOEBER_BOARD_ID = "BOARD.ID"; //$NON-NLS-1$ + private final String KEY_SLOEBER_UPLOAD_PORT = "UPLOAD.PORT"; //$NON-NLS-1$ + private final String KEY_SLOEBER_MENU_SELECTION = "BOARD.MENU"; //$NON-NLS-1$ private static final IEclipsePreferences myStorageNode = InstanceScope.INSTANCE.getNode(NODE_ARDUINO); - private static final TxtFile pluginPreProcessingPlatformTxt = new TxtFile( - ConfigurationPreferences.getPreProcessingPlatformFile()); - private static final TxtFile pluginPostProcessingPlatformTxt = new TxtFile( - ConfigurationPreferences.getPostProcessingPlatformFile()); /* * This is the basic info contained in the descriptor @@ -73,25 +66,17 @@ public class BoardDescription { private String myProgrammer = EMPTY; private String myBoardID = EMPTY; private Map myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + private BoardTxtFile myBoardTxtFile; + + private String myBoardsCore = null; + private String myBoardsVariant = null; + private String myUploadTool = null; + + private ArduinoPlatformVersion myReferencedPlatformVariant = null; + private ArduinoPlatformVersion myReferencedPlatformCore = null; + private ArduinoPlatformVersion myReferencedPlatformUpload = null; - /* - * Stuff to make things work - */ - private File myreferencingBoardsFile; - protected BoardTxtFile myBoardTxtFile; - - private String myBoardsVariant; - private IPath myReferencedBoardVariantPlatformPath; - private String myBoardsCore; - private IPath myReferencedCorePlatformPath; - private IPath myReferencedUploadToolPlatformPath; - private String myUploadTool; private boolean isDirty = true; - private final String KEY_SLOEBER_PROGRAMMER = "PROGRAMMER.NAME"; //$NON-NLS-1$ - private final String KEY_SLOEBER_BOARD_TXT = "BOARD.TXT"; //$NON-NLS-1$ - private final String KEY_SLOEBER_BOARD_ID = "BOARD.ID"; //$NON-NLS-1$ - private final String KEY_SLOEBER_UPLOAD_PORT = "UPLOAD.PORT"; //$NON-NLS-1$ - private final String KEY_SLOEBER_MENU_SELECTION = "BOARD.MENU"; //$NON-NLS-1$ @Override public String toString() { @@ -133,8 +118,8 @@ public boolean needsRebuild(BoardDescription otherBoardDescriptor) { if (!this.getBoardID().equals(otherBoardDescriptor.getBoardID())) { return true; } - String moddedReferencingBoardsFile = makePathEnvironmentString(getReferencingBoardsFile()); - String moddedOtherReferencingBoardsFile = makePathEnvironmentString( + String moddedReferencingBoardsFile = makePathVersionString(getReferencingBoardsFile()); + String moddedOtherReferencingBoardsFile = makePathVersionString( otherBoardDescriptor.getReferencingBoardsFile()); if (!moddedReferencingBoardsFile.equals(moddedOtherReferencingBoardsFile)) { return true; @@ -151,11 +136,11 @@ public boolean needsRebuild(BoardDescription otherBoardDescriptor) { */ private void calculateDerivedFields() { - myReferencedCorePlatformPath = getreferencingPlatformPath(); + myReferencedPlatformCore = null; myBoardsCore = null; - myReferencedBoardVariantPlatformPath = myReferencedCorePlatformPath; + myReferencedPlatformVariant = null; myBoardsVariant = null; - myReferencedUploadToolPlatformPath = myReferencedCorePlatformPath; + myReferencedPlatformUpload = null; myUploadTool = null; setDefaultOptions(); // search in the board info @@ -192,10 +177,9 @@ private void ParseSection() { String valueSplit[] = core.split(COLON); if (valueSplit.length == 2) { String refVendor = valueSplit[0]; - String actualValue = valueSplit[1]; - myBoardsCore = actualValue; - myReferencedCorePlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, architecture); - if (this.myReferencedCorePlatformPath == null) { + myBoardsCore = valueSplit[1]; + myReferencedPlatformCore = BoardsManager.getNewestInstalledPlatform(refVendor, architecture); + if (myReferencedPlatformCore == null) { Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, core) .replace(FILE_TAG, getReferencingBoardsFile().toString()) @@ -205,12 +189,10 @@ private void ParseSection() { } else if (valueSplit.length == 4) { String refVendor = valueSplit[0]; String refArchitecture = valueSplit[1]; - String refVersion = valueSplit[2]; - String actualValue = valueSplit[3]; - myBoardsCore = actualValue; - myReferencedCorePlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, refArchitecture, - refVersion); - if (this.myReferencedCorePlatformPath == null) { + VersionNumber refVersion = new VersionNumber(valueSplit[2]); + myBoardsCore = valueSplit[3]; + myReferencedPlatformCore = BoardsManager.getPlatform(refVendor, refArchitecture, refVersion); + if (myReferencedPlatformCore == null) { Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, core) .replace(FILE_TAG, getReferencingBoardsFile().toString()) @@ -225,11 +207,9 @@ private void ParseSection() { String valueSplit[] = variant.split(COLON); if (valueSplit.length == 2) { String refVendor = valueSplit[0]; - String actualValue = valueSplit[1]; - this.myBoardsVariant = actualValue; - this.myReferencedBoardVariantPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, - architecture); - if (this.myReferencedBoardVariantPlatformPath == null) { + myBoardsVariant = valueSplit[1]; + myReferencedPlatformVariant = BoardsManager.getNewestInstalledPlatform(refVendor, architecture); + if (myReferencedPlatformVariant == null) { Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, variant) .replace(FILE_TAG, getReferencingBoardsFile().toString()) @@ -239,17 +219,14 @@ private void ParseSection() { } else if (valueSplit.length == 4) { String refVendor = valueSplit[0]; String refArchitecture = valueSplit[1]; - String refVersion = valueSplit[2]; - String actualValue = valueSplit[3]; - this.myBoardsVariant = actualValue; - if ("*".equals(refVersion)) { //$NON-NLS-1$ - this.myReferencedBoardVariantPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, - refArchitecture); + VersionNumber refVersion = new VersionNumber(valueSplit[2]); + myBoardsVariant = valueSplit[3]; + if ("*".equals(valueSplit[2])) { //$NON-NLS-1$ + myReferencedPlatformVariant = BoardsManager.getNewestInstalledPlatform(refVendor, refArchitecture); } else { - this.myReferencedBoardVariantPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, - refArchitecture, refVersion); + myReferencedPlatformVariant = BoardsManager.getPlatform(refVendor, refArchitecture, refVersion); } - if (this.myReferencedBoardVariantPlatformPath == null) { + if (myReferencedPlatformVariant == null) { Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, variant) .replace(FILE_TAG, getReferencingBoardsFile().toString()) @@ -264,11 +241,9 @@ private void ParseSection() { String valueSplit[] = upload.split(COLON); if (valueSplit.length == 2) { String refVendor = valueSplit[0]; - String actualValue = valueSplit[1]; - this.myUploadTool = actualValue; - this.myReferencedUploadToolPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, - architecture); - if (this.myReferencedUploadToolPlatformPath == null) { + myUploadTool = valueSplit[1]; + myReferencedPlatformUpload = BoardsManager.getNewestInstalledPlatform(refVendor, architecture); + if (myReferencedPlatformUpload == null) { Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, upload) .replace(FILE_TAG, getReferencingBoardsFile().toString()) @@ -278,12 +253,10 @@ private void ParseSection() { } else if (valueSplit.length == 4) { String refVendor = valueSplit[0]; String refArchitecture = valueSplit[1]; - String refVersion = valueSplit[2]; - String actualValue = valueSplit[3]; - this.myUploadTool = actualValue; - this.myReferencedUploadToolPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, - refArchitecture, refVersion); - if (this.myReferencedUploadToolPlatformPath == null) { + VersionNumber refVersion = new VersionNumber(valueSplit[2]); + myUploadTool = valueSplit[3]; + myReferencedPlatformUpload = BoardsManager.getPlatform(refVendor, refArchitecture, refVersion); + if (this.myReferencedPlatformUpload == null) { Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, Helpers_tool_reference_missing.replace(TOOL_TAG, upload) .replace(FILE_TAG, getReferencingBoardsFile().toString()) @@ -303,15 +276,15 @@ private void ParseSection() { * @param boardFile * @return a list of board descriptors */ - public static List makeBoardDescriptors(File boardFile, Map options) { + public static List makeBoardDescriptors(File boardFile) { BoardTxtFile txtFile = new BoardTxtFile(resolvePathEnvironmentString(boardFile)); List boards = new ArrayList<>(); - String[] allSectionNames = txtFile.getAllSectionNames(); - for (String curboardName : allSectionNames) { - Map boardSection = txtFile.getSection(txtFile.getIDFromNiceName(curboardName)); + List boardIDs = txtFile.getAllBoardIDs(); + for (String curboardID : boardIDs) { + Map boardSection = txtFile.getSection(curboardID); if (boardSection != null) { if (!"true".equalsIgnoreCase(boardSection.get("hide"))) { //$NON-NLS-1$ //$NON-NLS-2$ - boards.add(new BoardDescription(boardFile, txtFile.getIDFromNiceName(curboardName), options)); + boards.add(new BoardDescription(boardFile, curboardID, null)); } } } @@ -327,19 +300,17 @@ public static List makeBoardDescriptors(File boardFile, Map options) { - this.myBoardID = boardID; - this.myreferencingBoardsFile = resolvePathEnvironmentString(boardsFile); - this.myBoardTxtFile = new BoardTxtFile(this.myreferencingBoardsFile); + myBoardID = boardID; + myBoardTxtFile = new BoardTxtFile(resolvePathEnvironmentString(boardsFile)); setDefaultOptions(); if (options != null) { - this.myOptions.putAll(options); + myOptions.putAll(options); } } public BoardDescription() { - myreferencingBoardsFile = resolvePathEnvironmentString( - new File(myStorageNode.get(KEY_LAST_USED_BOARDS_FILE, EMPTY))); - myBoardTxtFile = new BoardTxtFile(this.myreferencingBoardsFile); + File boardsFile = new File(myStorageNode.get(KEY_LAST_USED_BOARDS_FILE, EMPTY)); + myBoardTxtFile = new BoardTxtFile(boardsFile); myBoardID = myStorageNode.get(KEY_LAST_USED_BOARD, EMPTY); myUploadPort = myStorageNode.get(KEY_LAST_USED_UPLOAD_PORT, EMPTY); myProgrammer = myStorageNode.get(KEY_LAST_USED_UPLOAD_PROTOCOL, EMPTY); @@ -347,7 +318,6 @@ public BoardDescription() { } public BoardDescription(BoardDescription srcObject) { - myreferencingBoardsFile = srcObject.myreferencingBoardsFile; myBoardTxtFile = srcObject.myBoardTxtFile; myBoardID = srcObject.myBoardID; myUploadPort = srcObject.myUploadPort; @@ -370,7 +340,8 @@ private void setDefaultOptions() { Map allMenuIDs = this.myBoardTxtFile.getMenus(); for (Map.Entry curMenuID : allMenuIDs.entrySet()) { String providedMenuValue = this.myOptions.get(curMenuID.getKey()); - ArrayList menuOptions = this.myBoardTxtFile.getMenuItemIDsFromMenuID(curMenuID.getKey(), getBoardID()); + ArrayList menuOptions = this.myBoardTxtFile.getMenuItemIDsFromMenuID(curMenuID.getKey(), + getBoardID()); if (menuOptions.size() > 0) { if (providedMenuValue == null) { @@ -387,7 +358,7 @@ private void setDefaultOptions() { * project */ public void saveUserSelection() { - myStorageNode.put(KEY_LAST_USED_BOARDS_FILE, makePathEnvironmentString(getReferencingBoardsFile())); + myStorageNode.put(KEY_LAST_USED_BOARDS_FILE, getReferencingBoardsFile().toString()); myStorageNode.put(KEY_LAST_USED_BOARD, this.myBoardID); myStorageNode.put(KEY_LAST_USED_UPLOAD_PORT, this.myUploadPort); myStorageNode.put(KEY_LAST_USED_UPLOAD_PROTOCOL, this.myProgrammer); @@ -395,11 +366,11 @@ public void saveUserSelection() { } public String getArchitecture() { - return this.myBoardTxtFile.getArchitecture(); + return myBoardTxtFile.getArchitecture(); } public File getReferencingBoardsFile() { - return this.myreferencingBoardsFile; + return myBoardTxtFile.getLoadedFile(); } public String getBoardName() { @@ -471,8 +442,7 @@ public void setreferencingBoardsFile(File boardsFile) { * )) { return; } */ - this.myreferencingBoardsFile = resolvePathEnvironmentString(boardsFile); - this.myBoardTxtFile = new BoardTxtFile(this.myreferencingBoardsFile); + myBoardTxtFile = new BoardTxtFile(resolvePathEnvironmentString(boardsFile)); setDirty(); } @@ -546,14 +516,15 @@ public String getMenuItemIDFromMenuItemName(String menuItemName, String menuID) */ public IPath getActualVariantPath() { updateWhenDirty(); - if (getBoardVariant() == null) { + String boardVariant = getBoardVariant(); + if (boardVariant == null) { return null; } - IPath retPath = getReferencedVariantPlatformPath(); - if (retPath == null) { - retPath = getreferencingPlatformPath(); + if (myReferencedPlatformVariant == null) { + return new Path(myBoardTxtFile.getLoadedFile().getParent().toString()).append(VARIANTS_FOLDER_NAME) + .append(boardVariant); } - return retPath.append(VARIANTS_FOLDER_NAME).append(getBoardVariant()); + return myReferencedPlatformVariant.getInstallPath().append(VARIANTS_FOLDER_NAME).append(boardVariant); } private String getBoardVariant() { @@ -563,42 +534,22 @@ private String getBoardVariant() { public IPath getActualCoreCodePath() { updateWhenDirty(); - IPath retPath = getReferencedCorePlatformPath(); - if (retPath == null) { - retPath = getreferencingPlatformPath(); - } - if (this.myBoardsCore == null) { + if (myBoardsCore == null) { return null; } - return retPath.append(CORES).append(this.myBoardsCore); - } - - /** - * provide the actual path to the variant. Use this method if you want to know - * where the variant is - * - * @return the path to the variant - */ - public IPath getReferencedCorePlatformPath() { - updateWhenDirty(); - if (myReferencedCorePlatformPath != null) { - return myReferencedCorePlatformPath; + IPath retPath = null; + if (myReferencedPlatformCore == null) { + retPath = getreferencingPlatformPath(); + } else { + retPath = myReferencedPlatformCore.getInstallPath(); } - return getreferencingPlatformPath(); + return retPath.append(CORES).append(myBoardsCore); } public IPath getReferencedUploadPlatformPath() { updateWhenDirty(); - if (myReferencedUploadToolPlatformPath != null) { - return myReferencedUploadToolPlatformPath; - } - return getreferencingPlatformPath(); - } - - public IPath getReferencedVariantPlatformPath() { - updateWhenDirty(); - if (myReferencedBoardVariantPlatformPath != null) { - return myReferencedBoardVariantPlatformPath; + if (myReferencedPlatformUpload != null) { + return myReferencedPlatformUpload.getInstallPath(); } return getreferencingPlatformPath(); } @@ -614,30 +565,30 @@ public PlatformTxtFile getReferencingPlatformFile() { public Path getreferencingPlatformPath() { try { - return new Path(this.myreferencingBoardsFile.getParent()); + return new Path(myBoardTxtFile.getLoadedFile().getParent()); } catch (@SuppressWarnings("unused") Exception e) { return new Path(EMPTY); } } - public PlatformTxtFile getreferencedPlatformFile() { + public PlatformTxtFile getreferencedCorePlatformFile() { updateWhenDirty(); - if (this.myReferencedCorePlatformPath == null) { + if (myReferencedPlatformCore == null) { return null; } - File platformFile = myReferencedCorePlatformPath.append(PLATFORM_FILE_NAME).toFile(); + File platformFile = myReferencedPlatformCore.getInstallPath().append(PLATFORM_FILE_NAME).toFile(); if (platformFile != null && platformFile.exists()) { return new PlatformTxtFile(platformFile); } return null; } - public IPath getReferencedLibraryPath() { + public IPath getReferencedCoreLibraryPath() { updateWhenDirty(); - if (this.myReferencedCorePlatformPath == null) { + if (myReferencedPlatformCore == null) { return null; } - return this.myReferencedCorePlatformPath.append(LIBRARY_PATH_SUFFIX); + return this.myReferencedPlatformCore.getInstallPath().append(LIBRARY_PATH_SUFFIX); } public IPath getReferencingLibraryPath() { @@ -655,10 +606,12 @@ public String getUploadPatternKey() { return TOOLS + DOT + upLoadTool + DOT + UPLOAD + DOT + networkPrefix + PATTERN; } - public IPath getreferencedHardwarePath() { + public IPath getreferencedCoreHardwarePath() { updateWhenDirty(); - IPath platformPath = getReferencedCorePlatformPath(); - return platformPath.removeLastSegments(1); + if (myReferencedPlatformCore == null) { + return new Path(myBoardTxtFile.getLoadedFile().toString()).removeLastSegments(1); + } + return myReferencedPlatformCore.getInstallPath(); } /* @@ -668,7 +621,15 @@ public IPath getreferencedHardwarePath() { */ public IPath getArduinoPlatformPath() { updateWhenDirty(); - return InternalPackageManager.getPlatformInstallPath(VendorArduino, getArchitecture()); + ArduinoPlatform platform = BoardsManager.getPlatform(VendorArduino, getArchitecture()); + if (platform == null) { + return null; + } + ArduinoPlatformVersion platformVersion = platform.getNewestInstalled(); + if(platformVersion==null) { + return null; + } + return platformVersion.getInstallPath(); } /** @@ -695,9 +656,8 @@ public boolean isNetworkUpload() { } protected BoardDescription(File txtFile, String boardID) { - this.myBoardID = boardID; - this.myreferencingBoardsFile = txtFile; - this.myBoardTxtFile = new BoardTxtFile(txtFile); + myBoardID = boardID; + myBoardTxtFile = new BoardTxtFile(txtFile); setDefaultOptions(); calculateDerivedFields(); } @@ -706,15 +666,15 @@ protected BoardDescription(File txtFile, String boardID) { KeyValueTree tree = configFile.getData(); KeyValueTree section = tree.getChild(prefix); - this.myProgrammer = section.getValue(KEY_SLOEBER_PROGRAMMER); - this.myBoardID = section.getValue(KEY_SLOEBER_BOARD_ID); + myProgrammer = section.getValue(KEY_SLOEBER_PROGRAMMER); + myBoardID = section.getValue(KEY_SLOEBER_BOARD_ID); String board_txt = section.getValue(KEY_SLOEBER_BOARD_TXT); - this.myUploadPort = section.getValue(KEY_SLOEBER_UPLOAD_PORT); + myUploadPort = section.getValue(KEY_SLOEBER_UPLOAD_PORT); KeyValueTree optionsTree = section.getChild(KEY_SLOEBER_MENU_SELECTION); Map options = optionsTree.toKeyValues(EMPTY, false); - myreferencingBoardsFile = resolvePathEnvironmentString(new File(board_txt)); - this.myBoardTxtFile = new BoardTxtFile(this.myreferencingBoardsFile); + File ResolvedFile = resolvePathEnvironmentString(new File(board_txt)); + myBoardTxtFile = new BoardTxtFile(ResolvedFile); setDefaultOptions(); if (options != null) { // Only add the valid options for this board to our options @@ -802,6 +762,8 @@ public Map getEnvVarsVersion(String prefix) { public Map getEnvVars() { updateWhenDirty(); + TxtFile pluginPreProcessingPlatformTxt = new TxtFile(ConfigurationPreferences.getPreProcessingPlatformFile()); + TxtFile pluginPostProcessingPlatformTxt = new TxtFile(ConfigurationPreferences.getPostProcessingPlatformFile()); BoardTxtFile pluginPreProcessingBoardsTxt = new BoardTxtFile( ConfigurationPreferences.getPreProcessingBoardsFile()); BoardTxtFile pluginPostProcessingBoardsTxt = new BoardTxtFile( @@ -811,8 +773,10 @@ public Map getEnvVars() { allVars.putAll(pluginPreProcessingBoardsTxt.getBoardEnvironVars(getBoardID())); String architecture = getArchitecture(); + IPath coreHardwarePath = getreferencedCoreHardwarePath(); allVars.put(ENV_KEY_BUILD_ARCH, architecture.toUpperCase()); - allVars.put(ENV_KEY_HARDWARE_PATH, getreferencedHardwarePath().toOSString()); + allVars.put(ENV_KEY_HARDWARE_PATH, coreHardwarePath.removeLastSegments(1).toOSString()); + allVars.put(ENV_KEY_BUILD_SYSTEM_PATH, coreHardwarePath.append(SYSTEM).toOSString()); allVars.put(ENV_KEY_PLATFORM_PATH, getreferencingPlatformPath().toOSString()); allVars.put(ENV_KEY_SERIAL_PORT, getActualUploadPort()); @@ -829,14 +793,7 @@ public Map getEnvVars() { allVars.put(ENV_KEY_BUILD_VARIANT_PATH, EMPTY); } - // the entries below are only saved for special platforms that heavily rely on - // referencing such as jantjes hardware - - allVars.put(ENV_KEY_REFERENCED_CORE_PLATFORM_PATH, getReferencedCorePlatformPath().toOSString()); - allVars.put(ENV_KEY_REFERENCED_VARIANT_PLATFORM_PATH, getReferencedVariantPlatformPath().toOSString()); - allVars.put(ENV_KEY_REFERENCED_UPLOAD_PLATFORM_PATH, getReferencedUploadPlatformPath().toOSString()); - - PlatformTxtFile referencedPlatfromFile = getreferencedPlatformFile(); + PlatformTxtFile referencedPlatfromFile = getreferencedCorePlatformFile(); // process the platform file referenced by the boards.txt if (referencedPlatfromFile != null) { allVars.putAll(referencedPlatfromFile.getAllEnvironVars()); @@ -853,7 +810,6 @@ public Map getEnvVars() { Programmers localProgrammers[] = Programmers.fromBoards(this); String programmer = getProgrammer(); for (Programmers curProgrammer : localProgrammers) { - // allVars.putAll(curProgrammer.getAllEnvironVars()); String programmerID = curProgrammer.getIDFromNiceName(programmer); if (programmerID != null) { allVars.putAll(curProgrammer.getAllEnvironVars(programmerID)); @@ -885,31 +841,66 @@ public Map getEnvVars() { } private Map getEnVarPlatformInfo() { + Map ret = new HashMap<>(); IPath referencingPlatformPath = getreferencingPlatformPath(); - IPath referencedPlatformPath = getReferencedCorePlatformPath(); + ArduinoPlatformVersion referencingPlatform = BoardsManager.getPlatform(referencingPlatformPath); - if ((referencingPlatformPath == null) || (referencedPlatformPath == null)) { - // something is seriously wrong -->shoot - return new HashMap<>(); + if (referencingPlatform == null) { + // This is the case for private hardware + //there is no need to specify tool path as they do not use them + return ret; + } + ArduinoPlatformVersion latestArduinoPlatform = BoardsManager.getNewestInstalledPlatform(Const.ARDUINO, + referencingPlatform.getArchitecture()); + if (latestArduinoPlatform != null) { + ret.putAll(getEnvVarPlatformFileTools(latestArduinoPlatform)); } - ArduinoPlatform referencingPlatform = InternalPackageManager.getPlatform(referencingPlatformPath); - ArduinoPlatform referencedPlatform = InternalPackageManager.getPlatform(referencedPlatformPath); + if (myReferencedPlatformCore == null) { + //there is no referenced core so no need to do smart stuff + ret.putAll(getEnvVarPlatformFileTools(referencingPlatform)); + return ret; + } boolean jsonBasedPlatformManagement = !Preferences.getUseArduinoToolSelection(); if (jsonBasedPlatformManagement) { // overrule the Arduino IDE way of working and use the json refereced tools - Map ret = Helpers.getEnvVarPlatformFileTools(referencedPlatform, true); - ret.putAll(Helpers.getEnvVarPlatformFileTools(referencingPlatform, false)); + ret.putAll(getEnvVarPlatformFileTools(myReferencedPlatformCore)); + ret.putAll(getEnvVarPlatformFileTools(referencingPlatform)); return ret; } // standard arduino IDE way - Map ret = Helpers.getEnvVarPlatformFileTools(referencingPlatform, false); - ret.putAll(Helpers.getEnvVarPlatformFileTools(referencedPlatform, true)); + ret.putAll(getEnvVarPlatformFileTools(referencingPlatform)); + ret.putAll(getEnvVarPlatformFileTools(myReferencedPlatformCore)); return ret; } + /** + * This method only returns environment variables with and without version + * number + * These are purely based on the tool dependencies + * + * @param platformVersion + * @return environment variables pointing to the tools used by the platform + */ + private static Map getEnvVarPlatformFileTools(ArduinoPlatformVersion platformVersion) { + HashMap vars = new HashMap<>(); + for (ArduinoPlatformTooldDependency tool : platformVersion.getToolsDependencies()) { + IPath installPath = tool.getInstallPath(); + if (installPath.toFile().exists()) { + String value = installPath.toOSString(); + String keyString = RUNTIME_TOOLS + tool.getName() + tool.getVersion() + DOT_PATH; + vars.put(keyString, value); + keyString = RUNTIME_TOOLS + tool.getName() + '-' + tool.getVersion() + DOT_PATH; + vars.put(keyString, value); + keyString = RUNTIME_TOOLS + tool.getName() + DOT_PATH; + vars.put(keyString, value); + } + } + return vars; + } + /** * Following post processing is done * @@ -1065,17 +1056,18 @@ public static BoardDescription getFromCDT(ICConfigurationDescription confDesc) { if (packagesIndex != -1) { referencingBoardsFile = sloeberHomePath.append(referencingBoardsFile.substring(packagesIndex)).toString(); } - ret.myreferencingBoardsFile = resolvePathEnvironmentString(new File(referencingBoardsFile)); - ret.myBoardTxtFile = new BoardTxtFile(ret.myreferencingBoardsFile); + File resolvedFile = resolvePathEnvironmentString(new File(referencingBoardsFile)); + ret.myBoardTxtFile = new BoardTxtFile(resolvedFile); return ret; } public boolean isValid() { - if (myreferencingBoardsFile == null) { + File boardsFile = myBoardTxtFile.getLoadedFile(); + if (boardsFile == null) { return false; } - return myreferencingBoardsFile.exists(); + return boardsFile.exists(); } public void reloadTxtFile() { diff --git a/io.sloeber.core/src/io/sloeber/core/api/PackageManager.java b/io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java similarity index 54% rename from io.sloeber.core/src/io/sloeber/core/api/PackageManager.java rename to io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java index 3af285641..74e71ac03 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/PackageManager.java +++ b/io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java @@ -3,24 +3,22 @@ import static io.sloeber.core.Messages.*; import static io.sloeber.core.common.ConfigurationPreferences.*; import static io.sloeber.core.common.Const.*; -import static java.nio.file.StandardCopyOption.*; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.io.InputStream; import java.io.Reader; -import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -35,23 +33,29 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; +import org.eclipse.ui.statushandlers.StatusManager; import com.google.gson.Gson; import io.sloeber.core.Activator; -import io.sloeber.core.api.PackageManager.PlatformTree.IndexFile; -import io.sloeber.core.api.PackageManager.PlatformTree.InstallableVersion; -import io.sloeber.core.api.PackageManager.PlatformTree.Platform; +import io.sloeber.core.Messages; +import io.sloeber.core.api.Json.ArduinoInstallable; +import io.sloeber.core.api.Json.ArduinoPackage; +import io.sloeber.core.api.Json.ArduinoPlatform; +import io.sloeber.core.api.Json.ArduinoPlatformPackageIndex; +import io.sloeber.core.api.Json.ArduinoPlatformTool; +import io.sloeber.core.api.Json.ArduinoPlatformToolVersion; +import io.sloeber.core.api.Json.ArduinoPlatformTooldDependency; +import io.sloeber.core.api.Json.ArduinoPlatformVersion; import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.core.common.Const; import io.sloeber.core.common.InstancePreferences; -import io.sloeber.core.managers.ArduinoPlatform; -import io.sloeber.core.managers.InternalPackageManager; -import io.sloeber.core.managers.Package; -import io.sloeber.core.managers.PackageIndex; -import io.sloeber.core.tools.Helpers; +import io.sloeber.core.managers.InstallProgress; +import io.sloeber.core.tools.MyMultiStatus; +import io.sloeber.core.tools.PackageManager; import io.sloeber.core.txt.BoardTxtFile; +import io.sloeber.core.txt.WorkAround; /** * This class groups both boards installed by the hardware manager and boards @@ -60,7 +64,7 @@ * @author jantje * */ -public class PackageManager { +public class BoardsManager { private static String stringSplitter = "\n";//$NON-NLS-1$ private static final String KEY_MANAGER_JSON_URLS_V3 = "Arduino Manager board Urls"; //$NON-NLS-1$ private static final String KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL = "https://downloads.arduino.cc/libraries/library_index.json"; //$NON-NLS-1$ @@ -71,11 +75,10 @@ public class PackageManager { + "https://arduino.esp8266.com/stable/package_esp8266com_index.json\n" //$NON-NLS-1$ + KEY_MANAGER_ARDUINO_LIBRARY_JSON_URL; - - protected static List packageIndices; + protected static List packageIndices; private static boolean myHasbeenLogged = false; private static boolean envVarsNeedUpdating = true;// reset global variables at startup - private final static int MAX_HTTP_REDIRECTIONS = 5; + private static HashMap myWorkbenchEnvironmentVariables = new HashMap<>(); /** @@ -113,18 +116,19 @@ static public BoardDescription getBoardDescription(String jsonFileName, String p static private BoardDescription getNewestBoardIDFromBoardsManager(String jsonFileName, String packageName, String architectureName, String boardID, Map options) { - Package thePackage = InternalPackageManager.getPackage(jsonFileName, packageName); + ArduinoPackage thePackage = getPackage(jsonFileName, packageName); if (thePackage == null) { // fail("failed to find package:" + this.mPackageName); return null; } - ArduinoPlatform platform = thePackage.getLatestPlatform(architectureName, true); + ArduinoPlatform platform = thePackage.getPlatform(architectureName); if (platform == null) { // fail("failed to find platform " + this.mPlatform + " in // package:" + this.mPackageName); return null; } - java.io.File boardsFile = platform.getBoardsFile(); + ArduinoPlatformVersion platformVersion = platform.getNewestVersion(); + java.io.File boardsFile = platformVersion.getBoardsFile(); BoardDescription boardid = new BoardDescription(boardsFile, boardID, options); return boardid; @@ -147,15 +151,6 @@ public static void setPackageURLs(HashSet packageUrls, boolean forceDown loadJsons(forceDownload); } - public static void removePackageURLs(Set packageUrlsToRemove) { - if (!isReady()) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception())); - return; - } - InternalPackageManager.removePackageURLs(packageUrlsToRemove); - - } - /** * installs a subset of the latest platforms It skips the first * platforms And stops at platforms. To install the 5 first latest @@ -174,12 +169,12 @@ public static void installsubsetOfLatestPlatforms(int fromIndex, int toIndex) { envVarsNeedUpdating = true; int currPlatformIndex = 1; NullProgressMonitor monitor = new NullProgressMonitor(); - List allPackages = InternalPackageManager.getPackages(); - for (Package curPackage : allPackages) { - Collection latestPlatforms = curPackage.getLatestPlatforms(); + List allPackages = getPackages(); + for (ArduinoPackage curPackage : allPackages) { + Collection latestPlatforms = curPackage.getPlatforms(); for (ArduinoPlatform curPlatform : latestPlatforms) { if (currPlatformIndex > fromIndex) { - curPlatform.install(monitor); + install(curPlatform.getNewestVersion(), monitor); } if (currPlatformIndex++ > toIndex) return; @@ -200,19 +195,84 @@ public static void installLatestPlatform(String JasonName, String packageName, S return; } envVarsNeedUpdating = true; - Package curPackage = InternalPackageManager.getPackage(JasonName, packageName); + ArduinoPackage curPackage = getPackage(JasonName, packageName); if (curPackage != null) { - ArduinoPlatform curPlatform = curPackage.getLatestPlatform(architectureName, false); + ArduinoPlatform curPlatform = curPackage.getPlatform(architectureName); if (curPlatform != null) { - NullProgressMonitor monitor = new NullProgressMonitor(); - curPlatform.install(monitor); - return; + ArduinoPlatformVersion curPlatformVersion = curPlatform.getNewestVersion(); + if (curPlatformVersion != null) { + NullProgressMonitor monitor = new NullProgressMonitor(); + install(curPlatformVersion, monitor); + return; + } } } Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "failed to find " + JasonName + " " + packageName + " " + architectureName)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } + @SuppressWarnings("nls") + private static IStatus install(ArduinoPlatformVersion platformVersion, IProgressMonitor monitor) { + boolean forceDownload = false; + String name = platformVersion.getName(); + String architecture = platformVersion.getArchitecture(); + String version = platformVersion.getVersion().toString(); + // Check if we're installed already + if (platformVersion.isInstalled()) { + System.out.println("reusing platform " + name + " " + architecture + "(" + version + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + return Status.OK_STATUS; + } + + // Download platform archive + System.out.println("start installing platform " + name + " " + architecture + "(" + version + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + + MyMultiStatus mstatus = new MyMultiStatus("Failed to install " + platformVersion.getName()); //$NON-NLS-1$ + mstatus.addErrors(PackageManager.downloadAndInstall(platformVersion, forceDownload, monitor)); + if (!mstatus.isOK()) { + // no use installing tools when the boards failed installing + return mstatus; + } + + //keep a copy of the json file used at install + File packageFile = platformVersion.getParent().getParent().getPackageIndex().getJsonFile(); + File copyToFile = platformVersion.getInstallPath().append(packageFile.getName()).toFile(); + try { + Files.copy(packageFile.toPath(), copyToFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e) { + e.printStackTrace(); + } + + ArduinoPackage referencingPkg = platformVersion.getParent().getParent(); + for (ArduinoPlatformTooldDependency toolDependency : platformVersion.getToolsDependencies()) { + ArduinoPlatformToolVersion tool = referencingPkg.getTool(toolDependency.getName(), + toolDependency.getVersion()); + if (tool == null) { + //this is a tool provided by another platform + //and the referencing platform does not specify the installable info + //This means the package file of the referencing platform needs to be provided + ArduinoPackage pkg = getPackageByProvider(toolDependency.getPackager()); + if (pkg != null) { + tool = pkg.getTool(toolDependency.getName(), toolDependency.getVersion()); + } + } + if (tool == null) { + mstatus.add(new Status(IStatus.ERROR, Activator.getId(), + Messages.Tool_no_valid_system.replace(Messages.KEY_TAG, toolDependency.getName()))); + } else if (!tool.isInstalled()) { + ArduinoInstallable installable = tool.getInstallable(); + if (installable != null) { + monitor.setTaskName(InstallProgress.getRandomMessage()); + mstatus.addErrors(PackageManager.downloadAndInstall(installable, forceDownload, monitor)); + } + } + } + + WorkAround.applyKnownWorkArounds(platformVersion); + + System.out.println("done installing platform " + name + " " + architecture + "(" + version + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + return mstatus; + } + public static void addPrivateHardwarePath(String newHardwarePath) { if (newHardwarePath == null) { return; @@ -229,15 +289,6 @@ public static void addPrivateHardwarePath(String newHardwarePath) { InstancePreferences.setPrivateHardwarePaths(newPaths); } - public static boolean isReady() { - return InternalPackageManager.isReady(); - } - - public static String[] getBoardNames(String boardFile) { - BoardTxtFile theBoardsFile = new BoardTxtFile(new File(boardFile)); - return theBoardsFile.getAllSectionNames(); - } - /** * Searches for all boards.txt files from the hardware folders and the boards * manager @@ -291,329 +342,50 @@ private static String[] getHardwarePaths() { + ConfigurationPreferences.getInstallationPathPackages()).split(File.pathSeparator); } - public static class PlatformTree { - private TreeMap IndexFiles = new TreeMap<>(); - - public class InstallableVersion implements Comparable { - private Platform platform; - private ArduinoPlatform myInternalPlatformm; - private boolean isInstalled; - - public InstallableVersion(ArduinoPlatform internalPlatformm, Platform platform) { - this.platform = platform; - this.myInternalPlatformm = internalPlatformm; - this.isInstalled = this.myInternalPlatformm.isInstalled(); - } - - public VersionNumber getVersion() { - return new VersionNumber(this.myInternalPlatformm.getVersion()); - } - - public boolean isInstalled() { - return this.isInstalled; - } - - public void setInstalled(boolean isInstalled) { - this.isInstalled = isInstalled; - } - - @Override - public int compareTo(InstallableVersion o) { - return getVersion().compareTo(o.getVersion()); - } - - public Platform getPlatform() { - return this.platform; - } - - public ArduinoPlatform getInternalPlatform() { - return this.myInternalPlatformm; - } - - } - - public class Platform implements Comparable { - - private String name; - private String architecture; - protected TreeSet versions = new TreeSet<>(); - protected String boards; - private Package pac; - - public String getArchitecture() { - return this.architecture; - } - - public String getBoards() { - return this.boards; - } - - public Platform(ArduinoPlatform internalPlatformm, Package pac) { - this.name = internalPlatformm.getName(); - this.architecture = internalPlatformm.getArchitecture(); - this.versions.add(new InstallableVersion(internalPlatformm, this)); - this.boards = String.join("\n", internalPlatformm.getBoardNames()); //$NON-NLS-1$ - this.pac = pac; - } - - public void addVersion(ArduinoPlatform internalPlatformm) { - this.versions.add(new InstallableVersion(internalPlatformm, this)); - - } - - public Collection getVersions() { - return this.versions; - } - - public String getName() { - return this.name; - } - - public String getLatest() { - return this.versions.last().toString(); - } - - @Override - public int compareTo(Platform other) { - return this.name.compareToIgnoreCase(other.name); - } - - public InstallableVersion getVersion(VersionNumber versionNumber) { - for (InstallableVersion curVersion : this.versions) { - if (curVersion.getVersion().compareTo(versionNumber) == 0) { - return curVersion; - } - } - return null; - } - - public boolean isInstalled() { - for (InstallableVersion curVersion : this.versions) { - if (curVersion.isInstalled()) { - return true; - } - } - return false; - } - - public Package getPackage() { - return this.pac; - } - } - - /** - * This class represents the json file on disk - */ - public class IndexFile implements Comparable { - protected File jsonFile; - protected TreeMap packages = new TreeMap<>(); - - public IndexFile(File jsonFile) { - this.jsonFile = jsonFile; - } - - @Override - public int compareTo(IndexFile other) { - return this.jsonFile.compareTo(other.jsonFile); - } - - public Collection getAllPackages() { - return this.packages.values(); - } - - public String getNiceName() { - return this.jsonFile.getName(); - } - - public String getFullName() { - return this.jsonFile.getPath(); - } - - /** - * is one ore more packages of this index file installed - * - * @return returns true if at least one version of one child platform of a child - * packageis installed - */ - - public boolean isInstalled() { - for (Package curpackage : this.packages.values()) { - if (curpackage.isInstalled()) { - return true; - - } - } - return false; - } - } - - public class Package implements Comparable { - public String getMaintainer() { - return this.maintainer; - } - - public URL getWebsiteURL() { - return this.websiteURL; - } - - public String getEmail() { - return this.email; - } - - private String name; - private String maintainer; - private URL websiteURL; - private String email; - - protected TreeMap platforms = new TreeMap<>(); - private IndexFile indexFile; - - public Package(String name) { - this.name = name; - } - - public Package(io.sloeber.core.managers.Package pack, IndexFile indexFile) { - this.name = pack.getName(); - this.maintainer = pack.getMaintainer(); - try { - this.websiteURL = new URL(pack.getWebsiteURL()); - } catch (MalformedURLException e) { - // ignore this error - } - this.email = pack.getEmail(); - this.indexFile = indexFile; - } - - public String getName() { - return this.name; - } - - public Collection getPlatforms() { - return this.platforms.values(); - } - - @Override - public int compareTo(Package other) { - return this.name.compareToIgnoreCase(other.name); - } - - /** - * is one ore more platforms of this package installed - * - * @return returns true if at least one version of one child platform is - * installed - */ - public boolean isInstalled() { - for (Platform curplatform : this.platforms.values()) { - if (curplatform.isInstalled()) { - return true; - - } - } - return false; - } - - public IndexFile getIndexFile() { - return this.indexFile; - } - - } - - public PlatformTree() { - List packageIndexes = InternalPackageManager.getPackageIndices(); - for (PackageIndex curPackageIndex : packageIndexes) { - IndexFile curIndexFile = new IndexFile(curPackageIndex.getJsonFile()); - this.IndexFiles.put(curPackageIndex.getJsonFileName(), curIndexFile); - for (io.sloeber.core.managers.Package curInternalPackage : curPackageIndex.getPackages()) { - Package curPackage = new Package(curInternalPackage, curIndexFile); - curIndexFile.packages.put(curPackage.getName(), curPackage); - for (ArduinoPlatform curInternalPlatform : curInternalPackage.getPlatforms()) { - Platform curPlatform = new Platform(curInternalPlatform, curPackage); - Platform foundPlatform = curPackage.platforms.get(curPlatform.getName()); - if (foundPlatform == null) { - curPackage.platforms.put(curPlatform.getName(), curPlatform); - } else { - foundPlatform.addVersion(curInternalPlatform); - } - } - } - } - } - - public Collection getAllIndexFiles() { - return this.IndexFiles.values(); - } - - public Set getAllPackages() { - Set all = new TreeSet<>(); - for (IndexFile indexFile : this.IndexFiles.values()) { - all.addAll(indexFile.getAllPackages()); - } - return all; - } - - public Collection getAllPlatforms() { - Set all = new TreeSet<>(); - for (IndexFile curIndexFile : this.IndexFiles.values()) { - for (Package curPackage : curIndexFile.getAllPackages()) { - all.addAll(curPackage.getPlatforms()); - } - } - return all; - } - - public IndexFile getIndexFile(PackageIndex packageIndex) { - return this.IndexFiles.get(packageIndex.getJsonFileName()); - } - - @SuppressWarnings("static-method") - public Package getPackage(IndexFile indexFile, io.sloeber.core.managers.Package curInternalPackage) { - return indexFile.packages.get(curInternalPackage.getName()); - } - - @SuppressWarnings("static-method") - public Platform getPlatform(Package curPackage, ArduinoPlatform curInternalPlatform) { - return curPackage.platforms.get(curInternalPlatform.getName()); - } - - } - - public static IStatus setPlatformTree(PlatformTree platformTree, IProgressMonitor monitor, MultiStatus status) { + public static IStatus updatePlatforms(List platformsToInstall, + List platformsToRemove, IProgressMonitor monitor, MultiStatus status) { if (!isReady()) { status.add(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, null)); return status; } + //TODO updating the jsons after selecting what to install seems dangerous to me; check to delete if (!ConfigurationPreferences.getUpdateJasonFilesFlag()) { loadJsons(true); } envVarsNeedUpdating = true; try { - InternalPackageManager.setReady(false); - - for (IndexFile curIndexFile : platformTree.getAllIndexFiles()) { - for (io.sloeber.core.api.PackageManager.PlatformTree.Package curPackage : curIndexFile - .getAllPackages()) { - for (Platform curPlatform : curPackage.getPlatforms()) { - for (InstallableVersion curVersion : curPlatform.getVersions()) { - if (curVersion.isInstalled()) { - status.add(curVersion.getInternalPlatform().install(monitor)); - } else { - - status.add(curVersion.getInternalPlatform().remove(monitor)); - } - } - } - } - + myIsReady = false; + for (ArduinoPlatformVersion curPlatform : platformsToRemove) { + status.add(uninstall(curPlatform, monitor)); + } + for (ArduinoPlatformVersion curPlatform : platformsToInstall) { + status.add(install(curPlatform, monitor)); } + } catch (Exception e) { // do nothing } - InternalPackageManager.setReady(true); + myIsReady = true; SloeberProject.reloadTxtFile(); return status; } + public static IStatus uninstall(ArduinoPlatformVersion curPlatform, IProgressMonitor monitor) { + if (!curPlatform.isInstalled()) { + return Status.OK_STATUS; + } + + File installFolder = curPlatform.getInstallPath().toFile(); + try { + FileUtils.deleteDirectory(installFolder); + } catch (IOException e) { + return new Status(IStatus.ERROR, Activator.getId(), "Failed to remove folder" + installFolder.toString(), //$NON-NLS-1$ + e); + } + + return Status.OK_STATUS; + } + public static TreeMap getAllmenus() { TreeMap ret = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); File[] boardFiles = getAllBoardsFiles(); @@ -624,18 +396,6 @@ public static TreeMap getAllmenus() { return ret; } - /** - * Remove all packages that have a more recent version - */ - public static void onlyKeepLatestPlatforms() { - if (!isReady()) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception())); - return; - } - InternalPackageManager.onlyKeepLatestPlatforms(); - - } - public static void setPrivateHardwarePaths(String[] hardWarePaths) { if (!isReady()) { Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception())); @@ -657,6 +417,8 @@ protected static synchronized void loadJsons(boolean forceDownload) { if (!jsonUrl.trim().isEmpty()) // skip empty lines loadJson(jsonUrl, forceDownload); } + //sorting here so things look good in the gui + Collections.sort(packageIndices); } /** @@ -677,7 +439,7 @@ static private void loadJson(String url, boolean forceDownload) { if (!jsonFile.exists() || forceDownload) { jsonFile.getParentFile().mkdirs(); try { - mySafeCopy(new URL(url.trim()), jsonFile, false); + PackageManager.mySafeCopy(new URL(url.trim()), jsonFile, false); } catch (IOException e) { Common.log(new Status(IStatus.ERROR, Activator.getId(), "Unable to download " + url, e)); //$NON-NLS-1$ } @@ -696,9 +458,8 @@ static private void loadJson(String url, boolean forceDownload) { static private void loadPackage(File jsonFile) { try (Reader reader = new FileReader(jsonFile)) { - PackageIndex index = new Gson().fromJson(reader, PackageIndex.class); - index.setOwners(); - index.setJsonFile(jsonFile); + ArduinoPlatformPackageIndex index = new Gson().fromJson(reader, ArduinoPlatformPackageIndex.class); + index.setPackageFile(jsonFile); packageIndices.add(index); } catch (Exception e) { Common.log(new Status(IStatus.ERROR, Activator.getId(), @@ -741,88 +502,6 @@ protected static File getLocalFileName(String url, boolean show_error) { return packagePath.toFile(); } - /** - * copy a url locally taking into account redirections - * - * @param url - * @param localFile - * @throws IOException - */ - protected static void myCopy(URL url, File localFile, boolean report_error) throws IOException { - myCopy(url, localFile, report_error, 0); - } - - @SuppressWarnings("nls") - private static void myCopy(URL url, File localFile, boolean report_error, int redirectionCounter) - throws IOException { - if ("file".equals(url.getProtocol())) { - FileUtils.copyFile(new File(url.getFile()), localFile); - return; - } - try { - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setReadTimeout(30000); - conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8"); - conn.addRequestProperty("User-Agent", "Mozilla"); - conn.addRequestProperty("Referer", "google.com"); - - // normally, 3xx is redirect - int status = conn.getResponseCode(); - - if (status == HttpURLConnection.HTTP_OK) { - try (InputStream stream = url.openStream()) { - Files.copy(stream, localFile.toPath(), REPLACE_EXISTING); - } - return; - } - - if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM - || status == HttpURLConnection.HTTP_SEE_OTHER) { - if (redirectionCounter >= MAX_HTTP_REDIRECTIONS) { - throw new IOException("Too many redirections while downloading file."); - } - myCopy(new URL(conn.getHeaderField("Location")), localFile, report_error, redirectionCounter + 1); - return; - } - if (report_error) { - Common.log(new Status(IStatus.WARNING, Activator.getId(), - "Failed to download url " + url + " error code is: " + status, null)); - } - throw new IOException("Failed to download url " + url + " error code is: " + status); - - } catch (Exception e) { - if (report_error) { - Common.log(new Status(IStatus.WARNING, Activator.getId(), "Failed to download url " + url, e)); - } - throw e; - - } - } - - /** - * copy a url locally taking into account redirections in such a way that if - * there is already a file it does not get lost if the download fails - * - * @param url - * @param localFile - * @throws IOException - */ - protected static void mySafeCopy(URL url, File localFile, boolean report_error) throws IOException { - File savedFile = null; - if (localFile.exists()) { - savedFile = File.createTempFile(localFile.getName(), "Sloeber"); //$NON-NLS-1$ - Files.move(localFile.toPath(), savedFile.toPath(), REPLACE_EXISTING); - } - try { - myCopy(url, localFile, report_error); - } catch (Exception e) { - if (null != savedFile) { - Files.move(savedFile.toPath(), localFile.toPath(), REPLACE_EXISTING); - } - throw e; - } - } - public static String getDefaultJsonURLs() { return DEFAULT_JSON_URLS; } @@ -867,6 +546,7 @@ public static String getJsonURLs() { } return ret; } + /** * Completely replace the list with jsons with a new list * @@ -904,8 +584,6 @@ public static void setJsonURLs(String[] newJsonUrls) { loadJsons(false); } - - public static void removeAllInstalledPlatforms() { if (!isReady()) { Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception())); @@ -932,54 +610,283 @@ public static Map getEnvironmentVariables() { return myWorkbenchEnvironmentVariables; } myWorkbenchEnvironmentVariables.clear(); - ArduinoPlatform latestAvrPlatform=null; - ArduinoPlatform latestSamdPlatform=null; - ArduinoPlatform latestSamPlatform=null; - for (ArduinoPlatform curPlatform : InternalPackageManager.getInstalledPlatforms()) { - Package pkg = curPlatform.getParent(); + ArduinoPlatformVersion latestAvrPlatform = getNewestInstalledPlatform(Const.ARDUINO, Const.AVR); + ArduinoPlatformVersion latestSamdPlatform = getNewestInstalledPlatform(Const.ARDUINO, Const.SAMD); + ArduinoPlatformVersion latestSamPlatform = getNewestInstalledPlatform(Const.ARDUINO, Const.SAM); + + if (latestSamdPlatform != null) { + myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestSamdPlatform)); + } + if (latestSamPlatform != null) { + myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestSamPlatform)); + } + if (latestAvrPlatform != null) { + myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestAvrPlatform)); + } + envVarsNeedUpdating = false; + return myWorkbenchEnvironmentVariables; + } + + private static Map getEnvVarPlatformFileTools(ArduinoPlatformVersion platformVersion) { + HashMap vars = new HashMap<>(); + ArduinoPackage pkg = platformVersion.getParent().getParent(); + for (ArduinoPlatformTooldDependency tool : platformVersion.getToolsDependencies()) { + ArduinoPlatformTool theTool = pkg.getTool(tool.getName()); + if (theTool == null) { + System.err.println("Did not find " + tool.getName() + " in package with ID " + pkg.getID()); //$NON-NLS-1$ //$NON-NLS-2$ + } else { + vars.putAll(theTool.getEnvVars(null)); + } + } + return vars; + } + + /** + * given a vendor and a architecture provide the newest installed platform + * version + * + * @param vendor + * @param architecture + * @return the found platformVersion or null if none found + */ + public static ArduinoPlatformVersion getNewestInstalledPlatform(String vendor, String architecture) { + ArduinoPlatform platform = getPlatform(vendor, architecture); + if (platform == null) { + return null; + } + return platform.getNewestInstalled(); + } + + //Below is what used to be the internal package manager class + + private static boolean myIsReady = false; + + public static boolean isReady() { + return myIsReady; + } + + /** + * Loads all stuff needed and if this is the first time downloads the avr boards + * and needed tools + * + * @param monitor + */ + public static synchronized void startup_Pluging(IProgressMonitor monitor) { + loadJsons(ConfigurationPreferences.getUpdateJasonFilesFlag()); + + if (!LibraryManager.libsAreInstalled()) { + LibraryManager.InstallDefaultLibraries(monitor); + } + IPath examplesPath = ConfigurationPreferences.getInstallationPathExamples(); + if (!examplesPath.toFile().exists()) {// examples are not installed + // Download arduino IDE example programs + Common.log(PackageManager.downloadAndInstall(Defaults.EXAMPLES_URL, Defaults.EXAMPLE_PACKAGE, examplesPath, + false, monitor)); + } + if (!areThereInstalledBoards()) { + + IStatus status = null; + + // if successfully installed the examples: add the boards + ArduinoPlatform platform = getPlatform(Defaults.DEFAULT_INSTALL_MAINTAINER, + Defaults.DEFAULT_INSTALL_ARCHITECTURE); + //we failed to find arduino avr platform. Take the fiorst one + if (platform == null) { + try { + platform = getPlatforms().get(0); + } catch (@SuppressWarnings("unused") Exception e) { + //no need to do anything + } + } + if (platform == null) { + status = new Status(IStatus.ERROR, Activator.getId(), Messages.No_Platform_available); + } else { + status = install(platform.getNewestVersion(), monitor); + } + + if (!status.isOK()) { + StatusManager stMan = StatusManager.getManager(); + stMan.handle(status, StatusManager.LOG | StatusManager.SHOW | StatusManager.BLOCK); + } + + } + myIsReady = true; + + } + + synchronized static public List getPackageIndices() { + if (packageIndices == null) { + loadJsons(false); + } + return packageIndices; + } + + public static List getPlatforms() { + List platforms = new ArrayList<>(); + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + for (ArduinoPackage pkg : index.getPackages()) { + platforms.addAll(pkg.getPlatforms()); + } + } + return platforms; + } + + public static ArduinoPlatform getPlatform(String vendor, String architecture) { + + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + ArduinoPackage pkg = index.getPackage(vendor); if (pkg != null) { - myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(curPlatform, false)); - if(Const.ARDUINO.equalsIgnoreCase(pkg.getMaintainer())){ - switch (curPlatform.getArchitecture()) { - case Const.AVR: - latestAvrPlatform=curPlatform; - break; - case Const.SAM: - latestSamPlatform=curPlatform; - break; - case Const.SAMD: - latestSamdPlatform=curPlatform; - break; - } + ArduinoPlatform platform = pkg.getPlatform(architecture); + if (platform != null) { + return platform; + } + } + } + return null; + } + + /** + * Given a platform.txt file find the platform in the platform manager + * + * @param platformTxt + * @return the found platform otherwise null + */ + public static ArduinoPlatformVersion getPlatform(IPath platformPath) { + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + for (ArduinoPackage pkg : index.getPackages()) { + for (ArduinoPlatform curPlatform : pkg.getPlatforms()) { + if (platformPath + .matchingFirstSegments(curPlatform.getInstallPath()) > (platformPath.segmentCount() - 2)) + + for (ArduinoPlatformVersion curPlatformVersion : curPlatform.getVersions()) { + if (curPlatformVersion.getInstallPath().equals(platformPath)) { + return curPlatformVersion; + } + } } } } + return null; + } - if( latestSamdPlatform!=null) { - myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestSamdPlatform, false)); + static public List getInstalledPlatforms() { + List platforms = new ArrayList<>(); + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + for (ArduinoPackage pkg : index.getPackages()) { + + platforms.addAll(pkg.getInstalledPlatforms()); + + } } - if( latestSamPlatform!=null) { - myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestSamPlatform, false)); + return platforms; + } + + static public boolean areThereInstalledBoards() { + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + for (ArduinoPackage pkg : index.getPackages()) { + if (pkg.isInstalled()) { + return true; + } + } } - if( latestAvrPlatform!=null) { - myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestAvrPlatform, false)); + return false; + } + + static public List getPackages() { + List packages = new ArrayList<>(); + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + packages.addAll(index.getPackages()); } - envVarsNeedUpdating = false; - return myWorkbenchEnvironmentVariables; + + return packages; + } + + static public ArduinoPackage getPackage(String JasonName, String packageName) { + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + if (index.getJsonFile().getName().equals(JasonName)) { + return index.getPackage(packageName); + } + } + return null; + } + + static public ArduinoPackage getPackage(String packageName) { + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + ArduinoPackage pkg = index.getPackage(packageName); + if (pkg != null) { + return pkg; + } + } + return null; } /** - * Only the latest versions of the platforms. + * This method removes the json files from disk and removes memory references to + * these files or their content * - * @return latest platforms + * @param packageUrlsToRemove */ - public static Collection getLatestPlatforms() { - Collection allLatestPlatforms = new LinkedList<>(); - List allPackages = InternalPackageManager.getPackages(); - for (Package curPackage : allPackages) { - allLatestPlatforms.addAll(curPackage.getLatestPlatforms()); + public static void removePackageURLs(Set packageUrlsToRemove) { + if (!isReady()) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception())); + return; + } + // remove the files from memory + Set activeUrls = new HashSet<>(Arrays.asList(getJsonURLList())); + + activeUrls.removeAll(packageUrlsToRemove); + + setJsonURLs(activeUrls.toArray((String[]) null)); + + // remove the files from disk + for (String curJson : packageUrlsToRemove) { + File localFile = getLocalFileName(curJson, true); + if (localFile != null) { + if (localFile.exists()) { + localFile.delete(); + } + } + } + + // reload the indices (this will remove all potential remaining + // references + // existing files do not need to be refreshed as they have been + // refreshed at startup + loadJsons(false); + + } + + /** + * Remove all packages that have a more recent version + */ + public static void onlyKeepLatestPlatforms() { + if (!isReady()) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, BoardsManagerIsBussy, new Exception())); + return; + } + List allPackages = getPackages(); + for (ArduinoPackage curPackage : allPackages) { + curPackage.onlyKeepLatestPlatforms(); + } + } + + public static ArduinoPlatformVersion getPlatform(String vendor, String architecture, VersionNumber refVersion) { + ArduinoPlatform platform = getPlatform(vendor, architecture); + if (platform != null) { + return platform.getVersion(refVersion); + } + return null; + } + + public static ArduinoPackage getPackageByProvider(String packager) { + for (ArduinoPlatformPackageIndex index : getPackageIndices()) { + for (ArduinoPackage pkg : index.getPackages()) { + if (packager.equals(pkg.getID())) { + return pkg; + } + } } - return allLatestPlatforms; + return null; } } diff --git a/io.sloeber.core/src/io/sloeber/core/api/CodeDescription.java b/io.sloeber.core/src/io/sloeber/core/api/CodeDescription.java index 8e46e5775..4890e10b0 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/CodeDescription.java +++ b/io.sloeber.core/src/io/sloeber/core/api/CodeDescription.java @@ -20,6 +20,7 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; +import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.core.common.InstancePreferences; import io.sloeber.core.tools.FileModifiers; import io.sloeber.core.tools.Helpers; @@ -34,284 +35,291 @@ */ public class CodeDescription { - public enum CodeTypes { - None, defaultIno, defaultCPP, CustomTemplate, sample - } + public enum CodeTypes { + None, defaultIno, defaultCPP, CustomTemplate, sample + } static private final String DEFAULT_SKETCH_BASE = "sketch"; //$NON-NLS-1$ public static final String DEFAULT_SKETCH_INO = DEFAULT_SKETCH_BASE + ".ino"; //$NON-NLS-1$ public static final String DEFAULT_SKETCH_CPP = DEFAULT_SKETCH_BASE + ".cpp"; //$NON-NLS-1$ public static final String DEFAULT_SKETCH_H = DEFAULT_SKETCH_BASE + ".h"; //$NON-NLS-1$ - // - // template Sketch information + // + // template Sketch information static private final String SLOEBER_SKETCH_TEMPLATE_FOLDER = ENV_KEY_SLOEBER_START + "TEMPLATE_FOLDER"; //$NON-NLS-1$ - static private final String SLOEBER_SKETCH_TEMPLATE_USE_DEFAULT = ENV_KEY_SLOEBER_START - + "TEMPLATE_USE_DEFAULT"; //$NON-NLS-1$ - - private CodeTypes myCodeType; - private IPath myTemPlateFoldername; - private boolean myMakeLinks = false; - private ArrayList myExamples = new ArrayList<>(); - private Map< String, String> myReplacers=null; - - public IPath getTemPlateFoldername() { - return myTemPlateFoldername; - } - - /** - * set key value pairs that will be used to do a replace all in the code - * the key is the search key and the value is the replacement - * The keys are regular expressions. - * The idea is to use clear keys like #include {include} in the source code - * note that the keys - * \{include\} \{title\} \{SerialMonitorSerial\} - * are already used. Please use other keys as your replacements will overwrite the - * ones already used - * - * @param myReplacers a list of find an replace key value pairs. null is no replace needed - */ - public void setReplacers(Map myReplacers) { - this.myReplacers = myReplacers; - } + static private final String SLOEBER_SKETCH_TEMPLATE_USE_DEFAULT = ENV_KEY_SLOEBER_START + "TEMPLATE_USE_DEFAULT"; //$NON-NLS-1$ + + private CodeTypes myCodeType; + private IPath myTemPlateFoldername; + private boolean myMakeLinks = false; + private ArrayList myExamples = new ArrayList<>(); + private Map myReplacers = null; + + public IPath getTemPlateFoldername() { + return myTemPlateFoldername; + } + + /** + * set key value pairs that will be used to do a replace all in the code + * the key is the search key and the value is the replacement + * The keys are regular expressions. + * The idea is to use clear keys like #include {include} in the source code + * note that the keys + * \{include\} \{title\} \{SerialMonitorSerial\} + * are already used. Please use other keys as your replacements will overwrite + * the + * ones already used + * + * @param myReplacers + * a list of find an replace key value pairs. null is no replace + * needed + */ + public void setReplacers(Map myReplacers) { + this.myReplacers = myReplacers; + } public CodeDescription(CodeTypes codeType) { - myCodeType = codeType; - } - - public static CodeDescription createNone() { - return new CodeDescription(CodeTypes.None); - } - - public static CodeDescription createDefaultIno() { - return new CodeDescription(CodeTypes.defaultIno); - } - - public static CodeDescription createDefaultCPP() { - return new CodeDescription(CodeTypes.defaultCPP); - } - - public static CodeDescription createExample(boolean link, ArrayList sampleFolders) { - CodeDescription codeDescriptor = new CodeDescription(CodeTypes.sample); - codeDescriptor.myMakeLinks = link; - codeDescriptor.myExamples = sampleFolders; - return codeDescriptor; - } - - public static CodeDescription createCustomTemplate(IPath temPlateFoldername) { - CodeDescription codeDescriptor = new CodeDescription(CodeTypes.CustomTemplate); - codeDescriptor.myTemPlateFoldername = temPlateFoldername; - return codeDescriptor; - } - - public static CodeDescription createLastUsed() { - - String typeDescriptor = InstancePreferences.getString(SLOEBER_SKETCH_TEMPLATE_USE_DEFAULT, - new String()); - CodeTypes codeType = codeTypeFromDescription(typeDescriptor); - CodeDescription ret = new CodeDescription(codeType); - ret.myTemPlateFoldername = new Path( + myCodeType = codeType; + } + + public static CodeDescription createNone() { + return new CodeDescription(CodeTypes.None); + } + + public static CodeDescription createDefaultIno() { + return new CodeDescription(CodeTypes.defaultIno); + } + + public static CodeDescription createDefaultCPP() { + return new CodeDescription(CodeTypes.defaultCPP); + } + + public static CodeDescription createExample(boolean link, ArrayList sampleFolders) { + CodeDescription codeDescriptor = new CodeDescription(CodeTypes.sample); + codeDescriptor.myMakeLinks = link; + codeDescriptor.myExamples = sampleFolders; + return codeDescriptor; + } + + public static CodeDescription createCustomTemplate(IPath temPlateFoldername) { + CodeDescription codeDescriptor = new CodeDescription(CodeTypes.CustomTemplate); + codeDescriptor.myTemPlateFoldername = temPlateFoldername; + return codeDescriptor; + } + + public static CodeDescription createLastUsed() { + + String typeDescriptor = InstancePreferences.getString(SLOEBER_SKETCH_TEMPLATE_USE_DEFAULT, new String()); + CodeTypes codeType = codeTypeFromDescription(typeDescriptor); + CodeDescription ret = new CodeDescription(codeType); + ret.myTemPlateFoldername = new Path( InstancePreferences.getString(SLOEBER_SKETCH_TEMPLATE_FOLDER, new String())); - ret.loadLastUsedExamples(); - return ret; - } + ret.loadLastUsedExamples(); + return ret; + } - private static CodeTypes codeTypeFromDescription(String typeDescriptor) { + private static CodeTypes codeTypeFromDescription(String typeDescriptor) { - for (CodeTypes codeType : CodeTypes.values()) { - if (codeType.toString().equals(typeDescriptor)) { - return codeType; - } - } - return CodeTypes.defaultIno; + for (CodeTypes codeType : CodeTypes.values()) { + if (codeType.toString().equals(typeDescriptor)) { + return codeType; + } + } + return CodeTypes.defaultIno; - } + } - /** - * Save the setting in the last used - */ + /** + * Save the setting in the last used + */ private void save() { - if (myTemPlateFoldername != null) { - InstancePreferences.setGlobalValue(SLOEBER_SKETCH_TEMPLATE_FOLDER, - myTemPlateFoldername.toString()); - } + if (myTemPlateFoldername != null) { + InstancePreferences.setGlobalValue(SLOEBER_SKETCH_TEMPLATE_FOLDER, myTemPlateFoldername.toString()); + } InstancePreferences.setGlobalValue(SLOEBER_SKETCH_TEMPLATE_USE_DEFAULT, myCodeType.toString()); - saveLastUsedExamples(); - } + saveLastUsedExamples(); + } - /** - * given the source descriptor, add the sources to the project returns a set - * of libraries that need to be installed - **/ + /** + * given the source descriptor, add the sources to the project returns a set + * of libraries that need to be installed + **/ @SuppressWarnings("nls") Map createFiles(IProject project, IProgressMonitor monitor) throws CoreException { - Map libraries = new TreeMap<>(); + Map libraries = new TreeMap<>(); - save(); - Map replacers=new TreeMap<>(); + save(); + Map replacers = new TreeMap<>(); replacers.put("{Include}", "Arduino.h"); replacers.put("{title}", project.getName()); - if(myReplacers!=null) { - replacers.putAll(myReplacers); - } - - - switch (myCodeType) { - case None: - break; - case defaultIno: - Helpers.addFileToProject(project, new Path(project.getName() + ".ino"), - Stream.openContentStream("/io/sloeber/core/templates/" + DEFAULT_SKETCH_INO, false,replacers), - monitor, false); - break; - case defaultCPP: - Helpers.addFileToProject(project, new Path(project.getName() + ".cpp"), - Stream.openContentStream("/io/sloeber/core/templates/" + DEFAULT_SKETCH_CPP, false,replacers), - monitor, false); - Helpers.addFileToProject(project, new Path(project.getName() + ".h"), - Stream.openContentStream("/io/sloeber/core/templates/" + DEFAULT_SKETCH_H, false,replacers), - monitor, false); - break; - case CustomTemplate: - IPath folderName = myTemPlateFoldername; - String files[] = folderName.toFile().list(); - if (files == null) { - log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, - "No files found in template folder :" + folderName, null)); - } else { - for (String file : files) { - if (!(file.equals(".") || file.equals(".."))) { - File sourceFile = folderName.append(file).toFile(); - String renamedFile = file; - if (DEFAULT_SKETCH_INO.equalsIgnoreCase(file)) { - renamedFile = project.getName() + ".ino"; - } - try(InputStream theFileStream=Stream.openContentStream( sourceFile.toString(), true,replacers);){ - Helpers.addFileToProject(project, new Path(renamedFile), theFileStream, monitor, false); - } catch (IOException e) { + if (myReplacers != null) { + replacers.putAll(myReplacers); + } + + switch (myCodeType) { + case None: + break; + case defaultIno: + Helpers.addFileToProject(project, new Path(project.getName() + ".ino"), + Stream.openContentStream("/io/sloeber/core/templates/" + DEFAULT_SKETCH_INO, false, replacers), + monitor, false); + break; + case defaultCPP: + Helpers.addFileToProject(project, new Path(project.getName() + ".cpp"), + Stream.openContentStream("/io/sloeber/core/templates/" + DEFAULT_SKETCH_CPP, false, replacers), + monitor, false); + Helpers.addFileToProject(project, new Path(project.getName() + ".h"), + Stream.openContentStream("/io/sloeber/core/templates/" + DEFAULT_SKETCH_H, false, replacers), + monitor, false); + break; + case CustomTemplate: + IPath folderName = myTemPlateFoldername; + String files[] = folderName.toFile().list(); + if (files == null) { + log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "No files found in template folder :" + folderName, + null)); + } else { + for (String file : files) { + if (!(file.equals(".") || file.equals(".."))) { + File sourceFile = folderName.append(file).toFile(); + String renamedFile = file; + if (DEFAULT_SKETCH_INO.equalsIgnoreCase(file)) { + renamedFile = project.getName() + ".ino"; + } + try (InputStream theFileStream = Stream.openContentStream(sourceFile.toString(), true, + replacers);) { + Helpers.addFileToProject(project, new Path(renamedFile), theFileStream, monitor, false); + } catch (IOException e) { log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, "Failed to add template file :" + sourceFile.toString(), e)); } - } - } - } - - break; - case sample: - try { - for (IPath curPath : myExamples) { - if (myMakeLinks) { - Helpers.linkDirectory(project, curPath, new Path("/")); //$NON-NLS-1$ - } else { - FileUtils.copyDirectory(curPath.toFile(), project.getLocation().toFile()); - FileModifiers.addPragmaOnce(curPath); - } - libraries.put(getLibraryName(curPath), Libraries.getLibraryCodeFolder(curPath)); - } - } catch (IOException e) { - e.printStackTrace(); - } - break; - } - return libraries; - } - - @SuppressWarnings("nls") - private void loadLastUsedExamples() { - String examplePathNames[] = InstancePreferences + } + } + } + + break; + case sample: + try { + for (IPath curPath : myExamples) { + if (myMakeLinks) { + Helpers.linkDirectory(project, curPath, new Path("/")); //$NON-NLS-1$ + } else { + FileUtils.copyDirectory(curPath.toFile(), project.getLocation().toFile()); + FileModifiers.addPragmaOnce(curPath); + } + String libName = getLibraryName(curPath); + if (libName != null) { + libraries.put(libName, Libraries.getLibraryCodeFolder(curPath)); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + break; + } + return libraries; + } + + @SuppressWarnings("nls") + private void loadLastUsedExamples() { + String examplePathNames[] = InstancePreferences .getString(KEY_LAST_USED_EXAMPLES, Defaults.getPrivateLibraryPath()).split("\n"); - for (String curpath : examplePathNames) { - myExamples.add(new Path(curpath)); - } - } + for (String curpath : examplePathNames) { + myExamples.add(new Path(curpath)); + } + } - public ArrayList getExamples() { - return myExamples; - } + public ArrayList getExamples() { + return myExamples; + } - private void saveLastUsedExamples() { - if (myExamples != null) { - String toStore = StringUtils.join(myExamples, "\n"); //$NON-NLS-1$ + private void saveLastUsedExamples() { + if (myExamples != null) { + String toStore = StringUtils.join(myExamples, "\n"); //$NON-NLS-1$ InstancePreferences.setGlobalValue(KEY_LAST_USED_EXAMPLES, toStore); - } else { + } else { InstancePreferences.setGlobalValue(KEY_LAST_USED_EXAMPLES, new String()); - } - - } - - public CodeTypes getCodeType() { - return myCodeType; - } - - /** - * Get the name of the example for this project descriptor This is only - * "known in case of examples" as in all other cases the name will be - * project related which is unknown in this case. This method only exists to - * support unit testing where one knows only 1 example is selected - * - * @return the name of the first selected example in case of sample in all - * other cases null - */ - public String getExampleName() { - switch (myCodeType) { - case sample: - return myExamples.get(0).lastSegment(); - default: - break; - } - return null; - } - - /** - * Get the name of the library for this project descriptor This is only - * "known in case of examples" as in all other cases the name will be - * project related which is unknown in this case. This method only exists to - * support unit testing where one knows only 1 example is selected - * - * @return the name of the first selected example in case of sample in all - * other cases null - */ - public String getLibraryName() { - switch (myCodeType) { - case sample: - return getLibraryName(myExamples.get(0)); - default: - break; - } - return null; - } - - @SuppressWarnings("nls") + } + + } + + public CodeTypes getCodeType() { + return myCodeType; + } + + /** + * Get the name of the example for this project descriptor This is only + * "known in case of examples" as in all other cases the name will be + * project related which is unknown in this case. This method only exists to + * support unit testing where one knows only 1 example is selected + * + * @return the name of the first selected example in case of sample in all + * other cases null + */ + public String getExampleName() { + switch (myCodeType) { + case sample: + return myExamples.get(0).lastSegment(); + default: + break; + } + return null; + } + + /** + * Get the name of the library for this project descriptor This is only + * "known in case of examples" as in all other cases the name will be + * project related which is unknown in this case. This method only exists to + * support unit testing where one knows only 1 example is selected + * + * @return the name of the first selected example in case of sample in all + * other cases null + */ + public String getLibraryName() { + switch (myCodeType) { + case sample: + return getLibraryName(myExamples.get(0)); + default: + break; + } + return null; + } + + @SuppressWarnings("nls") private static String getLibraryName(IPath examplePath) { - if ("libraries".equalsIgnoreCase(examplePath.removeLastSegments(4).lastSegment())) { - return examplePath.removeLastSegments(3).lastSegment(); - } - if ("libraries".equalsIgnoreCase(examplePath.removeLastSegments(5).lastSegment())) { - return examplePath.removeLastSegments(4).lastSegment(); - } - return examplePath.removeLastSegments(2).lastSegment(); - } - - public boolean isLinkedExample() { - - return (myCodeType==CodeTypes.sample)&&myMakeLinks; - } - /** - * returns the path of the first linked example. - * This method is used to add a include folders to the FIRST linked example - * You could argue that ALL linked examples should be in the - * include path ... - * I don't want to support this use case because if you want to do - * so you should know what you are doing and you don't need this - * - * - * @return the path to the first linked example or NULL - */ - public IPath getLinkedExamplePath() - { - if(!isLinkedExample())return null; - return myExamples.get(0); - } + if (ConfigurationPreferences.getInstallationPathExamples().isPrefixOf(examplePath)) { + return null; + } + if ("libraries".equalsIgnoreCase(examplePath.removeLastSegments(4).lastSegment())) { + return examplePath.removeLastSegments(3).lastSegment(); + } + if ("libraries".equalsIgnoreCase(examplePath.removeLastSegments(5).lastSegment())) { + return examplePath.removeLastSegments(4).lastSegment(); + } + return examplePath.removeLastSegments(2).lastSegment(); + } + + public boolean isLinkedExample() { + + return (myCodeType == CodeTypes.sample) && myMakeLinks; + } + + /** + * returns the path of the first linked example. + * This method is used to add a include folders to the FIRST linked example + * You could argue that ALL linked examples should be in the + * include path ... + * I don't want to support this use case because if you want to do + * so you should know what you are doing and you don't need this + * + * + * @return the path to the first linked example or NULL + */ + public IPath getLinkedExamplePath() { + if (!isLinkedExample()) + return null; + return myExamples.get(0); + } } 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 67ba31e46..b43f0289f 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java +++ b/io.sloeber.core/src/io/sloeber/core/api/IInstallLibraryHandler.java @@ -2,6 +2,8 @@ import java.util.Map; +import io.sloeber.core.api.Json.ArduinoLibraryVersion; + /** * this interface is to allow the ui to handle the automatic installation * of libraries. @@ -14,20 +16,23 @@ * */ -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); +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/Json/ArduinoInstallable.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoInstallable.java new file mode 100644 index 000000000..75204b032 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoInstallable.java @@ -0,0 +1,34 @@ +package io.sloeber.core.api.Json; + +import org.eclipse.core.runtime.IPath; + +public abstract class ArduinoInstallable { + + protected String archiveFileName; + protected String url; + protected String checksum; + protected String size; + protected String name; + + abstract public IPath getInstallPath(); + + public String getArchiveFileName() { + return archiveFileName; + } + + public String getUrl() { + return url; + } + + public String getChecksum() { + return checksum; + } + + public String getSize() { + return size; + } + + public String getName() { + return name; + } +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibrary.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibrary.java new file mode 100644 index 000000000..2a4e25334 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibrary.java @@ -0,0 +1,160 @@ +package io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.TreeMap; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.common.ConfigurationPreferences; + +/** + * This class represents an entry ina a library json file + * + * @author jan + * + */ + +public class ArduinoLibrary extends Node implements Comparable { + + private String name; + private TreeMap versions = new TreeMap<>(Collections.reverseOrder()); + private ArduinoLibraryIndex myParent; + + private static final String VERSION_KEY = "version"; //$NON-NLS-1$ + + @SuppressWarnings("nls") + public ArduinoLibrary(JsonElement json, ArduinoLibraryIndex libraryIndexJson) { + JsonObject jsonObject = json.getAsJsonObject(); + try { + myParent = libraryIndexJson; + name = getSafeString(jsonObject, "name"); + addVersion(json); + } catch (Exception e) { + throw new JsonParseException("failed to parse json " + e.getMessage()); + } + + } + + protected void addVersion(JsonElement json) { + JsonObject jsonObject = json.getAsJsonObject(); + VersionNumber versionNumber = getSafeVersion(jsonObject, VERSION_KEY); + versions.put(versionNumber, new ArduinoLibraryVersion(jsonObject, this)); + } + + public Collection getVersions() { + return versions.values(); + } + + public String getAuthor() { + return getNewestVersion().getAuthor(); + } + + public String getMaintainer() { + return getNewestVersion().getMaintainer(); + } + + public String getSentence() { + return getNewestVersion().getSentence(); + } + + public String getParagraph() { + return getNewestVersion().getParagraph(); + } + + public String getWebsite() { + return getNewestVersion().getWebsite(); + } + + public String getCategory() { + return getNewestVersion().getCategory(); + } + + public List getArchitectures() { + return getNewestVersion().getArchitectures(); + } + + public List getTypes() { + return getNewestVersion().getTypes(); + } + + public String getUrl() { + return getNewestVersion().getUrl(); + } + + /** + * Get the newest version of this library + * + * @return the newest version of this library + */ + public ArduinoLibraryVersion getNewestVersion() { + return versions.firstEntry().getValue(); + } + + /** + * Get the version that is installed + * If no version is installed return NULL + * + * @return + */ + public ArduinoLibraryVersion getInstalledVersion() { + for (ArduinoLibraryVersion curVersion : versions.values()) { + if (curVersion.isInstalled()) { + return curVersion; + } + } + return null; + } + + /** + * checks if a version of this library is installed. + * + * @return true if a version is installed. false in case no version is installed + */ + public boolean isInstalled() { + return getInstalledVersion() != null; + } + + @Override + public int compareTo(ArduinoLibrary other) { + return getID().compareTo(other.getID()); + } + + //Below are the Node overrides + @Override + public String getName() { + return name; + } + + @Override + public Node getParent() { + return myParent; + } + + @Override + public Node[] getChildren() { + return versions.values().toArray(new Node[versions.size()]); + } + + @Override + public String getID() { + return name; + } + + public IPath getInstallPath() { + return ConfigurationPreferences.getInstallationPathLibraries().append(this.name.replace(' ', '_')); + } + + public ArduinoLibraryVersion getVersion(VersionNumber versionNumber) { + return versions.get(versionNumber); + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibraryIndex.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibraryIndex.java new file mode 100644 index 000000000..c4212426f --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibraryIndex.java @@ -0,0 +1,122 @@ +package io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; + +import java.io.File; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.annotations.JsonAdapter; + +/** + * This class represents a json file that references libraries + * + * @author jan + * + */ +@JsonAdapter(ArduinoLibraryIndex.class) +public class ArduinoLibraryIndex extends Node + implements Comparable, JsonDeserializer { + private TreeMap libraries = new TreeMap<>(); + private transient File jsonFile; + + public void setJsonFile(File packageFile) { + jsonFile = packageFile; + } + + /** + * given a library name provide the library + * + * @param libraryName + * @return the library or null if not found + */ + public ArduinoLibrary getLibrary(String libraryName) { + return libraries.get(libraryName); + } + + /** + * get all the latest versions of all 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 (ArduinoLibrary curLibrary : libraries.values()) { + if (libNames.contains(curLibrary.getName())) { + if (!curLibrary.isInstalled()) { + ret.put(curLibrary.getName(), curLibrary.getNewestVersion()); + } + } + } + return ret; + } + + @SuppressWarnings("nls") + @Override + public ArduinoLibraryIndex deserialize(JsonElement json, Type arg1, JsonDeserializationContext arg2) + throws JsonParseException { + JsonObject jsonObject = json.getAsJsonObject(); + + try { + for (JsonElement curElement : jsonObject.get("libraries").getAsJsonArray()) { + JsonObject jsonObject2 = curElement.getAsJsonObject(); + String libName = getSafeString(jsonObject2, "name"); + ArduinoLibrary library = libraries.get(libName); + if (library == null) { + libraries.put(libName, new ArduinoLibrary(curElement, this)); + } else { + library.addVersion(curElement); + } + } + } catch (Exception e) { + throw new JsonParseException("failed to parse LibraryIndexJson json " + e.getMessage(), e); + } + + return this; + + } + + @Override + public String getName() { + return jsonFile.getName(); + } + + @Override + public Node[] getChildren() { + return libraries.values().toArray(new Node[libraries.size()]); + } + + @Override + public Node getParent() { + return null; + } + + @Override + public String getID() { + return getName(); + } + + @Override + public int compareTo(ArduinoLibraryIndex o) { + return getID().compareTo(o.getID()); + } + + public Collection getLibraries() { + return libraries.values(); + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibraryVersion.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibraryVersion.java new file mode 100644 index 000000000..a60606d58 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoLibraryVersion.java @@ -0,0 +1,169 @@ +package io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import io.sloeber.core.api.VersionNumber; + +/** + * This class represents an entry in a library json file + * + * @author jan + * + */ + +public class ArduinoLibraryVersion extends Node implements Comparable { + + private String name; + private VersionNumber version; + private String author; + private String maintainer; + private String sentence; + private String paragraph; + private String website; + private String category; + private List architectures = new ArrayList<>(); + private List types = new ArrayList<>(); + private String url; + private String archiveFileName; + private int size; + private String checksum; + private ArduinoLibrary myParent; + + public static final String LIBRARY_SOURCE_FODER = "src"; //$NON-NLS-1$ + + @SuppressWarnings("nls") + public ArduinoLibraryVersion(JsonElement json, ArduinoLibrary arduinoLibrary) { + JsonObject jsonObject = json.getAsJsonObject(); + try { + myParent = arduinoLibrary; + name = getSafeString(jsonObject, "name"); + version = getSafeVersion(jsonObject, "version"); + author = getSafeString(jsonObject, "author"); + maintainer = getSafeString(jsonObject, "maintainer"); + sentence = getSafeString(jsonObject, "sentence"); + paragraph = getSafeString(jsonObject, "paragraph"); + website = getSafeString(jsonObject, "website"); + category = getSafeString(jsonObject, "category"); + for (JsonElement curType : jsonObject.get("architectures").getAsJsonArray()) { + architectures.add(curType.getAsString()); + } + for (JsonElement curType : jsonObject.get("types").getAsJsonArray()) { + types.add(curType.getAsString()); + } + url = getSafeString(jsonObject, "url"); + archiveFileName = getSafeString(jsonObject, "archiveFileName"); + size = jsonObject.get("size").getAsInt(); + checksum = getSafeString(jsonObject, "checksum"); + } catch (Exception e) { + throw new JsonParseException("failed to parse json " + e.getMessage()); + } + + } + + public VersionNumber getVersion() { + return version; + } + + public String getAuthor() { + return author; + } + + public String getMaintainer() { + return maintainer; + } + + public String getSentence() { + return sentence; + } + + public String getParagraph() { + return paragraph; + } + + public String getWebsite() { + return website; + } + + public String getCategory() { + return category; + } + + public List getArchitectures() { + return architectures; + } + + public List getTypes() { + return types; + } + + public String getUrl() { + return url; + } + + public String getArchiveFileName() { + return archiveFileName; + } + + public int getSize() { + return size; + } + + public String getChecksum() { + return checksum; + } + + public boolean isInstalled() { + return getInstallPath().toFile().exists(); + } + + @Override + public int compareTo(ArduinoLibraryVersion other) { + if (other == null) { + return 1; + } + int ret = getLibrary().compareTo(other.getLibrary()); + if (ret != 0) { + //seems we are comparing 2 different libraries. + //No need to look at the versions + return ret; + } + return getID().compareTo(other.getID()); + } + + public ArduinoLibrary getLibrary() { + return myParent; + } + + @Override + public String getName() { + return name; + } + + @Override + public Node getParent() { + return myParent; + } + + @Override + public Node[] getChildren() { + return null; + } + + @Override + public String getID() { + return version.toString(); + } + + public IPath getInstallPath() { + return myParent.getInstallPath().append(version.toString()); + } +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPackage.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPackage.java new file mode 100644 index 000000000..cb5ce0f3c --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPackage.java @@ -0,0 +1,242 @@ +/******************************************************************************* + * 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 io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.TreeMap; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import io.sloeber.core.api.BoardsManager; +import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.common.ConfigurationPreferences; + +public class ArduinoPackage extends Node implements Comparable { + + private String name; + private String maintainer; + private String websiteURL; + private String email; + private String helpOnline; + private TreeMap platforms = new TreeMap<>(); + private TreeMap tools = new TreeMap<>(); + private transient ArduinoPlatformPackageIndex myParent = null; + + @SuppressWarnings("nls") + public ArduinoPackage(JsonElement json, ArduinoPlatformPackageIndex packageIndex) { + myParent = packageIndex; + JsonObject jsonObject = json.getAsJsonObject(); + + try { + name = getSafeString(jsonObject, "name"); + maintainer = getSafeString(jsonObject, "maintainer"); + websiteURL = getSafeString(jsonObject, "websiteURL"); + email = getSafeString(jsonObject, "email"); + helpOnline = getSafeString(jsonObject, "help", "online"); + for (JsonElement curElement : jsonObject.get("platforms").getAsJsonArray()) { + JsonObject jsonObject2 = curElement.getAsJsonObject(); + // architecture is the id for a platform + String architecture = getSafeString(jsonObject2, "architecture"); + ArduinoPlatform platform = platforms.get(architecture); + if (platform == null) { + ArduinoPlatform newPlatform = new ArduinoPlatform(curElement, this); + platforms.put(newPlatform.getID(), newPlatform); + } else { + platform.addVersion(curElement); + } + } + for (JsonElement curElement : jsonObject.get("tools").getAsJsonArray()) { + JsonObject jsonObject2 = curElement.getAsJsonObject(); + // architecture is the id for a platform + String toolName = getSafeString(jsonObject2, "name"); + ArduinoPlatformTool tool = tools.get(toolName); + if (tool == null) { + ArduinoPlatformTool newTool = new ArduinoPlatformTool(curElement, this); + tools.put(newTool.getID(), newTool); + } else { + tool.addVersion(curElement); + } + } + } catch (Exception e) { + throw new JsonParseException("failed to parse Package json " + e.getMessage()); + } + } + + public ArduinoPlatformPackageIndex getPackageIndex() { + return myParent; + } + + @Override + public String getName() { + return name; + } + + public String getMaintainer() { + return maintainer; + } + + public String getWebsiteURL() { + return websiteURL; + } + + public String getEmail() { + return email; + } + + public String getHelp() { + return helpOnline; + } + + public Collection getPlatforms() { + return platforms.values(); + } + + /** + * This method looks up the installed platforms So if you have 2 arduino avr + * platform versions installed you will get back 2. + * + * @return all the installed platforms + */ + public List getInstalledPlatforms() { + List platformMap = new LinkedList<>(); + for (ArduinoPlatform platform : platforms.values()) { + for (ArduinoPlatformVersion platformVersion : platform.getVersions()) { + if (platformVersion.isInstalled()) { + platformMap.add(platformVersion); + } + } + } + return platformMap; + } + + /** + * get tyhe platform based on the platform ID + * The platform ID is the architecture + * + * @param platformID + * @return return the platfiorm or null if not found + */ + public ArduinoPlatform getPlatform(String platformID) { + return platforms.get(platformID); + } + + public Collection getTools() { + return tools.values(); + } + + public ArduinoPlatformToolVersion getTool(String toolName, VersionNumber version) { + ArduinoPlatformTool tool = tools.get(toolName); + if (tool == null) { + return null; + } + return tool.getVersion(version); + } + + public ArduinoPlatformTool getTool(String toolName) { + return tools.get(toolName); + } + + public ArduinoPlatformToolVersion getNewestInstalled(String toolName) { + ArduinoPlatformTool tool = tools.get(toolName); + if (tool == null) { + return null; + } + return tool.getNewestInstalled(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ArduinoPackage) { + return ((ArduinoPackage) obj).getName().equals(this.name); + } + return super.equals(obj); + } + + @Override + public int hashCode() { + return this.name.hashCode(); + } + + @Override + public int compareTo(ArduinoPackage other) { + return this.name.compareTo(other.name); + } + + public void onlyKeepLatestPlatforms() { + for (ArduinoPlatform curplatform : platforms.values()) { + ArduinoPlatformVersion newestVersion = null; + for (ArduinoPlatformVersion curVersion : curplatform.getVersions()) { + if (curVersion.isInstalled()) { + if (newestVersion == null) { + newestVersion = curVersion; + } else { + if (newestVersion.getVersion().compareTo(curVersion.getVersion()) > 0) { + BoardsManager.uninstall(curVersion, null); + } else { + BoardsManager.uninstall(newestVersion, null); + } + } + } + } + } + } + + public boolean isInstalled() { + for (ArduinoPlatform platform : platforms.values()) { + if (platform.isInstalled()) { + return true; + } + } + return false; + } + + /** + * Is any version of the platform installed + * + * @param platformName + * @return if a platform with this name is installed + */ + public boolean isAVersionOfThisPlatformInstalled(String platformName) { + for (ArduinoPlatform platform : this.platforms.values()) { + if (platform.getName().equals(platformName)) { + if (platform.isInstalled()) { + return true; + } + } + } + return false; + } + + @Override + public String getID() { + return name; + } + + public IPath getInstallPath() { + return ConfigurationPreferences.getInstallationPathPackages().append(getID()); + } + + @Override + public Node[] getChildren() { + return platforms.values().toArray(new Node[platforms.size()]); + } + + @Override + public Node getParent() { + return myParent; + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatform.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatform.java new file mode 100644 index 000000000..fcf84ab1a --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatform.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * 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 io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; + +import java.util.Collection; +import java.util.Collections; +import java.util.TreeMap; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.common.Const; + +public class ArduinoPlatform implements Comparable { + + private String name; + private String architecture; + private TreeMap myVersions = new TreeMap<>(Collections.reverseOrder()); + + private ArduinoPackage myParent; + + @SuppressWarnings("nls") + public ArduinoPlatform(JsonElement json, ArduinoPackage parent) { + myParent = parent; + JsonObject jsonObject = json.getAsJsonObject(); + + try { + name = getSafeString(jsonObject, "name"); + architecture = getSafeString(jsonObject, "architecture"); + addVersion(json); + } catch (Exception e) { + throw new JsonParseException("failed to parse ArduinoPlatform json " + e.getMessage()); + } + } + + protected void addVersion(JsonElement json) { + ArduinoPlatformVersion version = new ArduinoPlatformVersion(json, this); + myVersions.put(version.getVersion(), version); + } + + public ArduinoPackage getParent() { + return this.myParent; + } + + public String getName() { + return this.name; + } + + public String getArchitecture() { + return architecture; + } + + public boolean isInstalled() { + for (ArduinoPlatformVersion curPlatformVersion : myVersions.values()) { + if (curPlatformVersion.isInstalled()) { + return true; + } + } + return false; + } + + public IPath getInstallPath() { + return myParent.getInstallPath().append(Const.ARDUINO_HARDWARE_FOLDER_NAME).append(getID()); + } + + public String getID() { + return architecture; + } + + @Override + public int compareTo(ArduinoPlatform o) { + return name.compareTo(o.getName()); + } + + /** + * Get the newest version of this platform + * + * @return the newest version of this platform + */ + public ArduinoPlatformVersion getNewestVersion() { + return myVersions.firstEntry().getValue(); + } + + public Collection getVersions() { + return myVersions.values(); + } + + public ArduinoPlatformVersion getVersion(VersionNumber refVersion) { + return myVersions.get(refVersion); + } + + /** + * return the installed version with the newest version number + * Null if no version is installed + * + * @return + */ + public ArduinoPlatformVersion getNewestInstalled() { + for (ArduinoPlatformVersion curVersion : myVersions.values()) { + if (curVersion.isInstalled()) { + return curVersion; + } + } + return null; + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformPackageIndex.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformPackageIndex.java new file mode 100644 index 000000000..075834e4c --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformPackageIndex.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * 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 io.sloeber.core.api.Json; + +import java.io.File; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.annotations.JsonAdapter; + +@JsonAdapter(ArduinoPlatformPackageIndex.class) +public class ArduinoPlatformPackageIndex extends Node + implements Comparable, JsonDeserializer { + + private List myPackages = new ArrayList<>(); + + private transient File myJsonFile; + + public List getPackages() { + return myPackages; + } + + public ArduinoPackage getPackage(String packageName) { + for (ArduinoPackage pkg : myPackages) { + if (pkg.getName().equals(packageName)) { + return pkg; + } + } + return null; + } + + public void setPackageFile(File packageFile) { + myJsonFile = packageFile; + } + + public File getJsonFile() { + return myJsonFile; + } + + /** + * provide a identifier that uniquely identifies this package + * + * @return A ID that you can uses to identify this package + */ + public String getID() { + return myJsonFile.getPath(); + } + + @SuppressWarnings("nls") + @Override + public ArduinoPlatformPackageIndex deserialize(JsonElement json, Type arg1, JsonDeserializationContext arg2) + throws JsonParseException { + JsonObject jsonObject = json.getAsJsonObject(); + + try { + for (JsonElement curElement : jsonObject.get("packages").getAsJsonArray()) { + myPackages.add(new ArduinoPackage(curElement, this)); + } + } catch (Exception e) { + throw new JsonParseException("failed to parse PackageIndex json " + e.getMessage()); + } + + return this; + + } + + public boolean isInstalled() { + for (ArduinoPackage pkg : myPackages) { + if (pkg.isInstalled()) { + return true; + } + } + return false; + } + + @Override + public Node[] getChildren() { + return myPackages.toArray(new Node[myPackages.size()]); + } + + @Override + public Node getParent() { + return null; + } + + @Override + public String getName() { + return myJsonFile.getName(); + } + + @Override + public int compareTo(ArduinoPlatformPackageIndex o) { + return getID().compareTo(o.getID()); + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformTool.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformTool.java new file mode 100644 index 000000000..10a5ecfdf --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformTool.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * 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 io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; +import static io.sloeber.core.common.Const.*; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.TreeMap; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import io.sloeber.core.api.VersionNumber; + +public class ArduinoPlatformTool extends Node { + + private String myName; + private TreeMap myVersions = new TreeMap<>(Collections.reverseOrder()); + + private transient ArduinoPackage myParentPackage; + + @SuppressWarnings("nls") + public ArduinoPlatformTool(JsonElement json, ArduinoPackage pkg) { + myParentPackage = pkg; + JsonObject jsonObject = json.getAsJsonObject(); + + try { + myName = getSafeString(jsonObject, "name"); + addVersion(jsonObject); + } catch (Exception e) { + throw new JsonParseException("failed to parse Tool json " + e.getMessage()); + } + } + + protected void addVersion(JsonElement json) { + ArduinoPlatformToolVersion version = new ArduinoPlatformToolVersion(json, this); + myVersions.put(version.getVersion(), version); + } + + public ArduinoPackage getPackage() { + return myParentPackage; + } + + @Override + public String getName() { + return myName; + } + + public ArduinoPlatformToolVersion getVersion(VersionNumber version) { + return myVersions.get(version); + } + + public IPath getInstallPath() { + return myParentPackage.getInstallPath().append(TOOLS).append(getID()); + + } + + @Override + public Node[] getChildren() { + return myVersions.values().toArray(new Node[myVersions.size()]); + } + + @Override + public Node getParent() { + return myParentPackage; + } + + @Override + public String getID() { + return getName(); + } + + /** + * Get the newest version of this tool + * + * @return the newest version of this tool + */ + public ArduinoPlatformToolVersion getNewest() { + return myVersions.firstEntry().getValue(); + } + + /** + * return the installed version with the newest version number + * Null if no version is installed + * + * @return + */ + public ArduinoPlatformToolVersion getNewestInstalled() { + for (ArduinoPlatformToolVersion curVersion : myVersions.values()) { + if (curVersion.isInstalled()) { + return curVersion; + } + } + return null; + } + + public Collection getVersions() { + return myVersions.values(); + } + + public HashMap getEnvVars(VersionNumber defaultVersionNumber) { + + HashMap vars = new HashMap<>(); + for (ArduinoPlatformToolVersion curToolVersion : myVersions.values()) { + if (curToolVersion.isInstalled()) { + boolean skipdefault = (defaultVersionNumber == null) + || (curToolVersion.getVersion().compareTo(defaultVersionNumber) != 0); + vars.putAll(curToolVersion.getEnvVars(skipdefault)); + } + } + return vars; + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformToolVersion.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformToolVersion.java new file mode 100644 index 000000000..28fde7c81 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformToolVersion.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * 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 io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; +import static io.sloeber.core.common.Const.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import io.sloeber.core.api.VersionNumber; + +public class ArduinoPlatformToolVersion extends Node { + + private VersionNumber myVersion; + private List mySystems = new ArrayList<>(); + + private transient ArduinoPlatformTool myParentTool; + private transient IPath myInstallPath = null; + + @SuppressWarnings("nls") + public ArduinoPlatformToolVersion(JsonElement json, ArduinoPlatformTool tool) { + myParentTool = tool; + JsonObject jsonObject = json.getAsJsonObject(); + + try { + myVersion = getSafeVersion(jsonObject, "version"); + if (jsonObject.get("systems") != null) { + for (JsonElement curElement : jsonObject.get("systems").getAsJsonArray()) { + mySystems.add(new ArduinpPlatformToolSystem(curElement, this)); + } + } + } catch (Exception e) { + throw new JsonParseException("failed to parse Tool json " + e.getMessage()); + } + + } + + public ArduinoPlatformTool getTool() { + return myParentTool; + } + + @Override + public String getName() { + return myParentTool.getName(); + } + + public VersionNumber getVersion() { + return myVersion; + } + + public List getSystems() { + return mySystems; + } + + /** + * This method is fucking wierd ... + * but I can't help it... + * The problem is that the tool depency references a packager (which is part of + * the install path) + * but the tool itself doe not + * So to know where to install there are 2 options + * 1) install in the local platform (resulting in tool duplication) + * 2) search the dependency tree for the tooldepency and use the installpath + * from there + * + * @return + */ + public IPath getInstallPath() { + if (myInstallPath != null) { + return myInstallPath; + } + ArduinoPackage pkg = myParentTool.getPackage(); + for (ArduinoPlatform curPlatform : pkg.getPlatforms()) { + for (ArduinoPlatformVersion curplatformVersion : curPlatform.getVersions()) { + for (ArduinoPlatformTooldDependency curTooldependency : curplatformVersion.getToolsDependencies()) { + if (curTooldependency.getName().equals(myParentTool.getName()) + && curTooldependency.getVersion().compareTo(myVersion) == 0) { + myInstallPath = curTooldependency.getInstallPath(); + return myInstallPath; + } + } + } + } + myInstallPath = myParentTool.getInstallPath().append(getID()); + return myInstallPath; + + } + + public boolean isInstalled() { + return getInstallPath().toFile().exists(); + } + + /* + * Get the installable for this tool on this system + * May return null if none is found + */ + public ArduinoInstallable getInstallable() { + for (ArduinpPlatformToolSystem system : this.mySystems) { + if (system.isApplicable()) { + return system; + } + } + return null; + } + + @Override + public Node[] getChildren() { + return null; + } + + @Override + public Node getParent() { + return myParentTool; + } + + @Override + public String getID() { + return myVersion.toString(); + } + + public HashMap getEnvVars(boolean skipDefault) { + + HashMap vars = new HashMap<>(); + String installPath = getInstallPath().toOSString(); + String keyString = RUNTIME_TOOLS + getName() + getVersion() + DOT_PATH; + vars.put(keyString, installPath); + keyString = RUNTIME_TOOLS + getName() + '-' + getVersion() + DOT_PATH; + vars.put(keyString, installPath); + if (skipDefault) { + return vars; + } + keyString = RUNTIME_TOOLS + getName() + DOT_PATH; + vars.put(keyString, installPath); + return vars; + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformTooldDependency.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformTooldDependency.java new file mode 100644 index 000000000..5a0e032b4 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformTooldDependency.java @@ -0,0 +1,54 @@ +package io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; +import static io.sloeber.core.common.Const.*; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.common.ConfigurationPreferences; + +public class ArduinoPlatformTooldDependency { + + private String myName; + private String myPackager; + private VersionNumber myVersion; + + private transient ArduinoPlatformVersion myParentPlatform; + + @SuppressWarnings("nls") + public ArduinoPlatformTooldDependency(JsonElement json, ArduinoPlatformVersion arduinoPlatformVersion) { + myParentPlatform = arduinoPlatformVersion; + JsonObject jsonObject = json.getAsJsonObject(); + try { + + myName = getSafeString(jsonObject, "name"); + myPackager = getSafeString(jsonObject, "packager"); + myVersion = getSafeVersion(jsonObject, "version"); + } catch (Exception e) { + throw new JsonParseException("failed to parse json " + e.getMessage()); + } + } + + public String getName() { + return myName; + } + + public VersionNumber getVersion() { + return myVersion; + } + + public String getPackager() { + return myPackager; + } + + public IPath getInstallPath() { + return ConfigurationPreferences.getInstallationPathPackages().append(myPackager).append(TOOLS).append(myName) + .append(myVersion.toString()); + + } +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformVersion.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformVersion.java new file mode 100644 index 000000000..98f1bc778 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformVersion.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * 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 io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.common.Const; + +public class ArduinoPlatformVersion extends ArduinoInstallable implements Comparable { + + private String architecture; + private VersionNumber version; + private String category; + + private List boards = new ArrayList<>(); + private List toolsDependencies = new ArrayList<>();; + + private ArduinoPlatform myParent; + + @SuppressWarnings("nls") + public ArduinoPlatformVersion(JsonElement json, ArduinoPlatform parent) { + myParent = parent; + JsonObject jsonObject = json.getAsJsonObject(); + + try { + name = getSafeString(jsonObject, "name"); + architecture = getSafeString(jsonObject, "architecture"); + version = getSafeVersion(jsonObject, "version"); + category = getSafeString(jsonObject, "category"); + url = getSafeString(jsonObject, "url"); + archiveFileName = getSafeString(jsonObject, "archiveFileName"); + checksum = getSafeString(jsonObject, "checksum"); + size = getSafeString(jsonObject, "size"); + for (JsonElement curElement : jsonObject.get("boards").getAsJsonArray()) { + boards.add(getSafeString(curElement.getAsJsonObject(), "name")); + } + if (jsonObject.get("toolsDependencies") != null) { + for (JsonElement curElement : jsonObject.get("toolsDependencies").getAsJsonArray()) { + toolsDependencies.add(new ArduinoPlatformTooldDependency(curElement, this)); + } + } + } catch (Exception e) { + throw new JsonParseException("failed to parse ArduinoPlatform json " + e.getMessage()); + } + } + + public ArduinoPlatform getParent() { + return myParent; + } + + public String getArchitecture() { + return architecture; + } + + public VersionNumber getVersion() { + return version; + } + + public String getCategory() { + return category; + } + + public List getToolsDependencies() { + return toolsDependencies; + } + + public boolean isInstalled() { + return getBoardsFile().exists(); + } + + public File getBoardsFile() { + return getInstallPath().append(Const.BOARDS_FILE_NAME).toFile(); + } + + public File getPlatformFile() { + return getInstallPath().append(Const.PLATFORM_FILE_NAME).toFile(); + } + + @Override + public IPath getInstallPath() { + return getParent().getInstallPath().append(this.version.toString()); + } + + public List getIncludePath() { + IPath installPath = getInstallPath(); + return Arrays.asList(installPath.append("cores/{build.core}"), //$NON-NLS-1$ + installPath.append(Const.VARIANTS_FOLDER_NAME + "/{build.variant}")); //$NON-NLS-1$ + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.name == null) ? 0 : this.name.hashCode()); + result = prime * result + ((this.myParent == null) ? 0 : this.myParent.hashCode()); + result = prime * result + ((this.version == null) ? 0 : this.version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ArduinoPlatformVersion other = (ArduinoPlatformVersion) obj; + if (this.name == null) { + if (other.name != null) + return false; + } else if (!this.name.equals(other.name)) + return false; + if (this.myParent == null) { + if (other.myParent != null) + return false; + } else if (!this.myParent.equals(other.myParent)) + return false; + if (this.version == null) { + if (other.version != null) + return false; + } else if (!this.version.equals(other.version)) + return false; + return true; + } + + public List getBoardNames() { + return boards; + } + + public String getID() { + return version.toString(); + } + + public String getConcattenatedBoardNames() { + return String.join("\n", getBoardNames()); //$NON-NLS-1$ + } + + @Override + public int compareTo(ArduinoPlatformVersion o) { + return name.compareTo(o.getName()); + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinpPlatformToolSystem.java b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinpPlatformToolSystem.java new file mode 100644 index 000000000..23ce3b5d8 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/ArduinpPlatformToolSystem.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * 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 io.sloeber.core.api.Json; + +import static io.sloeber.core.Gson.GsonConverter.*; + +import org.eclipse.core.runtime.IPath; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +public class ArduinpPlatformToolSystem extends ArduinoInstallable { + + private transient ArduinoPlatformToolVersion myParent; + protected String host; + + @SuppressWarnings("nls") + public ArduinpPlatformToolSystem(JsonElement json, ArduinoPlatformToolVersion tool) { + myParent = tool; + JsonObject jsonObject = json.getAsJsonObject(); + + try { + host = getSafeString(jsonObject, "host"); + archiveFileName = getSafeString(jsonObject, "archiveFileName"); + url = getSafeString(jsonObject, "url"); + checksum = getSafeString(jsonObject, "checksum"); + size = getSafeString(jsonObject, "size"); + } catch (Exception e) { + throw new JsonParseException("failed to parse Tool json " + e.getMessage()); + } + } + + /** + * Is the tool compatible with the system sloeber is running on + * + * code as taken from arduino HostDependentDownloadableContribution + * https://github.com/arduino/Arduino/blob/master/arduino-core/src/cc/arduino/contributions/packages/HostDependentDownloadableContribution.java + * + * @return true if ok; false if not + */ + @SuppressWarnings("nls") + public boolean isApplicable() { + + String osName = System.getProperty("os.name"); + String osArch = System.getProperty("os.arch"); + + if (osName.contains("Linux")) { + if (osArch.equals("arm")) { + // Raspberry PI, BBB or other ARM based host + + // PI: "arm-linux-gnueabihf" + // Arch-linux on PI2: "armv7l-unknown-linux-gnueabihf" + // Raspbian on PI2: "arm-linux-gnueabihf" + // Ubuntu Mate on PI2: "arm-linux-gnueabihf" + // Debian 7.9 on BBB: "arm-linux-gnueabihf" + // Raspbian on PI Zero: "arm-linux-gnueabihf" + return host.matches("arm.*-linux-gnueabihf"); + } else if (osArch.contains("aarch64")) { + return host.matches("aarch64.*-linux-gnu*"); + } else if (osArch.contains("amd64")) { + return host.matches("x86_64-.*linux-gnu"); + } else { + return host.matches("i[3456]86-.*linux-gnu"); + } + } + + if (osName.contains("Windows")) { + return host.matches("i[3456]86-.*mingw32") || host.matches("i[3456]86-.*cygwin"); + } + + if (osName.contains("Mac")) { + if (osArch.contains("x86_64")) { + return host.matches("x86_64-apple-darwin.*") || host.matches("i[3456]86-apple-darwin.*"); + } + return host.matches("i[3456]86-apple-darwin.*"); + } + + if (osName.contains("FreeBSD")) { + if (osArch.contains("arm")) { + return host.matches("arm.*-freebsd[0-9]*"); + } + return host.matches(osArch + "-freebsd[0-9]*"); + } + + return false; + } + + public String getHost() { + return this.host; + } + + @Override + public IPath getInstallPath() { + return myParent.getInstallPath(); + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/Json/Node.java b/io.sloeber.core/src/io/sloeber/core/api/Json/Node.java new file mode 100644 index 000000000..0d80dddb3 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/api/Json/Node.java @@ -0,0 +1,19 @@ +package io.sloeber.core.api.Json; + +public abstract class Node { + public boolean hasChildren() { + Node[] children = getChildren(); + if (children == null) + return false; + return children.length > 0; + }; + + abstract public Node[] getChildren(); + + abstract public Node getParent(); + + abstract public String getName(); + + abstract public String getID(); + +} diff --git a/io.sloeber.core/src/io/sloeber/core/api/LibraryDescriptor.java b/io.sloeber.core/src/io/sloeber/core/api/LibraryDescriptor.java deleted file mode 100644 index 31a186ecf..000000000 --- a/io.sloeber.core/src/io/sloeber/core/api/LibraryDescriptor.java +++ /dev/null @@ -1,16 +0,0 @@ -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() { - 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 79c5de663..b225b2007 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java +++ b/io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java @@ -8,11 +8,10 @@ import java.io.IOException; import java.io.Reader; import java.util.ArrayList; -import java.util.Collection; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; @@ -30,14 +29,15 @@ import com.google.gson.Gson; import io.sloeber.core.Activator; +import io.sloeber.core.api.Json.ArduinoLibrary; +import io.sloeber.core.api.Json.ArduinoLibraryIndex; +import io.sloeber.core.api.Json.ArduinoLibraryVersion; 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.InternalPackageManager; -import io.sloeber.core.managers.Library; -import io.sloeber.core.managers.LibraryIndex; -import io.sloeber.core.tools.Version; +import io.sloeber.core.tools.FileModifiers; +import io.sloeber.core.tools.PackageManager; /** * This class is the main entry point for libraries. It handles private @@ -47,518 +47,370 @@ * */ public class LibraryManager { - private static final String INO = "ino"; //$NON-NLS-1$ - private static final String PDE = "pde";//$NON-NLS-1$ - private static final String CPP = "cpp";//$NON-NLS-1$ - private static final String C = "c";//$NON-NLS-1$ - private static final String LIBRARY_DESCRIPTOR_PREFIX = "Library"; //$NON-NLS-1$ - private static final String EXAMPLE_DESCRIPTOR_PREFIX = "Example"; //$NON-NLS-1$ - - static private List libraryIndices; - private static IInstallLibraryHandler myInstallLibraryHandler = new DefaultInstallHandler(); - - static public List getLibraryIndices() { - if (libraryIndices == null) { - InternalPackageManager.getPackageIndices(); - } - return libraryIndices; - } - - public static LibraryTree getLibraryTree() { - return new LibraryTree(); - - } - - public static class LibraryTree { - - private TreeMap categories = new TreeMap<>(); - - public class Category implements Comparable, Node { - private String name; - protected TreeMap libraries = new TreeMap<>(); - - public Category(String name) { - this.name = name; - } - - @Override - public String getName() { - return this.name; - } - - public Collection getLibraries() { - return this.libraries.values(); - } - - @Override - public int compareTo(Category other) { - return this.name.compareTo(other.name); - } - - @Override - public boolean hasChildren() { - return !this.libraries.isEmpty(); - } - - @Override - public Object[] getChildren() { - return this.libraries.values().toArray(); - } - - @Override - public Object getParent() { - return LibraryTree.this; - } - } - - public class Library implements Comparable, Node { - private String name; - private String indexName; - private Category category; - protected TreeSet versions = new TreeSet<>(); - protected String version; - private String tooltip; - - public Library(Category category, String name, String indexName, String tooltip) { - this.category = category; - this.name = name; - this.tooltip = tooltip; - this.indexName = indexName; - } - - public Collection getVersions() { - return this.versions; - } - - @Override - public String getName() { - return this.name; - } - - public String getTooltip() { - return this.tooltip; - } - - public String getLatest() { - return this.versions.last().toString(); - } - - public String getVersion() { - return this.version; - } - - public String getIndexName() { - return this.indexName; - } - - public void setVersion(String version) { - this.version = version; - } - - @Override - public int compareTo(Library other) { - return this.name.compareTo(other.name); - } - - @Override - public boolean hasChildren() { - return false; - } - - @Override - public Object[] getChildren() { - return null; - } - - @Override - public Object getParent() { - return this.category; - } - } - - public LibraryTree() { - for (LibraryIndex libraryIndex : getLibraryIndices()) { - for (String categoryName : libraryIndex.getCategories()) { - Category category = this.categories.get(categoryName); - if (category == null) { - category = new Category(categoryName); - this.categories.put(category.getName(), category); - } - for (io.sloeber.core.managers.Library library : libraryIndex.getLibraries(categoryName)) { - Library lib = category.libraries.get(library.getName() + " (" + libraryIndex.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - if (lib == null) { - String builder = "Architectures:" + library.getArchitectures().toString() + "\n\n" //$NON-NLS-1$ //$NON-NLS-2$ - + library.getSentence(); - lib = new Library(category, library.getName(), libraryIndex.getName(), builder); - category.libraries.put(library.getName() + " (" + libraryIndex.getName() + ")", lib); //$NON-NLS-1$//$NON-NLS-2$ - } - lib.versions.add(new VersionNumber(library.getVersion())); - if (library.isInstalled()) { - lib.version = library.getVersion(); - } - } - } - } - } - - public Collection getCategories() { - return this.categories.values(); - } - - public Collection getAllLibraries() { - Set all = new TreeSet<>(); - for (Category category : this.categories.values()) { - all.addAll(category.getLibraries()); - } - return all; - } - - private static LibraryIndex findLibraryIndex(String name) { - for (LibraryIndex libraryIndex : getLibraryIndices()) { - if (libraryIndex.getName().equals(name)) - return libraryIndex; - } - return null; - } - - public void reset() { - for (Library library : this.getAllLibraries()) { - LibraryIndex libraryIndex = findLibraryIndex(library.getIndexName()); - - if (libraryIndex != null) { - io.sloeber.core.managers.Library installed = libraryIndex.getInstalledLibrary(library.getName()); - library.setVersion(installed != null ? installed.getVersion() : null); - } - } - } - - } - - public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor, MultiStatus status) { - for (LibraryTree.Library lib : libs.getAllLibraries()) { - LibraryIndex libraryIndex = getLibraryIndex(lib.getIndexName()); - - if (libraryIndex != null) { - io.sloeber.core.managers.Library toRemove = libraryIndex.getInstalledLibrary(lib.getName()); - if (toRemove != null && !toRemove.getVersion().equals(lib.getVersion())) { - status.add(toRemove.remove(monitor)); - } - io.sloeber.core.managers.Library toInstall = libraryIndex.getLibrary(lib.getName(), lib.getVersion()); - if (toInstall != null && !toInstall.isInstalled()) { - status.add(toInstall.install(monitor)); - } - } - - if (monitor.isCanceled()) - return Status.CANCEL_STATUS; - } - return status; - } - - public static String getPrivateLibraryPathsString() { - return InstancePreferences.getPrivateLibraryPathsString(); - } - - public static void setPrivateLibraryPaths(String[] libraryPaths) { - InstancePreferences.setPrivateLibraryPaths(libraryPaths); - - } - - - public static void InstallDefaultLibraries(IProgressMonitor monitor) { - LibraryIndex libindex = getLibraryIndex(Defaults.DEFAULT); - if (libindex == null) - return; - - for (String library : Defaults.DEFAULT_INSTALLED_LIBRARIES) { - Library toInstalLib = libindex.getLatestLibrary(library); - if (toInstalLib != null) { - toInstalLib.install(monitor); - } - } - } - - static private LibraryIndex getLibraryIndex(String name) { - for (LibraryIndex index : getLibraryIndices()) { - if (index.getName().equals(name)) { - return index; - } - } - return null; - } - - static public void loadJson(File jsonFile) { - try (Reader reader = new FileReader(jsonFile)) { - LibraryIndex index = new Gson().fromJson(reader, LibraryIndex.class); - index.resolve(); - index.setJsonFile(jsonFile); - libraryIndices.add(index); - } catch (Exception e) { - Common.log(new Status(IStatus.ERROR, Activator.getId(), + private static final String INO = "ino"; //$NON-NLS-1$ + private static final String PDE = "pde";//$NON-NLS-1$ + private static final String CPP = "cpp";//$NON-NLS-1$ + private static final String C = "c";//$NON-NLS-1$ + private static final String LIBRARY_DESCRIPTOR_PREFIX = "Library"; //$NON-NLS-1$ + private static final String EXAMPLE_DESCRIPTOR_PREFIX = "Example"; //$NON-NLS-1$ + + static private List libraryIndices; + private static IInstallLibraryHandler myInstallLibraryHandler = new DefaultInstallHandler(); + + static public List getLibraryIndices() { + if (libraryIndices == null) { + BoardsManager.getPackageIndices(); + } + return libraryIndices; + } + + public static IStatus install(List removeLibs, List addLibs, + IProgressMonitor monitor, MultiStatus status) { + for (ArduinoLibraryVersion lib : removeLibs) { + status.add(unInstall(lib, monitor)); + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + } + for (ArduinoLibraryVersion lib : addLibs) { + status.add(install(lib, monitor)); + if (monitor.isCanceled()) + return Status.CANCEL_STATUS; + } + return status; + } + + public static String getPrivateLibraryPathsString() { + return InstancePreferences.getPrivateLibraryPathsString(); + } + + public static void setPrivateLibraryPaths(String[] libraryPaths) { + InstancePreferences.setPrivateLibraryPaths(libraryPaths); + + } + + public static void InstallDefaultLibraries(IProgressMonitor monitor) { + for (ArduinoLibraryIndex libindex : libraryIndices) { + + for (String libraryName : Defaults.DEFAULT_INSTALLED_LIBRARIES) { + ArduinoLibrary toInstalLib = libindex.getLibrary(libraryName); + if (toInstalLib != null) { + ArduinoLibraryVersion toInstalLibVersion = toInstalLib.getNewestVersion(); + ArduinoLibraryVersion instaledLibVersion = toInstalLib.getInstalledVersion(); + if (toInstalLibVersion != null) { + if (toInstalLibVersion != instaledLibVersion) { + if (instaledLibVersion != null) { + unInstall(instaledLibVersion, monitor); + } + install(toInstalLibVersion, monitor); + } + } + } + } + } + } + + static public void loadJson(File jsonFile) { + try (Reader reader = new FileReader(jsonFile)) { + ArduinoLibraryIndex index = new Gson().fromJson(reader, ArduinoLibraryIndex.class); + index.setJsonFile(jsonFile); + libraryIndices.add(index); + } catch (Exception e) { + Common.log(new Status(IStatus.ERROR, Activator.getId(), Manager_Failed_to_parse.replace(FILE_TAG, jsonFile.getAbsolutePath()), e)); - jsonFile.delete();// Delete the file so it stops damaging - } - } - - /** + jsonFile.delete();// Delete the file so it stops damaging + } + } + + /** * install 1 single library based on the library name + * * @param libName */ public static void installLibrary(String libName) { Set libNamesToInstall = new TreeSet<>(); libNamesToInstall.add(libName); - Map libsToInstall = LibraryManager.getLatestInstallableLibraries(libNamesToInstall); + Map libsToInstall = LibraryManager + .getLatestInstallableLibraries(libNamesToInstall); if (!libsToInstall.isEmpty()) { - for (Entry curLib : libsToInstall.entrySet()) { - curLib.getValue().toLibrary().install(new NullProgressMonitor()); + for (ArduinoLibraryVersion curLib : libsToInstall.values()) { + install(curLib, new NullProgressMonitor()); + } + } + } + + public static IStatus install(ArduinoLibraryVersion lib, IProgressMonitor monitor) { + monitor.setTaskName("Downloading and installing " + lib.getName() + " library."); //$NON-NLS-1$ //$NON-NLS-2$ + if (lib.isInstalled()) { + return Status.OK_STATUS; + } + IStatus ret = PackageManager.downloadAndInstall(lib.getUrl(), lib.getArchiveFileName(), lib.getInstallPath(), + false, monitor); + FileModifiers.addPragmaOnce(lib.getInstallPath()); + return ret; + } + + /** + * 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 + */ + public static IStatus unInstall(ArduinoLibraryVersion lib, IProgressMonitor monitor) { + if (!lib.isInstalled()) { + return Status.OK_STATUS; + } + + try { + FileUtils.deleteDirectory(lib.getInstallPath().toFile().getParentFile()); + } catch (IOException e) { + return new Status(IStatus.ERROR, Activator.getId(), + "Failed to remove folder" + lib.getInstallPath().toString(), //$NON-NLS-1$ + e); + } + + return Status.OK_STATUS; + } + + /** + * 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 + */ + public static void installAllLatestLibraries() { + List libraryIndices1 = getLibraryIndices(); + for (ArduinoLibraryIndex libraryIndex : libraryIndices1) { + for (ArduinoLibrary curLib : libraryIndex.getLibraries()) { + String curLibName = curLib.getName(); + String[] skipArray = { "Base64", "Add others if needed" }; //$NON-NLS-1$ //$NON-NLS-2$ + List skipList = Arrays.asList(skipArray); + if (!skipList.contains(curLibName)) { + ArduinoLibraryVersion latestLibVersion = curLib.getNewestVersion(); + if (!latestLibVersion.isInstalled()) { + ArduinoLibraryVersion installedLibVersion = curLib.getInstalledVersion(); + if (installedLibVersion != null) { + unInstall(installedLibVersion, null); + } + install(latestLibVersion, null); + } + } } } } - /** - * 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 - */ - public static void installAllLatestLibraries() { - List libraryIndices1 = getLibraryIndices(); - Map latestLibs = new HashMap<>(); - for (LibraryIndex libraryIndex : libraryIndices1) { - Map libraries = libraryIndex.getLatestLibraries(); - for (Map.Entry entry : libraries.entrySet()) { - String curLibName = entry.getKey(); - Library curLibrary = entry.getValue(); - Library current = latestLibs.get(curLibName); - if (current != null) { - if (Version.compare(curLibrary.getVersion(), current.getVersion()) > 0) { - latestLibs.put(curLibName, curLibrary); - } - } else { - latestLibs.put(curLibName, curLibrary); - } - } - } - // Base64 is a 1.0.0 version replaced with base64 So Don't install it - latestLibs.remove("Base64"); //$NON-NLS-1$ - for (Map.Entry entry : latestLibs.entrySet()) { - String curLibName = entry.getKey(); - Library curLibrary = entry.getValue(); - for (LibraryIndex libraryIndex : libraryIndices1) { - - Library previousVersion = libraryIndex.getInstalledLibrary(curLibName); - if ((previousVersion != null) && (previousVersion != curLibrary)) { - previousVersion.remove(new NullProgressMonitor()); - } - } - if (!curLibrary.isInstalled()) { - curLibrary.install(new NullProgressMonitor()); - } - } - - } - - public static void flushIndices() { - libraryIndices = new ArrayList<>(); - } - - public static void removeAllLibs() { - try { - FileUtils.deleteDirectory(ConfigurationPreferences.getInstallationPathLibraries().toFile()); - } catch (IOException e) { - e.printStackTrace(); - } - } - - 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; - } - - public static void registerInstallLibraryHandler(IInstallLibraryHandler installLibraryHandler) { - myInstallLibraryHandler = installLibraryHandler; - } - - public static IInstallLibraryHandler getInstallLibraryHandler() { - return myInstallLibraryHandler; - } - - /** - * Check wether a library is installed. The check looks at the library - * installation place at the disk. - * - * @return true if at least one library is installed - */ - public static boolean libsAreInstalled() { - if (ConfigurationPreferences.getInstallationPathLibraries().toFile().exists()) { - return ConfigurationPreferences.getInstallationPathLibraries().toFile().list().length != 0; - } - return false; - } - - /** - * find all examples that are delivered with a library This does not include the - * libraries delivered with hardware - * - * @return - */ - public static TreeMap getAllLibraryExamples() { - TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - String libLocations[] = InstancePreferences.getPrivateLibraryPaths(); - - File CommonLibLocation = ConfigurationPreferences.getInstallationPathLibraries().toFile(); - if (CommonLibLocation.exists()) { - examples.putAll(getLibExampleFolders(CommonLibLocation)); - } - - // get the examples from the user provide library locations - if (libLocations != null) { - for (String curLibLocation : libLocations) { - File curFile = new File(curLibLocation); - if (curFile.exists()) { - examples.putAll(getLibExampleFolders(curFile)); - } - } - } - return examples; - } - - /*** - * finds all the example folders for both the version including and without - * version libraries - * - * @param location - * The parent folder of the libraries - */ - private static TreeMap getLibExampleFolders(File LibRoot) { - TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - - if (LibRoot == null) { - return examples; - } - String[] Libs = LibRoot.list(); - if (Libs == null) { - // Either dir does not exist or is not a directory - return examples; - } - for (String curLib : Libs) { - String libID = LIBRARY_DESCRIPTOR_PREFIX + '/' + curLib; - File Lib_examples = LibRoot.toPath().resolve(curLib).resolve("examples").toFile();//$NON-NLS-1$ - File Lib_Examples = LibRoot.toPath().resolve(curLib).resolve("Examples").toFile();//$NON-NLS-1$ - if (Lib_examples.isDirectory()) { + public static void flushIndices() { + libraryIndices = new ArrayList<>(); + } + + public static void unInstallAllLibs() { + try { + FileUtils.deleteDirectory(ConfigurationPreferences.getInstallationPathLibraries().toFile()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static Map getLatestInstallableLibraries(Set libnames) { + Set remainingLibNames = new TreeSet<>(libnames); + Map ret = new HashMap<>(); + for (ArduinoLibraryIndex libraryIndex : libraryIndices) { + 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; + } + + /** + * Check wether a library is installed. The check looks at the library + * installation place at the disk. + * + * @return true if at least one library is installed + */ + public static boolean libsAreInstalled() { + if (ConfigurationPreferences.getInstallationPathLibraries().toFile().exists()) { + return ConfigurationPreferences.getInstallationPathLibraries().toFile().list().length != 0; + } + return false; + } + + /** + * find all examples that are delivered with a library This does not include the + * libraries delivered with hardware + * + * @return + */ + public static TreeMap getAllLibraryExamples() { + TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + String libLocations[] = InstancePreferences.getPrivateLibraryPaths(); + + File CommonLibLocation = ConfigurationPreferences.getInstallationPathLibraries().toFile(); + if (CommonLibLocation.exists()) { + examples.putAll(getLibExampleFolders(CommonLibLocation)); + } + + // get the examples from the user provide library locations + if (libLocations != null) { + for (String curLibLocation : libLocations) { + File curFile = new File(curLibLocation); + if (curFile.exists()) { + examples.putAll(getLibExampleFolders(curFile)); + } + } + } + return examples; + } + + /*** + * finds all the example folders for both the version including and without + * version libraries + * + * @param location + * The parent folder of the libraries + */ + private static TreeMap getLibExampleFolders(File LibRoot) { + TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + + if (LibRoot == null) { + return examples; + } + String[] Libs = LibRoot.list(); + if (Libs == null) { + // Either dir does not exist or is not a directory + return examples; + } + for (String curLib : Libs) { + String libID = LIBRARY_DESCRIPTOR_PREFIX + '/' + curLib; + File Lib_examples = LibRoot.toPath().resolve(curLib).resolve("examples").toFile();//$NON-NLS-1$ + File Lib_Examples = LibRoot.toPath().resolve(curLib).resolve("Examples").toFile();//$NON-NLS-1$ + if (Lib_examples.isDirectory()) { examples.putAll(getExamplesFromFolder(libID, Lib_examples, 2)); - } else if (Lib_Examples.isDirectory()) { + } else if (Lib_Examples.isDirectory()) { examples.putAll(getExamplesFromFolder(libID, Lib_Examples, 2)); - } else // nothing found directly so maybe this is a version - // based lib - { - String[] versions = LibRoot.toPath().resolve(curLib).toFile().list(); - if (versions != null) { - if (versions.length == 1) {// There can only be 1 - // version of a lib - Lib_examples = LibRoot.toPath().resolve(curLib).resolve(versions[0]).resolve("examples") //$NON-NLS-1$ - .toFile(); - Lib_Examples = LibRoot.toPath().resolve(curLib).resolve(versions[0]).resolve("Examples") //$NON-NLS-1$ - .toFile(); - if (Lib_examples.isDirectory()) { + } else // nothing found directly so maybe this is a version + // based lib + { + String[] versions = LibRoot.toPath().resolve(curLib).toFile().list(); + if (versions != null) { + if (versions.length == 1) {// There can only be 1 + // version of a lib + Lib_examples = LibRoot.toPath().resolve(curLib).resolve(versions[0]).resolve("examples") //$NON-NLS-1$ + .toFile(); + Lib_Examples = LibRoot.toPath().resolve(curLib).resolve(versions[0]).resolve("Examples") //$NON-NLS-1$ + .toFile(); + if (Lib_examples.isDirectory()) { examples.putAll(getExamplesFromFolder(libID, Lib_examples, 2)); - } else if (Lib_Examples.isDirectory()) { + } else if (Lib_Examples.isDirectory()) { examples.putAll(getExamplesFromFolder(libID, Lib_Examples, 2)); - } - } - } - } - } - - return examples; - } - - /** - * This method adds a folder recursively examples. Leaves containing ino files - * are assumed to be examples - * - * @param File - */ + } + } + } + } + } + + return examples; + } + + /** + * This method adds a folder recursively examples. Leaves containing ino files + * are assumed to be examples + * + * @param File + */ private static TreeMap getExamplesFromFolder(String prefix, File location, int maxDepth) { - TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - File[] children = location.listFiles(); + TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + File[] children = location.listFiles(); if ((children == null) || (maxDepth <= 0)) { - // Either dir does not exist or is not a directory - return examples; - } + // Either dir does not exist or is not a directory + return examples; + } int newmaxDepth = maxDepth - 1; - for (File exampleFolder : children) { + for (File exampleFolder : children) { String extension = FilenameUtils.getExtension(exampleFolder.toString()).toLowerCase(); - if (exampleFolder.isDirectory()) { + if (exampleFolder.isDirectory()) { examples.putAll( getExamplesFromFolder(prefix + '/' + exampleFolder.getName(), exampleFolder, newmaxDepth)); } else if (INO.equals(extension) || PDE.equals(extension) || CPP.equals(extension) || C.equals(extension)) { - examples.put(prefix, new Path(location.toString())); - } - } - return examples; - } - - /* - * Get the examples of the libraries from the selected hardware These may be - * referenced libraries - */ - private static TreeMap getAllHardwareLibraryExamples(BoardDescription boardDescriptor) { - TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - if (boardDescriptor != null) { - IPath platformPath = boardDescriptor.getreferencingPlatformPath(); - if (platformPath.toFile().exists()) { - examples.putAll(getLibExampleFolders(platformPath.append(LIBRARY_PATH_SUFFIX).toFile())); - } - } - return examples; - } - - /** - * find all examples that are delivered with the Arduino IDE - * - * @return - */ - public static TreeMap getAllArduinoIDEExamples() { - TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - File exampleLocation = ConfigurationPreferences.getInstallationPathExamples().toFile(); - - if (exampleLocation.exists()) { + examples.put(prefix, new Path(location.toString())); + } + } + return examples; + } + + /* + * Get the examples of the libraries from the selected hardware These may be + * referenced libraries + */ + private static TreeMap getAllHardwareLibraryExamples(BoardDescription boardDescriptor) { + TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + if (boardDescriptor != null) { + IPath platformPath = boardDescriptor.getreferencingPlatformPath(); + if (platformPath.toFile().exists()) { + examples.putAll(getLibExampleFolders(platformPath.append(LIBRARY_PATH_SUFFIX).toFile())); + } + } + return examples; + } + + /** + * find all examples that are delivered with the Arduino IDE + * + * @return + */ + public static TreeMap getAllArduinoIDEExamples() { + TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + File exampleLocation = ConfigurationPreferences.getInstallationPathExamples().toFile(); + + if (exampleLocation.exists()) { examples.putAll(getExamplesFromFolder(EXAMPLE_DESCRIPTOR_PREFIX, exampleLocation, 100)); - } - return examples; - } - - /** - * find all examples for this type of board. That is the examples provided by - * Arduino The examples provided by the common libraries The examples provided - * by the private libraries The examples provided by the platform the board - * belongs to - * - * If the boardID is null there will be no platform examples - * - * @param boardDescriptor - * @return - */ - public static TreeMap getAllExamples(BoardDescription boardDescriptor) { - TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - // Get the examples of the library manager installed libraries - - examples.putAll(getAllLibraryExamples()); - examples.putAll(getAllArduinoIDEExamples()); - // This one should be the last as hasmap overwrites doubles. This way - // hardware libraries are preferred to others - examples.putAll(getAllHardwareLibraryExamples(boardDescriptor)); - - return examples; - } + } + return examples; + } + + /** + * find all examples for this type of board. That is the examples provided by + * Arduino The examples provided by the common libraries The examples provided + * by the private libraries The examples provided by the platform the board + * belongs to + * + * If the boardID is null there will be no platform examples + * + * @param boardDescriptor + * @return + */ + public static TreeMap getAllExamples(BoardDescription boardDescriptor) { + TreeMap examples = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + // Get the examples of the library manager installed libraries + + examples.putAll(getAllLibraryExamples()); + examples.putAll(getAllArduinoIDEExamples()); + // This one should be the last as hasmap overwrites doubles. This way + // hardware libraries are preferred to others + examples.putAll(getAllHardwareLibraryExamples(boardDescriptor)); + return examples; + } + + public static IStatus updateLibraries(Set toUnInstallLibs, + Set toInstallLibs, IProgressMonitor monitor, MultiStatus status) { + for (ArduinoLibraryVersion curLib : toUnInstallLibs) { + status.add(unInstall(curLib, monitor)); + } + for (ArduinoLibraryVersion curLib : toInstallLibs) { + status.add(install(curLib, monitor)); + } + return status; + } } \ No newline at end of file diff --git a/io.sloeber.core/src/io/sloeber/core/api/Node.java b/io.sloeber.core/src/io/sloeber/core/api/Node.java deleted file mode 100644 index d5c13d56e..000000000 --- a/io.sloeber.core/src/io/sloeber/core/api/Node.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.sloeber.core.api; - -public interface Node { - boolean hasChildren(); - - Object[] getChildren(); - - Object getParent(); - - String getName(); -} \ No newline at end of file diff --git a/io.sloeber.core/src/io/sloeber/core/api/Other.java b/io.sloeber.core/src/io/sloeber/core/api/Other.java deleted file mode 100644 index 8bad43589..000000000 --- a/io.sloeber.core/src/io/sloeber/core/api/Other.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.sloeber.core.api; - -import io.sloeber.core.common.ConfigurationPreferences; - -public class Other { - public static String getSystemHash() { - return ConfigurationPreferences.getSystemHash(); - } -} diff --git a/io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java b/io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java index 3d52c48aa..b0fc60b07 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java +++ b/io.sloeber.core/src/io/sloeber/core/api/SloeberProject.java @@ -1101,10 +1101,10 @@ private IStatus BuildTarget(String targetName) { try { IMakeTargetManager targetManager = MakeCorePlugin.getDefault().getTargetManager(); - IContainer targetResource = myProject.getFolder("Release"); + IContainer targetResource = myProject.getFolder("Release"); //$NON-NLS-1$ IMakeTarget target = targetManager.findTarget(targetResource, targetName); if (target == null) { - target = targetManager.createTarget(myProject, targetName, "org.eclipse.cdt.build.MakeTargetBuilder"); + target = targetManager.createTarget(myProject, targetName, "org.eclipse.cdt.build.MakeTargetBuilder"); //$NON-NLS-1$ target.setBuildTarget(targetName); targetManager.addTarget(targetResource, target); } @@ -1112,8 +1112,7 @@ private IStatus BuildTarget(String targetName) { target.build(new NullProgressMonitor()); } } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + return new Status(IStatus.ERROR, CORE_PLUGIN_ID, e.getMessage(), e); } return Status.OK_STATUS; } diff --git a/io.sloeber.core/src/io/sloeber/core/api/VersionNumber.java b/io.sloeber.core/src/io/sloeber/core/api/VersionNumber.java index 30e178270..89408b09f 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/VersionNumber.java +++ b/io.sloeber.core/src/io/sloeber/core/api/VersionNumber.java @@ -1,42 +1,77 @@ package io.sloeber.core.api; + @SuppressWarnings("unused") public class VersionNumber implements Comparable { private String[] parts; public VersionNumber(String version) { - this.parts = version.split("\\."); //$NON-NLS-1$ + parts = version.split("\\."); //$NON-NLS-1$ } @Override public int compareTo(Object other) { - if (other instanceof String) { - return this.compareTo(new VersionNumber((String) other)); - } else if (other instanceof VersionNumber) { - return this.compareParts(((VersionNumber) other).parts, 0); - } else { - throw new UnsupportedOperationException(); - } + if (other instanceof String) { + return compareParts(new VersionNumber((String) other).parts, 0); + } else if (other instanceof VersionNumber) { + return compareParts(((VersionNumber) other).parts, 0); + } else { + throw new UnsupportedOperationException(); + } } private int compareParts(String[] other, int level) { - if (this.parts.length > level && other.length > level) { - if (this.parts[level].compareTo(other[level]) == 0) { - return this.compareParts(other, level + 1); - } - try { - return Integer.valueOf(this.parts[level]).compareTo( Integer.valueOf(Integer.parseInt(other[level]))); - } catch (Exception e) { - return this.parts[level].compareTo(other[level]); - } - } - if (this.parts.length == other.length) { - return 0; - } - return this.parts.length > other.length ? 1 : -1; + if (parts.length > level && other.length > level) { + if (parts[level].compareTo(other[level]) == 0) { + return compareParts(other, level + 1); + } + try { + try { + int vi1 = Integer.parseInt(parts[level]); + int vi2 = Integer.parseInt(other[level]); + if (vi1 < vi2) { + return -1; + } + + if (vi1 > vi2) { + return 1; + } + } catch (NumberFormatException e) { + // not numbers try number string like 6r2 + try { + int vi1 = Integer.parseInt(parts[level].replaceAll("\\D", " ").split(" ")[0]); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + int vi2 = Integer.parseInt(other[level].replaceAll("\\D", " ").split(" ")[0]); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (vi1 < vi2) { + return -1; + } + + if (vi1 > vi2) { + return 1; + } + } catch (Exception e2) { + // + } + //do string compares + int c = parts[level].compareTo(other[level]); + if (c < 0) { + return -1; + } + if (c > 0) { + return 1; + } + } + return Integer.valueOf(this.parts[level]).compareTo(Integer.valueOf(Integer.parseInt(other[level]))); + } catch (Exception e) { + return this.parts[level].compareTo(other[level]); + } + } + if (parts.length == other.length) { + return 0; + } + return parts.length > other.length ? 1 : -1; } @Override public String toString() { - return String.join(".", this.parts); //$NON-NLS-1$ + return String.join(".", parts); //$NON-NLS-1$ } } \ No newline at end of file diff --git a/io.sloeber.core/src/io/sloeber/core/common/Common.java b/io.sloeber.core/src/io/sloeber/core/common/Common.java index 143b9ffa2..960db1e5f 100644 --- a/io.sloeber.core/src/io/sloeber/core/common/Common.java +++ b/io.sloeber.core/src/io/sloeber/core/common/Common.java @@ -29,7 +29,6 @@ public class Common { public final static String sloeberHome = getSloeberHome(); public final static IPath sloeberHomePath = new Path(sloeberHome); - public final static String sloeberHomePathToOSString = sloeberHomePath.toOSString(); public final static String sloeberHomePathToString = sloeberHomePath.toString(); private static String getSloeberHome() { @@ -54,15 +53,12 @@ private static String getSloeberHome() { e)); } return null; - } - - + } public static final boolean isWindows = Platform.getOS().equals(Platform.OS_WIN32); public static final boolean isLinux = Platform.getOS().equals(Platform.OS_LINUX); public static final boolean isMac = Platform.getOS().equals(Platform.OS_MACOSX); - /** * This method makes sure that a string can be used as a file or folder name *
@@ -70,52 +66,53 @@ private static String getSloeberHome() { * Currently it replaces (based on http://en.wikipedia.org/wiki/Filename ) / * slash used as a path name component separator in Unix-like, Windows, and * Amiga systems. (The MS-DOS command.com shell would consume it as a switch - * character, but Windows itself always accepts it as a + * character, but Windows itself always accepts it as a * separator.[6][vague]) \ backslash Also used as a path name component * separator in MS-DOS, OS/2 and Windows (where there are few differences * between slash and backslash); allowed in Unix filenames, see Note 1 ? - * question mark used as a wildcard in Unix, Windows and AmigaOS; marks a - * single character. Allowed in Unix filenames, see Note 1 % percent used as - * a wildcard in RT-11; marks a single character. asterisk or star used as a - * wildcard in Unix, MS-DOS, RT-11, VMS and Windows. Marks any sequence of - * characters (Unix, Windows, later versions of MS-DOS) or any sequence of - * characters in either the basename or extension (thus "*.*" in early - * versions of MS-DOS means "all files". Allowed in Unix filenames, see note - * 1 : colon used to determine the mount point / drive on Windows; used to - * determine the virtual device or physical device such as a drive on - * AmigaOS, RT-11 and VMS; used as a pathname separator in classic Mac OS. - * Doubled after a name on VMS, indicates the DECnet nodename (equivalent to - * a NetBIOS (Windows networking) hostname preceded by "\\".) | vertical bar - * or pipe designates software pipelining in Unix and Windows; allowed in - * Unix filenames, see Note 1 " quote used to mark beginning and end of - * filenames containing spaces in Windows, see Note 1 < less than used to - * redirect input, allowed in Unix filenames, see Note 1 > greater than used - * to redirect output, allowed in Unix filenames, see Note 1 . period or dot + * question mark used as a wildcard in Unix, Windows and AmigaOS; marks a + * single character. Allowed in Unix filenames, see Note 1 % percent used as + * a wildcard in RT-11; marks a single character. asterisk or star used as a + * wildcard in Unix, MS-DOS, RT-11, VMS and Windows. Marks any sequence of + * characters (Unix, Windows, later versions of MS-DOS) or any sequence of + * characters in either the basename or extension (thus "*.*" in early + * versions of MS-DOS means "all files". Allowed in Unix filenames, see note + * 1 : colon used to determine the mount point / drive on Windows; used to + * determine the virtual device or physical device such as a drive on + * AmigaOS, RT-11 and VMS; used as a pathname separator in classic Mac OS. + * Doubled after a name on VMS, indicates the DECnet nodename (equivalent to + * a NetBIOS (Windows networking) hostname preceded by "\\".) | vertical bar + * or pipe designates software pipelining in Unix and Windows; allowed in + * Unix filenames, see Note 1 " quote used to mark beginning and end of + * filenames containing spaces in Windows, see Note 1 < less than used to + * redirect input, allowed in Unix filenames, see Note 1 > greater than used + * to redirect output, allowed in Unix filenames, see Note 1 . period or dot * - * # is excluded as it is seen as a special character by make -======= - * character, but Windows itself always accepts it as a separator.[6][vague]) \ - * backslash Also used as a path name component separator in MS-DOS, OS/2 and - * Windows (where there are few differences between slash and backslash); - * allowed in Unix filenames, see Note 1 ? question mark used as a wildcard in - * Unix, Windows and AmigaOS; marks a single character. Allowed in Unix - * filenames, see Note 1 % percent used as a wildcard in RT-11; marks a single - * character. asterisk or star used as a wildcard in Unix, MS-DOS, RT-11, VMS - * and Windows. Marks any sequence of characters (Unix, Windows, later versions - * of MS-DOS) or any sequence of characters in either the basename or extension - * (thus "*.*" in early versions of MS-DOS means "all files". Allowed in Unix - * filenames, see note 1 : colon used to determine the mount point / drive on - * Windows; used to determine the virtual device or physical device such as a - * drive on AmigaOS, RT-11 and VMS; used as a pathname separator in classic Mac - * OS. Doubled after a name on VMS, indicates the DECnet nodename (equivalent to - * a NetBIOS (Windows networking) hostname preceded by "\\".) | vertical bar or - * pipe designates software pipelining in Unix and Windows; allowed in Unix + * # is excluded as it is seen as a special character by make + * ======= + * character, but Windows itself always accepts it as a separator.[6][vague]) \ + * backslash Also used as a path name component separator in MS-DOS, OS/2 and + * Windows (where there are few differences between slash and backslash); + * allowed in Unix filenames, see Note 1 ? question mark used as a wildcard in + * Unix, Windows and AmigaOS; marks a single character. Allowed in Unix + * filenames, see Note 1 % percent used as a wildcard in RT-11; marks a single + * character. asterisk or star used as a wildcard in Unix, MS-DOS, RT-11, VMS + * and Windows. Marks any sequence of characters (Unix, Windows, later versions + * of MS-DOS) or any sequence of characters in either the basename or extension + * (thus "*.*" in early versions of MS-DOS means "all files". Allowed in Unix + * filenames, see note 1 : colon used to determine the mount point / drive on + * Windows; used to determine the virtual device or physical device such as a + * drive on AmigaOS, RT-11 and VMS; used as a pathname separator in classic Mac + * OS. Doubled after a name on VMS, indicates the DECnet nodename (equivalent to + * a NetBIOS (Windows networking) hostname preceded by "\\".) | vertical bar or + * pipe designates software pipelining in Unix and Windows; allowed in Unix * filenames, see Note 1 " quote used to mark beginning and end of filenames * containing spaces in Windows, see Note 1 < less than used to redirect input, * allowed in Unix filenames, see Note 1 > greater than used to redirect output, - * allowed in Unix filenames, see Note 1 . period or dot + * allowed in Unix filenames, see Note 1 . period or dot * - * @param name the string that needs to be checked + * @param name + * the string that needs to be checked * @return a name safe to create files or folders */ public static String MakeNameCompileSafe(String name) { @@ -127,7 +124,6 @@ public static String MakeNameCompileSafe(String name) { return ret; } - /** * Logs the status information if status is OK then nothing happens * @@ -145,23 +141,26 @@ public static void log(IStatus status) { stMan.handle(status, style); break; } - case SLOEBER_STATUS_DEBUG: + case SLOEBER_STATUS_DEBUG: // break;//remove break to add debugging - default: + default: Activator.getDefault().getLog().log(status); } } - /** * * Provides the build environment variable based on project and string This * method does not add any knowledge.(like adding A.) * - * @param project the project that contains the environment variable - * @param configName the project configuration to use - * @param envName the key that describes the variable - * @param defaultvalue The return value if the variable is not found. + * @param project + * the project that contains the environment variable + * @param configName + * the project configuration to use + * @param envName + * the key that describes the variable + * @param defaultvalue + * The return value if the variable is not found. * @return The expanded build environment variable */ static public String getBuildEnvironmentVariable(IProject project, String configName, String envName, @@ -175,10 +174,13 @@ static public String getBuildEnvironmentVariable(IProject project, String config * Provides the build environment variable based on project and string This * method does not add any knowledge.(like adding A.) * - * @param project the project that contains the environment variable + * @param project + * the project that contains the environment variable * - * @param envName the key that describes the variable - * @param defaultvalue The return value if the variable is not found. + * @param envName + * the key that describes the variable + * @param defaultvalue + * The return value if the variable is not found. * @return The expanded build environment variable */ static public String getBuildEnvironmentVariable(IProject project, String envName, String defaultvalue) { @@ -191,9 +193,12 @@ static public String getBuildEnvironmentVariable(IProject project, String envNam * Provides the build environment variable based on project and string This * method does not add any knowledge.(like adding A.) * - * @param project the project that contains the environment variable - * @param envName the key that describes the variable - * @param defaultvalue The return value if the variable is not found. + * @param project + * the project that contains the environment variable + * @param envName + * the key that describes the variable + * @param defaultvalue + * The return value if the variable is not found. * @return The expanded build environment variable */ static public String getBuildEnvironmentVariable(ICConfigurationDescription configurationDescription, @@ -229,25 +234,24 @@ public static IPath getWorkspaceRoot() { * @return modified string or the original */ public static String makePathEnvironmentString(IPath path) { - return path.toOSString().replace(sloeberHomePathToOSString, SLOEBER_HOME_VAR); - } - - public static String makePathEnvironmentString(File file) { - return file.getPath().replace(sloeberHomePathToOSString, SLOEBER_HOME_VAR); + return path.toOSString().replace(sloeberHomePathToString, SLOEBER_HOME_VAR); } public static String makePathVersionString(File file) { - String osPathString = file.getPath(); - IPath path = new Path(osPathString); - return path.toString().replace(sloeberHomePathToString, SLOEBER_HOME_VAR); + return file.getPath().replace(sloeberHomePathToString, SLOEBER_HOME_VAR); } + /** + * Support for the environment variable SLOBER_HOME + * + * @param file + * @return + */ public static File resolvePathEnvironmentString(File file) { - String retString = file.getPath().replace(SLOEBER_HOME_VAR, sloeberHomePathToOSString); + String retString = file.getPath().replace(SLOEBER_HOME_VAR, sloeberHomePathToString); return new File(retString); } - /** * Converts a name to a tagged environment variable if variableName ="this" the * output is "${this}" @@ -273,5 +277,4 @@ static public String getOldWayEnvVar(ICConfigurationDescription confDesc, String getBuildEnvironmentVariable(confDesc, envName.toUpperCase(), EMPTY, true), true); } - } diff --git a/io.sloeber.core/src/io/sloeber/core/common/ConfigurationPreferences.java b/io.sloeber.core/src/io/sloeber/core/common/ConfigurationPreferences.java index 264947e1b..66392a32c 100644 --- a/io.sloeber.core/src/io/sloeber/core/common/ConfigurationPreferences.java +++ b/io.sloeber.core/src/io/sloeber/core/common/ConfigurationPreferences.java @@ -3,11 +3,6 @@ import static io.sloeber.core.common.Const.*; import java.io.File; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Collection; -import java.util.Enumeration; -import java.util.TreeSet; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -38,36 +33,6 @@ public class ConfigurationPreferences { // preference nodes private static final String PACKAGES_FOLDER_NAME = "packages"; //$NON-NLS-1$ - private static String systemHash = "no hash generated"; //$NON-NLS-1$ - static { - // make a hashkey to identify the system - Collection macs = new TreeSet<>(); - Enumeration inters; - try { - inters = NetworkInterface.getNetworkInterfaces(); - - while (inters.hasMoreElements()) { - NetworkInterface inter = inters.nextElement(); - if (inter.getHardwareAddress() == null) { - continue; - } - if (inter.isVirtual()) { - continue; - } - byte curmac[] = inter.getHardwareAddress(); - StringBuilder b = new StringBuilder(); - for (byte curbyte : curmac) { - b.append(String.format("%02X", Byte.valueOf(curbyte))); //$NON-NLS-1$ - } - macs.add(b.toString()); - } - } catch (@SuppressWarnings("unused") SocketException e) { - // ignore - } - Integer hascode = Integer.valueOf(macs.toString().hashCode()); - systemHash = hascode.toString(); - } - public static void removeKey(String key) { IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(NODE_ARDUINO); myScope.remove(key); @@ -166,14 +131,4 @@ public static void setUpdateJasonFilesFlag(boolean newFlag) { setBoolean(KEY_UPDATE_JASONS, newFlag); } - /** - * Make a unique hashKey based on system parameters so we can identify users To - * make the key the mac addresses of the network cards are used - * - * @return a unique key identifying the system - */ - public static String getSystemHash() { - return systemHash; - } - } diff --git a/io.sloeber.core/src/io/sloeber/core/common/Const.java b/io.sloeber.core/src/io/sloeber/core/common/Const.java index b3d20c8a6..f88afda6a 100644 --- a/io.sloeber.core/src/io/sloeber/core/common/Const.java +++ b/io.sloeber.core/src/io/sloeber/core/common/Const.java @@ -14,71 +14,73 @@ public class Const { public static final String NODE_ARDUINO = "io.sloeber.arduino"; //for debug messages - public static final int SLOEBER_STATUS_DEBUG=IStatus.CANCEL; - - // java stuff so I do not have to add all the time $NON-NLS-1$ - public static final String DOT = "."; - public static final String SLACH = "/"; - public static final String FALSE = "FALSE"; - public static final String TRUE = "TRUE"; - public static final String COLON = ":"; + public static final int SLOEBER_STATUS_DEBUG = IStatus.CANCEL; + + // java stuff so I do not have to add all the time $NON-NLS-1$ + public static final String DOT = "."; + public static final String SLACH = "/"; + public static final String FALSE = "FALSE"; + public static final String TRUE = "TRUE"; + public static final String COLON = ":"; public static final String EMPTY = ""; public static final String NEWLINE = "\n"; public static final String EQUAL = "="; - // arduino txt basic keys - public static final String VARIANT = "variant"; - public static final String CORE = "core"; - public static final String CORES = "cores"; - public static final String UPLOAD = "upload"; - public static final String PROGRAM = "program"; - public static final String TOOL = "tool"; - public static final String TOOLS = "tools"; + // arduino txt basic keys + public static final String VARIANT = "variant"; + public static final String CORE = "core"; + public static final String CORES = "cores"; + public static final String UPLOAD = "upload"; + public static final String PROGRAM = "program"; + public static final String TOOL = "tool"; + public static final String TOOLS = "tools"; public static final String RUNTIME = "runtime"; - public static final String MENU = "menu"; - public static final String STEP = "step"; - public static final String PATTERN = "pattern"; - public static final String NAME = "name"; - public static final String HARDWARE = "hardware"; + public static final String MENU = "menu"; + public static final String STEP = "step"; + public static final String PATTERN = "pattern"; + public static final String NAME = "name"; + public static final String HARDWARE = "hardware"; public static final String PLATFORM = "platform"; public static final String TXT = "txt"; public static final String SOURCE = "source"; public static final String COMPILER = "compiler"; - public static final String NETWORK = "network"; - public static final String PORT = "port"; - public static final String AUTH = "auth"; - public static final String RECIPE = "recipe"; - public static final String BUILD = "build"; - public static final String COM_PORT = "com_port"; - public static final String ARDUINO = "arduino"; - public static final String PATH = "path"; + public static final String NETWORK = "network"; + public static final String PORT = "port"; + public static final String AUTH = "auth"; + public static final String RECIPE = "recipe"; + public static final String BUILD = "build"; + public static final String SYSTEM = "system"; + public static final String COM_PORT = "com_port"; + public static final String ARDUINO = "arduino"; + public static final String PATH = "path"; public static final String PROTOCOL = "protocol"; + public static final String VendorArduino = "arduino"; - // arduino txt pre and suffix - public static final String NETWORK_PREFIX = "network_"; - public static final String REMOTE_SUFFIX = "_remote"; + // arduino txt pre and suffix + public static final String NETWORK_PREFIX = "network_"; + public static final String REMOTE_SUFFIX = "_remote"; - // General stuff + // General stuff public static final String PLUGIN_ID = "io.sloeber.core"; - public static final String CORE_PLUGIN_ID = "io.sloeber.arduino.core"; - public static final String ARDUINO_NATURE_ID = "io.sloeber.arduinonature"; - public static final String KEY_LAST_USED_EXAMPLES = "Last used Examples"; - public static final String SLOEBER_HOME = "SLOEBER_HOME"; + public static final String CORE_PLUGIN_ID = "io.sloeber.arduino.core"; + public static final String ARDUINO_NATURE_ID = "io.sloeber.arduinonature"; + public static final String KEY_LAST_USED_EXAMPLES = "Last used Examples"; + public static final String SLOEBER_HOME = "SLOEBER_HOME"; public static final String LOCAL = "local"; - // Folder and file Information - public static final String ARDUINO_HARDWARE_FOLDER_NAME = HARDWARE; - public static final String ARDUINO_CODE_FOLDER_NAME = CORE; + // Folder and file Information + public static final String ARDUINO_HARDWARE_FOLDER_NAME = HARDWARE; + public static final String ARDUINO_CODE_FOLDER_NAME = CORE; public static final String BOARDS_FILE_NAME = "boards" + DOT + TXT; public static final String PLATFORM_FILE_NAME = PLATFORM + DOT + TXT; - public static final String VARIANTS_FOLDER_NAME = "variants"; - public static final String LIBRARY_PATH_SUFFIX = "libraries"; - public static final String ARDUINO_VARIANT_FOLDER_PATH = ARDUINO_CODE_FOLDER_NAME + SLACH + VARIANT; - public static final String ARDUINO_CODE_FOLDER_PATH = ARDUINO_CODE_FOLDER_NAME + SLACH + CORE; + public static final String VARIANTS_FOLDER_NAME = "variants"; + public static final String LIBRARY_PATH_SUFFIX = "libraries"; + public static final String ARDUINO_VARIANT_FOLDER_PATH = ARDUINO_CODE_FOLDER_NAME + SLACH + VARIANT; + public static final String ARDUINO_CODE_FOLDER_PATH = ARDUINO_CODE_FOLDER_NAME + SLACH + CORE; public static final String SLOEBER_CFG = "sloeber.cfg"; - // Environment variable stuff + // Environment variable stuff public static final String ENV_KEY_SLOEBER_START = "sloeber" + DOT; public static final String ENV_KEY_UPLOAD_USE_1200BPS_TOUCH = UPLOAD + DOT + "use_1200bps_touch"; @@ -94,13 +96,13 @@ public class Const { public static final String PROGRAM_TOOL = PROGRAM + DOT + TOOL; public static final String UPLOAD_TOOL = UPLOAD + DOT + TOOL; - // link time variables + // link time variables public static final String EXTRA_TIME_UTC = "extra.time.UTC"; public static final String EXTRA_TIME_LOCAL = "extra.time.local"; public static final String EXTRA_TIME_ZONE = "extra.time.zone"; public static final String EXTRA_TIME_DTS = "extra.time.DTS"; - // Actions + // Actions public static final String RECIPE_C_to_O = RECIPE + DOT + "c.o" + DOT + PATTERN; public static final String RECIPE_CPP_to_O = RECIPE + DOT + "cpp.o" + DOT + PATTERN; public static final String RECIPE_S_to_O = RECIPE + DOT + "S.o" + DOT + PATTERN; @@ -113,13 +115,13 @@ public class Const { public static final String CODAN_C_to_O = RECIPE + DOT + "c.o" + DOT + CODAN; public static final String CODAN_CPP_to_O = RECIPE + DOT + "cpp.o" + DOT + CODAN; - public static final String SLOEBER_OBJCOPY = ENV_KEY_SLOEBER_START + "objcopy"; - - public static final String AVR = "avr"; - public static final String SAM = "sam"; - public static final String SAMD = "samd"; - + public static final String SLOEBER_OBJCOPY = ENV_KEY_SLOEBER_START + "objcopy"; + public static final String RUNTIME_TOOLS = RUNTIME + DOT + TOOLS + DOT; + public static final String DOT_PATH = DOT + PATH; + public static final String AVR = "avr"; + public static final String SAM = "sam"; + public static final String SAMD = "samd"; } 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 985ec95c4..a021f9d42 100644 --- a/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java +++ b/io.sloeber.core/src/io/sloeber/core/core/DefaultInstallHandler.java @@ -3,20 +3,19 @@ import java.util.Map; import io.sloeber.core.api.IInstallLibraryHandler; -import io.sloeber.core.api.LibraryDescriptor; +import io.sloeber.core.api.Json.ArduinoLibraryVersion; public class DefaultInstallHandler implements IInstallLibraryHandler { - @Override - public boolean autoInstall() { - return false; - } + @Override + public boolean autoInstall() { + return false; + } + @Override + public Map selectLibrariesToInstall(Map proposedLibsToInstall) { - @Override - public Map selectLibrariesToInstall(Map proposedLibsToInstall) { - - return proposedLibsToInstall; - } + return proposedLibsToInstall; + } } diff --git a/io.sloeber.core/src/io/sloeber/core/managers/ArduinoPlatform.java b/io.sloeber.core/src/io/sloeber/core/managers/ArduinoPlatform.java deleted file mode 100644 index 76062eb0d..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/ArduinoPlatform.java +++ /dev/null @@ -1,219 +0,0 @@ -/******************************************************************************* - * 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 io.sloeber.core.managers; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.io.FileUtils; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -import io.sloeber.core.Activator; -import io.sloeber.core.common.ConfigurationPreferences; -import io.sloeber.core.common.Const; - -public class ArduinoPlatform { - - private String name; - private String architecture; - private String version; - private String category; - private String url; - private String archiveFileName; - private String checksum; - private String size; - private List boards; - private List toolsDependencies; - - private Package myParent; - - private static final String ID_SEPERATOR = "-"; //$NON-NLS-1$ - - void setParent(Package parent) { - myParent = parent; - for (Board board : boards) { - board.setOwners(this); - } - if (this.toolsDependencies != null) { - for (ToolDependency toolDep : toolsDependencies) { - toolDep.setOwner(this); - } - } - } - - public Package getParent() { - return this.myParent; - } - - public String getName() { - return this.name; - } - - public String getArchitecture() { - return this.architecture; - } - - public String getVersion() { - return this.version; - } - - public String getCategory() { - return this.category; - } - - public String getUrl() { - return this.url; - } - - public String getArchiveFileName() { - return this.archiveFileName; - } - - public String getChecksum() { - return this.checksum; - } - - public String getSize() { - return this.size; - } - - public List getBoards() { - return this.boards; - } - - - public List getToolsDependencies() { - return this.toolsDependencies; - } - - - public boolean isInstalled() { - return getBoardsFile().exists(); - } - - public File getBoardsFile() { - return getInstallPath().append(Const.BOARDS_FILE_NAME).toFile(); - } - - public File getPlatformFile() { - return getInstallPath().append(Const.PLATFORM_FILE_NAME).toFile(); - } - - public IPath getInstallPath() { - IPath stPath = ConfigurationPreferences.getInstallationPathPackages().append(this.myParent.getName()) - .append(Const.ARDUINO_HARDWARE_FOLDER_NAME).append(this.architecture).append(this.version); - return stPath; - } - - public List getIncludePath() { - IPath installPath = getInstallPath(); - return Arrays.asList(installPath.append("cores/{build.core}"), //$NON-NLS-1$ - installPath.append(Const.VARIANTS_FOLDER_NAME + "/{build.variant}")); //$NON-NLS-1$ - } - - @SuppressWarnings("unused") - public IStatus remove(IProgressMonitor monitor) { - // Check if we're installed - if (!isInstalled()) { - return Status.OK_STATUS; - } - - try { - FileUtils.deleteDirectory(getInstallPath().toFile()); - } catch (IOException e) { - return new Status(IStatus.ERROR, Activator.getId(), "Failed to remove folder" + getInstallPath().toString(), //$NON-NLS-1$ - e); - } - - return Status.OK_STATUS; - } - - //jaba added the @SuppressWarnings("nls") because I added some debugging stuff - @SuppressWarnings("nls") - public IStatus install(IProgressMonitor monitor) { - // Check if we're installed already - if (isInstalled()) { - System.out.println("reusing platform "+name + " "+architecture +"("+version+")"); - return Status.OK_STATUS; - } - - // Download platform archive - System.out.println("start installing platform "+name + " "+architecture +"("+version+")"); - IStatus ret= InternalPackageManager.downloadAndInstall(this, false, monitor); - System.out.println("done installing platform "+name + " "+architecture +"("+version+")"); - return ret; - - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.name == null) ? 0 : this.name.hashCode()); - result = prime * result + ((this.myParent == null) ? 0 : this.myParent.hashCode()); - result = prime * result + ((this.version == null) ? 0 : this.version.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ArduinoPlatform other = (ArduinoPlatform) obj; - if (this.name == null) { - if (other.name != null) - return false; - } else if (!this.name.equals(other.name)) - return false; - if (this.myParent == null) { - if (other.myParent != null) - return false; - } else if (!this.myParent.equals(other.myParent)) - return false; - if (this.version == null) { - if (other.version != null) - return false; - } else if (!this.version.equals(other.version)) - return false; - return true; - } - - public List getBoardNames() { - List ret = new ArrayList<>(); - for (Board curBoar : this.boards) { - ret.add(curBoar.getName()); - } - return ret; - } - - - public String getID() { - String ID=new String(); - - if (myParent==null) { - ID = getInstallPath().toString(); - } - else { - ID=myParent.getName(); - } - ID=ID+ID_SEPERATOR+name+ID_SEPERATOR+architecture; - - return ID; - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/Board.java b/io.sloeber.core/src/io/sloeber/core/managers/Board.java deleted file mode 100644 index dfb02e66f..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/Board.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * 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 io.sloeber.core.managers; - -class Board { - - private String name; - private ArduinoPlatform platform; - - public Board() { - } - - - public String getName() { - return this.name; - } - - public ArduinoPlatform getPlatform() { - return this.platform; - } - - Board setOwners(ArduinoPlatform platform) { - this.platform = platform; - return this; - } - - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.name == null) ? 0 : this.name.hashCode()); - result = prime * result + ((this.platform == null) ? 0 : this.platform.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Board other = (Board) obj; - if (this.name == null) { - if (other.name != null) - return false; - } else if (!this.name.equals(other.name)) - return false; - if (this.platform == null) { - if (other.platform != null) - return false; - } else if (!this.platform.equals(other.platform)) - return false; - return true; - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/Help.java b/io.sloeber.core/src/io/sloeber/core/managers/Help.java deleted file mode 100644 index ae2c95d94..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/Help.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.sloeber.core.managers; - -class Help { - private String online; - - public String getOnline() { - return this.online; - } -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/InternalPackageManager.java b/io.sloeber.core/src/io/sloeber/core/managers/InternalPackageManager.java deleted file mode 100644 index 7e50d0254..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/InternalPackageManager.java +++ /dev/null @@ -1,691 +0,0 @@ -/******************************************************************************* - * 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 - * - * Contributors: - * QNX Software Systems - Initial API and implementation - * Jan Baeyens integrated in and extended for the arduino eclipse plugin named Sloeber - *******************************************************************************/ -package io.sloeber.core.managers; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.compress.archivers.ArchiveEntry; -import org.apache.commons.compress.archivers.ArchiveInputStream; -import org.apache.commons.compress.archivers.tar.TarArchiveEntry; -import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; -import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; -import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; -import org.apache.commons.lang.SystemUtils; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.ui.statushandlers.StatusManager; - -import io.sloeber.core.Activator; -import io.sloeber.core.Messages; -import io.sloeber.core.api.Defaults; -import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.PackageManager; -import io.sloeber.core.common.Common; -import io.sloeber.core.common.ConfigurationPreferences; -import io.sloeber.core.tools.MyMultiStatus; -import io.sloeber.core.txt.WorkAround; - -public class InternalPackageManager extends PackageManager { - - private static final String FILE = Messages.FILE_TAG; - private static final String FOLDER = Messages.FOLDER_TAG; - private static boolean myIsReady = false; - - public static boolean isReady() { - return myIsReady; - } - - private InternalPackageManager() { - } - - /** - * Loads all stuff needed and if this is the first time downloads the avr boards - * and needed tools - * - * @param monitor - */ - public static synchronized void startup_Pluging(IProgressMonitor monitor) { - loadJsons(ConfigurationPreferences.getUpdateJasonFilesFlag()); - List allBoards = getInstalledBoards(); - if (!LibraryManager.libsAreInstalled()) { - LibraryManager.InstallDefaultLibraries(monitor); - } - IPath examplesPath = ConfigurationPreferences.getInstallationPathExamples(); - if (!examplesPath.toFile().exists()) {// examples are not installed - // Download arduino IDE example programs - Common.log( - downloadAndInstall(Defaults.EXAMPLES_URL, Defaults.EXAMPLE_PACKAGE, examplesPath, false, monitor)); - } - if (allBoards.isEmpty()) { // If no boards are installed - - MyMultiStatus mstatus = new MyMultiStatus("Failed to configer Sloeber"); //$NON-NLS-1$ - - if (mstatus.isOK()) { - // if successfully installed the examples: add the boards - ArduinoPlatform platform = null; - Collection latestsPlatforms = getLatestPlatforms(); - if (!latestsPlatforms.isEmpty()) { - platform = latestsPlatforms.iterator().next(); - for (ArduinoPlatform curPlatform : latestsPlatforms) { - - if (Defaults.DEFAULT_INSTALL_PLATFORM_NAME.equalsIgnoreCase(curPlatform.getName()) - && Defaults.DEFAULT_INSTALL_ARCHITECTURE.equalsIgnoreCase(curPlatform.getArchitecture()) - && Defaults.DEFAULT_INSTALL_MAINTAINER - .equalsIgnoreCase(curPlatform.getParent().getMaintainer())) { - platform = curPlatform; - } - } - } - if (platform == null) { - mstatus.add(new Status(IStatus.ERROR, Activator.getId(), Messages.No_Platform_available)); - } else { - mstatus.addErrors(downloadAndInstall(platform, false, monitor)); - } - - } - if (!mstatus.isOK()) { - StatusManager stMan = StatusManager.getManager(); - stMan.handle(mstatus, StatusManager.LOG | StatusManager.SHOW | StatusManager.BLOCK); - } - - } - myIsReady = true; - - } - - /** - * Given a platform description in a json file download and install all needed - * stuff. All stuff is including all tools and core files and hardware specific - * libraries. That is (on windows) inclusive the make.exe - * - * @param platform - * @param monitor - * @param object - * @return - */ - static public synchronized IStatus downloadAndInstall(ArduinoPlatform platform, boolean forceDownload, - IProgressMonitor monitor) { - - MyMultiStatus mstatus = new MyMultiStatus("Failed to install " + platform.getName()); //$NON-NLS-1$ - mstatus.addErrors(downloadAndInstall(platform.getUrl(), platform.getArchiveFileName(), - platform.getInstallPath(), forceDownload, monitor)); - if (!mstatus.isOK()) { - // no use going on installing tools if the boards failed installing - return mstatus; - } - File packageFile = platform.getParent().getParent().getJsonFile(); - File copyToFile = platform.getInstallPath().append(packageFile.getName()).toFile(); - try { - Files.copy(packageFile.toPath(), copyToFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - e.printStackTrace(); - } - - if (platform.getToolsDependencies() != null) { - for (ToolDependency tool : platform.getToolsDependencies()) { - monitor.setTaskName(InstallProgress.getRandomMessage()); - mstatus.addErrors(tool.install(monitor)); - } - } - - - WorkAround.applyKnownWorkArounds(platform); - return mstatus; - - } - - synchronized - static public List getPackageIndices() { - if (packageIndices == null) { - loadJsons(false); - } - return packageIndices; - } - - static public List getBoards() { - List boards = new ArrayList<>(); - for (PackageIndex index : getPackageIndices()) { - for (Package pkg : index.getPackages()) { - for (ArduinoPlatform platform : pkg.getLatestPlatforms()) { - boards.addAll(platform.getBoards()); - } - } - } - return boards; - } - - public static List getPlatforms() { - List platforms = new ArrayList<>(); - for (PackageIndex index : getPackageIndices()) { - for (Package pkg : index.getPackages()) { - platforms.addAll(pkg.getPlatforms()); - } - } - return platforms; - } - - public static IPath getPlatformInstallPath(String vendor, String architecture) { - - for (PackageIndex index : getPackageIndices()) { - for (Package pkg : index.getPackages()) { - for (ArduinoPlatform curPlatform : pkg.getLatestInstalledPlatforms()) { - if (architecture.equalsIgnoreCase(curPlatform.getArchitecture()) - && (vendor.equalsIgnoreCase(pkg.getName()))) { - return new org.eclipse.core.runtime.Path(curPlatform.getInstallPath().toString()); - } - } - } - } - return null; - } - - public static IPath getPlatformInstallPath(String refVendor, String refArchitecture, String refVersion) { - for (PackageIndex index : getPackageIndices()) { - for (Package pkg : index.getPackages()) { - if (refVendor.equalsIgnoreCase(pkg.getName())) { - for (ArduinoPlatform curPlatform : pkg.getInstalledPlatforms()) { - if (refArchitecture.equalsIgnoreCase(curPlatform.getArchitecture()) - && refVersion.equalsIgnoreCase(curPlatform.getVersion())) { - return new org.eclipse.core.runtime.Path(curPlatform.getInstallPath().toString()); - } - } - } - } - } - return null; - } - - /** - * Given a platform.txt file find the platform in the platform manager - * - * @param platformTxt - * @return the found platform otherwise null - */ - public static ArduinoPlatform getPlatform(IPath platformPath) { - for (PackageIndex index : getPackageIndices()) { - for (Package pkg : index.getPackages()) { - for (ArduinoPlatform curPlatform : pkg.getPlatforms()) { - if (curPlatform.getInstallPath().equals(platformPath)) { - return curPlatform; - } - } - } - } - return null; - } - - static public List getLatestInstalledPlatforms() { - List platforms = new ArrayList<>(); - for (PackageIndex index : getPackageIndices()) { - for (Package pkg : index.getPackages()) { - - platforms.addAll(pkg.getLatestInstalledPlatforms()); - - } - } - return platforms; - } - - static public List getInstalledPlatforms() { - List platforms = new ArrayList<>(); - for (PackageIndex index : getPackageIndices()) { - for (Package pkg : index.getPackages()) { - - platforms.addAll(pkg.getInstalledPlatforms()); - - } - } - return platforms; - } - - static public List getInstalledBoards() { - List boards = new ArrayList<>(); - for (PackageIndex index : getPackageIndices()) { - for (Package pkg : index.getPackages()) { - for (ArduinoPlatform platform : pkg.getLatestInstalledPlatforms()) { - boards.addAll(platform.getBoards()); - } - } - } - return boards; - } - - static public List getPackages() { - List packages = new ArrayList<>(); - for (PackageIndex index : getPackageIndices()) { - packages.addAll(index.getPackages()); - } - return packages; - } - - static public Package getPackage(String JasonName, String packageName) { - for (PackageIndex index : getPackageIndices()) { - if (index.getJsonFileName().equals(JasonName)) { - return index.getPackage(packageName); - } - } - return null; - } - - static public Package getPackage(String packageName) { - for (PackageIndex index : getPackageIndices()) { - Package pkg = index.getPackage(packageName); - if (pkg != null) { - return pkg; - } - } - return null; - } - - static public Tool getTool(String packageName, String toolName, String version) { - for (PackageIndex index : getPackageIndices()) { - Package pkg = index.getPackage(packageName); - if (pkg != null) { - Tool tool = pkg.getTool(toolName, version); - if (tool != null) { - return tool; - } - } - } - return null; - } - - /** - * downloads an archive file from the internet and saves it in the download - * folder under the name "pArchiveFileName" then extrats the file to - * pInstallPath if pForceDownload is true the file will be downloaded even if - * the download file already exists if pForceDownload is false the file will - * only be downloaded if the download file does not exists The extraction is - * done with processArchive so only files types supported by this method will be - * properly extracted - * - * @param pURL the url of the file to download - * @param pArchiveFileName the name of the file in the download folder - * @param pInstallPath - * @param pForceDownload - * @param pMonitor - * @return - */ - public static IStatus downloadAndInstall(String pURL, String pArchiveFileName, IPath pInstallPath, - boolean pForceDownload, IProgressMonitor pMonitor) { - IPath dlDir = ConfigurationPreferences.getInstallationPathDownload(); - IPath archivePath = dlDir.append(pArchiveFileName); - try { - URL dl = new URL(pURL); - dlDir.toFile().mkdir(); - if (!archivePath.toFile().exists() || pForceDownload) { - pMonitor.subTask("Downloading " + pArchiveFileName + " .."); //$NON-NLS-1$ //$NON-NLS-2$ - myCopy(dl, archivePath.toFile(), true); - } - } catch (IOException e) { - return new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Failed_to_download.replace(FILE, pURL), - e); - } - return processArchive(pArchiveFileName, pInstallPath, pForceDownload, archivePath.toString(), pMonitor); - } - - private static IStatus processArchive(String pArchiveFileName, IPath pInstallPath, boolean pForceDownload, - String pArchiveFullFileName, IProgressMonitor pMonitor) { - // Create an ArchiveInputStream with the correct archiving algorithm - String faileToExtractMessage = Messages.Manager_Failed_to_extract.replace(FILE, pArchiveFullFileName); - if (pArchiveFileName.endsWith("tar.bz2")) { //$NON-NLS-1$ - try (ArchiveInputStream inStream = new TarArchiveInputStream( - new BZip2CompressorInputStream(new FileInputStream(pArchiveFullFileName)))) { - return extract(inStream, pInstallPath.toFile(), 1, pForceDownload, pMonitor); - } catch (IOException | InterruptedException e) { - return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e); - } - } else if (pArchiveFileName.endsWith("zip")) { //$NON-NLS-1$ - try (ArchiveInputStream in = new ZipArchiveInputStream(new FileInputStream(pArchiveFullFileName))) { - return extract(in, pInstallPath.toFile(), 1, pForceDownload, pMonitor); - } catch (IOException | InterruptedException e) { - return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e); - } - } else if (pArchiveFileName.endsWith("tar.gz")) { //$NON-NLS-1$ - try (ArchiveInputStream in = new TarArchiveInputStream( - new GzipCompressorInputStream(new FileInputStream(pArchiveFullFileName)))) { - return extract(in, pInstallPath.toFile(), 1, pForceDownload, pMonitor); - } catch (IOException | InterruptedException e) { - return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e); - } - } else if (pArchiveFileName.endsWith("tar")) { //$NON-NLS-1$ - try (ArchiveInputStream in = new TarArchiveInputStream(new FileInputStream(pArchiveFullFileName))) { - return extract(in, pInstallPath.toFile(), 1, pForceDownload, pMonitor); - } catch (IOException | InterruptedException e) { - return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e); - } - } else { - return new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Format_not_supported); - } - } - - public static IStatus extract(ArchiveInputStream in, File destFolder, int stripPath, boolean overwrite, - IProgressMonitor pMonitor) throws IOException, InterruptedException { - - // Folders timestamps must be set at the end of archive extraction - // (because creating a file in a folder alters the folder's timestamp) - Map foldersTimestamps = new HashMap<>(); - - String pathPrefix = new String(); - - Map hardLinks = new HashMap<>(); - Map hardLinksMode = new HashMap<>(); - Map symLinks = new HashMap<>(); - Map symLinksModifiedTimes = new HashMap<>(); - - // Cycle through all the archive entries - while (true) { - ArchiveEntry entry = in.getNextEntry(); - if (entry == null) { - break; - } - - // Extract entry info - long size = entry.getSize(); - String name = entry.getName(); - boolean isDirectory = entry.isDirectory(); - boolean isLink = false; - boolean isSymLink = false; - String linkName = null; - Integer mode = null; - Long modifiedTime = Long.valueOf(entry.getLastModifiedDate().getTime()); - - pMonitor.subTask("Processing " + name); //$NON-NLS-1$ - - { - // Skip MacOSX metadata - // http://superuser.com/questions/61185/why-do-i-get-files-like-foo-in-my-tarball-on-os-x - int slash = name.lastIndexOf('/'); - if (slash == -1) { - if (name.startsWith("._")) { //$NON-NLS-1$ - continue; - } - } else { - if (name.substring(slash + 1).startsWith("._")) { //$NON-NLS-1$ - continue; - } - } - } - - // Skip git metadata - // http://www.unix.com/unix-for-dummies-questions-and-answers/124958-file-pax_global_header-means-what.html - if (name.contains("pax_global_header")) { //$NON-NLS-1$ - continue; - } - - if (entry instanceof TarArchiveEntry) { - TarArchiveEntry tarEntry = (TarArchiveEntry) entry; - mode = Integer.valueOf(tarEntry.getMode()); - isLink = tarEntry.isLink(); - isSymLink = tarEntry.isSymbolicLink(); - linkName = tarEntry.getLinkName(); - } - - // On the first archive entry, if requested, detect the common path - // prefix to be stripped from filenames - int localstripPath = stripPath; - if (localstripPath > 0 && pathPrefix.isEmpty()) { - int slash = 0; - while (localstripPath > 0) { - slash = name.indexOf("/", slash); //$NON-NLS-1$ - if (slash == -1) { - throw new IOException(Messages.Manager_archiver_eror_single_root_folder_required); - } - slash++; - localstripPath--; - } - pathPrefix = name.substring(0, slash); - } - - // Strip the common path prefix when requested - if (!name.startsWith(pathPrefix)) { - throw new IOException(Messages.Manager_archive_error_root_folder_name_mismatch.replace(FILE, name) - .replace(FOLDER, pathPrefix)); - - } - name = name.substring(pathPrefix.length()); - if (name.isEmpty()) { - continue; - } - File outputFile = new File(destFolder, name); - - File outputLinkedFile = null; - if (isLink && linkName != null) { - if (!linkName.startsWith(pathPrefix)) { - throw new IOException(Messages.Manager_archive_error_root_folder_name_mismatch.replace(FILE, name) - .replace(FOLDER, pathPrefix)); - } - linkName = linkName.substring(pathPrefix.length()); - outputLinkedFile = new File(destFolder, linkName); - } - if (isSymLink) { - // Symbolic links are referenced with relative paths - outputLinkedFile = new File(linkName); - if (outputLinkedFile.isAbsolute()) { - System.err.println(Messages.Manager_archive_error_symbolic_link_to_absolute_path - .replace(FILE, outputFile.toString()).replace(FOLDER, outputLinkedFile.toString())); - System.err.println(); - } - } - - // Safety check - if (isDirectory) { - if (outputFile.isFile() && !overwrite) { - throw new IOException( - Messages.Manager_Cant_create_folder_exists.replace(FILE, outputFile.getPath())); - } - } else { - // - isLink - // - isSymLink - // - anything else - if (outputFile.exists() && !overwrite) { - throw new IOException(Messages.Manager_Cant_extract_file_exist.replace(FILE, outputFile.getPath())); - } - } - - // Extract the entry - if (isDirectory) { - if (!outputFile.exists() && !outputFile.mkdirs()) { - throw new IOException(Messages.Manager_Cant_create_folder.replace(FILE, outputFile.getPath())); - } - foldersTimestamps.put(outputFile, modifiedTime); - } else if (isLink) { - hardLinks.put(outputFile, outputLinkedFile); - hardLinksMode.put(outputFile, mode); - } else if (isSymLink) { - symLinks.put(outputFile, linkName); - symLinksModifiedTimes.put(outputFile, modifiedTime); - } else { - // Create the containing folder if not exists - if (!outputFile.getParentFile().isDirectory()) { - outputFile.getParentFile().mkdirs(); - } - copyStreamToFile(in, size, outputFile); - outputFile.setLastModified(modifiedTime.longValue()); - } - - // Set file/folder permission - if (mode != null && !isSymLink && outputFile.exists()) { - chmod(outputFile, mode.intValue()); - } - } - - for (Map.Entry entry : hardLinks.entrySet()) { - if (entry.getKey().exists() && overwrite) { - entry.getKey().delete(); - } - link(entry.getValue(), entry.getKey()); - Integer mode = hardLinksMode.get(entry.getKey()); - if (mode != null) { - chmod(entry.getKey(), mode.intValue()); - } - } - - for (Map.Entry entry : symLinks.entrySet()) { - if (entry.getKey().exists() && overwrite) { - entry.getKey().delete(); - } - - symlink(entry.getValue(), entry.getKey()); - entry.getKey().setLastModified(symLinksModifiedTimes.get(entry.getKey()).longValue()); - } - - // Set folders timestamps - for (Map.Entry entry : foldersTimestamps.entrySet()) { - entry.getKey().setLastModified(entry.getValue().longValue()); - } - - return Status.OK_STATUS; - - } - - private static void symlink(String from, File to) throws IOException, InterruptedException { - if (Common.isWindows) { - // needs special rights only one board seems to fail due to this - // Process process = Runtime.getRuntime().exec(new String[] { - // "mklink", from, to.getAbsolutePath() }, //$NON-NLS-1$ - // null, to.getParentFile()); - // process.waitFor(); - } else { - Process process = Runtime.getRuntime().exec(new String[] { "ln", "-s", from, to.getAbsolutePath() }, //$NON-NLS-1$ //$NON-NLS-2$ - null, to.getParentFile()); - process.waitFor(); - } - - } - - /* - * create a link file at the level of the os using mklink /H on windows makes - * that no admin rights are needed - */ - @SuppressWarnings("nls") - private static void link(File actualFile, File linkName) throws IOException, InterruptedException { - String[] command = new String[] { "ln", actualFile.getAbsolutePath(), linkName.getAbsolutePath() }; - if (SystemUtils.IS_OS_WINDOWS) { - command = new String[] { "cmd", "/c", "mklink", "/H", linkName.getAbsolutePath(), - actualFile.getAbsolutePath() }; - } - Process process = Runtime.getRuntime().exec(command, null, null); - process.waitFor(); - } - - private static void chmod(File file, int mode) throws IOException, InterruptedException { - String octal = Integer.toOctalString(mode); - if (Common.isWindows) { - boolean ownerExecute = (((mode / (8 * 8)) & 1) == 1); - boolean ownerRead = (((mode / (8 * 8)) & 4) == 4); - boolean ownerWrite = (((mode / (8 * 8)) & 2) == 2); - boolean everyoneExecute = (((mode / 8) & 1) == 1); - boolean everyoneRead = (((mode / 8) & 4) == 4); - boolean everyoneWrite = (((mode / 8) & 2) == 2); - file.setWritable(true, false); - file.setExecutable(ownerExecute, !everyoneExecute); - file.setReadable(ownerRead, !everyoneRead); - file.setWritable(ownerWrite, !everyoneWrite); - } else { - Process process = Runtime.getRuntime().exec(new String[] { "chmod", octal, file.getAbsolutePath() }, null, //$NON-NLS-1$ - null); - process.waitFor(); - } - } - - private static void copyStreamToFile(InputStream in, long size, File outputFile) throws IOException { - try (FileOutputStream fos = new FileOutputStream(outputFile)) { - - // if size is not available, copy until EOF... - if (size == -1) { - byte[] buffer = new byte[4096]; - int length; - while ((length = in.read(buffer)) != -1) { - fos.write(buffer, 0, length); - } - return; - } - - // ...else copy just the needed amount of bytes - byte[] buffer = new byte[4096]; - long leftToWrite = size; - while (leftToWrite > 0) { - int length = in.read(buffer); - if (length <= 0) { - throw new IOException( - Messages.Manager_Failed_to_extract.replace(FILE, outputFile.getAbsolutePath())); - } - fos.write(buffer, 0, length); - leftToWrite -= length; - } - } - } - - /** - * This method removes the json files from disk and removes memory references to - * these files or their content - * - * @param packageUrlsToRemove - */ - public static void removePackageURLs(Set packageUrlsToRemove) { - // remove the files from memory - Set activeUrls = new HashSet<>(Arrays.asList(getJsonURLList())); - - activeUrls.removeAll(packageUrlsToRemove); - - setJsonURLs(activeUrls.toArray((String[]) null)); - - // remove the files from disk - for (String curJson : packageUrlsToRemove) { - File localFile = getLocalFileName(curJson, true); - if (localFile != null) { - if (localFile.exists()) { - localFile.delete(); - } - } - } - - // reload the indices (this will remove all potential remaining - // references - // existing files do not need to be refreshed as they have been - // refreshed at startup - loadJsons(false); - - } - - public static void setReady(boolean b) { - myIsReady = b; - - } - - public static void onlyKeepLatestPlatforms() { - List allPackages = getPackages(); - for (Package curPackage : allPackages) { - curPackage.onlyKeepLatestPlatforms(); - } - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/Library.java b/io.sloeber.core/src/io/sloeber/core/managers/Library.java deleted file mode 100644 index 6b34a3177..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/Library.java +++ /dev/null @@ -1,268 +0,0 @@ -package io.sloeber.core.managers; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.apache.commons.io.FileUtils; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -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; - -/** - * This class represents an entry ina a library json file - * - * @author jan - * - */ -public class Library implements Comparable { - - private String name; - private String version; - private String author; - private String maintainer; - private String sentence; - private String paragraph; - private String website; - private String category; - private List architectures; - private List types; - private String url; - private String archiveFileName; - private int size; - private String checksum; - public static final String LIBRARY_SOURCE_FODER = "src"; //$NON-NLS-1$ - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getVersion() { - return this.version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getAuthor() { - return this.author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getMaintainer() { - return this.maintainer; - } - - public void setMaintainer(String maintainer) { - this.maintainer = maintainer; - } - - public String getSentence() { - return this.sentence; - } - - public void setSentence(String sentence) { - this.sentence = sentence; - } - - public String getParagraph() { - return this.paragraph; - } - - public void setParagraph(String paragraph) { - this.paragraph = paragraph; - } - - public String getWebsite() { - return this.website; - } - - public void setWebsite(String website) { - this.website = website; - } - - public String getCategory() { - return this.category; - } - - public void setCategory(String category) { - this.category = category; - } - - public List getArchitectures() { - return this.architectures; - } - - public void setArchitectures(List architectures) { - this.architectures = architectures; - } - - public List getTypes() { - return this.types; - } - - public void setTypes(List types) { - this.types = types; - } - - public String getUrl() { - return this.url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getArchiveFileName() { - return this.archiveFileName; - } - - public void setArchiveFileName(String archiveFileName) { - this.archiveFileName = archiveFileName; - } - - public int getSize() { - return this.size; - } - - public void setSize(int size) { - this.size = size; - } - - public String getChecksum() { - return this.checksum; - } - - public void setChecksum(String checksum) { - this.checksum = checksum; - } - - public IPath getInstallPath() { - return ConfigurationPreferences.getInstallationPathLibraries().append(this.name.replace(' ', '_')) - .append(this.version); - } - - 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() { - File rootFolder=getInstallPath().toFile().getParentFile(); - if (!rootFolder.exists()) { - return false; - } - if (rootFolder.isFile()) { - // something is wrong here - Common.log(new Status(IStatus.ERROR, Activator.getId(), - rootFolder + " is a file but it should be a directory.")); //$NON-NLS-1$ - return false; - } - return rootFolder.list().length > 0; - } - - public IStatus install(IProgressMonitor monitor) { - monitor.setTaskName("Downloading and installing " + getName() + " library."); //$NON-NLS-1$ //$NON-NLS-2$ - if (isInstalled()) { - return Status.OK_STATUS; - } - IStatus ret = InternalPackageManager.downloadAndInstall(this.url, this.archiveFileName, getInstallPath(), false, monitor); - FileModifiers.addPragmaOnce(getInstallPath()); - return ret; - } - - public Collection getIncludePath() { - IPath installPath = getInstallPath(); - IPath srcPath = installPath.append(LIBRARY_SOURCE_FODER); - if (srcPath.toFile().isDirectory()) { - return Collections.singletonList(srcPath); - } - return Collections.singletonList(installPath); - - } - - private void getSources(IProject project, Collection sources, File dir, boolean recurse) { - for (File file : dir.listFiles()) { - if (file.isDirectory()) { - if (recurse) { - getSources(project, sources, file, recurse); - } - } else { - if (CoreModel.isValidSourceUnitName(project, file.getName())) { - sources.add(new Path(file.toString())); - } - } - } - } - - public Collection getSources(IProject project) { - List sources = new ArrayList<>(); - IPath installPath = getInstallPath(); - File srcPath = installPath.append(LIBRARY_SOURCE_FODER).toFile(); - if (srcPath.isDirectory()) { - getSources(project, sources, srcPath, true); - } else { - getSources(project, sources, installPath.toFile(), false); - File utilityPath = installPath.append("utility").toFile(); //$NON-NLS-1$ - if (utilityPath.isDirectory()) { - getSources(project, sources, utilityPath, false); - } - } - return sources; - } - - @Override - public int compareTo(Library other) { - return this.name.compareTo(other.name); - } - - /** - * 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 - */ - public IStatus remove(IProgressMonitor monitor) { - if (!isInstalled()) { - return Status.OK_STATUS; - } - - try { - FileUtils.deleteDirectory(getInstallPath().toFile().getParentFile()); - } catch (IOException e) { - return new Status(IStatus.ERROR, Activator.getId(), "Failed to remove folder" + getInstallPath().toString(), //$NON-NLS-1$ - e); - } - - return Status.OK_STATUS; - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java b/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java deleted file mode 100644 index a612602dc..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/LibraryIndex.java +++ /dev/null @@ -1,171 +0,0 @@ -package io.sloeber.core.managers; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -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; - -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; - - // category name to library name - private Map> categories = new HashMap<>(); - - // library name to latest version of library - private Map latestLibs = new HashMap<>(); - - public void resolve() { - for (Library library : this.libraries) { - String name = library.getName(); - - String category = library.getCategory(); - if (category == null) { - category = "Uncategorized"; //$NON-NLS-1$ - } - - Set categoryLibs = this.categories.get(category); - if (categoryLibs == null) { - categoryLibs = new HashSet<>(); - this.categories.put(category, categoryLibs); - } - categoryLibs.add(name); - - Library current = this.latestLibs.get(name); - if (current != null) { - if (Version.compare(library.getVersion(), current.getVersion()) > 0) { - this.latestLibs.put(name, library); - } - } else { - this.latestLibs.put(name, library); - } - } - } - - public Library getLatestLibrary(String name) { - return this.latestLibs.get(name); - } - - public Library getLibrary(String libName, String version) { - for (Library library : this.libraries) { - if (library.getName().equals(libName) && (library.getVersion().equals(version))) { - return library; - } - } - return null; - } - - public Library getInstalledLibrary(String libName) { - for (Library library : this.libraries) { - if (library.getName().equals(libName) && library.isInstalled()) { - return library; - } - } - return null; - } - - public Set getCategories() { - return this.categories.keySet(); - } - - public Collection getLatestLibraries(String category) { - Set categoryLibs = this.categories.get(category); - if (categoryLibs == null) { - return new ArrayList<>(0); - } - - List libs = new ArrayList<>(categoryLibs.size()); - for (String name : categoryLibs) { - libs.add(this.latestLibs.get(name)); - } - return libs; - } - - 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 (!curLibrary.getValue().isAVersionInstalled()) { - ret.put(curLibrary.getKey(),new LibraryDescriptor( curLibrary.getValue())); - } - } - return ret; - } - - public Collection getLibraries(String category) { - Set categoryLibs = this.categories.get(category); - if (categoryLibs == null) { - return new ArrayList<>(0); - } - - List libs = new ArrayList<>(categoryLibs.size()); - for (Library curLibrary : this.libraries) { - if (categoryLibs.contains(curLibrary.getName())) { - libs.add(curLibrary); - } - } - return libs; - } - - public void setJsonFile(File packageFile) { - String fileName = packageFile.getName().toLowerCase(); - if (fileName.matches("(?i)library_index.json")) { //$NON-NLS-1$ - this.jsonFileName = Defaults.DEFAULT; - } else { - this.jsonFileName = fileName.replaceAll("(?i)" + Pattern.quote("library_"), "") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - .replaceAll("(?i)" + Pattern.quote("_index.json"), ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - } - - 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(), new LibraryDescriptor(curLibrary.getValue())); - } - } - } - return ret; - } -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/Package.java b/io.sloeber.core/src/io/sloeber/core/managers/Package.java deleted file mode 100644 index 74a5cf1a8..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/Package.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * 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 io.sloeber.core.managers; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import io.sloeber.core.tools.Version; - -public class Package implements Comparable { - - private String name; - private String maintainer; - private String websiteURL; - private String email; - private Help help; - private List platforms; - private List tools; - private PackageIndex myParent=null; - - - public PackageIndex getParent() { - return myParent; - } - - void setParent(PackageIndex parent) { - myParent=parent; - - // it happened that the list contained a null so I remove null platforms - this.platforms.remove(null); - for (ArduinoPlatform platform : this.platforms) { - platform.setParent(this); - } - if (this.tools != null) { - for (Tool tool : this.tools) { - tool.setParent(this); - } - } - } - - public String getName() { - return this.name; - } - - public String getMaintainer() { - return this.maintainer; - } - - public String getWebsiteURL() { - return this.websiteURL; - } - - public String getEmail() { - return this.email; - } - - public Help getHelp() { - return this.help; - } - - public List getPlatforms() { - return this.platforms; - } - - /** - * Only the latest versions of the platforms. - * Arduino IDE does not do this based on the name. - * I hope it is based on the architecture because this code is now - * - * @return latest platforms - */ - public Collection getLatestPlatforms() { - Map platformMap = new HashMap<>(); - for (ArduinoPlatform platform : this.platforms) { - ArduinoPlatform p = platformMap.get(platform.getArchitecture()); - if (p == null || Version.compare(platform.getVersion(), p.getVersion()) > 0) { - platformMap.put(platform.getArchitecture(), platform); - } - } - return Collections.unmodifiableCollection(platformMap.values()); - } - - /** - * This method looks up the installed platforms with the highest version - * number So if you have 2 arduino avr platform versions installed you will - * only get back 1. - * - * @return the installed platforms but only one for each platform (the one - * with the highest version number) - */ - public Collection getLatestInstalledPlatforms() { - Map platformMap = new HashMap<>(); - for (ArduinoPlatform platform : this.platforms) { - if (platform.isInstalled()) { - ArduinoPlatform p = platformMap.get(platform.getID()); - if (p == null || Version.compare(platform.getVersion(), p.getVersion()) > 0) { - platformMap.put(platform.getID(), platform); - } - } - } - return Collections.unmodifiableCollection(platformMap.values()); - } - - /** - * This method looks up the installed platforms So if you have 2 arduino avr - * platform versions installed you will get back 2. - * - * @return all the installed platforms - */ - public List getInstalledPlatforms() { - List platformMap = new LinkedList<>(); - for (ArduinoPlatform platform : this.platforms) { - if (platform.isInstalled()) { - platformMap.add(platform); - } - } - return platformMap; - } - - public ArduinoPlatform getLatestPlatform(String architectureName, boolean mustBeInstalled) { - ArduinoPlatform foundPlatform = null; - for (ArduinoPlatform platform : this.platforms) { - if (!mustBeInstalled || platform.isInstalled()) { - if (architectureName.equals(platform.getArchitecture())) { - if (foundPlatform == null) { - foundPlatform = platform; - } else { - if (Version.compare(platform.getVersion(), foundPlatform.getVersion()) > 0) { - foundPlatform = platform; - } - } - } - } - } - return foundPlatform; - } - - public ArduinoPlatform getPlatform(String platformName, String version) { - - for (ArduinoPlatform platform : this.platforms) { - if (platform.getName().equals(platformName)) { - if (Version.compare(platform.getVersion(), version) == 0) { - return platform; - } - } - } - return null; - } - - public List getTools() { - return this.tools; - } - - public Tool getTool(String toolName, String version) { - for (Tool tool : this.tools) { - if (tool.getName().trim().equals(toolName) && tool.getVersion().equals(version)) { - return tool; - } - } - return null; - } - - public Tool getLatestTool(String toolName) { - Tool latestTool = null; - for (Tool tool : this.tools) { - if (tool.getName().equals(toolName)) { - if (latestTool == null || Version.compare(tool.getVersion(), latestTool.getVersion()) > 0) { - latestTool = tool; - } - } - } - return latestTool; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Package) { - return ((Package) obj).getName().equals(this.name); - } - return super.equals(obj); - } - - @Override - public int hashCode() { - return this.name.hashCode(); - } - - @Override - public int compareTo(Package other) { - return this.name.compareTo(other.name); - } - - public void onlyKeepLatestPlatforms() { - Collection latestPlatforms = getLatestPlatforms(); - for (ArduinoPlatform curplatform : this.platforms) { - if (!latestPlatforms.contains(curplatform)) { - curplatform.remove(null); - } - } - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/PackageIndex.java b/io.sloeber.core/src/io/sloeber/core/managers/PackageIndex.java deleted file mode 100644 index 212232f5c..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/PackageIndex.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * 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 io.sloeber.core.managers; - -import java.io.File; -import java.util.List; - -public class PackageIndex { - - private List packages; - - private String jsonFileName; - - private File jsonFile; - - public String getJsonFileName() { - return this.jsonFileName; - } - - public List getPackages() { - return this.packages; - } - - public Package getPackage(String packageName) { - for (Package pkg : this.packages) { - if (pkg.getName().equals(packageName)) { - return pkg; - } - } - return null; - } - - public void setOwners() { - for (Package pkg : this.packages) { - pkg.setParent(this); - } - } - - public File getJsonFile() { - return this.jsonFile; - } - - public void setJsonFile(File packageFile) { - this.jsonFileName = packageFile.getName(); - this.jsonFile = packageFile; - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/Tool.java b/io.sloeber.core/src/io/sloeber/core/managers/Tool.java deleted file mode 100644 index 80e6dc496..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/Tool.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * 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 io.sloeber.core.managers; - -import java.util.List; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -import io.sloeber.core.Activator; -import io.sloeber.core.Messages; -import io.sloeber.core.common.ConfigurationPreferences; - -public class Tool { - - private static final String TOOLS = "tools"; //$NON-NLS-1$ - private static final String KEY = Messages.KEY_TAG; - private String name; - private String version; - private List systems; - - private transient Package pkg; - - public void setParent(Package pkg) { - this.pkg = pkg; - for (ToolSystem system : this.systems) { - system.setOwner(this); - } - } - - public Package getPackage() { - return this.pkg; - } - - public String getName() { - return this.name; - } - - public String getVersion() { - return this.version; - } - - public List getSystems() { - return this.systems; - } - - public IPath getInstallPath() { - return ConfigurationPreferences.getInstallationPathPackages().append(this.pkg.getName()).append(TOOLS) - .append(this.name).append(this.version); - - } - - public boolean isInstalled() { - return getInstallPath().toFile().exists(); - } - - public IStatus install(IProgressMonitor monitor) { - if (isInstalled()) { - return Status.OK_STATUS; - } - - for (ToolSystem system : this.systems) { - if (system.isApplicable()) { - return system.install(monitor); - } - } - - // No valid system - return new Status(IStatus.ERROR, Activator.getId(), Messages.Tool_no_valid_system.replace(KEY, this.name)); - } - - // public Properties getToolProperties() { - // Properties properties = new Properties(); - // properties.put("runtime.tools." + name + ".path", - // ArduinoBuildConfiguration.pathString(getInstallPath())); // $NON-NLS-1$ - // //$NON-NLS-2$ - // return properties; - // } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/ToolDependency.java b/io.sloeber.core/src/io/sloeber/core/managers/ToolDependency.java deleted file mode 100644 index c554bed47..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/ToolDependency.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * 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 io.sloeber.core.managers; - -import static io.sloeber.core.Messages.*; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -import io.sloeber.core.Activator; - -public class ToolDependency { - - private String packager; - private String name; - private String version; - - private transient ArduinoPlatform platform; - - public void setOwner(ArduinoPlatform platform) { - this.platform = platform; - } - - public String getPackager() { - return this.packager; - } - - public String getName() { - return this.name; - } - - public String getVersion() { - return this.version; - } - - public Tool getTool() { - Package pkg = this.platform.getParent(); - if (!pkg.getName().equals(this.packager)) { - pkg = InternalPackageManager.getPackage(this.packager); - } - if(pkg==null) { - return null; - } - return pkg.getTool(this.name, getVersion()); - } - - public IStatus install(IProgressMonitor monitor) { - Tool tool = getTool(); - if (tool == null) { - return new Status(IStatus.ERROR, Activator.getId(), - ToolDependency_Tool_not_found.replace(NAME_TAG, this.name).replace(VERSION_TAG, this.version)); - } - return tool.install(monitor); - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/managers/ToolSystem.java b/io.sloeber.core/src/io/sloeber/core/managers/ToolSystem.java deleted file mode 100644 index c8cd109c8..000000000 --- a/io.sloeber.core/src/io/sloeber/core/managers/ToolSystem.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * 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 io.sloeber.core.managers; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; - -public class ToolSystem { - - private String host; - private String archiveFileName; - private String url; - private String checksum; - private String size; - - private transient Tool tool; - - public void setOwner(Tool tool) { - this.tool = tool; - } - - public String getHost() { - return this.host; - } - - public String getArchiveFileName() { - return this.archiveFileName; - } - - public String getUrl() { - return this.url; - } - - public String getChecksum() { - return this.checksum; - } - - public String getSize() { - return this.size; - } - - - - /** - * Is the tool compatible with the system sloeber is running on - * - * code as taken from arduino HostDependentDownloadableContribution - * https://github.com/arduino/Arduino/blob/master/arduino-core/src/cc/arduino/contributions/packages/HostDependentDownloadableContribution.java - * - * @return true if ok; false if not - */ - @SuppressWarnings("nls") - public boolean isApplicable() { - - String osName =System.getProperty("os.name"); - String osArch =System.getProperty("os.arch"); - - if (osName.contains("Linux")) { - if (osArch.equals("arm")) { - // Raspberry PI, BBB or other ARM based host - - // PI: "arm-linux-gnueabihf" - // Arch-linux on PI2: "armv7l-unknown-linux-gnueabihf" - // Raspbian on PI2: "arm-linux-gnueabihf" - // Ubuntu Mate on PI2: "arm-linux-gnueabihf" - // Debian 7.9 on BBB: "arm-linux-gnueabihf" - // Raspbian on PI Zero: "arm-linux-gnueabihf" - return host.matches("arm.*-linux-gnueabihf"); - } else if (osArch.contains("aarch64")) { - return host.matches("aarch64.*-linux-gnu*"); - } else if (osArch.contains("amd64")) { - return host.matches("x86_64-.*linux-gnu"); - } else { - return host.matches("i[3456]86-.*linux-gnu"); - } - } - - if (osName.contains("Windows")) { - return host.matches("i[3456]86-.*mingw32") || host.matches("i[3456]86-.*cygwin"); - } - - if (osName.contains("Mac")) { - if (osArch.contains("x86_64")) { - return host.matches("x86_64-apple-darwin.*") || host.matches("i[3456]86-apple-darwin.*"); - } - return host.matches("i[3456]86-apple-darwin.*"); - } - - if (osName.contains("FreeBSD")) { - if (osArch.contains("arm")) { - return host.matches("arm.*-freebsd[0-9]*"); - } - return host.matches(osArch + "-freebsd[0-9]*"); - } - - return false; - } - - public IStatus install(IProgressMonitor monitor) { - return InternalPackageManager.downloadAndInstall(this.url, this.archiveFileName, this.tool.getInstallPath(), - false, monitor); - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/toolchain/SloeberConfigurationVariableSupplier.java b/io.sloeber.core/src/io/sloeber/core/toolchain/SloeberConfigurationVariableSupplier.java index 9e476c780..1711a6006 100644 --- a/io.sloeber.core/src/io/sloeber/core/toolchain/SloeberConfigurationVariableSupplier.java +++ b/io.sloeber.core/src/io/sloeber/core/toolchain/SloeberConfigurationVariableSupplier.java @@ -13,7 +13,7 @@ import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider; import org.eclipse.core.resources.IProject; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.SloeberProject; public class SloeberConfigurationVariableSupplier implements IConfigurationEnvironmentVariableSupplier { @@ -39,7 +39,7 @@ public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration } if (ret == null) { // when the configuration doesn't hold the env var maybe the workbench does - ret = PackageManager.getEnvironmentVariables().get(variableName); + ret = BoardsManager.getEnvironmentVariables().get(variableName); } if (ret == null) { return null; @@ -51,7 +51,7 @@ public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration, IEnvironmentVariableProvider provider) { Map retVars = new HashMap<>(); - Map workbenchVars = PackageManager.getEnvironmentVariables(); + Map workbenchVars = BoardsManager.getEnvironmentVariables(); if (workbenchVars != null) { retVars.putAll(workbenchVars); } diff --git a/io.sloeber.core/src/io/sloeber/core/tools/Helpers.java b/io.sloeber.core/src/io/sloeber/core/tools/Helpers.java index 6f3a8e379..c9a84b04a 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Helpers.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Helpers.java @@ -7,10 +7,8 @@ import java.io.InputStream; import java.net.URI; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -40,10 +38,7 @@ import io.sloeber.core.Messages; import io.sloeber.core.api.BoardDescription; -import io.sloeber.core.managers.ArduinoPlatform; -import io.sloeber.core.managers.Library; -import io.sloeber.core.managers.Tool; -import io.sloeber.core.managers.ToolDependency; +import io.sloeber.core.api.Json.ArduinoLibraryVersion; /** * ArduinoHelpers is a static class containing general purpose functions @@ -229,7 +224,7 @@ public static List addCodeFolder(IProject project, IPath toLinkFolder, St addToIncludePath.add(link.getFullPath()); } else { // add src or root give priority to src - possibleIncludeFolder = Library.LIBRARY_SOURCE_FODER; + possibleIncludeFolder = ArduinoLibraryVersion.LIBRARY_SOURCE_FODER; file = toLinkFolder.append(possibleIncludeFolder).toFile(); if (file.exists()) { addToIncludePath.add(link.getFullPath().append(possibleIncludeFolder)); @@ -440,35 +435,4 @@ public static void linkDirectory(IProject project, IPath source, IPath target) { } - public static Map getEnvVarPlatformFileTools(ArduinoPlatform platform, boolean reportToolNotFound) { - HashMap vars = new HashMap<>(); - if (platform == null) { - return vars; - } - if (platform.getToolsDependencies() == null) { - return vars; - } - Iterable tools = platform.getToolsDependencies(); - String RUNTIME_TOOLS = RUNTIME + DOT + TOOLS + DOT; - String DOT_PATH = DOT + PATH; - for (ToolDependency tool : tools) { - String keyString = RUNTIME_TOOLS + tool.getName() + DOT_PATH; - Tool theTool = tool.getTool(); - if (theTool == null) { - if (reportToolNotFound) { - log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, - "Error adding platformFileTools while processing tool " + tool.getName() + " version " //$NON-NLS-1$ //$NON-NLS-2$ - + tool.getVersion() + " Installpath is null")); //$NON-NLS-1$ - } - } else { - IPath installPath = theTool.getInstallPath(); - vars.put(keyString, installPath.toOSString()); - keyString = RUNTIME_TOOLS + tool.getName() + tool.getVersion() + DOT_PATH; - vars.put(keyString, installPath.toOSString()); - keyString = RUNTIME_TOOLS + tool.getName() + '-' + tool.getVersion() + DOT_PATH; - vars.put(keyString, installPath.toOSString()); - } - } - return vars; - } } 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 3f7025033..70129912f 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Libraries.java @@ -38,13 +38,13 @@ import io.sloeber.core.api.BoardDescription; import io.sloeber.core.api.IInstallLibraryHandler; -import io.sloeber.core.api.LibraryDescriptor; import io.sloeber.core.api.LibraryManager; import io.sloeber.core.api.SloeberProject; +import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.api.Json.ArduinoLibraryVersion; import io.sloeber.core.common.Common; import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.core.common.InstancePreferences; -import io.sloeber.core.managers.Library; public class Libraries { public static final String WORKSPACE_LIB_FOLDER = "libraries/"; //$NON-NLS-1$ @@ -117,7 +117,7 @@ private static Map findAllHarwareLibraries(ICConfigurationDescrip SloeberProject sProject = SloeberProject.getSloeberProject(project, false); BoardDescription boardDescriptor = sProject.getBoardDescription(confDesc.getName(), false); // first add the referenced - IPath libPath = boardDescriptor.getReferencedLibraryPath(); + IPath libPath = boardDescriptor.getReferencedCoreLibraryPath(); if (libPath != null) { ret.putAll(findAllSubFolders(libPath)); } @@ -156,8 +156,8 @@ public static Map findAllArduinoManagerLibraries() { if (versions != null) { switch (versions.length) { case 0:// A empty lib folder is hanging around - Common.log( - new Status(IStatus.WARNING, CORE_PLUGIN_ID, EmptyLibFolder.replace(LIB_TAG, curLib))); + Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, + EmptyLibFolder.replace(LIB_TAG, curLib))); Lib_root.toFile().delete(); break; case 1:// There should only be 1 @@ -167,7 +167,7 @@ public static Map findAllArduinoManagerLibraries() { default:// multiple lib versions are installed take // the // latest - int highestVersion = Version.getHighestVersion(versions); + int highestVersion = getHighestVersion(versions); ret.put(curLib, Lib_root.append(versions[highestVersion])); Common.log(new Status(IStatus.WARNING, CORE_PLUGIN_ID, MultipleVersionsOfLib.replace(LIB_TAG, curLib))); @@ -181,6 +181,28 @@ public static Map findAllArduinoManagerLibraries() { } + /** + * Given a list of version strings returns the index of the highest version + * If the highest version is multiple times in the list the result will + * point to one of those but the result may be different for each call + * + * @param versions + * a string list of version numbers + * + * @return the index to the highest version or 0 in case of an empty + * versions + */ + private static int getHighestVersion(String[] versions) { + int returnIndex = 0; + for (int curVersion = 1; curVersion < versions.length; curVersion++) { + if (new VersionNumber(versions[returnIndex]).compareTo(versions[curVersion]) == -1) { + returnIndex = curVersion; + } + + } + return returnIndex; + } + /** * Removes a set of libraries from a project * @@ -198,7 +220,8 @@ public static boolean removeLibrariesFromProject(IProject project, ICConfigurati final IFolder folderHandle = project.getFolder(WORKSPACE_LIB_FOLDER + CurItem); folderHandle.delete(true, null); } catch (CoreException e) { - Common.log(new Status(IStatus.ERROR, CORE_PLUGIN_ID, failed_to_remove_lib.replace(LIB_TAG, CurItem), e)); + Common.log( + new Status(IStatus.ERROR, CORE_PLUGIN_ID, failed_to_remove_lib.replace(LIB_TAG, CurItem), e)); } } return Helpers.removeInvalidIncludeFolders(confdesc); @@ -399,17 +422,14 @@ public static void checkLibraries(IProject affectedProject) { if (!uninstalledIncludedHeaders.isEmpty()) { // some libraries may need to be installed - Map availableLibs = LibraryManager + 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 + // Ask the user which libs need installing availableLibs = installHandler.selectLibrariesToInstall(availableLibs); - for (Entry curLib : availableLibs.entrySet()) { - curLib.getValue().toLibrary().install(new NullProgressMonitor()); + for (Entry curLib : availableLibs.entrySet()) { + LibraryManager.install(curLib.getValue(), new NullProgressMonitor()); } } } @@ -497,8 +517,8 @@ private static Map buildincludeHeaderReplacementMap() { for (Entry CurItem : libraries.entrySet()) { IPath sourcePath = CurItem.getValue(); String curLibName = CurItem.getKey(); - if (sourcePath.append(Library.LIBRARY_SOURCE_FODER).toFile().exists()) { - sourcePath = sourcePath.append(Library.LIBRARY_SOURCE_FODER); + if (sourcePath.append(ArduinoLibraryVersion.LIBRARY_SOURCE_FODER).toFile().exists()) { + sourcePath = sourcePath.append(ArduinoLibraryVersion.LIBRARY_SOURCE_FODER); } File[] allHeaderFiles = sourcePath.toFile().listFiles(new FilenameFilter() { @Override diff --git a/io.sloeber.core/src/io/sloeber/core/tools/PackageManager.java b/io.sloeber.core/src/io/sloeber/core/tools/PackageManager.java new file mode 100644 index 000000000..2dea2d212 --- /dev/null +++ b/io.sloeber.core/src/io/sloeber/core/tools/PackageManager.java @@ -0,0 +1,470 @@ +package io.sloeber.core.tools; + +import static java.nio.file.StandardCopyOption.*; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.compress.archivers.ArchiveEntry; +import org.apache.commons.compress.archivers.ArchiveInputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; +import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; +import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.SystemUtils; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +import io.sloeber.core.Activator; +import io.sloeber.core.Messages; +import io.sloeber.core.api.Json.ArduinoInstallable; +import io.sloeber.core.common.Common; +import io.sloeber.core.common.ConfigurationPreferences; + +public class PackageManager { + private static final String FILE = Messages.FILE_TAG; + private static final String FOLDER = Messages.FOLDER_TAG; + private final static int MAX_HTTP_REDIRECTIONS = 5; + + /** + * downloads an archive file from the internet and saves it in the download + * folder under the name "pArchiveFileName" then extrats the file to + * pInstallPath if pForceDownload is true the file will be downloaded even if + * the download file already exists if pForceDownload is false the file will + * only be downloaded if the download file does not exists The extraction is + * done with processArchive so only files types supported by this method will be + * properly extracted + * + * @param pURL + * the url of the file to download + * @param pArchiveFileName + * the name of the file in the download folder + * @param pInstallPath + * @param pForceDownload + * @param pMonitor + * @return + */ + public static IStatus downloadAndInstall(String pURL, String pArchiveFileName, IPath pInstallPath, + boolean pForceDownload, IProgressMonitor pMonitor) { + IPath dlDir = ConfigurationPreferences.getInstallationPathDownload(); + IPath archivePath = dlDir.append(pArchiveFileName); + try { + URL dl = new URL(pURL); + dlDir.toFile().mkdir(); + if (!archivePath.toFile().exists() || pForceDownload) { + pMonitor.subTask("Downloading " + pArchiveFileName + " .."); //$NON-NLS-1$ //$NON-NLS-2$ + myCopy(dl, archivePath.toFile(), true); + } + } catch (IOException e) { + return new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Failed_to_download.replace(FILE, pURL), + e); + } + return processArchive(pArchiveFileName, pInstallPath, pForceDownload, archivePath.toString(), pMonitor); + } + + private static IStatus processArchive(String pArchiveFileName, IPath pInstallPath, boolean pForceDownload, + String pArchiveFullFileName, IProgressMonitor pMonitor) { + // Create an ArchiveInputStream with the correct archiving algorithm + String faileToExtractMessage = Messages.Manager_Failed_to_extract.replace(FILE, pArchiveFullFileName); + if (pArchiveFileName.endsWith("tar.bz2")) { //$NON-NLS-1$ + try (ArchiveInputStream inStream = new TarArchiveInputStream( + new BZip2CompressorInputStream(new FileInputStream(pArchiveFullFileName)))) { + return extract(inStream, pInstallPath.toFile(), 1, pForceDownload, pMonitor); + } catch (IOException | InterruptedException e) { + return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e); + } + } else if (pArchiveFileName.endsWith("zip")) { //$NON-NLS-1$ + try (ArchiveInputStream in = new ZipArchiveInputStream(new FileInputStream(pArchiveFullFileName))) { + return extract(in, pInstallPath.toFile(), 1, pForceDownload, pMonitor); + } catch (IOException | InterruptedException e) { + return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e); + } + } else if (pArchiveFileName.endsWith("tar.gz")) { //$NON-NLS-1$ + try (ArchiveInputStream in = new TarArchiveInputStream( + new GzipCompressorInputStream(new FileInputStream(pArchiveFullFileName)))) { + return extract(in, pInstallPath.toFile(), 1, pForceDownload, pMonitor); + } catch (IOException | InterruptedException e) { + return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e); + } + } else if (pArchiveFileName.endsWith("tar")) { //$NON-NLS-1$ + try (ArchiveInputStream in = new TarArchiveInputStream(new FileInputStream(pArchiveFullFileName))) { + return extract(in, pInstallPath.toFile(), 1, pForceDownload, pMonitor); + } catch (IOException | InterruptedException e) { + return new Status(IStatus.ERROR, Activator.getId(), faileToExtractMessage, e); + } + } else { + return new Status(IStatus.ERROR, Activator.getId(), Messages.Manager_Format_not_supported); + } + } + + private static IStatus extract(ArchiveInputStream in, File destFolder, int stripPath, boolean overwrite, + IProgressMonitor pMonitor) throws IOException, InterruptedException { + + // Folders timestamps must be set at the end of archive extraction + // (because creating a file in a folder alters the folder's timestamp) + Map foldersTimestamps = new HashMap<>(); + + String pathPrefix = new String(); + + Map hardLinks = new HashMap<>(); + Map hardLinksMode = new HashMap<>(); + Map symLinks = new HashMap<>(); + Map symLinksModifiedTimes = new HashMap<>(); + + // Cycle through all the archive entries + while (true) { + ArchiveEntry entry = in.getNextEntry(); + if (entry == null) { + break; + } + + // Extract entry info + long size = entry.getSize(); + String name = entry.getName(); + boolean isDirectory = entry.isDirectory(); + boolean isLink = false; + boolean isSymLink = false; + String linkName = null; + Integer mode = null; + Long modifiedTime = Long.valueOf(entry.getLastModifiedDate().getTime()); + + pMonitor.subTask("Processing " + name); //$NON-NLS-1$ + + { + // Skip MacOSX metadata + // http://superuser.com/questions/61185/why-do-i-get-files-like-foo-in-my-tarball-on-os-x + int slash = name.lastIndexOf('/'); + if (slash == -1) { + if (name.startsWith("._")) { //$NON-NLS-1$ + continue; + } + } else { + if (name.substring(slash + 1).startsWith("._")) { //$NON-NLS-1$ + continue; + } + } + } + + // Skip git metadata + // http://www.unix.com/unix-for-dummies-questions-and-answers/124958-file-pax_global_header-means-what.html + if (name.contains("pax_global_header")) { //$NON-NLS-1$ + continue; + } + + if (entry instanceof TarArchiveEntry) { + TarArchiveEntry tarEntry = (TarArchiveEntry) entry; + mode = Integer.valueOf(tarEntry.getMode()); + isLink = tarEntry.isLink(); + isSymLink = tarEntry.isSymbolicLink(); + linkName = tarEntry.getLinkName(); + } + + // On the first archive entry, if requested, detect the common path + // prefix to be stripped from filenames + int localstripPath = stripPath; + if (localstripPath > 0 && pathPrefix.isEmpty()) { + int slash = 0; + while (localstripPath > 0) { + slash = name.indexOf("/", slash); //$NON-NLS-1$ + if (slash == -1) { + throw new IOException(Messages.Manager_archiver_eror_single_root_folder_required); + } + slash++; + localstripPath--; + } + pathPrefix = name.substring(0, slash); + } + + // Strip the common path prefix when requested + if (!name.startsWith(pathPrefix)) { + throw new IOException(Messages.Manager_archive_error_root_folder_name_mismatch.replace(FILE, name) + .replace(FOLDER, pathPrefix)); + + } + name = name.substring(pathPrefix.length()); + if (name.isEmpty()) { + continue; + } + File outputFile = new File(destFolder, name); + + File outputLinkedFile = null; + if (isLink && linkName != null) { + if (!linkName.startsWith(pathPrefix)) { + throw new IOException(Messages.Manager_archive_error_root_folder_name_mismatch.replace(FILE, name) + .replace(FOLDER, pathPrefix)); + } + linkName = linkName.substring(pathPrefix.length()); + outputLinkedFile = new File(destFolder, linkName); + } + if (isSymLink) { + // Symbolic links are referenced with relative paths + outputLinkedFile = new File(linkName); + if (outputLinkedFile.isAbsolute()) { + System.err.println(Messages.Manager_archive_error_symbolic_link_to_absolute_path + .replace(FILE, outputFile.toString()).replace(FOLDER, outputLinkedFile.toString())); + System.err.println(); + } + } + + // Safety check + if (isDirectory) { + if (outputFile.isFile() && !overwrite) { + throw new IOException( + Messages.Manager_Cant_create_folder_exists.replace(FILE, outputFile.getPath())); + } + } else { + // - isLink + // - isSymLink + // - anything else + if (outputFile.exists() && !overwrite) { + throw new IOException(Messages.Manager_Cant_extract_file_exist.replace(FILE, outputFile.getPath())); + } + } + + // Extract the entry + if (isDirectory) { + if (!outputFile.exists() && !outputFile.mkdirs()) { + throw new IOException(Messages.Manager_Cant_create_folder.replace(FILE, outputFile.getPath())); + } + foldersTimestamps.put(outputFile, modifiedTime); + } else if (isLink) { + hardLinks.put(outputFile, outputLinkedFile); + hardLinksMode.put(outputFile, mode); + } else if (isSymLink) { + symLinks.put(outputFile, linkName); + symLinksModifiedTimes.put(outputFile, modifiedTime); + } else { + // Create the containing folder if not exists + if (!outputFile.getParentFile().isDirectory()) { + outputFile.getParentFile().mkdirs(); + } + copyStreamToFile(in, size, outputFile); + outputFile.setLastModified(modifiedTime.longValue()); + } + + // Set file/folder permission + if (mode != null && !isSymLink && outputFile.exists()) { + chmod(outputFile, mode.intValue()); + } + } + + for (Map.Entry entry : hardLinks.entrySet()) { + if (entry.getKey().exists() && overwrite) { + entry.getKey().delete(); + } + link(entry.getValue(), entry.getKey()); + Integer mode = hardLinksMode.get(entry.getKey()); + if (mode != null) { + chmod(entry.getKey(), mode.intValue()); + } + } + + for (Map.Entry entry : symLinks.entrySet()) { + if (entry.getKey().exists() && overwrite) { + entry.getKey().delete(); + } + + symlink(entry.getValue(), entry.getKey()); + entry.getKey().setLastModified(symLinksModifiedTimes.get(entry.getKey()).longValue()); + } + + // Set folders timestamps + for (Map.Entry entry : foldersTimestamps.entrySet()) { + entry.getKey().setLastModified(entry.getValue().longValue()); + } + + return Status.OK_STATUS; + + } + + private static void symlink(String from, File to) throws IOException, InterruptedException { + if (Common.isWindows) { + // needs special rights only one board seems to fail due to this + // Process process = Runtime.getRuntime().exec(new String[] { + // "mklink", from, to.getAbsolutePath() }, //$NON-NLS-1$ + // null, to.getParentFile()); + // process.waitFor(); + } else { + Process process = Runtime.getRuntime().exec(new String[] { "ln", "-s", from, to.getAbsolutePath() }, //$NON-NLS-1$ //$NON-NLS-2$ + null, to.getParentFile()); + process.waitFor(); + } + + } + + /* + * create a link file at the level of the os using mklink /H on windows makes + * that no admin rights are needed + */ + @SuppressWarnings("nls") + private static void link(File actualFile, File linkName) throws IOException, InterruptedException { + String[] command = new String[] { "ln", actualFile.getAbsolutePath(), linkName.getAbsolutePath() }; + if (SystemUtils.IS_OS_WINDOWS) { + command = new String[] { "cmd", "/c", "mklink", "/H", linkName.getAbsolutePath(), + actualFile.getAbsolutePath() }; + } + Process process = Runtime.getRuntime().exec(command, null, null); + process.waitFor(); + } + + private static void chmod(File file, int mode) throws IOException, InterruptedException { + String octal = Integer.toOctalString(mode); + if (Common.isWindows) { + boolean ownerExecute = (((mode / (8 * 8)) & 1) == 1); + boolean ownerRead = (((mode / (8 * 8)) & 4) == 4); + boolean ownerWrite = (((mode / (8 * 8)) & 2) == 2); + boolean everyoneExecute = (((mode / 8) & 1) == 1); + boolean everyoneRead = (((mode / 8) & 4) == 4); + boolean everyoneWrite = (((mode / 8) & 2) == 2); + file.setWritable(true, false); + file.setExecutable(ownerExecute, !everyoneExecute); + file.setReadable(ownerRead, !everyoneRead); + file.setWritable(ownerWrite, !everyoneWrite); + } else { + Process process = Runtime.getRuntime().exec(new String[] { "chmod", octal, file.getAbsolutePath() }, null, //$NON-NLS-1$ + null); + process.waitFor(); + } + } + + private static void copyStreamToFile(InputStream in, long size, File outputFile) throws IOException { + try (FileOutputStream fos = new FileOutputStream(outputFile)) { + + // if size is not available, copy until EOF... + if (size == -1) { + byte[] buffer = new byte[4096]; + int length; + while ((length = in.read(buffer)) != -1) { + fos.write(buffer, 0, length); + } + return; + } + + // ...else copy just the needed amount of bytes + byte[] buffer = new byte[4096]; + long leftToWrite = size; + while (leftToWrite > 0) { + int length = in.read(buffer); + if (length <= 0) { + throw new IOException( + Messages.Manager_Failed_to_extract.replace(FILE, outputFile.getAbsolutePath())); + } + fos.write(buffer, 0, length); + leftToWrite -= length; + } + } + } + + /** + * copy a url locally taking into account redirections + * + * @param url + * @param localFile + * @throws IOException + */ + protected static void myCopy(URL url, File localFile, boolean report_error) throws IOException { + myCopy(url, localFile, report_error, 0); + } + + @SuppressWarnings("nls") + private static void myCopy(URL url, File localFile, boolean report_error, int redirectionCounter) + throws IOException { + if ("file".equals(url.getProtocol())) { + FileUtils.copyFile(new File(url.getFile()), localFile); + return; + } + try { + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setReadTimeout(30000); + conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8"); + conn.addRequestProperty("User-Agent", "Mozilla"); + conn.addRequestProperty("Referer", "google.com"); + + // normally, 3xx is redirect + int status = conn.getResponseCode(); + + if (status == HttpURLConnection.HTTP_OK) { + try (InputStream stream = url.openStream()) { + Files.copy(stream, localFile.toPath(), REPLACE_EXISTING); + } + return; + } + + if (status == HttpURLConnection.HTTP_MOVED_TEMP || status == HttpURLConnection.HTTP_MOVED_PERM + || status == HttpURLConnection.HTTP_SEE_OTHER) { + if (redirectionCounter >= MAX_HTTP_REDIRECTIONS) { + throw new IOException("Too many redirections while downloading file."); + } + myCopy(new URL(conn.getHeaderField("Location")), localFile, report_error, redirectionCounter + 1); + return; + } + if (report_error) { + Common.log(new Status(IStatus.WARNING, Activator.getId(), + "Failed to download url " + url + " error code is: " + status, null)); + } + throw new IOException("Failed to download url " + url + " error code is: " + status); + + } catch (Exception e) { + if (report_error) { + Common.log(new Status(IStatus.WARNING, Activator.getId(), "Failed to download url " + url, e)); + } + throw e; + + } + } + + /** + * copy a url locally taking into account redirections in such a way that if + * there is already a file it does not get lost if the download fails + * + * @param url + * @param localFile + * @throws IOException + */ + public static void mySafeCopy(URL url, File localFile, boolean report_error) throws IOException { + File savedFile = null; + if (localFile.exists()) { + savedFile = File.createTempFile(localFile.getName(), "Sloeber"); //$NON-NLS-1$ + Files.move(localFile.toPath(), savedFile.toPath(), REPLACE_EXISTING); + } + try { + myCopy(url, localFile, report_error); + } catch (Exception e) { + if (null != savedFile) { + Files.move(savedFile.toPath(), localFile.toPath(), REPLACE_EXISTING); + } + throw e; + } + } + + /** + * Given a platform description in a json file download and install all needed + * stuff. All stuff is including all tools and core files and hardware specific + * libraries. That is (on windows) inclusive the make.exe + * + * @param installable + * @param monitor + * @param object + * @return + */ + static public synchronized IStatus downloadAndInstall(ArduinoInstallable installable, boolean forceDownload, + IProgressMonitor monitor) { + + return downloadAndInstall(installable.getUrl(), installable.getArchiveFileName(), installable.getInstallPath(), + forceDownload, monitor); + + } + +} diff --git a/io.sloeber.core/src/io/sloeber/core/tools/Version.java b/io.sloeber.core/src/io/sloeber/core/tools/Version.java deleted file mode 100644 index 1be503d03..000000000 --- a/io.sloeber.core/src/io/sloeber/core/tools/Version.java +++ /dev/null @@ -1,95 +0,0 @@ -package io.sloeber.core.tools; -@SuppressWarnings("unused") -public class Version { - /** - * compares 2 strings as if they are version numbers - * if version1 < version2 returns -1 - * if version1==version2 (also if both are null) returns 0 - * else return 1 This method caters for the null case - * - * @param version1 - * @param version2 - * @return - **/ - public static int compare(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 try number string like 6r2 - try { - int vi1 = Integer.parseInt(v1[i].replaceAll("\\D", " " ).split(" ")[0]); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - int vi2 = Integer.parseInt(v2[i].replaceAll("\\D", " " ).split(" ")[0]); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (vi1 < vi2) { - return -1; - } - - if (vi1 > vi2) { - return 1; - }} - catch(Exception e2) { - // - } - //do string compares - int c = v1[i].compareTo(v2[i]); - if (c < 0) { - return -1; - } - if (c > 0) { - return 1; - } - } - } - - return 0; - } - - /** - * Given a list of version strings returns the index of the highest version - * If the highest version is multiple times in the list the result will - * point to one of those but the result may be different for each call - * - * @param versions - * a string list of version numbers - * - * @return the index to the highest version or 0 in case of an empty - * versions - */ - public static int getHighestVersion(String[] versions) { - int returnIndex = 0; - for (int curVersion = 1; curVersion < versions.length; curVersion++) { - if (compare(versions[returnIndex], versions[curVersion]) == -1) { - returnIndex = curVersion; - } - - } - return returnIndex; - } - -} diff --git a/io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java b/io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java index 20581071f..bb3e89bd2 100644 --- a/io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java +++ b/io.sloeber.core/src/io/sloeber/core/txt/BoardTxtFile.java @@ -7,11 +7,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; - public class BoardTxtFile extends TxtFile { public BoardTxtFile(File boardsFile) { @@ -28,7 +29,6 @@ private static File getActualTxtFile(File boardsFile) { return boardsFile; } - public String getMenuItemIDFromMenuItemName(String boardID, String menuID, String menuItemName) { // boardid."menu".menuid.menuitemid=name @@ -149,7 +149,6 @@ public Map getMenus() { return getSection(MENU); } - /** * this is public String[] getAllSectionNames (String[] toaddNames) with a empty * toaddnames @@ -173,7 +172,7 @@ public String[] getAllSectionNames() { * @author Trump * */ - String[] getAllSectionNames(String[] toaddNames) { + public String[] getAllSectionNames(String[] toaddNames) { HashSet allNames = new HashSet<>(); for (String curName : toaddNames) { @@ -193,6 +192,19 @@ String[] getAllSectionNames(String[] toaddNames) { return sBoards; } + public List getAllBoardIDs() { + List allBoardIDs = new LinkedList<>(); + for (String curKey : myData.getChildren().keySet()) { + if ((curKey != null) && (!curKey.isEmpty())) { + String theName = myData.getValue(curKey + DOT + NAME); + if ((theName != null) && (!theName.isEmpty())) { + allBoardIDs.add(curKey); + } + } + } + return allBoardIDs; + } + /** * Get all the key value pairs that need to be added to the environment * variables for the given boardID diff --git a/io.sloeber.core/src/io/sloeber/core/txt/TxtFile.java b/io.sloeber.core/src/io/sloeber/core/txt/TxtFile.java index 683ea0bb2..833a7741b 100644 --- a/io.sloeber.core/src/io/sloeber/core/txt/TxtFile.java +++ b/io.sloeber.core/src/io/sloeber/core/txt/TxtFile.java @@ -41,7 +41,7 @@ public class TxtFile { public TxtFile(File boardsFileName) { - this.mLoadedTxtFile = boardsFileName; + mLoadedTxtFile = boardsFileName; mergeFile(boardsFileName); } @@ -114,12 +114,10 @@ private static String[] readLines(String filename) throws IOException { } } - public String getNiceNameFromID(String myBoardID) { return myData.getValue(myBoardID + DOT + NAME); } - /* * Returns the architecture based on the platform file name Caters for the * packages (with version number and for the old way if the boards file does not @@ -130,7 +128,7 @@ public String getArchitecture() { IPath platformFile = new Path(this.mLoadedTxtFile.toString().trim()); String architecture = platformFile.removeLastSegments(1).lastSegment(); if (architecture == null) {// for error conditions - architecture = Const.AVR; + architecture = Const.AVR; } if (architecture.contains(Const.DOT)) { // This is a version number so // package @@ -175,4 +173,8 @@ public void reloadTxtFile() { mergeFile(mLoadedTxtFile); } + + public File getLoadedFile() { + return mLoadedTxtFile; + } } diff --git a/io.sloeber.core/src/io/sloeber/core/txt/WorkAround.java b/io.sloeber.core/src/io/sloeber/core/txt/WorkAround.java index d70639c45..d416ba483 100644 --- a/io.sloeber.core/src/io/sloeber/core/txt/WorkAround.java +++ b/io.sloeber.core/src/io/sloeber/core/txt/WorkAround.java @@ -20,11 +20,11 @@ import org.eclipse.core.runtime.Status; import io.sloeber.core.Activator; +import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.api.Json.ArduinoPlatformVersion; import io.sloeber.core.common.Common; import io.sloeber.core.common.Const; -import io.sloeber.core.managers.ArduinoPlatform; import io.sloeber.core.tools.FileModifiers; -import io.sloeber.core.tools.Version; /** * A class to apply workarounds to installed packages. Workaround are done after @@ -52,21 +52,21 @@ public class WorkAround extends Const { * none platform.txt and boards.txt workarounds need to be done during install * time * - * @param platform + * @param arduinoPlatformVersion */ - static public void applyKnownWorkArounds(ArduinoPlatform platform) { + static public void applyKnownWorkArounds(ArduinoPlatformVersion arduinoPlatformVersion) { /* * for STM32 V1.8 and later #include "SrcWrapper.h" to Arduino.h remove the * prebuild actions remove the build_opt * https://github.com/Sloeber/arduino-eclipse-plugin/issues/1143 */ - if (Version.compare("1.8.0", platform.getVersion()) != 1) { - if ("stm32".equals(platform.getArchitecture())) { - if ("STM32".equals(platform.getParent().getName())) { - if (Version.compare("1.8.0", platform.getVersion()) == 0) { - File arduino_h = platform.getInstallPath().append("cores").append("arduino").append("Arduino.h") - .toFile(); + if (new VersionNumber("1.8.0").compareTo(arduinoPlatformVersion.getVersion()) != 1) { + if ("stm32".equals(arduinoPlatformVersion.getArchitecture())) { + if ("STM32".equals(arduinoPlatformVersion.getParent().getName())) { + if (arduinoPlatformVersion.getVersion().compareTo("1.8.0") == 0) { + File arduino_h = arduinoPlatformVersion.getInstallPath().append("cores").append("arduino") + .append("Arduino.h").toFile(); if (arduino_h.exists()) { FileModifiers.replaceInFile(arduino_h, false, "#include \"pins_arduino.h\"", "#include \"pins_arduino.h\"\n#include \"SrcWrapper.h\""); @@ -76,8 +76,8 @@ static public void applyKnownWorkArounds(ArduinoPlatform platform) { } } - MakePlatformSloeberTXT(platform.getPlatformFile()); - MakeBoardsSloeberTxt(platform.getBoardsFile()); + MakePlatformSloeberTXT(arduinoPlatformVersion.getPlatformFile()); + MakeBoardsSloeberTxt(arduinoPlatformVersion.getBoardsFile()); } @@ -294,7 +294,7 @@ private static String platformApplyReleaseWorkArounds(String inPlatformTxt, File String platformVersion = platformTXTPath.segment(totalSegments - 2); String platformArchitecture = platformTXTPath.segment(totalSegments - 3); String platformName = platformTXTPath.segment(totalSegments - 5); - if (Version.compare("1.8.0", platformVersion) != 1) { + if (new VersionNumber("1.8.0").compareTo(platformVersion) != 1) { if ("stm32".equals(platformArchitecture)) { if ("STM32".equals(platformName)) { platformTXT = platformTXT.replace("\"@{build.opt.path}\"", ""); diff --git a/io.sloeber.tests/src/io/sloeber/core/BoardAttributes.java b/io.sloeber.tests/src/io/sloeber/core/BoardAttributes.java index 490c3d0ab..285ce7802 100644 --- a/io.sloeber.tests/src/io/sloeber/core/BoardAttributes.java +++ b/io.sloeber.tests/src/io/sloeber/core/BoardAttributes.java @@ -3,6 +3,7 @@ public class BoardAttributes { public boolean serial = false; public boolean serial1 = false; + public boolean serialUSB = false; public boolean keyboard = false; public boolean flightSim = false; public boolean joyStick = false; @@ -11,8 +12,19 @@ public class BoardAttributes { public boolean wire1 = false; public boolean rawHID = false; public boolean buildInLed = true; + public boolean tone = true; + //the number of ADC ports needed/available + //default is ridiculous high so boards should + // 1)default to test + // 2 fail if insufficient ADC's are available + public int myNumAD = 20; + //directmode is something from the capacitiveSensor library + //but as the arduino examples contain examples using this libraries + //and mbed boards do not support it I added it as a boardAttribute + public boolean directMode = true; + /* - * Only a very rara selection of boards supports input_pulldown as pin mode + * Only a very rare selection of boards supports input_pulldown as pin mode */ public boolean inputPullDown = false; public boolean teensy = false;// Teensy specific hardware or software @@ -31,8 +43,9 @@ public class BoardAttributes { public boolean compatibleWithExampleRequirements(BoardAttributes example) { boolean ret = worksOutOfTheBox; ret = ret && matches(example.serial, serial); - ret = ret && matches(example.rawHID, rawHID); ret = ret && matches(example.serial1, serial1); + ret = ret && matches(example.serialUSB, serialUSB); + ret = ret && matches(example.rawHID, rawHID); ret = ret && matches(example.keyboard, keyboard); ret = ret && matches(example.flightSim, flightSim); ret = ret && matches(example.joyStick, joyStick); @@ -44,6 +57,11 @@ public boolean compatibleWithExampleRequirements(BoardAttributes example) { ret = ret && matches(example.mo_mcu, mo_mcu); ret = ret && matches(example.esp8266_mcu, esp8266_mcu); ret = ret && matches(example.buildInLed, buildInLed); + ret = ret && matches(example.tone, tone); + ret = ret && matches(example.directMode, directMode); + + ret = ret && example.myNumAD <= myNumAD; + if (example.boardName != null) { ret = ret && example.boardName.equals(boardName); } @@ -67,10 +85,13 @@ public BoardAttributes or(BoardAttributes or) { // fields that need a binary and ret.worksOutOfTheBox = worksOutOfTheBox && or.worksOutOfTheBox; ret.buildInLed = buildInLed && or.buildInLed; + ret.tone = tone && or.tone; + ret.directMode = directMode && or.directMode; // fields that can do with or ret.serial = serial || or.serial; - ret.rawHID = rawHID || or.rawHID; ret.serial1 = serial1 || or.serial1; + ret.serialUSB = serialUSB || or.serialUSB; + ret.rawHID = rawHID || or.rawHID; ret.keyboard = keyboard || or.keyboard; ret.flightSim = flightSim || or.flightSim; ret.joyStick = joyStick || or.joyStick; diff --git a/io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java b/io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java index 659380f2d..bd1a31a1f 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java +++ b/io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java @@ -31,7 +31,7 @@ import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.CompileDescription; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.Preferences; import io.sloeber.core.api.Sketch; import io.sloeber.core.api.SloeberProject; @@ -122,10 +122,10 @@ public static void installAdditionalBoards() { String[] packageUrlsToAdd = { ESP32.packageURL, ESP8266.packageURL }; - PackageManager.addPackageURLs( + BoardsManager.addPackageURLs( new HashSet<>(Arrays.asList(packageUrlsToAdd)), true); if (reinstall_boards_and_libraries) { - PackageManager.removeAllInstalledPlatforms(); + BoardsManager.removeAllInstalledPlatforms(); } // make sure the needed boards are available @@ -135,7 +135,7 @@ public static void installAdditionalBoards() { Arduino.installLatestIntellCurieBoards(); Arduino.installLatestSamBoards(); - PackageManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); + BoardsManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); } diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java index 44ea473a1..abfc7427b 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java @@ -9,11 +9,12 @@ * At the time of writing 560 examples are compiled * */ -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -34,72 +35,72 @@ @SuppressWarnings({ "nls" }) @RunWith(Parameterized.class) public class CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest { - private CodeDescription myCodeDescriptor; - private MCUBoard myBoard; - private String myProjectName; - private static int myBuildCounter = 0; - private static int myTotalFails = 0; - private static int maxFails = 50; - private static int mySkipAtStart = 0; - - public CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest(String projectName, CodeDescription codeDescriptor, - MCUBoard board) { - - myCodeDescriptor = codeDescriptor; - myBoard = board; - myProjectName = projectName; - } - - @SuppressWarnings("rawtypes") - @Parameters(name = " {0}") - public static Collection examples() { - Shared.waitForAllJobsToFinish(); - Preferences.setUseBonjour(false); - LinkedList examples = new LinkedList<>(); - MCUBoard[] allBoards = Arduino.getAllBoards(); - - TreeMap exampleFolders = LibraryManager.getAllArduinoIDEExamples(); - for (Map.Entry curexample : exampleFolders.entrySet()) { - String fqn = curexample.getKey().trim(); - IPath examplePath = curexample.getValue(); - Examples example = new Examples(fqn, examplePath); - if (!skipExample(example)) { - ArrayList paths = new ArrayList<>(); - - paths.add(examplePath); - CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); - for (MCUBoard curboard : allBoards) { - if (curboard.isExampleSupported(example)) { - String projectName = Shared.getProjectName(codeDescriptor, example, curboard); - Object[] theData = new Object[] { projectName, codeDescriptor, curboard }; - examples.add(theData); - } - } - } - } - - return examples; - - } - - private static boolean skipExample(Examples example) { - // skip Teensy stuff on Arduino hardware - // Teensy is so mutch more advanced that most arduino avr hardware can not - // handle it - return example.getPath().toString().contains("Teensy"); - } - - @Test - public void testExample() { - - Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); - Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); - - if (!Shared.BuildAndVerify(myProjectName, myBoard.getBoardDescriptor(), myCodeDescriptor, + private CodeDescription myCodeDescriptor; + private MCUBoard myBoard; + private String myProjectName; + private static int myBuildCounter = 0; + private static int myTotalFails = 0; + private static int maxFails = 50; + private static int mySkipAtStart = 0; + + public CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest(String projectName, CodeDescription codeDescriptor, + MCUBoard board) { + + myCodeDescriptor = codeDescriptor; + myBoard = board; + myProjectName = projectName; + } + + @SuppressWarnings("rawtypes") + @Parameters(name = " {0}") + public static Collection examples() { + Shared.waitForAllJobsToFinish(); + Preferences.setUseBonjour(false); + LinkedList examples = new LinkedList<>(); + List allBoards = Arduino.getAllBoards(); + + TreeMap exampleFolders = LibraryManager.getAllArduinoIDEExamples(); + for (Map.Entry curexample : exampleFolders.entrySet()) { + String fqn = curexample.getKey().trim(); + IPath examplePath = curexample.getValue(); + Example example = new Example(fqn, examplePath); + if (!skipExample(example)) { + ArrayList paths = new ArrayList<>(); + + paths.add(examplePath); + CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); + for (MCUBoard curboard : allBoards) { + if (curboard.isExampleSupported(example)) { + String projectName = Shared.getProjectName(codeDescriptor, example, curboard); + Object[] theData = new Object[] { projectName, codeDescriptor, curboard }; + examples.add(theData); + } + } + } + } + + return examples; + + } + + private static boolean skipExample(Example example) { + // skip Teensy stuff on Arduino hardware + // Teensy is so mutch more advanced that most arduino avr hardware can not + // handle it + return example.getPath().toString().contains("Teensy"); + } + + @Test + public void testExample() { + + Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); + Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); + + if (!Shared.BuildAndVerify(myProjectName, myBoard.getBoardDescriptor(), myCodeDescriptor, new CompileDescription())) { - myTotalFails++; - fail(Shared.getLastFailMessage()); - } - } + myTotalFails++; + fail(Shared.getLastFailMessage()); + } + } } diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java index eab4e157d..d98af2b61 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java @@ -12,11 +12,12 @@ * only the private static method skipExample allows to skip examples */ -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -28,10 +29,10 @@ import org.junit.runners.Parameterized.Parameters; import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.CompileDescription; import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.PackageManager; import io.sloeber.core.api.Preferences; import io.sloeber.providers.MCUBoard; import io.sloeber.providers.Teensy; @@ -39,83 +40,83 @@ @SuppressWarnings({ "nls" }) @RunWith(Parameterized.class) public class CreateAndCompileArduinoIDEExamplesOnTeensyTest { - private CodeDescription myCodeDescriptor; - - private String myTestName; - private BoardDescription myBoardDescriptor; - private static int myBuildCounter = 0; - private static int myTotalFails = 0; - private static int maxFails = 50; - private static int mySkipAtStart = 0; - - public CreateAndCompileArduinoIDEExamplesOnTeensyTest(String testName, CodeDescription codeDescriptor, - BoardDescription board) { - - myCodeDescriptor = codeDescriptor; - myTestName = testName; - myBoardDescriptor = board; - } - - @SuppressWarnings("rawtypes") - @Parameters(name = "{0}") - public static Collection examples() { - installAdditionalBoards(); - - Shared.waitForAllJobsToFinish(); - Preferences.setUseBonjour(false); - LinkedList examples = new LinkedList<>(); - MCUBoard[] allBoards = Teensy.getAllBoards(); - - TreeMap exampleFolders = LibraryManager.getAllArduinoIDEExamples(); - for (Map.Entry curexample : exampleFolders.entrySet()) { - String fqn = curexample.getKey().trim(); - IPath examplePath = curexample.getValue(); - Examples example = new Examples(fqn, examplePath); - if (!skipExample(example)) { - ArrayList paths = new ArrayList<>(); - paths.add(examplePath); - CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); - - for (MCUBoard curBoard : allBoards) { - if (curBoard.isExampleSupported(example)) { - String projectName = Shared.getProjectName(codeDescriptor, example, curBoard); - Map boardOptions = curBoard.getBoardOptions(example); - BoardDescription boardDescriptor = curBoard.getBoardDescriptor(); - boardDescriptor.setOptions(boardOptions); - Object[] theData = new Object[] { projectName, codeDescriptor, boardDescriptor }; - examples.add(theData); - } - } - } - } - - return examples; - - } - - @SuppressWarnings("unused") - private static boolean skipExample(Examples example) { - // no need to skip examples in this test - return false; - } - - public static void installAdditionalBoards() { - if (MySystem.getTeensyPlatform().isEmpty()) { - System.err.println("ERROR: Teensy not installed/configured skipping tests!!!"); - } else { - PackageManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); - } - - } - - @Test - public void testArduinoIDEExamplesOnTeensy() { - Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); - Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); + private CodeDescription myCodeDescriptor; + + private String myTestName; + private BoardDescription myBoardDescriptor; + private static int myBuildCounter = 0; + private static int myTotalFails = 0; + private static int maxFails = 50; + private static int mySkipAtStart = 0; + + public CreateAndCompileArduinoIDEExamplesOnTeensyTest(String testName, CodeDescription codeDescriptor, + BoardDescription board) { + + myCodeDescriptor = codeDescriptor; + myTestName = testName; + myBoardDescriptor = board; + } + + @SuppressWarnings("rawtypes") + @Parameters(name = "{0}") + public static Collection examples() { + installAdditionalBoards(); + + Shared.waitForAllJobsToFinish(); + Preferences.setUseBonjour(false); + LinkedList examples = new LinkedList<>(); + List allBoards = Teensy.getAllBoards(); + + TreeMap exampleFolders = LibraryManager.getAllArduinoIDEExamples(); + for (Map.Entry curexample : exampleFolders.entrySet()) { + String fqn = curexample.getKey().trim(); + IPath examplePath = curexample.getValue(); + Example example = new Example(fqn, examplePath); + if (!skipExample(example)) { + ArrayList paths = new ArrayList<>(); + paths.add(examplePath); + CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); + + for (MCUBoard curBoard : allBoards) { + if (curBoard.isExampleSupported(example)) { + String projectName = Shared.getProjectName(codeDescriptor, example, curBoard); + Map boardOptions = curBoard.getBoardOptions(example); + BoardDescription boardDescriptor = curBoard.getBoardDescriptor(); + boardDescriptor.setOptions(boardOptions); + Object[] theData = new Object[] { projectName, codeDescriptor, boardDescriptor }; + examples.add(theData); + } + } + } + } + + return examples; + + } + + @SuppressWarnings("unused") + private static boolean skipExample(Example example) { + // no need to skip examples in this test + return false; + } + + public static void installAdditionalBoards() { + if (MySystem.getTeensyPlatform().isEmpty()) { + System.err.println("ERROR: Teensy not installed/configured skipping tests!!!"); + } else { + BoardsManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); + } + + } + + @Test + public void testArduinoIDEExamplesOnTeensy() { + Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); + Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); if (!Shared.BuildAndVerify(myTestName, myBoardDescriptor, myCodeDescriptor, new CompileDescription())) { - myTotalFails++; - fail(Shared.getLastFailMessage()); - } - } + myTotalFails++; + fail(Shared.getLastFailMessage()); + } + } } diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest.java index da615d7f9..a54e40fb5 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest.java @@ -1,12 +1,13 @@ package io.sloeber.core; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -18,99 +19,101 @@ import org.junit.runners.Parameterized.Parameters; import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.PackageManager; import io.sloeber.core.api.Preferences; import io.sloeber.providers.Jantje; import io.sloeber.providers.MCUBoard; -@SuppressWarnings({"nls"}) +@SuppressWarnings({ "nls" }) @RunWith(Parameterized.class) public class CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest { - private CodeDescription myCodeDescriptor; - private static BoardDescription myBoard; + private CodeDescription myCodeDescriptor; + private static BoardDescription myBoard; private static int myBuildCounter = 0; private static int myTotalFails = 0; private static int maxFails = 200; private static int mySkipAtStart = 0; - @SuppressWarnings("unused") - public CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest( String name,CodeDescription codeDescriptor,BoardDescription board) { - - myCodeDescriptor = codeDescriptor; - myBoard=board; - - } - - @SuppressWarnings("rawtypes") - @Parameters(name = "{0}") - public static Collection examples() { - Preferences.setUseBonjour(false); - String[] packageUrlsToAdd = {Jantje.jsonURL }; - PackageManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true); - Jantje.installLatestLocalDebugBoards(); - Shared.waitForAllJobsToFinish(); - - MCUBoard[] allBoards=Jantje.getAllBoards(); - LinkedList examples = new LinkedList<>(); - - TreeMap exampleFolders = LibraryManager.getAllArduinoIDEExamples(); - for (Map.Entry curexample : exampleFolders.entrySet()) { - String fqn = curexample.getKey().trim(); - IPath examplePath = curexample.getValue(); - Examples example = new Examples(fqn, examplePath); - if (!skipExample(example)) { - ArrayList paths = new ArrayList<>(); - - paths.add(examplePath); - CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); - for (MCUBoard curboard : allBoards) { - if (curboard.isExampleSupported(example)) { - Object[] theData = new Object[] {Shared.getCounterName(codeDescriptor.getExampleName()), codeDescriptor ,curboard.getBoardDescriptor()}; - examples.add(theData); - } - } - } - } - - return examples; - - } - - private static boolean skipExample(Examples example) { - switch (example.getFQN()) { - case "example/10.StarterKit/BasicKit/p13_TouchSensorLamp": - return true; - case "example/09.USB/KeyboardAndMouseControl": - return true; - case "example/09.USB/Mouse/JoystickMouseControl": - return true; - case "example/09.USB/Mouse/ButtonMouseControl": - return true; - case "example/09.USB/Keyboard/KeyboardSerial": - return true; - case "example/09.USB/Keyboard/KeyboardReprogram": - return true; - case "example/09.USB/Keyboard/KeyboardMessage": - return true; - case "example/09.USB/Keyboard/KeyboardLogout": - return true; - default: - break; - } - return false; - } - @Test - public void testExample() { - Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); - Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); - - - if (!Shared.BuildAndVerify( myBoard, myCodeDescriptor)) { + @SuppressWarnings("unused") + public CreateAndCompileArduinoIDEExamplesonJantjesBoardsTest(String name, CodeDescription codeDescriptor, + BoardDescription board) { + + myCodeDescriptor = codeDescriptor; + myBoard = board; + + } + + @SuppressWarnings("rawtypes") + @Parameters(name = "{0}") + public static Collection examples() { + Preferences.setUseBonjour(false); + String[] packageUrlsToAdd = { Jantje.additionalJsonURL }; + BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true); + Jantje.installLatestLocalDebugBoards(); + Shared.waitForAllJobsToFinish(); + + List allBoards = Jantje.getAllBoards(); + LinkedList examples = new LinkedList<>(); + + TreeMap exampleFolders = LibraryManager.getAllArduinoIDEExamples(); + for (Map.Entry curexample : exampleFolders.entrySet()) { + String fqn = curexample.getKey().trim(); + IPath examplePath = curexample.getValue(); + Example example = new Example(fqn, examplePath); + if (!skipExample(example)) { + ArrayList paths = new ArrayList<>(); + + paths.add(examplePath); + CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); + for (MCUBoard curboard : allBoards) { + if (curboard.isExampleSupported(example)) { + Object[] theData = new Object[] { Shared.getCounterName(codeDescriptor.getExampleName()), + codeDescriptor, curboard.getBoardDescriptor() }; + examples.add(theData); + } + } + } + } + + return examples; + + } + + private static boolean skipExample(Example example) { + switch (example.getFQN()) { + case "example/10.StarterKit/BasicKit/p13_TouchSensorLamp": + return true; + case "example/09.USB/KeyboardAndMouseControl": + return true; + case "example/09.USB/Mouse/JoystickMouseControl": + return true; + case "example/09.USB/Mouse/ButtonMouseControl": + return true; + case "example/09.USB/Keyboard/KeyboardSerial": + return true; + case "example/09.USB/Keyboard/KeyboardReprogram": + return true; + case "example/09.USB/Keyboard/KeyboardMessage": + return true; + case "example/09.USB/Keyboard/KeyboardLogout": + return true; + default: + break; + } + return false; + } + + @Test + public void testExample() { + Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); + Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); + + if (!Shared.BuildAndVerify(myBoard, myCodeDescriptor)) { myTotalFails++; - fail(Shared.getLastFailMessage() ); + fail(Shared.getLastFailMessage()); } - } + } } diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java index 53b4e141a..836839a28 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java @@ -1,6 +1,6 @@ package io.sloeber.core; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.io.File; import java.util.ArrayList; @@ -8,7 +8,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Map; import org.apache.commons.lang.SystemUtils; import org.eclipse.core.runtime.IPath; @@ -19,345 +18,340 @@ import org.junit.runners.Parameterized.Parameters; import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.PackageManager; import io.sloeber.core.api.Preferences; @SuppressWarnings("nls") @RunWith(Parameterized.class) public class CreateAndCompileDefaultInoOnAllBoardsTest { - // use the boolean below to avoid downloading and installation - private static final boolean removeAllinstallationInfoAtStartup = false; - private static final boolean skipPlatformInstallation = false; - private static final boolean apply_known_work_Arounds = true; - private static final boolean testPrivateHardware = true; - private static final boolean closeFailedProjects = false; - private static int myBuildCounter = 0; - private static int myTotalFails = 0; - private static int maxFails = 50; - private static int mySkipTestsAtStart = 0; - private BoardDescription mBoard; - private static final String[] packageUrlsToIgnoreonAllOSes = { - // There is a newer version - "https://raw.githubusercontent.com/ElektorLabs/arduino/master/package_elektor-labs.com_ide-1.6.5_index.json", - // Third party url implies this is outdated (it also doesn't work) - "http://downloads.arduino.cc/packages/package_mkr1000_index.json", - // http 403 download error - "https://git.oschina.net/dfrobot/FireBeetle-ESP32/raw/master/package_esp32_index.json", - "http://www.arducam.com/downloads/ESP8266_UNO/package_ArduCAM_index.json", - "http://www.arducam.com/downloads/ESP32_UNO/package_ArduCAM_ESP32S_UNO_index.json", - // moved their stuff but didn't bother to update arduino site - "http://www.dwengo.org/sites/default/files/package_dwengo.org_dwenguino_index.json", - // uses extra windows in the tolpath and even after that fix it still fails the - // build - "https://github.com/sonydevworld/spresense-arduino-compatible/releases/download/generic/package_spresense_index.json", - // web site not responding - "http://zoubworld.com/~zoubworld_Arduino/files/Release/package_Zoubworld_index.json", - // discontinued - "http://rfduino.com/package_rfduino_index.json", - "https://redbearlab.github.io/arduino/package_redbear_index.json", - "https://redbearlab.github.io/arduino/package_redbearlab_index.json", - "http://drazzy.com/package_drazzy.com_index.json", - // confirmed 2020 03 09 version 25 12 17 - "https://raw.githubusercontent.com/avandalen/SAM15x15/master/package_avdweb_nl_index.json", - - // uses busybox on windows so command line issues and on Linux the all in one archive build fails - "https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_index.json", - }; - private static final String[] packageUrlsToIgnoreonWindows = { - // following packages did not work in the arduino ide on windows at last test - // confirmed 220 03 09 was version 1.0 - "https://ardhat.github.io/ardhat-board-support/arduino/package_ardhat_index.json", - - - - }; - private static final String[] packageUrlsToIgnoreOnLinux = { - // following packages did not work in the arduino ide on windows at last test - "https://ardhat.github.io/ardhat-board-support/arduino/package_ardhat_index.json", - // A ( is used in a define in the compile command and that seems to be a issue - "https://raw.githubusercontent.com/NicoHood/HoodLoader2/master/package_NicoHood_HoodLoader2_index.json", - // Arduinoide says npt supported on this os - // Sloeber misses a tool - "http://download.labs.mediatek.com/package_mtk_linkit_index.json", - // command contains ( and compiler complains; works in arduino IDE - "https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json" - - }; - private static final String[] packageUrlsToIgnoreOnMac = { - - }; - private static final String[] boardsToIgnoreOnAllOses = { - // Variant folder non existing but using core that references variant.h - // confirmed 2020 03 09 version 4.0.0 - "SmartEverything Bee (Native USB Port)", - - // issue #1152 (confirmed 2020 03 07 ) - "Engimusing EFM32WG840", "Engimusing EFM32WG842", "Engimusing EFM32WG842F64", - - "D-duino-32", // confirmed 2020 03 09 - "SparkFun Blynk Board", // (confirmed 2020 03 07 ) - "ATtiny167 @ 8 MHz (internal oscillator; BOD enabled)", // (confirmed 2020 03 07 ) - "Optiboot ATtiny167 @ 20 MHz (external oscillator; BOD enabled)", // (confirmed 2020 03 07 ) - "Rock Solid XMega 128A", // (confirmed 2020 03 07 ) - - "ATXmega128A1U", // (confirmed 2020 03 07 ) - "ATXMega128A1", // (confirmed 2020 03 07 ) - // this board does not use gcc so there is no added value in using Sloeber - "Windows 10 IoT Core", - - "256RFR2ZBITXPRO", // confirmed 2020 03 09 - "256RFR2ZBIT", // confirmed 2020 03 09 - - "Maple (RET6)", // confirmed failing in arduino IDE 2020 05 30 - "Generic STM32F103Z series",// confirmed failing in arduino IDE 2020 05 30 - - }; - private static final String[] boardsToIgnoreOnWindows = { - - // does not work in, arduino ide on windows - - }; - - private static final String[] boardsToIgnoreOnLinux = { - // The installation script fail in Arduino IDE and so does - // the verify action. - // Sloeber does not support the install stuff and the verify fails as well - "Intel® Galileo", "Intel® Galileo Gen2", "Intel® Edison", - // uses cmd /c in recipes - "STM32 Discovery F407", "Blackpill STM32F401CCU6", "STM32 Discovery F411E", "Generic STM32F407V series", - "Generic STM32F407V mini series", "Seeed Arch Max 1.1", - - // folder casing problem - "LilyPad LilyMini", - - //linkerscript file name casing problem; github code is old - "DFRduino M0 MainBoard", - - }; - private static final String[] packageUrlsFromThirthPartyWebPage = { - /* - * the list below is made as follows extract all url's containing .json from - * https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards- - * support-urls replace http with "http replace .json with .json", - * - * remove the error line - * "https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.6.x-package_index.json" - * ,-format-specification - */ - "http://clkdiv8.com/download/package_clkdiv8_index.json", - "http://dan.drown.org/stm32duino/package_STM32duino_index.json", - "http://digistump.com/package_digistump_index.json", - "http://dl.sipeed.com/MAIX/Maixduino/package_Maixduino_k210_dl_cdn_index.json", - "http://dl.sipeed.com/MAIX/Maixduino/package_Maixduino_k210_index.json", - "http://download.labs.mediatek.com/package_mtk_linkit_7697_index.json", - "http://download.labs.mediatek.com/package_mtk_linkit_index.json", - "http://download.labs.mediatek.com/package_mtk_linkit_smart_7688_index.json", - "http://downloads.arduino.cc/packages/package_mkr1000_index.json", - "http://downloads.konekt.io/arduino/package_konekt_index.json", - "http://downloads.sodaq.net/package_sodaq_index.json", - "http://downloads.sodaq.net/package_sodaq_samd_index.json", - "http://drazzy.com/package_drazzy.com_index.json", - "http://fpgalibre.sf.net/Lattuino/package_lattuino_index.json", - "http://hidnseek.github.io/hidnseek/package_hidnseek_boot_index.json", - "http://library.radino.cc/Arduino_1_8/package_radino_radino32_index.json", - "http://navspark.mybigcommerce.com/content/package_navspark_index.json", - "http://panstamp.org/arduino/package_panstamp_index.json", "http://rfduino.com/package_rfduino_index.json", - "http://rig.reka.com.my/package_rig_index.json", - "http://talk2arduino.wisen.com.au/master/package_talk2.wisen.com_index.json", - "http://www.arducam.com/downloads/ESP32_UNO/package_ArduCAM_ESP32S_UNO_index.json", - "http://www.arducam.com/downloads/ESP8266_UNO/package_ArduCAM_index.json", - "http://www.dwengo.org/sites/default/files/package_dwengo.org_dwenguino_index.json", - "http://www.leonardomiliani.com/repository/package_leonardomiliani.com_index.json", - "http://zoubworld.com/~zoubworld_Arduino/files/Release/package_Zoubworld_index.json", - "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json", - "https://ambasat.com/boards/package_ambasat-1.com_index.json", - "https://ardhat.github.io/ardhat-board-support/arduino/package_ardhat_index.json", - "https://arduboy.github.io/board-support/package_arduboy_index.json", - "https://arduino.esp8266.com/stable/package_esp8266com_index.json", - "https://dl.espressif.com/dl/package_esp32_index.json", - "https://engimusing.github.io/arduinoIDE/package_engimusing_modules_index.json", - "https://git.oschina.net/dfrobot/FireBeetle-ESP32/raw/master/package_esp32_index.json", - "https://github.com/Ameba8195/Arduino/raw/master/release/package_realtek.com_ameba_index.json", - "https://github.com/Infineon/Assets/releases/download/current/package_infineon_index.json", - "https://github.com/IntoRobot/IntoRobotPackages-ArduinoIDE/releases/download/1.0.0/package_intorobot_index.json", - "https://github.com/XMegaForArduino/IDE/raw/master/package_XMegaForArduino_index.json", - "https://github.com/chipKIT32/chipKIT-core/raw/master/package_chipkit_index.json", - "https://github.com/ms-iot/iot-utilities/raw/master/IotCoreAppDeployment/ArduinoIde/package_iotcore_ide-1.6.6_index.json", - "https://github.com/sonydevworld/spresense-arduino-compatible/releases/download/generic/package_spresense_index.json", - "https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_index.json", - "https://lowpowerlab.github.io/MoteinoCore/package_LowPowerLab_index.json", - "https://macchina.cc/package_macchina_index.json", - "https://mcudude.github.io/MegaCore/package_MCUdude_MegaCore_index.json", - "https://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json", - "https://mcudude.github.io/MightyCore/package_MCUdude_MightyCore_index.json", - "https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json", - "https://mesom.de/atflash/package_atflash_index.json", - "https://nekuneko.github.io/arduino-board-index/package_nekuneko_index.json", - "https://openpanzerproject.github.io/OpenPanzerBoards/package_openpanzer_index.json", - "https://per1234.github.io/Ariadne-Bootloader/package_codebendercc_ariadne-bootloader_index.json", - "https://per1234.github.io/wirino/package_per1234_wirino_index.json", - "https://raw.githubusercontent.com/AloriumTechnology/Arduino_Boards/master/package_aloriumtech_index.json", - "https://raw.githubusercontent.com/CytronTechnologies/Cytron-Arduino-URL/master/package_cytron_index.json", - "https://raw.githubusercontent.com/DFRobot/DFRobotDuinoBoard/master/package_dfrobot_index.json", - "https://raw.githubusercontent.com/DFRobot/DFRobotDuinoBoard/master/package_dfrobot_iot_mainboard.json", - "https://raw.githubusercontent.com/ElektorLabs/arduino/master/package_elektor-labs.com_ide-1.6.5_index.json", - "https://raw.githubusercontent.com/ElektorLabs/arduino/master/package_elektor-labs.com_ide-1.6.6_index.json", - "https://raw.githubusercontent.com/FemtoCow/ATTinyCore/master/Downloads/package_femtocow_attiny_index.json", - "https://raw.githubusercontent.com/Lauszus/Sanguino/master/package_lauszus_sanguino_index.json", - "https://raw.githubusercontent.com/MauricioJancic/Elemon/master/package_Elemon_index.json", - "https://raw.githubusercontent.com/MaximIntegratedMicros/arduino-collateral/master/package_maxim_index.json", - "https://raw.githubusercontent.com/NicoHood/HoodLoader2/master/package_NicoHood_HoodLoader2_index.json", - "https://raw.githubusercontent.com/OLIMEX/Arduino_configurations/master/AVR/package_olimex_avr_index.json", - "https://raw.githubusercontent.com/OLIMEX/Arduino_configurations/master/PIC/package_olimex_pic_index.json", - "https://raw.githubusercontent.com/OLIMEX/Arduino_configurations/master/STM/package_olimex_stm_index.json", - "https://raw.githubusercontent.com/Quirkbot/QuirkbotArduinoHardware/master/package_quirkbot.com_index.json", - "https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json", - "https://raw.githubusercontent.com/RiddleAndCode/RnCAtmega256RFR2/master/Board_Manager/package_rnc_index.json", - "https://raw.githubusercontent.com/RobotCing/Cing/master/Software/Packages/package_RobotCing_index.json", - "https://raw.githubusercontent.com/Seeed-Studio/Seeeduino-Boards/master/package_seeeduino_index.json", - "https://raw.githubusercontent.com/TKJElectronics/Balanduino/master/package_tkj_balanduino_index.json", - "https://raw.githubusercontent.com/ThamesValleyReprapUserGroup/Beta-TVRRUG-Mendel90/master/Added-Documents/OMC/package_omc_index.json", - "https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json", - "https://raw.githubusercontent.com/akafugu/akafugu_core/master/package_akafugu_index.json", - "https://raw.githubusercontent.com/arachnidlabs/arachnidlabs-boards/master/package_arachnidlabs.com_boards_index.json", - "https://raw.githubusercontent.com/avandalen/SAM15x15/master/package_avdweb_nl_index.json", - "https://raw.githubusercontent.com/carlosefr/atmega/master/package_carlosefr_atmega_index.json", - "https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json", - "https://raw.githubusercontent.com/eerimoq/simba-releases/master/arduino/avr/package_simba_avr_index.json", - "https://raw.githubusercontent.com/eerimoq/simba-releases/master/arduino/esp/package_simba_esp_index.json", - "https://raw.githubusercontent.com/eerimoq/simba-releases/master/arduino/sam/package_simba_sam_index.json", - "https://raw.githubusercontent.com/eightdog/laika_arduino/master/IDE_Board_Manager/package_project_laika.com_index.json", - "https://raw.githubusercontent.com/facts-engineering/facts-engineering.github.io/master/package_productivity-P1AM-boardmanagermodule_index.json", - "https://raw.githubusercontent.com/feilipu/feilipu.github.io/master/package_goldilocks_index.json", - "https://raw.githubusercontent.com/geolink/opentracker-arduino-board/master/package_opentracker_index.json", - "https://raw.githubusercontent.com/harbaum/ftduino/master/package_ftduino_index.json", - "https://raw.githubusercontent.com/ioteamit/ioteam-arduino-core/master/package_ioteam_index.json", - "https://raw.githubusercontent.com/ioteamit/smarteverything-core/master/package_arrow_index.json", - "https://raw.githubusercontent.com/mikaelpatel/Cosa/master/package_cosa_index.json", - "https://raw.githubusercontent.com/oshlab/Breadboard-Arduino/master/avr/boardsmanager/package_oshlab_breadboard_index.json", - "https://raw.githubusercontent.com/sanu-krishnan/ebot-arduino-core/master/package_ebots.cc_index.json", - "https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json", - "https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/master/STM32/package_stm_index.json", - "https://raw.githubusercontent.com/udif/ITEADSW_Iteaduino-Lite-HSP/master/package/package_iteaduino_lite_index.json", - "https://rawgit.com/hunianhang/nufront_arduino_json/master/package_tl7788_index.json", - "https://redbearlab.github.io/arduino/package_redbear_index.json", - "https://redbearlab.github.io/arduino/package_redbearlab_index.json", - "https://resources.canique.com/ide/package_canique_index.json", - "https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json", - "https://thomasonw.github.io/ATmegaxxM1-C1/package_thomasonw_ATmegaxxM1-C1_index.json", - "https://udooboard.github.io/arduino-board-package/package_udoo_index.json", - "https://www.mattairtech.com/software/arduino/package_MattairTech_index.json", - "https://zevero.github.io/avr_boot/package_zevero_avr_boot_index.json", - "http://adelino.cc/package_adelino_index.json", - - }; - - public CreateAndCompileDefaultInoOnAllBoardsTest(BoardDescription board) { - this.mBoard = board; - } - - @SuppressWarnings("rawtypes") - @Parameters(name = "{index}: {0} ") - public static Collection boards() { - Shared.setCloseFailedProjects(closeFailedProjects); - // make sure all plugin installation is done - Shared.waitForAllJobsToFinish(); - // build the Arduino way - Preferences.setUseArduinoToolSelection(true); - Preferences.setUseBonjour(false); - installAdditionalBoards(); - - List boards = new ArrayList<>(); - for (File curBoardFile : PackageManager.getAllBoardsFiles()) { - // TOFIX these options should not be set here but in IBoard.getOptions - Map options = null; - System.out.println("Adding boards of " + curBoardFile.toString()); - boards.addAll(BoardDescription.makeBoardDescriptors(curBoardFile, options)); - } - // to avoid warnings set the upload port to some value - for (BoardDescription curBoard : boards) { - curBoard.setUploadPort("none"); - } - - HashSet boardsToIgnoreList = new HashSet<>(Arrays.asList(boardsToIgnoreOnAllOses)); - - if (SystemUtils.IS_OS_LINUX) { - boardsToIgnoreList.addAll(Arrays.asList(boardsToIgnoreOnLinux)); - } - if (SystemUtils.IS_OS_WINDOWS) { - boardsToIgnoreList.addAll(Arrays.asList(boardsToIgnoreOnWindows)); - } - List ignoreBoards = new ArrayList<>(); - for (BoardDescription curBoard : boards) { - if (boardsToIgnoreList.contains(curBoard.getBoardName())) { - ignoreBoards.add(curBoard); - } - } - - boards.removeAll(ignoreBoards); - return boards; - } - - /* - * In new installations (of the Sloeber development environment) the installer - * job will trigger downloads and uncompression jobs These must have finished - * before we can start testing - * - * This method will take a long time "Don't panic before 60 minutes are over". - * You can check the [eclipseInstall]/arduinoPlugin/packages folder for progress - */ - public static void installAdditionalBoards() { - if (removeAllinstallationInfoAtStartup) { - PackageManager.removeAllInstalledPlatforms(); - LibraryManager.removeAllLibs(); - } - - HashSet toAddList = new HashSet<>(Arrays.asList(packageUrlsFromThirthPartyWebPage)); - toAddList.addAll(Arrays.asList(PackageManager.getJsonURLList())); - toAddList.removeAll(Arrays.asList(packageUrlsToIgnoreonAllOSes)); - if (SystemUtils.IS_OS_WINDOWS) { - toAddList.removeAll(Arrays.asList(packageUrlsToIgnoreonWindows)); - } - if (SystemUtils.IS_OS_LINUX) { - toAddList.removeAll(Arrays.asList(packageUrlsToIgnoreOnLinux)); - } - if (SystemUtils.IS_OS_MAC) { - toAddList.removeAll(Arrays.asList(packageUrlsToIgnoreOnMac)); - } - PackageManager.setPackageURLs(toAddList, true); - - if (testPrivateHardware) { - PackageManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); - } - - if (!skipPlatformInstallation) { - PackageManager.installAllLatestPlatforms(); - // PackageManager.installsubsetOfLatestPlatforms(0,5); - // PackageManager.onlyKeepLatestPlatforms(); - } - - if (apply_known_work_Arounds) { - Shared.applyKnownWorkArounds(); - } - Shared.waitForAllJobsToFinish(); - } - - @Test + // use the boolean below to avoid downloading and installation + private static final boolean removeAllinstallationInfoAtStartup = false; + private static final boolean skipPlatformInstallation = false; + private static final boolean apply_known_work_Arounds = true; + private static final boolean testPrivateHardware = true; + private static final boolean closeFailedProjects = false; + private static int myBuildCounter = 0; + private static int myTotalFails = 0; + private static int maxFails = 50; + private static int mySkipTestsAtStart = 0; + private BoardDescription mBoard; + private static final String[] packageUrlsToIgnoreonAllOSes = { + // There is a newer version + "https://raw.githubusercontent.com/ElektorLabs/arduino/master/package_elektor-labs.com_ide-1.6.5_index.json", + // Third party url implies this is outdated (it also doesn't work) + "http://downloads.arduino.cc/packages/package_mkr1000_index.json", + // http 403 download error + "https://git.oschina.net/dfrobot/FireBeetle-ESP32/raw/master/package_esp32_index.json", + "http://www.arducam.com/downloads/ESP8266_UNO/package_ArduCAM_index.json", + "http://www.arducam.com/downloads/ESP32_UNO/package_ArduCAM_ESP32S_UNO_index.json", + // moved their stuff but didn't bother to update arduino site + "http://www.dwengo.org/sites/default/files/package_dwengo.org_dwenguino_index.json", + // uses extra windows in the tolpath and even after that fix it still fails the + // build + "https://github.com/sonydevworld/spresense-arduino-compatible/releases/download/generic/package_spresense_index.json", + // web site not responding + "http://zoubworld.com/~zoubworld_Arduino/files/Release/package_Zoubworld_index.json", + // discontinued + "http://rfduino.com/package_rfduino_index.json", + "https://redbearlab.github.io/arduino/package_redbear_index.json", + "https://redbearlab.github.io/arduino/package_redbearlab_index.json", + "http://drazzy.com/package_drazzy.com_index.json", + // confirmed 2020 03 09 version 25 12 17 + "https://raw.githubusercontent.com/avandalen/SAM15x15/master/package_avdweb_nl_index.json", + + // uses busybox on windows so command line issues and on Linux the all in one archive build fails + "https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_index.json", }; + private static final String[] packageUrlsToIgnoreonWindows = { + // following packages did not work in the arduino ide on windows at last test + // confirmed 220 03 09 was version 1.0 + "https://ardhat.github.io/ardhat-board-support/arduino/package_ardhat_index.json", + + }; + private static final String[] packageUrlsToIgnoreOnLinux = { + // following packages did not work in the arduino ide on windows at last test + "https://ardhat.github.io/ardhat-board-support/arduino/package_ardhat_index.json", + // A ( is used in a define in the compile command and that seems to be a issue + "https://raw.githubusercontent.com/NicoHood/HoodLoader2/master/package_NicoHood_HoodLoader2_index.json", + // Arduinoide says npt supported on this os + // Sloeber misses a tool + "http://download.labs.mediatek.com/package_mtk_linkit_index.json", + // command contains ( and compiler complains; works in arduino IDE + "https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json" + + }; + private static final String[] packageUrlsToIgnoreOnMac = { + + }; + private static final String[] boardsToIgnoreOnAllOses = { + // Variant folder non existing but using core that references variant.h + // confirmed 2020 03 09 version 4.0.0 + "SmartEverything Bee (Native USB Port)", + + // issue #1152 (confirmed 2020 03 07 ) + "Engimusing EFM32WG840", "Engimusing EFM32WG842", "Engimusing EFM32WG842F64", + + "D-duino-32", // confirmed 2020 03 09 + "SparkFun Blynk Board", // (confirmed 2020 03 07 ) + "ATtiny167 @ 8 MHz (internal oscillator; BOD enabled)", // (confirmed 2020 03 07 ) + "Optiboot ATtiny167 @ 20 MHz (external oscillator; BOD enabled)", // (confirmed 2020 03 07 ) + "Rock Solid XMega 128A", // (confirmed 2020 03 07 ) + + "ATXmega128A1U", // (confirmed 2020 03 07 ) + "ATXMega128A1", // (confirmed 2020 03 07 ) + // this board does not use gcc so there is no added value in using Sloeber + "Windows 10 IoT Core", + + "256RFR2ZBITXPRO", // confirmed 2020 03 09 + "256RFR2ZBIT", // confirmed 2020 03 09 + + "Maple (RET6)", // confirmed failing in arduino IDE 2020 05 30 + "Generic STM32F103Z series",// confirmed failing in arduino IDE 2020 05 30 + + }; + private static final String[] boardsToIgnoreOnWindows = { + + // does not work in, arduino ide on windows + + }; + + private static final String[] boardsToIgnoreOnLinux = { + // The installation script fail in Arduino IDE and so does + // the verify action. + // Sloeber does not support the install stuff and the verify fails as well + "Intel® Galileo", "Intel® Galileo Gen2", "Intel® Edison", + // uses cmd /c in recipes + "STM32 Discovery F407", "Blackpill STM32F401CCU6", "STM32 Discovery F411E", "Generic STM32F407V series", + "Generic STM32F407V mini series", "Seeed Arch Max 1.1", + + // folder casing problem + "LilyPad LilyMini", + + //linkerscript file name casing problem; github code is old + "DFRduino M0 MainBoard", + + }; + private static final String[] packageUrlsFromThirthPartyWebPage = { + /* + * the list below is made as follows extract all url's containing .json from + * https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards- + * support-urls replace http with "http replace .json with .json", + * + * remove the error line + * "https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.6.x-package_index.json" + * ,-format-specification + */ + "http://clkdiv8.com/download/package_clkdiv8_index.json", + "http://dan.drown.org/stm32duino/package_STM32duino_index.json", + "http://digistump.com/package_digistump_index.json", + "http://dl.sipeed.com/MAIX/Maixduino/package_Maixduino_k210_dl_cdn_index.json", + "http://dl.sipeed.com/MAIX/Maixduino/package_Maixduino_k210_index.json", + "http://download.labs.mediatek.com/package_mtk_linkit_7697_index.json", + "http://download.labs.mediatek.com/package_mtk_linkit_index.json", + "http://download.labs.mediatek.com/package_mtk_linkit_smart_7688_index.json", + "http://downloads.arduino.cc/packages/package_mkr1000_index.json", + "http://downloads.konekt.io/arduino/package_konekt_index.json", + "http://downloads.sodaq.net/package_sodaq_index.json", + "http://downloads.sodaq.net/package_sodaq_samd_index.json", + "http://drazzy.com/package_drazzy.com_index.json", + "http://fpgalibre.sf.net/Lattuino/package_lattuino_index.json", + "http://hidnseek.github.io/hidnseek/package_hidnseek_boot_index.json", + "http://library.radino.cc/Arduino_1_8/package_radino_radino32_index.json", + "http://navspark.mybigcommerce.com/content/package_navspark_index.json", + "http://panstamp.org/arduino/package_panstamp_index.json", "http://rfduino.com/package_rfduino_index.json", + "http://rig.reka.com.my/package_rig_index.json", + "http://talk2arduino.wisen.com.au/master/package_talk2.wisen.com_index.json", + "http://www.arducam.com/downloads/ESP32_UNO/package_ArduCAM_ESP32S_UNO_index.json", + "http://www.arducam.com/downloads/ESP8266_UNO/package_ArduCAM_index.json", + "http://www.dwengo.org/sites/default/files/package_dwengo.org_dwenguino_index.json", + "http://www.leonardomiliani.com/repository/package_leonardomiliani.com_index.json", + "http://zoubworld.com/~zoubworld_Arduino/files/Release/package_Zoubworld_index.json", + "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json", + "https://ambasat.com/boards/package_ambasat-1.com_index.json", + "https://ardhat.github.io/ardhat-board-support/arduino/package_ardhat_index.json", + "https://arduboy.github.io/board-support/package_arduboy_index.json", + "https://arduino.esp8266.com/stable/package_esp8266com_index.json", + "https://dl.espressif.com/dl/package_esp32_index.json", + "https://engimusing.github.io/arduinoIDE/package_engimusing_modules_index.json", + "https://git.oschina.net/dfrobot/FireBeetle-ESP32/raw/master/package_esp32_index.json", + "https://github.com/Ameba8195/Arduino/raw/master/release/package_realtek.com_ameba_index.json", + "https://github.com/Infineon/Assets/releases/download/current/package_infineon_index.json", + "https://github.com/IntoRobot/IntoRobotPackages-ArduinoIDE/releases/download/1.0.0/package_intorobot_index.json", + "https://github.com/XMegaForArduino/IDE/raw/master/package_XMegaForArduino_index.json", + "https://github.com/chipKIT32/chipKIT-core/raw/master/package_chipkit_index.json", + "https://github.com/ms-iot/iot-utilities/raw/master/IotCoreAppDeployment/ArduinoIde/package_iotcore_ide-1.6.6_index.json", + "https://github.com/sonydevworld/spresense-arduino-compatible/releases/download/generic/package_spresense_index.json", + "https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_index.json", + "https://lowpowerlab.github.io/MoteinoCore/package_LowPowerLab_index.json", + "https://macchina.cc/package_macchina_index.json", + "https://mcudude.github.io/MegaCore/package_MCUdude_MegaCore_index.json", + "https://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json", + "https://mcudude.github.io/MightyCore/package_MCUdude_MightyCore_index.json", + "https://mcudude.github.io/MiniCore/package_MCUdude_MiniCore_index.json", + "https://mesom.de/atflash/package_atflash_index.json", + "https://nekuneko.github.io/arduino-board-index/package_nekuneko_index.json", + "https://openpanzerproject.github.io/OpenPanzerBoards/package_openpanzer_index.json", + "https://per1234.github.io/Ariadne-Bootloader/package_codebendercc_ariadne-bootloader_index.json", + "https://per1234.github.io/wirino/package_per1234_wirino_index.json", + "https://raw.githubusercontent.com/AloriumTechnology/Arduino_Boards/master/package_aloriumtech_index.json", + "https://raw.githubusercontent.com/CytronTechnologies/Cytron-Arduino-URL/master/package_cytron_index.json", + "https://raw.githubusercontent.com/DFRobot/DFRobotDuinoBoard/master/package_dfrobot_index.json", + "https://raw.githubusercontent.com/DFRobot/DFRobotDuinoBoard/master/package_dfrobot_iot_mainboard.json", + "https://raw.githubusercontent.com/ElektorLabs/arduino/master/package_elektor-labs.com_ide-1.6.5_index.json", + "https://raw.githubusercontent.com/ElektorLabs/arduino/master/package_elektor-labs.com_ide-1.6.6_index.json", + "https://raw.githubusercontent.com/FemtoCow/ATTinyCore/master/Downloads/package_femtocow_attiny_index.json", + "https://raw.githubusercontent.com/Lauszus/Sanguino/master/package_lauszus_sanguino_index.json", + "https://raw.githubusercontent.com/MauricioJancic/Elemon/master/package_Elemon_index.json", + "https://raw.githubusercontent.com/MaximIntegratedMicros/arduino-collateral/master/package_maxim_index.json", + "https://raw.githubusercontent.com/NicoHood/HoodLoader2/master/package_NicoHood_HoodLoader2_index.json", + "https://raw.githubusercontent.com/OLIMEX/Arduino_configurations/master/AVR/package_olimex_avr_index.json", + "https://raw.githubusercontent.com/OLIMEX/Arduino_configurations/master/PIC/package_olimex_pic_index.json", + "https://raw.githubusercontent.com/OLIMEX/Arduino_configurations/master/STM/package_olimex_stm_index.json", + "https://raw.githubusercontent.com/Quirkbot/QuirkbotArduinoHardware/master/package_quirkbot.com_index.json", + "https://raw.githubusercontent.com/ROBOTIS-GIT/OpenCR/master/arduino/opencr_release/package_opencr_index.json", + "https://raw.githubusercontent.com/RiddleAndCode/RnCAtmega256RFR2/master/Board_Manager/package_rnc_index.json", + "https://raw.githubusercontent.com/RobotCing/Cing/master/Software/Packages/package_RobotCing_index.json", + "https://raw.githubusercontent.com/Seeed-Studio/Seeeduino-Boards/master/package_seeeduino_index.json", + "https://raw.githubusercontent.com/TKJElectronics/Balanduino/master/package_tkj_balanduino_index.json", + "https://raw.githubusercontent.com/ThamesValleyReprapUserGroup/Beta-TVRRUG-Mendel90/master/Added-Documents/OMC/package_omc_index.json", + "https://raw.githubusercontent.com/VSChina/azureiotdevkit_tools/master/package_azureboard_index.json", + "https://raw.githubusercontent.com/akafugu/akafugu_core/master/package_akafugu_index.json", + "https://raw.githubusercontent.com/arachnidlabs/arachnidlabs-boards/master/package_arachnidlabs.com_boards_index.json", + "https://raw.githubusercontent.com/avandalen/SAM15x15/master/package_avdweb_nl_index.json", + "https://raw.githubusercontent.com/carlosefr/atmega/master/package_carlosefr_atmega_index.json", + "https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json", + "https://raw.githubusercontent.com/eerimoq/simba-releases/master/arduino/avr/package_simba_avr_index.json", + "https://raw.githubusercontent.com/eerimoq/simba-releases/master/arduino/esp/package_simba_esp_index.json", + "https://raw.githubusercontent.com/eerimoq/simba-releases/master/arduino/sam/package_simba_sam_index.json", + "https://raw.githubusercontent.com/eightdog/laika_arduino/master/IDE_Board_Manager/package_project_laika.com_index.json", + "https://raw.githubusercontent.com/facts-engineering/facts-engineering.github.io/master/package_productivity-P1AM-boardmanagermodule_index.json", + "https://raw.githubusercontent.com/feilipu/feilipu.github.io/master/package_goldilocks_index.json", + "https://raw.githubusercontent.com/geolink/opentracker-arduino-board/master/package_opentracker_index.json", + "https://raw.githubusercontent.com/harbaum/ftduino/master/package_ftduino_index.json", + "https://raw.githubusercontent.com/ioteamit/ioteam-arduino-core/master/package_ioteam_index.json", + "https://raw.githubusercontent.com/ioteamit/smarteverything-core/master/package_arrow_index.json", + "https://raw.githubusercontent.com/mikaelpatel/Cosa/master/package_cosa_index.json", + "https://raw.githubusercontent.com/oshlab/Breadboard-Arduino/master/avr/boardsmanager/package_oshlab_breadboard_index.json", + "https://raw.githubusercontent.com/sanu-krishnan/ebot-arduino-core/master/package_ebots.cc_index.json", + "https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json", + "https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/master/STM32/package_stm_index.json", + "https://raw.githubusercontent.com/udif/ITEADSW_Iteaduino-Lite-HSP/master/package/package_iteaduino_lite_index.json", + "https://rawgit.com/hunianhang/nufront_arduino_json/master/package_tl7788_index.json", + "https://redbearlab.github.io/arduino/package_redbear_index.json", + "https://redbearlab.github.io/arduino/package_redbearlab_index.json", + "https://resources.canique.com/ide/package_canique_index.json", + "https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json", + "https://thomasonw.github.io/ATmegaxxM1-C1/package_thomasonw_ATmegaxxM1-C1_index.json", + "https://udooboard.github.io/arduino-board-package/package_udoo_index.json", + "https://www.mattairtech.com/software/arduino/package_MattairTech_index.json", + "https://zevero.github.io/avr_boot/package_zevero_avr_boot_index.json", + "http://adelino.cc/package_adelino_index.json", + + }; + + public CreateAndCompileDefaultInoOnAllBoardsTest(BoardDescription board) { + this.mBoard = board; + } + + @SuppressWarnings("rawtypes") + @Parameters(name = "{index}: {0} ") + public static Collection boards() { + Shared.setCloseFailedProjects(closeFailedProjects); + // make sure all plugin installation is done + Shared.waitForAllJobsToFinish(); + // build the Arduino way + Preferences.setUseArduinoToolSelection(true); + Preferences.setUseBonjour(false); + installAdditionalBoards(); + + List boards = new ArrayList<>(); + for (File curBoardFile : BoardsManager.getAllBoardsFiles()) { + System.out.println("Adding boards of " + curBoardFile.toString()); + boards.addAll(BoardDescription.makeBoardDescriptors(curBoardFile)); + } + // to avoid warnings set the upload port to some value + for (BoardDescription curBoard : boards) { + curBoard.setUploadPort("none"); + } + + HashSet boardsToIgnoreList = new HashSet<>(Arrays.asList(boardsToIgnoreOnAllOses)); + + if (SystemUtils.IS_OS_LINUX) { + boardsToIgnoreList.addAll(Arrays.asList(boardsToIgnoreOnLinux)); + } + if (SystemUtils.IS_OS_WINDOWS) { + boardsToIgnoreList.addAll(Arrays.asList(boardsToIgnoreOnWindows)); + } + List ignoreBoards = new ArrayList<>(); + for (BoardDescription curBoard : boards) { + if (boardsToIgnoreList.contains(curBoard.getBoardName())) { + ignoreBoards.add(curBoard); + } + } + + boards.removeAll(ignoreBoards); + return boards; + } + + /* + * In new installations (of the Sloeber development environment) the installer + * job will trigger downloads and uncompression jobs These must have finished + * before we can start testing + * + * This method will take a long time "Don't panic before 60 minutes are over". + * You can check the [eclipseInstall]/arduinoPlugin/packages folder for progress + */ + public static void installAdditionalBoards() { + if (removeAllinstallationInfoAtStartup) { + BoardsManager.removeAllInstalledPlatforms(); + LibraryManager.unInstallAllLibs(); + } + + HashSet toAddList = new HashSet<>(Arrays.asList(packageUrlsFromThirthPartyWebPage)); + toAddList.addAll(Arrays.asList(BoardsManager.getJsonURLList())); + toAddList.removeAll(Arrays.asList(packageUrlsToIgnoreonAllOSes)); + if (SystemUtils.IS_OS_WINDOWS) { + toAddList.removeAll(Arrays.asList(packageUrlsToIgnoreonWindows)); + } + if (SystemUtils.IS_OS_LINUX) { + toAddList.removeAll(Arrays.asList(packageUrlsToIgnoreOnLinux)); + } + if (SystemUtils.IS_OS_MAC) { + toAddList.removeAll(Arrays.asList(packageUrlsToIgnoreOnMac)); + } + BoardsManager.setPackageURLs(toAddList, true); + + if (testPrivateHardware) { + BoardsManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); + } + + if (!skipPlatformInstallation) { + BoardsManager.installAllLatestPlatforms(); + // PackageManager.installsubsetOfLatestPlatforms(0,5); + // PackageManager.onlyKeepLatestPlatforms(); + } + + if (apply_known_work_Arounds) { + Shared.applyKnownWorkArounds(); + } + Shared.waitForAllJobsToFinish(); + } + + @Test public void testBoard() throws Exception { - myBuildCounter++; - Assume.assumeTrue("Skipping first " + mySkipTestsAtStart + " tests", myBuildCounter >= mySkipTestsAtStart); - Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); - - IPath templateFolder = Shared.getTemplateFolder("CreateAndCompileTest"); - if (!Shared.BuildAndVerify(this.mBoard, CodeDescription.createCustomTemplate(templateFolder), null, - myBuildCounter)) { - myTotalFails++; - fail(Shared.getLastFailMessage()); - } - - } + myBuildCounter++; + Assume.assumeTrue("Skipping first " + mySkipTestsAtStart + " tests", myBuildCounter >= mySkipTestsAtStart); + Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); + + IPath templateFolder = Shared.getTemplateFolder("CreateAndCompileTest"); + if (!Shared.BuildAndVerify(this.mBoard, CodeDescription.createCustomTemplate(templateFolder), null, + myBuildCounter)) { + myTotalFails++; + fail(Shared.getLastFailMessage()); + } + + } } diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileExamplesTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileExamplesTest.java index 61b043e3a..1942f9449 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileExamplesTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileExamplesTest.java @@ -22,7 +22,7 @@ import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.CompileDescription; import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.Preferences; import io.sloeber.providers.Adafruit; import io.sloeber.providers.Arduino; @@ -75,9 +75,9 @@ public static Collection examples() { CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); String fqn=curexample.getKey(); - Examples example=new Examples(fqn,curexample.getValue()); + Example example=new Example(fqn,curexample.getValue()); // with the current amount of examples only do one - MCUBoard board = Examples.pickBestBoard(example, myBoards); + MCUBoard board = Example.pickBestBoard(example, myBoards); if (board != null) { BoardDescription curBoard = board.getBoardDescriptor(); if (curBoard != null) { @@ -106,12 +106,12 @@ public static void WaitForInstallerToFinish() { public static void installAdditionalBoards() { String[] packageUrlsToAdd = { ESP8266.packageURL, Adafruit.packageURL }; - PackageManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true); + BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true); if (reinstall_boards_and_examples) { - PackageManager.installAllLatestPlatforms(); - PackageManager.onlyKeepLatestPlatforms(); + BoardsManager.installAllLatestPlatforms(); + BoardsManager.onlyKeepLatestPlatforms(); // deal with removal of json files or libs from json files - LibraryManager.removeAllLibs(); + LibraryManager.unInstallAllLibs(); LibraryManager.installAllLatestLibraries(); } diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileLibraryExamplesTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileLibraryExamplesTest.java index 5477eea5a..36fec502a 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileLibraryExamplesTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileLibraryExamplesTest.java @@ -20,7 +20,7 @@ import io.sloeber.core.api.BoardDescription; import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.Preferences; import io.sloeber.providers.Adafruit; import io.sloeber.providers.Arduino; @@ -38,11 +38,11 @@ public class CreateAndCompileLibraryExamplesTest { private static int myBuildCounter = 0; private static int myTotalFails = 0; - private Examples myExample; + private Example myExample; private MCUBoard myBoard; @SuppressWarnings("unused") - public CreateAndCompileLibraryExamplesTest(String name, MCUBoard boardID, Examples example) { + public CreateAndCompileLibraryExamplesTest(String name, MCUBoard boardID, Example example) { myBoard = boardID; myExample = example; } @@ -66,10 +66,10 @@ public static Collection examples() { for (Map.Entry curexample : exampleFolders.entrySet()) { String fqn = curexample.getKey().trim(); IPath examplePath = curexample.getValue(); - Examples example = new Examples(fqn, examplePath); + Example example = new Example(fqn, examplePath); // with the current amount of examples only do one - MCUBoard curBoard = Examples.pickBestBoard(example, myBoards); + MCUBoard curBoard = Example.pickBestBoard(example, myBoards); if (curBoard != null) { Object[] theData = new Object[] { example.getLibName() + ":" + fqn + ":" + curBoard.getID(), curBoard, @@ -97,21 +97,21 @@ public static void installMyStuff() { public static void installAdditionalBoards() { String[] packageUrlsToAdd = { ESP8266.packageURL, Adafruit.packageURL, ESP32.packageURL }; - PackageManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), reinstall_boards_and_examples); + BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), reinstall_boards_and_examples); if (reinstall_boards_and_examples) { - PackageManager.installAllLatestPlatforms(); - PackageManager.onlyKeepLatestPlatforms(); + BoardsManager.installAllLatestPlatforms(); + BoardsManager.onlyKeepLatestPlatforms(); // deal with removal of json files or libs from json files - LibraryManager.removeAllLibs(); + LibraryManager.unInstallAllLibs(); LibraryManager.installAllLatestLibraries(); // LibraryManager.onlyKeepLatestPlatforms(); } if (MySystem.getTeensyPlatform().isEmpty()) { System.err.println("ERROR: Teensy not installed/configured skipping tests!!!"); } else { - PackageManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); + BoardsManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); } - PackageManager.installAllLatestPlatforms(); + BoardsManager.installAllLatestPlatforms(); } diff --git a/io.sloeber.tests/src/io/sloeber/core/Example.java b/io.sloeber.tests/src/io/sloeber/core/Example.java new file mode 100644 index 000000000..583b531d8 --- /dev/null +++ b/io.sloeber.tests/src/io/sloeber/core/Example.java @@ -0,0 +1,573 @@ +package io.sloeber.core; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.runtime.IPath; + +import io.sloeber.providers.ESP32; +import io.sloeber.providers.MCUBoard; +import io.sloeber.providers.Teensy; + +@SuppressWarnings("nls") +public class Example { + private String myFQN; + private String myLibName; + private IPath myPath; + private BoardAttributes myRequiredBoardAttributes; + private static int noBoardFoundCount = 0; + + public BoardAttributes getRequiredBoardAttributes() { + return myRequiredBoardAttributes; + } + + public Example(String fqn, IPath path) { + myFQN = fqn; + myPath = path; + getLibNameFromPath(); + myRequiredBoardAttributes = new BoardAttributes(); + myRequiredBoardAttributes.serial = examplesUsingSerial().contains(myFQN); + myRequiredBoardAttributes.serial1 = examplesUsingSerial1().contains(myFQN); + myRequiredBoardAttributes.serialUSB = examplesUsingSerialUSB().contains(myFQN); + myRequiredBoardAttributes.keyboard = examplesUsingKeyboard().contains(myFQN); + myRequiredBoardAttributes.flightSim = examplesUsingFlightSim().contains(myFQN); + myRequiredBoardAttributes.joyStick = examplesUsingJoyStick().contains(myFQN); + myRequiredBoardAttributes.mouse = examplesUsingMouse().contains(myFQN); + myRequiredBoardAttributes.tone = examplesUsingTone().contains(myFQN); + myRequiredBoardAttributes.wire1 = examplesUsingWire1().contains(myFQN); + myRequiredBoardAttributes.midi = examplesUsingMidi().contains(myFQN) || myFQN.contains("USB_MIDI"); + myRequiredBoardAttributes.teensy = myFQN.startsWith("Example/Teensy"); + myRequiredBoardAttributes.worksOutOfTheBox = !failingExamples().contains(myFQN); + myRequiredBoardAttributes.boardName = getRequiredBoardID(myFQN); + myRequiredBoardAttributes.mo_mcu = examplesUsingMCUmo().contains(fqn); + myRequiredBoardAttributes.rawHID = myFQN.contains("USB_RawHID"); + myRequiredBoardAttributes.buildInLed = myFQN.contains("Blink"); + myRequiredBoardAttributes.myNumAD = getNumADCUsedInExample(myFQN); + myRequiredBoardAttributes.directMode = examplesUsingDirectMode().contains(myFQN); + + myRequiredBoardAttributes = myRequiredBoardAttributes.or(Libraries.getRequiredBoardAttributes(getLibName())); + } + + private static int getNumADCUsedInExample(String myFQN2) { + switch (myFQN2) { + case "Example/04.Communication/VirtualColorMixer": + case "Example/10.StarterKit_BasicKit/p04_ColorMixingLamp": + return 3; + case "Example/06.Sensors/ADXL3xx": + return 4; + case "Example/08.Strings/StringComparisonOperators": + return 6; + default: + return 0; + } + } + + private void getLibNameFromPath() { + myLibName = new String(); + String[] splits = myFQN.split("/"); + if (splits.length >= 2) { + if ("Library".equals(splits[0])) { + myLibName = splits[1]; + } + } + } + + public IPath getPath() { + return myPath; + } + + public String getLibName() { + return myLibName; + } + + public String getFQN() { + return myFQN; + } + + public String getInoName() { + return myPath.lastSegment(); + } + + private static LinkedList examplesUsingMidi() { + LinkedList myUsesMidiExampleList = new LinkedList<>(); + // myUsesMidiExampleList.add("Example/Teensy/USB_FlightSim/ThrottleServo"); + return myUsesMidiExampleList; + } + + private static LinkedList examplesUsingFlightSim() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/Teensy/USB_FlightSim/BlinkTransponder"); + ret.add("Example/Teensy/USB_FlightSim/FrameRateDisplay"); + ret.add("Example/Teensy/USB_FlightSim/NavFrequency"); + ret.add("Example/Teensy/USB_FlightSim/ThrottleServo"); + return ret; + } + + private static LinkedList examplesUsingSerial1() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/04.Communication/MultiSerial"); + ret.add("Example/04.Communication/SerialPassthrough"); + ret.add("Example/Teensy/Serial/EchoBoth"); + return ret; + } + + private static LinkedList examplesUsingSerialUSB() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/11.ArduinoISP/ArduinoISP"); + return ret; + } + + private static LinkedList examplesUsingDirectMode() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/10.StarterKit_BasicKit/p13_TouchSensorLamp"); + return ret; + } + + private static LinkedList examplesUsingKeyboard() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/09.USB/Keyboard/KeyboardLogout"); + ret.add("Example/09.USB/Keyboard/KeyboardMessage"); + ret.add("Example/09.USB/Keyboard/KeyboardReprogram"); + ret.add("Example/09.USB/Keyboard/KeyboardSerial"); + ret.add("Example/09.USB/Mouse/ButtonMouseControl"); + ret.add("Example/09.USB/Mouse/JoystickMouseControl"); + ret.add("Example/09.USB/KeyboardAndMouseControl"); + return ret; + } + + private static LinkedList examplesUsingSerial() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/01.Basics/AnalogReadSerial"); + ret.add("Example/01.Basics/DigitalReadSerial"); + ret.add("Example/01.Basics/ReadAnalogVoltage"); + ret.add("Example/02.Digital/DigitalInputPullup"); + ret.add("Example/02.Digital/StateChangeDetection"); + ret.add("Example/02.Digital/tonePitchFollower"); + ret.add("Example/03.Analog/AnalogInOutSerial"); + ret.add("Example/03.Analog/Smoothing"); + ret.add("Example/04.Communication/ASCIITable"); + ret.add("Example/04.Communication/Dimmer"); + ret.add("Example/04.Communication/Graph"); + ret.add("Example/04.Communication/Midi"); + ret.add("Example/04.Communication/PhysicalPixel"); + ret.add("Example/04.Communication/ReadASCIIString"); + ret.add("Example/04.Communication/SerialCallResponse"); + ret.add("Example/04.Communication/SerialCallResponseASCII"); + ret.add("Example/04.Communication/SerialEvent"); + ret.add("Example/04.Communication/VirtualColorMixer"); + ret.add("Example/05.Control/IfStatementConditional"); + ret.add("Example/05.Control/switchCase"); + ret.add("Example/05.Control/switchCase2"); + ret.add("Example/06.Sensors/ADXL3xx"); + ret.add("Example/06.Sensors/Knock"); + ret.add("Example/06.Sensors/Memsic2125"); + ret.add("Example/06.Sensors/Ping"); + ret.add("Example/08.Strings/CharacterAnalysis"); + ret.add("Example/08.Strings/StringAdditionOperator"); + ret.add("Example/08.Strings/StringAppendOperator"); + ret.add("Example/08.Strings/StringCaseChanges"); + ret.add("Example/08.Strings/StringCharacters"); + ret.add("Example/08.Strings/StringComparisonOperators"); + ret.add("Example/08.Strings/StringConstructors"); + ret.add("Example/08.Strings/StringIndexOf"); + ret.add("Example/08.Strings/StringLength"); + ret.add("Example/08.Strings/StringLengthTrim"); + ret.add("Example/08.Strings/StringReplace"); + ret.add("Example/08.Strings/StringStartsWithEndsWith"); + ret.add("Example/08.Strings/StringSubstring"); + ret.add("Example/08.Strings/StringToInt"); + ret.add("Example/10.StarterKit_BasicKit/p03_LoveOMeter"); + ret.add("Example/10.StarterKit_BasicKit/p04_ColorMixingLamp"); + ret.add("Example/10.StarterKit_BasicKit/p05_ServoMoodIndicator"); + ret.add("Example/10.StarterKit_BasicKit/p07_Keyboard"); + ret.add("Example/10.StarterKit_BasicKit/p12_KnockLock"); + ret.add("Example/10.StarterKit_BasicKit/p13_TouchSensorLamp"); + ret.add("Example/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo"); + ret.add("Example/11.ArduinoISP/ArduinoISP"); + ret.add("Example/Teensy/Tutorial3/HelloSerialMonitor"); + ret.add("Example/Teensy/Tutorial3/Pushbutton"); + ret.add("Example/Teensy/Tutorial3/PushbuttonPullup"); + ret.add("Example/Teensy/Tutorial3/PushbuttonRGBcolor"); + ret.add("Example/Teensy/Tutorial4/AnalogInput"); + ret.add("Example/Teensy/Tutorial4/TemperatureNumberOnly"); + ret.add("Example/Teensy/Tutorial4/TemperatureScaled"); + ret.add("Example/Teensy/Tutorial4/TemperatureScaledMulti"); + return ret; + } + + private static LinkedList examplesUsingJoyStick() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/Teensy/USB_Joystick/Basic"); + ret.add("Example/Teensy/USB_Joystick/Buttons"); + ret.add("Example/Teensy/USB_Joystick/Complete"); + return ret; + } + + private static LinkedList examplesUsingMouse() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/Teensy/USB_Joystick/Basic"); + ret.add("Example/Teensy/USB_Joystick/Buttons"); + ret.add("Example/Teensy/USB_Joystick/Complete"); + ret.add("Example/Teensy/USB_RawHID/Basic"); + return ret; + } + + private static LinkedList examplesUsingTone() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/10.StarterKit_BasicKit/p06_LightTheremin"); + ret.add("Example/02.Digital/toneMultiple"); + ret.add("Example/02.Digital/toneMelody"); + ret.add("Example/02.Digital/toneKeyboard"); + ret.add("Example/02.Digital/tonePitchFollower"); + ret.add("Example/10.StarterKit_BasicKit/p07_Keyboard"); + return ret; + } + + private static LinkedList examplesUsingWire1() { + LinkedList ret = new LinkedList<>(); + ret.add("Example/Teensy/USB_Joystick/Basic"); + ret.add("Example/Teensy/USB_Joystick/Buttons"); + ret.add("Example/Teensy/USB_Joystick/Complete"); + ret.add("Example/Teensy/USB_RawHID/Basic"); + ret.add("Library/Adafruit_BME280_Library/advancedsettings"); + ret.add("Library/AS3935MI/AS3935MI_LightningDetector_otherInterfaces"); + return ret; + } + + private static LinkedList examplesUsingMCUmo() { + LinkedList ret = new LinkedList<>(); + ret.add("Library/Adafruit_Circuit_Playground/CircuitPlaygroundFirmata_Express_CodeOrg"); + return ret; + } + + /* + * These examples that are known to fail + */ + private static LinkedList failingExamples() { + LinkedList ret = new LinkedList<>(); + /* + * Because you can not define a enum 2 times Sloeber can not add the enum in + * Sloeber.ino.cpp as a result the function declarations using these enums + * generate a error because the enum is not defined. The examples below fail due + * to this + */ + ret.add("Library/_2020Bot_Library/_2020Bot_Demo"); + // These examples are the processing part and are not a deal of sloeber + ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate"); + // manual action is needed for following examples + ret.add("Library/Accessories/CANCommander"); + ret.add("Library/Accessories_CANCommander"); + ret.add("Library/Accessories/Demo"); + ret.add("Library/Accessories/Full"); + ret.add("Library/Accessories/Group"); + ret.add("Library/Accessories/LightFading"); + ret.add("Library/Accessories/LMD18200"); + ret.add("Library/Accessories/Servos"); + ret.add("Library/Accessories/SignalFrench"); + ret.add("Library/Accessories/Signals4x3"); + ret.add("Library/Accessories/SimpleLed"); + ret.add("Library/Accessories/SimpleLedMulti"); + ret.add("Library/Accessories/Stepper"); + ret.add("Library/Accessory/Shield/OLED/example/Adafruit"); + ret.add("Library/Accessory/Shield/temp/humidity/oled"); + // at the time of testing there were case sensetivity issues + ret.add("Library/AutoAnalogAudio/SDAudio/SdAudioRecording"); + ret.add("Library/AutoAnalogAudio/SDAudio/SdAudioWavPlayer"); + ret.add("Library/AutoAnalogAudio/AudioRadioRelay"); + ret.add("Library/AutoAnalogAudio/WirelessMicrophone"); + ret.add("Library/AutoAnalogAudio/WirelessSpeaker"); + ret.add("Library/AutoAnalogAudio/WirelessTx_RPi"); + // needs to get the defines and includes right + ret.add("Library/Accessories/Locoduino.org/Programme4"); + ret.add("Library/Accessories/Locoduino.org/Programme5"); + // Should be build on a stm32 (nucleo as far as I get) + // but these bards require #927 (and probably more :-( + ret.add("Library/ADCTouchSensor/CapacitiveController"); + ret.add("Library/ADCTouchSensor/CapacitivePiano"); + // failed in SPI :-( + ret.add("Library/Adafruit_TinyFlash/TrinketPlayer"); + // not sure how this could work + ret.add("Library/Adafruit_VS1053_Library/feather_midi"); + // all kinds of incompatibility issues I guess + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8b_Use_Bluetooth_Signal_Strength_to_Control_Things"); + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8c_Change_Andee_Bluetooth_Device_Name"); + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8d_How_to_Read_and_Write_to_SD_Card"); + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8f_Using_Andee_IO_Pins_as_OUTPUT_Pins"); + ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8g_Getting_Inputs_from_Andee_IO_Pins"); + ret.add("Library/Andee/Lesson_09_SmartDevice_Control/Lesson_9a_Get_Device_Bluetooth_MAC_Address_ANDROID_Only"); + ret.add("Library/Andee/Lesson_09_SmartDevice_Control/Lesson_9b_Filter_Devices_by_Bluetooth_MAC_Address_ANDROID_Only"); + // doc says not finished + ret.add("Library/ANT-Arduino/NativeAnt"); + // uses missing library MobileBLE + ret.add("Library/ArduinoBlue/differentialDriveCar"); + // defining struct/enum in ino file + ret.add("Library/ArduinoJson/JsonConfigFile"); + ret.add("Library/Arduboy2/RGBled"); + // error: no matching function for call to 'aREST_UI::addToBuffer(const char + ret.add("Library/aREST_UI/ESP8266"); + ret.add("Library/aREST_UI/WiFi_CC3000"); + ret.add("Library/aREST_UI/WildFire"); + // uses arduinoWIFI + ret.add("Library/Braccio/braccioOfUnoWiFi"); + // uses lib that does not has lib folder= include-.h + ret.add("Library/ArduinoCloud/SimpleCloudButtonYun"); + // usi!ng non exsisting methods + ret.add("Library/CAN-BUS_Shield/gpioRead"); + ret.add("Library/CAN-BUS_Shield/gpioWrite"); + // using defines inino file to generate functions (not supported in Sloeber) + ret.add("Library/Adafruit_VEML6070_Library/unittests"); + // uses a non existing header + ret.add("Library/AESLib/complex"); + // using wrong sdfat librarie + ret.add("Library/Arduino_OPL2_SimpleTone"); + ret.add("Library/Arduino_OPL2_Teensy_PlayDRO"); + ret.add("Library/Arduino_OPL2_Teensy_PlayIMF"); + // I don't recall why following examples didn't work + ret.add("Library/arduino_ess_ess_yun"); + ret.add("Library/arduino_ess_linkit_one_dweet"); + ret.add("Library/AD7193/AD7193_VoltageMeasurePsuedoDifferential_Example"); + ret.add("Library/bunny_cuberotate/cuberotate"); + ret.add("Library/XPT2046_Touchscreen/ILI9341Test"); + ret.add("Library/Adafruit_AHRS/ahrs_mahony"); + ret.add("Library/Adafruit_BLEFirmata/StandardFirmata"); + ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate"); + ret.add("Library/Adafruit_GPS_Library/due_shield_sdlog"); + ret.add("Library/Adafruit_Graphic_VFD_Display_Library/GraphicVFDtest"); + ret.add("Library/Adafruit_GPS_Library/locus_erase"); + ret.add("Library/Adafruit_GPS_Library/shield_sdlog"); + ret.add("Library/Adafruit_HX8357_Library/breakouttouchpaint"); + ret.add("Library/Adafruit_ILI9341/breakouttouchpaint"); + ret.add("Library/Adafruit_ILI9341/onoffbutton_breakout"); + ret.add("Library/Adafruit_GPS_Library/echo"); + ret.add("Library/Adafruit_LED_Backpack_Library/wavface"); + ret.add("Library/Adafruit_SSD1306/ssd1306_128x64_i2c"); + ret.add("Library/Adafruit_SSD1306/ssd1306_128x64_spi"); + ret.add("Library/Adafruit_ST7735_Library/soft_spitftbitmap"); + ret.add("Library/Adafruit_TCS34725/colorview/processing/colorview"); + ret.add("Library/Adafruit_TinyRGBLCDShield/TinyHelloWorld"); + ret.add("Library/Akafugu_TWILiquidCrystal_Library/change_address"); + ret.add("Library/Akafugu_WireRtc_Library/alarm"); + ret.add("Library/ALA/RgbStripButton"); + ret.add("Library/APA102/GameOfLife"); + ret.add("Library/arduino-menusystem/led_matrix"); + ret.add("Library/arduino-menusystem/led_matrix_animated"); + ret.add("Library/Arduino_Low_Power/TianStandby"); + ret.add("Library/aREST/BLE"); + ret.add("Library/aREST/ESP32"); + ret.add("Library/aREST/ESP32_cloud"); + ret.add("Library/ArduinoHttpClient/DweetGet"); + ret.add("Library/ArduinoMenu_library/adafruitGfx/lcdMono/lcdMono"); + ret.add("Library/ArduinoMenu_library/adafruitGfx/tft/tft"); + ret.add("Library/ArdVoice/Sample2-Complex"); + ret.add("Library/Aspen_SIM800/Access_HTTP"); + ret.add("Library/Awesome/advanced/how_fast"); + ret.add("Library/Awesome/advanced/lie_detector"); + ret.add("Library/AzureIoTUtility/simplesample_http"); + ret.add("Library/BLEPeripheral/ir_bridge"); + ret.add("Library/BLEPeripheral/temp_sensor"); + ret.add("Library/Brasilino/Basicos/controleGradual"); + ret.add("Library/ClosedCube_HDC1010/hdc1010demo"); + ret.add("Library/Chrono/Resolutions"); + ret.add("Library/Chrono/StopResume"); + ret.add("Library/ConfigurableFirmata/ConfigurableFirmataWiFi"); + ret.add("Library/ControleForno/configuravel"); + ret.add("Library/CopyThreads/c"); + ret.add("Library/ArduinoCloud/SimpleCloudButtoBrzo_I2C"); + ret.add("Library/CopyThreads/FromReadme"); + ret.add("Library/DallasTemperature/Multibus_simple"); + ret.add("Library/DecodeIR/InfraredDecode"); + ret.add("Library/AutoAnalogAudio/SimpleSine"); + ret.add("Library/DimSwitch/DimSwitchTester-ESP-MQTT"); + ret.add("Library/DS3231/echo_time"); + ret.add("Library/Easy_NeoPixels"); + ret.add("Library/DallasTemperature/AlarmHandler"); + ret.add("Library/AmazonDRS/amazonDashNfc"); + ret.add("Library/Andee/Lesson_02_Buttons/Lesson_2h_Using_Buttons_to_Control_Servos"); + ret.add("Library/Andee/Project_Christmas_Lights_and_Annoying_Music"); + ret.add("Library/Andee/Project_Rubber_Band_Launcher"); + ret.add("Library/Andee/Project_Time_Automated_Data_Logger"); + ret.add("Library/ANT-Arduino_library/NativeAnt"); + ret.add("Library/arduino-fsm/timed_switchoff"); + ret.add("Library/BME280/BME_280_BRZO_I2C_Test"); + ret.add("Library/Adafruit_seesaw_Library/DAP"); + // uses unknown NO_ERROR + ret.add("Library/ClosedCube_TCA9546A/tca9546a_sht31d"); + // uses dht.h from dht_sensor_lib + ret.add("Library/CMMC_MQTT_Connector/basic_dht"); + ret.add("Library/ArduinoLearningKitStarter/boardTest"); + // uses altsoftserial and then Serial2???? + ret.add("Library/CMMC_NB-IoT/example1"); + // some bu!g I guess + ret.add("Library/CopyThreads/ExamplesFromReadme"); + ret.add("Library/CRC_Simula_Arduino_IDE_Library/Simula_BehaviorTree"); + // empty sketch?? + ret.add("Library/DFW/ProvisionController"); + // error: 'mapSensor' was not declared in this scope + ret.add("Library/AD_Sensors/ConstrainAnalogSensor"); + // error: 'sensor' was not declared in this scope + ret.add("Library/AD_Sensors/MapAndConstrainAnalogSensor"); + // ess-yun.ino:17:12: error: no matching function for call to + // 'HttpClient::HttpClient()' + ret.add("Library/arduino-ess/ess-yun"); + // I have no linket board in test setup + ret.add("Library/arduino-ess/linkit-one-dweet"); + //cores\arduino/WString.h:38:74: error: statement-expressions + ret.add("Library/ArduinoTrace/TraceFromGlobalScope"); + // no matching function for call to 'aREST::handle(EthernetClient&)' + ret.add("Library/aREST/Ethernet"); + // AsciiMassage_servos.ino:75:37: error: no matching function for call to + // 'AsciiMassagePacker::streamEmpty(const char [6])' + ret.add("Library/AsciiMassage/AsciiMassage_servos"); + // \BH1750FVI_Simple.ino:33:10: error: 'class Serial_' has no member named + // 'printf' + ret.add("Library/BH1750FVI/BH1750FVI_Simple"); + // * This example not complete at all. + ret.add("Library/Blinker/Blinker_AUTO/AUTO_MQTT"); + // 3: error: 'StaticJsonBuffer' was not declared in this scope + ret.add("Library/Boodskap_Message_library/SimpleMessageUsage"); + return ret; + } + + /** + * Give a list of boards pick the board that is best to test this code Boards in + * the beginning of the array are prefered (first found ok algorithm) + * + * returns null if this code should not be tested return null if myBoards is + * empty returns the best known boarddescriptor to run this example + */ + public static MCUBoard pickBestBoard(Example example, MCUBoard myBoards[]) { + String libName = example.getLibName(); + String fqn = example.getFQN(); + if (myBoards.length == 0) { + return null; + } + + if (example.getRequiredBoardAttributes().worksOutOfTheBox) { + + // if example states which board it wants use that board + if (example.getRequiredBoardAttributes().boardName != null) { + String wantedBoardName = example.getRequiredBoardAttributes().boardName; + for (MCUBoard curBoard : myBoards) { + if (curBoard.getID().equals(wantedBoardName)) { + return curBoard; + } + } + } else { + // examples using DHT_sensor_library libraries are not found as the include is + // DHT.h + if (!libName.equals("DHT_sensor_library") && fqn.contains("DHT")) { + return null; + } + // if the boardname is in the libname or ino name pick this one + for (MCUBoard curBoard : myBoards) { + String curBoardName = curBoard.getName(); + List curBoardExampleNames = getSlangNames(curBoardName); + for (String curBoardExampleName : curBoardExampleNames) { + if (libName.toLowerCase().contains(curBoardName) + || fqn.toLowerCase().contains(curBoardExampleName)) { + if (curBoard.isExampleSupported(example)) { + return curBoard; + } + } + } + } + // If the architecture is in the libname or boardname pick this one + for (MCUBoard curBoard : myBoards) { + String curArchitectureName = curBoard.getBoardDescriptor().getArchitecture().toLowerCase(); + if (libName.toLowerCase().contains(curArchitectureName) + || fqn.toLowerCase().contains(curArchitectureName)) { + if (curBoard.isExampleSupported(example)) { + return curBoard; + } + } + } + // if the example name contains teensy try teensy board + if (example.getFQN().toLowerCase().contains("teensy")) { + for (MCUBoard curBoard : myBoards) { + if (Teensy.class.isInstance(curBoard)) { + return curBoard; + } + } + } + // if the example name contains ESP32 try ESP32 board + if (example.getFQN().toLowerCase().contains("esp32")) { + for (MCUBoard curBoard : myBoards) { + if (ESP32.class.isInstance(curBoard)) { + return curBoard; + } + } + } + // if the example name contains ESP try ESP8266 board + // if (example.getFQN().toLowerCase().contains("esp")) { + // for (MCUBoard curBoard : myBoards) { + // if (ESP8266.class.isInstance(curBoard)) { + // return curBoard; + // } + // } + // } + //causes issues with response + + // Out of guesses based on the name. Take the first ok one + for (MCUBoard curBoard : myBoards) { + if (curBoard.isExampleSupported(example)) { + return curBoard; + } + } + } + } + System.out.println("No board found for " + Integer.toString(++noBoardFoundCount) + " " + example.getFQN()); + return null; + } + + private static List getSlangNames(String curBoardName) { + Map singleNames = new HashMap<>(); + singleNames.put("adafruit_metro_m4", "metroM4"); + singleNames.put("feather52832", "feather"); + singleNames.put("trinket3", "trinket"); + singleNames.put("adafruit_feather_m0", "FeatherM0"); + singleNames.put("arduino_zero_edbg", "zero"); + singleNames.put("arduino_101", "101"); + singleNames.put("arduino_zero_native", "zero Native"); + singleNames.put("d1_mini", "wemos"); + singleNames.put("teensy36", "teensy3"); + singleNames.put("adafruit_metro_m4", "metroM4"); + + List ret = new ArrayList<>(); + String singleName = singleNames.get(curBoardName); + if (singleName != null) { + ret.add(singleName); + } + ret.add(curBoardName); + return ret; + } + + private static String getRequiredBoardID(String fqn) { + switch (fqn) { + case "Library/Accessory_Shield/OLED_example_Adafruit": + case "Library/Accessory_Shield/temp_humidity_oled": + return "uno"; + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_NeoPixel": + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Read": + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Record": + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Send": + case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Testpattern": + case "Library/Adafruit_Zero_FFT_Library/CircuitPlayground": + return "adafruit_circuitplayground_m0"; + case "Library/Adafruit_MiniMLX90614/templight": + return "gemma"; + case "Library/ArduinoThread/SensorThread": + return "due"; + case "Library/AudioFrequencyMeter/SimpleAudioFrequencyMeter": + case "Library/Adafruit_NeoPXL8/strandtest": + return "zero"; + case "Library/BLEPeripheral/iBeacon": + return "feather52"; + default: + return null; + } + + } +} diff --git a/io.sloeber.tests/src/io/sloeber/core/Examples.java b/io.sloeber.tests/src/io/sloeber/core/Examples.java deleted file mode 100644 index d40c79759..000000000 --- a/io.sloeber.tests/src/io/sloeber/core/Examples.java +++ /dev/null @@ -1,501 +0,0 @@ -package io.sloeber.core; - -import java.util.LinkedList; - -import org.eclipse.core.runtime.IPath; - -import io.sloeber.providers.ESP32; -import io.sloeber.providers.MCUBoard; -import io.sloeber.providers.Teensy; - -@SuppressWarnings("nls") -public class Examples { - private String myFQN; - private String myLibName; - private IPath myPath; - private BoardAttributes myRequiredBoardAttributes; - private static int noBoardFoundCount = 0; - - public BoardAttributes getRequiredBoardAttributes() { - return myRequiredBoardAttributes; - } - - public Examples(String fqn, IPath path) { - myFQN = fqn; - myPath = path; - getLibNameFromPath(); - myRequiredBoardAttributes = new BoardAttributes(); - myRequiredBoardAttributes.serial = examplesUsingSerial().contains(myFQN); - myRequiredBoardAttributes.serial1 = examplesUsingSerial1().contains(myFQN); - myRequiredBoardAttributes.keyboard = examplesUsingKeyboard().contains(myFQN); - myRequiredBoardAttributes.flightSim = examplesUsingFlightSim().contains(myFQN); - myRequiredBoardAttributes.joyStick = examplesUsingJoyStick().contains(myFQN); - myRequiredBoardAttributes.mouse = examplesUsingMouse().contains(myFQN); - myRequiredBoardAttributes.wire1 = examplesUsingWire1().contains(myFQN); - myRequiredBoardAttributes.midi = examplesUsingMidi().contains(myFQN) || myFQN.contains("USB_MIDI"); - myRequiredBoardAttributes.teensy = myFQN.startsWith("Example/Teensy"); - myRequiredBoardAttributes.worksOutOfTheBox = !failingExamples().contains(myFQN); - myRequiredBoardAttributes.boardName = getRequiredBoardID(myFQN); - myRequiredBoardAttributes.mo_mcu = examplesUsingMCUmo().contains(fqn); - myRequiredBoardAttributes.rawHID = myFQN.contains("USB_RawHID"); - myRequiredBoardAttributes.buildInLed = myFQN.contains("Blink"); - myRequiredBoardAttributes = myRequiredBoardAttributes.or(Libraries.getRequiredBoardAttributes(getLibName())); - } - - private void getLibNameFromPath() { - myLibName = new String(); - String[] splits = myFQN.split("/"); - if (splits.length >= 2) { - if ("Library".equals(splits[0])) { - myLibName = splits[1]; - } - } - } - - public IPath getPath() { - return myPath; - } - - public String getLibName() { - return myLibName; - } - - public String getFQN() { - return myFQN; - } - - public String getInoName() { - return myPath.lastSegment(); - } - - private static LinkedList examplesUsingMidi() { - LinkedList myUsesMidiExampleList = new LinkedList<>(); - // myUsesMidiExampleList.add("Example/Teensy/USB_FlightSim/ThrottleServo"); - return myUsesMidiExampleList; - } - - private static LinkedList examplesUsingFlightSim() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/Teensy/USB_FlightSim/BlinkTransponder"); - ret.add("Example/Teensy/USB_FlightSim/FrameRateDisplay"); - ret.add("Example/Teensy/USB_FlightSim/NavFrequency"); - ret.add("Example/Teensy/USB_FlightSim/ThrottleServo"); - return ret; - } - - private static LinkedList examplesUsingSerial1() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/04.Communication/MultiSerial"); - ret.add("Example/04.Communication/SerialPassthrough"); - ret.add("Example/Teensy/Serial/EchoBoth"); - return ret; - } - - private static LinkedList examplesUsingKeyboard() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/09.USB/Keyboard/KeyboardLogout"); - ret.add("Example/09.USB/Keyboard/KeyboardMessage"); - ret.add("Example/09.USB/Keyboard/KeyboardReprogram"); - ret.add("Example/09.USB/Keyboard/KeyboardSerial"); - ret.add("Example/09.USB/Mouse/ButtonMouseControl"); - ret.add("Example/09.USB/Mouse/JoystickMouseControl"); - ret.add("Example/09.USB/KeyboardAndMouseControl"); - return ret; - } - - private static LinkedList examplesUsingSerial() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/01.Basics/AnalogReadSerial"); - ret.add("Example/01.Basics/DigitalReadSerial"); - ret.add("Example/01.Basics/ReadAnalogVoltage"); - ret.add("Example/02.Digital/DigitalInputPullup"); - ret.add("Example/02.Digital/StateChangeDetection"); - ret.add("Example/02.Digital/tonePitchFollower"); - ret.add("Example/03.Analog/AnalogInOutSerial"); - ret.add("Example/03.Analog/Smoothing"); - ret.add("Example/04.Communication/ASCIITable"); - ret.add("Example/04.Communication/Dimmer"); - ret.add("Example/04.Communication/Graph"); - ret.add("Example/04.Communication/Midi"); - ret.add("Example/04.Communication/PhysicalPixel"); - ret.add("Example/04.Communication/ReadASCIIString"); - ret.add("Example/04.Communication/SerialCallResponse"); - ret.add("Example/04.Communication/SerialCallResponseASCII"); - ret.add("Example/04.Communication/SerialEvent"); - ret.add("Example/04.Communication/VirtualColorMixer"); - ret.add("Example/05.Control/IfStatementConditional"); - ret.add("Example/05.Control/switchCase"); - ret.add("Example/05.Control/switchCase2"); - ret.add("Example/06.Sensors/ADXL3xx"); - ret.add("Example/06.Sensors/Knock"); - ret.add("Example/06.Sensors/Memsic2125"); - ret.add("Example/06.Sensors/Ping"); - ret.add("Example/08.Strings/CharacterAnalysis"); - ret.add("Example/08.Strings/StringAdditionOperator"); - ret.add("Example/08.Strings/StringAppendOperator"); - ret.add("Example/08.Strings/StringCaseChanges"); - ret.add("Example/08.Strings/StringCharacters"); - ret.add("Example/08.Strings/StringComparisonOperators"); - ret.add("Example/08.Strings/StringConstructors"); - ret.add("Example/08.Strings/StringIndexOf"); - ret.add("Example/08.Strings/StringLength"); - ret.add("Example/08.Strings/StringLengthTrim"); - ret.add("Example/08.Strings/StringReplace"); - ret.add("Example/08.Strings/StringStartsWithEndsWith"); - ret.add("Example/08.Strings/StringSubstring"); - ret.add("Example/08.Strings/StringToInt"); - ret.add("Example/10.StarterKit_BasicKit/p03_LoveOMeter"); - ret.add("Example/10.StarterKit_BasicKit/p04_ColorMixingLamp"); - ret.add("Example/10.StarterKit_BasicKit/p05_ServoMoodIndicator"); - ret.add("Example/10.StarterKit_BasicKit/p07_Keyboard"); - ret.add("Example/10.StarterKit_BasicKit/p12_KnockLock"); - ret.add("Example/10.StarterKit_BasicKit/p13_TouchSensorLamp"); - ret.add("Example/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo"); - ret.add("Example/11.ArduinoISP/ArduinoISP"); - ret.add("Example/Teensy/Tutorial3/HelloSerialMonitor"); - ret.add("Example/Teensy/Tutorial3/Pushbutton"); - ret.add("Example/Teensy/Tutorial3/PushbuttonPullup"); - ret.add("Example/Teensy/Tutorial3/PushbuttonRGBcolor"); - ret.add("Example/Teensy/Tutorial4/AnalogInput"); - ret.add("Example/Teensy/Tutorial4/TemperatureNumberOnly"); - ret.add("Example/Teensy/Tutorial4/TemperatureScaled"); - ret.add("Example/Teensy/Tutorial4/TemperatureScaledMulti"); - return ret; - } - - private static LinkedList examplesUsingJoyStick() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/Teensy/USB_Joystick/Basic"); - ret.add("Example/Teensy/USB_Joystick/Buttons"); - ret.add("Example/Teensy/USB_Joystick/Complete"); - return ret; - } - - private static LinkedList examplesUsingMouse() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/Teensy/USB_Joystick/Basic"); - ret.add("Example/Teensy/USB_Joystick/Buttons"); - ret.add("Example/Teensy/USB_Joystick/Complete"); - ret.add("Example/Teensy/USB_RawHID/Basic"); - return ret; - } - - private static LinkedList examplesUsingWire1() { - LinkedList ret = new LinkedList<>(); - ret.add("Example/Teensy/USB_Joystick/Basic"); - ret.add("Example/Teensy/USB_Joystick/Buttons"); - ret.add("Example/Teensy/USB_Joystick/Complete"); - ret.add("Example/Teensy/USB_RawHID/Basic"); - ret.add("Library/Adafruit_BME280_Library/advancedsettings"); - ret.add("Library/AS3935MI/AS3935MI_LightningDetector_otherInterfaces"); - return ret; - } - - private static LinkedList examplesUsingMCUmo() { - LinkedList ret = new LinkedList<>(); - ret.add("Library/Adafruit_Circuit_Playground/CircuitPlaygroundFirmata_Express_CodeOrg"); - return ret; - } - - /* - * These examples that are known to fail - */ - private static LinkedList failingExamples() { - LinkedList ret = new LinkedList<>(); - /* - * Because you can not define a enum 2 times Sloeber can not add the enum in - * Slober.ino.cpp as a result the function declarations using these enums - * generate a error because the enum is not defined. The examples below fail due - * to this - */ - ret.add("Library/_2020Bot_Library/_2020Bot_Demo"); - // These examples are the processing part and are not a deal of sloeber - ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate"); - // manual action is needed for following examples - ret.add("Library/Accessories/CANCommander"); - ret.add("Library/Accessories_CANCommander"); - ret.add("Library/Accessories/Demo"); - ret.add("Library/Accessories/Full"); - ret.add("Library/Accessories/Group"); - ret.add("Library/Accessories/LightFading"); - ret.add("Library/Accessories/LMD18200"); - ret.add("Library/Accessories/Servos"); - ret.add("Library/Accessories/SignalFrench"); - ret.add("Library/Accessories/Signals4x3"); - ret.add("Library/Accessories/SimpleLed"); - ret.add("Library/Accessories/SimpleLedMulti"); - ret.add("Library/Accessories/Stepper"); - ret.add("Library/Accessory/Shield/OLED/example/Adafruit"); - ret.add("Library/Accessory/Shield/temp/humidity/oled"); - // at the time of testing there were case sensetivity issues - ret.add("Library/AutoAnalogAudio/SDAudio/SdAudioRecording"); - ret.add("Library/AutoAnalogAudio/SDAudio/SdAudioWavPlayer"); - ret.add("Library/AutoAnalogAudio/AudioRadioRelay"); - ret.add("Library/AutoAnalogAudio/WirelessMicrophone"); - ret.add("Library/AutoAnalogAudio/WirelessSpeaker"); - ret.add("Library/AutoAnalogAudio/WirelessTx_RPi"); - // needs to get the defines and includes right - ret.add("Library/Accessories/Locoduino.org/Programme4"); - ret.add("Library/Accessories/Locoduino.org/Programme5"); - // Should be build on a stm32 (nucleo as far as I get) - // but these bards require #927 (and probably more :-( - ret.add("Library/ADCTouchSensor/CapacitiveController"); - ret.add("Library/ADCTouchSensor/CapacitivePiano"); - // failed in SPI :-( - ret.add("Library/Adafruit_TinyFlash/TrinketPlayer"); - // not sure how this could work - ret.add("Library/Adafruit_VS1053_Library/feather_midi"); - // all kinds of incompatibility issues I guess - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8b_Use_Bluetooth_Signal_Strength_to_Control_Things"); - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8c_Change_Andee_Bluetooth_Device_Name"); - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8d_How_to_Read_and_Write_to_SD_Card"); - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8f_Using_Andee_IO_Pins_as_OUTPUT_Pins"); - ret.add("Library/Andee/Lesson_08_Miscellaneous/Lesson_8g_Getting_Inputs_from_Andee_IO_Pins"); - ret.add("Library/Andee/Lesson_09_SmartDevice_Control/Lesson_9a_Get_Device_Bluetooth_MAC_Address_ANDROID_Only"); - ret.add("Library/Andee/Lesson_09_SmartDevice_Control/Lesson_9b_Filter_Devices_by_Bluetooth_MAC_Address_ANDROID_Only"); - // doc says not finished - ret.add("Library/ANT-Arduino/NativeAnt"); - // uses missing library MobileBLE - ret.add("Library/ArduinoBlue/differentialDriveCar"); - // defining struct/enum in ino file - ret.add("Library/ArduinoJson/JsonConfigFile"); - ret.add("Library/Arduboy2/RGBled"); - // error: no matching function for call to 'aREST_UI::addToBuffer(const char - ret.add("Library/aREST_UI/ESP8266"); - ret.add("Library/aREST_UI/WiFi_CC3000"); - ret.add("Library/aREST_UI/WildFire"); - // uses arduinoWIFI - ret.add("Library/Braccio/braccioOfUnoWiFi"); - // uses lib that does not has lib folder= include-.h - ret.add("Library/ArduinoCloud/SimpleCloudButtonYun"); - // usi!ng non exsisting methods - ret.add("Library/CAN-BUS_Shield/gpioRead"); - ret.add("Library/CAN-BUS_Shield/gpioWrite"); - // using defines inino file to generate functions (not supported in Sloeber) - ret.add("Library/Adafruit_VEML6070_Library/unittests"); - // uses a non existing header - ret.add("Library/AESLib/complex"); - // using wrong sdfat librarie - ret.add("Library/Arduino_OPL2_SimpleTone"); - ret.add("Library/Arduino_OPL2_Teensy_PlayDRO"); - ret.add("Library/Arduino_OPL2_Teensy_PlayIMF"); - // I don't recall why following examples didn't work - ret.add("Library/arduino_ess_ess_yun"); - ret.add("Library/arduino_ess_linkit_one_dweet"); - ret.add("Library/AD7193/AD7193_VoltageMeasurePsuedoDifferential_Example"); - ret.add("Library/bunny_cuberotate/cuberotate"); - ret.add("Library/XPT2046_Touchscreen/ILI9341Test"); - ret.add("Library/Adafruit_AHRS/ahrs_mahony"); - ret.add("Library/Adafruit_BLEFirmata/StandardFirmata"); - ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate"); - ret.add("Library/Adafruit_GPS_Library/due_shield_sdlog"); - ret.add("Library/Adafruit_Graphic_VFD_Display_Library/GraphicVFDtest"); - ret.add("Library/Adafruit_GPS_Library/locus_erase"); - ret.add("Library/Adafruit_GPS_Library/shield_sdlog"); - ret.add("Library/Adafruit_HX8357_Library/breakouttouchpaint"); - ret.add("Library/Adafruit_ILI9341/breakouttouchpaint"); - ret.add("Library/Adafruit_ILI9341/onoffbutton_breakout"); - ret.add("Library/Adafruit_GPS_Library/echo"); - ret.add("Library/Adafruit_LED_Backpack_Library/wavface"); - ret.add("Library/Adafruit_SSD1306/ssd1306_128x64_i2c"); - ret.add("Library/Adafruit_SSD1306/ssd1306_128x64_spi"); - ret.add("Library/Adafruit_ST7735_Library/soft_spitftbitmap"); - ret.add("Library/Adafruit_TCS34725/colorview/processing/colorview"); - ret.add("Library/Adafruit_TinyRGBLCDShield/TinyHelloWorld"); - ret.add("Library/Akafugu_TWILiquidCrystal_Library/change_address"); - ret.add("Library/Akafugu_WireRtc_Library/alarm"); - ret.add("Library/ALA/RgbStripButton"); - ret.add("Library/APA102/GameOfLife"); - ret.add("Library/arduino-menusystem/led_matrix"); - ret.add("Library/arduino-menusystem/led_matrix_animated"); - ret.add("Library/Arduino_Low_Power/TianStandby"); - ret.add("Library/aREST/BLE"); - ret.add("Library/aREST/ESP32"); - ret.add("Library/aREST/ESP32_cloud"); - ret.add("Library/ArduinoHttpClient/DweetGet"); - ret.add("Library/ArduinoMenu_library/adafruitGfx/lcdMono/lcdMono"); - ret.add("Library/ArduinoMenu_library/adafruitGfx/tft/tft"); - ret.add("Library/ArdVoice/Sample2-Complex"); - ret.add("Library/Aspen_SIM800/Access_HTTP"); - ret.add("Library/Awesome/advanced/how_fast"); - ret.add("Library/Awesome/advanced/lie_detector"); - ret.add("Library/AzureIoTUtility/simplesample_http"); - ret.add("Library/BLEPeripheral/ir_bridge"); - ret.add("Library/BLEPeripheral/temp_sensor"); - ret.add("Library/Brasilino/Basicos/controleGradual"); - ret.add("Library/ClosedCube_HDC1010/hdc1010demo"); - ret.add("Library/Chrono/Resolutions"); - ret.add("Library/Chrono/StopResume"); - ret.add("Library/ConfigurableFirmata/ConfigurableFirmataWiFi"); - ret.add("Library/ControleForno/configuravel"); - ret.add("Library/CopyThreads/c"); - ret.add("Library/ArduinoCloud/SimpleCloudButtoBrzo_I2C"); - ret.add("Library/CopyThreads/FromReadme"); - ret.add("Library/DallasTemperature/Multibus_simple"); - ret.add("Library/DecodeIR/InfraredDecode"); - ret.add("Library/AutoAnalogAudio/SimpleSine"); - ret.add("Library/DimSwitch/DimSwitchTester-ESP-MQTT"); - ret.add("Library/DS3231/echo_time"); - ret.add("Library/Easy_NeoPixels"); - ret.add("Library/DallasTemperature/AlarmHandler"); - ret.add("Library/AmazonDRS/amazonDashNfc"); - ret.add("Library/Andee/Lesson_02_Buttons/Lesson_2h_Using_Buttons_to_Control_Servos"); - ret.add("Library/Andee/Project_Christmas_Lights_and_Annoying_Music"); - ret.add("Library/Andee/Project_Rubber_Band_Launcher"); - ret.add("Library/Andee/Project_Time_Automated_Data_Logger"); - ret.add("Library/ANT-Arduino_library/NativeAnt"); - ret.add("Library/arduino-fsm/timed_switchoff"); - ret.add("Library/BME280/BME_280_BRZO_I2C_Test"); - ret.add("Library/Adafruit_seesaw_Library/DAP"); - // uses unknown NO_ERROR - ret.add("Library/ClosedCube_TCA9546A/tca9546a_sht31d"); - // uses dht.h from dht_sensor_lib - ret.add("Library/CMMC_MQTT_Connector/basic_dht"); - ret.add("Library/ArduinoLearningKitStarter/boardTest"); - // uses altsoftserial and then Serial2???? - ret.add("Library/CMMC_NB-IoT/example1"); - // some bu!g I guess - ret.add("Library/CopyThreads/ExamplesFromReadme"); - ret.add("Library/CRC_Simula_Arduino_IDE_Library/Simula_BehaviorTree"); - // empty sketch?? - ret.add("Library/DFW/ProvisionController"); - // error: 'mapSensor' was not declared in this scope - ret.add("Library/AD_Sensors/ConstrainAnalogSensor"); - // error: 'sensor' was not declared in this scope - ret.add("Library/AD_Sensors/MapAndConstrainAnalogSensor"); - // ess-yun.ino:17:12: error: no matching function for call to - // 'HttpClient::HttpClient()' - ret.add("Library/arduino-ess/ess-yun"); - // I have no linket board in test setup - ret.add("Library/arduino-ess/linkit-one-dweet"); - //cores\arduino/WString.h:38:74: error: statement-expressions - ret.add("Library/ArduinoTrace/TraceFromGlobalScope"); - // no matching function for call to 'aREST::handle(EthernetClient&)' - ret.add("Library/aREST/Ethernet"); - // AsciiMassage_servos.ino:75:37: error: no matching function for call to - // 'AsciiMassagePacker::streamEmpty(const char [6])' - ret.add("Library/AsciiMassage/AsciiMassage_servos"); - // \BH1750FVI_Simple.ino:33:10: error: 'class Serial_' has no member named - // 'printf' - ret.add("Library/BH1750FVI/BH1750FVI_Simple"); - // * This example not complete at all, TODO. - ret.add("Library/Blinker/Blinker_AUTO/AUTO_MQTT"); - // 3: error: 'StaticJsonBuffer' was not declared in this scope - ret.add("Library/Boodskap_Message_library/SimpleMessageUsage"); - return ret; - } - - /** - * Give a list of boards pick the board that is best to test this code Boards in - * the beginning of the array are prefered (first found ok algorithm) - * - * returns null if this code should not be tested return null if myBoards is - * empty returns the best known boarddescriptor to run this example - */ - public static MCUBoard pickBestBoard(Examples example, MCUBoard myBoards[]) { - String libName = example.getLibName(); - String fqn = example.getFQN(); - if (myBoards.length == 0) { - return null; - } - - if (example.getRequiredBoardAttributes().worksOutOfTheBox) { - - // if example states which board it wants use that board - if (example.getRequiredBoardAttributes().boardName != null) { - String wantedBoardName = example.getRequiredBoardAttributes().boardName; - for (MCUBoard curBoard : myBoards) { - if (curBoard.getID().equals(wantedBoardName)) { - return curBoard; - } - } - } else { - // examples using DHT_sensor_library libraries are not found as the include is - // DHT.h - if (!libName.equals("DHT_sensor_library") && fqn.contains("DHT")) { - return null; - } - // if the boardname is in the libname or ino name pick this one - for (MCUBoard curBoard : myBoards) { - String curBoardName = curBoard.getSlangName().toLowerCase(); - if (libName.toLowerCase().contains(curBoardName) || fqn.toLowerCase().contains(curBoardName)) { - if (curBoard.isExampleSupported(example)) { - return curBoard; - } - } - } - // If the architecture is in the libname or boardname pick this one - for (MCUBoard curBoard : myBoards) { - String curArchitectureName = curBoard.getBoardDescriptor().getArchitecture().toLowerCase(); - if (libName.toLowerCase().contains(curArchitectureName) - || fqn.toLowerCase().contains(curArchitectureName)) { - if (curBoard.isExampleSupported(example)) { - return curBoard; - } - } - } - // if the example name contains teensy try teensy board - if (example.getFQN().toLowerCase().contains("teensy")) { - for (MCUBoard curBoard : myBoards) { - if (Teensy.class.isInstance(curBoard)) { - return curBoard; - } - } - } - // if the example name contains ESP32 try ESP32 board - if (example.getFQN().toLowerCase().contains("esp32")) { - for (MCUBoard curBoard : myBoards) { - if (ESP32.class.isInstance(curBoard)) { - return curBoard; - } - } - } - // if the example name contains ESP try ESP8266 board -// if (example.getFQN().toLowerCase().contains("esp")) { -// for (MCUBoard curBoard : myBoards) { -// if (ESP8266.class.isInstance(curBoard)) { -// return curBoard; -// } -// } -// } -//causes issues with response - - // Out of guesses based on the name. Take the first ok one - for (MCUBoard curBoard : myBoards) { - if (curBoard.isExampleSupported(example)) { - return curBoard; - } - } - } - } - System.out.println("No board found for " + Integer.toString(++noBoardFoundCount) + " " + example.getFQN()); - return null; - } - - private static String getRequiredBoardID(String fqn) { - switch (fqn) { - case "Library/Accessory_Shield/OLED_example_Adafruit": - case "Library/Accessory_Shield/temp_humidity_oled": - return "uno"; - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_NeoPixel": - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Read": - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Record": - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Send": - case "Library/Adafruit_Circuit_Playground/Infrared_Demos/Infrared_Testpattern": - case "Library/Adafruit_Zero_FFT_Library/CircuitPlayground": - return "adafruit_circuitplayground_m0"; - case "Library/Adafruit_MiniMLX90614/templight": - return "gemma"; - case "Library/ArduinoThread/SensorThread": - return "due"; - case "Library/AudioFrequencyMeter/SimpleAudioFrequencyMeter": - case "Library/Adafruit_NeoPXL8/strandtest": - return "zero"; - case "Library/BLEPeripheral/iBeacon": - return "feather52"; - default: - return null; - } - - } -} diff --git a/io.sloeber.tests/src/io/sloeber/core/MySystem.java b/io.sloeber.tests/src/io/sloeber/core/MySystem.java index 9063d85ad..839a797c8 100644 --- a/io.sloeber.tests/src/io/sloeber/core/MySystem.java +++ b/io.sloeber.tests/src/io/sloeber/core/MySystem.java @@ -2,7 +2,6 @@ import static org.junit.Assert.*; -import io.sloeber.core.api.Other; import io.sloeber.providers.Arduino; import io.sloeber.providers.ESP8266; import io.sloeber.providers.MCUBoard; @@ -14,69 +13,54 @@ */ @SuppressWarnings("nls") public class MySystem { - private static final String jantjesWindowsMachineHashKey = "1248215851"; - //the one below is based on one mac address Fysiek adres (MAC): C0-3F-D5-66-04-58 - private static final String jantjesWindowsMachineHashkeyAfterUpdate="139705674"; - private static final String jantjesLinuxMachineHashKey = "88937904"; - private static final String jantjeWindowsMachineHashkeyAfterSecondUpdate="-441525448"; + private static final String jantjesWindowsMachine = "1248215851"; + //the one below is based on one mac address Fysiek adres (MAC): C0-3F-D5-66-04-58 + private static final String jantjesLinuxMachine = "88937904"; + private static final String currentMachine = jantjesWindowsMachine; - public static String getTeensyPlatform() { - switch (Other.getSystemHash()) { - case jantjesWindowsMachineHashKey: - case jantjesWindowsMachineHashkeyAfterUpdate: - case jantjeWindowsMachineHashkeyAfterSecondUpdate: - return "E:\\arduino\\arduino-1.8.12 - teensy\\hardware\\teensy"; - case jantjesLinuxMachineHashKey: - return "/home/jan/tensyduino/arduino-1.8.12/hardware/teensy"; - default: - return new String(); - } - } + public static String getTeensyPlatform() { + switch (currentMachine) { + case jantjesWindowsMachine: + return "E:\\arduino\\arduino-1.8.12 - teensy\\hardware\\teensy"; + case jantjesLinuxMachine: + return "/home/jan/tensyduino/arduino-1.8.12/hardware/teensy"; + default: + return new String(); + } + } - public static String getTeensyBoard_txt() { - return getTeensyPlatform() + "/avr/boards.txt"; - } - public static MCUBoard[] getUploadBoards() { - switch (Other.getSystemHash()) { - case jantjesLinuxMachineHashKey: { - MCUBoard[] boards = { - Teensy.teensypp2("/dev/ttyACM0"), - Arduino.leonardo("/dev/ttyS0"), //werkt niet - Arduino.fried2016("/dev/ttyS0"), //werkt niet - Arduino.zeroNatviePort("/dev/ttyS0"), //werkt niet - Arduino.yun("COM20"), - ESP8266.wemosD1("/dev/ttyUSB0"), - Arduino.arduino_101("COM15"), - Arduino.zeroProgrammingPort("COM14"), - Arduino.getMega2560Board("COM11"), - Arduino.dueprogramming("COM8"), - Arduino.uno("COM6"), - }; - return boards; - } - case jantjesWindowsMachineHashKey: - case jantjeWindowsMachineHashkeyAfterSecondUpdate: - case jantjesWindowsMachineHashkeyAfterUpdate:{ - //due native upload gives to mutch trouble even in arduino IDE - MCUBoard[] boards = { - Teensy.teensypp2("COM103"), - // Teensy.Teensy3_1("COM24"), - Arduino.leonardo("COM101"), - Arduino.fried2016("COM102"), - Arduino.zeroNatviePort("COM104"), //boardSponsor - Arduino.yun("COM106"), - ESP8266.wemosD1("COM108"), - Arduino.arduino_101("COM110"), - Arduino.zeroProgrammingPort("COM111"), - Arduino.getMega2560Board("COM112"), - Arduino.dueprogramming("COM124"), - Arduino.uno("COM126"), - }; - return boards; - } - default: - fail("Boards for the system with haskey " + Other.getSystemHash() + " are not found"); - return null; - } - } + public static String getTeensyBoard_txt() { + return getTeensyPlatform() + "/avr/boards.txt"; + } + + public static MCUBoard[] getUploadBoards() { + switch (currentMachine) { + case jantjesLinuxMachine: { + MCUBoard[] boards = { Teensy.teensypp2().setUploadPort("/dev/ttyACM0"), + Arduino.leonardo().setUploadPort("/dev/ttyS0"), //werkt niet + Arduino.fried2016().setUploadPort("/dev/ttyS0"), //werkt niet + Arduino.zeroNatviePort().setUploadPort("/dev/ttyS0"), //werkt niet + Arduino.yun().setUploadPort("COM20"), ESP8266.wemosD1().setUploadPort("/dev/ttyUSB0"), + Arduino.arduino_101().setUploadPort("COM15"), Arduino.zeroProgrammingPort().setUploadPort("COM14"), + Arduino.getMega2560Board().setUploadPort("COM11"), Arduino.dueprogramming().setUploadPort("COM8"), + Arduino.uno().setUploadPort("COM6"), }; + return boards; + } + case jantjesWindowsMachine: + //due native upload gives to mutch trouble even in arduino IDE + MCUBoard[] boards = { Teensy.teensypp2().setUploadPort("COM103"), + // Teensy.Teensy3_1("COM24"), + Arduino.leonardo().setUploadPort("COM101"), Arduino.fried2016().setUploadPort("COM102"), + Arduino.zeroNatviePort().setUploadPort("COM104"), //boardSponsor + Arduino.yun().setUploadPort("COM106"), ESP8266.wemosD1().setUploadPort("COM108"), + Arduino.arduino_101().setUploadPort("COM110"), + Arduino.zeroProgrammingPort().setUploadPort("COM111"), + Arduino.getMega2560Board().setUploadPort("COM112"), + Arduino.dueprogramming().setUploadPort("COM124"), Arduino.uno().setUploadPort("COM126"), }; + return boards; + default: + fail("Boards for the system with haskey " + currentMachine + " are not found"); + return null; + } + } } diff --git a/io.sloeber.tests/src/io/sloeber/core/NightlyBoardPatronTest.java b/io.sloeber.tests/src/io/sloeber/core/NightlyBoardPatronTest.java index 00e76c514..ea62f3ed8 100644 --- a/io.sloeber.tests/src/io/sloeber/core/NightlyBoardPatronTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/NightlyBoardPatronTest.java @@ -28,7 +28,7 @@ public class NightlyBoardPatronTest { private static int myBuildCounter = 0; - private Examples myExample; + private Example myExample; private MCUBoard myBoardID; private static int mySkipAtStart = 0; private static int myTotalFails = 0; @@ -36,7 +36,7 @@ public class NightlyBoardPatronTest { private static CompileDescription myCompileOptions; private static boolean deleteProjects =true; //delete the projects after trying to build them - public NightlyBoardPatronTest(String name, MCUBoard boardID, Examples example) { + public NightlyBoardPatronTest(String name, MCUBoard boardID, Example example) { myBoardID = boardID; myExample = example; } @@ -62,7 +62,7 @@ public static Collection examples() { IPath examplePath = curexample.getValue(); //for patron Keith Willis. Thanks Keith if (fqn.contains("RTCZero")) { - Examples example = new Examples(fqn, examplePath); + Example example = new Example(fqn, examplePath); Object[] theData = new Object[] {Shared.getCounterName( example.getLibName() + ":" + fqn + ":" + zeroBoard.getID()), zeroBoard, example }; diff --git a/io.sloeber.tests/src/io/sloeber/core/RegressionTest.java b/io.sloeber.tests/src/io/sloeber/core/RegressionTest.java index 7c3709c5e..637f5ffea 100644 --- a/io.sloeber.tests/src/io/sloeber/core/RegressionTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/RegressionTest.java @@ -23,12 +23,12 @@ import org.junit.Test; import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.CompileDescription; import io.sloeber.core.api.CompileDescription.SizeCommands; import io.sloeber.core.api.CompileDescription.WarningLevels; import io.sloeber.core.api.OtherDescription; -import io.sloeber.core.api.PackageManager; import io.sloeber.core.api.Preferences; import io.sloeber.core.api.SloeberProject; import io.sloeber.providers.Arduino; @@ -56,9 +56,9 @@ public static void WaitForInstallerToFinish() { public static void installAdditionalBoards() { String[] packageUrlsToAdd = { ESP8266.packageURL, ESP32.packageURL }; - PackageManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true); + BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true); if (reinstall_boards_and_libraries) { - PackageManager.removeAllInstalledPlatforms(); + BoardsManager.removeAllInstalledPlatforms(); } ; // make sure the needed boards are available @@ -67,7 +67,7 @@ public static void installAdditionalBoards() { Arduino.installLatestAVRBoards(); if (!MySystem.getTeensyPlatform().isEmpty()) { - PackageManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); + BoardsManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); } } @@ -85,7 +85,7 @@ public void issue555() { } System.out.println("Teensy is installed at " + MySystem.getTeensyPlatform()); BoardDescription unoBoardid = Arduino.uno().getBoardDescriptor(); - BoardDescription teensyBoardid = Teensy.Teensy3_1("").getBoardDescriptor(); + BoardDescription teensyBoardid = Teensy.Teensy3_1().getBoardDescriptor(); IProject theTestProject = null; CodeDescription codeDescriptor = CodeDescription.createDefaultIno(); diff --git a/io.sloeber.tests/src/io/sloeber/core/RegressionTestFailingOnTravis.java b/io.sloeber.tests/src/io/sloeber/core/RegressionTestFailingOnTravis.java index ab7b93d62..4ea0e14c3 100644 --- a/io.sloeber.tests/src/io/sloeber/core/RegressionTestFailingOnTravis.java +++ b/io.sloeber.tests/src/io/sloeber/core/RegressionTestFailingOnTravis.java @@ -13,7 +13,7 @@ import io.sloeber.core.api.BoardDescription; import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.CompileDescription; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.Preferences; import io.sloeber.providers.Arduino; @@ -34,9 +34,9 @@ public static void WaitForInstallerToFinish() { public static void installAdditionalBoards() { String[] packageUrlsToAdd = { "http://talk2arduino.wisen.com.au/master/package_talk2.wisen.com_index.json" }; - PackageManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), false); + BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), false); if (!MySystem.getTeensyPlatform().isEmpty()) { - PackageManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); + BoardsManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); } } @@ -49,10 +49,10 @@ public static void installAdditionalBoards() { public void redirectedJson() { //this board references to arduino avr so install that one to Arduino.installLatestAVRBoards(); - PackageManager.installLatestPlatform("package_talk2.wisen.com_index.json", "Talk2", "avr"); + BoardsManager.installLatestPlatform("package_talk2.wisen.com_index.json", "Talk2", "avr"); Map options = new HashMap<>(); options.put("mhz", "16MHz"); - BoardDescription boardid = PackageManager.getBoardDescription("package_talk2.wisen.com_index.json", "Talk2", + BoardDescription boardid = BoardsManager.getBoardDescription("package_talk2.wisen.com_index.json", "Talk2", "avr", "whispernode", options); if (boardid == null) { fail("redirect Json "); diff --git a/io.sloeber.tests/src/io/sloeber/core/Shared.java b/io.sloeber.tests/src/io/sloeber/core/Shared.java index 41af9c27d..4e19d46d6 100644 --- a/io.sloeber.tests/src/io/sloeber/core/Shared.java +++ b/io.sloeber.tests/src/io/sloeber/core/Shared.java @@ -35,7 +35,7 @@ import io.sloeber.core.api.BoardDescription; import io.sloeber.core.api.CodeDescription; import io.sloeber.core.api.CompileDescription; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.SloeberProject; import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.providers.MCUBoard; @@ -89,7 +89,7 @@ public static void waitForAllJobsToFinish() { try { Thread.sleep(1000); IJobManager jobMan = Job.getJobManager(); - while (!(jobMan.isIdle() && PackageManager.isReady())) { + while (!(jobMan.isIdle() && BoardsManager.isReady())) { Thread.sleep(500); // If you do not get out of this loop it probably means you are // runnning the test in the gui thread @@ -263,7 +263,7 @@ public static String getCounterName(String name) { } @SuppressWarnings("unused") - public static String getProjectName(CodeDescription codeDescriptor, Examples example, MCUBoard board) { + public static String getProjectName(CodeDescription codeDescriptor, Example example, MCUBoard board) { return String.format("%05d_%s_%s", Integer.valueOf(myTestCounter++), codeDescriptor.getExampleName(), board.getBoardDescriptor().getBoardID()); } diff --git a/io.sloeber.tests/src/io/sloeber/junit/AllJUnitTests.java b/io.sloeber.tests/src/io/sloeber/junit/AllJUnitTests.java index 47af3d0d7..8f7f09196 100644 --- a/io.sloeber.tests/src/io/sloeber/junit/AllJUnitTests.java +++ b/io.sloeber.tests/src/io/sloeber/junit/AllJUnitTests.java @@ -8,5 +8,5 @@ @SuiteClasses({ TestPlatformWorkAround.class, TestSerialPlotterFilter.class, TestTxtFile.class, TestWorkAround.class, TxtWorkAroundRegression.class, TestVersionCompare.class }) public class AllJUnitTests { - + //no need for code here } diff --git a/io.sloeber.tests/src/io/sloeber/junit/TestPlatformWorkAround.java b/io.sloeber.tests/src/io/sloeber/junit/TestPlatformWorkAround.java index fb52cee2a..f3ff731b8 100644 --- a/io.sloeber.tests/src/io/sloeber/junit/TestPlatformWorkAround.java +++ b/io.sloeber.tests/src/io/sloeber/junit/TestPlatformWorkAround.java @@ -5,7 +5,7 @@ import org.junit.Test; -import io.sloeber.core.tools.Version; +import io.sloeber.core.api.VersionNumber; @SuppressWarnings({ "nls", "static-method" }) public class TestPlatformWorkAround { @@ -26,21 +26,21 @@ public void PlatformFixes() { @Test public void ToolFixes() { - assertEquals("1", Version.compare("1.0.0", "16"), -1); - assertEquals("2", Version.compare("1.1.0", "1.16"), -1); - assertEquals("3", Version.compare("1.1", "1.1.16"), -1); - assertEquals("3", Version.compare("1", "16.1"), -1); - assertEquals("4", Version.compare("1.16.0", "1.1.0"), 1); - assertEquals("5", Version.compare("16.0.0", "1.0.1"), 1); - assertEquals("6", Version.compare("1.1.16", "1.1.1"), 1); + assertEquals("1", new VersionNumber("1.0.0").compareTo("16"), -1); + assertEquals("2", new VersionNumber("1.1.0").compareTo("1.16"), -1); + assertEquals("3", new VersionNumber("1.1").compareTo("1.1.16"), -1); + assertEquals("3", new VersionNumber("1").compareTo("16.1"), -1); + assertEquals("4", new VersionNumber("1.16.0").compareTo("1.1.0"), 1); + assertEquals("5", new VersionNumber("16.0.0").compareTo("1.0.1"), 1); + assertEquals("6", new VersionNumber("1.1.16").compareTo("1.1.1"), 1); } @Test public void StringVersions() { - assertEquals("1", Version.compare("4.5.2r2", "4.5.2"), 1); - assertEquals("1", Version.compare("4.5.2r2", "4.5.2r3"), -1); - assertEquals("1", Version.compare("4.5.2r2", "4.5.20"), -1); - assertEquals("1", Version.compare("4.5.20r2", "4.5.20"), 1); + assertEquals("1", new VersionNumber("4.5.2r2").compareTo("4.5.2"), 1); + assertEquals("1", new VersionNumber("4.5.2r2").compareTo("4.5.2r3"), -1); + assertEquals("1", new VersionNumber("4.5.2r2").compareTo("4.5.20"), -1); + assertEquals("1", new VersionNumber("4.5.20r2").compareTo("4.5.20"), 1); } } diff --git a/io.sloeber.tests/src/io/sloeber/junit/TestVersionCompare.java b/io.sloeber.tests/src/io/sloeber/junit/TestVersionCompare.java index 5f19481c8..daf2898ba 100644 --- a/io.sloeber.tests/src/io/sloeber/junit/TestVersionCompare.java +++ b/io.sloeber.tests/src/io/sloeber/junit/TestVersionCompare.java @@ -1,47 +1,48 @@ package io.sloeber.junit; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import org.junit.Test; -import io.sloeber.core.tools.Version; +import io.sloeber.core.api.VersionNumber; -@SuppressWarnings({"nls","static-method"}) +@SuppressWarnings({ "nls", "static-method" }) public class TestVersionCompare { + @Test + public void NonStringVersion() { + assertEquals("1", new VersionNumber("1.0.0").compareTo("1"), 1); + assertEquals("2", new VersionNumber("1.1.0").compareTo("1.1"), 1); + assertEquals("3", new VersionNumber("1.1").compareTo("1.1.1"), -1); + assertEquals("3", new VersionNumber("1").compareTo("1.1"), -1); + assertEquals("1", new VersionNumber("1.0.0").compareTo("1.0.0"), 0); + assertEquals("2", new VersionNumber("1.1.0").compareTo("1.1.0"), 0); + assertEquals("3", new VersionNumber("1.1.1").compareTo("1.1.1"), 0); + assertEquals("4", new VersionNumber("1.0.0").compareTo("1.1.0"), -1); + assertEquals("5", new VersionNumber("1.0.0").compareTo("1.0.1"), -1); + assertEquals("6", new VersionNumber("1.0.0").compareTo("1.1.1"), -1); + assertEquals("7", new VersionNumber("1.1.0").compareTo("1.0.0"), 1); + assertEquals("8", new VersionNumber("1.0.1").compareTo("1.0.0"), 1); + assertEquals("9", new VersionNumber("1.1.1").compareTo("1.0.0"), 1); + } - @Test - public void NonStringVersion() { - assertEquals("1",Version.compare("1.0.0","1"),1); - assertEquals("2",Version.compare("1.1.0","1.1"),1); - assertEquals("3",Version.compare("1.1","1.1.1"),-1); - assertEquals("3",Version.compare("1","1.1"),-1); - assertEquals("1",Version.compare("1.0.0","1.0.0"),0); - assertEquals("2",Version.compare("1.1.0","1.1.0"),0); - assertEquals("3",Version.compare("1.1.1","1.1.1"),0); - assertEquals("4",Version.compare("1.0.0","1.1.0"),-1); - assertEquals("5",Version.compare("1.0.0","1.0.1"),-1); - assertEquals("6",Version.compare("1.0.0","1.1.1"),-1); - assertEquals("7",Version.compare("1.1.0","1.0.0"),1); - assertEquals("8",Version.compare("1.0.1","1.0.0"),1); - assertEquals("9",Version.compare("1.1.1","1.0.0"),1); - } - @Test - public void doubleDigit() { - assertEquals("1",Version.compare("1.0.0","16"),-1); - assertEquals("2",Version.compare("1.1.0","1.16"),-1); - assertEquals("3",Version.compare("1.1","1.1.16"),-1); - assertEquals("3",Version.compare("1","16.1"),-1); - assertEquals("4",Version.compare("1.16.0","1.1.0"),1); - assertEquals("5",Version.compare("16.0.0","1.0.1"),1); - assertEquals("6",Version.compare("1.1.16","1.1.1"),1); - - } - @Test - public void StringVersions() { - assertEquals("1",Version.compare("4.5.2r2","4.5.2"),1); - assertEquals("1",Version.compare("4.5.2r2","4.5.2r3"),-1); - assertEquals("1",Version.compare("4.5.2r2","4.5.20"),-1); - assertEquals("1",Version.compare("4.5.20r2","4.5.20"),1); - } + @Test + public void doubleDigit() { + assertEquals("1", new VersionNumber("1.0.0").compareTo("16"), -1); + assertEquals("2", new VersionNumber("1.1.0").compareTo("1.16"), -1); + assertEquals("3", new VersionNumber("1.1").compareTo("1.1.16"), -1); + assertEquals("3", new VersionNumber("1").compareTo("16.1"), -1); + assertEquals("4", new VersionNumber("1.16.0").compareTo("1.1.0"), 1); + assertEquals("5", new VersionNumber("16.0.0").compareTo("1.0.1"), 1); + assertEquals("6", new VersionNumber("1.1.16").compareTo("1.1.1"), 1); + + } + + @Test + public void StringVersions() { + assertEquals("1", new VersionNumber("4.5.2r2").compareTo("4.5.2"), 1); + assertEquals("1", new VersionNumber("4.5.2r2").compareTo("4.5.2r3"), -1); + assertEquals("1", new VersionNumber("4.5.2r2").compareTo("4.5.20"), -1); + assertEquals("1", new VersionNumber("4.5.20r2").compareTo("4.5.20"), 1); + } } diff --git a/io.sloeber.tests/src/io/sloeber/junit/TxtWorkAroundRegression.java b/io.sloeber.tests/src/io/sloeber/junit/TxtWorkAroundRegression.java index 9e263ed1e..f2854c40f 100644 --- a/io.sloeber.tests/src/io/sloeber/junit/TxtWorkAroundRegression.java +++ b/io.sloeber.tests/src/io/sloeber/junit/TxtWorkAroundRegression.java @@ -135,7 +135,7 @@ public void programmerTxt() throws Exception { } if (!expectedFile.exists()) { System.out.println("file does not exists " + expectedFile); - assumeFalse(true);// skip the test + return; } String input = FileUtils.readFileToString(inputFile, Charset.defaultCharset()); input = input.replace("\r\n", "\n"); @@ -154,8 +154,8 @@ public void programmerTxt() throws Exception { private String clean(String expected) { return expected.replace("\r\n", "\n").replaceAll("(?m)^#.*", "").replaceAll("(?m)^\\s*", "") - .replaceAll("(?m)\\s*$", "").replaceAll("(?m)^(\\S*)\\s*=", "$1=") - .replace("\n\n", "\n").replace("\n\n", "\n"); + .replaceAll("(?m)\\s*$", "").replaceAll("(?m)^(\\S*)\\s*=", "$1=").replace("\n\n", "\n") + .replace("\n\n", "\n"); } } diff --git a/io.sloeber.tests/src/io/sloeber/providers/Adafruit.java b/io.sloeber.tests/src/io/sloeber/providers/Adafruit.java index 47abc7e4e..3f9fd9825 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/Adafruit.java +++ b/io.sloeber.tests/src/io/sloeber/providers/Adafruit.java @@ -2,56 +2,67 @@ import static org.junit.Assert.*; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; + @SuppressWarnings("nls") public class Adafruit extends MCUBoard { - public final static String packageURL = "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"; + public final static String packageURL = "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json"; private static final String AVRArchitectureName = "avr"; private static final String SAMDArchitectureName = "samd"; - //private static final String SAMPlatformName = "Arduino SAM Boards (32-bits ARM Cortex-M3)"; + //private static final String SAMPlatformName = "Arduino SAM Boards (32-bits ARM Cortex-M3)"; private static final String NFR52ArchitectureName = "nRF52"; - //private static final String XICEDPlatformName = "Adafruit WICED"; - public static final String metroM4SlangName="metroM4"; - public static final String metroM4ID="adafruit_metro_m4"; - - - - public Adafruit( String architectureName, String boardName) { - - this.myBoardDescriptor = PackageManager.getBoardDescription( "package_adafruit_index.json","adafruit",architectureName , - boardName, null); - if (this.myBoardDescriptor == null) { - fail(boardName + " Board not found"); - } - this.myBoardDescriptor.setUploadPort("none"); - } - - - public static MCUBoard feather() { - MCUBoard ret= new Adafruit(NFR52ArchitectureName,"feather52832"); - ret.mySlangName="feather"; - return ret; - } - - - public static MCUBoard trinket8MH() { - MCUBoard ret = new Adafruit(AVRArchitectureName, "trinket3"); - ret.mySlangName="trinket"; - return ret; - } - - public static MCUBoard featherMO() { - MCUBoard ret = new Adafruit(SAMDArchitectureName, "adafruit_feather_m0"); - ret.mySlangName="FeatherM0"; - ret.myAttributes.mo_mcu=true; - return ret; - } - - public static MCUBoard metroM4() { - MCUBoard ret = new Adafruit(SAMDArchitectureName, metroM4ID); - ret.mySlangName=metroM4SlangName; - ret.myAttributes.mo_mcu=true; - return ret; - } - + //private static final String XICEDPlatformName = "Adafruit WICED"; + public static final String metroM4ID = "adafruit_metro_m4"; + + public Adafruit(String architectureName, String boardName) { + + myBoardDescriptor = BoardsManager.getBoardDescription("package_adafruit_index.json", "adafruit", + architectureName, boardName, null); + if (myBoardDescriptor == null) { + fail(boardName + " Board not found"); + } + myBoardDescriptor.setUploadPort("none"); + setAttributes(); + } + + public Adafruit(BoardDescription boardDesc) { + myBoardDescriptor = boardDesc; + myBoardDescriptor.setUploadPort("none"); + setAttributes(); + } + + public static MCUBoard feather() { + return new Adafruit(NFR52ArchitectureName, "feather52832"); + } + + public static MCUBoard trinket8MH() { + return new Adafruit(AVRArchitectureName, "trinket3"); + } + + public static MCUBoard featherMO() { + return new Adafruit(SAMDArchitectureName, "adafruit_feather_m0"); + } + + public static MCUBoard metroM4() { + return new Adafruit(SAMDArchitectureName, metroM4ID); + } + + @Override + protected void setAttributes() { + String BoardID = myBoardDescriptor.getBoardID(); + switch (BoardID) { + case metroM4ID: + case "adafruit_feather_m0": + myAttributes.mo_mcu = true; + return; + } + + } + + @Override + public MCUBoard createMCUBoard(BoardDescription boardDesc) { + return new Adafruit(boardDesc); + } + } diff --git a/io.sloeber.tests/src/io/sloeber/providers/Arduino.java b/io.sloeber.tests/src/io/sloeber/providers/Arduino.java index 7c4f7388a..01bfc2329 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/Arduino.java +++ b/io.sloeber.tests/src/io/sloeber/providers/Arduino.java @@ -7,302 +7,281 @@ import java.util.Map; import java.util.TreeMap; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.BoardAttributes; +import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; +import io.sloeber.core.api.Json.ArduinoPackage; +import io.sloeber.core.api.Json.ArduinoPlatform; +import io.sloeber.core.api.Json.ArduinoPlatformVersion; @SuppressWarnings("nls") public class Arduino extends MCUBoard { - private static final String providerArduino = "arduino"; - private static final String providerIntel = "Intel"; + private static final String providerArduino = "arduino"; + private static final String providerIntel = "Intel"; private static final String AVRArchitectureName = "avr"; private static final String SAMDArchitectureName = "samd"; private static final String SAMArchitectureName = "sam"; private static final String NFRArchitectureName = "nrf52"; + private static final String MBEDArchitectureName = "mbed"; private static final String intelCurieArchitectureName = "arc32"; - private static final String jsonFileName ="package_index.json"; - - public static final String circuitplay32ID="circuitplay32u4cat"; - public static final String unoID="uno"; - public static final String ethernetID="ethernet"; - - public static MCUBoard gemma() { - MCUBoard ret = new Arduino(providerArduino, AVRArchitectureName, "gemma"); - ret.mySlangName="gemma"; - return ret; - } - - public static MCUBoard MegaADK() { - return new Arduino(providerArduino, AVRArchitectureName, "megaADK"); - } - - public static MCUBoard esplora() { - return new Arduino(providerArduino, AVRArchitectureName, "esplora"); - } - - public static MCUBoard adafruitnCirquitPlayground() { - return new Arduino(providerArduino, AVRArchitectureName, circuitplay32ID); - } - public static MCUBoard cirquitPlaygroundExpress() { + private static final String jsonFileName = "package_index.json"; + + public static final String circuitplay32ID = "circuitplay32u4cat"; + public static final String unoID = "uno"; + public static final String ethernetID = "ethernet"; + public static final List mbedBoards = getAllmBedBoardNames(); + + public static MCUBoard gemma() { + return new Arduino(providerArduino, AVRArchitectureName, "gemma"); + } + + public static MCUBoard MegaADK() { + return new Arduino(providerArduino, AVRArchitectureName, "megaADK"); + } + + public static MCUBoard esplora() { + return new Arduino(providerArduino, AVRArchitectureName, "esplora"); + } + + public static MCUBoard adafruitnCirquitPlayground() { + return new Arduino(providerArduino, AVRArchitectureName, circuitplay32ID); + } + + public static MCUBoard cirquitPlaygroundExpress() { return new Arduino(providerArduino, SAMDArchitectureName, "adafruit_circuitplayground_m0"); - } - - public static MCUBoard getAvrBoard(String boardID) { - return new Arduino(providerArduino, AVRArchitectureName, boardID); - } - - public static MCUBoard fried2016() { - return new Arduino(providerArduino, AVRArchitectureName, "LilyPadUSB"); - } - - public static MCUBoard fried2016(String uploadPort) { - MCUBoard fried = fried2016(); - fried.myBoardDescriptor.setUploadPort(uploadPort); - return fried; - } - - public static MCUBoard getMega2560Board() { - MCUBoard mega = new Arduino(providerArduino, AVRArchitectureName, "mega"); - Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - options.put("cpu", "atmega2560"); - mega.myBoardDescriptor.setOptions(options); - return mega; - } - - public static MCUBoard getMega2560Board(String uploadPort) { - MCUBoard mega = getMega2560Board(); - mega.myBoardDescriptor.setUploadPort(uploadPort); - return mega; - } - - public static MCUBoard leonardo() { - MCUBoard leonardo = new Arduino(providerArduino, AVRArchitectureName, "leonardo"); - return leonardo; - } - - public static MCUBoard leonardo(String uploadPort) { - MCUBoard leonardo = leonardo(); - leonardo.myBoardDescriptor.setUploadPort(uploadPort); - return leonardo; - } - - public static MCUBoard yun() { - MCUBoard yun = new Arduino(providerArduino, AVRArchitectureName, "yun"); - return yun; - } - - public static MCUBoard yun(String uploadPort) { - MCUBoard yun = yun(); - yun.myBoardDescriptor.setUploadPort(uploadPort); - return yun; - } - - public static MCUBoard zeroProgrammingPort() { - MCUBoard zero = new Arduino(providerArduino, SAMDArchitectureName, "arduino_zero_edbg"); - zero.mySlangName="zero"; - return zero; - } - - public static MCUBoard zeroProgrammingPort(String uploadPort) { - MCUBoard zero = zeroProgrammingPort(); - zero.myBoardDescriptor.setUploadPort(uploadPort); - return zero; - } - - public static MCUBoard due() { - return new Arduino(providerArduino, SAMArchitectureName, "arduino_due_x"); - } + } - public static MCUBoard due(String uploadPort) { - MCUBoard board = due(); - board.myBoardDescriptor.setUploadPort(uploadPort); - return board; - } + public static MCUBoard fried2016() { + return new Arduino(providerArduino, AVRArchitectureName, "LilyPadUSB"); + } - public static MCUBoard dueprogramming() { - return new Arduino(providerArduino, SAMArchitectureName, "arduino_due_x_dbg"); - } + public static MCUBoard getMega2560Board() { + MCUBoard mega = new Arduino(providerArduino, AVRArchitectureName, "mega"); + Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + options.put("cpu", "atmega2560"); + mega.myBoardDescriptor.setOptions(options); + return mega; + } + + public static MCUBoard leonardo() { + return new Arduino(providerArduino, AVRArchitectureName, "leonardo"); + } + + public static MCUBoard yun() { + return new Arduino(providerArduino, AVRArchitectureName, "yun"); + } + + public static MCUBoard zeroProgrammingPort() { + return new Arduino(providerArduino, SAMDArchitectureName, "arduino_zero_edbg"); + } - public static MCUBoard dueprogramming(String uploadPort) { - MCUBoard board = dueprogramming(); - board.myBoardDescriptor.setUploadPort(uploadPort); - return board; - } + public static MCUBoard zeroNatviePort() { + MCUBoard zero = new Arduino(providerArduino, SAMDArchitectureName, "arduino_zero_native"); + zero.mySerialPort = "SerialUSB"; + return zero; + } - public static MCUBoard mkrfox1200() { + public static MCUBoard due() { + return new Arduino(providerArduino, SAMArchitectureName, "arduino_due_x"); + } + + public static MCUBoard dueprogramming() { + return new Arduino(providerArduino, SAMArchitectureName, "arduino_due_x_dbg"); + } + + public static MCUBoard mkrfox1200() { return new Arduino(providerArduino, SAMDArchitectureName, "mkrfox1200"); - } + } - public static MCUBoard primo() { + public static MCUBoard primo() { return new Arduino(providerArduino, NFRArchitectureName, "primo"); - } - - public static MCUBoard uno() { - MCUBoard uno = new Arduino(providerArduino, AVRArchitectureName, unoID); - uno.mySlangName="uno"; - return uno; - } - public static MCUBoard ethernet() { - MCUBoard uno = new Arduino(providerArduino, AVRArchitectureName, ethernetID); - return uno; - } - - public static MCUBoard uno(String uploadPort) { - MCUBoard uno = uno(); - uno.myBoardDescriptor.setUploadPort(uploadPort); - return uno; - } - - public static MCUBoard arduino_101() { - MCUBoard arduino_101 = new Arduino(providerIntel, intelCurieArchitectureName, "arduino_101"); - arduino_101.mySlangName="101"; - return arduino_101; - } - - public static MCUBoard arduino_101(String uploadPort) { - MCUBoard arduino_101 = arduino_101(); - arduino_101.myBoardDescriptor.setUploadPort(uploadPort); - return arduino_101; - } - - - private Arduino(String providerName, String architectureName, String boardName) { - this.myBoardDescriptor = PackageManager.getBoardDescription(jsonFileName, providerName, architectureName, - boardName, null); - if (this.myBoardDescriptor == null) { - fail(boardName + " Board not found"); - } - this.myBoardDescriptor.setUploadPort("none"); - - myAttributes.serial = !doesNotSupportSerialList().contains(boardName); - myAttributes.serial1 = supportSerial1List().contains(boardName); - myAttributes.keyboard = supportKeyboardList().contains(boardName); - myAttributes.wire1 = supportWire1List().contains(boardName); - myAttributes.buildInLed = !doesNotSupportbuildInLed().contains(boardName); - - } - - static List supportWire1List() { - List ret = new LinkedList<>(); - ret.add("zero"); - return ret; - } - - static List doesNotSupportbuildInLed() { + } + + public static MCUBoard uno() { + return new Arduino(providerArduino, AVRArchitectureName, unoID); + } + + public static MCUBoard ethernet() { + return new Arduino(providerArduino, AVRArchitectureName, ethernetID); + } + + public static MCUBoard arduino_101() { + return new Arduino(providerIntel, intelCurieArchitectureName, "arduino_101"); + } + + private Arduino(String providerName, String architectureName, String boardID) { + this.myBoardDescriptor = BoardsManager.getBoardDescription(jsonFileName, providerName, architectureName, + boardID, null); + if (this.myBoardDescriptor == null) { + fail(boardID + " Board not found"); + } + this.myBoardDescriptor.setUploadPort("none"); + setAttributes(); + } + + @Override + public MCUBoard createMCUBoard(BoardDescription boardDescriptor) { + return new Arduino(boardDescriptor); + + } + + public Arduino(BoardDescription boardDescriptor) { + myBoardDescriptor = boardDescriptor; + myBoardDescriptor.setUploadPort("none"); + setAttributes(); + } + + @Override + protected void setAttributes() { + String boardID = myBoardDescriptor.getBoardID(); + sharedsetAttributes(boardID, myAttributes); + // myAttributes.serial = !doesNotSupportSerialList().contains(boardID); + // myAttributes.serial1 = supportSerial1List().contains(boardID); + // myAttributes.keyboard = supportKeyboardList().contains(boardID); + // myAttributes.wire1 = supportWire1List().contains(boardID); + // myAttributes.buildInLed = !doesNotSupportbuildInLed().contains(boardID); + // myAttributes.tone = !doesNotSupportTone().contains(boardID); + // myAttributes.myNumAD = getNumADCsAvailable(boardID); + // myAttributes.directMode = !doesNotSupportDirectModeList().contains(boardID); + // myAttributes.serialUSB = !doesNotSupportSerialUSBList().contains(boardID); + } + + static protected void sharedsetAttributes(String boardID, BoardAttributes attributes) { + attributes.serial = !doesNotSupportSerialList().contains(boardID); + attributes.serial1 = supportSerial1List().contains(boardID); + attributes.keyboard = supportKeyboardList().contains(boardID); + attributes.wire1 = supportWire1List().contains(boardID); + attributes.buildInLed = !doesNotSupportbuildInLed().contains(boardID); + attributes.tone = !doesNotSupportTone().contains(boardID); + attributes.myNumAD = getNumADCsAvailable(boardID, attributes.myNumAD); + attributes.directMode = !doesNotSupportDirectModeList().contains(boardID); + attributes.serialUSB = !doesNotSupportSerialUSBList().contains(boardID); + } + + private static int getNumADCsAvailable(String boardID, int standard) { + switch (boardID) { + case "nicla_sense": + return 2; + case "pico": + case "nanorp2040connect": + return 4; + default: + //don't change default + return standard; + } + } + + private static List supportWire1List() { + List ret = new LinkedList<>(); + ret.add("zero"); + return ret; + } + + private static List doesNotSupportbuildInLed() { + List ret = new LinkedList<>(); + ret.add("robotControl"); + ret.add("robotMotor"); + ret.add("edge_control"); + ret.add("nicla_sense"); + return ret; + } + + protected static List supportSerial1List() { List ret = new LinkedList<>(); + ret.add("circuitplay32u4cat"); + ret.add("LilyPadUSB"); + ret.add("Micro"); + ret.add("yunMini"); ret.add("robotControl"); + ret.add("Esplora"); + ret.add("mega"); + ret.add("chiwawa"); + ret.add("yun"); + ret.add("one"); + ret.add("leonardo"); ret.add("robotMotor"); + ret.add("leonardoEth"); + ret.add("megaADK"); + + return ret; + } + + protected static List doesNotSupportSerialList() { + List ret = new LinkedList<>(); + ret.add("gemma"); return ret; } - static List supportSerial1List() { - List ret = new LinkedList<>(); - ret.add("circuitplay32u4cat"); - ret.add("LilyPadUSB"); - ret.add("Micro"); - ret.add("yunMini"); - ret.add("robotControl"); - ret.add("Esplora"); - ret.add("mega"); - ret.add("chiwawa"); - ret.add("yun"); - ret.add("one"); - ret.add("leonardo"); - ret.add("robotMotor"); - ret.add("leonardoEth"); - ret.add("megaADK"); - - return ret; - } - - static List doesNotSupportSerialList() { - List ret = new LinkedList<>(); - ret.add("gemma"); - - return ret; - } - - static List supportKeyboardList() { - List ret = new LinkedList<>(); - ret.add("circuitplay32u4cat"); - ret.add("LilyPadUSB"); - ret.add("Micro"); - ret.add("yunMini"); - ret.add("robotControl"); - ret.add("Esplora"); - ret.add("chiwawa"); - ret.add("yun"); - // mySupportKeyboardList.add("one"); - // mySupportKeyboardList.add("Leonardo"); - // mySupportKeyboardList.add("robotMotor"); - // mySupportKeyboardList.add("LeonardoEth"); - // mySupportKeyboardList.add("MegaADK"); - - return ret; - } - public static void installLatestAVRBoards() { - PackageManager.installLatestPlatform(jsonFileName,providerArduino, AVRArchitectureName); - } + protected static List doesNotSupportSerialUSBList() { + List ret = new LinkedList<>(); + ret.addAll(mbedBoards); + return ret; + } + + private static List doesNotSupportDirectModeList() { + List ret = new LinkedList<>(); + ret.addAll(mbedBoards); + return ret; + } + + private static List doesNotSupportTone() { + List ret = new LinkedList<>(); + ret.add("arduino_due_x"); + ret.add("arduino_due_x_dbg"); + + return ret; + } + + private static List supportKeyboardList() { + List ret = new LinkedList<>(); + ret.add("circuitplay32u4cat"); + ret.add("LilyPadUSB"); + ret.add("Micro"); + ret.add("yunMini"); + ret.add("robotControl"); + ret.add("Esplora"); + ret.add("chiwawa"); + ret.add("yun"); + return ret; + } + + public static void installLatestAVRBoards() { + BoardsManager.installLatestPlatform(jsonFileName, providerArduino, AVRArchitectureName); + } public static void installLatestSamDBoards() { - PackageManager.installLatestPlatform(jsonFileName, providerArduino, SAMDArchitectureName); + BoardsManager.installLatestPlatform(jsonFileName, providerArduino, SAMDArchitectureName); } public static void installLatestSamBoards() { - PackageManager.installLatestPlatform(jsonFileName, providerArduino, SAMArchitectureName); + BoardsManager.installLatestPlatform(jsonFileName, providerArduino, SAMArchitectureName); } public static void installLatestIntellCurieBoards() { - PackageManager.installLatestPlatform(jsonFileName, providerIntel, intelCurieArchitectureName); - } - - public static MCUBoard[] getAllBoards() { - // TODO - // hardcode this stuff now because I want to release 4.3.1 - //shoulds be something like - //return PackageManager.getAllBoardDescriptors(getJsonFileName(),getPackageName(),getPlatformName() , options); - MCUBoard[] boards = { Arduino.uno(), - Arduino.leonardo(), - Arduino.esplora(), - Arduino.yun(), - Arduino.getAvrBoard("diecimila"), - Arduino.getMega2560Board(), - Arduino.MegaADK(), - Arduino.getAvrBoard("leonardoeth"), - Arduino.getAvrBoard("micro"), - Arduino.getAvrBoard("mini"), - Arduino.getAvrBoard("ethernet"), - Arduino.getAvrBoard("fio"), - Arduino.getAvrBoard("bt"), - Arduino.getAvrBoard("LilyPadUSB"), - Arduino.getAvrBoard("lilypad"), - Arduino.getAvrBoard("pro"), - Arduino.getAvrBoard("atmegang"), - Arduino.getAvrBoard("robotControl"), - Arduino.getAvrBoard("robotMotor"), - Arduino.getAvrBoard("gemma"), - Arduino.adafruitnCirquitPlayground(), - Arduino.getAvrBoard("yunmini"), - Arduino.getAvrBoard("chiwawa"), - Arduino.getAvrBoard("one"), - Arduino.getAvrBoard("unowifi"), }; - return boards; - - } - public static MCUBoard zeroNatviePort() { - MCUBoard zero = new Arduino(providerArduino, SAMDArchitectureName, "arduino_zero_native"); - zero.mySlangName="zero Native"; - zero.mySerialPort="SerialUSB"; - return zero; - } - - - public static MCUBoard zeroNatviePort(String uploadPort) { - MCUBoard zero = zeroNatviePort(); - zero.myBoardDescriptor.setUploadPort(uploadPort); - return zero; - } - - - - -} \ No newline at end of file + BoardsManager.installLatestPlatform(jsonFileName, providerIntel, intelCurieArchitectureName); + } + + public static List getAllBoards() { + return getAllBoards(providerArduino, uno()); + } + + private static List getAllmBedBoardNames() { + List ret = new LinkedList<>(); + ArduinoPackage arduinoPkg = BoardsManager.getPackageByProvider(providerArduino); + for (ArduinoPlatform curPlatform : arduinoPkg.getPlatforms()) { + if (curPlatform.getArchitecture().equals(MBEDArchitectureName)) { + ArduinoPlatformVersion curPlatformVersion = curPlatform.getNewestInstalled(); + if (curPlatformVersion != null) { + List boardDescriptions = BoardDescription + .makeBoardDescriptors(curPlatformVersion.getBoardsFile()); + for (BoardDescription curBoardDesc : boardDescriptions) { + ret.add(curBoardDesc.getBoardName()); + } + } + } + } + return ret; + } + +} diff --git a/io.sloeber.tests/src/io/sloeber/providers/ESP32.java b/io.sloeber.tests/src/io/sloeber/providers/ESP32.java index 67104b8c9..783e23a6a 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/ESP32.java +++ b/io.sloeber.tests/src/io/sloeber/providers/ESP32.java @@ -5,40 +5,55 @@ import java.util.Map; import java.util.TreeMap; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; @SuppressWarnings("nls") public class ESP32 extends MCUBoard { - private static final String provider = "esp32"; + private static final String provider = "esp32"; private static final String architectureName = "esp32"; - private static final String jsonFileName ="package_esp32_index.json"; - public static final String packageURL ="https://dl.espressif.com/dl/package_esp32_index.json"; - public static final String esp32ID ="esp32"; - - - public static MCUBoard esp32() { - Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); -// options.put("CpuFrequency", "80"); -// options.put("UploadSpeed", "115200"); -// options.put("FlashSize", "4M1M"); - ESP32 ret= new ESP32(esp32ID, options); - // ret.mySlangName="wemos"; - return ret; - } - - - - public ESP32(String boardName, Map options) { - this.myBoardDescriptor = PackageManager.getBoardDescription(jsonFileName, provider, architectureName, - boardName, options); - if (this.myBoardDescriptor == null) { - fail(boardName + " Board not found"); - } - - } - - public static void installLatest() { - PackageManager.installLatestPlatform(jsonFileName,provider, architectureName); - } + private static final String jsonFileName = "package_esp32_index.json"; + public static final String packageURL = "https://dl.espressif.com/dl/package_esp32_index.json"; + public static final String esp32ID = "esp32"; + + public static MCUBoard esp32() { + Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + // options.put("CpuFrequency", "80"); + // options.put("UploadSpeed", "115200"); + // options.put("FlashSize", "4M1M"); + ESP32 ret = new ESP32(esp32ID, options); + // ret.mySlangName="wemos"; + return ret; + } + + public ESP32(String boardName, Map options) { + myBoardDescriptor = BoardsManager.getBoardDescription(jsonFileName, provider, architectureName, boardName, + options); + if (myBoardDescriptor == null) { + fail(boardName + " Board not found"); + } + setAttributes(); + } + + public ESP32(BoardDescription boardDesc) { + myBoardDescriptor = boardDesc; + myBoardDescriptor.setUploadPort("none"); + setAttributes(); + } + + public static void installLatest() { + BoardsManager.installLatestPlatform(jsonFileName, provider, architectureName); + } + + @Override + protected void setAttributes() { + // nothing to set + + } + + @Override + public MCUBoard createMCUBoard(BoardDescription boardDesc) { + return new ESP32(boardDesc); + } } \ No newline at end of file diff --git a/io.sloeber.tests/src/io/sloeber/providers/ESP8266.java b/io.sloeber.tests/src/io/sloeber/providers/ESP8266.java index aecb2d28e..adb114acc 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/ESP8266.java +++ b/io.sloeber.tests/src/io/sloeber/providers/ESP8266.java @@ -1,64 +1,65 @@ package io.sloeber.providers; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.util.Map; import java.util.TreeMap; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; @SuppressWarnings("nls") public class ESP8266 extends MCUBoard { - private static final String provider = "esp8266"; - private static final String architectureName = "esp8266"; - private static final String jsonFileName ="package_esp8266com_index.json"; - public static final String packageURL ="http://arduino.esp8266.com/stable/package_esp8266com_index.json"; + private static final String provider = "esp8266"; + private static final String architectureName = "esp8266"; + private static final String jsonFileName = "package_esp8266com_index.json"; + public static final String packageURL = "http://arduino.esp8266.com/stable/package_esp8266com_index.json"; - + public static MCUBoard wemosD1() { + Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + options.put("CpuFrequency", "80"); + options.put("UploadSpeed", "115200"); + options.put("FlashSize", "4M1M"); + return new ESP8266("d1_mini", options); + } - public static MCUBoard wemosD1() { - Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - options.put("CpuFrequency", "80"); - options.put("UploadSpeed", "115200"); - options.put("FlashSize", "4M1M"); - ESP8266 ret= new ESP8266("d1_mini", options); - ret.mySlangName="wemos"; - return ret; - } + public static MCUBoard nodeMCU() { + return new ESP8266("nodemcu", null); + } - public static MCUBoard wemosD1(String uploadPort) { - MCUBoard board = wemosD1(); - board.myBoardDescriptor.setUploadPort(uploadPort); - return board; - } + public static MCUBoard ESPressoLite() { + return new ESP8266("espresso_lite_v2", null); + } + public ESP8266(String boardName, Map options) { + this.myBoardDescriptor = BoardsManager.getBoardDescription(jsonFileName, provider, architectureName, boardName, + options); + if (this.myBoardDescriptor == null) { + fail(boardName + " Board not found"); + } - public static MCUBoard nodeMCU() { - return new ESP8266("nodemcu", null); - } + } - public static MCUBoard NodeMCUBoard(String uploadPort) { - MCUBoard board = wemosD1(); - board.myBoardDescriptor.setUploadPort(uploadPort); - return board; - } + public ESP8266(BoardDescription boardDesc) { + myBoardDescriptor = boardDesc; + myBoardDescriptor.setUploadPort("none"); + setAttributes(); + } - public static MCUBoard ESPressoLite() { - return new ESP8266("espresso_lite_v2", null); - } + public static void installLatest() { + BoardsManager.installLatestPlatform(jsonFileName, provider, architectureName); + } + @Override + protected void setAttributes() { + // No attributes to set - public ESP8266(String boardName, Map options) { - this.myBoardDescriptor = PackageManager.getBoardDescription(jsonFileName, provider, architectureName, - boardName, options); - if (this.myBoardDescriptor == null) { - fail(boardName + " Board not found"); - } + } - } - - public static void installLatest() { - PackageManager.installLatestPlatform(jsonFileName,provider, architectureName); - } + @Override + public MCUBoard createMCUBoard(BoardDescription boardDesc) { + // TODO Auto-generated method stub + return new ESP8266(boardDesc); + } } \ No newline at end of file diff --git a/io.sloeber.tests/src/io/sloeber/providers/Jantje.java b/io.sloeber.tests/src/io/sloeber/providers/Jantje.java index a7e49e8d1..ca1ac6077 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/Jantje.java +++ b/io.sloeber.tests/src/io/sloeber/providers/Jantje.java @@ -3,40 +3,26 @@ import static org.junit.Assert.*; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.TreeMap; -import io.sloeber.core.Examples; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.Example; +import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; @SuppressWarnings("nls") public class Jantje extends MCUBoard { - private static final String provider = "Jantje"; - private static final String packageName = "Jantje"; + private static final String provider = "Jantje"; + private static final String packageName = "Jantje"; private static final String localDebugArchitectureName = "pc"; - private static final String jsonFileName ="package_jantje_index.json"; - // TODO check the line below as it seems wrong - public static final String jsonURL ="http://arduino.esp8266.com/stable/package_esp8266com_index.json"; + private static final String jsonFileName = "package_jantje_index.json"; + // the below json url is need as esp8266 is a referenced platform + public static final String additionalJsonURL = "http://arduino.esp8266.com/stable/package_esp8266com_index.json"; - - - public Jantje(String boardName) { - Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - options.put("type", "debug"); - this.myBoardDescriptor = PackageManager.getBoardDescription(jsonFileName,packageName,localDebugArchitectureName , - boardName, options); - if (this.myBoardDescriptor == null) { - fail(boardName + " Board not found"); - } - this.myBoardDescriptor.setUploadPort("none"); - - myAttributes.serial=!Arduino.doesNotSupportSerialList().contains(boardName); - myAttributes.serial1=Arduino.supportSerial1List().contains(boardName); - myAttributes.keyboard=Arduino.supportKeyboardList().contains(boardName); - } @Override - public boolean isExampleSupported(Examples example) { + public boolean isExampleSupported(Example example) { LinkedList notSupportedExamples = new LinkedList<>(); notSupportedExamples.add("Example/09.USB/Keyboard/KeyboardLogout"); notSupportedExamples.add("Example/09.USB/Keyboard/KeyboardMessage"); @@ -46,25 +32,48 @@ public boolean isExampleSupported(Examples example) { notSupportedExamples.add("Example/09.USB/Mouse/ButtonMouseControl"); notSupportedExamples.add("Example/09.USB/Mouse/JoystickMouseControl"); notSupportedExamples.add("Example/10.StarterKit_BasicKit/p13_TouchSensorLamp"); - if( notSupportedExamples.contains(example.getFQN())) { - return false; - } + if (notSupportedExamples.contains(example.getFQN())) { + return false; + } return super.isExampleSupported(example); } - public static MCUBoard[] getAllBoards() { - // TOFIX hardcode this stuff now because I want to release 4.3.1 - //shoulds be something like - //return PackageManager.getAllBoardDescriptors(getJsonFileName(),getPackageName(),getPlatformName() , options); - MCUBoard[] boards = { new Jantje("yun"),new Jantje("uno"),new Jantje("diecimila"),new Jantje("nano"),new Jantje("mega"),new Jantje("megaADK"),new Jantje("leonardo"),new Jantje("micro"), - new Jantje("esplora"),new Jantje("mini"),new Jantje("ethernet"),new Jantje("fio"),new Jantje("bt"),new Jantje("LilyPadUSB"),new Jantje("lilypad"),new Jantje("pro"), - new Jantje("atmegang"),new Jantje("robotControl") }; - return boards; + public static List getAllBoards() { + return getAllBoards(provider, Arduino.uno()); + } + + @Override + public MCUBoard createMCUBoard(BoardDescription boardDescriptor) { + return new Jantje(boardDescriptor); + + } + + public Jantje(BoardDescription boardDescriptor) { + myBoardDescriptor = boardDescriptor; + setAttributes(); + } + + public Jantje(String boardName) { + Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + options.put("type", "debug"); + myBoardDescriptor = BoardsManager.getBoardDescription(jsonFileName, packageName, localDebugArchitectureName, + boardName, options); + if (myBoardDescriptor == null) { + fail(boardName + " Board not found"); + } + setAttributes(); + } + + public static void installLatestLocalDebugBoards() { + BoardsManager.installLatestPlatform(jsonFileName, provider, localDebugArchitectureName); } - - public static void installLatestLocalDebugBoards() { - PackageManager.installLatestPlatform(jsonFileName,provider, localDebugArchitectureName); - } + @Override + protected void setAttributes() { + String boardID = myBoardDescriptor.getBoardID(); + Arduino.sharedsetAttributes(boardID, myAttributes); + setUploadPort("none"); + + } } diff --git a/io.sloeber.tests/src/io/sloeber/providers/MCUBoard.java b/io.sloeber.tests/src/io/sloeber/providers/MCUBoard.java index 6904088e2..99a09450e 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/MCUBoard.java +++ b/io.sloeber.tests/src/io/sloeber/providers/MCUBoard.java @@ -1,79 +1,103 @@ package io.sloeber.providers; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.TreeMap; import io.sloeber.core.BoardAttributes; -import io.sloeber.core.Examples; +import io.sloeber.core.Example; import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; +import io.sloeber.core.api.Json.ArduinoPackage; +import io.sloeber.core.api.Json.ArduinoPlatform; +import io.sloeber.core.api.Json.ArduinoPlatformVersion; @SuppressWarnings("nls") -public class MCUBoard { - - protected BoardDescription myBoardDescriptor = null; - public BoardAttributes myAttributes=new BoardAttributes(); - public String mySlangName; - public String mySerialPort="Serial"; - - - public BoardDescription getBoardDescriptor() { - return myBoardDescriptor; - } - - - public boolean isExampleSupported(Examples example) { - if (myBoardDescriptor == null) { - return false; - } - - - /* - * There is one know Teensy example that does not - * run on all teensy boards - */ - if ("Teensy".equalsIgnoreCase(getID())) { - if (example.getFQN().contains("Teensy/USB_Mouse/Buttons")) { - String boardID = myBoardDescriptor.getBoardID(); - if ("teensypp2".equals(boardID) || "teensy2".equals(boardID)) { - return false; - } - } - } - myAttributes.boardName=myBoardDescriptor.getBoardID(); - return myAttributes.compatibleWithExampleRequirements(example.getRequiredBoardAttributes()); - } - -/** - * give the name of the board as it appears in boards.txt - * @return the name of the board as shown in the gui - */ - public String getID() { - if (myBoardDescriptor == null) { - return null; - } - return myBoardDescriptor.getBoardID(); - } - - - /** - * give the name of the board as it is generally known - * For instance the board "Arduino genuino uno" is uno - * or zero programming port is zero - * - * @return the name of the board as commonly used - */ - public String getSlangName() { - if (mySlangName != null) { - return mySlangName; - } - return getID(); - } - - @SuppressWarnings({ "static-method" }) - public Map getBoardOptions(Examples example) { - Map ret = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - return ret; - } - +public abstract class MCUBoard { + + protected BoardDescription myBoardDescriptor = null; + public BoardAttributes myAttributes = new BoardAttributes(); + public String mySerialPort = "Serial"; + + public abstract MCUBoard createMCUBoard(BoardDescription boardDesc); + + protected abstract void setAttributes(); + + public static List getAllBoards(String provider, MCUBoard creator) { + List ret = new LinkedList<>(); + ArduinoPackage arduinoPkg = BoardsManager.getPackageByProvider(provider); + for (ArduinoPlatform curPlatform : arduinoPkg.getPlatforms()) { + ArduinoPlatformVersion curPlatformVersion = curPlatform.getNewestInstalled(); + if (curPlatformVersion != null) { + List boardDescriptions = BoardDescription + .makeBoardDescriptors(curPlatformVersion.getBoardsFile()); + for (BoardDescription curBoardDesc : boardDescriptions) { + ret.add(creator.createMCUBoard(curBoardDesc)); + } + } + } + return ret; + } + + public BoardDescription getBoardDescriptor() { + return myBoardDescriptor; + } + + public boolean isExampleSupported(Example example) { + if (myBoardDescriptor == null) { + return false; + } + /* + * There is one know Teensy example that does not + * run on all teensy boards + */ + if ("Teensy".equalsIgnoreCase(getID())) { + if (example.getFQN().contains("Teensy/USB_Mouse/Buttons")) { + String boardID = myBoardDescriptor.getBoardID(); + if ("teensypp2".equals(boardID) || "teensy2".equals(boardID)) { + return false; + } + } + } + myAttributes.boardName = myBoardDescriptor.getBoardID(); + return myAttributes.compatibleWithExampleRequirements(example.getRequiredBoardAttributes()); + } + + /** + * give the name of the board as it appears in boards.txt + * + * @return the name of the board as shown in the gui + */ + public String getID() { + if (myBoardDescriptor == null) { + return null; + } + return myBoardDescriptor.getBoardID(); + } + + @SuppressWarnings({ "static-method" }) + public Map getBoardOptions(Example example) { + Map ret = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + return ret; + } + + /** + * give the name of the board as it appears in boards.txt + * + * @return the name of the board as shown in the gui or null + */ + public String getName() { + if (myBoardDescriptor == null) { + return null; + } + return myBoardDescriptor.getBoardName(); + } + + public MCUBoard setUploadPort(String uploadPort) { + myBoardDescriptor.setUploadPort(uploadPort); + return this; + + } } \ No newline at end of file diff --git a/io.sloeber.tests/src/io/sloeber/providers/Teensy.java b/io.sloeber.tests/src/io/sloeber/providers/Teensy.java index d2778f1dc..cdf0fb13a 100644 --- a/io.sloeber.tests/src/io/sloeber/providers/Teensy.java +++ b/io.sloeber.tests/src/io/sloeber/providers/Teensy.java @@ -3,151 +3,146 @@ import static io.sloeber.core.common.Const.*; import static org.junit.Assert.*; +import java.util.List; import java.util.Map; import java.util.TreeMap; import io.sloeber.core.BoardAttributes; -import io.sloeber.core.Examples; +import io.sloeber.core.Example; import io.sloeber.core.MySystem; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardDescription; +import io.sloeber.core.api.BoardsManager; @SuppressWarnings("nls") public class Teensy extends MCUBoard { - public final static String Teensy3_0_ID = "teensy30"; - public final static String Teensy3_1_ID = "teensy31"; - public final static String Teensy_PP2_ID = "teensypp2"; - public final static String Teensy_2_ID = "teensy2"; - public final static String Teensy3_5_ID = "teensy35"; - public final static String Teensy3_6_ID = "teensy36"; - public final static String Teensy_LC_ID = "teensyLC"; - - public static MCUBoard Teensy_LC() { - return new Teensy(Teensy_LC_ID); - } - - public static MCUBoard Teensy3_5() { - return new Teensy(Teensy3_5_ID); - } - - public static MCUBoard Teensy3_6() { - MCUBoard board = new Teensy(Teensy3_6_ID); - board.mySlangName="teensy3"; - return board; - } - - public static MCUBoard Teensy3_1() { - return new Teensy(Teensy3_1_ID); - } - public static MCUBoard Teensy3_1(String uploadPort) { - MCUBoard board = Teensy3_1(); - board.myBoardDescriptor.setUploadPort(uploadPort); - return board; - } - - public static MCUBoard Teensy3_0() { - return new Teensy(Teensy3_0_ID); - } - - public static MCUBoard teensypp2() { - return new Teensy(Teensy_PP2_ID); - } - public static MCUBoard teensypp2(String uploadPort) { - MCUBoard board = teensypp2(); - board.myBoardDescriptor.setUploadPort(uploadPort); - return board; - } - - public static MCUBoard teensy2() { - return new Teensy(Teensy_2_ID); - } - - private Teensy(String boardName) { - Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - options.put("usb", "serialhid"); - options.put("speed", "48"); - options.put("opt", "o2std"); - options.put("keys", "en-us"); - switch (boardName) { - case Teensy_PP2_ID: - options.put("speed", "8"); - break; - case Teensy_2_ID: - options.put("speed", "8"); - break; - case Teensy3_1_ID: - options.put("speed", "72"); - break; - default: - break; - } - - this.myBoardDescriptor = PackageManager.getBoardDescription(LOCAL, MySystem.getTeensyBoard_txt(), - "ignored", - boardName, options); - if (this.myBoardDescriptor == null) { - fail(boardName + " Board not found"); - } - this.myBoardDescriptor.setUploadPort("none"); - - myAttributes.serial = true; - myAttributes.serial1 = true; - myAttributes.keyboard = true; - myAttributes.joyStick = true; - myAttributes.mouse = true; - myAttributes.flightSim = true; - myAttributes.midi = true; - myAttributes.wire1 = true; - myAttributes.teensy = true; - } - - - - /* - * For teensy any menu option is ok except for menu.usb There the main options - * are: serial keyboard touch hidtouch hid serialhid midi serialmidi audio - * serialmidiaudio rawhid flightsim flightsimjoystick everything disable - * unfortunately not all boards support the everything option - * - * @see - * io.sloeber.core.boards.MCUBoard#getBoardOptions(io.sloeber.core.Examples) - */ - @Override - public Map getBoardOptions(Examples example) { - Map ret = super.getBoardOptions(example); - switch (myBoardDescriptor.getBoardID()) { - case Teensy3_5_ID: - case Teensy3_6_ID: - ret.put("usb", "everything"); - break; - default: - BoardAttributes attribs = example.getRequiredBoardAttributes(); - if (attribs.flightSim) { - ret.put("usb", "flightsim"); - } - if (attribs.mouse || attribs.keyboard || attribs.serial || attribs.joyStick) { - ret.put("usb", "serialhid"); - } - if (attribs.midi) { - ret.put("usb", "serialmidiaudio"); - } - if (attribs.rawHID) { - ret.put("usb", "rawhid"); - } - } - return ret; - } - - public static MCUBoard[] getAllBoards() { - // TOFIX hardcode this stuff now because I want to release 4.3.1 - // shoulds be something like - // return - // PackageManager.getAllBoardDescriptors(getJsonFileName(),getPackageName(),getPlatformName() - // , options); - MCUBoard[] boards = { Teensy.Teensy3_6(), Teensy.Teensy3_5(), Teensy.Teensy3_1(), Teensy.Teensy3_0(), - Teensy.Teensy_LC(), Teensy.teensypp2(), Teensy.teensy2() }; - return boards; + public final static String Teensy3_0_ID = "teensy30"; + public final static String Teensy3_1_ID = "teensy31"; + public final static String Teensy_PP2_ID = "teensypp2"; + public final static String Teensy_2_ID = "teensy2"; + public final static String Teensy3_5_ID = "teensy35"; + public final static String Teensy3_6_ID = "teensy36"; + public final static String Teensy_LC_ID = "teensyLC"; + public static MCUBoard Teensy_LC() { + return new Teensy(Teensy_LC_ID); + } + + public static MCUBoard Teensy3_5() { + return new Teensy(Teensy3_5_ID); + } + + public static MCUBoard Teensy3_6() { + return new Teensy(Teensy3_6_ID); + } + + public static MCUBoard Teensy3_1() { + return new Teensy(Teensy3_1_ID); + } + + public static MCUBoard Teensy3_0() { + return new Teensy(Teensy3_0_ID); + } + + public static MCUBoard teensypp2() { + return new Teensy(Teensy_PP2_ID); + } + + public static MCUBoard teensy2() { + return new Teensy(Teensy_2_ID); + } + + private Teensy(String boardName) { + Map options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + options.put("usb", "serialhid"); + options.put("speed", "48"); + options.put("opt", "o2std"); + options.put("keys", "en-us"); + switch (boardName) { + case Teensy_PP2_ID: + options.put("speed", "8"); + break; + case Teensy_2_ID: + options.put("speed", "8"); + break; + case Teensy3_1_ID: + options.put("speed", "72"); + break; + default: + break; + } + + myBoardDescriptor = BoardsManager.getBoardDescription(LOCAL, MySystem.getTeensyBoard_txt(), "ignored", + boardName, options); + if (myBoardDescriptor == null) { + fail(boardName + " Board not found"); + } + setUploadPort("none"); + setAttributes(); + } + + /* + * For teensy any menu option is ok except for menu.usb There the main options + * are: serial keyboard touch hidtouch hid serialhid midi serialmidi audio + * serialmidiaudio rawhid flightsim flightsimjoystick everything disable + * unfortunately not all boards support the everything option + * + * @see + * io.sloeber.core.boards.MCUBoard#getBoardOptions(io.sloeber.core.Examples) + */ + @Override + public Map getBoardOptions(Example example) { + Map ret = super.getBoardOptions(example); + switch (myBoardDescriptor.getBoardID()) { + case Teensy3_5_ID: + case Teensy3_6_ID: + ret.put("usb", "everything"); + break; + default: + BoardAttributes attribs = example.getRequiredBoardAttributes(); + if (attribs.flightSim) { + ret.put("usb", "flightsim"); + } + if (attribs.mouse || attribs.keyboard || attribs.serial || attribs.joyStick) { + ret.put("usb", "serialhid"); + } + if (attribs.midi) { + ret.put("usb", "serialmidiaudio"); + } + if (attribs.rawHID) { + ret.put("usb", "rawhid"); + } + } + return ret; + } + + public static List getAllBoards() { + return getAllBoards(MySystem.getTeensyPlatform(), teensy2()); + } + + @Override + public MCUBoard createMCUBoard(BoardDescription boardDescriptor) { + return new Teensy(boardDescriptor); + + } + + public Teensy(BoardDescription boardDescriptor) { + myBoardDescriptor = boardDescriptor; + myBoardDescriptor.setUploadPort("none"); + setAttributes(); + + } + @Override + protected void setAttributes() { + myAttributes.flightSim = true; + myAttributes.joyStick = true; + myAttributes.keyboard = true; + myAttributes.midi = true; + myAttributes.mouse = true; + myAttributes.serial = true; + myAttributes.serial1 = true; + myAttributes.teensy = true; + myAttributes.wire1 = true; } } \ No newline at end of file diff --git a/io.sloeber.ui/src/io/sloeber/ui/actions/AddLibraryAction.java b/io.sloeber.ui/src/io/sloeber/ui/actions/AddLibraryAction.java index c0b693b9d..e6c93fb19 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/actions/AddLibraryAction.java +++ b/io.sloeber.ui/src/io/sloeber/ui/actions/AddLibraryAction.java @@ -15,7 +15,7 @@ import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.wizards.IWizardDescriptor; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.ui.Messages; import io.sloeber.ui.listeners.ProjectExplorerListener; @@ -23,7 +23,7 @@ public class AddLibraryAction extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - if (!PackageManager.isReady()) { + if (!BoardsManager.isReady()) { log(new Status(IStatus.ERROR, PLUGIN_ID, Messages.pleaseWaitForInstallerJob, null)); return null; } diff --git a/io.sloeber.ui/src/io/sloeber/ui/actions/AddSourceFolderAction.java b/io.sloeber.ui/src/io/sloeber/ui/actions/AddSourceFolderAction.java index ee348a4a6..ae5afdec8 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/actions/AddSourceFolderAction.java +++ b/io.sloeber.ui/src/io/sloeber/ui/actions/AddSourceFolderAction.java @@ -15,7 +15,7 @@ import org.eclipse.ui.console.ConsolePlugin; import org.eclipse.ui.wizards.IWizardDescriptor; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.ui.Messages; import io.sloeber.ui.listeners.ProjectExplorerListener; @@ -25,7 +25,7 @@ public class AddSourceFolderAction extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - if (!PackageManager.isReady()) { + if (!BoardsManager.isReady()) { log(new Status(IStatus.ERROR, PLUGIN_ID, Messages.pleaseWaitForInstallerJob, null)); return null; } diff --git a/io.sloeber.ui/src/io/sloeber/ui/actions/BurnBootloaderHandler.java b/io.sloeber.ui/src/io/sloeber/ui/actions/BurnBootloaderHandler.java index 24487344e..e24e11e99 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/actions/BurnBootloaderHandler.java +++ b/io.sloeber.ui/src/io/sloeber/ui/actions/BurnBootloaderHandler.java @@ -9,7 +9,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.SloeberProject; import io.sloeber.ui.Messages; import io.sloeber.ui.listeners.ProjectExplorerListener; @@ -25,7 +25,7 @@ public class BurnBootloaderHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - if (!PackageManager.isReady()) { + if (!BoardsManager.isReady()) { log(new Status(IStatus.ERROR, PLUGIN_ID, Messages.pleaseWaitForInstallerJob, null)); return null; } diff --git a/io.sloeber.ui/src/io/sloeber/ui/actions/NewSketchHandler.java b/io.sloeber.ui/src/io/sloeber/ui/actions/NewSketchHandler.java index 304c2fd77..6b7501865 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/actions/NewSketchHandler.java +++ b/io.sloeber.ui/src/io/sloeber/ui/actions/NewSketchHandler.java @@ -11,7 +11,7 @@ import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.ui.console.ConsolePlugin; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.ui.Messages; import io.sloeber.ui.wizard.newsketch.NewSketchWizard; @@ -19,7 +19,7 @@ public class NewSketchHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - if (!PackageManager.isReady()) { + if (!BoardsManager.isReady()) { log(new Status(IStatus.ERROR, PLUGIN_ID, Messages.pleaseWaitForInstallerJob, null)); return null; } diff --git a/io.sloeber.ui/src/io/sloeber/ui/actions/ProgramProjectHandler.java b/io.sloeber.ui/src/io/sloeber/ui/actions/ProgramProjectHandler.java index b05554bb1..2021c2c59 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/actions/ProgramProjectHandler.java +++ b/io.sloeber.ui/src/io/sloeber/ui/actions/ProgramProjectHandler.java @@ -11,7 +11,7 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.ui.PlatformUI; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.ui.Messages; import io.sloeber.ui.listeners.ProjectExplorerListener; @@ -26,7 +26,7 @@ public class ProgramProjectHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - if (!PackageManager.isReady()) { + if (!BoardsManager.isReady()) { log(new Status(IStatus.ERROR, PLUGIN_ID, Messages.pleaseWaitForInstallerJob, null)); return null; } diff --git a/io.sloeber.ui/src/io/sloeber/ui/actions/UploadProjectHandler.java b/io.sloeber.ui/src/io/sloeber/ui/actions/UploadProjectHandler.java index 920dcd71f..a60e798e7 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/actions/UploadProjectHandler.java +++ b/io.sloeber.ui/src/io/sloeber/ui/actions/UploadProjectHandler.java @@ -22,7 +22,7 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.SloeberProject; import io.sloeber.ui.Messages; import io.sloeber.ui.helpers.MyPreferences; @@ -123,7 +123,7 @@ public class UploadProjectHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { - if (!PackageManager.isReady()) { + if (!BoardsManager.isReady()) { log(new Status(IStatus.ERROR, PLUGIN_ID, Messages.pleaseWaitForInstallerJob, null)); return null; } 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 02d53518b..46e549201 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java +++ b/io.sloeber.ui/src/io/sloeber/ui/listeners/MyLibraryInstallHandler.java @@ -3,7 +3,7 @@ import java.util.Map; import io.sloeber.core.api.IInstallLibraryHandler; -import io.sloeber.core.api.LibraryDescriptor; +import io.sloeber.core.api.Json.ArduinoLibraryVersion; import io.sloeber.ui.helpers.MyPreferences; public class MyLibraryInstallHandler 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.ui/src/io/sloeber/ui/preferences/LibrarySelectionPage.java b/io.sloeber.ui/src/io/sloeber/ui/preferences/LibrarySelectionPage.java index 29140c37b..47bc58d09 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/preferences/LibrarySelectionPage.java +++ b/io.sloeber.ui/src/io/sloeber/ui/preferences/LibrarySelectionPage.java @@ -2,6 +2,11 @@ import static io.sloeber.ui.Activator.*; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.TreeMap; + import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; @@ -37,10 +42,14 @@ import org.eclipse.ui.dialogs.PatternFilter; import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.LibraryManager.LibraryTree; -import io.sloeber.core.api.Node; import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.api.Json.ArduinoLibrary; +import io.sloeber.core.api.Json.ArduinoLibraryIndex; +import io.sloeber.core.api.Json.ArduinoLibraryVersion; +import io.sloeber.core.api.Json.Node; import io.sloeber.ui.Messages; +import io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Category; +import io.sloeber.ui.preferences.LibrarySelectionPage.LibraryTree.Library; public class LibrarySelectionPage extends PreferencePage implements IWorkbenchPreferencePage { @@ -48,22 +57,208 @@ public class LibrarySelectionPage extends PreferencePage implements IWorkbenchPr private boolean isJobRunning = false; protected TreeViewer viewer; protected TreeEditor editor; - protected LibraryTree libs = LibraryManager.getLibraryTree(); + protected LibraryTree libs = new LibraryTree(); final static String emptyString = ""; //$NON-NLS-1$ + final static String blankLine = "\n\n";//$NON-NLS-1$ + final static String canUpdateLabel = " (can update)"; - @Override - public void init(IWorkbench workbench) { - // nothing needed here + public static class LibraryTree extends Node { + + private TreeMap categories = new TreeMap<>(); + + public class Category extends Node implements Comparable { + private String name; + private TreeMap libraries = new TreeMap<>(); + + public Category(String name) { + this.name = name; + } + + @Override + public String getName() { + return this.name; + } + + public Collection getLibraries() { + return this.libraries.values(); + } + + @Override + public int compareTo(Category other) { + return this.name.compareTo(other.name); + } + + @Override + public boolean hasChildren() { + return !libraries.isEmpty(); + } + + @Override + public Node[] getChildren() { + return libraries.values().toArray(new Node[libraries.size()]); + } + + @Override + public Node getParent() { + return LibraryTree.this; + } + + @Override + public String getID() { + return getName(); + } + } + + public class Library extends Node implements Comparable { + private ArduinoLibrary myLib; + private Category myParent; + protected ArduinoLibraryVersion myToInstallVersion; + protected ArduinoLibraryVersion myInstalledVersion; + + public Library(Category category, ArduinoLibrary lib) { + myParent = category; + myLib = lib; + myInstalledVersion = myLib.getInstalledVersion(); + myToInstallVersion = myInstalledVersion; + } + + public ArduinoLibraryVersion getInstalledVersion() { + return myInstalledVersion; + } + + public Collection getVersions() { + return myLib.getVersions(); + } + + @Override + public String getName() { + if (canUpdate()) { + return myLib.getName() + canUpdateLabel; + } + return myLib.getName(); + } + + public boolean canUpdate() { + return myToInstallVersion == null ? false : getLatest().compareTo(myToInstallVersion) != 0; + } + + private String myTooltip = null; + + public String getTooltip() { + if (myTooltip == null) { + ArduinoLibraryVersion libVers = getLatest(); + myTooltip = "Architectures:" + libVers.getArchitectures().toString() + blankLine + + libVers.getSentence() + blankLine + libVers.getParagraph() + blankLine + "Author: " + + libVers.getAuthor() + blankLine + "Maintainer: " + libVers.getMaintainer() + blankLine + + "provided by: " + libVers.getParent().getParent().getName(); + } + return myTooltip; + } + + public ArduinoLibraryVersion getLatest() { + return myLib.getNewestVersion(); + } + + public ArduinoLibraryVersion getVersion() { + return myToInstallVersion; + } + + public void setVersion(ArduinoLibraryVersion version) { + myToInstallVersion = version; + } + + public void setVersion(VersionNumber versionNumber) { + if (versionNumber == null) { + myToInstallVersion = null; + } + myToInstallVersion = myLib.getVersion(versionNumber); + } + + @Override + public int compareTo(Library other) { + return myLib.compareTo(other.getArduinoLibrary()); + } + + private ArduinoLibrary getArduinoLibrary() { + return myLib; + } + + @Override + public boolean hasChildren() { + return false; + } + + @Override + public Node[] getChildren() { + return null; + } + + @Override + public Node getParent() { + return myParent; + } + + public String getVersionString() { + if (myToInstallVersion == null) { + return emptyString; + } + return myToInstallVersion.getVersion().toString(); + } + + @Override + public String getID() { + return getName(); + } + + } + + public LibraryTree() { + for (ArduinoLibraryIndex libraryIndex : LibraryManager.getLibraryIndices()) { + for (ArduinoLibrary arduinoLibrary : libraryIndex.getLibraries()) { + String categoryName = arduinoLibrary.getCategory(); + Category category = this.categories.get(categoryName); + if (category == null) { + category = new Category(categoryName); + this.categories.put(category.getName(), category); + } + category.libraries.put(arduinoLibrary.getName(), new Library(category, arduinoLibrary)); + } + } + } + + private Collection getCategories() { + return categories.values(); + } + + @Override + public boolean hasChildren() { + return getCategories().isEmpty(); + } + + @Override + public Node[] getChildren() { + return categories.values().toArray(new Node[categories.size()]); + } + + @Override + public Node getParent() { + return null; + } + + @Override + public String getName() { + return null; + } + + @Override + public String getID() { + return null; + } } @Override - protected void performDefaults() { - this.libs.reset(); - this.viewer.refresh(); - if (this.editor != null && this.editor.getEditor() != null) { - this.editor.getEditor().dispose(); - } - super.performDefaults(); + public void init(IWorkbench workbench) { + // nothing needed here } @Override @@ -83,31 +278,44 @@ protected Control createContents(Composite parent) { @Override public boolean performOk() { - if (this.isJobRunning == false) { - this.isJobRunning = true; - Job job = new Job(Messages.ui_Adopting_arduino_libraries) { - @Override - protected IStatus run(IProgressMonitor monitor) { - MultiStatus status = new MultiStatus(PLUGIN_ID, 0, Messages.ui_installing_arduino_libraries, null); - return LibraryManager.setLibraryTree(LibrarySelectionPage.this.libs, monitor, status); + if (this.isJobRunning == true) { + MessageDialog.openInformation(getShell(), "Library Manager", //$NON-NLS-1$ + "Library Manager is busy. Please wait some time..."); //$NON-NLS-1$ + return false; + } + this.isJobRunning = true; + Job job = new Job(Messages.ui_Adopting_arduino_libraries) { + @Override + protected IStatus run(IProgressMonitor monitor) { + MultiStatus status = new MultiStatus(PLUGIN_ID, 0, Messages.ui_installing_arduino_libraries, null); + Set toRemoveLibs = new HashSet<>(); + Set toInstallLibs = new HashSet<>(); + for (Category category : libs.categories.values()) { + for (Library library : category.libraries.values()) { + ArduinoLibraryVersion installedVersion = library.getInstalledVersion(); + ArduinoLibraryVersion toInstalVersion = library.getVersion(); + if ((installedVersion != null) && (installedVersion.compareTo(toInstalVersion) != 0)) { + toRemoveLibs.add(installedVersion); + } + if ((toInstalVersion != null) && (toInstalVersion.compareTo(installedVersion) != 0)) { + toInstallLibs.add(toInstalVersion); + } + } } - }; - job.addJobChangeListener(new JobChangeAdapter() { + return LibraryManager.updateLibraries(toRemoveLibs, toInstallLibs, monitor, status); + } + }; + job.addJobChangeListener(new JobChangeAdapter() { - @Override - public void done(IJobChangeEvent event) { - LibrarySelectionPage.this.isJobRunning = false; - } + @Override + public void done(IJobChangeEvent event) { + LibrarySelectionPage.this.isJobRunning = false; + } - }); - job.setUser(true); - job.schedule(); - return true; - } else { - MessageDialog.openInformation(getShell(), "Library Manager", - "Library Manager is busy. Please wait some time..."); - } - return false; + }); + job.setUser(true); + job.schedule(); + return true; } public void createTree(Composite parent) { @@ -169,43 +377,49 @@ public void widgetSelected(SelectionEvent event) { final TreeItem item = event.item instanceof TreeItem ? (TreeItem) event.item : null; if (item != null && event.detail == SWT.CHECK) { if (item.getData() instanceof LibraryTree.Category) { + Category category = ((LibraryTree.Category) item.getData()); item.setGrayed(false); - for (LibraryTree.Library child : ((LibraryTree.Category) item.getData()).getLibraries()) { + for (LibraryTree.Library child : category.getLibraries()) { if (item.getChecked()) { child.setVersion(child.getLatest()); } else { - child.setVersion(null); + child.setVersion((ArduinoLibraryVersion) null); } } for (TreeItem child : item.getItems()) { child.setChecked(item.getChecked()); + child.setText(1, ((LibraryTree.Library) child.getData()).getVersionString()); + } + } else { + if (item.getData() instanceof LibraryTree.Library) { + Library lib = ((LibraryTree.Library) item.getData()); if (item.getChecked()) { - child.setText(1, ((LibraryTree.Library) child.getData()).getLatest()); + lib.setVersion(lib.getLatest()); } else { - child.setText(1, emptyString); + lib.setVersion((ArduinoLibraryVersion) null); + } + item.setText(0, lib.getName()); + item.setText(1, lib.getVersionString()); + verifySubtreeCheckStatus(item.getParentItem()); } - } else { - if (item.getChecked()) { - ((LibraryTree.Library) item.getData()) - .setVersion(((LibraryTree.Library) item.getData()).getLatest()); - item.setText(1, ((LibraryTree.Library) item.getData()).getLatest()); - } else { - ((LibraryTree.Library) item.getData()).setVersion(null); - item.setText(1, emptyString); - } - verifySubtreeCheckStatus(item.getParentItem()); } } if (item != null && item.getItemCount() == 0 && item.getChecked()) { // Create the dropdown and add data to it final CCombo combo = new CCombo(LibrarySelectionPage.this.viewer.getTree(), SWT.READ_ONLY); - for (VersionNumber version1 : ((LibraryTree.Library) item.getData()).getVersions()) { - combo.add(version1.toString()); + Library selectedLib = ((LibraryTree.Library) item.getData()); + for (ArduinoLibraryVersion version1 : selectedLib.getVersions()) { + combo.add(version1.getVersion().toString()); } - // Select the previously selected item from the cell - combo.select(combo.indexOf(item.getText(1))); + ArduinoLibraryVersion displayVersion = selectedLib.getVersion(); + if (displayVersion == null) { + displayVersion = selectedLib.getLatest(); + selectedLib.setVersion(displayVersion); + item.setText(0, selectedLib.getName()); + } + combo.select(combo.indexOf(displayVersion.getVersion().toString())); // Compute the width for the editor // Also, compute the column width, so that the dropdown fits @@ -219,8 +433,10 @@ public void widgetSelected(SelectionEvent event) { combo.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event1) { - ((LibraryTree.Library) item.getData()).setVersion(combo.getText()); - item.setText(1, combo.getText()); + LibraryTree.Library lib = (LibraryTree.Library) item.getData(); + lib.setVersion(new VersionNumber(combo.getText())); + item.setText(1, lib.getVersionString()); + item.setText(0, lib.getName()); // Item selected: end the editing session combo.dispose(); } @@ -269,13 +485,12 @@ public static String getColumnText(Object element, int col) { switch (col) { case 0: if (element instanceof LibraryTree.Library) { - return ((LibraryTree.Library) element).getName() + " (" //$NON-NLS-1$ - + ((LibraryTree.Library) element).getIndexName() + ")"; //$NON-NLS-1$ + return ((LibraryTree.Library) element).getName(); } return emptyString; case 1: if (element instanceof LibraryTree.Library) { - return ((LibraryTree.Library) element).getVersion(); + return ((LibraryTree.Library) element).getVersionString(); } return emptyString; default: @@ -302,14 +517,9 @@ public int getToolTipTimeDisplayed(Object object) { @Override public void update(ViewerCell cell) { if (cell.getColumnIndex() == 0) { - if (cell.getElement() instanceof LibraryTree.Library) { - cell.setText(((LibraryTree.Library) cell.getElement()).getName() + " (" //$NON-NLS-1$ - + ((LibraryTree.Library) cell.getElement()).getIndexName() + ")"); //$NON-NLS-1$ - } else { - cell.setText(((Node) cell.getElement()).getName()); - } + cell.setText(((Node) cell.getElement()).getName()); } else if (cell.getElement() instanceof LibraryTree.Library) { - cell.setText(((LibraryTree.Library) cell.getElement()).getVersion()); + cell.setText(((LibraryTree.Library) cell.getElement()).getVersionString()); } else { cell.setText(null); } @@ -361,25 +571,16 @@ public Object[] getChildren(Object node) { @Override public Object getParent(Object node) { - if (node instanceof Node) { - return ((Node) node).getParent(); - } - return null; + return ((Node) node).getParent(); } @Override public boolean hasChildren(Object node) { - if (node instanceof LibraryTree) { - return !((LibraryTree) node).getCategories().isEmpty(); - } return ((Node) node).hasChildren(); } @Override public Object[] getElements(Object node) { - if (node instanceof LibraryTree) { - return ((LibraryTree) node).getCategories().toArray(); - } return getChildren(node); } diff --git a/io.sloeber.ui/src/io/sloeber/ui/preferences/PlatformSelectionPage.java b/io.sloeber.ui/src/io/sloeber/ui/preferences/PlatformSelectionPage.java index eb95f111c..6b7eb8c1d 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/preferences/PlatformSelectionPage.java +++ b/io.sloeber.ui/src/io/sloeber/ui/preferences/PlatformSelectionPage.java @@ -3,11 +3,12 @@ import static io.sloeber.ui.Activator.*; -import java.net.URL; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Set; +import java.util.LinkedList; +import java.util.List; +import java.util.TreeMap; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -38,22 +39,124 @@ import org.eclipse.ui.dialogs.FilteredTree; import org.eclipse.ui.dialogs.PatternFilter; -import io.sloeber.core.api.PackageManager; -import io.sloeber.core.api.PackageManager.PlatformTree; -import io.sloeber.core.api.PackageManager.PlatformTree.IndexFile; -import io.sloeber.core.api.PackageManager.PlatformTree.InstallableVersion; -import io.sloeber.core.api.PackageManager.PlatformTree.Package; -import io.sloeber.core.api.PackageManager.PlatformTree.Platform; +import io.sloeber.core.api.BoardsManager; +import io.sloeber.core.api.VersionNumber; +import io.sloeber.core.api.Json.ArduinoPackage; +import io.sloeber.core.api.Json.ArduinoPlatform; +import io.sloeber.core.api.Json.ArduinoPlatformPackageIndex; +import io.sloeber.core.api.Json.ArduinoPlatformVersion; import io.sloeber.ui.Messages; import io.sloeber.ui.helpers.MyPreferences; public class PlatformSelectionPage extends PreferencePage implements IWorkbenchPreferencePage { private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + // platform index json, package,platform,versions structure + private TreeMap>> myShownPlatforms = new TreeMap<>(); + + private boolean mustBeInstalled(ArduinoPlatform platform) { + ArduinoPackage parentPkg = platform.getParent(); + ArduinoPlatformPackageIndex parentIndex = parentPkg.getPackageIndex(); + InstallableVersion[] inScopeVersions = myShownPlatforms.get(parentIndex.getID()).get(parentPkg.getID()) + .get(platform.getID()); + for (InstallableVersion version : inScopeVersions) { + if (version.mustBeInstalled()) { + return true; + } + } + return false; + } + + private boolean mustBeInstalled(ArduinoPlatformPackageIndex packageIndex) { + TreeMap> inScopeVersions = myShownPlatforms + .get(packageIndex.getID()); + for (TreeMap platform : inScopeVersions.values()) { + for (InstallableVersion[] versions : platform.values()) { + for (InstallableVersion version : versions) { + if (version.mustBeInstalled()) { + return true; + } + } + } + } + return false; + } + + private boolean mustBeInstalled(ArduinoPackage pkg) { + ArduinoPlatformPackageIndex parentIndex = pkg.getPackageIndex(); + TreeMap inScopeVersions = myShownPlatforms.get(parentIndex.getID()) + .get(pkg.getID()); + for (InstallableVersion[] versions : inScopeVersions.values()) { + for (InstallableVersion version : versions) { + if (version.mustBeInstalled()) { + return true; + } + } + } + return false; + } + + public static class InstallableVersion implements Comparable { + private ArduinoPlatformVersion myPlatformm; + private boolean myMustBeInstalled; + + public InstallableVersion(ArduinoPlatformVersion platformm) { + myPlatformm = platformm; + myMustBeInstalled = myPlatformm.isInstalled(); + } + + public boolean mustBeInstalled() { + return myMustBeInstalled; + } + + public VersionNumber getVersion() { + return myPlatformm.getVersion(); + } + + public boolean isInstalled() { + return myPlatformm.isInstalled(); + } + + public void setMustBeInstalled(boolean mustBeInstalled) { + this.myMustBeInstalled = mustBeInstalled; + } + + @Override + public int compareTo(InstallableVersion o) { + return getVersion().compareTo(o.getVersion()); + } + + public ArduinoPlatformVersion getPlatform() { + return myPlatformm; + } + + } public PlatformSelectionPage() { + for (ArduinoPlatformPackageIndex curPackageIndex : BoardsManager.getPackageIndices()) { + String pkgIndexID = curPackageIndex.getID(); + TreeMap> packageMap = new TreeMap<>(); + for (ArduinoPackage curPackage : curPackageIndex.getPackages()) { + TreeMap platformMap = new TreeMap<>(); + String pkgID = curPackage.getID(); + for (ArduinoPlatform curPlatform : curPackage.getPlatforms()) { + String platformID = curPlatform.getID(); + Collection platformVersions = curPlatform.getVersions(); + InstallableVersion versions[] = new InstallableVersion[platformVersions.size()]; + int index = 0; + for (ArduinoPlatformVersion curPlatformversion : platformVersions) { + versions[index++] = new InstallableVersion(curPlatformversion); + } +// InstallableVersion arrayVersions[] = versions.toArray(new InstallableVersion[versions.size()]); +// Arrays.sort(arrayVersions, Collections.reverseOrder()); + platformMap.put(platformID, versions); + } + packageMap.put(pkgID, platformMap); + } + myShownPlatforms.put(pkgIndexID, packageMap); + } } - protected PlatformTree myPlatformTree = new PackageManager.PlatformTree(); +// protected PlatformTree myPlatformTree = new PackageManager.PlatformTree(); protected FilteredTree myGuiplatformTree; protected boolean myHideJson = MyPreferences.getHideJson(); protected TreeViewer viewer; @@ -98,42 +201,42 @@ protected boolean isLeafMatch(final Viewer viewer1, final Object element) { isMatch |= myWordMatches(ver.getPlatform()); } - if (element instanceof IndexFile) { - IndexFile indexFile = (IndexFile) element; + if (element instanceof ArduinoPlatformPackageIndex) { + ArduinoPlatformPackageIndex indexFile = (ArduinoPlatformPackageIndex) element; isMatch |= myWordMatches(indexFile); } - if (element instanceof Package) { - Package pac = (Package) element; + if (element instanceof ArduinoPackage) { + ArduinoPackage pac = (ArduinoPackage) element; isMatch |= myWordMatches(pac); } - if (element instanceof Platform) { - Platform platform = (Platform) element; + if (element instanceof ArduinoPlatformVersion) { + ArduinoPlatformVersion platform = (ArduinoPlatformVersion) element; isMatch |= myWordMatches(platform); } return isMatch; } - private boolean myWordMatches(Platform platform) { - boolean ret = wordMatches(platform.getName()); - ret |= wordMatches(platform.getArchitecture()); - ret |= wordMatches(platform.getBoards()); - ret |= myWordMatches(platform.getPackage()); + private boolean myWordMatches(ArduinoPlatformVersion arduinoPlatformVersion) { + boolean ret = wordMatches(arduinoPlatformVersion.getName()); + ret |= wordMatches(arduinoPlatformVersion.getArchitecture()); + ret |= wordMatches(arduinoPlatformVersion.getConcattenatedBoardNames()); + ret |= myWordMatches(arduinoPlatformVersion.getParent().getParent()); return ret; } - private boolean myWordMatches(Package pac) { + private boolean myWordMatches(ArduinoPackage pac) { boolean ret = wordMatches(pac.getEmail()); ret |= wordMatches(pac.getMaintainer()); ret |= wordMatches(pac.getName()); ret |= wordMatches(pac.getWebsiteURL().toString()); - ret |= wordMatches(pac.getIndexFile().toString()); + ret |= wordMatches(pac.getPackageIndex().getJsonFile().toString()); return ret; } - private boolean myWordMatches(IndexFile indexFile) { + private boolean myWordMatches(ArduinoPlatformPackageIndex indexFile) { - return wordMatches(indexFile.getFullName()); + return wordMatches(indexFile.getID()); } }; @@ -148,16 +251,16 @@ protected TreeViewer doCreateTreeViewer(Composite composite, int style) { @Override public boolean isChecked(Object element) { if (element instanceof InstallableVersion) { - return ((InstallableVersion) element).isInstalled(); + return ((InstallableVersion) element).mustBeInstalled(); } - if (element instanceof IndexFile) { - return ((IndexFile) element).isInstalled(); + if (element instanceof ArduinoPlatformPackageIndex) { + return mustBeInstalled((ArduinoPlatformPackageIndex) element); } - if (element instanceof Package) { - return ((Package) element).isInstalled(); + if (element instanceof ArduinoPackage) { + return mustBeInstalled((ArduinoPackage) element); } - if (element instanceof Platform) { - return ((Platform) element).isInstalled(); + if (element instanceof ArduinoPlatform) { + return mustBeInstalled((ArduinoPlatform) element); } return false; } @@ -167,17 +270,18 @@ public boolean isGrayed(Object element) { if (element instanceof InstallableVersion) { return false; } - if (element instanceof IndexFile) { - return ((IndexFile) element).isInstalled(); + if (element instanceof ArduinoPlatformPackageIndex) { + return mustBeInstalled((ArduinoPlatformPackageIndex) element); } - if (element instanceof Package) { - return ((Package) element).isInstalled(); + if (element instanceof ArduinoPackage) { + return mustBeInstalled((ArduinoPackage) element); } - if (element instanceof Platform) { - return ((Platform) element).isInstalled(); + if (element instanceof ArduinoPlatform) { + return mustBeInstalled((ArduinoPlatform) element); } return false; } + }); viewer1.addCheckStateListener(new ICheckStateListener() { @@ -187,7 +291,7 @@ public void checkStateChanged(CheckStateChangedEvent event) { Object element = event.getElement(); if (element instanceof InstallableVersion) { InstallableVersion cur = (InstallableVersion) element; - cur.setInstalled(event.getChecked()); + cur.setMustBeInstalled(event.getChecked()); } PlatformSelectionPage.this.viewer.refresh(); @@ -198,12 +302,12 @@ public void checkStateChanged(CheckStateChangedEvent event) { @Override public Object[] getElements(Object inputElement) { if (PlatformSelectionPage.this.myHideJson) { - Set packages = PlatformSelectionPage.this.myPlatformTree.getAllPackages(); + List packages = BoardsManager.getPackages(); + Collections.sort(packages); return packages.toArray(new Object[packages.size()]); } - Collection indexFiles = PlatformSelectionPage.this.myPlatformTree.getAllIndexFiles(); + List indexFiles = BoardsManager.getPackageIndices(); return indexFiles.toArray(new Object[indexFiles.size()]); - } @Override @@ -218,20 +322,23 @@ public void inputChanged(Viewer viewer11, Object oldInput, Object newInput) { @Override public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IndexFile) { - Collection packages = ((IndexFile) parentElement).getAllPackages(); + if (parentElement instanceof ArduinoPlatformPackageIndex) { + Collection packages = ((ArduinoPlatformPackageIndex) parentElement) + .getPackages(); return packages.toArray(new Object[packages.size()]); } - if (parentElement instanceof Package) { - Collection platforms = ((Package) parentElement).getPlatforms(); - return platforms.toArray(new Object[platforms.size()]); + if (parentElement instanceof ArduinoPackage) { + Collection platforms = ((ArduinoPackage) parentElement).getPlatforms(); + ArduinoPlatform platformArray[] = platforms.toArray(new ArduinoPlatform[platforms.size()]); + Arrays.sort(platformArray); + return platformArray; } - if (parentElement instanceof Platform) { - Collection versions = ((Platform) parentElement).getVersions(); - InstallableVersion arrayVersions[] = versions - .toArray(new InstallableVersion[versions.size()]); - Arrays.sort(arrayVersions, Collections.reverseOrder()); - return arrayVersions; + if (parentElement instanceof ArduinoPlatform) { + ArduinoPlatform platform = (ArduinoPlatform) parentElement; + ArduinoPackage parentPackage = platform.getParent(); + ArduinoPlatformPackageIndex parentIndex = parentPackage.getPackageIndex(); + return myShownPlatforms.get(parentIndex.getID()).get(parentPackage.getID()) + .get(platform.getID()); } return null; @@ -251,30 +358,29 @@ public boolean hasChildren(Object element) { viewer1.setLabelProvider(new CellLabelProvider() { @Override public String getToolTipText(Object element) { - if (element instanceof IndexFile) { - return ((IndexFile) element).getFullName(); + if (element instanceof ArduinoPlatformPackageIndex) { + return ((ArduinoPlatformPackageIndex) element).getID(); } - if (element instanceof Package) { + if (element instanceof ArduinoPackage) { String NULL = "NULL"; //$NON-NLS-1$ - Package pkg = (Package) element; + ArduinoPackage pkg = (ArduinoPackage) element; String maintainer = pkg.getMaintainer(); String email = pkg.getEmail(); - URL weburl = pkg.getWebsiteURL(); - String weburlString = NULL; + String weburlString = pkg.getWebsiteURL(); if (maintainer == null) maintainer = NULL; if (email == null) email = NULL; - if (weburl != null) - weburlString = weburl.toString(); + if (weburlString == null) + weburlString = NULL; return Messages.packageTooltip.replace(Messages.MAINTAINER, maintainer) .replace(Messages.EMAIL, email).replace(Messages.URL, weburlString); } - if (element instanceof Platform) { - return ((Platform) element).getBoards(); + if (element instanceof ArduinoPlatformVersion) { + return ((ArduinoPlatformVersion) element).getConcattenatedBoardNames(); } if (element instanceof InstallableVersion) { @@ -301,16 +407,16 @@ public int getToolTipTimeDisplayed(Object object) { @Override public void update(ViewerCell cell) { - if (cell.getElement() instanceof IndexFile) { - cell.setText(((IndexFile) cell.getElement()).getNiceName()); + if (cell.getElement() instanceof ArduinoPlatformPackageIndex) { + cell.setText(((ArduinoPlatformPackageIndex) cell.getElement()).getName()); } - if (cell.getElement() instanceof Package) { - cell.setText(((Package) cell.getElement()).getName()); + if (cell.getElement() instanceof ArduinoPackage) { + cell.setText(((ArduinoPackage) cell.getElement()).getName()); } - if (cell.getElement() instanceof Platform) { - cell.setText(((Platform) cell.getElement()).getName()); + if (cell.getElement() instanceof ArduinoPlatform) { + cell.setText(((ArduinoPlatform) cell.getElement()).getName()); } if (cell.getElement() instanceof InstallableVersion) { @@ -334,8 +440,26 @@ public void update(ViewerCell cell) { } protected IStatus updateInstallation(IProgressMonitor monitor) { + List platformsToInstall = new LinkedList<>(); + List platformsToRemove = new LinkedList<>(); + for (TreeMap> packageIndex : myShownPlatforms.values()) { + for (TreeMap arduinoPackage : packageIndex.values()) { + for (InstallableVersion[] versions : arduinoPackage.values()) { + for (InstallableVersion version : versions) { + if (version.isInstalled() != version.mustBeInstalled()) { + if (version.mustBeInstalled()) { + platformsToInstall.add(version.getPlatform()); + } else { + platformsToRemove.add(version.getPlatform()); + } + } + } + } + } + } + MultiStatus status = new MultiStatus(PLUGIN_ID, 0, Messages.ui_installing_platforms, null); - PackageManager.setPlatformTree(this.myPlatformTree, monitor, status); + BoardsManager.updatePlatforms(platformsToInstall, platformsToRemove, monitor, status); return status; } 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 f34a06b17..e2e2da656 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java +++ b/io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java @@ -25,7 +25,7 @@ import io.sloeber.core.api.Defaults; import io.sloeber.core.api.LibraryManager; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.Preferences; import io.sloeber.ui.Messages; import io.sloeber.ui.helpers.MyPreferences; @@ -130,7 +130,7 @@ public boolean performOk() { Preferences.setAutoImportLibraries(this.automaticallyImportLibrariesOptionEditor.getBooleanValue()); Preferences.setPragmaOnceHeaders(this.pragmaOnceHeaderOptionEditor.getBooleanValue()); Preferences.setUseBonjour(enableBonjour.getBooleanValue()); - PackageManager.setPrivateHardwarePaths(hardWarePaths); + BoardsManager.setPrivateHardwarePaths(hardWarePaths); LibraryManager.setPrivateLibraryPaths(libraryPaths); return ret; } @@ -142,7 +142,7 @@ public boolean performOk() { * @return null if no filtering is needed else filtered list */ private static String[] filterUnwantedPaths(String[] paths) { - IPath unWanted=PackageManager.getInstallationPath(); + IPath unWanted=BoardsManager.getInstallationPath(); ArrayList filteredList = new ArrayList<>(); boolean filtered=false; for (int i = 0; i < paths.length; i++) { @@ -162,7 +162,7 @@ private static String[] filterUnwantedPaths(String[] paths) { @Override public void init(IWorkbench workbench) { - String hardWarePaths = PackageManager.getPrivateHardwarePathsString(); + String hardWarePaths = BoardsManager.getPrivateHardwarePathsString(); String libraryPaths = LibraryManager.getPrivateLibraryPathsString(); boolean autoImport = Preferences.getAutoImportLibraries(); boolean pragmaOnceHeaders = Preferences.getPragmaOnceHeaders(); diff --git a/io.sloeber.ui/src/io/sloeber/ui/preferences/ThirdPartyHardwareSelectionPage.java b/io.sloeber.ui/src/io/sloeber/ui/preferences/ThirdPartyHardwareSelectionPage.java index 27baf8ee2..569a7116e 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/preferences/ThirdPartyHardwareSelectionPage.java +++ b/io.sloeber.ui/src/io/sloeber/ui/preferences/ThirdPartyHardwareSelectionPage.java @@ -22,7 +22,7 @@ import org.eclipse.ui.forms.widgets.Hyperlink; import org.eclipse.ui.preferences.ScopedPreferenceStore; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.Preferences; import io.sloeber.ui.Messages; import io.sloeber.ui.helpers.MyPreferences; @@ -40,7 +40,7 @@ public ThirdPartyHardwareSelectionPage() { @Override public boolean performOk() { - PackageManager.setJsonURLs(this.urlsText.getText().split(System.lineSeparator())); + BoardsManager.setJsonURLs(this.urlsText.getText().split(System.lineSeparator())); Preferences.setUpdateJsonFiles(this.upDateJsons.getBooleanValue()); return super.performOk(); } @@ -48,12 +48,12 @@ public boolean performOk() { @Override protected void performDefaults() { super.performDefaults(); - this.urlsText.setText(PackageManager.getDefaultJsonURLs()); + this.urlsText.setText(BoardsManager.getDefaultJsonURLs()); } @Override protected void createFieldEditors() { - String selectedJsons[] = PackageManager.getJsonURLList(); + String selectedJsons[] = BoardsManager.getJsonURLList(); final Composite parent = getFieldEditorParent(); // Composite control = new Composite(parent, SWT.NONE); Label title = new Label(parent, SWT.UP); diff --git a/io.sloeber.ui/src/io/sloeber/ui/project/properties/BoardSelectionPage.java b/io.sloeber.ui/src/io/sloeber/ui/project/properties/BoardSelectionPage.java index bde438dec..17ce9bab6 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/project/properties/BoardSelectionPage.java +++ b/io.sloeber.ui/src/io/sloeber/ui/project/properties/BoardSelectionPage.java @@ -27,7 +27,7 @@ import org.eclipse.swt.widgets.Listener; import io.sloeber.core.api.BoardDescription; -import io.sloeber.core.api.PackageManager; +import io.sloeber.core.api.BoardsManager; import io.sloeber.core.api.PasswordManager; import io.sloeber.core.api.SerialManager; import io.sloeber.ui.LabelCombo; @@ -144,7 +144,7 @@ public void draw(Composite parent) { myScrollComposite.setContent(myComposite); - File[] allBoardsFileNames = PackageManager.getAllBoardsFiles(); + File[] allBoardsFileNames = BoardsManager.getAllBoardsFiles(); for (File curBoardFile : allBoardsFileNames) { myAllBoardsFiles.put(tidyUpLength(curBoardFile.toString()), curBoardFile); }