1
/*******************************************************************************
2
* Copyright (c) 2002, 2010 IBM Software Corporation and others.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Rational Software - Initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.managedbuilder.internal.core;
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.List;
19
import org.eclipse.cdt.core.model.CModelException;
20
import org.eclipse.cdt.core.model.CoreModel;
21
import org.eclipse.cdt.core.model.ICProject;
22
import org.eclipse.cdt.core.model.IContainerEntry;
23
import org.eclipse.cdt.core.model.IIncludeEntry;
24
import org.eclipse.cdt.core.model.IMacroEntry;
25
import org.eclipse.cdt.core.model.IPathEntry;
26
import org.eclipse.cdt.core.model.IPathEntryContainer;
27
import org.eclipse.cdt.core.parser.IScannerInfo;
28
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
29
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
30
import org.eclipse.cdt.core.settings.model.ICStorageElement;
31
import org.eclipse.cdt.core.settings.model.WriteAccessException;
32
import org.eclipse.cdt.core.settings.model.XmlStorageUtil;
33
import org.eclipse.cdt.managedbuilder.core.BuildException;
34
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
35
import org.eclipse.cdt.managedbuilder.core.IBuilder;
36
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
37
import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
38
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
39
import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo;
40
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
41
import org.eclipse.cdt.managedbuilder.core.IOption;
42
import org.eclipse.cdt.managedbuilder.core.IOptionApplicability;
43
import org.eclipse.cdt.managedbuilder.core.IOptionPathConverter;
44
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
45
import org.eclipse.cdt.managedbuilder.core.ITarget;
46
import org.eclipse.cdt.managedbuilder.core.ITool;
47
import org.eclipse.cdt.managedbuilder.core.IToolChain;
48
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
49
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
50
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
51
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
52
import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData;
53
import org.eclipse.cdt.managedbuilder.internal.scannerconfig.ManagedBuildCPathEntryContainer;
54
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
55
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
56
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGeneratorType;
57
import org.eclipse.core.resources.IProject;
58
import org.eclipse.core.resources.IResource;
59
import org.eclipse.core.runtime.CoreException;
60
import org.eclipse.core.runtime.IPath;
61
import org.eclipse.core.runtime.NullProgressMonitor;
62
import org.eclipse.core.runtime.Path;
63
import org.w3c.dom.Document;
64
import org.w3c.dom.Element;
67
* Concrete IManagedBuildInfo storing runtime ManagedProject metadata with utility settings for accessing
68
* some attributes in the default configuration
70
public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
71
// The path container used for all managed projects
72
public static final IContainerEntry containerEntry = CoreModel.newContainerEntry(new Path("org.eclipse.cdt.managedbuilder.MANAGED_CONTAINER")); //$NON-NLS-1$
73
// private static final QualifiedName defaultConfigProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), DEFAULT_CONFIGURATION);
74
//private static final QualifiedName defaultTargetProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), DEFAULT_TARGET);
76
private volatile IManagedProject managedProject;
77
private volatile ICProject cProject;
78
private volatile boolean isDirty;
79
private volatile boolean isValid = false;
80
private volatile IResource owner;
81
private volatile boolean rebuildNeeded;
82
private volatile String version;
83
private volatile IConfiguration selectedConfig;
86
private List<ITarget> targetList;
88
private Map<String, ITarget> targetMap;
90
private volatile boolean isReadOnly = false;
91
private volatile boolean bIsContainerInited = false;
95
* Basic constructor used when the project is brand new.
97
public ManagedBuildInfo(IResource owner) {
99
cProject = CoreModel.getDefault().create(owner.getProject());
101
// Does not need a save but should be rebuilt
103
rebuildNeeded = true;
107
* Reads the build information from the project file and creates the
108
* internal representation of the build settings for the project.
110
public ManagedBuildInfo(IResource owner, ICStorageElement element, boolean loadConfigs, String managedBuildRevision) {
113
// Recreate the managed build project element and its children
114
ICStorageElement projNodes[] = element.getChildren();
115
// TODO: There should only be 1?
116
for (int projIndex = projNodes.length - 1; projIndex >= 0; --projIndex) {
117
if(IManagedProject.MANAGED_PROJECT_ELEMENT_NAME.equals(projNodes[projIndex].getName())){
118
ManagedProject proj = new ManagedProject(this, projNodes[projIndex], loadConfigs, managedBuildRevision);
119
if (!proj.resolveReferences())
120
proj.setValid(false);
124
// Switch the rebuild off since this is an existing project
125
rebuildNeeded = false;
127
version = managedBuildRevision;
131
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#setManagedProject(IManagedProject)
133
public void setManagedProject(IManagedProject managedProject) {
134
this.managedProject = managedProject;
135
//setDirty(true); - It is primarily up to the ManagedProject to maintain the dirty state
139
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getManagedProject()
141
public IManagedProject getManagedProject() {
142
return managedProject;
146
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#buildsFileType(java.lang.String)
148
public boolean buildsFileType(String srcExt) {
149
return getDefaultConfiguration().buildsFileType(srcExt);
153
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#getBuildArtifactExtension()
155
public String getBuildArtifactExtension() {
156
String ext = new String();
157
IConfiguration config = getDefaultConfiguration();
158
if (config != null) {
159
ext = config.getArtifactExtension();
165
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getBuildArtifactName()
167
public String getBuildArtifactName() {
168
// Get the default configuration and use its value
169
String name = new String();
170
IConfiguration config = getDefaultConfiguration();
171
if (config != null) {
172
name = config.getArtifactName();
178
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getCleanCommand()
180
public String getCleanCommand() {
181
// Get from the model
182
String command = new String();
183
IConfiguration config = getDefaultConfiguration();
184
if (config != null) {
185
command = config.getCleanCommand();
191
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getConfigurationName()
193
public String getConfigurationName() {
194
// Return the human-readable name of the default configuration
195
IConfiguration config = getDefaultConfiguration();
196
return config == null ? new String() : config.getName();
200
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getConfigurationNames()
202
public String[] getConfigurationNames() {
203
ArrayList<String> configNames = new ArrayList<String>();
204
IConfiguration[] configs = managedProject.getConfigurations();
205
for (int i = 0; i < configs.length; i++) {
206
IConfiguration configuration = configs[i];
207
configNames.add(configuration.getName());
209
configNames.trimToSize();
210
return configNames.toArray(new String[configNames.size()]);
213
public ICProject getCProject() {
218
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getDefaultConfiguration()
220
public IConfiguration getDefaultConfiguration() {
221
// Get the default config associated with the project
222
/* if (defaultConfig == null) {
223
if (managedProject != null) {
224
if (defaultConfigId != null) {
225
defaultConfig = managedProject.getConfiguration(defaultConfigId);
227
if (defaultConfig == null) {
228
IConfiguration[] configs = managedProject.getConfigurations();
229
for (int i = 0; i < configs.length; i++){
230
if (configs[i].isSupported()){
231
defaultConfig = configs[i];
232
defaultConfigId = defaultConfig.getId();
236
if (defaultConfig == null && configs.length > 0) {
237
defaultConfig = configs[0];
238
defaultConfigId = defaultConfig.getId();
243
return defaultConfig;
245
IConfiguration activeCfg = findExistingDefaultConfiguration(null);
247
if(activeCfg == null){
248
IConfiguration cfgs[] = managedProject.getConfigurations();
257
private IConfiguration findExistingDefaultConfiguration(ICProjectDescription des) {
259
des = CoreModel.getDefault().getProjectDescription(getOwner().getProject(), false);
260
IConfiguration activeCfg = null;
262
ICConfigurationDescription cfgDes = des.getActiveConfiguration();
263
activeCfg = managedProject.getConfiguration(cfgDes.getId());
270
* @see org.eclipse.cdt.core.build.managed.IScannerInfo#getDefinedSymbols()
272
public Map<String, String> getDefinedSymbols() {
273
// Return the defined symbols for the default configuration
274
HashMap<String, String> symbols = getMacroPathEntries();
279
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#getDependencyGenerator(java.lang.String)
281
public IManagedDependencyGeneratorType getDependencyGenerator(String sourceExtension) {
282
// Find the tool and ask the Managed Build Manager for its dep generator
284
if (getDefaultConfiguration() != null) {
285
ITool[] tools = getDefaultConfiguration().getFilteredTools();
286
for (int index = 0; index < tools.length; ++index) {
287
if(tools[index].buildsFileType(sourceExtension)) {
288
return tools[index].getDependencyGeneratorForExtension(sourceExtension);
292
} catch (NullPointerException e) {
300
* Helper method to extract a list of valid tools that are filtered by the
305
private ITool[] getFilteredTools() {
306
// Get all the tools for the current config filtered by the project nature
307
IConfiguration config = getDefaultConfiguration();
308
return config.getFilteredTools();
312
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getFlagsForSource(java.lang.String)
314
public String getFlagsForSource(String extension) {
315
return getToolFlagsForSource(extension,null,null);
319
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#getToolFlagsForSource(java.lang.String, org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath)
321
public String getToolFlagsForSource(String extension, IPath inputLocation, IPath outputLocation){
322
// Get all the tools for the current config
323
ITool[] tools = getFilteredTools();
324
for (int index = 0; index < tools.length; index++) {
325
ITool tool = tools[index];
326
if (tool != null && tool.buildsFileType(extension)) {
328
return tool.getToolCommandFlagsString(inputLocation,outputLocation);
329
} catch (BuildException e) {
338
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getFlagsForConfiguration(java.lang.String)
340
public String getFlagsForConfiguration(String extension) {
341
return getToolFlagsForConfiguration(extension, null, null);
345
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#getToolFlagsForConfiguration(java.lang.String, org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath)
347
public String getToolFlagsForConfiguration(String extension, IPath inputLocation, IPath outputLocation){
348
// Treat null extensions as an empty string
349
String ext = extension == null ? new String() : extension;
351
// Get all the tools for the current config
352
ITool[] tools = getFilteredTools();
353
for (int index = 0; index < tools.length; index++) {
354
ITool tool = tools[index];
355
if (tool.producesFileType(ext)) {
357
return tool.getToolCommandFlagsString(inputLocation,outputLocation);
358
} catch (BuildException e) {
366
private ArrayList<String> getIncludePathEntries() {
367
// Extract the resolved paths from the project (if any)
368
ArrayList<String> paths = new ArrayList<String>();
369
if (cProject != null) {
371
IPathEntry[] entries = cProject.getResolvedPathEntries();
372
for (int index = 0; index < entries.length; ++index) {
373
int kind = entries[index].getEntryKind();
374
if (kind == IPathEntry.CDT_INCLUDE) {
375
IIncludeEntry include = (IIncludeEntry) entries[index];
376
if (include.isSystemInclude()) {
377
IPath entryPath = include.getFullIncludePath();
378
paths.add(entryPath.toString());
382
} catch (CModelException e) {
383
// Just return an empty array
392
* @see org.eclipse.cdt.core.build.managed.IScannerInfo#getIncludePaths()
394
public String[] getIncludePaths() {
395
// Return the include paths for the default configuration
396
ArrayList<String> paths = getIncludePathEntries();
397
return paths.toArray(new String[paths.size()]);
401
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getLibsForConfiguration(java.lang.String)
403
public String[] getLibsForConfiguration(String extension) {
404
return getDefaultConfiguration().getLibs(extension);
407
private HashMap<String, String> getMacroPathEntries() {
408
HashMap<String, String> macros = new HashMap<String, String>();
409
if (cProject != null) {
411
IPathEntry[] entries = cProject.getResolvedPathEntries();
412
for (int index = 0; index < entries.length; ++index) {
413
if (entries[index].getEntryKind() == IPathEntry.CDT_MACRO) {
414
IMacroEntry macro = (IMacroEntry) entries[index];
415
macros.put(macro.getMacroName(), macro.getMacroValue());
418
} catch (CModelException e) {
419
// return an empty map
429
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getMakeArguments()
431
public String getBuildArguments() {
432
if (getDefaultConfiguration() != null) {
433
IToolChain toolChain = getDefaultConfiguration().getToolChain();
434
IBuilder builder = toolChain.getBuilder();
435
if (builder != null) {
436
return builder.getArguments();
439
return new String("-k"); //$NON-NLS-1$
443
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getMakeCommand()
445
public String getBuildCommand() {
446
if (getDefaultConfiguration() != null) {
447
IToolChain toolChain = getDefaultConfiguration().getToolChain();
448
IBuilder builder = toolChain.getBuilder();
449
if (builder != null) {
450
return builder.getCommand();
453
return new String("make"); //$NON-NLS-1$
459
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getPrebuildStep()
461
public String getPrebuildStep() {
462
// Get the default configuration and use its value
463
String name = new String();
464
IConfiguration config = getDefaultConfiguration();
465
if (config != null) {
466
name = config.getPrebuildStep();
474
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getPostbuildStep()
476
public String getPostbuildStep() {
477
// Get the default configuration and use its value
478
String name = new String();
479
IConfiguration config = getDefaultConfiguration();
480
if (config != null) {
481
name = config.getPostbuildStep();
489
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getPreannouncebuildStep()
491
public String getPreannouncebuildStep() {
492
// Get the default configuration and use its value
493
String name = new String();
494
IConfiguration config = getDefaultConfiguration();
495
if (config != null) {
496
name = config.getPreannouncebuildStep();
504
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getPostannouncebuildStep()
506
public String getPostannouncebuildStep() {
507
// Get the default configuration and use its value
508
String name = new String();
509
IConfiguration config = getDefaultConfiguration();
510
if (config != null) {
511
name = config.getPostannouncebuildStep();
519
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getOutputExtension(java.lang.String)
521
public String getOutputExtension(String resourceExtension) {
522
return getDefaultConfiguration().getOutputExtension(resourceExtension);
528
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getOutputFlag()
530
public String getOutputFlag(String outputExt) {
531
return getDefaultConfiguration().getOutputFlag(outputExt);
535
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getOutputPrefix(java.lang.String)
537
public String getOutputPrefix(String outputExtension) {
538
return getDefaultConfiguration().getOutputPrefix(outputExtension);
542
* @return IResource owner
544
public IResource getOwner() {
549
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getToolForSource(java.lang.String)
551
public String getToolForSource(String sourceExtension) {
552
// Get all the tools for the current config
553
ITool[] tools = getFilteredTools();
554
for (int index = 0; index < tools.length; index++) {
555
ITool tool = tools[index];
556
if (tool.buildsFileType(sourceExtension)) {
557
return tool.getToolCommand();
564
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getToolForConfiguration(java.lang.String)
566
public String getToolForConfiguration(String extension) {
567
// Treat a null argument as an empty string
568
String ext = extension == null ? new String() : extension;
569
// Get all the tools for the current config
570
ITool[] tools = getFilteredTools();
571
for (int index = 0; index < tools.length; index++) {
572
ITool tool = tools[index];
573
if (tool.producesFileType(ext)) {
574
return tool.getToolCommand();
581
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getToolFromInputExtension(java.lang.String)
583
public ITool getToolFromInputExtension(String sourceExtension) {
584
IConfiguration config = getDefaultConfiguration();
585
return config.getToolFromInputExtension(sourceExtension);
589
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getToolFromOutputExtension(java.lang.String)
591
public ITool getToolFromOutputExtension(String extension) {
592
IConfiguration config = getDefaultConfiguration();
593
return config.getToolFromOutputExtension(extension);
597
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#generateCommandLineInfo(java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String, java.lang.String[])
599
public IManagedCommandLineInfo generateCommandLineInfo(
600
String sourceExtension, String[] flags, String outputFlag,
601
String outputPrefix, String outputName, String[] inputResources) {
602
return generateToolCommandLineInfo( sourceExtension, flags,
603
outputFlag, outputPrefix, outputName, inputResources, null, null );
607
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#generateToolCommandLineInfo(java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String, java.lang.String[], org.eclipse.core.runtime.IPath, org.eclipse.core.runtime.IPath)
609
public IManagedCommandLineInfo generateToolCommandLineInfo( String sourceExtension, String[] flags,
610
String outputFlag, String outputPrefix, String outputName, String[] inputResources, IPath inputLocation, IPath outputLocation ){
611
return getDefaultConfiguration().generateToolCommandLineInfo(sourceExtension, flags, outputFlag, outputPrefix, outputName, inputResources, inputLocation, outputLocation);
615
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#getUserObjectsForConfiguration(java.lang.String)
617
public String[] getUserObjectsForConfiguration(String extension) {
618
return getDefaultConfiguration().getUserObjects(extension);
622
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#getVersion()
624
public String getVersion() {
631
public void initializePathEntries() {
632
if (!isValid()) return;
634
IPathEntryContainer container = new ManagedBuildCPathEntryContainer(getOwner().getProject());
635
CoreModel.setPathEntryContainer(new ICProject[]{cProject}, container, new NullProgressMonitor());
636
} catch (CModelException e) {
641
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#isDirty()
643
public boolean isDirty() {
644
// If the info has been flagged dirty, answer true
649
// Check if the project is dirty
650
if (managedProject != null) {
651
return managedProject.isDirty();
657
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#isValid()
659
public boolean isValid() {
660
// If the info has been flagged as valid, answer true
665
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#isReadOnly()
667
public boolean isReadOnly(){
672
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#isHeaderFile(java.lang.String)
674
public boolean isHeaderFile(String ext) {
675
// Check to see if there is a rule to build a file with this extension
676
IConfiguration config = getDefaultConfiguration();
677
return config.isHeaderFile(ext);
684
public boolean isContainerInited() {
685
return bIsContainerInited;
689
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#needsRebuild()
691
public boolean needsRebuild() {
692
if (rebuildNeeded) return true;
694
if (getDefaultConfiguration() != null) {
695
return getDefaultConfiguration().needsRebuild();
703
/* private void persistDefaultConfiguration() {
704
// Persist the default configuration
705
IProject project = owner.getProject();
707
if(defaultConfigId != null)
708
project.setPersistentProperty(defaultConfigProperty, defaultConfigId.toString().trim());
709
} catch (CoreException e) {
715
* Write the contents of the build model to the persistent store
716
* specified in the argument.
717
* @deprecated as of CDT 7.0
720
public void serializeLegacy(Document doc, Element element) {
721
// Write out the managed build project
723
if(managedProject != null){
724
Element projElement = doc.createElement(IManagedProject.MANAGED_PROJECT_ELEMENT_NAME);
725
element.appendChild(projElement);
726
((ManagedProject)managedProject).serialize(XmlStorageUtil.createCStorageTree(projElement), true);
729
Iterator<ITarget> iter = getTargets().listIterator();
730
while (iter.hasNext()) {
732
Target targ = (Target)iter.next();
733
// Create an XML element to hold the target settings
734
Element targetElement = doc.createElement(ITarget.TARGET_ELEMENT_NAME);
735
element.appendChild(targetElement);
736
targ.serialize(doc, targetElement);
738
// persistDefaultTarget();
742
// Remember the default configuration
743
// persistDefaultConfiguration();
750
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#setDefaultConfiguration(org.eclipse.cdt.core.build.managed.IConfiguration)
752
public void setDefaultConfiguration(IConfiguration configuration) {
753
// TODO: This is probably wrong. I'll bet we don't handle the case where all configs are deleted...
754
// But, at least, our UI does not allow the last config to be deleted.
756
if (configuration == null || configuration.isExtensionElement()) return;
758
ICProjectDescription des = null;
760
des = BuildSettingsUtil.checkSynchBuildInfo(getOwner().getProject());
761
} catch (CoreException e1) {
762
ManagedBuilderCorePlugin.log(e1);
765
if (!configuration.equals(findExistingDefaultConfiguration(des))) {
766
IProject project = owner.getProject();
768
des = CoreModel.getDefault().getProjectDescription(project);
770
ICConfigurationDescription activeCfgDes = des.getConfigurationById(configuration.getId());
771
if(activeCfgDes == null){
773
activeCfgDes = des.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, configuration.getConfigurationData());
774
} catch (WriteAccessException e) {
775
} catch (CoreException e) {
779
if(activeCfgDes != null){
780
des.setActiveConfiguration(activeCfgDes);
789
BuildSettingsUtil.checkApplyDescription(owner.getProject(), des);
790
} catch (CoreException e) {
791
ManagedBuilderCorePlugin.log(e);
797
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#setDefaultConfiguration(java.lang.String)
799
public boolean setDefaultConfiguration(String configName) {
800
if (configName != null) {
801
// Look for the configuration with the same name as the argument
802
IConfiguration[] configs = managedProject.getConfigurations();
803
for (int index = configs.length - 1; index >= 0; --index) {
804
IConfiguration config = configs[index];
805
if (configName.equalsIgnoreCase(config.getName())) {
806
setDefaultConfiguration(config);
815
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#setDirty(boolean)
817
public void setDirty(boolean isDirty) {
818
// Reset the dirty status here
819
// and in the managed project
820
if (managedProject != null) {
821
managedProject.setDirty(isDirty);
823
this.isDirty = isDirty;
827
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#setValid(boolean)
829
public void setValid(boolean isValid) {
830
// Reset the valid status
831
this.isValid = isValid;
835
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#setReadOnly(boolean)
837
public void setReadOnly(boolean readOnly){
838
if(!readOnly && isReadOnly)
840
isReadOnly = readOnly;
844
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#setRebuildState(boolean)
846
public void setRebuildState(boolean rebuild) {
847
// TODO: Is the appropriate? Should the rebuild state be stored in the project file?
848
// and in the managed project
849
if (getDefaultConfiguration() != null) {
850
getDefaultConfiguration().setRebuildState(rebuild);
852
// Reset the status here
853
rebuildNeeded = rebuild;
856
public void setVersion(String version) {
857
updateRevision(version);
858
if (version != null && !version.equals(this.version))
859
this.version = version;
860
//setDirty(true); - It is primarily up to the ManagedProject to maintain the dirty state
863
public void setContainerInited(boolean bInited) {
864
bIsContainerInited = bInited;
868
public String toString() {
869
// Just print out the name of the project
870
return "Managed build information for " + owner.getName(); //$NON-NLS-1$
874
* Sets the owner of the receiver to be the <code>IResource</code> specified
877
public void updateOwner(IResource resource) {
878
// Check to see if the owner is the same as the argument
879
if (resource != null) {
880
if (!owner.equals(resource)) {
881
// Update owner on the managed project
882
if(managedProject != null)
883
managedProject.updateOwner(resource);
884
// And finally update the cModelElement
885
cProject = CoreModel.getDefault().create(resource.getProject());
889
setRebuildState(true);
890
// Finally update this managedbuild info's owner
897
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getSelectedConfiguration()
899
public IConfiguration getSelectedConfiguration() {
900
return selectedConfig;
904
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#setSelectedConfiguration(org.eclipse.cdt.core.build.managed.IConfiguration)
906
public void setSelectedConfiguration(IConfiguration config) {
907
selectedConfig = config;
911
* Note: "Target" routines are only currently applicable when loading a CDT 2.0
912
* or earlier managed build project file (.cdtbuild)
916
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#addTarget(org.eclipse.cdt.core.build.managed.ITarget)
919
public void addTarget(ITarget target) {
920
getTargetMap().put(target.getId(), target);
921
getTargets().add(target);
926
* @see org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo#removeTarget(java.lang.String)
929
public void removeTarget(String id) {
930
getTargets().remove(getTarget(id));
931
getTargetMap().remove(id);
937
public ITarget getTarget(String id) {
938
return getTargetMap().get(id);
944
* @return Returns the map of IDs to ITargets.
947
private Map<String, ITarget> getTargetMap() {
948
if (targetMap == null) {
949
targetMap = new HashMap<String, ITarget>();
955
* @see org.eclipse.cdt.core.build.managed.IManagedBuildInfo#getTargets(org.eclipse.cdt.core.build.managed.IConfiguration)
959
public List<ITarget> getTargets() {
960
if (targetList == null) {
961
targetList = new ArrayList<ITarget>();
966
private String getCWD() {
967
String cwd = ""; //$NON-NLS-1$
968
IBuildEnvironmentVariable cwdvar = ManagedBuildManager.getEnvironmentVariableProvider().getVariable("CWD", getDefaultConfiguration(), false, true); //$NON-NLS-1$
969
if (cwdvar != null) { cwd = cwdvar.getValue().replace('\\','/'); }
975
private List<String> processPath(List<String> list, String path, int context, Object obj) {
976
final String EMPTY = ""; //$NON-NLS-1$
980
String paths[] = ManagedBuildManager.getBuildMacroProvider().resolveStringListValue(path, EMPTY, " ", context, obj); //$NON-NLS-1$
982
for(int i = 0; i < paths.length; i++){
983
// Check for registered path converter
984
if (obj instanceof OptionContextData) {
985
OptionContextData optionContext = (OptionContextData) obj;
986
IBuildObject buildObject = optionContext.getParent() ;
987
IOptionPathConverter optionPathConverter = getPathConverter(buildObject);
988
if (null!=optionPathConverter) {
989
IPath platformPath = optionPathConverter
990
.convertToPlatformLocation(paths[i], null, null);
991
paths[i] = platformPath.toOSString();
994
list.add(checkPath(paths[i]));
997
} catch (BuildMacroException e) {
1000
list.add(checkPath(path));
1006
private IOptionPathConverter getPathConverter(IBuildObject buildObject) {
1007
IOptionPathConverter converter = null ;
1008
if (buildObject instanceof ITool) {
1009
ITool tool = (ITool) buildObject;
1010
converter = tool.getOptionPathConverter() ;
1014
private String checkPath(String p){
1015
final String QUOTE = "\""; //$NON-NLS-1$
1016
final String EMPTY = ""; //$NON-NLS-1$
1021
if (p.length()> 1 && p.startsWith(QUOTE) && p.endsWith(QUOTE)) {
1022
p = p.substring(1, p.length()-1);
1025
if ( ".".equals(p) ) { //$NON-NLS-1$
1026
String cwd = getCWD();
1027
if (cwd.length()>0) { p = cwd; }
1029
if (!(new Path(p)).isAbsolute()) {
1030
String cwd = getCWD();
1031
if (cwd.length()>0) { p = cwd + "/" + p; } //$NON-NLS-1$
1038
* Obtain all possible Managed build values
1039
* @return IPathEntry[]
1041
public IPathEntry[] getManagedBuildValues() {
1042
List<IPathEntry> entries = new ArrayList<IPathEntry>();
1044
IPathEntry[] a = getManagedBuildValues(IPathEntry.CDT_INCLUDE);
1045
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
1046
a = getManagedBuildValues(IPathEntry.CDT_LIBRARY);
1047
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
1048
a = getManagedBuildValues(IPathEntry.CDT_MACRO);
1049
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
1050
return entries.toArray(new IPathEntry[entries.size()]);
1054
* Obtain all possible Managed build built-ins
1055
* @return IPathEntry[]
1057
public IPathEntry[] getManagedBuildBuiltIns() {
1058
List<IPathEntry> entries = new ArrayList<IPathEntry>();
1060
IPathEntry[] a = getManagedBuildBuiltIns(IPathEntry.CDT_INCLUDE);
1061
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
1062
a = getManagedBuildBuiltIns(IPathEntry.CDT_LIBRARY);
1063
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
1064
a = getManagedBuildBuiltIns(IPathEntry.CDT_MACRO);
1065
if (a != null) { for (i=0; i<a.length; i++) entries.add(a[i]); }
1066
return entries.toArray(new IPathEntry[entries.size()]);
1069
public IPathEntry[] getManagedBuildValues(int entryType) {
1070
// obtain option values
1071
List<IPathEntry> entries = getOptionValues(entryType, false);
1073
// for includes, get env variables values; useless for other entry types
1074
if (entryType == IPathEntry.CDT_INCLUDE) {
1075
IEnvironmentVariableProvider env = ManagedBuildManager.getEnvironmentVariableProvider();
1076
entries = addIncludes(entries, env.getBuildPaths(getDefaultConfiguration(), IEnvVarBuildPath.BUILDPATH_INCLUDE), Path.EMPTY, 0, null);
1078
return entries.toArray(new IPathEntry[entries.size()]);
1081
public IPathEntry[] getManagedBuildBuiltIns(int entryType) {
1082
List<IPathEntry> entries = getOptionValues(entryType, true);
1083
return entries.toArray(new IPathEntry[entries.size()]);
1088
* @param entryType - data type to be scanned for
1089
* @param builtIns - return either values or built-in's
1090
* @return list of strings which contains all found values
1092
private List<IPathEntry> getOptionValues(int entryType, boolean builtIns) {
1093
List<IPathEntry> entries = new ArrayList<IPathEntry>();
1094
IConfiguration cfg = getDefaultConfiguration();
1096
// process config toolchain's options
1097
entries = readToolsOptions(
1104
// code below (obtaining of resource config values)
1105
// is now commented because resource-related include
1106
// paths are displayed by UI together with config-
1107
// related includes, so paths are duplicated in
1108
// project's "includes" folder.
1110
// Uncomment following code after UI problem fix.
1112
// process resource configurations
1113
IResourceConfiguration[] rescfgs = cfg.getResourceConfigurations();
1114
if (rescfgs != null) {
1115
for (int i=0; i<rescfgs.length; i++) {
1116
entries = readToolsOptions(
1129
* @param entryType - data type: include | library | symbols
1130
* @param entries - list to be affected
1131
* @param builtIns - whether get actual values or builtins
1132
* @param obj - object to be processed (ResCfg | Cfg)
1134
private List<IPathEntry> readToolsOptions(int entryType, List<IPathEntry> entries, boolean builtIns, IBuildObject obj) {
1136
IPath resPath = Path.EMPTY;
1138
// check that entryType is correct
1139
if (entryType != IPathEntry.CDT_INCLUDE &&
1140
//TODO: we need to implement the proper CDT_LIBRARY handling
1141
//calculating the CDT_LIBRARY entries from the managed build
1142
//options is disabled for now, we need to define a new option type
1143
//that will represent library paths
1145
// entryType != IPathEntry.CDT_LIBRARY &&
1146
entryType != IPathEntry.CDT_MACRO) { return entries; }
1148
// calculate parameters depending of object type
1149
if (obj instanceof IResourceConfiguration) {
1150
resPath = new Path(((IResourceConfiguration)obj).getResourcePath()).removeFirstSegments(1);
1151
t = ((IResourceConfiguration)obj).getToolsToInvoke();
1152
} else if (obj instanceof IConfiguration) {
1153
t = ((IConfiguration)obj).getFilteredTools();
1154
} else { return entries; } // wrong object passed
1155
if (t == null) { return entries; }
1157
// process all tools and all their options
1158
for (int i=0; i<t.length; i++) {
1159
IOption[] op = t[i].getOptions();
1160
for (int j=0; j<op.length; j++) {
1162
// check to see if the option has an applicability calculator
1163
IOptionApplicability applicabilityCalculator = op[j].getApplicabilityCalculator();
1164
if (applicabilityCalculator != null &&
1165
!applicabilityCalculator.isOptionUsedInCommandLine(obj, t[i], op[j])) continue;
1168
if (entryType == IPathEntry.CDT_INCLUDE &&
1169
op[j].getValueType() == IOption.INCLUDE_PATH)
1171
OptionContextData ocd = new OptionContextData(op[j], t[i]);
1172
addIncludes(entries, builtIns ? op[j].getBuiltIns() : op[j].getIncludePaths(), resPath, IBuildMacroProvider.CONTEXT_OPTION, ocd);
1173
} else if (entryType == IPathEntry.CDT_LIBRARY &&
1174
op[j].getValueType() == IOption.LIBRARIES)
1176
OptionContextData ocd = new OptionContextData(op[j], t[i]);
1177
addLibraries(entries, builtIns ? op[j].getBuiltIns() : op[j].getLibraries(), resPath, IBuildMacroProvider.CONTEXT_OPTION, ocd);
1178
} else if (entryType == IPathEntry.CDT_MACRO &&
1179
op[j].getValueType() == IOption.PREPROCESSOR_SYMBOLS)
1181
OptionContextData ocd = new OptionContextData(op[j], t[i]);
1182
addSymbols(entries, builtIns ? op[j].getBuiltIns() : op[j].getDefinedSymbols(), resPath, IBuildMacroProvider.CONTEXT_OPTION, ocd);
1183
} else { continue; }
1184
} catch (BuildException e) {}
1190
protected List<IPathEntry> addIncludes(List<IPathEntry> entries, String[] values, IPath resPath, int context ,Object obj) {
1191
return addPaths(entries, values, resPath, context, obj, IPathEntry.CDT_INCLUDE);
1194
protected List<IPathEntry> addPaths(List<IPathEntry> entries, String[] values, IPath resPath, int context ,Object obj, int type){
1195
if (values != null && values.length > 0) {
1196
List<String> list = new ArrayList<String>();
1197
for (int k=0; k<values.length; k++) {
1198
processPath(list, values[k], context, obj);
1201
Iterator<String> iter = list.iterator();
1202
while(iter.hasNext()){
1203
IPathEntry entry = null;
1205
case IPathEntry.CDT_INCLUDE:
1206
entry = CoreModel.newIncludeEntry(resPath, Path.EMPTY, new Path(iter.next()), true);
1208
case IPathEntry.CDT_LIBRARY:
1209
entry = CoreModel.newLibraryEntry(resPath, Path.EMPTY, new Path(iter.next()), null, null, null, true);
1212
if (entry != null && !entries.contains(entry)) { entries.add(entry); }
1218
protected List<IPathEntry> addLibraries(List<IPathEntry> entries, String[] values, IPath resPath, int context, Object obj) {
1219
return addPaths(entries, values, resPath, context, obj, IPathEntry.CDT_LIBRARY);
1222
protected List<IPathEntry> addSymbols(List<IPathEntry> entries, String[] values, IPath resPath, int context, Object obj) {
1223
if (values == null) return entries;
1224
for (int i=0; i<values.length; i++) {
1226
String res[] = ManagedBuildManager.getBuildMacroProvider().resolveStringListValue(values[i],
1227
"", " ", context, obj); //$NON-NLS-1$ //$NON-NLS-2$
1229
for(int k = 0; k < res.length; k++)
1230
createMacroEntry(entries, res[k], resPath);
1232
} catch (BuildMacroException e) {
1238
private List<IPathEntry> createMacroEntry(List<IPathEntry> entries, String val, IPath resPath){
1239
if (val != null && val.length() != 0){
1241
String[] tokens = val.split("="); //$NON-NLS-1$
1242
String key = tokens[0].trim();
1243
String value = (tokens.length > 1) ? tokens[1].trim() : new String();
1244
// Make sure the current entries do not contain a duplicate
1246
Iterator<IPathEntry> entryIter = entries.listIterator();
1247
while (entryIter.hasNext()) {
1248
IPathEntry entry = entryIter.next();
1249
if (entry.getEntryKind() == IPathEntry.CDT_MACRO) {
1250
if (((IMacroEntry)entry).getMacroName().equals(key) &&
1251
((IMacroEntry)entry).getMacroValue().equals(value)) {
1257
if (add) { entries.add(CoreModel.newMacroEntry(resPath, key, value)); }
1262
public void updateRevision(String revision){
1263
if(managedProject != null)
1264
((ManagedProject)managedProject).updateManagedBuildRevision(revision);