-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IEP-1247 Run CMake initial build for newly created project(idf.py reconfigure) #1051
base: master
Are you sure you want to change the base?
Changes from 5 commits
ebf8111
1b1376a
989c39c
e6f987a
e938ba8
25b57f0
786e86f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont understand the need for this class, maybe I am not clear on this. Just a question from my side that why do we need a separate class to just execute this command when we can do that in the Job we are creating for the console? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @alirana01, thanks for the review. I've created this class not only for this command but also for other idf commands that we have to execute in the console. My idea was that in the future we could refactor existing code and move other IDF commands and their preparation into this class to not scatter similar logic over the code base and to avoid duplicate code |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> arguments = prepareArguments(); | ||
Map<String, String> environment = new HashMap<>(new IDFEnvironmentVariables().getSystemEnvMap()); | ||
|
||
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<String> prepareArguments() | ||
{ | ||
List<String> 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<String> arguments, Map<String, String> 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); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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,26 +86,25 @@ 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); | ||||||||||||||||||
mainComposite.setLayout(new GridLayout()); | ||||||||||||||||||
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; | ||||||||||||||||||
projectNameGroup.setLayout(layout); | ||||||||||||||||||
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(); | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+178
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add null check for robustness The getter method should handle cases where the button hasn't been initialized yet. public boolean isRunIdfReconfigureEnabled()
{
- return runIdfReconfigureCheckBoxButton.getSelection();
+ return runIdfReconfigureCheckBoxButton != null && runIdfReconfigureCheckBoxButton.getSelection();
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
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); | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add documentation and parameter validation.
The method logic is correct, but could benefit from these improvements:
📝 Committable suggestion