Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] RE: Change CDT Project Configuration programmatically

Hello Oleg,

Thx for your quick response. I have already done it like you have
described. The only difference is that I am first copying a
configuration and then trying to set the values of the copy which is not
working at all.

My Code looks like this, maybe you have an Idea! (can contain some
compile errors due to copy paste)

      // Get the project description and configuration
      ICProjectDescription cProjectDescr =
CCorePlugin.getDefault().getProjectDescription(project, true);
      ICConfigurationDescription cConfigDescr =
cProjectDescr.getConfigurationById(buildCfgId);


      // If overwrite is true, delete the cfg and recreate a new one
      if (overwrite && cConfigDescr != null) {
        cProjectDescr.removeConfiguration(cConfigDescr);
        cConfigDescr = null;
      }
      // Create new configuration
      if (cConfigDescr == null) {
        IConfiguration parentConfig =
 
ManagedBuildManager.getConfigurationForDescription(cProjectDescr.getActi
veConfiguration());
        ManagedProject mp = (ManagedProject) imp;

        Configuration config = new Configuration(mp, (Configuration)
parentConfig, buildCfgId, false, true);
        if (config != null) {
          // Copy the settings from the active configuration
          ICConfigurationDescription parentConfigDescr =
 
ManagedBuildManager.getDescriptionForConfiguration(parentConfig);
          cConfigDescr = cProjectDescr.createConfiguration(buildCfgId,
buildCfgName, parentConfigDescr);

          config.exportArtifactInfo();
          config.setName(buildCfgName);
          config.setDescription(buildCfgDescr);

          String target = config.getArtifactName();
          if (target == null || target.length() == 0)
            config.setArtifactName(mp.getDefaultArtifactName());
        }
        String buildCmd="basicBuildCommand";
        config.getEditableBuilder().setCommand(buildCmd);

        config.setConfigurationDescription(cConfigDescr);

        // Activate the new configuration and apply it to the project
        cProjectDescr.setActiveConfiguration(cConfigDescr);
        CoreModel.getDefault().setProjectDescription(project,
cProjectDescr);


Greetings Marko

------------------------------
------------------------------
------------------------------
   4. Change CDT Project Configuration programmatically
      (Tomljenovic Marko (G2/PJ-PMT2))
   5. RE: Change CDT Project Configuration programmatically
      (Krasilnikov, Oleg)
------------------------------

Message: 4
Date: Wed, 12 Dec 2007 14:39:30 +0100
From: "Tomljenovic Marko (G2/PJ-PMT2)"
	<Marko.Tomljenovic@xxxxxxxxxxxx>
Subject: [cdt-dev] Change CDT Project Configuration programmatically
To: <cdt-dev@xxxxxxxxxxx>
Message-ID:
	
<1805A00F0C39F1448396BBFDECA3B6D20177BED9@xxxxxxxxxxxxxxxxxxxxxx>
Content-Type: text/plain; charset="us-ascii"

Hello guys,

I am trying to configure a Standard Make CDT (4.0.2) project
programmatically. I have managed to create a new configuration but now I
am stuck on setting the different settings (e.g. build command, enable
clean build, ...)

I am really searching for quite a while and I cannot find the solution!

Pls hlp

Greetings Marko T.

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
https://dev.eclipse.org/mailman/listinfo/cdt-dev/attachments/20071212/6a
890919/attachment.html

------------------------------

Message: 5
Date: Wed, 12 Dec 2007 17:39:02 +0300
From: "Krasilnikov, Oleg" <oleg.krasilnikov@xxxxxxxxx>
Subject: RE: [cdt-dev] Change CDT Project Configuration
	programmatically
To: "CDT General developers list." <cdt-dev@xxxxxxxxxxx>
Message-ID:
	
<E3C0BCA40296C347AF7142161DB9FC8201472BA6@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
	
Content-Type: text/plain; charset="us-ascii"

Marko,
 
In brief, procedure looks like follows:
 
IProject project = ...; // I hope you have it 
ICProjectDescription prjd = ...; // I hope you have it 
ICConfigurationDescription cfgd = ...; // I hope you have it 
 
// change your fields
IConfiguration cfg =
ManagedBuildManager.getConfigurationForDescription(cfgd);
IBuilder bldr = cfg.getEditableBuilder();
String command = ...; // command without parameters
String arguments = ...; // in Property page, user's line is split to cmd
and args.
boolean cleanState = ...;
 
bldr.setCommand(command);
bldr.setArguments(arguments);
bldr.setCleanBuildEnable(cleanState);
 
// to save your changes, you need do this (normally called when
<OK>/<Apply> pressed) :
 
CoreModel.getDefault().setProjectDescription(project, prjd);
________________________________

You can find some samples of config setting in CDT Property pages UI.
 
They are located in 2 places:
org.eclipse.cdt.managedbuilder.ui.properties (for MBS-specific settings)
org.eclipse.cdt.ui.newui (for CDT core settings).
 
All classes representing Property pages context have "*Tab" name (ex.:
ErrorParsTab.java)
 
In your case, changing build command is performed in 
org.eclipse.cdt.managedbuilder.ui.properties/BuilderSettingsTab.java,
and clean build enabling is made on neighbour tab:
org.eclipse.cdt.managedbuilder.ui.properties/BuildBehaviourTab.java,


Back to the top