From ebf8111edbdafe4f7afd1232197fd3da906da1b5 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Mon, 16 Sep 2024 19:38:36 +0300 Subject: [PATCH 1/7] feat: running idf.py reconfigure after project creation --- .../idf/ui/wizard/NewIDFProjectWizard.java | 146 +++++++++++++++++- 1 file changed, 145 insertions(+), 1 deletion(-) diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java index d43476490..d2afdad6e 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java @@ -4,14 +4,22 @@ *******************************************************************************/ package com.espressif.idf.ui.wizard; +import java.io.BufferedReader; import java.io.File; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.eclipse.cdt.debug.internal.core.InternalDebugCoreMessages; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; 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.Job; import org.eclipse.debug.core.DebugPlugin; @@ -34,14 +42,22 @@ import org.eclipse.tools.templates.ui.TemplateWizard; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; import com.espressif.idf.core.IDFConstants; import com.espressif.idf.core.LaunchBarTargetConstants; +import com.espressif.idf.core.IDFCorePlugin; +import com.espressif.idf.core.IDFEnvironmentVariables; +import com.espressif.idf.core.ProcessBuilderFactory; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.ClangFormatFileHandler; import com.espressif.idf.core.util.ClangdConfigFileHandler; +import com.espressif.idf.core.util.IDFUtil; import com.espressif.idf.core.util.LaunchUtil; import com.espressif.idf.ui.UIPlugin; import com.espressif.idf.ui.handlers.EclipseHandler; @@ -62,6 +78,8 @@ public class NewIDFProjectWizard extends TemplateWizard private static final String NEW_LAUNCH_CONFIG_EDIT_PAGE = "NewLaunchConfigEditPage"; //$NON-NLS-1$ public static final String TARGET_SWITCH_JOB = "TARGET SWITCH JOB"; //$NON-NLS-1$ private NewProjectCreationWizardPage projectCreationWizardPage; + private IProject project; + private MessageConsole console; public NewIDFProjectWizard() { @@ -110,7 +128,7 @@ public boolean performFinish() { ISelectionProvider selProvider = viewPart.getSite().getSelectionProvider(); String projectName = projectCreationWizardPage.getProjectName(); - IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); + project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); selProvider.setSelection(new StructuredSelection(project)); updateClangFiles(project); } @@ -139,10 +157,136 @@ public boolean performFinish() { Logger.log(e); } + Job job = new Job("Running idf.py reconfigure command...") + { + + protected IStatus run(IProgressMonitor monitor) + { + IStatus status = runCommandIdfPyInIdfEnv(target); + try + { + IDEWorkbenchPlugin.getPluginWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null); + } + catch (CoreException e) + { + Logger.log(e); + } + return status; + } + }; + job.schedule(); }); return performFinish; } + protected IStatus runCommandIdfPyInIdfEnv(String target) + { + openConsole("CDT Build Console"); //$NON-NLS-1$ + console.activate(); + MessageConsoleStream messageConsoleStream = console.newMessageStream(); + ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); + StringBuilder output = new StringBuilder(); + int waitCount = 10; + List arguments = new ArrayList(); + try + { + arguments.add(0, pythonVirtualExecutablePath()); + arguments.add(1, IDFUtil.getIDFPythonScriptFile().getAbsolutePath()); + arguments.add("-DIDF_TARGET=" + target); //$NON-NLS-1$ + arguments.add("reconfigure"); //$NON-NLS-1$ + + Map environment = new HashMap<>(new IDFEnvironmentVariables().getEnvMap()); + Logger.log(environment.toString()); + Process process = processRunner.run(arguments, project.getLocation(), environment); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line; + while ((line = reader.readLine()) != null) + { + output.append(line).append(System.lineSeparator()); + messageConsoleStream.println(line); + messageConsoleStream.flush(); + } + + while (process.isAlive() && waitCount > 0) + { + try + { + Thread.sleep(300); + } + catch (InterruptedException e) + { + Logger.log(e); + } + waitCount--; + } + + if (waitCount == 0) + { + messageConsoleStream.println("Process possibly stuck"); //$NON-NLS-1$ + Logger.log("Process possibly stuck"); //$NON-NLS-1$ + return Status.CANCEL_STATUS; + } + + IStatus status = new Status(process.exitValue() == 0 ? IStatus.OK : IStatus.ERROR, UIPlugin.PLUGIN_ID, + process.exitValue(), output.toString(), null); + messageConsoleStream.flush(); + return status; + } + catch (Exception e1) + { + Logger.log(IDFCorePlugin.getPlugin(), e1); + return IDFCorePlugin.errorStatus(e1.getMessage(), e1); + } + } + + private void openConsole(String consoleName) + { + // add it if necessary + boolean found = false; + + IConsole[] consoles = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); + for (int i = 0; i < consoles.length; i++) + { + if (consoleName.equals(consoles[i].getName())) + { + console = (MessageConsole) consoles[i]; + found = true; + break; + } + } + + if (!found) + { + console = new MessageConsole(consoleName, null); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); + } + + ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console); + } + + protected String pythonVirtualExecutablePath() + { + String pythonVirtualPath = new IDFEnvironmentVariables() + .getEnvValue(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH); + StringBuilder pythonVirtualExePath = new StringBuilder(); + pythonVirtualExePath.append(pythonVirtualPath); + pythonVirtualExePath.append("/"); //$NON-NLS-1$ + if (Platform.getOS().equals(Platform.OS_WIN32)) + { + pythonVirtualExePath.append("Scripts"); //$NON-NLS-1$ + pythonVirtualExePath.append("/"); //$NON-NLS-1$ + pythonVirtualExePath.append("python.exe"); //$NON-NLS-1$ + } + else + { + pythonVirtualExePath.append("bin"); //$NON-NLS-1$ + pythonVirtualExePath.append("/"); //$NON-NLS-1$ + pythonVirtualExePath.append("python"); //$NON-NLS-1$ + } + + return pythonVirtualExePath.toString(); + } + private void updateClangFiles(IProject project) { try From 1b1376a84065b72fce5aedd81a283bf4112159b6 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Mon, 11 Nov 2024 10:43:25 +0200 Subject: [PATCH 2/7] fix: fixing esp-idf terminal and idf.py reconfigure not working on windows --- .../META-INF/MANIFEST.MF | 3 +- .../idf/core/ProcessBuilderFactory.java | 7 +- .../idf/core/util/ConsoleManager.java | 42 ++++++ .../idf/core/util/IdfCommandExecutor.java | 93 +++++++++++++ .../launcher/IDFConsoleLauncherDelegate.java | 3 +- .../com/espressif/idf/ui/wizard/Messages.java | 12 +- .../idf/ui/wizard/NewIDFProjectWizard.java | 127 +----------------- .../idf/ui/wizard/messages.properties | 3 +- 8 files changed, 159 insertions(+), 131 deletions(-) create mode 100644 bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ConsoleManager.java create mode 100644 bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java diff --git a/bundles/com.espressif.idf.core/META-INF/MANIFEST.MF b/bundles/com.espressif.idf.core/META-INF/MANIFEST.MF index 6298a9e93..521544273 100644 --- a/bundles/com.espressif.idf.core/META-INF/MANIFEST.MF +++ b/bundles/com.espressif.idf.core/META-INF/MANIFEST.MF @@ -63,4 +63,5 @@ Bundle-ClassPath: ., lib/commons-compress-1.21.jar, lib/xz-1.9.jar Import-Package: org.eclipse.embedcdt.core, - org.eclipse.launchbar.ui.target + org.eclipse.launchbar.ui.target, + org.eclipse.ui.console diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java index 0eba109ce..a9c1e9dcb 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java @@ -36,8 +36,10 @@ public Process run(List commands, IPath workingDirectory, Map commands, IPath workingDirectory, Ma throws IOException { Process process = run(commands, workingDirectory, environment); - return processData(process.getInputStream(), process.getErrorStream(), process.getOutputStream(), - process); + return processData(process.getInputStream(), process.getErrorStream(), process.getOutputStream(), process); } /** diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ConsoleManager.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ConsoleManager.java new file mode 100644 index 000000000..03c9e518c --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ConsoleManager.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ + +package com.espressif.idf.core.util; + +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.MessageConsole; + +public class ConsoleManager +{ + + private ConsoleManager() + { + } + + public static MessageConsole getConsole(String consoleName) + { + MessageConsole console = findConsole(consoleName); + if (console == null) + { + console = new MessageConsole(consoleName, null); + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); + } + ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console); + return console; + } + + private static MessageConsole findConsole(String consoleName) + { + for (IConsole existing : ConsolePlugin.getDefault().getConsoleManager().getConsoles()) + { + if (consoleName.equals(existing.getName())) + { + return (MessageConsole) existing; + } + } + return null; + } +} diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java new file mode 100644 index 000000000..93ff26eff --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright 2021 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ + +package com.espressif.idf.core.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +import com.espressif.idf.core.IDFCorePlugin; +import com.espressif.idf.core.IDFEnvironmentVariables; +import com.espressif.idf.core.ProcessBuilderFactory; +import com.espressif.idf.core.logging.Logger; + +public class IdfCommandExecutor +{ + + private final String target; + private final MessageConsole console; + + public IdfCommandExecutor(String target, MessageConsole console) + { + this.target = target; + this.console = console; + } + + public IStatus executeReconfigure(IProject project) + { + console.activate(); + return runIdfReconfigureCommand(project); + } + + private IStatus runIdfReconfigureCommand(IProject project) + { + ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); + List arguments = prepareArguments(); + Map environment = new HashMap<>(new IDFEnvironmentVariables().getEnvMap()); + + try (MessageConsoleStream messageConsoleStream = console.newMessageStream()) + { + return runProcess(arguments, environment, processRunner, project, messageConsoleStream); + } + catch (IOException e1) + { + Logger.log(e1); + return IDFCorePlugin.errorStatus(e1.getMessage(), e1); + } + } + + private List prepareArguments() + { + List arguments = new ArrayList<>(); + arguments.add(IDFUtil.getIDFPythonEnvPath()); + arguments.add(IDFUtil.getIDFPythonScriptFile().getAbsolutePath()); + arguments.add("-DIDF_TARGET=" + target); //$NON-NLS-1$ + arguments.add("reconfigure"); //$NON-NLS-1$ + return arguments; + } + + private IStatus runProcess(List arguments, Map environment, + ProcessBuilderFactory processRunner, IProject project, MessageConsoleStream messageConsoleStream) + { + StringBuilder output = new StringBuilder(); + try (BufferedReader reader = new BufferedReader(new InputStreamReader( + processRunner.run(arguments, project.getLocation(), environment).getInputStream()))) + { + String line; + while ((line = reader.readLine()) != null) + { + output.append(line).append(System.lineSeparator()); + messageConsoleStream.println(line); + } + return new Status(IStatus.OK, IDFCorePlugin.PLUGIN_ID, output.toString()); + } + catch (Exception e) + { + Logger.log(e); + return IDFCorePlugin.errorStatus(e.getMessage(), e); + } + } +} diff --git a/bundles/com.espressif.idf.terminal.connector/src/com/espressif/idf/terminal/connector/launcher/IDFConsoleLauncherDelegate.java b/bundles/com.espressif.idf.terminal.connector/src/com/espressif/idf/terminal/connector/launcher/IDFConsoleLauncherDelegate.java index 26bc07285..c940b314c 100644 --- a/bundles/com.espressif.idf.terminal.connector/src/com/espressif/idf/terminal/connector/launcher/IDFConsoleLauncherDelegate.java +++ b/bundles/com.espressif.idf.terminal.connector/src/com/espressif/idf/terminal/connector/launcher/IDFConsoleLauncherDelegate.java @@ -397,7 +397,8 @@ public ITerminalConnector createTerminalConnector(Map properties } envpList.add(envKey + "=" + envValue); //$NON-NLS-1$ } - + //Removing path, since we are using PATH + envMap.remove("Path"); //$NON-NLS-1$ // Convert back into a string array envp = envpList.toArray(new String[envpList.size()]); diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/Messages.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/Messages.java index 48ab9667e..bb1aa3f9c 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/Messages.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/Messages.java @@ -10,7 +10,8 @@ * @author Kondal Kolipaka * */ -public class Messages extends NLS { +public class Messages extends NLS +{ private static final String BUNDLE_NAME = "com.espressif.idf.ui.wizard.messages"; //$NON-NLS-1$ public static String ImportIDFProjectWizard_0; public static String ImportIDFProjectWizardPage_0; @@ -41,12 +42,15 @@ public class Messages extends NLS { public static String NewComponentWizardPage_CantCreateCompErr; public static String NewComponentWizardPage_ProjectDoesntExistErr; public static String NewComponentWizardPage_ProjectNameLbl; - - static { + public static String IdfReconfigureJobName; + + static + { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); } - private Messages() { + private Messages() + { } } diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java index d2afdad6e..e65e4aa33 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java @@ -4,13 +4,7 @@ *******************************************************************************/ package com.espressif.idf.ui.wizard; -import java.io.BufferedReader; import java.io.File; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.eclipse.cdt.debug.internal.core.InternalDebugCoreMessages; import org.eclipse.core.resources.IProject; @@ -19,7 +13,6 @@ import org.eclipse.core.runtime.CoreException; 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.Job; import org.eclipse.debug.core.DebugPlugin; @@ -42,10 +35,7 @@ import org.eclipse.tools.templates.ui.TemplateWizard; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.console.ConsolePlugin; -import org.eclipse.ui.console.IConsole; import org.eclipse.ui.console.MessageConsole; -import org.eclipse.ui.console.MessageConsoleStream; import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; import com.espressif.idf.core.IDFConstants; @@ -57,7 +47,8 @@ import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.ClangFormatFileHandler; import com.espressif.idf.core.util.ClangdConfigFileHandler; -import com.espressif.idf.core.util.IDFUtil; +import com.espressif.idf.core.util.ConsoleManager; +import com.espressif.idf.core.util.IdfCommandExecutor; import com.espressif.idf.core.util.LaunchUtil; import com.espressif.idf.ui.UIPlugin; import com.espressif.idf.ui.handlers.EclipseHandler; @@ -157,12 +148,14 @@ public boolean performFinish() { Logger.log(e); } - Job job = new Job("Running idf.py reconfigure command...") + Job job = new Job(Messages.IdfReconfigureJobName) { protected IStatus run(IProgressMonitor monitor) { - IStatus status = runCommandIdfPyInIdfEnv(target); + IdfCommandExecutor executor = new IdfCommandExecutor(target, + ConsoleManager.getConsole("CDT Build Console")); //$NON-NLS-1$ + IStatus status = executor.executeReconfigure(project); try { IDEWorkbenchPlugin.getPluginWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null); @@ -179,114 +172,6 @@ protected IStatus run(IProgressMonitor monitor) return performFinish; } - protected IStatus runCommandIdfPyInIdfEnv(String target) - { - openConsole("CDT Build Console"); //$NON-NLS-1$ - console.activate(); - MessageConsoleStream messageConsoleStream = console.newMessageStream(); - ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); - StringBuilder output = new StringBuilder(); - int waitCount = 10; - List arguments = new ArrayList(); - try - { - arguments.add(0, pythonVirtualExecutablePath()); - arguments.add(1, IDFUtil.getIDFPythonScriptFile().getAbsolutePath()); - arguments.add("-DIDF_TARGET=" + target); //$NON-NLS-1$ - arguments.add("reconfigure"); //$NON-NLS-1$ - - Map environment = new HashMap<>(new IDFEnvironmentVariables().getEnvMap()); - Logger.log(environment.toString()); - Process process = processRunner.run(arguments, project.getLocation(), environment); - BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); - String line; - while ((line = reader.readLine()) != null) - { - output.append(line).append(System.lineSeparator()); - messageConsoleStream.println(line); - messageConsoleStream.flush(); - } - - while (process.isAlive() && waitCount > 0) - { - try - { - Thread.sleep(300); - } - catch (InterruptedException e) - { - Logger.log(e); - } - waitCount--; - } - - if (waitCount == 0) - { - messageConsoleStream.println("Process possibly stuck"); //$NON-NLS-1$ - Logger.log("Process possibly stuck"); //$NON-NLS-1$ - return Status.CANCEL_STATUS; - } - - IStatus status = new Status(process.exitValue() == 0 ? IStatus.OK : IStatus.ERROR, UIPlugin.PLUGIN_ID, - process.exitValue(), output.toString(), null); - messageConsoleStream.flush(); - return status; - } - catch (Exception e1) - { - Logger.log(IDFCorePlugin.getPlugin(), e1); - return IDFCorePlugin.errorStatus(e1.getMessage(), e1); - } - } - - private void openConsole(String consoleName) - { - // add it if necessary - boolean found = false; - - IConsole[] consoles = ConsolePlugin.getDefault().getConsoleManager().getConsoles(); - for (int i = 0; i < consoles.length; i++) - { - if (consoleName.equals(consoles[i].getName())) - { - console = (MessageConsole) consoles[i]; - found = true; - break; - } - } - - if (!found) - { - console = new MessageConsole(consoleName, null); - ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); - } - - ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console); - } - - protected String pythonVirtualExecutablePath() - { - String pythonVirtualPath = new IDFEnvironmentVariables() - .getEnvValue(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH); - StringBuilder pythonVirtualExePath = new StringBuilder(); - pythonVirtualExePath.append(pythonVirtualPath); - pythonVirtualExePath.append("/"); //$NON-NLS-1$ - if (Platform.getOS().equals(Platform.OS_WIN32)) - { - pythonVirtualExePath.append("Scripts"); //$NON-NLS-1$ - pythonVirtualExePath.append("/"); //$NON-NLS-1$ - pythonVirtualExePath.append("python.exe"); //$NON-NLS-1$ - } - else - { - pythonVirtualExePath.append("bin"); //$NON-NLS-1$ - pythonVirtualExePath.append("/"); //$NON-NLS-1$ - pythonVirtualExePath.append("python"); //$NON-NLS-1$ - } - - return pythonVirtualExePath.toString(); - } - private void updateClangFiles(IProject project) { try diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/messages.properties b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/messages.properties index 9bc7f0299..225d3a5fe 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/messages.properties +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/messages.properties @@ -26,4 +26,5 @@ NewIdfComponentWizard_NameCantBeEmptyErr=A component name can't be empty NewIdfComponentWizard_NameAlreadyExistsErr=A component with such a name is already exists NewComponentWizardPage_CantCreateCompErr=Can not create a component without a project selection NewComponentWizardPage_ProjectDoesntExistErr=Project doesn't exist -NewComponentWizardPage_ProjectNameLbl=Project name: \ No newline at end of file +NewComponentWizardPage_ProjectNameLbl=Project name: +IdfReconfigureJobName=Running idf.py reconfigure command... From 989c39c606d085c492b54832638962dfbf06ef2d Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Mon, 18 Nov 2024 13:55:14 +0200 Subject: [PATCH 3/7] fix: fixed problem with installation tools and making remove Path more robust --- .../src/com/espressif/idf/core/ProcessBuilderFactory.java | 5 ++++- .../connector/launcher/IDFConsoleLauncherDelegate.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java index a9c1e9dcb..5b29fec2a 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java @@ -37,7 +37,10 @@ public Process run(List commands, IPath workingDirectory, Map properties envpList.add(envKey + "=" + envValue); //$NON-NLS-1$ } //Removing path, since we are using PATH - envMap.remove("Path"); //$NON-NLS-1$ + if (envMap.containsKey("PATH") && envMap.containsKey("Path")) { //$NON-NLS-1$ //$NON-NLS-2$ + envMap.remove("Path"); //$NON-NLS-1$ + } // Convert back into a string array envp = envpList.toArray(new String[envpList.size()]); From e6f987a9ca3339bd0020dba1be02987a57221df2 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Tue, 19 Nov 2024 11:56:03 +0200 Subject: [PATCH 4/7] fix: passing system env map instead env map before command execution --- .../src/com/espressif/idf/core/util/IdfCommandExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java index 93ff26eff..26c3643fe 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java @@ -46,7 +46,7 @@ private IStatus runIdfReconfigureCommand(IProject project) { ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); List arguments = prepareArguments(); - Map environment = new HashMap<>(new IDFEnvironmentVariables().getEnvMap()); + Map environment = new HashMap<>(new IDFEnvironmentVariables().getSystemEnvMap()); try (MessageConsoleStream messageConsoleStream = console.newMessageStream()) { From e938ba88d54c88c46fd4d04bdeccc83f69f3a920 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Wed, 20 Nov 2024 22:57:01 +0200 Subject: [PATCH 5/7] fix: adding option to turn off idf.py reconfigure --- .../espressif/idf/ui/templates/Messages.java | 3 +- .../NewProjectCreationWizardPage.java | 52 ++++++++++++------- .../idf/ui/templates/messages.properties | 2 +- .../idf/ui/wizard/NewIDFProjectWizard.java | 48 +++++++++-------- 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/Messages.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/Messages.java index 6abab1022..5c0305f1e 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/Messages.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/Messages.java @@ -23,7 +23,8 @@ public class Messages extends NLS public static String TemplateGroupHeader; public static String NewProjectTargetSelection_Tooltip; public static String NewProjectTargetSelection_Label; - + public static String RunIdfCommandButtonTxt; + static { // initialize resource bundle diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/NewProjectCreationWizardPage.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/NewProjectCreationWizardPage.java index 2f1bdb415..b7b1e6729 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/NewProjectCreationWizardPage.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/NewProjectCreationWizardPage.java @@ -22,6 +22,7 @@ import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; @@ -47,6 +48,7 @@ public class NewProjectCreationWizardPage extends AbstractTemplatesSelectionPage private Combo targetCombo; // initial value stores private String initialProjectFieldValue; + private Button runIdfReconfigureCheckBoxButton; /** * Constructor @@ -84,7 +86,7 @@ private void createProjectTargetSelection(Composite container) targetCombo.select(0); targetCombo.setToolTipText(Messages.NewProjectTargetSelection_Tooltip); } - + private void createProjectNameGroup(Composite container) { Composite mainComposite = new Composite(container, SWT.NONE); @@ -92,9 +94,9 @@ private void createProjectNameGroup(Composite container) GridData gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 20; gridData.verticalSpan = 5; - + mainComposite.setLayoutData(gridData); - + Composite projectNameGroup = new Composite(mainComposite, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; @@ -102,8 +104,7 @@ private void createProjectNameGroup(Composite container) projectNameGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); Label projectNameLabel = new Label(projectNameGroup, SWT.NONE); projectNameLabel.setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel); - - + projectNameField = new Text(projectNameGroup, SWT.BORDER); projectNameField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); projectNameField.addModifyListener(new ModifyListener() @@ -119,20 +120,26 @@ public void modifyText(ModifyEvent e) { setPageComplete(false); } - + boolean valid = validatePage(); setPageComplete(valid); } }); - - + locationArea = new ProjectContentsLocationArea(getErrorReporter(), mainComposite); if (initialProjectFieldValue != null) { locationArea.updateProjectName(initialProjectFieldValue); } + + runIdfReconfigureCheckBoxButton = new Button(projectNameGroup, SWT.CHECK | SWT.RIGHT); + GridData buttonData = new GridData(); + buttonData.horizontalSpan = 4; + runIdfReconfigureCheckBoxButton.setLayoutData(buttonData); + runIdfReconfigureCheckBoxButton.setSelection(true); + runIdfReconfigureCheckBoxButton.setText(Messages.RunIdfCommandButtonTxt); } - + /** * Get an error reporter for the receiver. * @@ -157,7 +164,7 @@ private IErrorMessageReporter getErrorReporter() setPageComplete(valid); }; } - + /** * Returns the useDefaults. * @@ -167,17 +174,22 @@ public boolean useDefaults() { return locationArea.isDefault(); } - + + public boolean isRunIdfReconfigureEnabled() + { + return runIdfReconfigureCheckBoxButton.getSelection(); + } + public IPath getLocationPath() { return new Path(locationArea.getProjectLocation()); } - + public URI getLocationURI() { return locationArea.getProjectLocationURI(); } - + /** * Sets the initial project name that this page will use when created. The name is ignored if the * createControl(Composite) method has already been called. Leading and trailing spaces in the name are ignored. @@ -204,7 +216,7 @@ public void setInitialProjectName(String name) } } } - + /** * Set the location to the default location if we are set to useDefaults. */ @@ -213,7 +225,6 @@ void setLocationForSelection() locationArea.updateProjectName(getProjectNameFieldValue()); } - /** * Returns the value of the project name field with leading and trailing spaces removed. * @@ -228,7 +239,7 @@ private String getProjectNameFieldValue() return projectNameField.getText().trim(); } - + @Override protected boolean validatePage() { @@ -242,7 +253,8 @@ protected boolean validatePage() if (!IDFUtil.checkIfIdfSupportsSpaces() && worspaceLocation.contains(" ")) //$NON-NLS-1$ { - setErrorMessage(com.espressif.idf.ui.wizard.Messages.WizardNewProjectCreationPage_WorkspaceLocCantIncludeSpaceErr); + setErrorMessage( + com.espressif.idf.ui.wizard.Messages.WizardNewProjectCreationPage_WorkspaceLocCantIncludeSpaceErr); return false; } @@ -303,7 +315,7 @@ public IProject getProjectHandle() { return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName()); } - + /** * Returns the current project name as entered by the user, or its anticipated initial value. * @@ -318,7 +330,7 @@ public String getProjectName() return getProjectNameFieldValue(); } - + @Override protected void initializeViewer() { @@ -401,7 +413,7 @@ public void setInitialTemplateId(ITemplateNode templateNode) @Override public void setVisible(boolean visible) { - if (visible && getfUseTemplate() != null ) + if (visible && getfUseTemplate() != null) { if (getfUseTemplate().getSelection() == false) templateViewer.getControl().setEnabled(false); diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/messages.properties b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/messages.properties index a57b0a6d2..3487dcfdc 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/messages.properties +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/templates/messages.properties @@ -8,4 +8,4 @@ NewProjectWizardPage_NoTemplateFoundMessage=No Templates were found on the syste TemplateGroupHeader=Template Selection NewProjectTargetSelection_Tooltip=Select a project target from the list. This setting is not final and can be changed later in the Launchbar target configuration, where you'll also configure the serial port. NewProjectTargetSelection_Label=Select Project Target: - \ No newline at end of file +RunIdfCommandButtonTxt=Execute idf.py reconfigure with Project Creation \ No newline at end of file diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java index e65e4aa33..3214e5189 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java @@ -40,9 +40,6 @@ import com.espressif.idf.core.IDFConstants; import com.espressif.idf.core.LaunchBarTargetConstants; -import com.espressif.idf.core.IDFCorePlugin; -import com.espressif.idf.core.IDFEnvironmentVariables; -import com.espressif.idf.core.ProcessBuilderFactory; import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; import com.espressif.idf.core.util.ClangFormatFileHandler; @@ -148,30 +145,39 @@ public boolean performFinish() { Logger.log(e); } - Job job = new Job(Messages.IdfReconfigureJobName) + if (projectCreationWizardPage.isRunIdfReconfigureEnabled()) { + runIdfReconfigureCommandJob(target); - protected IStatus run(IProgressMonitor monitor) - { - IdfCommandExecutor executor = new IdfCommandExecutor(target, - ConsoleManager.getConsole("CDT Build Console")); //$NON-NLS-1$ - IStatus status = executor.executeReconfigure(project); - try - { - IDEWorkbenchPlugin.getPluginWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null); - } - catch (CoreException e) - { - Logger.log(e); - } - return status; - } - }; - job.schedule(); + } }); return performFinish; } + private void runIdfReconfigureCommandJob(final String target) + { + Job job = new Job(Messages.IdfReconfigureJobName) + { + + protected IStatus run(IProgressMonitor monitor) + { + IdfCommandExecutor executor = new IdfCommandExecutor(target, + ConsoleManager.getConsole("CDT Build Console")); //$NON-NLS-1$ + IStatus status = executor.executeReconfigure(project); + try + { + IDEWorkbenchPlugin.getPluginWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null); + } + catch (CoreException e) + { + Logger.log(e); + } + return status; + } + }; + job.schedule(); + } + private void updateClangFiles(IProject project) { try From 25b57f017fc7f7502f0301d11d3b051c1f9c6149 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Thu, 21 Nov 2024 19:48:52 +0200 Subject: [PATCH 6/7] fix: adding reconfigure command to the menu --- bundles/com.espressif.idf.ui/plugin.xml | 10 +++ .../ui/handlers/IdfReconfigureHandler.java | 74 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/IdfReconfigureHandler.java diff --git a/bundles/com.espressif.idf.ui/plugin.xml b/bundles/com.espressif.idf.ui/plugin.xml index 8f248ed24..8d7d6dc97 100644 --- a/bundles/com.espressif.idf.ui/plugin.xml +++ b/bundles/com.espressif.idf.ui/plugin.xml @@ -476,6 +476,12 @@ + + + + diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/IdfReconfigureHandler.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/IdfReconfigureHandler.java new file mode 100644 index 000000000..64a643019 --- /dev/null +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/IdfReconfigureHandler.java @@ -0,0 +1,74 @@ +package com.espressif.idf.ui.handlers; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.launchbar.core.ILaunchBarManager; +import org.eclipse.launchbar.core.target.ILaunchTarget; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; + +import com.espressif.idf.core.IDFCorePlugin; +import com.espressif.idf.core.LaunchBarTargetConstants; +import com.espressif.idf.core.logging.Logger; +import com.espressif.idf.core.util.ConsoleManager; +import com.espressif.idf.core.util.IdfCommandExecutor; +import com.espressif.idf.core.util.StringUtil; +import com.espressif.idf.ui.EclipseUtil; +import com.espressif.idf.ui.wizard.Messages; + +@SuppressWarnings("restriction") +public class IdfReconfigureHandler extends AbstractHandler +{ + + private static final String DEFAULT_TARGET = "esp32"; //$NON-NLS-1$ + + public Object execute(ExecutionEvent event) throws ExecutionException + { + IProject selectedProject = EclipseUtil.getSelectedProjectInExplorer(); + + Job job = new Job(Messages.IdfReconfigureJobName) + { + + protected IStatus run(IProgressMonitor monitor) + { + + IdfCommandExecutor executor = new IdfCommandExecutor(getCurrentTarget(), + ConsoleManager.getConsole("CDT Build Console")); //$NON-NLS-1$ + IStatus status = executor.executeReconfigure(selectedProject); + try + { + IDEWorkbenchPlugin.getPluginWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null); + } + catch (CoreException e) + { + Logger.log(e); + } + return status; + } + }; + job.schedule(); + return null; + } + + private String getCurrentTarget() + { + ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); + ILaunchTarget target; + try + { + target = launchBarManager.getActiveLaunchTarget(); + return target.getAttribute(LaunchBarTargetConstants.TARGET, StringUtil.EMPTY); + } + catch (CoreException e) + { + Logger.log(e); + } + return DEFAULT_TARGET; + } +} From 786e86f717a2741964d1ac087dbbff4f32f3b444 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Thu, 28 Nov 2024 20:16:43 +0200 Subject: [PATCH 7/7] fix: changing idf.py reconfigure to cmake command to allow -B --- .../idf/core/IDFEnvironmentVariables.java | 17 ++-- .../idf/core/util/IdfCommandExecutor.java | 98 +++++++++++++++++-- 2 files changed, 101 insertions(+), 14 deletions(-) diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFEnvironmentVariables.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFEnvironmentVariables.java index d83ba27a6..e60d02acd 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFEnvironmentVariables.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFEnvironmentVariables.java @@ -44,12 +44,13 @@ public class IDFEnvironmentVariables public static final String ESP_IDF_VERSION = "ESP_IDF_VERSION"; //$NON-NLS-1$ - public static final String GIT_PATH ="GIT_PATH"; //$NON-NLS-1$ - - public static final String PYTHON_EXE_PATH ="PYTHON_EXE_PATH"; //$NON-NLS-1$ - + public static final String GIT_PATH = "GIT_PATH"; //$NON-NLS-1$ + + public static final String PYTHON_EXE_PATH = "PYTHON_EXE_PATH"; //$NON-NLS-1$ + public static final String IDF_MAINTAINER = "IDF_MAINTAINER"; //$NON-NLS-1$ + public static final String IDF_CCACHE_ENABLE = "IDF_CCACHE_ENABLE"; //$NON-NLS-1$ /** * @param variableName Environment variable Name @@ -68,11 +69,11 @@ public void removeEnvVariable(String variableName) IContributedEnvironment contributedEnvironment = getEnvironment(); contributedEnvironment.removeVariable(variableName, null); } - + public void removeAllEnvVariables() { Map currentVarMap = getEnvMap(); - for(Entry varEntry : currentVarMap.entrySet()) + for (Entry varEntry : currentVarMap.entrySet()) { removeEnvVariable(varEntry.getKey()); } @@ -100,7 +101,7 @@ public String getEnvValue(String variableName) return envValue; } - + public void addEnvVariable(String name, String value) { Logger.log(MessageFormat.format("Updating environment variables with key:{0} value:{1}", name, value)); //$NON-NLS-1$ @@ -142,7 +143,7 @@ public Map getSystemEnvMap() envMap.put(key, value); } } - + return envMap; } diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java index 26c3643fe..0e452ed01 100644 --- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java @@ -12,16 +12,23 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.console.MessageConsoleStream; import com.espressif.idf.core.IDFCorePlugin; import com.espressif.idf.core.IDFEnvironmentVariables; import com.espressif.idf.core.ProcessBuilderFactory; +import com.espressif.idf.core.build.ActiveLaunchConfigurationProvider; +import com.espressif.idf.core.build.IDFLaunchConstants; import com.espressif.idf.core.logging.Logger; public class IdfCommandExecutor @@ -29,6 +36,8 @@ public class IdfCommandExecutor private final String target; private final MessageConsole console; + private static final String CMAKE_ARGUMENTS = "cmake.arguments"; //$NON-NLS-1$ + private static final ActiveLaunchConfigurationProvider LAUNCH_CONFIG_PROVIDER = new ActiveLaunchConfigurationProvider(); public IdfCommandExecutor(String target, MessageConsole console) { @@ -45,11 +54,13 @@ public IStatus executeReconfigure(IProject project) private IStatus runIdfReconfigureCommand(IProject project) { ProcessBuilderFactory processRunner = new ProcessBuilderFactory(); - List arguments = prepareArguments(); + setBuildFolder(project); + List arguments = prepareCmakeArguments(project); Map environment = new HashMap<>(new IDFEnvironmentVariables().getSystemEnvMap()); try (MessageConsoleStream messageConsoleStream = console.newMessageStream()) { + messageConsoleStream.println(String.join(" ", arguments)); //$NON-NLS-1$ return runProcess(arguments, environment, processRunner, project, messageConsoleStream); } catch (IOException e1) @@ -59,16 +70,91 @@ private IStatus runIdfReconfigureCommand(IProject project) } } - private List prepareArguments() + private List prepareCmakeArguments(IProject project) { List arguments = new ArrayList<>(); - arguments.add(IDFUtil.getIDFPythonEnvPath()); - arguments.add(IDFUtil.getIDFPythonScriptFile().getAbsolutePath()); - arguments.add("-DIDF_TARGET=" + target); //$NON-NLS-1$ - arguments.add("reconfigure"); //$NON-NLS-1$ + arguments.add("cmake"); //$NON-NLS-1$ + arguments.add("-G"); //$NON-NLS-1$ + arguments.add("Ninja"); //$NON-NLS-1$ + arguments.add("-DPYTHON_DEPS_CHECKED=1"); //$NON-NLS-1$ + arguments.add("-DPYTHON=" + IDFUtil.getIDFPythonEnvPath()); //$NON-NLS-1$ + arguments.add("DESP_PLATFORM=1"); //$NON-NLS-1$ + + String ccache = new IDFEnvironmentVariables().getEnvValue(IDFEnvironmentVariables.IDF_CCACHE_ENABLE); + ccache = ccache.isBlank() ? "0" : ccache; //$NON-NLS-1$ + + arguments.add("DCCACHE_ENABLE=" + ccache); //$NON-NLS-1$ + arguments.add(project.getLocation().toOSString()); + arguments.add("-B"); //$NON-NLS-1$ + try + { + arguments.add(IDFUtil.getBuildDir(project)); + } + catch (CoreException e) + { + Logger.log(e); + } return arguments; } + private boolean setBuildFolder(IProject project) + { + String userArgs = getProperty(CMAKE_ARGUMENTS); + // Custom build directory + String[] cmakeArgumentsArr = userArgs.split(" "); //$NON-NLS-1$ + String customBuildDir = StringUtil.EMPTY; + for (int i = 0; i < cmakeArgumentsArr.length; i++) + { + if (cmakeArgumentsArr[i].equals("-B")) //$NON-NLS-1$ + { + customBuildDir = cmakeArgumentsArr[i + 1]; + break; + } + } + try + { + IDFUtil.setBuildDir(project, customBuildDir); + } + catch (CoreException e) + { + Logger.log(e); + } + + return !customBuildDir.isBlank(); + } + + public String getProperty(String name) + { + try + { + ILaunchConfiguration configuration = LAUNCH_CONFIG_PROVIDER.getActiveLaunchConfiguration(); + if (configuration != null + && configuration.getType().getIdentifier().equals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE)) + { + configuration = getBoundConfiguration(configuration); + } + return configuration == null ? StringUtil.EMPTY : configuration.getAttribute(name, StringUtil.EMPTY); + } + catch (CoreException e) + { + Logger.log(e); + } + return StringUtil.EMPTY; + } + + private ILaunchConfiguration getBoundConfiguration(ILaunchConfiguration configuration) throws CoreException + { + String bindedLaunchConfigName = configuration.getAttribute(IDFLaunchConstants.ATTR_LAUNCH_CONFIGURATION_NAME, + StringUtil.EMPTY); + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(DebugPlugin.getDefault() + .getLaunchManager().getLaunchConfigurationType(IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE)); + ILaunchConfiguration defaultConfiguration = launchConfigurations[0]; + return Stream.of(launchConfigurations).filter(config -> config.getName().contentEquals(bindedLaunchConfigName)) + .findFirst().orElse(defaultConfiguration); + + } + private IStatus runProcess(List arguments, Map environment, ProcessBuilderFactory processRunner, IProject project, MessageConsoleStream messageConsoleStream) {