From 369ddea39cdbe5cb7ce23a59ea76b3aed6f029ab Mon Sep 17 00:00:00 2001
From: 15knots <11367029+15knots@users.noreply.github.com>
Date: Fri, 4 Nov 2022 21:30:22 +0100
Subject: [PATCH] Add ManagedBuildManager#createConfigurationForProject()
(#131)
* Add ManagedBuildManager#createConfigurationForProject()
This should allow ISV's to create MBS based project with a
vendor-specific build-system ID without using internal API.
Update New & Noteworthy
Signed-off-by: 15knots <11367029+15knots@users.noreply.github.com>
---
NewAndNoteworthy/CDT-11.0.md | 5 ++
.../core/ManagedBuildManager.java | 48 +++++++++++++++++++
.../ui/wizards/MBSWizardHandler.java | 28 +++++------
3 files changed, 66 insertions(+), 15 deletions(-)
diff --git a/NewAndNoteworthy/CDT-11.0.md b/NewAndNoteworthy/CDT-11.0.md
index 2f03c0b22e1..c10915f9e40 100644
--- a/NewAndNoteworthy/CDT-11.0.md
+++ b/NewAndNoteworthy/CDT-11.0.md
@@ -51,6 +51,11 @@ Job.getJobManager().join(ManagedBuilderCorePlugin.BUILD_SETTING_UPDATE_JOB_FAMIL
This new job family was added to improve stability of tests to ensure background operations are complete.
It may have other uses to other API consumers as well and is therefore included here.
+## New method ManagedBuildManager#createConfigurationForProject()
+
+This should allow ISV's to create MBS based project with a vendor-specific build-system ID without using internal API.
+
+
# Bugs Fixed in this Release
See [GitHub milestones](https://github.com/eclipse-cdt/cdt/milestone/2?closed=1) and for bugs that haven't been transitioned to GitHub please see Bugzilla report [Bugs Fixed in CDT 11.0](https://bugs.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&classification=Tools&product=CDT&query_format=advanced&resolution=FIXED&target_milestone=11.0.0).
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
index 36a52608c23..29a367f5f47 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java
@@ -3650,6 +3650,54 @@ private static IConfiguration getConfigurationForDescription(ICConfigurationDesc
return null;
}
+ /**
+ * Creates a new IConfiguration
object associated to the specified
+ * managed project and adds it to the corresponding project description.
+ * This purpose of this method is to set up build configurations for MBS
+ * projects that are in the phase of being created programmatically.
+ *
+ * @param projectDescription the ICProjectDescription
to use for
+ * creating the new configuration
+ * @param managedProject the managed project to associate the new
+ * IConfiguration
with
+ * @param cloneConfiguration the IConfiguration
to copy the
+ * settings from
+ * @param buildSystemId buildSystemId build system id, i.e. the extension
+ * id contributing to the
+ * org.eclipse.cdt.core.CConfigurationDataProvider
+ * extension point
+ *
+ * @return the newly created IConfiguration
object
+ *
+ * @throws CoreException if the creation of a new
+ * ICConfigurationDescription failed
+ * @throws IllegalArgumentException if the IProject
associated with
+ * the specified
+ * ICProjectDescription
does not
+ * match the project associated with the given
+ * IManagedProject
+ * @since 9.5
+ */
+ public static IConfiguration createConfigurationForProject(ICProjectDescription projectDescription,
+ IManagedProject managedProject, IConfiguration cloneConfiguration, String buildSystemId)
+ throws CoreException {
+ // sanity checks..
+ if (projectDescription.getProject() != managedProject.getOwner()) {
+ String msg = String.format(
+ "IProject associated with 'projectDescription' (%s) does not match the one associated with 'managedProject' (%s)", //$NON-NLS-1$
+ projectDescription.getProject(), managedProject.getOwner());
+ throw new IllegalArgumentException(msg);
+ }
+ String id = calculateChildId(cloneConfiguration.getId(), null);
+ Configuration config = new Configuration((ManagedProject) managedProject, (Configuration) cloneConfiguration,
+ id, false, true);
+ config.exportArtifactInfo();
+ CConfigurationData data = config.getConfigurationData();
+ ICConfigurationDescription cfgDes = projectDescription.createConfiguration(buildSystemId, data);
+ config.setConfigurationDescription(cfgDes);
+ return config;
+ }
+
/**
* Convert the IOption integer type ID to the {@link ICSettingEntry#getKind()} type ID
* @param type {@link IOption#getValueType()}
diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java
index 0af8672ff60..14fac7f98ad 100644
--- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java
+++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/MBSWizardHandler.java
@@ -30,7 +30,6 @@
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
-import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.internal.ui.wizards.ICDTCommonProjectWizard;
import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty;
@@ -611,20 +610,14 @@ private void setProjectDescription(IProject project, boolean defaults, boolean o
cfgs = CfgHolder.unique(cfgs);
cfgs = CfgHolder.reorder(cfgs);
- ICConfigurationDescription cfgDebug = null;
- ICConfigurationDescription cfgFirst = null;
subMonitor.worked(1);
+ IConfiguration active = null;
SubMonitor cfgMonitor = SubMonitor.convert(subMonitor.split(1), cfgs.length);
for (CfgHolder cfg : cfgs) {
cf = (Configuration) cfg.getConfiguration();
- String id = ManagedBuildManager.calculateChildId(cf.getId(), null);
- Configuration config = new Configuration(mProj, cf, id, false, true);
- CConfigurationData data = config.getConfigurationData();
- ICConfigurationDescription cfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
- config.setConfigurationDescription(cfgDes);
- config.exportArtifactInfo();
-
+ IConfiguration config = ManagedBuildManager.createConfigurationForProject(des, mProj, cf,
+ ManagedBuildManager.CFG_DATA_PROVIDER_ID);
IBuilder bld = config.getEditableBuilder();
if (bld != null) {
bld.setManagedBuildOn(true);
@@ -633,13 +626,18 @@ private void setProjectDescription(IProject project, boolean defaults, boolean o
config.setName(cfg.getName());
config.setArtifactName(mProj.getDefaultArtifactName());
- IBuildProperty b = config.getBuildProperties().getProperty(PROPERTY);
- if (cfgDebug == null && b != null && b.getValue() != null && PROP_VAL.equals(b.getValue().getId()))
- cfgDebug = cfgDes;
- if (cfgFirst == null) // select at least first configuration
- cfgFirst = cfgDes;
+ IBuildProperty b = config.getBuildProperties().getProperty(ManagedBuildManager.BUILD_TYPE_PROPERTY_ID);
+ if (active == null && b != null && b.getValue() != null
+ && ManagedBuildManager.BUILD_TYPE_PROPERTY_DEBUG.equals(b.getValue().getId())) {
+ active = config;
+ }
cfgMonitor.worked(1);
}
+ // activate DEBUG configuration...
+ if (active != null) {
+ ICConfigurationDescription conf = ManagedBuildManager.getDescriptionForConfiguration(active);
+ des.setActiveConfiguration(conf);
+ }
mngr.setProjectDescription(project, des);
}