1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Added hasNature expression for MBS enablement. This allows things like setting magic options when the C++ nature is in effect for a project, like for the linker.

This commit is contained in:
Doug Schaefer 2007-07-25 20:21:01 +00:00
parent d2b052c767
commit 04e799d307
3 changed files with 100 additions and 10 deletions

View file

@ -922,7 +922,6 @@ The value of this attribute is used only in case languageInfoCalculator is not s
<documentation>
Specifies the name of the class that implements org.eclipse.cdt.managedbuilder.core.ILanguageInfoCalculator for dinamic providing the language id info.
Overrides language id specified with the languageId attribute.
</documentation>
<appInfo>
<meta.attribute kind="java" basedOn=":org.eclipse.cdt.managedbuilder.core.ILanguageInfoCalculator"/>
@ -1933,6 +1932,7 @@ If the &quot;buildPathResolver&quot; attribute is specified, the &quot;pathDelim
<element ref="false" minOccurs="0" maxOccurs="unbounded"/>
<element ref="checkHolder" minOccurs="0" maxOccurs="unbounded"/>
<element ref="checkBuildProperty" minOccurs="0" maxOccurs="unbounded"/>
<element ref="hasNature" minOccurs="0" maxOccurs="unbounded"/>
</choice>
<attribute name="type" type="string" use="default" value="ALL">
<annotation>
@ -2325,6 +2325,23 @@ The only difference between this element and the resourceConfiguration is that r
</complexType>
</element>
<element name="hasNature">
<annotation>
<documentation>
Checks whether the project containing the resource has a given nature
</documentation>
</annotation>
<complexType>
<attribute name="natureId" type="string">
<annotation>
<documentation>
The id of the nature
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<meta.section type="since"/>

View file

@ -39,23 +39,24 @@ public abstract class CompositeExpression implements IBooleanExpression {
protected IBooleanExpression createExpression(IManagedConfigElement element){
String name = element.getName();
if(AndExpression.NAME.equals(name))
if (AndExpression.NAME.equals(name))
return new AndExpression(element);
else if(OrExpression.NAME.equals(name))
else if (OrExpression.NAME.equals(name))
return new OrExpression(element);
else if(NotExpression.NAME.equals(name))
else if (NotExpression.NAME.equals(name))
return new NotExpression(element);
else if(CheckOptionExpression.NAME.equals(name))
else if (CheckOptionExpression.NAME.equals(name))
return new CheckOptionExpression(element);
else if(CheckStringExpression.NAME.equals(name))
else if (CheckStringExpression.NAME.equals(name))
return new CheckStringExpression(element);
else if(FalseExpression.NAME.equals(name))
else if (FalseExpression.NAME.equals(name))
return new FalseExpression(element);
else if(CheckHolderExpression.NAME.equals(name))
else if (CheckHolderExpression.NAME.equals(name))
return new CheckHolderExpression(element);
else if(CheckBuildPropertyExpression.NAME.equals(name)){
else if (CheckBuildPropertyExpression.NAME.equals(name))
return new CheckBuildPropertyExpression(element);
}
else if (HasNatureExpression.NAME.equals(name))
return new HasNatureExpression(element);
return null;
}

View file

@ -0,0 +1,72 @@
/**********************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
**********************************************************************/
package org.eclipse.cdt.managedbuilder.internal.enablement;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IHoldsOptions;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
/**
* @author Doug Schaefer
*
*/
public class HasNatureExpression implements IBooleanExpression {
public static final String NAME = "hasNature";
private static final String NATURE_ID = "natureId";
private String natureId;
public HasNatureExpression(IManagedConfigElement element) {
natureId = element.getAttribute(NATURE_ID);
}
public boolean evaluate(IResourceInfo rcInfo, IHoldsOptions holder,
IOption option) {
// All null checks returns false to keep this expression
// from accidentally turning things on. Although
// a 'z' value would be better to avoid having any affect.
if (natureId == null || natureId.length() == 0)
return false;
IConfiguration config = rcInfo.getParent();
if (config == null)
return false;
IResource resource = config.getOwner();
if (resource == null)
return false;
IProject project = resource.getProject();
try {
IProjectDescription projDesc = project.getDescription();
String[] natures = projDesc.getNatureIds();
for (int i = 0; i < natures.length; ++i) {
if (natureId.equals(natures[i]))
return true;
}
// Not found
return false;
} catch (CoreException e) {
ManagedBuilderCorePlugin.log(e);
return false;
}
}
}