From 84de9d2a69139cec24892d1885b660cc47e99eba Mon Sep 17 00:00:00 2001 From: alirana01 Date: Tue, 17 Oct 2023 12:08:27 +0200 Subject: [PATCH] IEP-897: refactoring and installing freertos-gdb package --- .../idf/core/tools/util/Messages.java | 27 ++ .../idf/core/tools/util/ToolsUtility.java | 268 +++++++++++++++++- .../idf/core/tools/util/messages.properties | 7 + .../com/espressif/idf/ui/tools/Messages.java | 7 - .../ui/tools/ToolsInstallationHandler.java | 135 +-------- .../idf/ui/tools/messages.properties | 7 - .../idf/ui/update/InstallToolsHandler.java | 94 +----- .../com/espressif/idf/ui/update/Messages.java | 1 + .../idf/ui/update/messages.properties | 1 + 9 files changed, 305 insertions(+), 242 deletions(-) create mode 100644 bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/Messages.java create mode 100644 bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/messages.properties diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/Messages.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/Messages.java new file mode 100644 index 000000000..a092c35dc --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/Messages.java @@ -0,0 +1,27 @@ +package com.espressif.idf.core.tools.util; + +import org.eclipse.osgi.util.NLS; + +public class Messages extends NLS +{ + private static final String BUNDLE_NAME = "com.espressif.idf.core.tools.util.messages"; //$NON-NLS-1$ + + + public static String InstallToolsHandler_CopyingOpenOCDRules; + public static String InstallToolsHandler_OpenOCDRulesCopied; + public static String InstallToolsHandler_OpenOCDRulesCopyError; + public static String InstallToolsHandler_OpenOCDRulesCopyPaths; + public static String InstallToolsHandler_OpenOCDRulesCopyWarning; + public static String InstallToolsHandler_OpenOCDRulesCopyWarningMessage; + public static String InstallToolsHandler_OpenOCDRulesNotCopied; + + static + { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() + { + } +} diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/ToolsUtility.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/ToolsUtility.java index 6c4479a43..2d001d729 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/ToolsUtility.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/ToolsUtility.java @@ -16,9 +16,12 @@ import java.nio.file.StandardCopyOption; import java.security.MessageDigest; import java.text.DecimalFormat; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Queue; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; @@ -28,15 +31,23 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.compress.utils.IOUtils; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MessageBox; import org.tukaani.xz.XZInputStream; +import com.espressif.idf.core.IDFConstants; +import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFEnvironmentVariables; +import com.espressif.idf.core.ProcessBuilderFactory; import com.espressif.idf.core.SystemExecutableFinder; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.tools.ToolsSystemWrapper; import com.espressif.idf.core.tools.vo.ToolsVO; import com.espressif.idf.core.util.FileUtil; +import com.espressif.idf.core.util.IDFUtil; import com.espressif.idf.core.util.StringUtil; /** @@ -79,7 +90,7 @@ public static boolean isToolInstalled(String toolName, String versionsName) } } } - + return false; } @@ -149,7 +160,7 @@ public static void extractTarGz(String tarFile, String outputDir) { TarArchiveInputStream tararchiveinputstream = new TarArchiveInputStream( new GzipCompressorInputStream(new BufferedInputStream(Files.newInputStream(pathInput)))); - + ArchiveEntry archiveentry = null; while ((archiveentry = tararchiveinputstream.getNextEntry()) != null) { @@ -165,7 +176,7 @@ public static void extractTarGz(String tarFile, String outputDir) Files.copy(tararchiveinputstream, pathEntryOutput, StandardCopyOption.REPLACE_EXISTING); Runtime.getRuntime().exec("/bin/chmod 755 ".concat(pathEntryOutput.toString())); //$NON-NLS-1$ } - + } tararchiveinputstream.close(); @@ -175,7 +186,7 @@ public static void extractTarGz(String tarFile, String outputDir) Logger.log(e); } } - + public static void extractTarXz(String tarFile, String outputDir) { Path pathOutput = Paths.get(outputDir); @@ -199,8 +210,7 @@ public static void extractTarXz(String tarFile, String outputDir) } else if (archiveentry.isLink()) { - hardLinks.put(pathEntryOutput, - pathOutput.resolve(archiveentry.getLinkName())); + hardLinks.put(pathEntryOutput, pathOutput.resolve(archiveentry.getLinkName())); continue; } else if (archiveentry.isDirectory()) @@ -226,7 +236,7 @@ else if (archiveentry.isDirectory()) Logger.log(e); } } - + private static void createHardLinks(Path link, Path target) { try @@ -307,11 +317,12 @@ public static String getFileChecksum(MessageDigest digest, File file) throws IOE } return sb.toString(); } - + /** * Gets the absolute path for the tool from the given path + * * @param toolName tool to find absolute path - * @param path the path to variable to look into, if null System.getenv() will be used + * @param path the path to variable to look into, if null System.getenv() will be used * @return absolute path to the tool */ public static IPath findAbsoluteToolPath(String toolName, String path) @@ -319,13 +330,248 @@ public static IPath findAbsoluteToolPath(String toolName, String path) if (StringUtil.isEmpty(path)) { Map env = System.getenv(); - if (env.containsKey(IDFEnvironmentVariables.PATH)) + if (env.containsKey(IDFEnvironmentVariables.PATH)) path = env.get(IDFEnvironmentVariables.PATH); else path = env.get("Path"); //$NON-NLS-1$ } - + SystemExecutableFinder systemExecutableFinder = new SystemExecutableFinder(new ToolsSystemWrapper(path)); return systemExecutableFinder.find(toolName); } + + public static void installWebSocketClientPipPackage(Queue logQueue) + { + String websocketclient = "websocket-client"; //$NON-NLS-1$ + final String pythonEnvPath = IDFUtil.getIDFPythonEnvPath(); + if (pythonEnvPath == null || !new File(pythonEnvPath).exists()) + { + if (logQueue != null) + { + logQueue.add( + String.format("%s executable not found. Unable to run `%s -m pip install websocket-client`", //$NON-NLS-1$ + IDFConstants.PYTHON_CMD, IDFConstants.PYTHON_CMD)); + } + + return; + } + + List arguments = getPipInstallCommand(pythonEnvPath); + arguments.add(websocketclient); + + ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); + + try + { + String cmdMsg = "Executing " + getCommandString(arguments); //$NON-NLS-1$ + if (logQueue != null) + { + logQueue.add(cmdMsg); + } + Logger.log(cmdMsg); + + Map environment = new HashMap<>(System.getenv()); + Logger.log(environment.toString()); + + IStatus status = processRunner.runInBackground(arguments, org.eclipse.core.runtime.Path.ROOT, environment); + if (status == null) + { + Logger.log(IDFCorePlugin.getPlugin(), + IDFCorePlugin.errorStatus("Unable to get the process status.", null)); //$NON-NLS-1$ + if (logQueue != null) + { + logQueue.add("Unable to get the process status."); //$NON-NLS-1$ + } + return; + } + if (logQueue != null) + { + logQueue.add(status.getMessage()); + } + + } + catch (Exception e1) + { + Logger.log(IDFCorePlugin.getPlugin(), e1); + if (logQueue != null) + { + logQueue.add(e1.getLocalizedMessage()); + } + + } + } + + public static void installFreertosGdbPipPackage(Queue logQueue) + { + String freeRtosGdb = "freertos-gdb"; //$NON-NLS-1$ + final String pythonEnvPath = IDFUtil.getIDFPythonEnvPath(); + if (pythonEnvPath == null || !new File(pythonEnvPath).exists()) + { + if (logQueue != null) + { + logQueue.add( + String.format("%s executable not found. Unable to run `%s -m pip install websocket-client`", //$NON-NLS-1$ + IDFConstants.PYTHON_CMD, IDFConstants.PYTHON_CMD)); + } + + return; + } + + List arguments = getPipInstallCommand(pythonEnvPath); + arguments.add(freeRtosGdb); + + ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); + + try + { + String cmdMsg = "Executing " + getCommandString(arguments); //$NON-NLS-1$ + if (logQueue != null) + { + logQueue.add(cmdMsg); + } + Logger.log(cmdMsg); + + Map environment = new HashMap<>(System.getenv()); + Logger.log(environment.toString()); + + IStatus status = processRunner.runInBackground(arguments, org.eclipse.core.runtime.Path.ROOT, environment); + if (status == null) + { + Logger.log(IDFCorePlugin.getPlugin(), + IDFCorePlugin.errorStatus("Unable to get the process status.", null)); //$NON-NLS-1$ + if (logQueue != null) + { + logQueue.add("Unable to get the process status."); //$NON-NLS-1$ + } + return; + } + if (logQueue != null) + { + logQueue.add(status.getMessage()); + } + + } + catch (Exception e1) + { + Logger.log(IDFCorePlugin.getPlugin(), e1); + if (logQueue != null) + { + logQueue.add(e1.getLocalizedMessage()); + } + + } + } + + private static List getPipInstallCommand(String pythonPath) + { + List arguments = new ArrayList(); + arguments.add(pythonPath); + arguments.add("-m"); //$NON-NLS-1$ + arguments.add("pip"); //$NON-NLS-1$ + + arguments.add("install"); //$NON-NLS-1$ + return arguments; + } + + private static String getCommandString(List arguments) + { + StringBuilder builder = new StringBuilder(); + arguments.forEach(entry -> builder.append(entry + " ")); //$NON-NLS-1$ + + return builder.toString().trim(); + } + + public static void configureRequiredEnvVars(IDFEnvironmentVariables idfEnvironmentVariables) + { + if (idfEnvironmentVariables == null) + { + idfEnvironmentVariables = new IDFEnvironmentVariables(); + } + // Enable IDF_COMPONENT_MANAGER by default + idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER, "1"); //$NON-NLS-1$ + // IDF_MAINTAINER=1 to be able to build with the clang toolchain + idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_MAINTAINER, "1"); //$NON-NLS-1$ + } + + public static void copyOpenOcdRules(Queue logQueue) + { + if (Platform.getOS().equals(Platform.OS_LINUX) + && !IDFUtil.getOpenOCDLocation().equalsIgnoreCase(StringUtil.EMPTY)) + { + Logger.log("Copying OpenOCD Rules"); //$NON-NLS-1$ + if (logQueue != null) + { + logQueue.add(Messages.InstallToolsHandler_CopyingOpenOCDRules); + } + // Copy the rules to the idf + StringBuilder pathToRules = new StringBuilder(); + pathToRules.append(IDFUtil.getOpenOCDLocation()); + pathToRules.append("/../share/openocd/contrib/60-openocd.rules"); //$NON-NLS-1$ + File rulesFile = new File(pathToRules.toString()); + if (rulesFile.exists()) + { + Path source = Paths.get(pathToRules.toString()); + Path target = Paths.get("/etc/udev/rules.d/60-openocd.rules"); //$NON-NLS-1$ + Logger.log(String.format("Copying File: %s to destination: %s", source.toString(), //$NON-NLS-1$ + target.toString())); + if (logQueue != null) + { + logQueue.add(String.format(Messages.InstallToolsHandler_OpenOCDRulesCopyPaths, source.toString(), + target.toString())); + } + + Display.getDefault().syncExec(new Runnable() + { + @Override + public void run() + { + try + { + if (target.toFile().exists()) + { + MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(), + SWT.ICON_WARNING | SWT.YES | SWT.NO); + messageBox.setText(Messages.InstallToolsHandler_OpenOCDRulesCopyWarning); + messageBox.setMessage(Messages.InstallToolsHandler_OpenOCDRulesCopyWarningMessage); + int response = messageBox.open(); + if (response == SWT.YES) + { + Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); + } + else + { + Logger.log("Rules Not Copied to system"); //$NON-NLS-1$ + if (logQueue != null) + { + logQueue.add(Messages.InstallToolsHandler_OpenOCDRulesNotCopied); + } + return; + } + } + else + { + Files.copy(source, target); + } + + Logger.log("Rules Copied to system"); //$NON-NLS-1$ + if (logQueue != null) + { + logQueue.add(Messages.InstallToolsHandler_OpenOCDRulesCopied); + } + } + catch (IOException e) + { + Logger.log(e); + Logger.log("Unable to copy rules for OpenOCD to system directory, try running the eclipse with sudo command"); //$NON-NLS-1$ + if (logQueue != null) + { + logQueue.add(Messages.InstallToolsHandler_OpenOCDRulesCopyError); + } + } + } + }); + } + } + } + } diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/messages.properties b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/messages.properties new file mode 100644 index 000000000..a00a49d19 --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/tools/util/messages.properties @@ -0,0 +1,7 @@ +InstallToolsHandler_CopyingOpenOCDRules=Copying OpenOCD Rules +InstallToolsHandler_OpenOCDRulesCopied=Rules Copied to system +InstallToolsHandler_OpenOCDRulesNotCopied=Rules Not Copied to system +InstallToolsHandler_OpenOCDRulesCopyPaths=Copying File: %s to destination: %s +InstallToolsHandler_OpenOCDRulesCopyError=Unable to copy rules for OpenOCD to system directory, try running the eclipse with sudo command +InstallToolsHandler_OpenOCDRulesCopyWarning=Warning +InstallToolsHandler_OpenOCDRulesCopyWarningMessage=The rules file is already present in the /etc/udev/rules.d/ directory, Do you want to replace the file with the file from OpenOCD directory diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/Messages.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/Messages.java index a2bf5e032..40bed6f50 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/Messages.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/Messages.java @@ -71,13 +71,6 @@ public class Messages extends NLS public static String IDFDownloadWizard_UpdatingIDFPathMessage; public static String BtnCancel; public static String OperationCancelledByUser; - public static String InstallToolsHandler_CopyingOpenOCDRules; - public static String InstallToolsHandler_OpenOCDRulesCopied; - public static String InstallToolsHandler_OpenOCDRulesCopyError; - public static String InstallToolsHandler_OpenOCDRulesCopyPaths; - public static String InstallToolsHandler_OpenOCDRulesCopyWarning; - public static String InstallToolsHandler_OpenOCDRulesCopyWarningMessage; - public static String InstallToolsHandler_OpenOCDRulesNotCopied; public static String AbstractToolsHandler_ExecutingMsg; public static String ToolAreadyPresent; public static String ForceDownload_ToolTip; diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationHandler.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationHandler.java index f5e24de5e..2d928d9e0 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationHandler.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsInstallationHandler.java @@ -11,10 +11,8 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.security.MessageDigest; import java.text.MessageFormat; import java.util.ArrayList; @@ -31,9 +29,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.MessageBox; import org.osgi.service.prefs.Preferences; import com.espressif.idf.core.IDFConstants; @@ -573,9 +568,10 @@ public Boolean call() throws Exception runPythonEnvCommand(); runToolsExport(idfEnvironmentVariables.getEnvValue(IDFEnvironmentVariables.GIT_PATH)); new ESPToolChainManager().configureToolChain(); - configEnv(); - handleWebSocketClientInstall(); - copyOpenOcdRules(); + ToolsUtility.configureRequiredEnvVars(idfEnvironmentVariables); + ToolsUtility.installWebSocketClientPipPackage(logQueue); + ToolsUtility.installFreertosGdbPipPackage(logQueue); + ToolsUtility.copyOpenOcdRules(logQueue); IDFUtil.updateEspressifPrefPageOpenocdPath(); validateToolsInstall(); scopedPreferenceStore.putBoolean(InstallToolsHandler.INSTALL_TOOLS_FLAG, true); @@ -659,14 +655,6 @@ else if (environment.containsKey("Path")) }); } - private void configEnv() - { - // Enable IDF_COMPONENT_MANAGER by default - idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER, "1"); - // IDF_MAINTAINER=1 to be able to build with the clang toolchain - idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.IDF_MAINTAINER, "1"); - } - private void runToolsExport(final String gitExePath) { final List arguments = new ArrayList<>(); @@ -866,72 +854,6 @@ else if (environment.containsKey("Path")) idfEnvironmentVariables.addEnvVariable(IDFEnvironmentVariables.PATH, paths.toString()); } - private void copyOpenOcdRules() - { - if (Platform.getOS().equals(Platform.OS_LINUX) - && !IDFUtil.getOpenOCDLocation().equalsIgnoreCase(StringUtil.EMPTY)) - { - Logger.log(Messages.InstallToolsHandler_CopyingOpenOCDRules); - logQueue.add(Messages.InstallToolsHandler_CopyingOpenOCDRules); - // Copy the rules to the idf - StringBuilder pathToRules = new StringBuilder(); - pathToRules.append(IDFUtil.getOpenOCDLocation()); - pathToRules.append("/../share/openocd/contrib/60-openocd.rules"); //$NON-NLS-1$ - File rulesFile = new File(pathToRules.toString()); - if (rulesFile.exists()) - { - Path source = Paths.get(pathToRules.toString()); - Path target = Paths.get("/etc/udev/rules.d/60-openocd.rules"); //$NON-NLS-1$ - Logger.log(String.format(Messages.InstallToolsHandler_OpenOCDRulesCopyPaths, source.toString(), - target.toString())); - logQueue.add(String.format(Messages.InstallToolsHandler_OpenOCDRulesCopyPaths, source.toString(), - target.toString())); - - Display.getDefault().syncExec(new Runnable() - { - @Override - public void run() - { - try - { - if (target.toFile().exists()) - { - MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(), - SWT.ICON_WARNING | SWT.YES | SWT.NO); - messageBox.setText(Messages.InstallToolsHandler_OpenOCDRulesCopyWarning); - messageBox.setMessage(Messages.InstallToolsHandler_OpenOCDRulesCopyWarningMessage); - int response = messageBox.open(); - if (response == SWT.YES) - { - Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); - } - else - { - Logger.log(Messages.InstallToolsHandler_OpenOCDRulesNotCopied); - logQueue.add(Messages.InstallToolsHandler_OpenOCDRulesNotCopied); - return; - } - } - else - { - Files.copy(source, target); - } - - Logger.log(Messages.InstallToolsHandler_OpenOCDRulesCopied); - logQueue.add(Messages.InstallToolsHandler_OpenOCDRulesCopied); - } - catch (IOException e) - { - Logger.log(e); - Logger.log(Messages.InstallToolsHandler_OpenOCDRulesCopyError); - logQueue.add(Messages.InstallToolsHandler_OpenOCDRulesCopyError); - } - } - }); - } - } - } - private String getCommandString(List arguments) { StringBuilder builder = new StringBuilder(); @@ -979,55 +901,6 @@ private void runPythonEnvCommand() } } - private void handleWebSocketClientInstall() - { - List arguments = new ArrayList(); - final String pythonEnvPath = IDFUtil.getIDFPythonEnvPath(); - if (pythonEnvPath == null || !new File(pythonEnvPath).exists()) - { - logQueue.add( - String.format("%s executable not found. Unable to run `%s -m pip install websocket-client`", //$NON-NLS-1$ - IDFConstants.PYTHON_CMD, IDFConstants.PYTHON_CMD)); - return; - } - arguments.add(pythonEnvPath); - arguments.add("-m"); //$NON-NLS-1$ - arguments.add("pip"); //$NON-NLS-1$ - - arguments.add("install"); //$NON-NLS-1$ - arguments.add("websocket-client"); //$NON-NLS-1$ - - ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); - - try - { - String cmdMsg = "Executing " + getCommandString(arguments); //$NON-NLS-1$ - logQueue.add(cmdMsg); - Logger.log(cmdMsg); - - Map environment = new HashMap<>(System.getenv()); - Logger.log(environment.toString()); - - IStatus status = processRunner.runInBackground(arguments, org.eclipse.core.runtime.Path.ROOT, - environment); - if (status == null) - { - Logger.log(IDFCorePlugin.getPlugin(), - IDFCorePlugin.errorStatus("Unable to get the process status.", null)); //$NON-NLS-1$ - logQueue.add("Unable to get the process status."); - return; - } - - logQueue.add(status.getMessage()); - - } - catch (Exception e1) - { - Logger.log(IDFCorePlugin.getPlugin(), e1); - logQueue.add(e1.getLocalizedMessage()); - - } - } } private class DeleteToolsThread implements Callable diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/messages.properties b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/messages.properties index 017182328..f043bddbf 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/messages.properties +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/messages.properties @@ -70,13 +70,6 @@ IDFDownloadWizard_DecompressingCompleted=Archive extracted! IDFDownloadWizard_UpdatingIDFPathMessage=Updating IDF_PATH to: {0} BtnCancel=Cancel OperationCancelledByUser=Operation is cancelled by the user! -InstallToolsHandler_CopyingOpenOCDRules=Copying OpenOCD Rules -InstallToolsHandler_OpenOCDRulesCopied=Rules Copied to system -InstallToolsHandler_OpenOCDRulesNotCopied=Rules Not Copied to system -InstallToolsHandler_OpenOCDRulesCopyPaths=Copying File: %s to destination: %s -InstallToolsHandler_OpenOCDRulesCopyError=Unable to copy rules for OpenOCD to system directory, try running the eclipse with sudo command -InstallToolsHandler_OpenOCDRulesCopyWarning=Warning -InstallToolsHandler_OpenOCDRulesCopyWarningMessage=The rules file is already present in the /etc/udev/rules.d/ directory, Do you want to replace the file with the file from OpenOCD directory AbstractToolsHandler_ExecutingMsg=Executing ToolAreadyPresent=Tool already present in ESPRESSIF home directory. ForceDownloadToolTip=Downloads the tools again even if they are already downloaded in ESPRESSIF home directory. diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/InstallToolsHandler.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/InstallToolsHandler.java index 58d2617af..9c3bd9cf6 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/InstallToolsHandler.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/InstallToolsHandler.java @@ -5,11 +5,6 @@ package com.espressif.idf.ui.update; import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -18,15 +13,11 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.IJobChangeListener; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.MessageBox; import org.eclipse.ui.console.MessageConsoleStream; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; @@ -37,8 +28,8 @@ import com.espressif.idf.core.ProcessBuilderFactory; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.toolchain.ESPToolChainManager; +import com.espressif.idf.core.tools.util.ToolsUtility; import com.espressif.idf.core.util.IDFUtil; -import com.espressif.idf.core.util.StringUtil; import com.espressif.idf.ui.UIPlugin; /** @@ -94,13 +85,17 @@ protected IStatus run(IProgressMonitor monitor) new ESPToolChainManager().configureToolChain(); monitor.worked(1); - configEnv(); + ToolsUtility.configureRequiredEnvVars(null); monitor.setTaskName(Messages.InstallToolsHandler_InstallingWebscoketMsg); - handleWebSocketClientInstall(); + ToolsUtility.installWebSocketClientPipPackage(null); monitor.worked(1); - copyOpenOcdRules(); + monitor.setTaskName(Messages.InstallToolsHandler_InstallingFreeRtosGdbtMsg); + ToolsUtility.installFreertosGdbPipPackage(null); + monitor.worked(1); + + ToolsUtility.copyOpenOcdRules(null); console.println(Messages.InstallToolsHandler_ConfiguredCMakeMsg); console.println(Messages.InstallToolsHandler_ToolsCompleted); @@ -121,79 +116,6 @@ protected IStatus run(IProgressMonitor monitor) installToolsJob.schedule(); } - /** - * Configure all the required environment variables here - */ - protected void configEnv() - { - IDFEnvironmentVariables idfEnvMgr = new IDFEnvironmentVariables(); - - // Enable IDF_COMPONENT_MANAGER by default - idfEnvMgr.addEnvVariable(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER, "1"); - // IDF_MAINTAINER=1 to be able to build with the clang toolchain - idfEnvMgr.addEnvVariable(IDFEnvironmentVariables.IDF_MAINTAINER, "1"); - - } - - private void copyOpenOcdRules() - { - if (Platform.getOS().equals(Platform.OS_LINUX) - && !IDFUtil.getOpenOCDLocation().equalsIgnoreCase(StringUtil.EMPTY)) - { - console.println(Messages.InstallToolsHandler_CopyingOpenOCDRules); - // Copy the rules to the idf - StringBuilder pathToRules = new StringBuilder(); - pathToRules.append(IDFUtil.getOpenOCDLocation()); - pathToRules.append("/../share/openocd/contrib/60-openocd.rules"); //$NON-NLS-1$ - File rulesFile = new File(pathToRules.toString()); - if (rulesFile.exists()) - { - Path source = Paths.get(pathToRules.toString()); - Path target = Paths.get("/etc/udev/rules.d/60-openocd.rules"); //$NON-NLS-1$ - console.println(String.format(Messages.InstallToolsHandler_OpenOCDRulesCopyPaths, source.toString(), - target.toString())); - - Display.getDefault().syncExec(new Runnable() - { - @Override - public void run() - { - try - { - if (target.toFile().exists()) - { - MessageBox messageBox = new MessageBox(Display.getDefault().getActiveShell(), - SWT.ICON_WARNING | SWT.YES | SWT.NO); - messageBox.setText(Messages.InstallToolsHandler_OpenOCDRulesCopyWarning); - messageBox.setMessage(Messages.InstallToolsHandler_OpenOCDRulesCopyWarningMessage); - int response = messageBox.open(); - if (response == SWT.YES) - { - Files.copy(source, target, StandardCopyOption.REPLACE_EXISTING); - } - else - { - console.println(Messages.InstallToolsHandler_OpenOCDRulesNotCopied); - return; - } - } - else - { - Files.copy(source, target); - } - - console.println(Messages.InstallToolsHandler_OpenOCDRulesCopied); - } - catch (IOException e) - { - Logger.log(e); - errorConsoleStream.println(Messages.InstallToolsHandler_OpenOCDRulesCopyError); - } - } - }); - } - } - } protected IStatus handleToolsInstall() { diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/Messages.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/Messages.java index 6eee46609..858c814a0 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/Messages.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/Messages.java @@ -30,6 +30,7 @@ public class Messages extends NLS public static String InstallToolsHandler_ExportingPathsMsg; public static String InstallToolsHandler_InstallingPythonMsg; public static String InstallToolsHandler_InstallingWebscoketMsg; + public static String InstallToolsHandler_InstallingFreeRtosGdbtMsg; public static String InstallToolsHandler_InstallingToolsMsg; public static String InstallToolsHandler_ItWilltakeTimeMsg; public static String InstallToolsHandler_ToolsCompleted; diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/messages.properties b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/messages.properties index 03336ab14..cf0443c20 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/messages.properties +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/messages.properties @@ -23,6 +23,7 @@ InstallToolsHandler_ConfiguredCMakeMsg=Configured CMake toolchain. You can check InstallToolsHandler_ExportingPathsMsg=Exporting and processing tools paths InstallToolsHandler_InstallingPythonMsg=Installing Python InstallToolsHandler_InstallingWebscoketMsg=Installing websocket_client +InstallToolsHandler_InstallingFreeRtosGdbtMsg=Installing freertos-gdb InstallToolsHandler_InstallingToolsMsg=Installing tools... InstallToolsHandler_ItWilltakeTimeMsg=This can take a while. Please be patient. InstallToolsHandler_ToolsCompleted=Install tools completed.