diff --git a/io.sloeber.core/plugin.xml b/io.sloeber.core/plugin.xml index 0c34e3086..4bb277e55 100644 --- a/io.sloeber.core/plugin.xml +++ b/io.sloeber.core/plugin.xml @@ -142,7 +142,6 @@ + sourceContentType="io.sloeber.tool.objcopy.output" + sources="hex"> + name="size info" + outputNames="${ProjName}.size" + outputs="size" + primaryOutput="false"> diff --git a/io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java b/io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java index fcd9a6a97..56cf9d42c 100644 --- a/io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java +++ b/io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java @@ -15,24 +15,26 @@ import org.eclipse.cdt.core.envvar.IContributedEnvironment; import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.settings.model.CSourceEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICExclusionPatternPathEntry; import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.core.settings.model.ICResourceDescription; -import org.eclipse.cdt.core.settings.model.ICSettingEntry; -import org.eclipse.cdt.core.settings.model.ICSourceEntry; +import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.core.IManagedProject; +import org.eclipse.cdt.managedbuilder.core.IProjectType; +import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; +import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; +import org.eclipse.cdt.managedbuilder.core.ManagedCProjectNature; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; @@ -48,997 +50,1016 @@ import io.sloeber.core.managers.InternalPackageManager; import io.sloeber.core.tools.Helpers; import io.sloeber.core.tools.KeyValue; -import io.sloeber.core.tools.Libraries; import io.sloeber.core.tools.Programmers; -import io.sloeber.core.tools.ShouldHaveBeenInCDT; import io.sloeber.core.tools.TxtFile; @SuppressWarnings({ "nls" }) public class BoardDescriptor { - /* - * Some constants - */ - private static final String KEY_LAST_USED_BOARD = "Last used Board"; - private static final String KEY_LAST_USED_UPLOAD_PORT = "Last Used Upload port"; - private static final String KEY_LAST_USED_UPLOAD_PROTOCOL = "last Used upload Protocol"; - private static final String KEY_LAST_USED_BOARDS_FILE = "Last used Boards file"; - private static final String KEY_LAST_USED_BOARD_MENU_OPTIONS = "last used Board custom option selections"; - private static final String ENV_KEY_JANTJE_MENU_SELECTION = Const.ENV_KEY_JANTJE_START + "MENU"; - private static final String ENV_KEY_JANTJE_UPLOAD_PORT = Const.ENV_KEY_JANTJE_START + "COM_PORT"; - private static final String ENV_KEY_JANTJE_BOARD_NAME = Const.ENV_KEY_JANTJE_START + "BOARD_NAME"; - private static final String ENV_KEY_JANTJE_PROJECT_NAME = Const.ENV_KEY_JANTJE_START + "PROJECT_NAME"; - private static final String ENV_KEY_JANTJE_OS = Const.ENV_KEY_JANTJE_START + "OS_NAME"; - private static final String ENV_KEY_JANTJE_WORKSPACE_LOCATION = Const.ENV_KEY_JANTJE_START + "WORKSPACE_LOCATION"; - private static final String ENV_KEY_JANTJE_ECLIPSE_LOCATION = Const.ENV_KEY_JANTJE_START + "ECLIPSE_LOCATION"; - - public static final String ENV_KEY_JANTJE_BOARDS_FILE = Const.ENV_KEY_JANTJE_START + "BOARDS_FILE"; - - public static final String ENV_KEY_JANTJE_PACKAGE_ID = Const.ENV_KEY_JANTJE_START + "PACKAGE_ID"; - public static final String ENV_KEY_JANTJE_ARCITECTURE_ID = Const.ENV_KEY_JANTJE_START + "ARCHITECTURE_ID"; - public static final String ENV_KEY_JANTJE_BOARD_ID = Const.ENV_KEY_JANTJE_START + "BOARD_ID"; - public static final String ENV_KEY_SERIAL_PORT = Const.ERASE_START + "SERIAL.PORT"; - public static final String ENV_KEY_SERIAL_PORT_FILE = Const.ERASE_START + "SERIAL.PORT.FILE"; - private static final String ENV_KEY_BUILD_VARIANT_PATH = Const.ERASE_START + "BUILD.VARIANT.PATH"; - private static final String ENV_KEY_BUILD_ACTUAL_CORE_PATH = Const.ERASE_START + "BUILD.CORE.PATH"; - - private static final String ENV_KEY_REFERENCED_CORE_PLATFORM_PATH = Const.ERASE_START + "REFERENCED.CORE.PATH"; - private static final String ENV_KEY_REFERENCED_VARIANT_PLATFORM_PATH = Const.ERASE_START - + "REFERENCED.VARIANT.PATH"; - private static final String ENV_KEY_REFERENCED_UPLOAD_PLATFORM_PATH = Const.ERASE_START + "REFERENCED.UPLOAD.PATH"; - - // preference nodes - private static final String NODE_ARDUINO = Activator.NODE_ARDUINO; - private static final String LIBRARY_PATH_SUFFIX = "libraries"; - private static final String JANTJE_ACTION_UPLOAD = "JANTJE.UPLOAD"; // this is actually the programmer - private static final IEclipsePreferences myStorageNode = InstanceScope.INSTANCE.getNode(NODE_ARDUINO); - private static final String TOOL = Messages.TOOL; - private static final String BOARD = Messages.BOARD; - private static final String FILE = Messages.FILE; - - /* - * This is the basic info contained in the descriptor - */ - private String myUploadPort; - private String myProgrammer; - private String myBoardID; - private Map myOptions; - - /* - * the following data is stored to detect changes that will make the equal fail - * so os changes, workspace changes, eclipse install changes will force a update - * on the stored data - */ - private String myProjectName = new String(); - private String myOSName = Platform.getOS(); - private String myWorkSpaceLocation = Common.getWorkspaceRoot().toString(); - private String myWorkEclipseLocation = ConfigurationPreferences.getEclipseHome().toString(); - - /* - * Stuff to make things work - */ - private File myreferencingBoardsFile; - protected TxtFile myTxtFile; - private ChangeListener myChangeListener = null; - - private String myBoardsVariant; - private IPath myReferencedBoardVariantPlatformPath; - private String myBoardsCore; - private IPath myReferencedCorePlatformPath; - private IPath myReferencedUploadToolPlatformPath; - private String myUploadTool; - - @Override - public String toString() { - return getReferencingBoardsFile() + " \"" + getBoardName() + "\" " + getUploadPort(); //$NON-NLS-2$ - } - - /** - * Compare 2 descriptors and return true is they are equal. This method detects - * - OS changes - project name changes - moves of workspace - changed runtine - * eclipse install - * - * @param obj - * @return true if equal otherwise false - */ - public boolean equals(BoardDescriptor otherBoardDescriptor) { - if (!this.getUploadPort().equals(otherBoardDescriptor.getUploadPort())) { - return false; - } - if (!this.getProgrammer().equals(otherBoardDescriptor.getProgrammer())) { - return false; - } - return !needsSettingDirty(otherBoardDescriptor); - } - - /** - * compare 2 board descriptors and return true if replacing one board descriptor - * with the other implies that a rebuild is needed - * - * @param otherBoardDescriptor - * @return - */ - public boolean needsSettingDirty(BoardDescriptor otherBoardDescriptor) { - - if (!this.getBoardID().equals(otherBoardDescriptor.getBoardID())) { - return true; - } - if (!this.getReferencingBoardsFile().equals(otherBoardDescriptor.getReferencingBoardsFile())) { - return true; - } - if (!this.getOptions().equals(otherBoardDescriptor.getOptions())) { - return true; - } - if (!this.getProjectName().equals(otherBoardDescriptor.getProjectName())) { - return true; - } - if (!this.getMyOSName().equals(otherBoardDescriptor.getMyOSName())) { - return true; - } - if (!this.getMyWorkEclipseLocation().equals(otherBoardDescriptor.getMyWorkEclipseLocation())) { - return true; - } - if (!this.getMyWorkSpaceLocation().equals(otherBoardDescriptor.getMyWorkSpaceLocation())) { - return true; - } - return false; - } - - /* - * Create a sketchProject. This class does not really create a sketch object. - * Nor does it look for existing (mapping) sketch projects This class represents - * the data passed between the UI and the core This class does contain a create - * to create the project When confdesc is null the data will be taken from the - * "last used " otherwise the data is taken from the project the confdesc - * belongs to - * - */ - public static BoardDescriptor makeBoardDescriptor(ICConfigurationDescription confdesc) { - return new InternalBoardDescriptor(confdesc); - } - - /** - * after construction data needs to be derived from other data. This method - * derives all other data and puts it in fields - */ - private void calculateDerivedFields() { - - myReferencedCorePlatformPath = getreferencingPlatformPath(); - myBoardsCore = null; - myReferencedBoardVariantPlatformPath = myReferencedCorePlatformPath; - myBoardsVariant = null; - myReferencedUploadToolPlatformPath = myReferencedCorePlatformPath; - myUploadTool = null; - setDefaultOptions(); - // search in the board info - Map boardInfo = myTxtFile.getSection(getBoardID()); - ParseSection(boardInfo); - - } - - private void ParseSection(Map boardInfo) { - final String COLON = ":"; - if (boardInfo == null) { - return; // there is a problem with the board ID - } - String core = boardInfo.get("build.core"); - String variant = boardInfo.get("build.variant"); - String upload = boardInfo.get("upload.tool"); - // also search the options - for (Entry curOption : this.myOptions.entrySet()) { - String keyPrefix = "menu." + curOption.getKey() + '.' + curOption.getValue(); - String coreOption = boardInfo.get(keyPrefix + ".build.core"); - String variantOption = boardInfo.get(keyPrefix + ".build.variant"); - String uploadOption = boardInfo.get(keyPrefix + ".upload.tool"); - if (coreOption != null) { - core = coreOption; - } - if (variantOption != null) { - variant = variantOption; - } - if (uploadOption != null) { - upload = uploadOption; - } - } - String architecture = getArchitecture(); - if (core != null) { - String valueSplit[] = core.split(":"); - if (valueSplit.length == 2) { - String refVendor = valueSplit[0]; - String actualValue = valueSplit[1]; - myBoardsCore = actualValue; - myReferencedCorePlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, architecture); - if (this.myReferencedCorePlatformPath == null) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, - Messages.Helpers_tool_reference_missing.replaceAll(TOOL, core) - .replaceAll(FILE, getReferencingBoardsFile().toString()) - .replaceAll(BOARD, getBoardID()))); - return; - } - } 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) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, - Messages.Helpers_tool_reference_missing.replaceAll(TOOL, core) - .replaceAll(FILE, getReferencingBoardsFile().toString()) - .replaceAll(BOARD, getBoardID()))); - return; - } - } else { - this.myBoardsCore = core; - } - } - if (variant != null) { - 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) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, - Messages.Helpers_tool_reference_missing.replaceAll(TOOL, variant) - .replaceAll(FILE, getReferencingBoardsFile().toString()) - .replaceAll(BOARD, getBoardID()))); - return; - } - } 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)) { - this.myReferencedBoardVariantPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, refArchitecture); - } else { - this.myReferencedBoardVariantPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, refArchitecture, - refVersion); - } - if (this.myReferencedBoardVariantPlatformPath == null) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, - Messages.Helpers_tool_reference_missing.replaceAll(TOOL, variant) - .replaceAll(FILE, getReferencingBoardsFile().toString()) - .replaceAll(BOARD, getBoardID()))); - return; - } - } else { - myBoardsVariant = variant; - } - } - if (upload != null) { - 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) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, - Messages.Helpers_tool_reference_missing.replaceAll(TOOL, upload) - .replaceAll(FILE, getReferencingBoardsFile().toString()) - .replaceAll(BOARD, getBoardID()))); - return; - } - } 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) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, - Messages.Helpers_tool_reference_missing.replaceAll(TOOL, upload) - .replaceAll(FILE, getReferencingBoardsFile().toString()) - .replaceAll(BOARD, getBoardID()))); - return; - } - } else { - myUploadTool = upload; - } - } - - } - - protected BoardDescriptor(ICConfigurationDescription confdesc) { - if (confdesc == null) { - this.myreferencingBoardsFile = new File(myStorageNode.get(KEY_LAST_USED_BOARDS_FILE, "")); - this.myTxtFile = new TxtFile(this.myreferencingBoardsFile,true); - this.myBoardID = myStorageNode.get(KEY_LAST_USED_BOARD, ""); - this.myUploadPort = myStorageNode.get(KEY_LAST_USED_UPLOAD_PORT, ""); - this.myProgrammer = myStorageNode.get(KEY_LAST_USED_UPLOAD_PROTOCOL, Defaults.getDefaultUploadProtocol()); - this.myOptions = KeyValue.makeMap(myStorageNode.get(KEY_LAST_USED_BOARD_MENU_OPTIONS, new String())); - - } else { - this.myUploadPort = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_UPLOAD_PORT, ""); - this.myProgrammer = Common.getBuildEnvironmentVariable(confdesc, JANTJE_ACTION_UPLOAD, ""); - this.myreferencingBoardsFile = new File( - Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_BOARDS_FILE, "")); - this.myBoardID = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_BOARD_ID, ""); - this.myProjectName = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_PROJECT_NAME, ""); - this.myTxtFile = new TxtFile(this.myreferencingBoardsFile,true); - this.myOSName = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_OS, ""); - this.myWorkSpaceLocation = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_WORKSPACE_LOCATION, - ""); - this.myWorkEclipseLocation = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_ECLIPSE_LOCATION, - ""); - String optinconcat = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_MENU_SELECTION, ""); - this.myOptions = KeyValue.makeMap(optinconcat); - } - calculateDerivedFields(); - } - - public static BoardDescriptor makeBoardDescriptor(File boardsFile, String boardID, Map options) { - return new InternalBoardDescriptor(boardsFile, boardID, options); - } - - /** - * make a board descriptor for each board in the board.txt file with the default - * options - * - * @param boardFile - * @return a list of board descriptors - */ - public static List makeBoardDescriptors(File boardFile, Map options) { - TxtFile txtFile = new TxtFile(boardFile,true); - List boards = new ArrayList<>(); - for (String curboardName : txtFile.getAllNames()) { - Map boardSection = txtFile.getSection(txtFile.getBoardIDFromBoardName(curboardName)); - if (boardSection != null) { - if (!"true".equalsIgnoreCase(boardSection.get("hide"))) { - boards.add(makeBoardDescriptor(boardFile, txtFile.getBoardIDFromBoardName(curboardName), options)); - } - } - } - return boards; - } - - /** - * create a board descriptor - * - * @param boardsFile - * @param boardID - * @param options - * if null default options are taken - */ - protected BoardDescriptor(File boardsFile, String boardID, Map options) { - this.myUploadPort = new String(); - this.myProgrammer = Defaults.getDefaultUploadProtocol(); - this.myBoardID = boardID; - this.myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - this.myreferencingBoardsFile = boardsFile; - this.myTxtFile = new TxtFile(this.myreferencingBoardsFile,true); - setDefaultOptions(); - if (options != null) { - this.myOptions.putAll(options); - } - calculateDerivedFields(); - - } - - protected BoardDescriptor(TxtFile txtFile, String boardID) { - this.myUploadPort = new String(); - this.myProgrammer = Defaults.getDefaultUploadProtocol(); - this.myBoardID = boardID; - this.myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - this.myreferencingBoardsFile = txtFile.getTxtFile(); - this.myTxtFile = txtFile; - setDefaultOptions(); - - calculateDerivedFields(); - } - - public static BoardDescriptor makeBoardDescriptor(BoardDescriptor sourceBoardDescriptor) { - return new InternalBoardDescriptor(sourceBoardDescriptor); - } - - protected BoardDescriptor(BoardDescriptor sourceBoardDescriptor) { - - this.myUploadPort = sourceBoardDescriptor.getUploadPort(); - this.myProgrammer = sourceBoardDescriptor.getProgrammer(); - this.myBoardID = sourceBoardDescriptor.getBoardID(); - this.myOptions = sourceBoardDescriptor.getOptions(); - this.myProjectName = sourceBoardDescriptor.getProjectName(); - this.myreferencingBoardsFile = sourceBoardDescriptor.getReferencingBoardsFile(); - this.myTxtFile = sourceBoardDescriptor.myTxtFile; - this.myChangeListener = null; - - this.myBoardsVariant = sourceBoardDescriptor.getBoardVariant(); - this.myReferencedBoardVariantPlatformPath = sourceBoardDescriptor.getReferencedVariantPlatformPath(); - this.myBoardsCore = sourceBoardDescriptor.getBoardsCore(); - this.myReferencedCorePlatformPath = sourceBoardDescriptor.getReferencedCorePlatformPath(); - this.myReferencedUploadToolPlatformPath = sourceBoardDescriptor.getReferencedUploadPlatformPath(); - this.myUploadTool = sourceBoardDescriptor.getuploadTool(); - } - - public String getuploadTool() { - return this.myUploadTool; - } - - private String getBoardsCore() { - return this.myBoardsCore; - } - - /* - * Sets default options as follows - * If no option is specified take the first one - * if a option is specified but the value is invalid take the first one - * - * this is so because I want to provide a list of options - * but if the options are incomplete or invalid - * this method still returns a complete and valid set. - */ - private void setDefaultOptions() { - - TreeMap allMenuIDs = this.myTxtFile.getMenus(); - for (Map.Entry curMenuID : allMenuIDs.entrySet()) { - String providedMenuValue = this.myOptions.get(curMenuID.getKey()); - ArrayList menuOptions = this.myTxtFile.getMenuItemIDsFromMenuID(curMenuID.getKey(), getBoardID()); - if (menuOptions.size() > 0) { - if (providedMenuValue == null) { - - this.myOptions.put(curMenuID.getKey(), menuOptions.get(0)); - } - else if (!menuOptions.contains(providedMenuValue)) { - this.myOptions.put(curMenuID.getKey(), menuOptions.get(0)); - } - } - } - } - - /** - * tries to set the project to the boarddescriptor - * - * @param project - * @param monitor - * @return true if success false if failed - */ - public boolean configureProject(IProject project, IProgressMonitor monitor) { - ICProjectDescription prjCDesc = CoreModel.getDefault().getProjectDescription(project); - ICConfigurationDescription configurationDescription = prjCDesc.getActiveConfiguration(); - try { - save(configurationDescription); - // prjCDesc.setActiveConfiguration(configurationDescription); - CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(project, prjCDesc, true, null); - } catch (Exception e) { - e.printStackTrace(); - Common.log(new Status(IStatus.ERROR, io.sloeber.core.Activator.getId(), "failed to save the board settings", - e)); - return false; - } - return true; - } - - /* - * Method to create a project based on the board - */ - public IProject createProject(String projectName, URI projectURI, - ArrayList cfgNamesAndTCIds, CodeDescriptor codeDescription, - CompileOptions compileOptions, IProgressMonitor monitor) throws Exception { - IProject projectHandle; - projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(Common.MakeNameCompileSafe(projectName)); - - // try { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - final IProjectDescription desc = workspace.newProjectDescription(projectHandle.getName()); - desc.setLocationURI(projectURI); - - projectHandle.create(desc, monitor); - - if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } - - projectHandle.open(IResource.BACKGROUND_REFRESH, monitor); - - // Creates the .cproject file with the configurations - ICProjectDescription prjCDesc = ShouldHaveBeenInCDT.setCProjectDescription(projectHandle, cfgNamesAndTCIds, - true, compileOptions.isParallelBuildEnabled(), monitor); - - // Add the C C++ AVR and other needed Natures to the project - Helpers.addTheNatures(desc); - - // Add the Arduino folder - - Helpers.createNewFolder(projectHandle, Const.ARDUINO_CODE_FOLDER_NAME, null); - - for (ConfigurationDescriptor curConfig : cfgNamesAndTCIds) { - ICConfigurationDescription configurationDescription = prjCDesc.getConfigurationByName(curConfig.configName); - compileOptions.save(configurationDescription); - save(configurationDescription); - - } - - // Set the path variables - // ArduinoHelpers.setProjectPathVariables(prjCDesc.getActiveConfiguration()); - - // Intermediately save or the adding code will fail - // Release is the active config (as that is the "IDE" Arduino - // type....) - ICConfigurationDescription defaultConfigDescription = prjCDesc - .getConfigurationByName(cfgNamesAndTCIds.get(0).configName); - - ICResourceDescription cfgd = defaultConfigDescription.getResourceDescription(new Path(new String()), true); - ICExclusionPatternPathEntry[] entries = cfgd.getConfiguration().getSourceEntries(); - if (entries.length == 1) { - Path exclusionPath[] = new Path[6]; - exclusionPath[0] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/?xamples/**"); - exclusionPath[1] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/?xtras/**"); - exclusionPath[2] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/test*/**"); - exclusionPath[3] = new Path(LIBRARY_PATH_SUFFIX + "/?*/**/third-party/**"); - exclusionPath[4] = new Path(LIBRARY_PATH_SUFFIX + "/**/._*"); - exclusionPath[5] = new Path(LIBRARY_PATH_SUFFIX + "/?*/utility/*/*"); - - ICExclusionPatternPathEntry newSourceEntry = new CSourceEntry(entries[0].getFullPath(), exclusionPath, - ICSettingEntry.VALUE_WORKSPACE_PATH); - ICSourceEntry[] out = null; - out = new ICSourceEntry[1]; - out[0] = (ICSourceEntry) newSourceEntry; - try { - cfgd.getConfiguration().setSourceEntries(out); - } catch (@SuppressWarnings("unused") CoreException e) { - // ignore - } - - } else { - // this should not happen - } - Set librariesToInstall = codeDescription.createFiles(projectHandle, monitor); - IPath linkedPath = codeDescription.getLinkedExamplePath(); - if (linkedPath != null) { - Helpers.addIncludeFolder(defaultConfigDescription, linkedPath, false); - } - Libraries.addLibrariesToProject(projectHandle, defaultConfigDescription, librariesToInstall); - prjCDesc.setActiveConfiguration(defaultConfigDescription); - prjCDesc.setCdtProjectCreated(); - CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(projectHandle, prjCDesc, true, - null); - projectHandle.setDescription(desc, new NullProgressMonitor()); - projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null); - monitor.done(); - return projectHandle; - } - - public void save(ICConfigurationDescription confdesc) throws Exception { - boolean needsSettingDirty = saveConfiguration(confdesc, null); - - if (confdesc != null) { - IProject project = confdesc.getProjectDescription().getProject(); - - Helpers.setTheEnvironmentVariables(project, confdesc, (InternalBoardDescriptor) this); - - Helpers.addArduinoCodeToProject(this, project, confdesc); - - needsSettingDirty = needsSettingDirty || Helpers.removeInvalidIncludeFolders(confdesc); - if (needsSettingDirty) { - Helpers.setDirtyFlag(project, confdesc); - } else { - Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), - "Ignoring update; clean may be required: " + project.getName())); - } - } - } - - public void saveConfiguration() { - saveConfiguration(null, null); - } - - public boolean saveConfiguration(ICConfigurationDescription confDesc, IContributedEnvironment contribEnvIn) { - boolean needsSettingDirty = false; - if (confDesc != null) { - if (getActualCoreCodePath() == null) { - // don't change stuff if the setup is wonky - return false; - } - BoardDescriptor curBoardDesCriptor = makeBoardDescriptor(confDesc); - needsSettingDirty = curBoardDesCriptor.needsSettingDirty(this); - IContributedEnvironment contribEnv = contribEnvIn; - if (contribEnv == null) { - IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager(); - contribEnv = envManager.getContributedEnvironment(); - } - Common.setBuildEnvironmentVariable(contribEnv, confDesc, "JANTJE.SELECTED.PLATFORM", - getreferencingPlatformPath().toString()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARD_NAME, getBoardName()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARDS_FILE, - getReferencingBoardsFile().toString()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARD_ID, this.myBoardID); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_ARCITECTURE_ID, getArchitecture()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_PACKAGE_ID, getPackage()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_UPLOAD_PORT, this.myUploadPort); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_PROJECT_NAME, - confDesc.getProjectDescription().getProject().getName()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_OS, this.myOSName); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_WORKSPACE_LOCATION, - this.myWorkSpaceLocation); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_ECLIPSE_LOCATION, - this.myWorkEclipseLocation); - Common.setBuildEnvironmentVariable(confDesc, JANTJE_ACTION_UPLOAD, this.myProgrammer); - String value = KeyValue.makeString(this.myOptions); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_MENU_SELECTION, value); - - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT, getActualUploadPort()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT_FILE, - getActualUploadPort().replace("/dev/", new String())); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_ACTUAL_CORE_PATH, getActualCoreCodePath().toOSString()); - IPath variantPath = getActualVariantPath(); - if (variantPath != null) { - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH, - variantPath.toOSString()); - } else {// teensy does not use variants - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH, new String()); - } - - // the entries below are only saved for special platforms that heavily rely on - // referencing such as jantjes hardware - - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_REFERENCED_CORE_PLATFORM_PATH, - getReferencedCorePlatformPath().toOSString()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_REFERENCED_VARIANT_PLATFORM_PATH, - getReferencedVariantPlatformPath().toOSString()); - Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_REFERENCED_UPLOAD_PLATFORM_PATH, - getReferencedUploadPlatformPath().toOSString()); - - } - - // Also save last used values - 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); - myStorageNode.put(KEY_LAST_USED_BOARD_MENU_OPTIONS, KeyValue.makeString(this.myOptions)); - return needsSettingDirty; - } - - public String getPackage() { - return this.myTxtFile.getPackage(); - } - - public String getArchitecture() { - return this.myTxtFile.getArchitecture(); - } - - public File getReferencingBoardsFile() { - return this.myreferencingBoardsFile; - } - - public String getBoardName() { - return this.myTxtFile.getNameFromID(this.myBoardID); - } - - public String getUploadPort() { - return this.myUploadPort; - } - - /** - * return the actual adress en,coded in the upload port - * example - * uploadport com4 returns com4 - * uploadport = arduino.local at 199.25.25.1 returns arduino.local - * - * @return - */ - public String getActualUploadPort() { - return myUploadPort.split(" ")[0]; - } - - public String getProgrammer() { - return this.myProgrammer; - } - - /** - * Set the upload port like in the gui. - * The upload port can be a comport or a networkadress space and something else - * note that getuploadport returns the before space part of this method - * @param newUploadPort - */ - public void setUploadPort(String newUploadPort) { - this.myUploadPort = newUploadPort; - } - - public void setUploadProtocol(String newUploadProtocol) { - this.myProgrammer = newUploadProtocol; - - } - - public void setBoardID(String boardID) { - if (!boardID.equals(this.myBoardID)) { - this.myBoardID = boardID; - informChangeListeners(); - } - } - - public void setBoardName(String boardName) { - String newBoardID = this.myTxtFile.getBoardIDFromBoardName(boardName); - if ((newBoardID == null || this.myBoardID.equals(newBoardID))) { - return; - } - - this.myBoardID = newBoardID; - informChangeListeners(); - - } - - public void setreferencingBoardsFile(File boardsFile) { - if (boardsFile == null) { - return;// ignore - } - if (this.myreferencingBoardsFile.equals(boardsFile)) { - return; - } - - this.myreferencingBoardsFile = boardsFile; - this.myTxtFile = new TxtFile(this.myreferencingBoardsFile,true); - informChangeListeners(); - } - - public void setOptions(Map options) { - if (options == null) { - return; - } - this.myOptions.putAll(options); - calculateDerivedFields(); - } - - /** - * Returns the options for this board This reflects the options selected through - * the menu functionality in the boards.txt - * - * @return a map of case insensitive ordered key value pairs - */ - public Map getOptions() { - return this.myOptions; - } - - public String getBoardID() { - return this.myBoardID; - } - - public String[] getCompatibleBoards() { - return this.myTxtFile.getAllNames(); - } - - public String[] getUploadProtocols() { - - return Programmers.getUploadProtocols(this); - - } - - public String[] getMenuItemNamesFromMenuID(String menuID) { - return this.myTxtFile.getMenuItemNamesFromMenuID(menuID, this.myBoardID); - } - - public Set getAllMenuNames() { - return this.myTxtFile.getMenuNames(); - } - - public TreeMap getAllExamples() { - return LibraryManager.getAllExamples(this); - } - - public void addChangeListener(ChangeListener l) { - this.myChangeListener = l; - } - - public void removeChangeListener() { - this.myChangeListener = null; - } - - private void informChangeListeners() { - calculateDerivedFields(); - if (this.myChangeListener != null) { - this.myChangeListener.stateChanged(null); - } - } - - public String getMenuIdFromMenuName(String menuName) { - return this.myTxtFile.getMenuIDFromMenuName(menuName); - } - - public String getMenuNameFromMenuID(String id) { - return this.myTxtFile.getMenuNameFromID(id); - } - - public String getMenuItemNamedFromMenuItemID(String menuItemID, String menuID) { - return this.myTxtFile.getMenuItemNameFromMenuItemID(this.myBoardID, menuID, menuItemID); - } - - public String getMenuItemIDFromMenuItemName(String menuItemName, String menuID) { - return this.myTxtFile.getMenuItemIDFromMenuItemName(this.myBoardID, menuID, menuItemName); - } - - public static String getUploadPort(IProject project) { - return Common.getBuildEnvironmentVariable(project, ENV_KEY_JANTJE_UPLOAD_PORT, new String()); - } - - private String getMyOSName() { - return this.myOSName; - } - - private String getMyWorkSpaceLocation() { - return this.myWorkSpaceLocation; - } - - private String getMyWorkEclipseLocation() { - return this.myWorkEclipseLocation; - } - - public String getProjectName() { - return this.myProjectName; - } - - /** - * 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; null if no variant is needed - */ - public IPath getActualVariantPath() { - if (getBoardVariant() == null) { - return null; - } - IPath retPath = getReferencedVariantPlatformPath(); - if (retPath == null) { - retPath = getreferencingPlatformPath(); - } - return retPath.append(Const.VARIANTS_FOLDER_NAME).append(getBoardVariant()); - } - - private String getBoardVariant() { - return this.myBoardsVariant; - } - - public IPath getActualCoreCodePath() { - IPath retPath = getReferencedCorePlatformPath(); - if (retPath == null) { - retPath = getreferencingPlatformPath(); - } - if (this.myBoardsCore == null) { - return null; - } - return retPath.append("cores").append(this.myBoardsCore); - } - - /** + /* + * Some constants + */ + private static final String KEY_LAST_USED_BOARD = "Last used Board"; + private static final String KEY_LAST_USED_UPLOAD_PORT = "Last Used Upload port"; + private static final String KEY_LAST_USED_UPLOAD_PROTOCOL = "last Used upload Protocol"; + private static final String KEY_LAST_USED_BOARDS_FILE = "Last used Boards file"; + private static final String KEY_LAST_USED_BOARD_MENU_OPTIONS = "last used Board custom option selections"; + private static final String ENV_KEY_JANTJE_MENU_SELECTION = Const.ENV_KEY_JANTJE_START + "MENU"; + private static final String ENV_KEY_JANTJE_UPLOAD_PORT = Const.ENV_KEY_JANTJE_START + "COM_PORT"; + private static final String ENV_KEY_JANTJE_BOARD_NAME = Const.ENV_KEY_JANTJE_START + "BOARD_NAME"; + private static final String ENV_KEY_JANTJE_PROJECT_NAME = Const.ENV_KEY_JANTJE_START + "PROJECT_NAME"; + private static final String ENV_KEY_JANTJE_OS = Const.ENV_KEY_JANTJE_START + "OS_NAME"; + private static final String ENV_KEY_JANTJE_WORKSPACE_LOCATION = Const.ENV_KEY_JANTJE_START + "WORKSPACE_LOCATION"; + private static final String ENV_KEY_JANTJE_ECLIPSE_LOCATION = Const.ENV_KEY_JANTJE_START + "ECLIPSE_LOCATION"; + + public static final String ENV_KEY_JANTJE_BOARDS_FILE = Const.ENV_KEY_JANTJE_START + "BOARDS_FILE"; + + public static final String ENV_KEY_JANTJE_PACKAGE_ID = Const.ENV_KEY_JANTJE_START + "PACKAGE_ID"; + public static final String ENV_KEY_JANTJE_ARCITECTURE_ID = Const.ENV_KEY_JANTJE_START + "ARCHITECTURE_ID"; + public static final String ENV_KEY_JANTJE_BOARD_ID = Const.ENV_KEY_JANTJE_START + "BOARD_ID"; + public static final String ENV_KEY_SERIAL_PORT = Const.ERASE_START + "SERIAL.PORT"; + public static final String ENV_KEY_SERIAL_PORT_FILE = Const.ERASE_START + "SERIAL.PORT.FILE"; + private static final String ENV_KEY_BUILD_VARIANT_PATH = Const.ERASE_START + "BUILD.VARIANT.PATH"; + private static final String ENV_KEY_BUILD_ACTUAL_CORE_PATH = Const.ERASE_START + "BUILD.CORE.PATH"; + + private static final String ENV_KEY_REFERENCED_CORE_PLATFORM_PATH = Const.ERASE_START + "REFERENCED.CORE.PATH"; + private static final String ENV_KEY_REFERENCED_VARIANT_PLATFORM_PATH = Const.ERASE_START + + "REFERENCED.VARIANT.PATH"; + private static final String ENV_KEY_REFERENCED_UPLOAD_PLATFORM_PATH = Const.ERASE_START + "REFERENCED.UPLOAD.PATH"; + + // preference nodes + private static final String NODE_ARDUINO = Activator.NODE_ARDUINO; + private static final String LIBRARY_PATH_SUFFIX = "libraries"; + private static final String JANTJE_ACTION_UPLOAD = "JANTJE.UPLOAD"; // this is actually the programmer + private static final IEclipsePreferences myStorageNode = InstanceScope.INSTANCE.getNode(NODE_ARDUINO); + private static final String TOOL = Messages.TOOL; + private static final String BOARD = Messages.BOARD; + private static final String FILE = Messages.FILE; + + /* + * This is the basic info contained in the descriptor + */ + private String myUploadPort; + private String myProgrammer; + private String myBoardID; + private Map myOptions; + + /* + * the following data is stored to detect changes that will make the equal fail + * so os changes, workspace changes, eclipse install changes will force a update + * on the stored data + */ + private String myProjectName = new String(); + private String myOSName = Platform.getOS(); + private String myWorkSpaceLocation = Common.getWorkspaceRoot().toString(); + private String myWorkEclipseLocation = ConfigurationPreferences.getEclipseHome().toString(); + + /* + * Stuff to make things work + */ + private File myreferencingBoardsFile; + protected TxtFile myTxtFile; + private ChangeListener myChangeListener = null; + + private String myBoardsVariant; + private IPath myReferencedBoardVariantPlatformPath; + private String myBoardsCore; + private IPath myReferencedCorePlatformPath; + private IPath myReferencedUploadToolPlatformPath; + private String myUploadTool; + + @Override + public String toString() { + return getReferencingBoardsFile() + " \"" + getBoardName() + "\" " + getUploadPort(); //$NON-NLS-2$ + } + + /** + * Compare 2 descriptors and return true is they are equal. This method detects + * - OS changes - project name changes - moves of workspace - changed runtine + * eclipse install + * + * @param obj + * @return true if equal otherwise false + */ + public boolean equals(BoardDescriptor otherBoardDescriptor) { + if (!this.getUploadPort().equals(otherBoardDescriptor.getUploadPort())) { + return false; + } + if (!this.getProgrammer().equals(otherBoardDescriptor.getProgrammer())) { + return false; + } + return !needsSettingDirty(otherBoardDescriptor); + } + + /** + * compare 2 board descriptors and return true if replacing one board descriptor + * with the other implies that a rebuild is needed + * + * @param otherBoardDescriptor + * @return + */ + public boolean needsSettingDirty(BoardDescriptor otherBoardDescriptor) { + + if (!this.getBoardID().equals(otherBoardDescriptor.getBoardID())) { + return true; + } + if (!this.getReferencingBoardsFile().equals(otherBoardDescriptor.getReferencingBoardsFile())) { + return true; + } + if (!this.getOptions().equals(otherBoardDescriptor.getOptions())) { + return true; + } + if (!this.getProjectName().equals(otherBoardDescriptor.getProjectName())) { + return true; + } + if (!this.getMyOSName().equals(otherBoardDescriptor.getMyOSName())) { + return true; + } + if (!this.getMyWorkEclipseLocation().equals(otherBoardDescriptor.getMyWorkEclipseLocation())) { + return true; + } + if (!this.getMyWorkSpaceLocation().equals(otherBoardDescriptor.getMyWorkSpaceLocation())) { + return true; + } + return false; + } + + /* + * Create a sketchProject. This class does not really create a sketch object. + * Nor does it look for existing (mapping) sketch projects This class represents + * the data passed between the UI and the core This class does contain a create + * to create the project When confdesc is null the data will be taken from the + * "last used " otherwise the data is taken from the project the confdesc + * belongs to + * + */ + public static BoardDescriptor makeBoardDescriptor(ICConfigurationDescription confdesc) { + return new InternalBoardDescriptor(confdesc); + } + + /** + * after construction data needs to be derived from other data. This method + * derives all other data and puts it in fields + */ + private void calculateDerivedFields() { + + myReferencedCorePlatformPath = getreferencingPlatformPath(); + myBoardsCore = null; + myReferencedBoardVariantPlatformPath = myReferencedCorePlatformPath; + myBoardsVariant = null; + myReferencedUploadToolPlatformPath = myReferencedCorePlatformPath; + myUploadTool = null; + setDefaultOptions(); + // search in the board info + Map boardInfo = myTxtFile.getSection(getBoardID()); + ParseSection(boardInfo); + + } + + private void ParseSection(Map boardInfo) { + final String COLON = ":"; + if (boardInfo == null) { + return; // there is a problem with the board ID + } + String core = boardInfo.get("build.core"); + String variant = boardInfo.get("build.variant"); + String upload = boardInfo.get("upload.tool"); + // also search the options + for (Entry curOption : this.myOptions.entrySet()) { + String keyPrefix = "menu." + curOption.getKey() + '.' + curOption.getValue(); + String coreOption = boardInfo.get(keyPrefix + ".build.core"); + String variantOption = boardInfo.get(keyPrefix + ".build.variant"); + String uploadOption = boardInfo.get(keyPrefix + ".upload.tool"); + if (coreOption != null) { + core = coreOption; + } + if (variantOption != null) { + variant = variantOption; + } + if (uploadOption != null) { + upload = uploadOption; + } + } + String architecture = getArchitecture(); + if (core != null) { + String valueSplit[] = core.split(":"); + if (valueSplit.length == 2) { + String refVendor = valueSplit[0]; + String actualValue = valueSplit[1]; + myBoardsCore = actualValue; + myReferencedCorePlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, architecture); + if (this.myReferencedCorePlatformPath == null) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, + Messages.Helpers_tool_reference_missing.replaceAll(TOOL, core) + .replaceAll(FILE, getReferencingBoardsFile().toString()) + .replaceAll(BOARD, getBoardID()))); + return; + } + } 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) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, + Messages.Helpers_tool_reference_missing.replaceAll(TOOL, core) + .replaceAll(FILE, getReferencingBoardsFile().toString()) + .replaceAll(BOARD, getBoardID()))); + return; + } + } else { + this.myBoardsCore = core; + } + } + if (variant != null) { + 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) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, + Messages.Helpers_tool_reference_missing.replaceAll(TOOL, variant) + .replaceAll(FILE, getReferencingBoardsFile().toString()) + .replaceAll(BOARD, getBoardID()))); + return; + } + } 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)) { + this.myReferencedBoardVariantPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, + refArchitecture); + } else { + this.myReferencedBoardVariantPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, + refArchitecture, refVersion); + } + if (this.myReferencedBoardVariantPlatformPath == null) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, + Messages.Helpers_tool_reference_missing.replaceAll(TOOL, variant) + .replaceAll(FILE, getReferencingBoardsFile().toString()) + .replaceAll(BOARD, getBoardID()))); + return; + } + } else { + myBoardsVariant = variant; + } + } + if (upload != null) { + 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) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, + Messages.Helpers_tool_reference_missing.replaceAll(TOOL, upload) + .replaceAll(FILE, getReferencingBoardsFile().toString()) + .replaceAll(BOARD, getBoardID()))); + return; + } + } 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) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, + Messages.Helpers_tool_reference_missing.replaceAll(TOOL, upload) + .replaceAll(FILE, getReferencingBoardsFile().toString()) + .replaceAll(BOARD, getBoardID()))); + return; + } + } else { + myUploadTool = upload; + } + } + + } + + protected BoardDescriptor(ICConfigurationDescription confdesc) { + if (confdesc == null) { + this.myreferencingBoardsFile = new File(myStorageNode.get(KEY_LAST_USED_BOARDS_FILE, "")); + this.myTxtFile = new TxtFile(this.myreferencingBoardsFile, true); + this.myBoardID = myStorageNode.get(KEY_LAST_USED_BOARD, ""); + this.myUploadPort = myStorageNode.get(KEY_LAST_USED_UPLOAD_PORT, ""); + this.myProgrammer = myStorageNode.get(KEY_LAST_USED_UPLOAD_PROTOCOL, Defaults.getDefaultUploadProtocol()); + this.myOptions = KeyValue.makeMap(myStorageNode.get(KEY_LAST_USED_BOARD_MENU_OPTIONS, new String())); + + } else { + this.myUploadPort = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_UPLOAD_PORT, ""); + this.myProgrammer = Common.getBuildEnvironmentVariable(confdesc, JANTJE_ACTION_UPLOAD, ""); + this.myreferencingBoardsFile = new File( + Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_BOARDS_FILE, "")); + this.myBoardID = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_BOARD_ID, ""); + this.myProjectName = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_PROJECT_NAME, ""); + this.myTxtFile = new TxtFile(this.myreferencingBoardsFile, true); + this.myOSName = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_OS, ""); + this.myWorkSpaceLocation = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_WORKSPACE_LOCATION, + ""); + this.myWorkEclipseLocation = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_ECLIPSE_LOCATION, + ""); + String optinconcat = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_MENU_SELECTION, ""); + this.myOptions = KeyValue.makeMap(optinconcat); + } + calculateDerivedFields(); + } + + public static BoardDescriptor makeBoardDescriptor(File boardsFile, String boardID, Map options) { + return new InternalBoardDescriptor(boardsFile, boardID, options); + } + + /** + * make a board descriptor for each board in the board.txt file with the default + * options + * + * @param boardFile + * @return a list of board descriptors + */ + public static List makeBoardDescriptors(File boardFile, Map options) { + TxtFile txtFile = new TxtFile(boardFile, true); + List boards = new ArrayList<>(); + for (String curboardName : txtFile.getAllNames()) { + Map boardSection = txtFile.getSection(txtFile.getBoardIDFromBoardName(curboardName)); + if (boardSection != null) { + if (!"true".equalsIgnoreCase(boardSection.get("hide"))) { + boards.add(makeBoardDescriptor(boardFile, txtFile.getBoardIDFromBoardName(curboardName), options)); + } + } + } + return boards; + } + + /** + * create a board descriptor + * + * @param boardsFile + * @param boardID + * @param options if null default options are taken + */ + protected BoardDescriptor(File boardsFile, String boardID, Map options) { + this.myUploadPort = new String(); + this.myProgrammer = Defaults.getDefaultUploadProtocol(); + this.myBoardID = boardID; + this.myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + this.myreferencingBoardsFile = boardsFile; + this.myTxtFile = new TxtFile(this.myreferencingBoardsFile, true); + setDefaultOptions(); + if (options != null) { + this.myOptions.putAll(options); + } + calculateDerivedFields(); + + } + + protected BoardDescriptor(TxtFile txtFile, String boardID) { + this.myUploadPort = new String(); + this.myProgrammer = Defaults.getDefaultUploadProtocol(); + this.myBoardID = boardID; + this.myOptions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); + this.myreferencingBoardsFile = txtFile.getTxtFile(); + this.myTxtFile = txtFile; + setDefaultOptions(); + + calculateDerivedFields(); + } + + public static BoardDescriptor makeBoardDescriptor(BoardDescriptor sourceBoardDescriptor) { + return new InternalBoardDescriptor(sourceBoardDescriptor); + } + + protected BoardDescriptor(BoardDescriptor sourceBoardDescriptor) { + + this.myUploadPort = sourceBoardDescriptor.getUploadPort(); + this.myProgrammer = sourceBoardDescriptor.getProgrammer(); + this.myBoardID = sourceBoardDescriptor.getBoardID(); + this.myOptions = sourceBoardDescriptor.getOptions(); + this.myProjectName = sourceBoardDescriptor.getProjectName(); + this.myreferencingBoardsFile = sourceBoardDescriptor.getReferencingBoardsFile(); + this.myTxtFile = sourceBoardDescriptor.myTxtFile; + this.myChangeListener = null; + + this.myBoardsVariant = sourceBoardDescriptor.getBoardVariant(); + this.myReferencedBoardVariantPlatformPath = sourceBoardDescriptor.getReferencedVariantPlatformPath(); + this.myBoardsCore = sourceBoardDescriptor.getBoardsCore(); + this.myReferencedCorePlatformPath = sourceBoardDescriptor.getReferencedCorePlatformPath(); + this.myReferencedUploadToolPlatformPath = sourceBoardDescriptor.getReferencedUploadPlatformPath(); + this.myUploadTool = sourceBoardDescriptor.getuploadTool(); + } + + public String getuploadTool() { + return this.myUploadTool; + } + + private String getBoardsCore() { + return this.myBoardsCore; + } + + /* + * Sets default options as follows If no option is specified take the first one + * if a option is specified but the value is invalid take the first one + * + * this is so because I want to provide a list of options but if the options are + * incomplete or invalid this method still returns a complete and valid set. + */ + private void setDefaultOptions() { + + TreeMap allMenuIDs = this.myTxtFile.getMenus(); + for (Map.Entry curMenuID : allMenuIDs.entrySet()) { + String providedMenuValue = this.myOptions.get(curMenuID.getKey()); + ArrayList menuOptions = this.myTxtFile.getMenuItemIDsFromMenuID(curMenuID.getKey(), getBoardID()); + if (menuOptions.size() > 0) { + if (providedMenuValue == null) { + + this.myOptions.put(curMenuID.getKey(), menuOptions.get(0)); + } else if (!menuOptions.contains(providedMenuValue)) { + this.myOptions.put(curMenuID.getKey(), menuOptions.get(0)); + } + } + } + } + + /** + * tries to set the project to the boarddescriptor + * + * @param project + * @param monitor + * @return true if success false if failed + */ + public boolean configureProject(IProject project, IProgressMonitor monitor) { + ICProjectDescription prjCDesc = CoreModel.getDefault().getProjectDescription(project); + ICConfigurationDescription configurationDescription = prjCDesc.getActiveConfiguration(); + try { + save(configurationDescription); + // prjCDesc.setActiveConfiguration(configurationDescription); + CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(project, prjCDesc, true, null); + } catch (Exception e) { + e.printStackTrace(); + Common.log(new Status(IStatus.ERROR, io.sloeber.core.Activator.getId(), "failed to save the board settings", + e)); + return false; + } + return true; + } + + /* + * Method to create a project based on the board + */ + public IProject createProject(String projectName, URI projectURI, CodeDescriptor codeDescription, + CompileOptions compileOptions, IProgressMonitor monitor) throws Exception { + + String realProjectName = Common.MakeNameCompileSafe(projectName); +// IProject newProjectHandle = ManagedBuildTestHelper.createProject(realProjectName, projectURI, +// "io.sloeber.core.sketch"); + + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + final IProject newProjectHandle = root.getProject(realProjectName); + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + IWorkspaceRunnable runnable = new IWorkspaceRunnable() { + @Override + public void run(IProgressMonitor monitor) throws CoreException { + + try { + // Create the base project + IWorkspaceDescription workspaceDesc = workspace.getDescription(); + workspaceDesc.setAutoBuilding(false); + workspace.setDescription(workspaceDesc); + + IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); + if (projectURI != null) { + description.setLocationURI(projectURI); + } + + CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), + ManagedBuilderCorePlugin.MANAGED_MAKE_PROJECT_ID); + // Add the managed build nature and builder + addManagedBuildNature(newProjectHandle); + + // Find the base project type definition + IProjectType projType = ManagedBuildManager.getProjectType("io.sloeber.core.sketch"); + + // Create the managed-project (.cdtbuild) for our project that builds an + // executable. + IManagedProject newProject = null; + newProject = ManagedBuildManager.createManagedProject(newProjectHandle, projType); + ManagedBuildManager.setNewProjectVersion(newProjectHandle); + // Copy over the configs + IConfiguration defaultConfig = null; + IConfiguration[] configs = projType.getConfigurations(); + for (int i = 0; i < configs.length; ++i) { + // Make the first configuration the default + if (i == 0) { + defaultConfig = newProject.createConfiguration(configs[i], projType.getId() + "." + i); //$NON-NLS-1$ + } else { + newProject.createConfiguration(configs[i], projType.getId() + "." + i); //$NON-NLS-1$ + } + } + ManagedBuildManager.setDefaultConfiguration(newProjectHandle, defaultConfig); + + IConfiguration cfgs[] = newProject.getConfigurations(); + for (int i = 0; i < cfgs.length; i++) { + cfgs[i].setArtifactName(newProject.getDefaultArtifactName()); + } + codeDescription.createFiles(newProjectHandle, new NullProgressMonitor()); + ManagedCProjectNature.addNature(newProjectHandle, "org.eclipse.cdt.core.ccnature", monitor); + ManagedCProjectNature.addNature(newProjectHandle, Const.ARDUINO_NATURE_ID, monitor); + + CCorePlugin cCorePlugin = CCorePlugin.getDefault(); + ICProjectDescription prjCDesc = cCorePlugin.getProjectDescription(newProjectHandle); + for (ICConfigurationDescription curConfig : prjCDesc.getConfigurations()) { + compileOptions.save(curConfig); + save(curConfig); + } + cCorePlugin.setProjectDescription(newProjectHandle, prjCDesc, true, null); + + ManagedBuildManager.getBuildInfo(newProjectHandle).setValid(true); + } catch (Exception e) { + + return; + } + + } + }; + + try { + workspace.run(runnable, root, IWorkspace.AVOID_UPDATE, monitor); + } catch (CoreException e2) { + + } + + monitor.done(); + + return newProjectHandle; + } + + static private void addManagedBuildNature(IProject project) throws Exception { + // Create the buildinformation object for the project + ManagedBuildManager.createBuildInfo(project); + + // Add the managed build nature + ManagedCProjectNature.addManagedNature(project, new NullProgressMonitor()); + ManagedCProjectNature.addManagedBuilder(project, new NullProgressMonitor()); + + // Associate the project with the managed builder so the clients can get proper + // information + + CCorePlugin cCorePlugin = CCorePlugin.getDefault(); + ICProjectDescription projDesc = cCorePlugin.getProjectDescription(project, true); + + for (ICConfigurationDescription curConfig : projDesc.getConfigurations()) { + curConfig.remove(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID); + curConfig.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, ManagedBuildManager.INTERFACE_IDENTITY); + } + + cCorePlugin.setProjectDescription(project, projDesc, true, null); + + } + + public void save(ICConfigurationDescription confdesc) throws Exception { + boolean needsSettingDirty = saveConfiguration(confdesc, null); + + if (confdesc != null) { + IProject project = confdesc.getProjectDescription().getProject(); + + Helpers.setTheEnvironmentVariables(project, confdesc, (InternalBoardDescriptor) this); + + Helpers.addArduinoCodeToProject(this, project, confdesc); + + needsSettingDirty = needsSettingDirty || Helpers.removeInvalidIncludeFolders(confdesc); + if (needsSettingDirty) { + Helpers.setDirtyFlag(project, confdesc); + } else { + Common.log(new Status(IStatus.INFO, io.sloeber.core.Activator.getId(), + "Ignoring update; clean may be required: " + project.getName())); + } + } + } + + public void saveConfiguration() { + saveConfiguration(null, null); + } + + public boolean saveConfiguration(ICConfigurationDescription confDesc, IContributedEnvironment contribEnvIn) { + boolean needsSettingDirty = false; + if (confDesc != null) { + if (getActualCoreCodePath() == null) { + // don't change stuff if the setup is wonky + return false; + } + BoardDescriptor curBoardDesCriptor = makeBoardDescriptor(confDesc); + needsSettingDirty = curBoardDesCriptor.needsSettingDirty(this); + IContributedEnvironment contribEnv = contribEnvIn; + if (contribEnv == null) { + IEnvironmentVariableManager envManager = CCorePlugin.getDefault().getBuildEnvironmentManager(); + contribEnv = envManager.getContributedEnvironment(); + } + Common.setBuildEnvironmentVariable(contribEnv, confDesc, "JANTJE.SELECTED.PLATFORM", + getreferencingPlatformPath().toString()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARD_NAME, getBoardName()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARDS_FILE, + getReferencingBoardsFile().toString()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_BOARD_ID, this.myBoardID); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_ARCITECTURE_ID, getArchitecture()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_PACKAGE_ID, getPackage()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_UPLOAD_PORT, this.myUploadPort); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_PROJECT_NAME, + confDesc.getProjectDescription().getProject().getName()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_OS, this.myOSName); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_WORKSPACE_LOCATION, + this.myWorkSpaceLocation); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_ECLIPSE_LOCATION, + this.myWorkEclipseLocation); + Common.setBuildEnvironmentVariable(confDesc, JANTJE_ACTION_UPLOAD, this.myProgrammer); + String value = KeyValue.makeString(this.myOptions); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_MENU_SELECTION, value); + + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT, getActualUploadPort()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT_FILE, + getActualUploadPort().replace("/dev/", new String())); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_ACTUAL_CORE_PATH, + getActualCoreCodePath().toOSString()); + IPath variantPath = getActualVariantPath(); + if (variantPath != null) { + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH, + variantPath.toOSString()); + } else {// teensy does not use variants + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_BUILD_VARIANT_PATH, new String()); + } + + // the entries below are only saved for special platforms that heavily rely on + // referencing such as jantjes hardware + + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_REFERENCED_CORE_PLATFORM_PATH, + getReferencedCorePlatformPath().toOSString()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_REFERENCED_VARIANT_PLATFORM_PATH, + getReferencedVariantPlatformPath().toOSString()); + Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_REFERENCED_UPLOAD_PLATFORM_PATH, + getReferencedUploadPlatformPath().toOSString()); + + } + + // Also save last used values + 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); + myStorageNode.put(KEY_LAST_USED_BOARD_MENU_OPTIONS, KeyValue.makeString(this.myOptions)); + return needsSettingDirty; + } + + public String getPackage() { + return this.myTxtFile.getPackage(); + } + + public String getArchitecture() { + return this.myTxtFile.getArchitecture(); + } + + public File getReferencingBoardsFile() { + return this.myreferencingBoardsFile; + } + + public String getBoardName() { + return this.myTxtFile.getNameFromID(this.myBoardID); + } + + public String getUploadPort() { + return this.myUploadPort; + } + + /** + * return the actual adress en,coded in the upload port example uploadport com4 + * returns com4 uploadport = arduino.local at 199.25.25.1 returns arduino.local + * + * @return + */ + public String getActualUploadPort() { + return myUploadPort.split(" ")[0]; + } + + public String getProgrammer() { + return this.myProgrammer; + } + + /** + * Set the upload port like in the gui. The upload port can be a comport or a + * networkadress space and something else note that getuploadport returns the + * before space part of this method + * + * @param newUploadPort + */ + public void setUploadPort(String newUploadPort) { + this.myUploadPort = newUploadPort; + } + + public void setUploadProtocol(String newUploadProtocol) { + this.myProgrammer = newUploadProtocol; + + } + + public void setBoardID(String boardID) { + if (!boardID.equals(this.myBoardID)) { + this.myBoardID = boardID; + informChangeListeners(); + } + } + + public void setBoardName(String boardName) { + String newBoardID = this.myTxtFile.getBoardIDFromBoardName(boardName); + if ((newBoardID == null || this.myBoardID.equals(newBoardID))) { + return; + } + + this.myBoardID = newBoardID; + informChangeListeners(); + + } + + public void setreferencingBoardsFile(File boardsFile) { + if (boardsFile == null) { + return;// ignore + } + if (this.myreferencingBoardsFile.equals(boardsFile)) { + return; + } + + this.myreferencingBoardsFile = boardsFile; + this.myTxtFile = new TxtFile(this.myreferencingBoardsFile, true); + informChangeListeners(); + } + + public void setOptions(Map options) { + if (options == null) { + return; + } + this.myOptions.putAll(options); + calculateDerivedFields(); + } + + /** + * Returns the options for this board This reflects the options selected through + * the menu functionality in the boards.txt + * + * @return a map of case insensitive ordered key value pairs + */ + public Map getOptions() { + return this.myOptions; + } + + public String getBoardID() { + return this.myBoardID; + } + + public String[] getCompatibleBoards() { + return this.myTxtFile.getAllNames(); + } + + public String[] getUploadProtocols() { + + return Programmers.getUploadProtocols(this); + + } + + public String[] getMenuItemNamesFromMenuID(String menuID) { + return this.myTxtFile.getMenuItemNamesFromMenuID(menuID, this.myBoardID); + } + + public Set getAllMenuNames() { + return this.myTxtFile.getMenuNames(); + } + + public TreeMap getAllExamples() { + return LibraryManager.getAllExamples(this); + } + + public void addChangeListener(ChangeListener l) { + this.myChangeListener = l; + } + + public void removeChangeListener() { + this.myChangeListener = null; + } + + private void informChangeListeners() { + calculateDerivedFields(); + if (this.myChangeListener != null) { + this.myChangeListener.stateChanged(null); + } + } + + public String getMenuIdFromMenuName(String menuName) { + return this.myTxtFile.getMenuIDFromMenuName(menuName); + } + + public String getMenuNameFromMenuID(String id) { + return this.myTxtFile.getMenuNameFromID(id); + } + + public String getMenuItemNamedFromMenuItemID(String menuItemID, String menuID) { + return this.myTxtFile.getMenuItemNameFromMenuItemID(this.myBoardID, menuID, menuItemID); + } + + public String getMenuItemIDFromMenuItemName(String menuItemName, String menuID) { + return this.myTxtFile.getMenuItemIDFromMenuItemName(this.myBoardID, menuID, menuItemName); + } + + public static String getUploadPort(IProject project) { + return Common.getBuildEnvironmentVariable(project, ENV_KEY_JANTJE_UPLOAD_PORT, new String()); + } + + private String getMyOSName() { + return this.myOSName; + } + + private String getMyWorkSpaceLocation() { + return this.myWorkSpaceLocation; + } + + private String getMyWorkEclipseLocation() { + return this.myWorkEclipseLocation; + } + + public String getProjectName() { + return this.myProjectName; + } + + /** * provide the actual path to the variant. Use this method if you want to know - * where the variant is - * + * where the variant is + * + * @return the path to the variant; null if no variant is needed + */ + public IPath getActualVariantPath() { + if (getBoardVariant() == null) { + return null; + } + IPath retPath = getReferencedVariantPlatformPath(); + if (retPath == null) { + retPath = getreferencingPlatformPath(); + } + return retPath.append(Const.VARIANTS_FOLDER_NAME).append(getBoardVariant()); + } + + private String getBoardVariant() { + return this.myBoardsVariant; + } + + public IPath getActualCoreCodePath() { + IPath retPath = getReferencedCorePlatformPath(); + if (retPath == null) { + retPath = getreferencingPlatformPath(); + } + if (this.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() { - if (myReferencedCorePlatformPath != null) { - return myReferencedCorePlatformPath; - } - return getreferencingPlatformPath(); - } - - public IPath getReferencedUploadPlatformPath() { - if (myReferencedUploadToolPlatformPath != null) { - return myReferencedUploadToolPlatformPath; - } - return getreferencingPlatformPath(); - } - - public IPath getReferencedVariantPlatformPath() { - if (myReferencedBoardVariantPlatformPath != null) { - return myReferencedBoardVariantPlatformPath; - } - return getreferencingPlatformPath(); - } - - public File getReferencingPlatformFile() { - return getreferencingPlatformPath().append(Const.PLATFORM_FILE_NAME).toFile(); - } - - public Path getreferencingPlatformPath() { - try { - return new Path(this.myreferencingBoardsFile.getParent()); - } catch (@SuppressWarnings("unused") Exception e) { - return new Path(new String()); - } - } - - public File getreferencedPlatformFile() { - if (this.myReferencedCorePlatformPath == null) { - return null; - } - return this.myReferencedCorePlatformPath.append(Const.PLATFORM_FILE_NAME).toFile(); - } - - public IPath getReferencedLibraryPath() { - if (this.myReferencedCorePlatformPath == null) { - return null; - } - return this.myReferencedCorePlatformPath.append(LIBRARY_PATH_SUFFIX); - } - - public IPath getReferencingLibraryPath() { - return this.getreferencingPlatformPath().append(LIBRARY_PATH_SUFFIX); - } - - public String getUploadCommand(ICConfigurationDescription confdesc) { - String upLoadTool = getActualUploadTool(confdesc); - String action = "UPLOAD"; - if (usesProgrammer()) { - action = "PROGRAM"; - } - String networkPrefix = ""; - if (isNetworkUpload()) { - networkPrefix = "NETWORK_"; - } - String key = "A.TOOLS." + upLoadTool.toUpperCase() + "." - + action + "." + networkPrefix+"PATTERN"; - String ret = Common.getBuildEnvironmentVariable(confdesc, key, ""); - if (ret.isEmpty()) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, - key + " : not found in the platform.txt file")); - } - return ret; - } - - public String getActualUploadTool(ICConfigurationDescription confdesc) { - if (confdesc == null) { - Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Confdesc null is not alowed here")); - return this.myUploadTool; - } - if (usesProgrammer()) { - return Common.getBuildEnvironmentVariable(confdesc, "A.PROGRAM.TOOL", - "Program tool not properly configured"); - } - - if (this.myUploadTool == null) { - return Common.getBuildEnvironmentVariable(confdesc, "A.UPLOAD.TOOL", "upload tool not properly configured"); - } - - return this.myUploadTool; - } - - public boolean usesProgrammer() { - return !this.myProgrammer.equals(Defaults.getDefaultUploadProtocol()); - } - - public IPath getreferencedHardwarePath() { - IPath platformPath = getReferencedCorePlatformPath(); - return platformPath.removeLastSegments(1); - } - - /* - * get the latest installed arduino platform with the same architecture. - * This is the platform to use the programmers.txt if no other programmers.txt - * are found. - */ - public IPath getArduinoPlatformPath() { - return InternalPackageManager.getPlatformInstallPath("arduino", getArchitecture()); - } - - /** - * If the upload port contains a space everything before the first space is - * considered to be a dns name or ip adress. - * - * @param mComPort - * @return null if no space in uploadport - * return dns name op ipadress - */ - public String getHost() { - String host = myUploadPort.split(" ")[0]; - if (host.equals(myUploadPort)) - return null; - return host; - } - - /** - * true if this board needs a networkUpload else false - * - * @return - */ - public boolean isNetworkUpload() { - return getHost() != null; - } + */ + public IPath getReferencedCorePlatformPath() { + if (myReferencedCorePlatformPath != null) { + return myReferencedCorePlatformPath; + } + return getreferencingPlatformPath(); + } + + public IPath getReferencedUploadPlatformPath() { + if (myReferencedUploadToolPlatformPath != null) { + return myReferencedUploadToolPlatformPath; + } + return getreferencingPlatformPath(); + } + + public IPath getReferencedVariantPlatformPath() { + if (myReferencedBoardVariantPlatformPath != null) { + return myReferencedBoardVariantPlatformPath; + } + return getreferencingPlatformPath(); + } + + public File getReferencingPlatformFile() { + return getreferencingPlatformPath().append(Const.PLATFORM_FILE_NAME).toFile(); + } + + public Path getreferencingPlatformPath() { + try { + return new Path(this.myreferencingBoardsFile.getParent()); + } catch (@SuppressWarnings("unused") Exception e) { + return new Path(new String()); + } + } + + public File getreferencedPlatformFile() { + if (this.myReferencedCorePlatformPath == null) { + return null; + } + return this.myReferencedCorePlatformPath.append(Const.PLATFORM_FILE_NAME).toFile(); + } + + public IPath getReferencedLibraryPath() { + if (this.myReferencedCorePlatformPath == null) { + return null; + } + return this.myReferencedCorePlatformPath.append(LIBRARY_PATH_SUFFIX); + } + + public IPath getReferencingLibraryPath() { + return this.getreferencingPlatformPath().append(LIBRARY_PATH_SUFFIX); + } + + public String getUploadCommand(ICConfigurationDescription confdesc) { + String upLoadTool = getActualUploadTool(confdesc); + String action = "UPLOAD"; + if (usesProgrammer()) { + action = "PROGRAM"; + } + String networkPrefix = ""; + if (isNetworkUpload()) { + networkPrefix = "NETWORK_"; + } + String key = "A.TOOLS." + upLoadTool.toUpperCase() + "." + action + "." + networkPrefix + "PATTERN"; + String ret = Common.getBuildEnvironmentVariable(confdesc, key, ""); + if (ret.isEmpty()) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, key + " : not found in the platform.txt file")); + } + return ret; + } + + public String getActualUploadTool(ICConfigurationDescription confdesc) { + if (confdesc == null) { + Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Confdesc null is not alowed here")); + return this.myUploadTool; + } + if (usesProgrammer()) { + return Common.getBuildEnvironmentVariable(confdesc, "A.PROGRAM.TOOL", + "Program tool not properly configured"); + } + + if (this.myUploadTool == null) { + return Common.getBuildEnvironmentVariable(confdesc, "A.UPLOAD.TOOL", "upload tool not properly configured"); + } + + return this.myUploadTool; + } + + public boolean usesProgrammer() { + return !this.myProgrammer.equals(Defaults.getDefaultUploadProtocol()); + } + + public IPath getreferencedHardwarePath() { + IPath platformPath = getReferencedCorePlatformPath(); + return platformPath.removeLastSegments(1); + } + + /* + * get the latest installed arduino platform with the same architecture. This is + * the platform to use the programmers.txt if no other programmers.txt are + * found. + */ + public IPath getArduinoPlatformPath() { + return InternalPackageManager.getPlatformInstallPath("arduino", getArchitecture()); + } + + /** + * If the upload port contains a space everything before the first space is + * considered to be a dns name or ip adress. + * + * @param mComPort + * @return null if no space in uploadport return dns name op ipadress + */ + public String getHost() { + String host = myUploadPort.split(" ")[0]; + if (host.equals(myUploadPort)) + return null; + return host; + } + + /** + * true if this board needs a networkUpload else false + * + * @return + */ + public boolean isNetworkUpload() { + return getHost() != null; + } } 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 f95edd031..be799e663 100644 --- a/io.sloeber.core/src/io/sloeber/core/common/Common.java +++ b/io.sloeber.core/src/io/sloeber/core/common/Common.java @@ -71,13 +71,15 @@ public class Common extends Const { * 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 * * @param name * the string that needs to be checked * @return a name safe to create files or folders */ public static String MakeNameCompileSafe(String name) { - char[] badChars = { ' ', '/', '.',':', '\\', '(', ')', '*', '?', '%', '|', '<', '>', ',', '-' }; + char[] badChars = { ' ', '/', '.',':', '\\', '(', ')', '*', '?', '%', '|', '<', '>', ',', '-','#' }; String ret = name.trim(); for (char curchar : badChars) { 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 fd0f61e3e..bf2827f40 100644 --- a/io.sloeber.core/src/io/sloeber/core/tools/Helpers.java +++ b/io.sloeber.core/src/io/sloeber/core/tools/Helpers.java @@ -37,7 +37,6 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -103,8 +102,10 @@ public class Helpers extends Common { * @param configurationDescription * @param IncludePath */ - public static void addIncludeFolder(ICConfigurationDescription configurationDescription, IPath IncludePath) { - addIncludeFolder(configurationDescription, IncludePath, true); + + public static void addIncludeFolder(ICFolderDescription folderDescription, IPath IncludePath) + { + addIncludeFolder( folderDescription, IncludePath,true) ; } /** @@ -116,10 +117,7 @@ public static void addIncludeFolder(ICConfigurationDescription configurationDesc * @param IncludePath The path to add to the include folders * @see addLibraryDependency {@link #addLibraryDependency(IProject, IProject)} */ - public static void addIncludeFolder(ICConfigurationDescription configurationDescription, IPath IncludePath, - boolean isWorkspacePath) { - // find all languages - ICFolderDescription folderDescription = configurationDescription.getRootFolderDescription(); + public static void addIncludeFolder(ICFolderDescription folderDescription, IPath IncludePath,boolean isWorkspacePath) { ICLanguageSetting[] languageSettings = folderDescription.getLanguageSettings(); int pathSetting = ICSettingEntry.VALUE_WORKSPACE_PATH; if (!isWorkspacePath) { @@ -247,6 +245,7 @@ public static void LinkFolderToFolder(IProject project, IPath source, IPath targ public static void addCodeFolder(IProject project, IPath toLinkFolder, String LinkName, ICConfigurationDescription configurationDescription, boolean forceRoot) throws CoreException { IFolder link = project.getFolder(LinkName); + ICFolderDescription folderDescription = configurationDescription.getRootFolderDescription(); LinkFolderToFolder(project, toLinkFolder, new Path(LinkName)); @@ -256,19 +255,19 @@ public static void addCodeFolder(IProject project, IPath toLinkFolder, String Li String possibleIncludeFolder = "utility"; File file = toLinkFolder.append(possibleIncludeFolder).toFile(); if (file.exists()) { - addIncludeFolder(configurationDescription, link.getFullPath().append(possibleIncludeFolder)); + addIncludeFolder(folderDescription, link.getFullPath().append(possibleIncludeFolder)); } if (forceRoot) { - addIncludeFolder(configurationDescription, link.getFullPath()); + addIncludeFolder(folderDescription, link.getFullPath()); } else { // add src or root give priority to src possibleIncludeFolder = Library.LIBRARY_SOURCE_FODER; file = toLinkFolder.append(possibleIncludeFolder).toFile(); if (file.exists()) { - addIncludeFolder(configurationDescription, link.getFullPath().append(possibleIncludeFolder)); + addIncludeFolder(folderDescription, link.getFullPath().append(possibleIncludeFolder)); } else { - addIncludeFolder(configurationDescription, link.getFullPath()); + addIncludeFolder(folderDescription, link.getFullPath()); } } @@ -276,7 +275,7 @@ public static void addCodeFolder(IProject project, IPath toLinkFolder, String Li file = toLinkFolder.append(possibleIncludeFolder).toFile(); if (file.exists()) { InternalBoardDescriptor boardDescriptor = new InternalBoardDescriptor(configurationDescription); - addIncludeFolder(configurationDescription, + addIncludeFolder(folderDescription, link.getFullPath().append(possibleIncludeFolder).append(boardDescriptor.getArchitecture())); } } @@ -316,24 +315,6 @@ public static void addCodeFolder(IProject project, Path Path, ICConfigurationDes addCodeFolder(project, Path, NiceName, configurationDescription, forceRoot); } - /** - * addTheNatures replaces all existing natures by the natures needed for a - * arduino project - * - * @param project The project where the natures need to be added to - * @throws CoreException - */ - public static void addTheNatures(IProjectDescription description) throws CoreException { - - String[] newnatures = new String[5]; - newnatures[0] = "org.eclipse.cdt.core.cnature"; - newnatures[1] = "org.eclipse.cdt.core.ccnature"; - newnatures[2] = "org.eclipse.cdt.managedbuilder.core.managedBuildNature"; - newnatures[3] = "org.eclipse.cdt.managedbuilder.core.ScannerConfigNature"; - newnatures[4] = Const.ARDUINO_NATURE_ID; - description.setNatureIds(newnatures); - - } /** * This method adds the content of a content stream to a file If the file diff --git a/io.sloeber.core/src/io/sloeber/core/tools/ShouldHaveBeenInCDT.java b/io.sloeber.core/src/io/sloeber/core/tools/ShouldHaveBeenInCDT.java deleted file mode 100644 index 1f8bc589d..000000000 --- a/io.sloeber.core/src/io/sloeber/core/tools/ShouldHaveBeenInCDT.java +++ /dev/null @@ -1,136 +0,0 @@ -package io.sloeber.core.tools; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; -import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; -import org.eclipse.cdt.core.language.settings.providers.LanguageSettingsManager; -import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; -import org.eclipse.cdt.core.settings.model.ICProjectDescription; -import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; -import org.eclipse.cdt.core.settings.model.extension.CConfigurationData; -import org.eclipse.cdt.managedbuilder.core.IBuilder; -import org.eclipse.cdt.managedbuilder.core.IConfiguration; -import org.eclipse.cdt.managedbuilder.core.IToolChain; -import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; -import org.eclipse.cdt.managedbuilder.internal.core.Configuration; -import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo; -import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -import io.sloeber.core.api.ConfigurationDescriptor; - -@SuppressWarnings("restriction") -// TOFIX Get this code in CDT so I should not have to do this -public class ShouldHaveBeenInCDT { - /* - * Copied from wizard STDWizardHandler package package - * org.eclipse.cdt.managedbuilder.ui.wizards;; This method creates the - * .cProject file in your project. - * - * BK: modified this and made it work for multiple configs. - */ - /** - * This method creates the .cProject file in your project. it is intended to - * be used with newly created projects. Using this method with project that - * have existed for some time is unknown - * - * - * @param project - * The newly created project that needs a .cproject file. - * @param alCfgs - * An array-list of configuration descriptors (names, toolchain - * IDs) to be used with this project - * @param isManagedBuild - * When true the project is managed build. Else the project is - * not (read you have to maintain the makefiles yourself) - * @param monitor - * The monitor to follow the process - * @throws CoreException - */ - public static ICProjectDescription setCProjectDescription(IProject project, - ArrayList alCfgs, boolean isManagedBuild, boolean enableParallelBuild, IProgressMonitor monitor) - throws CoreException { - - ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); - ICProjectDescription des = mngr.createProjectDescription(project, false, true); - ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); - ManagedProject mProj = new ManagedProject(des); - info.setManagedProject(mProj); - monitor.worked(20); - - // Iterate across the configurations - for (ConfigurationDescriptor curConfDesc : alCfgs) { - IToolChain tcs = ManagedBuildManager.getExtensionToolChain(curConfDesc.ToolchainID); - - Configuration cfg = new Configuration(mProj, tcs, - ManagedBuildManager.calculateChildId(curConfDesc.ToolchainID, null), curConfDesc.configName); - if (enableParallelBuild) { - cfg.setParallelDef(true); - } - IBuilder bld = cfg.getEditableBuilder(); - if (bld != null) { - bld.setManagedBuildOn(isManagedBuild); - cfg.setArtifactName("${ProjName}"); //$NON-NLS-1$ - } else { - System.out.println("Messages.StdProjectTypeHandler_3"); //$NON-NLS-1$ - } - CConfigurationData data = cfg.getConfigurationData(); - ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data); - - setDefaultLanguageSettingsProviders(project, curConfDesc, cfg, cfgDes); - } - monitor.worked(50); - return des; - - } - - private static void setDefaultLanguageSettingsProviders(IProject project, ConfigurationDescriptor cfgDes, - IConfiguration cfg, ICConfigurationDescription cfgDescription) { - // propagate the preference to project properties - boolean isPreferenceEnabled = ScannerDiscoveryLegacySupport - .isLanguageSettingsProvidersFunctionalityEnabled(null); - ScannerDiscoveryLegacySupport.setLanguageSettingsProvidersFunctionalityEnabled(project, isPreferenceEnabled); - - if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) { - ILanguageSettingsProvidersKeeper lspk = (ILanguageSettingsProvidersKeeper) cfgDescription; - - lspk.setDefaultLanguageSettingsProvidersIds(new String[] { cfgDes.ToolchainID }); - - List providers = getDefaultLanguageSettingsProviders(cfg, cfgDescription); - lspk.setLanguageSettingProviders(providers); - } - } - - private static List getDefaultLanguageSettingsProviders(IConfiguration cfg, - ICConfigurationDescription cfgDescription) { - List providers = new ArrayList<>(); - String[] ids = cfg != null ? cfg.getDefaultLanguageSettingsProviderIds() : null; - - if (ids == null) { - // Try with legacy providers - ids = ScannerDiscoveryLegacySupport.getDefaultProviderIdsLegacy(cfgDescription); - } - - if (ids != null) { - for (String id : ids) { - ILanguageSettingsProvider provider = null; - if (!LanguageSettingsManager.isPreferShared(id)) { - provider = LanguageSettingsManager.getExtensionProviderCopy(id, false); - } - if (provider == null) { - provider = LanguageSettingsManager.getWorkspaceProvider(id); - } - providers.add(provider); - } - } - - return providers; - } - -} diff --git a/io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java b/io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java index 594900095..089678635 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java +++ b/io.sloeber.tests/src/io/sloeber/core/CompileAndUpload.java @@ -31,7 +31,6 @@ import io.sloeber.core.api.CodeDescriptor; import io.sloeber.core.api.CompileOptions; -import io.sloeber.core.api.ConfigurationDescriptor; import io.sloeber.core.api.PackageManager; import io.sloeber.core.api.Preferences; import io.sloeber.core.api.Sketch; @@ -155,9 +154,7 @@ public void Build_Verify_upload(CodeDescriptor codeDescriptor, try { theTestProject = this.myBoard.getBoardDescriptor().createProject( - projectName, null, - ConfigurationDescriptor.getDefaultDescriptors(), - codeDescriptor, compileOptions, monitor); + projectName, null, codeDescriptor, compileOptions, monitor); Shared.waitForAllJobsToFinish(); // for the indexer } catch (Exception e) { e.printStackTrace(); diff --git a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java index 50c33b842..226a6aa39 100644 --- a/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/CreateAndCompileDefaultInoOnAllBoardsTest.java @@ -24,129 +24,123 @@ 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 int myBuildCounter = 0; - private static int myTotalFails = 0; - private static int maxFails = 50; + // 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 BoardDescriptor 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", + private BoardDescriptor 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",}; - 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", - - //uses busybox so command line issues I think - "https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_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", - - }; - 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 - */ + // confirmed 2020 03 09 version 25 12 17 + "https://raw.githubusercontent.com/avandalen/SAM15x15/master/package_avdweb_nl_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", + + // uses busybox so command line issues I think + "https://github.com/tenbaht/sduino/raw/master/package_sduino_stm8_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", + + }; + 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", @@ -164,8 +158,7 @@ public class CreateAndCompileDefaultInoOnAllBoardsTest { "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://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", @@ -254,84 +247,85 @@ public class CreateAndCompileDefaultInoOnAllBoardsTest { "https://zevero.github.io/avr_boot/package_zevero_avr_boot_index.json", "http://adelino.cc/package_adelino_index.json", - }; - - public CreateAndCompileDefaultInoOnAllBoardsTest(BoardDescriptor board) { - this.mBoard = board; - } - - @SuppressWarnings("rawtypes") - @Parameters(name = "{index}: {0} ") - public static Collection boards() { - //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(BoardDescriptor.makeBoardDescriptors(curBoardFile, options)); - } - // to avoid warnings set the upload port to some value - for (BoardDescriptor 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 (BoardDescriptor 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()); - } + }; + + public CreateAndCompileDefaultInoOnAllBoardsTest(BoardDescriptor 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(BoardDescriptor.makeBoardDescriptors(curBoardFile, options)); + } + // to avoid warnings set the upload port to some value + for (BoardDescriptor 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 (BoardDescriptor 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(); @@ -339,24 +333,25 @@ public static void installAdditionalBoards() { // PackageManager.onlyKeepLatestPlatforms(); } - if (apply_known_work_Arounds) { - Shared.applyKnownWorkArounds(); - } - Shared.waitForAllJobsToFinish(); - } - - @Test - public void testBoard() { - 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, CodeDescriptor.createCustomTemplate(templateFolder),null,myBuildCounter)) { - myTotalFails++; - fail(Shared.getLastFailMessage() ); - } - - } + if (apply_known_work_Arounds) { + Shared.applyKnownWorkArounds(); + } + Shared.waitForAllJobsToFinish(); + } + + @Test + public void testBoard() { + 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, CodeDescriptor.createCustomTemplate(templateFolder), null, + myBuildCounter)) { + myTotalFails++; + fail(Shared.getLastFailMessage()); + } + + } } diff --git a/io.sloeber.tests/src/io/sloeber/core/RegressionTest.java b/io.sloeber.tests/src/io/sloeber/core/RegressionTest.java index 24eb867ba..2f71370bd 100644 --- a/io.sloeber.tests/src/io/sloeber/core/RegressionTest.java +++ b/io.sloeber.tests/src/io/sloeber/core/RegressionTest.java @@ -20,7 +20,6 @@ import io.sloeber.core.api.BoardDescriptor; import io.sloeber.core.api.CodeDescriptor; import io.sloeber.core.api.CompileOptions; -import io.sloeber.core.api.ConfigurationDescriptor; import io.sloeber.core.api.PackageManager; import io.sloeber.core.api.Preferences; import io.sloeber.providers.Arduino; @@ -89,7 +88,7 @@ public void issue555() { try { theTestProject = unoBoardid.createProject(projectName, null, - ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, new CompileOptions(null), monitor); + codeDescriptor, new CompileOptions(null), monitor); Shared.waitForAllJobsToFinish(); // for the indexer } catch (Exception e) { e.printStackTrace(); @@ -135,8 +134,7 @@ public void issue687() throws Exception { CodeDescriptor codeDescriptor = CodeDescriptor.createCustomTemplate(templateFolder); try { theTestProject = unoBoardid.createProject(projectName, null, - ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, new CompileOptions(null), - new NullProgressMonitor()); + codeDescriptor, new CompileOptions(null), new NullProgressMonitor()); Shared.waitForAllJobsToFinish(); // for the indexer theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); if (Shared.hasBuildErrors(theTestProject)) { @@ -164,8 +162,7 @@ public void issue1047_Board_Names_Can_Be_used_as_Strings() throws Exception { CodeDescriptor codeDescriptor = CodeDescriptor.createCustomTemplate(templateFolder); try { IProject theTestProject = unoBoard.getBoardDescriptor().createProject(projectName, null, - ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, new CompileOptions(null), - new NullProgressMonitor()); + codeDescriptor, new CompileOptions(null), new NullProgressMonitor()); Shared.waitForAllJobsToFinish(); // for the indexer theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor()); if (Shared.hasBuildErrors(theTestProject)) { @@ -207,7 +204,7 @@ public void are_jantjes_options_taken_into_account() throws Exception { compileOptions.set_C_CompileOptions("-DTEST_C"); compileOptions.set_CPP_CompileOptions("-DTEST_CPP"); theTestProject = unoBoardid.createProject(projectName, null, - ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, compileOptions, monitor); + codeDescriptor, compileOptions, monitor); ICProjectDescription prjCDesc = CoreModel.getDefault().getProjectDescription(theTestProject); CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(theTestProject, prjCDesc, true, @@ -246,7 +243,7 @@ public void are_defines_before_includes_taken_into_account() throws Exception { try { theTestProject = unoBoardid.createProject(projectName, null, - ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, new CompileOptions(null), monitor); + codeDescriptor, new CompileOptions(null), monitor); Shared.waitForAllJobsToFinish(); // for the indexer theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor); @@ -282,7 +279,7 @@ public void is_extern_C_taken_into_account() throws Exception { try { theTestProject = unoBoardid.createProject(projectName, null, - ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, new CompileOptions(null), monitor); + codeDescriptor, new CompileOptions(null), monitor); Shared.waitForAllJobsToFinish(); // for the indexer theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor); diff --git a/io.sloeber.tests/src/io/sloeber/core/Shared.java b/io.sloeber.tests/src/io/sloeber/core/Shared.java index a60c0be85..b33fdfd53 100644 --- a/io.sloeber.tests/src/io/sloeber/core/Shared.java +++ b/io.sloeber.tests/src/io/sloeber/core/Shared.java @@ -2,6 +2,7 @@ import static org.junit.Assert.fail; +import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; @@ -27,7 +28,6 @@ import io.sloeber.core.api.BoardDescriptor; import io.sloeber.core.api.CodeDescriptor; import io.sloeber.core.api.CompileOptions; -import io.sloeber.core.api.ConfigurationDescriptor; import io.sloeber.core.api.PackageManager; import io.sloeber.core.common.ConfigurationPreferences; import io.sloeber.providers.MCUBoard; @@ -37,7 +37,16 @@ public class Shared { public static boolean deleteProjects = true; private static int myLocalBuildCounter; private static int myTestCounter; - private static String myLastFailMessage=new String(); + private static String myLastFailMessage = new String(); + private static boolean closeFailedProjects; + + public static boolean isCloseFailedProjects() { + return closeFailedProjects; + } + + public static void setCloseFailedProjects(boolean closeFailedProjects) { + Shared.closeFailedProjects = closeFailedProjects; + } public static boolean hasBuildErrors(IProject project) throws CoreException { IMarker[] markers = project.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); @@ -46,7 +55,20 @@ public static boolean hasBuildErrors(IProject project) throws CoreException { return true; } } - return false; + IPath resultPath = project.getLocation().append("release"); + File elfFile = resultPath.append(project.getName() + ".elf").toFile(); + if (elfFile.exists()) { + return false; + } + File binFile = resultPath.append(project.getName() + ".bin").toFile(); + if (binFile.exists()) { + return false; + } + File hexFile = resultPath.append(project.getName() + ".hex").toFile(); + if (hexFile.exists()) { + return false; + } + return true; } public static void waitForAllJobsToFinish() { @@ -90,7 +112,7 @@ public static IPath getTemplateFolder(String templateName) { * @return true if build is successful otherwise false */ public static boolean BuildAndVerify(BoardDescriptor boardDescriptor, CodeDescriptor codeDescriptor) { - return BuildAndVerify(boardDescriptor, codeDescriptor, null,-1); + return BuildAndVerify(boardDescriptor, codeDescriptor, null, -1); } /** @@ -103,16 +125,16 @@ public static boolean BuildAndVerify(BoardDescriptor boardDescriptor, CodeDescri * @return true if build is successful otherwise false */ public static boolean BuildAndVerify(BoardDescriptor boardDescriptor, CodeDescriptor codeDescriptor, - CompileOptions compileOptions,int globalBuildCounter) { + CompileOptions compileOptions, int globalBuildCounter) { - int projectCounter=myLocalBuildCounter; - if(globalBuildCounter>=0) { - projectCounter=globalBuildCounter; + int projectCounter = myLocalBuildCounter; + if (globalBuildCounter >= 0) { + projectCounter = globalBuildCounter; } - String projectName = String.format("%05d_%s", Integer.valueOf(projectCounter ), boardDescriptor.getBoardID()); + String projectName = String.format("%05d_%s", Integer.valueOf(projectCounter), boardDescriptor.getBoardID()); if (codeDescriptor.getExampleName() != null) { if (codeDescriptor.getExamples().get(0).toOSString().toLowerCase().contains("libraries")) { - projectName = String.format("%05d_Library_%s_%s", Integer.valueOf(projectCounter ), + projectName = String.format("%05d_Library_%s_%s", Integer.valueOf(projectCounter), codeDescriptor.getLibraryName(), codeDescriptor.getExampleName()); } else { projectName = String.format("%05d_%s", Integer.valueOf(projectCounter), @@ -135,12 +157,11 @@ public static boolean BuildAndVerify(String projectName, BoardDescriptor boardDe try { compileOptions.setEnableParallelBuild(true); - theTestProject = boardDescriptor.createProject(projectName, null, - ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, compileOptions, monitor); + theTestProject = boardDescriptor.createProject(projectName, null, codeDescriptor, compileOptions, monitor); waitForAllJobsToFinish(); // for the indexer } catch (Exception e) { e.printStackTrace(); - myLastFailMessage= "Failed to create the project:" + projectName; + myLastFailMessage = "Failed to create the project:" + projectName; return false; } try { @@ -154,15 +175,17 @@ public static boolean BuildAndVerify(String projectName, BoardDescriptor boardDe Thread.sleep(2000); theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor); if (hasBuildErrors(theTestProject)) { - myLastFailMessage= "Failed to compile the project:" + projectName + " build errors"; - theTestProject.close(null); + myLastFailMessage = "Failed to compile the project:" + projectName + " build errors"; + if (closeFailedProjects) { + theTestProject.close(null); + } return false; } } } } catch (Exception e) { e.printStackTrace(); - myLastFailMessage= "Failed to compile the project:" + boardDescriptor.getBoardName() + " exception"; + myLastFailMessage = "Failed to compile the project:" + boardDescriptor.getBoardName() + " exception"; return false; } try { @@ -184,8 +207,7 @@ public static boolean BuildAndVerify(String projectName, BoardDescriptor boardDe public static void applyKnownWorkArounds() { java.nio.file.Path packageRoot = Paths.get(ConfigurationPreferences.getInstallationPathPackages().toOSString()); - - + /* * oak on linux comes with a esptool2 in a wrong folder. As it is only 1 file I * move the file @@ -220,14 +242,13 @@ public static void applyKnownWorkArounds() { } public static String getCounterName(String name) { - String counterName = String.format("%05d_%s", Integer.valueOf(myTestCounter++), name); + String counterName = String.format("%05d_%s", Integer.valueOf(myTestCounter++), name); return counterName; } - @SuppressWarnings("unused") public static String getProjectName(CodeDescriptor codeDescriptor, Examples example, MCUBoard board) { - return String.format("%05d_%s_%s", Integer.valueOf(myTestCounter++), codeDescriptor.getExampleName(), + return String.format("%05d_%s_%s", Integer.valueOf(myTestCounter++), codeDescriptor.getExampleName(), board.getBoardDescriptor().getBoardID()); } diff --git a/io.sloeber.ui/src/io/sloeber/ui/ExplorerLabelDecorator.java b/io.sloeber.ui/src/io/sloeber/ui/ExplorerLabelDecorator.java index f457217e8..ad92f51ee 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/ExplorerLabelDecorator.java +++ b/io.sloeber.ui/src/io/sloeber/ui/ExplorerLabelDecorator.java @@ -44,7 +44,7 @@ public Image decorateImage(Image image, Object element) { @Override public String decorateText(String text, Object element) { IProject proj = (IProject) element; - if (proj.isOpen()) { + if (proj.isOpen() && proj.getLocation().toFile().exists()) { if (Sketch.isSketch(proj)) { ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(proj); if (prjDesc == null) { diff --git a/io.sloeber.ui/src/io/sloeber/ui/wizard/newsketch/NewSketchWizard.java b/io.sloeber.ui/src/io/sloeber/ui/wizard/newsketch/NewSketchWizard.java index 4fe1db148..29687adc1 100644 --- a/io.sloeber.ui/src/io/sloeber/ui/wizard/newsketch/NewSketchWizard.java +++ b/io.sloeber.ui/src/io/sloeber/ui/wizard/newsketch/NewSketchWizard.java @@ -23,7 +23,6 @@ import io.sloeber.core.api.BoardDescriptor; import io.sloeber.core.api.CodeDescriptor; import io.sloeber.core.api.CompileOptions; -import io.sloeber.core.api.ConfigurationDescriptor; import io.sloeber.ui.Activator; import io.sloeber.ui.Messages; import io.sloeber.ui.helpers.MyPreferences; @@ -126,8 +125,7 @@ protected void createProjectWrapper(IProgressMonitor monitor) { compileOptions.setEnableParallelBuild(MyPreferences.getEnableParallelBuildForNewProjects()); this.mProject = boardID.createProject(this.mWizardPage.getProjectName(), (!this.mWizardPage.useDefaults()) ? this.mWizardPage.getLocationURI() : null, - ConfigurationDescriptor.getDefaultDescriptors(), codeDescription, compileOptions, - monitor); + codeDescription, compileOptions, monitor); } catch (Exception e) { this.mProject = null;