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/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/ProcessBuilderFactory.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/ProcessBuilderFactory.java index 0eba109ce..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 @@ -36,8 +36,13 @@ 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..0e452ed01 --- /dev/null +++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IdfCommandExecutor.java @@ -0,0 +1,179 @@ +/******************************************************************************* + * 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 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 +{ + + 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) + { + 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(); + 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) + { + Logger.log(e1); + return IDFCorePlugin.errorStatus(e1.getMessage(), e1); + } + } + + private List prepareCmakeArguments(IProject project) + { + List arguments = new ArrayList<>(); + 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) + { + 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..2d4779fc2 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,10 @@ public ITerminalConnector createTerminalConnector(Map properties } envpList.add(envKey + "=" + envValue); //$NON-NLS-1$ } - + //Removing path, since we are using PATH + 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()]); 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; + } +} 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/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 d43476490..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 @@ -8,6 +8,7 @@ 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; @@ -34,6 +35,7 @@ import org.eclipse.tools.templates.ui.TemplateWizard; import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.console.MessageConsole; import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; import com.espressif.idf.core.IDFConstants; @@ -42,6 +44,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.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; @@ -62,6 +66,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 +116,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 +145,39 @@ public boolean performFinish() { Logger.log(e); } + if (projectCreationWizardPage.isRunIdfReconfigureEnabled()) + { + runIdfReconfigureCommandJob(target); + + } }); 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 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...