Skip to content

Commit

Permalink
Add ManagedBuildManager#createConfigurationForProject() (#131)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
15knots authored Nov 4, 2022
1 parent ac979bd commit 369ddea
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 15 deletions.
5 changes: 5 additions & 0 deletions NewAndNoteworthy/CDT-11.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -3650,6 +3650,54 @@ private static IConfiguration getConfigurationForDescription(ICConfigurationDesc
return null;
}

/**
* Creates a new <code>IConfiguration</code> object associated to the specified
* managed project and adds it to the corresponding project description.<br>
* 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 <code>ICProjectDescription</code> to use for
* creating the new configuration
* @param managedProject the managed project to associate the new
* <code>IConfiguration</code> with
* @param cloneConfiguration the <code>IConfiguration</code> 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 <code>IConfiguration</code> object
*
* @throws CoreException if the creation of a new
* ICConfigurationDescription failed
* @throws IllegalArgumentException if the <code>IProject</code> associated with
* the specified
* <code>ICProjectDescription</code> does not
* match the project associated with the given
* <code>IManagedProject</code>
* @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()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down

0 comments on commit 369ddea

Please sign in to comment.