Skip to content

Commit 122ccef

Browse files
authored
IEP-1067 Default config auto creation for debug (#895)
* fix: creating a default debug config together with project * fix: setting launch configuration as default
1 parent c268c4d commit 122ccef

3 files changed

Lines changed: 82 additions & 23 deletions

File tree

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* QNX - Initial API and implementation
1313
* kondal.kolipaka@espressif.com - ESP-IDF specific build configuration
@@ -140,10 +140,12 @@ public class IDFBuildConfiguration extends CBuildConfiguration
140140
public boolean isProgressSet;
141141
private QualifiedName TIMESTAMP_COMPILE_COMMANDS_PROPERTY = new QualifiedName(null,
142142
"timestamp:compile_commands.json"); //$NON-NLS-1$
143+
private ILaunchConfiguration configuration;
143144

144145
public IDFBuildConfiguration(IBuildConfiguration config, String name) throws CoreException
145146
{
146147
super(config, name);
148+
this.configuration = LAUNCH_CONFIG_PROVIDER.getActiveLaunchConfiguration();
147149
}
148150

149151
public IDFBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain)
@@ -156,6 +158,14 @@ public IDFBuildConfiguration(IBuildConfiguration config, String name, IToolChain
156158
{
157159
super(config, name, toolChain, launchMode);
158160
this.toolChainFile = toolChainFile;
161+
try
162+
{
163+
this.configuration = LAUNCH_CONFIG_PROVIDER.getActiveLaunchConfiguration();
164+
}
165+
catch (CoreException e)
166+
{
167+
Logger.log(e);
168+
}
159169
}
160170

161171
@Override
@@ -247,7 +257,6 @@ public String getProperty(String name)
247257
{
248258
try
249259
{
250-
ILaunchConfiguration configuration = LAUNCH_CONFIG_PROVIDER.getActiveLaunchConfiguration();
251260
if (configuration != null
252261
&& configuration.getType().getIdentifier().equals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE))
253262
{
@@ -639,7 +648,7 @@ private static String getIdfToolsPath()
639648

640649
/**
641650
* Link build components(build_component_paths) from project_description.json to the project.
642-
*
651+
*
643652
* @param project
644653
* @throws Exception
645654
*/
@@ -976,7 +985,7 @@ public void elementChanged(ElementChangedEvent event)
976985
/**
977986
* Processes the delta in order to detect whether one of the CMakeLists.txt files in the project has been modified
978987
* and saved by the user since the last build.
979-
*
988+
*
980989
* @return <code>true</code> to continue with delta processing, otherwise <code>false</code>
981990
*/
982991
private boolean processElementDelta(ICElementDelta delta)

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,24 @@
1414
import org.eclipse.core.runtime.IStatus;
1515
import org.eclipse.core.runtime.Status;
1616
import org.eclipse.core.runtime.jobs.Job;
17+
import org.eclipse.debug.core.DebugPlugin;
18+
import org.eclipse.debug.core.ILaunchConfigurationType;
1719
import org.eclipse.jface.dialogs.IDialogSettings;
20+
import org.eclipse.jface.dialogs.PageChangingEvent;
1821
import org.eclipse.jface.viewers.ISelectionProvider;
1922
import org.eclipse.jface.viewers.StructuredSelection;
23+
import org.eclipse.jface.wizard.WizardDialog;
2024
import org.eclipse.launchbar.core.ILaunchBarManager;
25+
import org.eclipse.launchbar.core.ILaunchDescriptor;
2126
import org.eclipse.launchbar.core.target.ILaunchTarget;
2227
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
28+
import org.eclipse.launchbar.ui.NewLaunchConfigWizard;
29+
import org.eclipse.launchbar.ui.NewLaunchConfigWizardDialog;
30+
import org.eclipse.launchbar.ui.internal.dialogs.NewLaunchConfigEditPage;
2331
import org.eclipse.swt.events.DisposeEvent;
2432
import org.eclipse.swt.events.DisposeListener;
2533
import org.eclipse.swt.widgets.Display;
34+
import org.eclipse.swt.widgets.Shell;
2635
import org.eclipse.tools.templates.core.IGenerator;
2736
import org.eclipse.tools.templates.ui.TemplateWizard;
2837
import org.eclipse.ui.IViewPart;
@@ -48,6 +57,7 @@
4857
@SuppressWarnings("restriction")
4958
public class NewIDFProjectWizard extends TemplateWizard
5059
{
60+
private static final String NEW_LAUNCH_CONFIG_EDIT_PAGE = "NewLaunchConfigEditPage"; //$NON-NLS-1$
5161
public static final String TARGET_SWITCH_JOB = "TARGET SWITCH JOB"; //$NON-NLS-1$
5262
private NewProjectCreationWizardPage projectCreationWizardPage;
5363

@@ -72,16 +82,17 @@ public void addPages()
7282
super.addPages();
7383

7484
this.setWindowTitle(Messages.NewIDFProjectWizard_NewIDFProject);
75-
85+
7686
TemplatesManager templatesManager = new TemplatesManager();
7787
ITemplateNode templateRoot = templatesManager.getTemplates();
78-
projectCreationWizardPage = new NewProjectCreationWizardPage(templateRoot, Messages.NewIDFProjectWizard_TemplatesHeader);
88+
projectCreationWizardPage = new NewProjectCreationWizardPage(templateRoot,
89+
Messages.NewIDFProjectWizard_TemplatesHeader);
7990
ITemplateNode templateNode = templatesManager.getTemplateNode(IDFConstants.DEFAULT_TEMPLATE_ID);
8091
if (templateNode != null)
8192
{
8293
projectCreationWizardPage.setInitialTemplateId(templateNode);
8394
}
84-
95+
8596
this.addPage(projectCreationWizardPage);
8697
}
8798

@@ -101,19 +112,61 @@ public boolean performFinish()
101112
selProvider.setSelection(new StructuredSelection(project));
102113
}
103114
}
115+
104116
final String target = projectCreationWizardPage.getSelectedTarget();
105117
this.getShell().addDisposeListener(new DisposeListener()
106118
{
107119
@Override
108-
public void widgetDisposed(DisposeEvent e)
120+
public void widgetDisposed(DisposeEvent event)
109121
{
122+
ILaunchBarManager launchBarManager = UIPlugin.getService(ILaunchBarManager.class);
110123
TargetSwitchJob targetSwtichJob = new TargetSwitchJob(target);
111124
targetSwtichJob.schedule();
125+
try
126+
{
127+
ILaunchDescriptor desc = launchBarManager.getActiveLaunchDescriptor();
128+
createDefaultDebugConfig();
129+
launchBarManager.setActiveLaunchDescriptor(desc);
130+
}
131+
catch (CoreException e)
132+
{
133+
Logger.log(e);
134+
}
135+
112136
}
113137
});
114138
return performFinish;
115139
}
116-
140+
141+
private void createDefaultDebugConfig()
142+
{
143+
Shell activeShell = Display.getDefault().getActiveShell();
144+
145+
NewLaunchConfigWizard wizard = new NewLaunchConfigWizard();
146+
WizardDialog dialog = new NewLaunchConfigWizardDialog(activeShell, wizard);
147+
dialog.create();
148+
149+
NewLaunchConfigEditPage editPage = (NewLaunchConfigEditPage) wizard.getPage(NEW_LAUNCH_CONFIG_EDIT_PAGE);
150+
ILaunchConfigurationType debugLaunchConfigType = DebugPlugin.getDefault().getLaunchManager()
151+
.getLaunchConfigurationType(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE);
152+
editPage.setLaunchConfigType(debugLaunchConfigType);
153+
154+
PageChangingEvent pageChangingEvent = new PageChangingEvent(wizard, wizard.getStartingPage(), editPage);
155+
editPage.handlePageChanging(pageChangingEvent);
156+
157+
wizard.performFinish();
158+
159+
try
160+
{
161+
wizard.getWorkingCopy().doSave();
162+
}
163+
catch (CoreException e)
164+
{
165+
Logger.log(e);
166+
}
167+
wizard.dispose();
168+
}
169+
117170
@Override
118171
protected IGenerator getGenerator()
119172
{
@@ -126,7 +179,8 @@ protected IGenerator getGenerator()
126179
manifest = null;
127180
}
128181

129-
IDFProjectGenerator generator = new IDFProjectGenerator(manifest, selectedTemplate, true, projectCreationWizardPage.getSelectedTarget());
182+
IDFProjectGenerator generator = new IDFProjectGenerator(manifest, selectedTemplate, true,
183+
projectCreationWizardPage.getSelectedTarget());
130184
generator.setProjectName(projectCreationWizardPage.getProjectName());
131185
if (!projectCreationWizardPage.useDefaults())
132186
{
@@ -135,19 +189,18 @@ protected IGenerator getGenerator()
135189
return generator;
136190
}
137191

138-
139192
private class TargetSwitchJob extends Job
140193
{
141194
private ILaunchBarManager launchBarManager;
142195
private String target;
196+
143197
public TargetSwitchJob(String target)
144198
{
145199
super(TARGET_SWITCH_JOB);
146200
this.target = target;
147201
launchBarManager = UIPlugin.getService(ILaunchBarManager.class);
148202
}
149203

150-
151204
private Job findInternalJob()
152205
{
153206
for (Job job : Job.getJobManager().find(null))
@@ -157,10 +210,9 @@ private Job findInternalJob()
157210
return job;
158211
}
159212
}
160-
213+
161214
return null;
162215
}
163-
164216

165217
@Override
166218
protected IStatus run(IProgressMonitor monitor)
@@ -177,7 +229,7 @@ protected IStatus run(IProgressMonitor monitor)
177229
Logger.log(e1);
178230
}
179231
}
180-
232+
181233
Display.getDefault().syncExec(() -> {
182234
ILaunchTarget launchTarget = findSuitableTargetForSelectedTargetString();
183235
try
@@ -187,13 +239,13 @@ protected IStatus run(IProgressMonitor monitor)
187239
catch (CoreException e)
188240
{
189241
Logger.log(e);
190-
}
242+
}
191243
});
192-
244+
193245
return Status.OK_STATUS;
194-
246+
195247
}
196-
248+
197249
private ILaunchTarget findSuitableTargetForSelectedTargetString()
198250
{
199251
ILaunchTargetManager launchTargetManager = UIPlugin.getService(ILaunchTargetManager.class);
@@ -202,14 +254,13 @@ private ILaunchTarget findSuitableTargetForSelectedTargetString()
202254

203255
for (ILaunchTarget iLaunchTarget : targets)
204256
{
205-
String idfTarget = iLaunchTarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET,
206-
null);
257+
String idfTarget = iLaunchTarget.getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, null);
207258
if (idfTarget.contentEquals(target))
208259
{
209260
return iLaunchTarget;
210261
}
211262
}
212-
263+
213264
return null;
214265
}
215266
}

bundles/com.espressif.idf.wokwi/bin/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)