Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Treggiari2005-04-28 16:55:15 +0000
committerLeo Treggiari2005-04-28 16:55:15 +0000
commitb1de8f55f519fa30eeed24456bfea98eec5abe1a (patch)
tree40385c5446e471a2fd62f06dc6215201cad51f5d /build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt
parent3bdeb43cf3ff0e99e61c85063651849d3a8c8722 (diff)
downloadorg.eclipse.cdt-b1de8f55f519fa30eeed24456bfea98eec5abe1a.tar.gz
org.eclipse.cdt-b1de8f55f519fa30eeed24456bfea98eec5abe1a.tar.xz
org.eclipse.cdt-b1de8f55f519fa30eeed24456bfea98eec5abe1a.zip
Initial check-in for the build environment variable support
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IBuildPathResolver.java34
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java9
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IEnvVarBuildPath.java61
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IProjectType.java12
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java7
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java13
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ManagedBuildManager.java31
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IBuildEnvironmentVariable.java69
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IConfigurationEnvironmentVariableSupplier.java61
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentBuildPathsChangeListener.java34
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentVariableProvider.java112
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentVariableSupplier.java34
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IProjectEnvironmentVariableSupplier.java62
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java14
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/EnvVarBuildPath.java138
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java17
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java17
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties4
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java47
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java30
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java53
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java7
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/BuildEnvVar.java80
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/DefaultContextInfo.java101
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EclipseEnvironmentSupplier.java62
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvVarCollector.java114
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvVarOperationProcessor.java251
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvironmentVariableProvider.java513
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/ExternalExtensionEnvironmentSupplier.java230
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/IContextInfo.java42
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/MbsEnvironmentSupplier.java90
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvVar.java109
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvironment.java195
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvironmentLoader.java220
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StoredBuildPathEnvironmentContainer.java265
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/UserDefinedEnvironmentSupplier.java349
-rw-r--r--build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java2
37 files changed, 3471 insertions, 18 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IBuildPathResolver.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IBuildPathResolver.java
new file mode 100644
index 00000000000..45f4677df99
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IBuildPathResolver.java
@@ -0,0 +1,34 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.core;
+
+/**
+ * this interface is to be implemented by the tool-integrator to provide some specific
+ * logic for resolving the build path variable values to the build paths
+ * @since 3.0
+ */
+public interface IBuildPathResolver {
+
+ /**
+ *
+ * @param pathType one of the IEnvVarBuildPath.BUILDPATH _xxx
+ * @param variableName represents the name of the variable that holds the build paths
+ * @param variableValue represents the value of the value specified with the
+ * variableName argument
+ * @param configuration represents configuration for which the build paths are requested
+ */
+ String[] resolveBuildPaths(
+ int pathType,
+ String variableName,
+ String variableValue,
+ IConfiguration configuration);
+}
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java
index a11e0b82904..c369142d11f 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IConfiguration.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.core;
+import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -425,4 +426,12 @@ public interface IConfiguration extends IBuildObject {
* @return boolean
*/
public boolean isSupported();
+
+ /**
+ * Returns the implementation of the IConfigurationEnvironmentVariableSupplier provided
+ * by the tool-integrator or <code>null</code> if none.
+ *
+ * @return IConfigurationEnvironmentVariableSupplier
+ */
+ public IConfigurationEnvironmentVariableSupplier getEnvironmentVariableSupplier();
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IEnvVarBuildPath.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IEnvVarBuildPath.java
new file mode 100644
index 00000000000..17b805aa449
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IEnvVarBuildPath.java
@@ -0,0 +1,61 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.core;
+
+/**
+ *
+ * @since 3.0
+ */
+public interface IEnvVarBuildPath {
+ public static final int BUILDPATH_INCLUDE = 1;
+ public static final int BUILDPATH_LIBRARY = 2;
+
+ public static final String BUILD_PATH_ELEMENT_NAME = "envVarBuildPath"; //$NON-NLS-1$
+ public static final String TYPE = "pathType"; //$NON-NLS-1$
+ public static final String LIST = "variableList"; //$NON-NLS-1$
+ public static final String PATH_DELIMITER = "pathDelimiter"; //$NON-NLS-1$
+ public static final String BUILD_PATH_RESOLVER = "buildPathResolver"; //$NON-NLS-1$
+
+ public static final String TYPE_INCLUDE = "buildpathInclude"; //$NON-NLS-1$
+ public static final String TYPE_LIBRARY = "buildpathLibrary"; //$NON-NLS-1$
+
+ public static final String NAME_SEPARATOR = ","; //$NON-NLS-1$
+
+ /**
+ *
+ * @return one of the ITool.BUILDPATH _xxx
+ */
+ public int getType();
+
+ /**
+ *
+ * @return the array of String representing the build variable names
+ */
+ public String[] getVariableNames();
+
+ /**
+ *
+ * @return the String representing the path delimiter used in the variables returned by
+ * the getVariableNames() method
+ */
+ public String getPathDelimiter();
+
+ /**
+ *
+ * @return the IBuildPathResolver interface implementation provided by the tool-integrator
+ * in order to specify his/her own logic of resolving the variable values to the build paths
+ * (see also the "Specifying the Includes and Library paths environment variables" and
+ * the "IBuildPathResolver" sections for more detail and for explanation why this callback
+ * might be needed)
+ */
+ public IBuildPathResolver getBuildPathResolver();
+}
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IProjectType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IProjectType.java
index 484992c42dd..c371372b4be 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IProjectType.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IProjectType.java
@@ -10,6 +10,9 @@
**********************************************************************/
package org.eclipse.cdt.managedbuilder.core;
+import org.eclipse.cdt.managedbuilder.envvar.IProjectEnvironmentVariableSupplier;
+import org.eclipse.core.runtime.IConfigurationElement;
+
/**
* This class represents project-types in the managed build system.
* A project-type is a tool-integrator defined class of project which
@@ -44,6 +47,7 @@ public interface IProjectType extends IBuildObject {
public static final String IS_ABSTRACT = "isAbstract"; //$NON-NLS-1$
public static final String UNUSED_CHILDREN = "unusedChildren"; //$NON-NLS-1$
public static final String IS_TEST = "isTest"; //$NON-NLS-1$
+ public static final String PROJECT_ENVIRONMENT_SUPPLIER = "projectEnvironmentSupplier"; //$NON-NLS-1$
/**
* Creates a configuration for this project-type populated with the tools
@@ -135,4 +139,12 @@ public interface IProjectType extends IBuildObject {
* @return boolean
*/
public boolean isSupported();
+
+ /**
+ * Returns the tool-integrator provided implementation of the project environment variable supplier
+ * or <code>null</code> if none.
+ *
+ * @return IProjectEnvironmentVariableSupplier
+ */
+ public IProjectEnvironmentVariableSupplier getEnvironmentVariableSupplier();
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java
index 13f09d5db74..58520462a54 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/ITool.java
@@ -688,4 +688,11 @@ public interface ITool extends IBuildObject {
* @return boolean
*/
public boolean isExtensionElement();
+
+ /**
+ * Returns an array of the Environment Build Path variable descriptors
+ *
+ * @return IEnvVarBuildPath[]
+ */
+ public IEnvVarBuildPath[] getEnvVarBuildPaths();
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java
index b2b19ada5a7..dd5f15f08f2 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/core/IToolChain.java
@@ -10,6 +10,9 @@
**********************************************************************/
package org.eclipse.cdt.managedbuilder.core;
+import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
+import org.eclipse.core.runtime.IConfigurationElement;
+
/**
* This interface represents a tool-integrator-defined, ordered set of tools
@@ -35,6 +38,8 @@ public interface IToolChain extends IBuildObject {
public static final String TARGET_TOOL = "targetTool"; //$NON-NLS-1$
public static final String SECONDARY_OUTPUTS = "secondaryOutputs"; //$NON-NLS-1$
public static final String IS_TOOL_CHAIN_SUPPORTED = "isToolChainSupported"; //$NON-NLS-1$
+ public static final String CONFIGURATION_ENVIRONMENT_SUPPLIER = "configurationEnvironmentSupplier"; //$NON-NLS-1$
+
// The attribute name for the scanner info collector
public static final String SCANNER_CONFIG_PROFILE_ID = "scannerConfigDiscoveryProfileId"; //$NON-NLS-1$
@@ -289,4 +294,12 @@ public interface IToolChain extends IBuildObject {
* @return boolean
*/
public boolean isSupported();
+
+ /**
+ * Returns the tool-integrator provided implementation of the configuration environment variable supplier
+ * or <code>null</code> if none.
+ *
+ * @return IConfigurationEnvironmentVariableSupplier
+ */
+ public IConfigurationEnvironmentVariableSupplier getEnvironmentVariableSupplier();
}
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 fc5e97a4d69..29858ecef50 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
@@ -44,6 +44,8 @@ import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoChangeListener;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
import org.eclipse.cdt.managedbuilder.internal.core.Builder;
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.DefaultManagedConfigElement;
@@ -61,6 +63,7 @@ import org.eclipse.cdt.managedbuilder.internal.core.Target;
import org.eclipse.cdt.managedbuilder.internal.core.TargetPlatform;
import org.eclipse.cdt.managedbuilder.internal.core.Tool;
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
+import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider;
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
import org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator;
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
@@ -155,7 +158,18 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
private static Map buildModelListeners;
// Random number for derived object model elements
private static Random randomNumber;
+ // Environment Build Paths Change Listener
+ private static IEnvironmentBuildPathsChangeListener fEnvironmentBuildPathsChangeListener;
+ static {
+ getEnvironmentVariableProvider().subscribe(
+ fEnvironmentBuildPathsChangeListener = new IEnvironmentBuildPathsChangeListener(){
+ public void buildPathsChanged(IConfiguration configuration, int buildPathType){
+ if(buildPathType == IEnvVarBuildPath.BUILDPATH_INCLUDE)
+ notifyListeners(configuration,null);
+ }
+ });
+ }
/**
* Returns the next random number.
*
@@ -576,6 +590,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
public static IManagedBuilderMakefileGenerator getBuildfileGenerator(IConfiguration config) {
try {
IToolChain toolChain = config.getToolChain();
+ if(toolChain != null){
IBuilder builder = toolChain.getBuilder();
IConfigurationElement element = builder.getBuildFileGeneratorElement();
if (element != null) {
@@ -590,6 +605,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
}
}
}
+ }
catch (CoreException e) {
// Probably not defined
}
@@ -650,7 +666,9 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
private static void notifyListeners(IConfiguration config, IOption option) {
// Continue if change is something that effect the scanner
try {
- if (!(option.getValueType() == IOption.INCLUDE_PATH
+ //an option can be null in the case of calling this method from the environment
+ //build path change listener
+ if (option != null && !(option.getValueType() == IOption.INCLUDE_PATH
|| option.getValueType() == IOption.PREPROCESSOR_SYMBOLS)) {
return;
}
@@ -1330,7 +1348,7 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
buildInfo.setVersion(fileVersion);
}
if(!UpdateManagedProjectManager.isCompatibleProject(buildInfo)){
- UpdateManagedProjectManager.updateProject(project, buildInfo);
+ UpdateManagedProjectManager.updateProject(project,buildInfo);
}
if (buildInfo.getManagedProject() == null ||
(!buildInfo.getManagedProject().isValid())) {
@@ -2024,4 +2042,13 @@ public class ManagedBuildManager extends AbstractCExtension implements IScannerI
public static void OutputManifestError(String message) {
System.err.println(ManagedMakeMessages.getResourceString(MANIFEST_ERROR_HEADER) + message + NEWLINE);
}
+
+ /**
+ * Returns the instance of the Environment Variable Provider
+ *
+ * @return IEnvironmentVariableProvider
+ */
+ public static IEnvironmentVariableProvider getEnvironmentVariableProvider(){
+ return EnvironmentVariableProvider.getDefault();
+ }
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IBuildEnvironmentVariable.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IBuildEnvironmentVariable.java
new file mode 100644
index 00000000000..8086a64e315
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IBuildEnvironmentVariable.java
@@ -0,0 +1,69 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.envvar;
+
+/**
+ * this interface represents the given environment variable
+ * @since 3.0
+ */
+public interface IBuildEnvironmentVariable{
+ public static final int ENVVAR_REPLACE = 1;
+ public static final int ENVVAR_REMOVE = 2;
+ public static final int ENVVAR_PREPEND = 3;
+ public static final int ENVVAR_APPEND = 4;
+
+ /**
+ *
+ * @return the variable name
+ */
+ public String getName();
+
+ /**
+ *
+ * @return the variable value
+ */
+ public String getValue();
+
+ /**
+ * @return one of the IBuildEnvironmentVariable.ENVVAR_* operation types
+ */
+ public int getOperation();
+
+ /**
+ * @return if the variable can hold the list of values this method returns the String representing
+ * the delimiter that is used to separate values. This information is used for the following:
+ *
+ * 1. in append and prepend operations:
+ * If the variable already exists and contains some value the new
+ * value will be calculated in the following way:
+ * For the "prepend" operation:
+ * <New value> = <the value from the getValue() method><delimiter><Old value>
+ * For the "append" operation:
+ * <New value> = <Old value><delimiter><the value from the getValue() method>
+ *
+ * The Environment Variable Provider will also remove the duplicates of "sub-values"
+ * in the resulting value.
+ * For example:
+ * If the current value is "string1:string2:string3", the getDelimiter() method returns “:”
+ * and getValue() method returns "string4:string2" the new value will contain:
+ * For the "prepend" operation: "string4:string2:string1:string3"
+ * For the "append" operation: "string1:string3:string4:string2"
+ *
+ * 2. Since the environment variables are also treated as build macros the delimiter is also used
+ * by the BuildMacroProvider to determine the type of the macro used to represent the
+ * given environment variable. If the variable has the delimiter it is treated as the Text-List macro
+ * otherwise it is treated as the Text macro. (See Build Macro design for more details)
+ *
+ * To specify that no delimiter should be used, the getDelimiter() method should
+ * return null or an empty string
+ */
+ public String getDelimiter();
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IConfigurationEnvironmentVariableSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IConfigurationEnvironmentVariableSupplier.java
new file mode 100644
index 00000000000..9fd80574782
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IConfigurationEnvironmentVariableSupplier.java
@@ -0,0 +1,61 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.envvar;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+
+/**
+ *
+ * this interface is to be implemented by the tool-integrator
+ * for supplying the configuration-specific environment
+ *
+ * @since 3.0
+ */
+public interface IConfigurationEnvironmentVariableSupplier{
+ /**
+ *
+ * @param variableName the variable mane
+ * @param configuration configuration
+ * @param provider the instance of the environment variable provider to be used for querying the
+ * environment variables from within the supplier. The supplier should use this provider to obtain
+ * the already defined environment instead of using the "default" provider returned by the
+ * ManagedBuildManager.getEnvironmentVariableProvider().
+ * The provider passed to a supplier will ignore searching the variables for the levels
+ * higher than the current supplier level, will query only the lower-precedence suppliers
+ * for the current level and will query all suppliers for the lower levels.
+ * This is done to avoid infinite loops that could be caused if the supplier calls the provider
+ * and the provider in turn calls that supplier again. Also the supplier should not know anything
+ * about the environment variables defined for the higher levels.
+ * @return the reference to the IBuildEnvironmentVariable interface representing
+ * the variable of a given name
+ */
+ IBuildEnvironmentVariable getVariable(String variableName,
+ IConfiguration configuration,
+ IEnvironmentVariableProvider provider);
+
+ /**
+ * @param configuration configuration
+ * @param provider the instance of the environment variable provider to be used for querying the
+ * environment variables from within the supplier. The supplier should use this provider to obtain
+ * the already defined environment instead of using the "default" provider returned by the
+ * ManagedBuildManager.getEnvironmentVariableProvider().
+ * The provider passed to a supplier will ignore searching the variables for the levels
+ * higher than the current supplier level, will query only the lower-precedence suppliers
+ * for the current level and will query all suppliers for the lower levels.
+ * This is done to avoid infinite loops that could be caused if the supplier calls the provider
+ * and the provider in turn calls that supplier again. Also the supplier should not know anything
+ * about the environment variables defined for the higher levels.
+ * @return the array of IBuildEnvironmentVariable that represents the environment variables
+ */
+ IBuildEnvironmentVariable[] getVariables (IConfiguration configuration,
+ IEnvironmentVariableProvider provider);
+}
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentBuildPathsChangeListener.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentBuildPathsChangeListener.java
new file mode 100644
index 00000000000..006f1b82f32
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentBuildPathsChangeListener.java
@@ -0,0 +1,34 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.envvar;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+
+/**
+ *
+ * listeners of the environment build path changes should implement this interface
+ *
+ * @since 3.0
+ */
+public interface IEnvironmentBuildPathsChangeListener {
+
+ /**
+ *
+ * @param configuration represent the configuration for which the paths were changed
+ * @param buildPathType set to one of
+ * the IEnvVarBuildPath.BUILDPATH_xxx
+ * (the IEnvVarBuildPath will represent the build environment variables, see also
+ * the "Specifying the Includes and Library paths environment variables",
+ * the "envVarBuildPath schema" and the "Expected CDT/MBS code changes" sections)
+ */
+ void buildPathsChanged(IConfiguration configuration, int buildPathType);
+}
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentVariableProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentVariableProvider.java
new file mode 100644
index 00000000000..ea55e0be1af
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentVariableProvider.java
@@ -0,0 +1,112 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.envvar;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+
+/**
+ *
+ * this interface represent the environment variable provider - the main entry-point
+ * to be used for querying the build environment
+ *
+ * @since 3.0
+ */
+public interface IEnvironmentVariableProvider{
+
+ /**
+ *
+ *
+ * @return the reference to the IBuildEnvironmentVariable interface representing
+ * the variable of a given name
+ * @param variableName environment variable name
+ * if environment variable names are case insensitive in the current OS,
+ * the environment variable provider will query the getVariable method of suppliers always
+ * passing it the uppercase variable name not depending on the case of the variableName
+ * passed to the IEnvironmentVariableProvider.getVariable() method. This will prevent the
+ * supplier from answering different values for the same variable given the names that differ
+ * only by case. E.g. if the current OS does not support case sensitive variables both of the
+ * calls below:
+ *
+ * provider.getVariable("FOO",level,includeParentContexts);
+ * provider.getVariable("foo",level,includeParentContexts);
+ *
+ * will result in asking suppliers for the "FOO" variable
+ *
+ * @param level could be one of the following:
+ * 1. IConfiguration to represent the configuration
+ * 2. IManagedProject to represent the managed project
+ * 3. IWorkspace to represent the workspace
+ * 4. null to represent the system environment passed to eclipse
+ */
+ public IBuildEnvironmentVariable getVariable(
+ String variableName, Object level, boolean includeParentLevels);
+
+ /**
+ *
+ * if environment variable names are case insensitive in the current OS,
+ * the environment variable provider will remove the duplicates of the variables if their names
+ * differ only by case
+ *
+ * @return the array of IBuildEnvironmentVariable that represents the environment variables
+ */
+ public IBuildEnvironmentVariable[] getVariables(
+ Object level, boolean includeParentLevels);
+
+ /**
+ *
+ * @return the String representing default system delimiter. That is the ":" for Unix-like
+ * systems and the ";" for Win32 systems. This method will be used by the
+ * tool-integrator provided variable supplier e.g. in order to concatenate the list of paths into the
+ * environment variable, etc.
+ */
+ public String getDefaultDelimiter();
+
+ /**
+ * @return true if the OS supports case sensitive variables (Unix-like systems) or false
+ * if it does not (Win32 systems)
+ */
+ public boolean isVariableCaseSensitive();
+
+ /**
+ * This method is defined to be used basically by the UI classes and should not be used by the
+ * tool-integrator
+ * @return the array of the provider-internal suppliers for the given level
+ */
+ IEnvironmentVariableSupplier[] getSuppliers(Object level);
+
+
+ /**
+ * returns the array of String that holds the build paths of the specified type
+ * @param configuration represent the configuration for which the paths were changed
+ * @param buildPathType can be set to one of the IEnvVarBuildPath.BUILDPATH _xxx
+ * (the IEnvVarBuildPath will represent the build environment variables, see also
+ * the "Specifying the Includes and Library paths environment variables",
+ * the "envVarBuildPath schema" and the "Expected CDT/MBS code changes" sections)
+ */
+ String[] getBuildPaths(IConfiguration configuration, int buildPathType);
+
+ /**
+ *
+ * adds the listener that will return notifications about the include and library paths changes.
+ * The ManagedBuildManager will register the change listener and will notify all registered
+ * Scanned Info Change Listeners about the include paths change.
+ */
+ void subscribe(
+ IEnvironmentBuildPathsChangeListener listener);
+
+ /**
+ *
+ * removes the include and library paths change listener
+ */
+ void unsubscribe(
+ IEnvironmentBuildPathsChangeListener listener);
+}
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentVariableSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentVariableSupplier.java
new file mode 100644
index 00000000000..257ad01bf97
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IEnvironmentVariableSupplier.java
@@ -0,0 +1,34 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.envvar;
+
+/**
+ *
+ * @since 3.0
+ */
+public interface IEnvironmentVariableSupplier {
+
+ /**
+ *
+ * @param name the variable mane
+ * @param context the context
+ * @return the reference to the IBuildEnvironmentVariable interface representing
+ * the variable of a given name
+ */
+ IBuildEnvironmentVariable getVariable(String name, Object context);
+
+ /**
+ *
+ * @param context the context
+ * @return the array of IBuildEnvironmentVariable that represents the environment variables
+ */
+ IBuildEnvironmentVariable[] getVariables(Object context);
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IProjectEnvironmentVariableSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IProjectEnvironmentVariableSupplier.java
new file mode 100644
index 00000000000..fb1b3cc789c
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/envvar/IProjectEnvironmentVariableSupplier.java
@@ -0,0 +1,62 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.envvar;
+
+import org.eclipse.cdt.managedbuilder.core.IManagedProject;
+
+/**
+ *
+ * this interface is to be implemented by the tool-integrator
+ * for supplying the project-specific environment
+ *
+ * @since 3.0
+ */
+public interface IProjectEnvironmentVariableSupplier{
+ /**
+ *
+ * @param variableName the variable mane
+ * @param project the managed project
+ * @param provider the instance of the environment variable provider to be used for querying the
+ * environment variables from within the supplier. The supplier should use this provider to obtain
+ * the already defined environment instead of using the "default" provider returned by the
+ * ManagedBuildManager.getEnvironmentVariableProvider().
+ * The provider passed to a supplier will ignore searching the variables for the levels
+ * higher than the current supplier level, will query only the lower-precedence suppliers
+ * for the current level and will query all suppliers for the lower levels.
+ * This is done to avoid infinite loops that could be caused if the supplier calls the provider
+ * and the provider in turn calls that supplier again. Also the supplier should not know anything
+ * about the environment variables defined for the higher levels.
+ * @return the reference to the IBuildEnvironmentVariable interface representing
+ * the variable of a given name
+ */
+ IBuildEnvironmentVariable getVariable(String variableName,
+ IManagedProject project,
+ IEnvironmentVariableProvider provider);
+
+ /**
+ *
+ * @param project the managed project
+ * @param provider the instance of the environment variable provider to be used for querying the
+ * environment variables from within the supplier. The supplier should use this provider to obtain
+ * the already defined environment instead of using the "default" provider returned by the
+ * ManagedBuildManager.getEnvironmentVariableProvider().
+ * The provider passed to a supplier will ignore searching the variables for the levels
+ * higher than the current supplier level, will query only the lower-precedence suppliers
+ * for the current level and will query all suppliers for the lower levels.
+ * This is done to avoid infinite loops that could be caused if the supplier calls the provider
+ * and the provider in turn calls that supplier again. Also the supplier should not know anything
+ * about the environment variables defined for the higher levels.
+ * @return the array of IBuildEnvironmentVariable that represents the environment variables
+ */
+ IBuildEnvironmentVariable[] getVariables (IManagedProject project,
+ IEnvironmentVariableProvider provider);
+}
+
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java
index bb86377bbcc..2109111bc1b 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java
@@ -34,6 +34,8 @@ import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.ResourceConfiguration;
+import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
+import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -1208,6 +1210,8 @@ public class Configuration extends BuildObject implements IConfiguration {
*/
public void setRebuildState(boolean rebuild) {
rebuildNeeded = rebuild;
+ if(rebuild)
+ ((EnvironmentVariableProvider)ManagedBuildManager.getEnvironmentVariableProvider()).checkBuildPathVariables(this);
}
/* (non-Javadoc)
@@ -1297,4 +1301,14 @@ public class Configuration extends BuildObject implements IConfiguration {
addResourceConfiguration(resConfig);
return resConfig;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.IConfiguration#getEnvironmentVariableSupplier()
+ */
+ public IConfigurationEnvironmentVariableSupplier getEnvironmentVariableSupplier(){
+ IToolChain toolChain = getToolChain();
+ if(toolChain != null)
+ return toolChain.getEnvironmentVariableSupplier();
+ return null;
+ }
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/EnvVarBuildPath.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/EnvVarBuildPath.java
new file mode 100644
index 00000000000..5b091ddca32
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/EnvVarBuildPath.java
@@ -0,0 +1,138 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.core;
+
+import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver;
+import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
+import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
+import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+
+public class EnvVarBuildPath implements
+ IEnvVarBuildPath {
+ private ITool tool;
+
+ private int type;
+ private String variableNames[];
+ private String pathDelimiter;
+ private IBuildPathResolver buildPathResolver;
+ private IConfigurationElement buildPathResolverElement;
+
+
+ /**
+ * Constructor to create an EnvVarBuildPath based on an element from the plugin
+ * manifest.
+ *
+ * @param element The element containing the information about the tool.
+ */
+ public EnvVarBuildPath(ITool tool, IManagedConfigElement element) {
+ this.tool = tool;
+ loadFromManifest(element);
+ }
+
+ /* (non-Javadoc)
+ * Load the EnvVarBuildPath information from the XML element specified in the
+ * argument
+ * @param element An XML element containing the tool information
+ */
+ protected void loadFromManifest(IManagedConfigElement element) {
+
+ setType(convertPathTypeToInt(element.getAttribute(TYPE)));
+
+ setVariableNames(element.getAttribute(LIST));
+
+ setPathDelimiter(element.getAttribute(PATH_DELIMITER));
+
+ // Store the configuration element IFF there is a build path resolver defined
+ String buildPathResolver = element.getAttribute(BUILD_PATH_RESOLVER);
+ if (buildPathResolver != null && element instanceof DefaultManagedConfigElement) {
+ buildPathResolverElement = ((DefaultManagedConfigElement)element).getConfigurationElement();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath#getType()
+ */
+ public int getType() {
+ return type;
+ }
+
+ public void setType(int type){
+ this.type = type;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath#getVariableNames()
+ */
+ public String[] getVariableNames() {
+ return variableNames;
+ }
+
+ public void setVariableNames(String names[]){
+ this.variableNames = names;
+ }
+
+ public void setVariableNames(String names){
+ setVariableNames(getNamesFromString(names));
+ }
+
+ public String[] getNamesFromString(String names){
+ if(names == null)
+ return null;
+ return names.split(NAME_SEPARATOR);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath#getPathDelimiter()
+ */
+ public String getPathDelimiter() {
+ return pathDelimiter;
+ }
+
+ public void setPathDelimiter(String delimiter) {
+ if(delimiter == null)
+ delimiter = ManagedBuildManager.getEnvironmentVariableProvider().getDefaultDelimiter();
+ this.pathDelimiter = delimiter;
+ }
+
+ private int convertPathTypeToInt(String pathType){
+ if(pathType != null && TYPE_LIBRARY.equals(pathType))
+ return BUILDPATH_LIBRARY;
+ return BUILDPATH_INCLUDE;
+ }
+
+ private String convertPathTypeToString(int pathType){
+ switch(pathType){
+ case BUILDPATH_LIBRARY:
+ return TYPE_LIBRARY;
+ case BUILDPATH_INCLUDE:
+ default:
+ return TYPE_INCLUDE;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath#getBuildPathResolver()
+ */
+ public IBuildPathResolver getBuildPathResolver() {
+ if(buildPathResolver == null && buildPathResolverElement != null){
+ try {
+ if (buildPathResolverElement.getAttribute(BUILD_PATH_RESOLVER) != null) {
+ buildPathResolver = (IBuildPathResolver) buildPathResolverElement.createExecutableExtension(BUILD_PATH_RESOLVER);
+ }
+ } catch (CoreException e) {}
+ }
+ return buildPathResolver;
+ }
+
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
index 1198912dd7a..986d6ef6ae6 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/GeneratedMakefileBuilder.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2002, 2005 IBM Corporation and others.
+ * Copyright (c) 2002,2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -32,6 +32,7 @@ import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -608,17 +609,13 @@ public class GeneratedMakefileBuilder extends ACBuilder {
CommandLauncher launcher = new CommandLauncher();
launcher.showCommand(true);
- // Set the environmennt, some scripts may need the CWD var to be set.
- Properties props = launcher.getEnvironment();
- props.put("CWD", workingDirectory.toOSString()); //$NON-NLS-1$
- props.put("PWD", workingDirectory.toOSString()); //$NON-NLS-1$
+ // Set the environmennt
+ IBuildEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider().getVariables(cfg,true);
String[] env = null;
ArrayList envList = new ArrayList();
- Enumeration names = props.propertyNames();
- if (names != null) {
- while (names.hasMoreElements()) {
- String key = (String) names.nextElement();
- envList.add(key + "=" + props.getProperty(key)); //$NON-NLS-1$
+ if (variables != null) {
+ for(int i = 0; i < variables.length; i++){
+ envList.add(variables[i].getName() + "=" + variables[i].getValue()); //$NON-NLS-1$
}
env = (String[]) envList.toArray(new String[envList.size()]);
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
index 3146ee3a142..ff2ad71f0ef 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ManagedBuildInfo.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2002, 2005 IBM Software Corporation and others.
+ * Copyright (c) 2002,2005 IBM Software Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v0.5
* which accompanies this distribution, and is available at
@@ -30,16 +30,18 @@ import org.eclipse.cdt.core.model.IPathEntry;
import org.eclipse.cdt.core.model.IPathEntryContainer;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.managedbuilder.core.BuildException;
+import org.eclipse.cdt.managedbuilder.core.IBuilder;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineGenerator;
import org.eclipse.cdt.managedbuilder.core.IManagedCommandLineInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedProject;
+import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.ITarget;
-import org.eclipse.cdt.managedbuilder.core.IConfiguration;
-import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ITool;
-import org.eclipse.cdt.managedbuilder.core.IOption;
-import org.eclipse.cdt.managedbuilder.core.IBuilder;
+import org.eclipse.cdt.managedbuilder.core.IToolChain;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.internal.scannerconfig.ManagedBuildCPathEntryContainer;
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyGenerator;
@@ -440,6 +442,11 @@ public class ManagedBuildInfo implements IManagedBuildInfo, IScannerInfo {
}
}
+ //add paths specified in the environment
+ String envIncludePaths[] = ManagedBuildManager.getEnvironmentVariableProvider().getBuildPaths(config,IEnvVarBuildPath.BUILDPATH_INCLUDE);
+ if(envIncludePaths != null)
+ paths.addAll(Arrays.asList(envIncludePaths));
+
// Answer the results as an array
return (String[])paths.toArray(new String[paths.size()]);
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties
index 08ade51f11f..762c99fe167 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/PluginResources.properties
@@ -79,4 +79,6 @@ ManagedBuildInfo.message.init.ok = Initializing path container succeeded for {0}
GnuMakefileGenerator.message.postproc.dep.file=Verifying contents of dependency file {0}
# Tool strings
-Tool.default.announcement=Invoking: \ No newline at end of file
+Tool.default.announcement=Invoking:
+#Environment loader messages
+StorableEnvironmentLoader.storeOutputStream.wrong.arguments="Wrong arguments"
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java
index 0fcbbe7b836..524682c2de2 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ProjectType.java
@@ -20,6 +20,9 @@ import org.eclipse.cdt.managedbuilder.core.IProjectType;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.envvar.IProjectEnvironmentVariableSupplier;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
public class ProjectType extends BuildObject implements IProjectType {
@@ -36,6 +39,9 @@ public class ProjectType extends BuildObject implements IProjectType {
private Boolean isAbstract;
private Boolean isTest;
private String unusedChildren;
+ private IConfigurationElement environmentVariableSupplierElement = null;
+ private IProjectEnvironmentVariableSupplier environmentVariableSupplier = null;
+
// Miscellaneous
private boolean resolved = true;
@@ -122,6 +128,13 @@ public class ProjectType extends BuildObject implements IProjectType {
if (isTestStr != null){
isTest = new Boolean("true".equals(isTestStr)); //$NON-NLS-1$
}
+
+ // Get the environmentVariableSupplier configuration element
+ String environmentVariableSupplier = element.getAttribute(PROJECT_ENVIRONMENT_SUPPLIER);
+ if(environmentVariableSupplier != null && element instanceof DefaultManagedConfigElement){
+ environmentVariableSupplierElement = ((DefaultManagedConfigElement)element).getConfigurationElement();
+ }
+
}
/*
@@ -350,4 +363,38 @@ public class ProjectType extends BuildObject implements IProjectType {
}
return false;
}
+
+ /**
+ * Returns the plugin.xml element of the projectEnvironmentSupplier extension or <code>null</code> if none.
+ *
+ * @return IConfigurationElement
+ */
+ public IConfigurationElement getEnvironmentVariableSupplierElement(){
+ if (environmentVariableSupplierElement == null) {
+ if (superClass != null && superClass instanceof ProjectType) {
+ return ((ProjectType)superClass).getEnvironmentVariableSupplierElement();
+ }
+ }
+ return environmentVariableSupplierElement;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.IProjectType#getEnvironmentVariableSupplier()
+ */
+ public IProjectEnvironmentVariableSupplier getEnvironmentVariableSupplier(){
+ if (environmentVariableSupplier != null) {
+ return environmentVariableSupplier;
+ }
+ IConfigurationElement element = getEnvironmentVariableSupplierElement();
+ if (element != null) {
+ try {
+ if (element.getAttribute(PROJECT_ENVIRONMENT_SUPPLIER) != null) {
+ environmentVariableSupplier = (IProjectEnvironmentVariableSupplier) element.createExecutableExtension(PROJECT_ENVIRONMENT_SUPPLIER);
+ return environmentVariableSupplier;
+ }
+ } catch (CoreException e) {}
+ }
+ return null;
+ }
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
index 0ec1a4ea069..b7927952533 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Tool.java
@@ -21,6 +21,7 @@ import java.util.Vector;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
@@ -73,6 +74,7 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
private Map inputTypeMap;
private Vector outputTypeList;
private Map outputTypeMap;
+ private List envVarBuildPathList;
// Managed Build model attributes
private String unusedChildren;
private Boolean isAbstract;
@@ -136,6 +138,8 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
} else if (toolElement.getName().equals(ITool.OUTPUT_TYPE)) {
OutputType outputType = new OutputType(this, toolElement);
addOutputType(outputType);
+ } else if (toolElement.getName().equals(IEnvVarBuildPath.BUILD_PATH_ELEMENT_NAME)){
+ addEnvVarBuildPath(new EnvVarBuildPath(this,toolElement));
}
}
}
@@ -310,6 +314,9 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
dependencyGeneratorElement = tool.dependencyGeneratorElement;
dependencyGenerator = tool.dependencyGenerator;
+ if(tool.envVarBuildPathList != null)
+ envVarBuildPathList = new ArrayList(tool.envVarBuildPathList);
+
// Clone the children
// Note: This constructor ignores OptionCategories since they should not be
// found on an non-extension tool - TODO: This may need to change!
@@ -2316,4 +2323,27 @@ public class Tool extends BuildObject implements ITool, IOptionCategory {
}
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.ITool#getEnvVarBuildPaths()
+ */
+ public IEnvVarBuildPath[] getEnvVarBuildPaths(){
+ if(envVarBuildPathList != null){
+ return (IEnvVarBuildPath[])envVarBuildPathList.toArray(
+ new IEnvVarBuildPath[envVarBuildPathList.size()]);
+ }
+ else if(superClass != null)
+ return superClass.getEnvVarBuildPaths();
+ return null;
+ }
+
+ private void addEnvVarBuildPath(IEnvVarBuildPath path){
+ if(path == null)
+ return;
+ if(envVarBuildPathList == null)
+ envVarBuildPathList = new ArrayList();
+
+ envVarBuildPathList.add(path);
+ }
+
+
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java
index cbed05ea471..376f8dd2b8c 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolChain.java
@@ -28,6 +28,7 @@ import org.eclipse.cdt.managedbuilder.core.ITargetPlatform;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.w3c.dom.Document;
@@ -59,6 +60,9 @@ public class ToolChain extends BuildObject implements IToolChain {
private String scannerConfigDiscoveryProfileId;
private IConfigurationElement managedIsToolChainSupportedElement = null;
private IManagedIsToolChainSupported managedIsToolChainSupported = null;
+ private IConfigurationElement environmentVariableSupplierElement = null;
+ private IConfigurationEnvironmentVariableSupplier environmentVariableSupplier = null;
+
// Miscellaneous
private boolean isExtensionToolChain = false;
private boolean isDirty = false;
@@ -225,6 +229,9 @@ public class ToolChain extends BuildObject implements IToolChain {
managedIsToolChainSupportedElement = toolChain.managedIsToolChainSupportedElement;
managedIsToolChainSupported = toolChain.managedIsToolChainSupported;
+ environmentVariableSupplierElement = toolChain.environmentVariableSupplierElement;
+ environmentVariableSupplier = toolChain.environmentVariableSupplier;
+
// Clone the children
if (toolChain.builder != null) {
int nnn = ManagedBuildManager.getRandomNumber();
@@ -342,6 +349,12 @@ public class ToolChain extends BuildObject implements IToolChain {
if (managedIsToolChainSupported != null && element instanceof DefaultManagedConfigElement) {
managedIsToolChainSupportedElement = ((DefaultManagedConfigElement)element).getConfigurationElement();
}
+
+ // Get the environmentVariableSupplier configuration element
+ String environmentVariableSupplier = element.getAttribute(CONFIGURATION_ENVIRONMENT_SUPPLIER);
+ if(environmentVariableSupplier != null && element instanceof DefaultManagedConfigElement){
+ environmentVariableSupplierElement = ((DefaultManagedConfigElement)element).getConfigurationElement();
+ }
}
/* (non-Javadoc)
@@ -519,6 +532,12 @@ public class ToolChain extends BuildObject implements IToolChain {
// TODO: issue warning?
}
+ // Note: environmentVariableSupplier cannot be specified in a project file because
+ // an IConfigurationElement is needed to load it!
+ if(environmentVariableSupplierElement != null) {
+ // TODO: issue warning?
+ }
+
// I am clean now
isDirty = false;
}
@@ -1124,4 +1143,38 @@ public class ToolChain extends BuildObject implements IToolChain {
return true;
}
+ /**
+ * Returns the plugin.xml element of the configurationEnvironmentSupplier extension or <code>null</code> if none.
+ *
+ * @return IConfigurationElement
+ */
+ public IConfigurationElement getEnvironmentVariableSupplierElement(){
+ if (environmentVariableSupplierElement == null) {
+ if (superClass != null && superClass instanceof ToolChain) {
+ return ((ToolChain)superClass).getEnvironmentVariableSupplierElement();
+ }
+ }
+ return environmentVariableSupplierElement;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.core.IToolChain#getEnvironmentVariableSupplier()
+ */
+ public IConfigurationEnvironmentVariableSupplier getEnvironmentVariableSupplier(){
+ if (environmentVariableSupplier != null) {
+ return environmentVariableSupplier;
+ }
+ IConfigurationElement element = getEnvironmentVariableSupplierElement();
+ if (element != null) {
+ try {
+ if (element.getAttribute(CONFIGURATION_ENVIRONMENT_SUPPLIER) != null) {
+ environmentVariableSupplier = (IConfigurationEnvironmentVariableSupplier) element.createExecutableExtension(CONFIGURATION_ENVIRONMENT_SUPPLIER);
+ return environmentVariableSupplier;
+ }
+ } catch (CoreException e) {}
+ }
+ return null;
+ }
+
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java
index c879ac39dac..b91797429bf 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/ToolReference.java
@@ -19,6 +19,7 @@ import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IBuildObject;
import org.eclipse.cdt.managedbuilder.core.IConfigurationV2;
import org.eclipse.cdt.managedbuilder.core.IInputType;
+import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement;
import org.eclipse.cdt.managedbuilder.core.IOption;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
@@ -1092,4 +1093,10 @@ public class ToolReference implements IToolReference {
return command;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.build.managed.ITool#getEnvVarBuildPaths()
+ */
+ public IEnvVarBuildPath[] getEnvVarBuildPaths(){
+ return null;
+ }
}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/BuildEnvVar.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/BuildEnvVar.java
new file mode 100644
index 00000000000..0dbc320f6c5
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/BuildEnvVar.java
@@ -0,0 +1,80 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+
+/**
+ * a trivial implementation of the IBuildEnvironmentVariable
+ *
+ * @since 3.0
+ */
+public class BuildEnvVar implements IBuildEnvironmentVariable {
+ protected String fName;
+ protected String fValue;
+ protected String fDelimiter;
+ protected int fOperation;
+
+ public BuildEnvVar(String name, String value, int op, String delimiter){
+ fName = name;
+ fOperation = op;
+ fValue = value;
+ fDelimiter = delimiter;
+ }
+
+ protected BuildEnvVar(){
+
+ }
+
+ public BuildEnvVar(String name){
+ this(name,null,ENVVAR_REPLACE,null);
+ }
+
+ public BuildEnvVar(String name, String value){
+ this(name,value,ENVVAR_REPLACE,null);
+ }
+
+ public BuildEnvVar(String name, String value, String delimiter){
+ this(name,value,ENVVAR_REPLACE,delimiter);
+ }
+
+ public BuildEnvVar(IBuildEnvironmentVariable var){
+ this(var.getName(),var.getValue(),var.getOperation(),var.getDelimiter());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable#getName()
+ */
+ public String getName(){
+ return fName;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable#getValue()
+ */
+ public String getValue(){
+ return fValue;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable#getOperation()
+ */
+ public int getOperation(){
+ return fOperation;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable#getDelimiter()
+ */
+ public String getDelimiter(){
+ return fDelimiter;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/DefaultContextInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/DefaultContextInfo.java
new file mode 100644
index 00000000000..6ef9d314979
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/DefaultContextInfo.java
@@ -0,0 +1,101 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedProject;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+
+/**
+ * The default implementation of the IContextInfo used by the Environment Variable Provider
+ * Used to represent the Configuration, Project, Workspace and Eclipse environment contexts
+ *
+ * @since 3.0
+ */
+public class DefaultContextInfo implements IContextInfo{
+ private Object fContextObject;
+ private IEnvironmentVariableSupplier fContextSuppliers[];
+
+ /**
+ * This constructor is used to create the default context info given a context object
+ *
+ * @param context
+ */
+ public DefaultContextInfo(Object context){
+ fContextObject = context;
+ }
+
+ protected DefaultContextInfo(Object context, IEnvironmentVariableSupplier suppliers[]){
+ fContextSuppliers = suppliers;
+ fContextObject = context;
+ }
+
+ /*
+ * answers the list of suppliers that should be used for the given context
+ */
+ protected IEnvironmentVariableSupplier[] getSuppliers(Object context){
+ IEnvironmentVariableSupplier suppliers[];
+ if(context == null)
+ suppliers = new IEnvironmentVariableSupplier[]{EnvironmentVariableProvider.fEclipseSupplier};
+ else if(context instanceof IWorkspace)
+ suppliers = new IEnvironmentVariableSupplier[]{EnvironmentVariableProvider.fUserSupplier};
+ else if(context instanceof IManagedProject)
+ suppliers = new IEnvironmentVariableSupplier[]{EnvironmentVariableProvider.fUserSupplier,EnvironmentVariableProvider.fExternalSupplier};
+ else if(context instanceof IConfiguration)
+ suppliers = new IEnvironmentVariableSupplier[]{EnvironmentVariableProvider.fUserSupplier,EnvironmentVariableProvider.fExternalSupplier,EnvironmentVariableProvider.fMbsSupplier};
+ else
+ suppliers = null;
+ return suppliers;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo#getNext()
+ */
+ public IContextInfo getNext(){
+ DefaultContextInfo next = null;
+ if(fContextObject == null)
+ next = null;
+ else if(fContextObject instanceof IWorkspace)
+ next = new DefaultContextInfo(null);
+ else if(fContextObject instanceof IManagedProject)
+ next = new DefaultContextInfo(ResourcesPlugin.getWorkspace());
+ else if(fContextObject instanceof IConfiguration)
+ next = new DefaultContextInfo(((IConfiguration)fContextObject).getManagedProject());
+ else
+ next = null;
+
+ if(next != null && next.getSuppliers() == null)
+ next = null;
+ return next;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo#getSuppliers()
+ */
+ public IEnvironmentVariableSupplier[] getSuppliers(){
+ if(fContextSuppliers == null)
+ fContextSuppliers = getSuppliers(fContextObject);
+ return fContextSuppliers;
+ }
+
+ protected void setSuppliers(IEnvironmentVariableSupplier suppliers[]){
+ fContextSuppliers = suppliers;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo#getContext()
+ */
+ public Object getContext(){
+ return fContextObject;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EclipseEnvironmentSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EclipseEnvironmentSupplier.java
new file mode 100644
index 00000000000..380b41ea6a3
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EclipseEnvironmentSupplier.java
@@ -0,0 +1,62 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
+import org.eclipse.cdt.utils.spawner.EnvironmentReader;
+
+/**
+ * This is the Environment Variable Supplier used to supply variables
+ * defined in eclipse environment
+ *
+ * @since 3.0
+ */
+public class EclipseEnvironmentSupplier implements IEnvironmentVariableSupplier {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariable()
+ */
+ public IBuildEnvironmentVariable getVariable(String name, Object context) {
+ if(context == null){
+ String value = EnvironmentReader.getEnvVar(name);
+ if(value == null)
+ return null;
+ return new BuildEnvVar(name,value,IBuildEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariables()
+ */
+ public IBuildEnvironmentVariable[] getVariables(Object context) {
+ if(context == null){
+ Properties values = EnvironmentReader.getEnvVars();
+ if(values == null)
+ return null;
+
+ IBuildEnvironmentVariable variables[] = new IBuildEnvironmentVariable[values.size()];
+ Enumeration en = values.propertyNames();
+ for( int i = 0; i < variables.length ; i++){
+ String name = (String)en.nextElement();
+ String value = values.getProperty(name);
+ variables[i] = new BuildEnvVar(name,value,IBuildEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+ return variables;
+ }
+ return null;
+ }
+
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvVarCollector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvVarCollector.java
new file mode 100644
index 00000000000..71f27632d6f
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvVarCollector.java
@@ -0,0 +1,114 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+
+/**
+ * This class implements the "merging" functionality of environment variables
+ * Used by the EnvironmentVariableProvider to "merge" the sets of macros returned
+ * by different suppliers into one set returned to the user
+ *
+ * @since 3.0
+ *
+ */
+public class EnvVarCollector {
+ private Map fMap = null;
+ public EnvVarCollector(){
+
+ }
+
+ /**
+ * adds an array of environment variables to the set of variables held by this collector
+ * performing environment variable operations
+ * @param vars
+ */
+ public void add(IBuildEnvironmentVariable vars[]){
+ if(vars == null)
+ return;
+ boolean isCaseInsensitive = !EnvironmentVariableProvider.getDefault().isVariableCaseSensitive();
+ for(int i = 0; i < vars.length; i ++) {
+ IBuildEnvironmentVariable var = vars[i];
+ String name = var.getName();
+ if(isCaseInsensitive)
+ name = name.toUpperCase();
+
+ boolean noCheck = false;
+
+ if(fMap == null){
+ noCheck = true;
+ fMap = new HashMap();
+ }
+
+ if(noCheck)
+ fMap.put(name,var);
+ else {
+ IBuildEnvironmentVariable prevVar = (IBuildEnvironmentVariable)fMap.remove(name);
+ fMap.put(name,EnvVarOperationProcessor.performOperation(prevVar,var));
+ }
+ }
+ }
+
+ /**
+ * Returns an array of variables held by this collector
+ *
+ * @param includeRemoved true if removed variables should be included in the resulting array
+ * @return IBuildEnvironmentVariable[]
+ */
+ public IBuildEnvironmentVariable[] toArray(boolean includeRemoved){
+ if(fMap == null)
+ return new IBuildEnvironmentVariable[0];
+ Collection values = fMap.values();
+ List list = new ArrayList();
+ Iterator iter = values.iterator();
+ while(iter.hasNext()){
+ IBuildEnvironmentVariable var = (IBuildEnvironmentVariable)iter.next();
+ if(var != null &&
+ (includeRemoved || var.getOperation() != IBuildEnvironmentVariable.ENVVAR_REMOVE))
+ list.add(var);
+ }
+ return (IBuildEnvironmentVariable[])list.toArray(new IBuildEnvironmentVariable[list.size()]);
+ }
+
+ /**
+ * Returns a variable of a given name held by this collector
+ *
+ * @param name a variable name
+ * @return IBuildEnvironmentVariable
+ */
+ public IBuildEnvironmentVariable getVariable(String name){
+ if(fMap == null)
+ return null;
+
+ if(!EnvironmentVariableProvider.getDefault().isVariableCaseSensitive())
+ name = name.toUpperCase();
+
+ return (IBuildEnvironmentVariable)fMap.get(name);
+ }
+
+ /**
+ * Returns an array of variables held by this collector
+ * The call to this method is equivalent of calling toArray(true)
+ *
+ * @return IBuildEnvironmentVariable[]
+ */
+ public IBuildEnvironmentVariable[] getVariables(){
+ return toArray(true);
+ }
+
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvVarOperationProcessor.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvVarOperationProcessor.java
new file mode 100644
index 00000000000..c489219f93d
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvVarOperationProcessor.java
@@ -0,0 +1,251 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+
+/**
+ * This is an utility class that implements environment variable operations
+ * functionality: append, prepend, replace and remove
+ *
+ * @since 3.0
+ */
+public class EnvVarOperationProcessor {
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ /**
+ * performs the environment variable operation given an initial variable and
+ * a variable representing an operation to be performed
+ * Returns a new variable the represents the result of a performed operation
+ *
+ * @param initial the initial variable
+ * @param added the variable that specifies an operation to be performed on the
+ * initial variable value
+ * @return the new variable the represents the result of a performed operation
+ */
+ static public IBuildEnvironmentVariable performOperation(IBuildEnvironmentVariable initial, IBuildEnvironmentVariable added){
+ if(initial == null){
+ return added;
+ }
+ if(added == null)
+ return initial;
+
+ String name = added.getName();
+
+ switch(added.getOperation()){
+ case IBuildEnvironmentVariable.ENVVAR_REMOVE:
+ return new BuildEnvVar(name,null,IBuildEnvironmentVariable.ENVVAR_REMOVE,null);
+ case IBuildEnvironmentVariable.ENVVAR_APPEND:{
+ String delimiter = added.getDelimiter();
+ return new BuildEnvVar(name,
+ performAppend(initial.getValue(),added.getValue(),delimiter),
+// IBuildEnvironmentVariable.ENVVAR_APPEND,
+ delimiter);
+ }
+ case IBuildEnvironmentVariable.ENVVAR_PREPEND:{
+ String delimiter = added.getDelimiter();
+ return new BuildEnvVar(name,
+ performPrepend(initial.getValue(),added.getValue(),delimiter),
+// IBuildEnvironmentVariable.ENVVAR_PREPEND,
+ delimiter);
+ }
+ case IBuildEnvironmentVariable.ENVVAR_REPLACE:
+ default:
+ return new BuildEnvVar(added.getName(),added.getValue(),added.getDelimiter());
+ }
+ }
+
+ /**
+ * performs append or prepend given an initial String, a string to be appended/prepended and a delimiter
+ * Returns a String representing the result of the operation
+ * @param initialValue
+ * @param addValue
+ * @param delimiter
+ * @param prepend
+ * @return String
+ */
+ static public String performAppendPrepend(String initialValue, String addValue, String delimiter, boolean prepend){
+ if(initialValue == null)
+ return addValue;
+ if(addValue == null)
+ return initialValue;
+
+ if(delimiter == null || "".equals(delimiter)){ //$NON-NLS-1$
+ return prepend ? addValue + initialValue : initialValue + addValue;
+ }
+
+ List value = convertToList(initialValue, delimiter);
+ List added = convertToList(addValue, delimiter);
+
+ value = removeDuplicates(value, added);
+
+ if(prepend)
+ value.addAll(0,added);
+ else
+ value.addAll(added);
+
+ return convertToString(value, delimiter);
+ }
+
+ /**
+ * performs append given an initial String, a string to be appended and a delimiter
+ * Returns a String representing the result of the operation
+ * @param initialValue
+ * @param addValue
+ * @param delimiter
+ * @return String
+ */
+ static public String performAppend(String initialValue, String addValue, String delimiter){
+ return performAppendPrepend(initialValue,addValue,delimiter,false);
+ }
+
+ /**
+ * performs prepend given an initial String, a string to be prepended and a delimiter
+ * Returns a String representing the result of the operation
+ * @param initialValue
+ * @param addValue
+ * @param delimiter
+ * @return String
+ */
+ static public String performPrepend(String initialValue, String addValue, String delimiter){
+ return performAppendPrepend(initialValue,addValue,delimiter,true);
+ }
+
+ /**
+ * performs an environment variable operation
+ * Returns String representing the result of the operation
+ * @param initialValue
+ * @param newValue
+ * @param delimiter
+ * @param op
+ * @return String
+ */
+ static public String performOperation(String initialValue, String newValue, String delimiter, int op){
+ switch(op){
+ case IBuildEnvironmentVariable.ENVVAR_REMOVE:
+ return null;
+ case IBuildEnvironmentVariable.ENVVAR_PREPEND:
+ return performPrepend(initialValue,newValue,delimiter);
+ case IBuildEnvironmentVariable.ENVVAR_APPEND:
+ return performAppend(initialValue,newValue,delimiter);
+ case IBuildEnvironmentVariable.ENVVAR_REPLACE:
+ default:
+ return initialValue;
+ }
+ }
+
+ /**
+ * Converts a given value to string using a delimiter passed to this method
+ * @param value
+ * @param delimiter
+ * @return
+ */
+ static public List convertToList(String value, String delimiter){
+ List list = new ArrayList();
+ int delLength = delimiter.length();
+ int valLength = value.length();
+
+ if(delLength == 0){
+ list.add(value);
+ }
+ else{
+ int start = 0;
+ int stop;
+ while(start < valLength){
+ stop = value.indexOf(delimiter,start);
+ if(stop == -1)
+ stop = valLength;
+ String subst = value.substring(start,stop);
+ list.add(subst);
+ start = stop + delLength;
+ }
+ }
+
+ return list;
+ }
+
+ /*
+ * removes duplicates
+ */
+ static public List removeDuplicates(List value, List duplicates){
+ List list = new ArrayList();
+ Iterator valueIter = value.iterator();
+ while(valueIter.hasNext()){
+ String curVal = (String)valueIter.next();
+ boolean duplFound = false;
+ Iterator duplicatesIter = duplicates.iterator();
+ while(duplicatesIter.hasNext()){
+ String curDupl = (String)duplicatesIter.next();
+ if(curVal.equals(curDupl)){
+ duplFound = true;
+ break;
+ }
+ }
+ if(!duplFound)
+ list.add(curVal);
+ }
+ return list;
+ }
+
+ /**
+ * Converts list to a single String using a given delimiter to separate
+ * the list value in the resulting String
+ * @param list
+ * @param delimiter
+ * @return String
+ */
+ static public String convertToString(List list, String delimiter){
+ Iterator iter = list.iterator();
+ StringBuffer buffer = new StringBuffer();
+
+ while(iter.hasNext()){
+ buffer.append((String)iter.next());
+
+ if(iter.hasNext())
+ buffer.append(delimiter);
+ }
+
+ return buffer.toString();
+ }
+
+ /*
+ * concatenetes two Strings
+ * Returns a resulting string
+ */
+ static private String concatenateStrings(String str1, String str2, String delimiter){
+ if(str1 == null || "".equals(str1)) //$NON-NLS-1$
+ return str2;
+ if(str2 == null || "".equals(str2)) //$NON-NLS-1$
+ return str1;
+
+ return str1 + delimiter + str2;
+ }
+
+ /*
+ * normalizes the variable name. That is: removes prepended and appended spaces
+ * and converts the name to upper-case for Win32 systems
+ * @return the normalized name or <code>null</code> in case the name is not valid
+ */
+ static public String normalizeName(String name){
+ if(name == null)
+ return null;
+ if("".equals(name = name.trim())) //$NON-NLS-1$
+ return null;
+ if(!ManagedBuildManager.getEnvironmentVariableProvider().isVariableCaseSensitive())
+ name = name.toUpperCase();
+ return name;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvironmentVariableProvider.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvironmentVariableProvider.java
new file mode 100644
index 00000000000..e5c251bfc06
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/EnvironmentVariableProvider.java
@@ -0,0 +1,513 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
+import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentBuildPathsChangeListener;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
+import org.eclipse.core.runtime.QualifiedName;
+
+/**
+ * This class implements the IEnvironmentVariableProvider interface and provides all
+ * build environment funvtionality to the MBS
+ *
+ * @since 3.0
+ *
+ */
+public class EnvironmentVariableProvider implements
+ IEnvironmentVariableProvider {
+ private static final QualifiedName fBuildPathVarProperty = new QualifiedName(ManagedBuilderCorePlugin.getUniqueIdentifier(), "buildPathVar"); //$NON-NLS-1$
+
+ private static final String DELIMITER_WIN32 = ";"; //$NON-NLS-1$
+ private static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
+
+ private static EnvironmentVariableProvider fInstance = null;
+ private List fListeners = null;
+
+ private StoredBuildPathEnvironmentContainer fIncludeStoredBuildPathVariables;
+ private StoredBuildPathEnvironmentContainer fLibraryStoredBuildPathVariables;
+
+ public static final UserDefinedEnvironmentSupplier fUserSupplier = new UserDefinedEnvironmentSupplier();
+ public static final ExternalExtensionEnvironmentSupplier fExternalSupplier = new ExternalExtensionEnvironmentSupplier();
+ public static final MbsEnvironmentSupplier fMbsSupplier = new MbsEnvironmentSupplier();
+ public static final EclipseEnvironmentSupplier fEclipseSupplier = new EclipseEnvironmentSupplier();
+
+ /**
+ * This class is used by the EnvironmentVariableProvider to calculate the build paths
+ * in case a tool-integrator did not provide the special logic for obtaining the build
+ * paths from environment variable values
+ *
+ * @since 3.0
+ *
+ */
+ static public class DefaultBuildPathResolver implements IBuildPathResolver {
+ private String fDelimiter;
+
+ public DefaultBuildPathResolver(String delimiter){
+ fDelimiter = delimiter;
+ }
+
+ public String[] resolveBuildPaths(int pathType, String variableName,
+ String variableValue, IConfiguration configuration) {
+
+ if(fDelimiter == null || "".equals(fDelimiter)) //$NON-NLS-1$
+ return new String[]{variableValue};
+
+ List list = EnvVarOperationProcessor.convertToList(variableValue,fDelimiter);
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+
+ }
+
+ EnvironmentVariableProvider(){
+
+ }
+
+ public static EnvironmentVariableProvider getDefault(){
+ if(fInstance == null)
+ fInstance = new EnvironmentVariableProvider();
+ return fInstance;
+ }
+
+ /*
+ * returns a variable of a given name or null
+ * the context information is taken from the contextInfo passed
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo
+ */
+ public IBuildEnvironmentVariable getVariable(String variableName,
+ IContextInfo contextInfo, boolean includeParentLevels){
+
+ if(contextInfo == null)
+ return null;
+ if(variableName == null || "".equals(variableName = variableName.trim())) //$NON-NLS-1$
+ return null;
+
+
+ IContextInfo infos[] = getAllContextInfos(contextInfo);
+ variableName = adjustName(variableName);
+
+ if(!includeParentLevels){
+ IEnvironmentVariableSupplier suppliers[] = infos[0].getSuppliers();
+ boolean bVarFound = false;
+ for(int i = 0; i < suppliers.length; i++){
+ if(suppliers[i].getVariable(variableName,infos[0].getContext()) != null){
+ bVarFound = true;
+ break;
+ }
+ }
+ if(!bVarFound)
+ return null;
+ }
+
+ IBuildEnvironmentVariable variable = null;
+
+ for(int i = infos.length-1 ; i >=0 ; i-- ) {
+ IContextInfo info = infos[i];
+ IEnvironmentVariableSupplier suppliers[] = info.getSuppliers();
+
+ for(int j = suppliers.length-1 ; j >= 0 ; j-- ) {
+ IEnvironmentVariableSupplier supplier = suppliers[j];
+ IBuildEnvironmentVariable var = supplier.getVariable(variableName,info.getContext());
+
+ if(var == null)
+ continue;
+
+ if(variable == null)
+ variable = var;
+ else
+ variable = EnvVarOperationProcessor.performOperation(variable,var);
+ }
+ }
+
+ if(variable != null && variable.getOperation() == IBuildEnvironmentVariable.ENVVAR_REMOVE)
+ variable = null;
+ return variable;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getVariable()
+ */
+ public IBuildEnvironmentVariable getVariable(String variableName,
+ Object level, boolean includeParentLevels) {
+
+ if(variableName == null || "".equals(variableName)) //$NON-NLS-1$
+ return null;
+
+ IBuildEnvironmentVariable var = getVariable(variableName,getContextInfo(level),includeParentLevels);
+ if(level instanceof IConfiguration)
+ checkBuildPathVariable((IConfiguration)level,variableName,var);
+ return var;
+ }
+
+ public String adjustName(String name){
+ if(!isVariableCaseSensitive())
+ name = name.toUpperCase();
+ return name;
+ }
+
+ /*
+ * returns the context info that should be used for the given level
+ * or null if the the given level is not supported
+ */
+ protected IContextInfo getContextInfo(Object level){
+ DefaultContextInfo info = new DefaultContextInfo(level);
+ if(info.getSuppliers() == null)
+ return null;
+ return info;
+ }
+
+ /*
+ * returns a list of defined variables.
+ * the context information is taken from the contextInfo passed
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.IContextInfo
+ */
+ public EnvVarCollector getVariables(IContextInfo contextInfo,
+ boolean includeParentLevels) {
+ if(contextInfo == null)
+ return null;
+
+ IContextInfo infos[] = getAllContextInfos(contextInfo);
+ HashSet set = null;
+
+ if(!includeParentLevels){
+ IEnvironmentVariableSupplier suppliers[] = infos[0].getSuppliers();
+ set = new HashSet();
+ for(int i = 0; i < suppliers.length; i++){
+ IBuildEnvironmentVariable vars[] = suppliers[i].getVariables(infos[0].getContext());
+ if(vars != null){
+ for(int j = 0; j < vars.length; j++){
+ set.add(
+ adjustName(vars[j].
+ getName())
+ );
+ }
+ }
+ }
+ if(set.size() == 0)
+ return new EnvVarCollector();
+ }
+
+ EnvVarCollector envVarSet = new EnvVarCollector();
+
+ for(int i = infos.length-1 ; i >=0 ; i-- ) {
+ IContextInfo info = infos[i];
+ IEnvironmentVariableSupplier suppliers[] = info.getSuppliers();
+
+ for(int j = suppliers.length-1 ; j >= 0 ; j-- ) {
+ IEnvironmentVariableSupplier supplier = suppliers[j];
+ IBuildEnvironmentVariable vars[] = null;
+ if(set != null){
+ List varList = new ArrayList();
+ Iterator iter = set.iterator();
+
+ while(iter.hasNext()){
+ IBuildEnvironmentVariable var = supplier.getVariable((String)iter.next(),info.getContext());
+ if(var != null)
+ varList.add(var);
+ }
+ vars = (IBuildEnvironmentVariable[])varList.toArray(new IBuildEnvironmentVariable[varList.size()]);
+ }
+ else{
+ vars = supplier.getVariables(info.getContext());
+ }
+ envVarSet.add(vars);
+ }
+ }
+
+ return envVarSet;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getVariables()
+ */
+ public IBuildEnvironmentVariable[] getVariables(Object level,
+ boolean includeParentLevels) {
+
+ EnvVarCollector varSet = getVariables(getContextInfo(level),includeParentLevels);
+
+ if(level instanceof IConfiguration)
+ checkBuildPathVariables((IConfiguration)level,varSet);
+
+ if(varSet != null)
+ return varSet.toArray(false);
+ return null;
+ }
+
+ /*
+ * returns an array of the IContextInfo that holds the context informations
+ * starting from the one passed to this method and including all subsequent parents
+ */
+ private IContextInfo[] getAllContextInfos(IContextInfo contextInfo){
+ if(contextInfo == null)
+ return null;
+
+ List list = new ArrayList();
+
+ list.add(contextInfo);
+
+ while((contextInfo = contextInfo.getNext()) != null)
+ list.add(contextInfo);
+
+ return (IContextInfo[])list.toArray(new IContextInfo[list.size()]);
+ }
+
+ private boolean isWin32(){
+ String os = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
+ if (os.startsWith("windows ")) //$NON-NLS-1$
+ return true;
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getDefaultDelimiter()
+ */
+ public String getDefaultDelimiter() {
+ return isWin32() ? DELIMITER_WIN32 : DELIMITER_UNIX;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#isVariableCaseSensitive()
+ */
+ public boolean isVariableCaseSensitive() {
+ return !isWin32();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getSuppliers()
+ */
+ public IEnvironmentVariableSupplier[] getSuppliers(Object level) {
+ IContextInfo info = getContextInfo(level);
+ if(info != null)
+ return info.getSuppliers();
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getBuildPaths()
+ */
+ public String[] getBuildPaths(IConfiguration configuration,
+ int buildPathType) {
+ ITool tools[] = configuration.getFilteredTools();
+ List list = new ArrayList();
+
+ for(int i = 0; i < tools.length; i++){
+ IEnvVarBuildPath pathDescriptors[] = tools[i].getEnvVarBuildPaths();
+
+ if(pathDescriptors == null || pathDescriptors.length == 0)
+ continue;
+
+ for(int j = 0; j < pathDescriptors.length; j++){
+ IEnvVarBuildPath curPathDes = pathDescriptors[j];
+ if(curPathDes.getType() != buildPathType)
+ continue;
+
+ String vars[] = curPathDes.getVariableNames();
+ if(vars == null || vars.length == 0)
+ continue;
+
+ IBuildPathResolver pathResolver = curPathDes.getBuildPathResolver();
+ if(pathResolver == null){
+ String delimiter = curPathDes.getPathDelimiter();
+ if(delimiter == null)
+ delimiter = getDefaultDelimiter();
+ pathResolver = new DefaultBuildPathResolver(delimiter);
+ }
+
+ for(int k = 0; k < vars.length; k++){
+ String varName = vars[k];
+
+ IBuildEnvironmentVariable var = getVariable(varName,configuration,true);
+ if(var == null)
+ continue;
+
+ String varValue = var.getValue();
+ String paths[] = pathResolver.resolveBuildPaths(buildPathType,varName,varValue,configuration);
+ if(paths != null && paths.length != 0)
+ list.addAll(Arrays.asList(paths));
+ }
+ }
+ }
+
+ return (String[])list.toArray(new String[list.size()]);
+ }
+
+ /*
+ * returns a list of registered listeners
+ */
+ private List getListeners(){
+ if(fListeners == null)
+ fListeners = new ArrayList();
+ return fListeners;
+ }
+
+ /*
+ * notifies registered listeners
+ */
+ private void notifyListeners(IConfiguration configuration, int buildPathType){
+ List listeners = getListeners();
+ Iterator iterator = listeners.iterator();
+ while(iterator.hasNext())
+ ((IEnvironmentBuildPathsChangeListener)iterator.next()).buildPathsChanged(configuration,buildPathType);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#subscribe()
+ */
+ public synchronized void subscribe(IEnvironmentBuildPathsChangeListener listener) {
+ if(listener == null)
+ return;
+
+ List listeners = getListeners();
+
+ if(!listeners.contains(listener))
+ listeners.add(listener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#unsubscribe()
+ */
+ public synchronized void unsubscribe(IEnvironmentBuildPathsChangeListener listener) {
+ if(listener == null)
+ return;
+
+ List listeners = getListeners();
+
+ listeners.remove(listener);
+ }
+
+ /*
+ * returns true if the first passed contextInfo is the child of the second one
+ */
+ public boolean checkParentContextRelation(IContextInfo child, IContextInfo parent){
+ if(child == null || parent == null)
+ return false;
+
+ IContextInfo enumInfo = child;
+ do{
+ if(parent.getContext() == enumInfo.getContext())
+ return true;
+ }while((enumInfo = enumInfo.getNext()) != null);
+ return false;
+ }
+
+ /*
+ * performs a check of the build path variables for the given configuration
+ * If the build variables are changed, the notification is sent
+ */
+ public void checkBuildPathVariables(IConfiguration configuration){
+ checkBuildPathVariables(configuration,getVariables(getContextInfo(configuration),true));
+ }
+
+ /*
+ * performs a check of the build path variables of the specified type
+ * for the given configuration
+ * If the build variables are changed, the notification is sent
+ */
+ public void checkBuildPathVariables(IConfiguration configuration,int buildPathType){
+ checkBuildPathVariables(configuration,buildPathType,getVariables(getContextInfo(configuration),true));
+ }
+
+ /*
+ * performs a check of the build path variables
+ * for the given configuration given the set of the variables
+ * defined for this configuration
+ * If the build variables are changed, the notification is sent
+ */
+ protected void checkBuildPathVariables(IConfiguration configuration, EnvVarCollector varSet){
+ checkBuildPathVariables(configuration,IEnvVarBuildPath.BUILDPATH_INCLUDE,varSet);
+ checkBuildPathVariables(configuration,IEnvVarBuildPath.BUILDPATH_LIBRARY,varSet);
+ }
+
+ /*
+ * performs a check of whether the given variable is the build path variable
+ * and if true checks whether it is changed.
+ * In the case of it is changed all other build path variables are checked
+ * and notification is sent.
+ * If it is not changed, other build path variables are not checked
+ * In the case of the given variable is not the build path one, this method does nothing
+ */
+ protected void checkBuildPathVariable(IConfiguration configuration, String varName, IBuildEnvironmentVariable var){
+ checkBuildPathVariable(configuration, IEnvVarBuildPath.BUILDPATH_INCLUDE, varName, var);
+ checkBuildPathVariable(configuration, IEnvVarBuildPath.BUILDPATH_LIBRARY, varName, var);
+ }
+
+ /*
+ * performs a check of whether the given variable is the build path variable
+ * of the specified type and if true checks whether it is changed.
+ * In the case of it is changed all other build path variables of that type are checked
+ * and notification is sent.
+ * If it is not changed, other build path variables are not checked
+ * In the case of the given variable is not the build path one, this method does nothing
+ */
+ protected void checkBuildPathVariable(IConfiguration configuration, int buildPathType, String varName, IBuildEnvironmentVariable var){
+ StoredBuildPathEnvironmentContainer buildPathVars = getStoredBuildPathVariables(buildPathType);
+ if(buildPathVars == null)
+ return;
+ if(buildPathVars.isVariableChanged(varName,var,configuration)){
+ buildPathVars.synchronize(getVariables(getContextInfo(configuration),true),configuration);
+ notifyListeners(configuration, buildPathType);
+ }
+ }
+
+ /*
+ * performs a check of the build path variables of the specified type
+ * for the given configuration given the set of the variables
+ * defined for this configuration.
+ * If the build variables are changed, the notification is sent
+ */
+ protected void checkBuildPathVariables(IConfiguration configuration, int buildPathType, EnvVarCollector varSet){
+ StoredBuildPathEnvironmentContainer buildPathVars = getStoredBuildPathVariables(buildPathType);
+ if(buildPathVars == null)
+ return;
+ if(buildPathVars.checkBuildPathChange(varSet,configuration)){
+ notifyListeners(configuration, buildPathType);
+ }
+ }
+
+ /*
+ * returns the container of the build variables of the specified type
+ */
+ protected StoredBuildPathEnvironmentContainer getStoredBuildPathVariables(int buildPathType){
+ return buildPathType == IEnvVarBuildPath.BUILDPATH_LIBRARY ?
+ getStoredLibraryBuildPathVariables() :
+ getStoredIncludeBuildPathVariables();
+ }
+
+ /*
+ * returns the container of the Include path variables
+ */
+ protected StoredBuildPathEnvironmentContainer getStoredIncludeBuildPathVariables(){
+ if(fIncludeStoredBuildPathVariables == null)
+ fIncludeStoredBuildPathVariables = new StoredBuildPathEnvironmentContainer(IEnvVarBuildPath.BUILDPATH_INCLUDE);
+ return fIncludeStoredBuildPathVariables;
+ }
+
+ /*
+ * returns the container of the Library path variables
+ */
+ protected StoredBuildPathEnvironmentContainer getStoredLibraryBuildPathVariables(){
+ if(fLibraryStoredBuildPathVariables == null)
+ fLibraryStoredBuildPathVariables = new StoredBuildPathEnvironmentContainer(IEnvVarBuildPath.BUILDPATH_LIBRARY);
+ return fLibraryStoredBuildPathVariables;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/ExternalExtensionEnvironmentSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/ExternalExtensionEnvironmentSupplier.java
new file mode 100644
index 00000000000..a15b626f273
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/ExternalExtensionEnvironmentSupplier.java
@@ -0,0 +1,230 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedProject;
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
+import org.eclipse.cdt.managedbuilder.envvar.IProjectEnvironmentVariableSupplier;
+
+/**
+ * This is the Environment Variable Supplier used to supply variables
+ * defined by the tool-integrator
+ *
+ * @since 3.0
+ */
+public class ExternalExtensionEnvironmentSupplier implements
+ IEnvironmentVariableSupplier {
+ private static final String fNonOverloadableVariables[] = new String[]{
+ //tool-integrators not allowed currently to override the "CWD" and "PWD" variables
+ EnvVarOperationProcessor.normalizeName("CWD"), //$NON-NLS-1$
+ EnvVarOperationProcessor.normalizeName("PWD") //$NON-NLS-1$
+ };
+
+ /**
+ * EnvironmentVariableProvider passed to the tool-integrator provided
+ * suppliers.
+ * Accepts only contexts lower than the one passed to a suppler
+ *
+ * @since 3.0
+ */
+ private class ExtensionEnvVarProvider extends EnvironmentVariableProvider{
+ private IContextInfo fStartInfo;
+ private Object fStartLevel;
+ private boolean fStartInitialized;
+
+ public ExtensionEnvVarProvider(Object level){
+ fStartLevel = level;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider#getVariable(java.lang.String, java.lang.Object, boolean)
+ */
+ public IBuildEnvironmentVariable getVariable(String variableName,
+ Object level, boolean includeParentLevels) {
+ if(getValidName(variableName) == null)
+ return null;
+ return super.getVariable(variableName,level,includeParentLevels);
+ }
+
+ public IBuildEnvironmentVariable[] getVariables(Object level, boolean includeParentLevels) {
+ return filterVariables(super.getVariables(level,includeParentLevels));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider#getContextInfo(java.lang.Object)
+ */
+ protected IContextInfo getContextInfo(Object level){
+ IContextInfo startInfo = getStartInfo();
+ if(level == fStartLevel)
+ return startInfo;
+
+ IContextInfo info = super.getContextInfo(level);
+ if(info == null)
+ return null;
+
+ if(checkParentContextRelation(startInfo,info))
+ return info;
+ return null;
+ }
+
+ protected IContextInfo getStartInfo(){
+ if(fStartInfo == null && !fStartInitialized){
+ IContextInfo info = super.getContextInfo(fStartLevel);
+ if(info != null){
+ IEnvironmentVariableSupplier suppliers[] = info.getSuppliers();
+ suppliers = filterValidSuppliers(suppliers);
+ if(suppliers != null)
+ fStartInfo = new DefaultContextInfo(fStartLevel,suppliers);
+ else
+ fStartInfo = info.getNext();
+ fStartInitialized = true;
+ }
+ fStartInitialized = true;
+ }
+ return fStartInfo;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider#getStoredBuildPathVariables(int)
+ */
+ protected StoredBuildPathEnvironmentContainer getStoredBuildPathVariables(int buildPathType){
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider#getStoredIncludeBuildPathVariables()
+ */
+ protected StoredBuildPathEnvironmentContainer getStoredIncludeBuildPathVariables(){
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableProvider#getStoredLibraryBuildPathVariables()
+ */
+ protected StoredBuildPathEnvironmentContainer getStoredLibraryBuildPathVariables(){
+ return null;
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariable()
+ */
+ public IBuildEnvironmentVariable getVariable(String name, Object context) {
+ if(context == null)
+ return null;
+ if((name = getValidName(name)) == null)
+ return null;
+
+ else if(context instanceof IConfiguration){
+ IConfiguration cfg = (IConfiguration)context;
+ IConfigurationEnvironmentVariableSupplier supplier = cfg.getEnvironmentVariableSupplier();
+ if(supplier == null)
+ return null;
+ return supplier.getVariable(name,cfg,new ExtensionEnvVarProvider(context));
+ }
+ else if (context instanceof IManagedProject) {
+ IManagedProject project = (IManagedProject)context;
+ IProjectEnvironmentVariableSupplier supplier = project.getProjectType().getEnvironmentVariableSupplier();
+ if(supplier == null)
+ return null;
+ return supplier.getVariable(name,project,new ExtensionEnvVarProvider(context));
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariables()
+ */
+ public IBuildEnvironmentVariable[] getVariables(Object context) {
+ if(context == null)
+ return null;
+ IBuildEnvironmentVariable variables[] = null;
+ if(context instanceof IConfiguration){
+ IConfiguration cfg = (IConfiguration)context;
+ IConfigurationEnvironmentVariableSupplier supplier = cfg.getEnvironmentVariableSupplier();
+ if(supplier == null)
+ return null;
+ variables = supplier.getVariables(cfg,new ExtensionEnvVarProvider(context));
+ }
+ else if (context instanceof IManagedProject) {
+ IManagedProject project = (IManagedProject)context;
+ IProjectEnvironmentVariableSupplier supplier = project.getProjectType().getEnvironmentVariableSupplier();
+ if(supplier == null)
+ return null;
+ variables = supplier.getVariables(project,new ExtensionEnvVarProvider(context));
+ }
+
+ return filterVariables(variables);
+ }
+
+ protected IEnvironmentVariableSupplier[] filterValidSuppliers(IEnvironmentVariableSupplier suppliers[]){
+ if(suppliers == null)
+ return null;
+
+ int i = 0, j = 0;
+ for(i = 0; i < suppliers.length; i++){
+ if(suppliers[i] == this)
+ break;
+ }
+
+
+ if(i >= suppliers.length)
+ return null;
+
+ int startNum = i + 1;
+
+
+ IEnvironmentVariableSupplier validSuppliers[] =
+ new IEnvironmentVariableSupplier[suppliers.length - startNum];
+
+ for(i = startNum, j = 0; i < suppliers.length; i++, j++)
+ validSuppliers[j] = suppliers[i];
+
+ return validSuppliers;
+ }
+
+ protected String getValidName(String name){
+ name = EnvVarOperationProcessor.normalizeName(name);
+ if(name == null)
+ return null;
+ if(fNonOverloadableVariables != null){
+ for(int i = 0; i < fNonOverloadableVariables.length; i++){
+ if(name.equals(fNonOverloadableVariables[i]))
+ return null;
+ }
+ }
+ return name;
+ }
+
+ protected IBuildEnvironmentVariable[] filterVariables(IBuildEnvironmentVariable variables[]){
+ if(variables == null || variables.length == 0)
+ return variables;
+
+ IBuildEnvironmentVariable filtered[] = new IBuildEnvironmentVariable[variables.length];
+ int filteredNum = 0;
+ for(int i = 0; i < variables.length; i++){
+ if(getValidName(variables[i].getName()) != null)
+ filtered[filteredNum++] = variables[i];
+ }
+
+ if(filteredNum != filtered.length){
+ IBuildEnvironmentVariable vars[] = new IBuildEnvironmentVariable[filteredNum];
+ for(int i = 0; i < filteredNum; i++)
+ vars[i] = filtered[i];
+ filtered = vars;
+ }
+ return filtered;
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/IContextInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/IContextInfo.java
new file mode 100644
index 00000000000..c1ef2ad39f5
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/IContextInfo.java
@@ -0,0 +1,42 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
+
+/**
+ * This interface is used by the Environment Variable Provider to
+ * represent the given context(level) information
+ *
+ * @since 3.0
+ */
+public interface IContextInfo {
+ /**
+ * Returns the next lower-precedence context
+ *
+ * @return IContextInfo
+ */
+ public IContextInfo getNext();
+
+ /**
+ * Returns the array of suppliers to be used for this context
+ *
+ * @return IEnvironmentVariableSupplier[]
+ */
+ public IEnvironmentVariableSupplier[] getSuppliers();
+
+ /**
+ * Returns the current context
+ *
+ * @return Object
+ */
+ public Object getContext();
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/MbsEnvironmentSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/MbsEnvironmentSupplier.java
new file mode 100644
index 00000000000..caad9fc92d8
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/MbsEnvironmentSupplier.java
@@ -0,0 +1,90 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
+import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+/**
+ * This is the Environment Variable Supplier used to supply variables
+ * defined by the MBS
+ *
+ * @since 3.0
+ */
+public class MbsEnvironmentSupplier implements IEnvironmentVariableSupplier {
+ private static final String fVariableNames[] = new String[]{
+ "CWD", //$NON-NLS-1$
+ "PWD" //$NON-NLS-1$
+ };
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariable()
+ */
+ public IBuildEnvironmentVariable getVariable(String name, Object context) {
+ if(context instanceof IConfiguration)
+ return getConfigurationVariable(name,(IConfiguration)context);
+ return null;
+ }
+
+ public IBuildEnvironmentVariable getConfigurationVariable(String name, IConfiguration configuration) {
+ IBuildEnvironmentVariable variable = null;
+ if("CWD".equals(name) || "PWD".equals(name)){ //$NON-NLS-1$ //$NON-NLS-2$
+ IResource owner = configuration.getOwner();
+ if(owner != null){
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(owner);
+ if(info != null && configuration.equals(info.getDefaultConfiguration())){
+ IManagedBuilderMakefileGenerator generator = ManagedBuildManager.getBuildfileGenerator(configuration);
+ generator.initialize((IProject)owner,info,null);
+
+ IPath topBuildDir = generator.getBuildWorkingDir();
+ if(topBuildDir == null)
+ topBuildDir = new Path(info.getConfigurationName());
+
+ IPath projectLocation = owner.getLocation();
+ IPath workingDirectory = projectLocation.append(topBuildDir);
+ String value = workingDirectory.toOSString();
+ variable = new BuildEnvVar(name,value,IBuildEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+ }
+ }
+ return variable;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariables()
+ */
+ public IBuildEnvironmentVariable[] getVariables(Object context) {
+ if(context instanceof IConfiguration){
+ List variables = new ArrayList(fVariableNames.length);
+ for(int i = 0; i < fVariableNames.length; i++){
+ IBuildEnvironmentVariable var = getConfigurationVariable(fVariableNames[i],(IConfiguration)context);
+ if(var != null)
+ variables.add(var);
+ }
+ if(variables.size() == 0)
+ return null;
+ return (IBuildEnvironmentVariable[])variables.toArray(new IBuildEnvironmentVariable[variables.size()]);
+ }
+ return null;
+ }
+
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvVar.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvVar.java
new file mode 100644
index 00000000000..f058b52742a
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvVar.java
@@ -0,0 +1,109 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * This class represents the Environment variable that could be loaded
+ * and stored in XML
+ *
+ * @since 3.0
+ *
+ */
+public class StorableEnvVar extends BuildEnvVar {
+ public static final String VARIABLE_ELEMENT_NAME = "variable"; //$NON-NLS-1$
+ public static final String NAME = "name"; //$NON-NLS-1$
+ public static final String VALUE = "value"; //$NON-NLS-1$
+ public static final String OPERATION = "operation"; //$NON-NLS-1$
+ public static final String DELIMITER = "delimiter"; //$NON-NLS-1$
+
+ public static final String REPLACE = "replace"; //$NON-NLS-1$
+ public static final String REMOVE = "remove"; //$NON-NLS-1$
+ public static final String APPEND = "append"; //$NON-NLS-1$
+ public static final String PREPEND = "prepend"; //$NON-NLS-1$
+
+ public StorableEnvVar(String name, String value, int op, String delimiter){
+ super(name,value,op,delimiter);
+ }
+
+ public StorableEnvVar(String name){
+ this(name,null,ENVVAR_REPLACE,null);
+ }
+
+ public StorableEnvVar(String name, String value){
+ this(name,value,ENVVAR_REPLACE,null);
+ }
+
+ public StorableEnvVar(String name, String value, String delimiter){
+ this(name,value,ENVVAR_REPLACE,delimiter);
+ }
+
+ public StorableEnvVar(Element element){
+ load(element);
+ }
+
+ private void load(Element element){
+ fName = element.getAttribute(NAME);
+
+ fValue = element.getAttribute(VALUE);
+
+ fOperation = opStringToInt(element.getAttribute(OPERATION));
+
+ fDelimiter = element.getAttribute(DELIMITER);
+ if("".equals(fDelimiter))
+ fDelimiter = null;
+ }
+
+ private int opStringToInt(String op){
+ int operation;
+
+ if(REMOVE.equals(op))
+ operation = ENVVAR_REMOVE;
+ else if(APPEND.equals(op))
+ operation = ENVVAR_APPEND;
+ else if(PREPEND.equals(op))
+ operation = ENVVAR_PREPEND;
+ else
+ operation = ENVVAR_REPLACE;
+
+ return operation;
+ }
+
+ private String opIntToString(int op){
+ String operation;
+
+ if(ENVVAR_REMOVE == op)
+ operation = REMOVE;
+ else if(ENVVAR_APPEND == op)
+ operation = APPEND;
+ else if(ENVVAR_PREPEND == op)
+ operation = PREPEND;
+ else
+ operation = REPLACE;
+
+ return operation;
+ }
+
+ public void serialize(Document doc, Element element){
+ if(fName != null)
+ element.setAttribute(NAME,fName);
+
+ if(fValue != null)
+ element.setAttribute(VALUE,fValue);
+
+ element.setAttribute(OPERATION,opIntToString(fOperation));
+
+ if(fDelimiter != null)
+ element.setAttribute(DELIMITER,fDelimiter);
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvironment.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvironment.java
new file mode 100644
index 00000000000..5c9119534c1
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvironment.java
@@ -0,0 +1,195 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * This class represents the set of environment variables that could be loaded
+ * and stored in XML
+ *
+ * @since 3.0
+ *
+ */public class StorableEnvironment {
+ public static final String ENVIRONMENT_ELEMENT_NAME = "environment"; //$NON-NLS-1$
+ private Map fVariables;
+ private boolean fIsDirty = false;
+ private boolean fIsChanged = false;
+
+ private Map getMap(){
+ if(fVariables == null)
+ fVariables = new HashMap();
+ return fVariables;
+ }
+
+ public StorableEnvironment() {
+
+ }
+
+ public StorableEnvironment(Element element) {
+ load(element);
+ }
+
+ private void load(Element element){
+ NodeList nodeList = element.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); ++i) {
+ Node node = nodeList.item(i);
+ if (node.getNodeName().equals(StorableEnvVar.VARIABLE_ELEMENT_NAME)) {
+ addVariable(new StorableEnvVar((Element)node));
+ }
+ }
+ fIsDirty = false;
+ fIsChanged = false;
+ }
+
+ public void serialize(Document doc, Element element){
+ if(fVariables != null){
+ Iterator iter = fVariables.values().iterator();
+ while(iter.hasNext()){
+ StorableEnvVar var = (StorableEnvVar)iter.next();
+ Element varEl = doc.createElement(StorableEnvVar.VARIABLE_ELEMENT_NAME);
+ element.appendChild(varEl);
+ var.serialize(doc,varEl);
+ }
+ }
+ fIsDirty = false;
+ }
+
+ private void addVariable(IBuildEnvironmentVariable var){
+ String name = var.getName();
+ if(name == null)
+ return;
+ IEnvironmentVariableProvider provider = ManagedBuildManager.getEnvironmentVariableProvider();
+ if(!provider.isVariableCaseSensitive())
+ name = name.toUpperCase();
+
+ getMap().put(name,var);
+ }
+
+ public IBuildEnvironmentVariable createVariable(String name, String value, int op, String delimiter){
+ if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$
+ return null;
+
+ StorableEnvVar var = new StorableEnvVar(name, value, op, delimiter);
+ addVariable(var);
+ fIsDirty = true;
+ fIsChanged = true;
+ return var;
+ }
+
+ public IBuildEnvironmentVariable createVariable(String name){
+ return createVariable(name,null,IBuildEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+
+ public IBuildEnvironmentVariable createVariable(String name, String value){
+ return createVariable(name,value,IBuildEnvironmentVariable.ENVVAR_REPLACE,null);
+ }
+
+ public IBuildEnvironmentVariable createVariable(String name, String value, String delimiter){
+ return createVariable(name,value,IBuildEnvironmentVariable.ENVVAR_REPLACE,delimiter);
+ }
+
+ /**
+ * Returns the "dirty" state of the environment.
+ * If the dirty state is <code>true</code>, that means that the environment
+ * is out of synch with the repository and the environment needs to be serialized.
+ * <br><br>
+ * The dirty state is automatically set to <code>false</code> when the environment is serialized
+ * by calling the serialize() method
+ * @return boolean
+ */
+ public boolean isDirty(){
+ return fIsDirty;
+ }
+
+ /**
+ * sets the "dirty" state of the environment
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.StorableEnvironment#isDirty()
+ * @param dirty represents the new state
+ */
+ public void setDirty(boolean dirty){
+ fIsDirty = dirty;
+ }
+
+ /**
+ * Returns the "change" state of the environment.
+ * The "change" state represents whether the environment was changed or not.
+ * This state is not reset when the serialize() method is called
+ * Users can use this state to monitor whether the environment was changed or not.
+ * This state can be reset to <code>false</code> only by calling the setChanged(false) method
+ * @return boolean
+ */
+ public boolean isChanged(){
+ return fIsChanged;
+ }
+
+ /**
+ * sets the "change" state of the environment
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.StorableEnvironment#isChanged()
+ * @param changed represents the new "change" state
+ */
+ public void setChanged(boolean changed){
+ fIsChanged = changed;
+ }
+
+ public IBuildEnvironmentVariable getVariable(String name){
+ if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$
+ return null;
+ IEnvironmentVariableProvider provider = EnvironmentVariableProvider.getDefault();
+ if(!provider.isVariableCaseSensitive())
+ name = name.toUpperCase();
+
+ return (IBuildEnvironmentVariable)getMap().get(name);
+ }
+
+ public IBuildEnvironmentVariable[] getVariables(){
+ Collection vars = getMap().values();
+
+ return (IBuildEnvironmentVariable[])vars.toArray(new IBuildEnvironmentVariable[vars.size()]);
+ }
+
+ IBuildEnvironmentVariable deleteVariable(String name){
+ if(name == null || "".equals(name = name.trim())) //$NON-NLS-1$
+ return null;
+ IEnvironmentVariableProvider provider = ManagedBuildManager.getEnvironmentVariableProvider();
+ if(!provider.isVariableCaseSensitive())
+ name = name.toUpperCase();
+
+ IBuildEnvironmentVariable var = (IBuildEnvironmentVariable)getMap().remove(name);
+ if(var != null){
+ fIsDirty = true;
+ fIsChanged = true;
+ }
+
+ return var;
+ }
+
+ public void deleteAll(){
+ Map map = getMap();
+ if(map.size() > 0){
+ fIsDirty = true;
+ fIsChanged = true;
+ }
+
+ map.clear();
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvironmentLoader.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvironmentLoader.java
new file mode 100644
index 00000000000..a63b37e6958
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StorableEnvironmentLoader.java
@@ -0,0 +1,220 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
+import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * This class implements the common functionality that allows
+ * storing and loading environment variable settings from eclipse properties
+ *
+ * @since 3.0
+ *
+ */
+public abstract class StorableEnvironmentLoader {
+
+ /**
+ * this interface represents the preference node and the preference name
+ * that are used for holding the environment data
+ *
+ */
+ protected interface ISerializeInfo{
+ Preferences getNode();
+
+ String getPrefName();
+ }
+
+ /**
+ * this method should return the ISerializeInfo representing the information
+ * of where the variable should be stored and loaded
+ * If the given context is not supported this method should return null
+ *
+ * @param context
+ * @return
+ */
+ protected abstract ISerializeInfo getSerializeInfo(Object context);
+
+ /*
+ * loads the stored environment for the given context
+ */
+ protected StorableEnvironment loadEnvironment(Object context){
+ ISerializeInfo serializeInfo = getSerializeInfo(context);
+ if(serializeInfo == null)
+ return null;
+
+ InputStream stream = loadInputStream(serializeInfo.getNode(),serializeInfo.getPrefName());
+ if(stream == null)
+ return new StorableEnvironment();
+ return loadEnvironmentFromStream(stream);
+ }
+
+ /*
+ * stores the given environment
+ */
+ protected void storeEnvironment(StorableEnvironment env, Object context, boolean force) throws CoreException{
+ if(!env.isDirty() && !force)
+ return;
+
+ ISerializeInfo serializeInfo = getSerializeInfo(context);
+ if(serializeInfo == null)
+ return;
+
+ ByteArrayOutputStream stream = storeEnvironmentToStream(env);
+ if(stream == null)
+ return;
+ storeOutputStream(stream,serializeInfo.getNode(),serializeInfo.getPrefName());
+ }
+
+ private StorableEnvironment loadEnvironmentFromStream(InputStream stream){
+ try{
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ InputSource inputSource = new InputSource(stream);
+ Document document = parser.parse(inputSource);
+ Element rootElement = document.getDocumentElement();
+
+ if(!StorableEnvironment.ENVIRONMENT_ELEMENT_NAME.equals(rootElement.getNodeName()))
+ return null;
+
+ return new StorableEnvironment(rootElement);
+ }
+ catch(ParserConfigurationException e){
+
+ }
+ catch(SAXException e){
+
+ }
+ catch(IOException e){
+
+ }
+
+ return null;
+ }
+
+ private ByteArrayOutputStream storeEnvironmentToStream(StorableEnvironment env) throws CoreException{
+ try{
+ DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder= factory.newDocumentBuilder();
+ Document document= builder.newDocument();
+
+ Element rootElement = document.createElement(StorableEnvironment.ENVIRONMENT_ELEMENT_NAME);
+ document.appendChild(rootElement);
+ env.serialize(document,rootElement);
+
+ Transformer transformer=TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ DOMSource source = new DOMSource(document);
+
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(stream);
+
+ transformer.transform(source, result);
+ return stream;
+ }
+ catch(ParserConfigurationException e){
+ throw new CoreException(new Status(IStatus.ERROR,
+ ManagedBuilderCorePlugin.getUniqueIdentifier(),
+ -1,
+ e.getMessage(),
+ e));
+ }
+ catch(TransformerConfigurationException e){
+ throw new CoreException(new Status(IStatus.ERROR,
+ ManagedBuilderCorePlugin.getUniqueIdentifier(),
+ -1,
+ e.getMessage(),
+ e));
+ }
+ catch(TransformerException e){
+ throw new CoreException(new Status(IStatus.ERROR,
+ ManagedBuilderCorePlugin.getUniqueIdentifier(),
+ -1,
+ e.getMessage(),
+ e));
+ }
+ }
+
+ private InputStream loadInputStream(Preferences node, String key){
+ if(node == null || key == null)
+ return null;
+
+ String value = node.get(key,null);
+ if(value == null || value.length() == 0)
+ return null;
+
+ byte[] bytes;
+ try {
+ bytes = value.getBytes("UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ bytes = value.getBytes();
+ }
+
+ return new ByteArrayInputStream(bytes);
+ }
+
+ private void storeOutputStream(ByteArrayOutputStream stream, Preferences node, String key) throws CoreException{
+ if(stream == null || node == null || key == null)
+ throw new CoreException(new Status(IStatus.ERROR,
+ ManagedBuilderCorePlugin.getUniqueIdentifier(),
+ -1,
+ ManagedMakeMessages.getResourceString("StorableEnvironmentLoader.storeOutputStream.wrong.arguments"), //$NON-NLS-1$
+ null));
+ byte[] bytes= stream.toByteArray();
+
+ String val = null;
+ try {
+ val= new String(bytes, "UTF-8"); //$NON-NLS-1$
+ } catch (UnsupportedEncodingException e) {
+ val= new String(bytes);
+ }
+
+ node.put(key,val);
+
+ try{
+ node.flush();
+ }
+ catch(BackingStoreException e){
+ throw new CoreException(new Status(IStatus.ERROR,
+ ManagedBuilderCorePlugin.getUniqueIdentifier(),
+ -1,
+ e.getMessage(),
+ e));
+ }
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StoredBuildPathEnvironmentContainer.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StoredBuildPathEnvironmentContainer.java
new file mode 100644
index 00000000000..5e7fb69bd8a
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/StoredBuildPathEnvironmentContainer.java
@@ -0,0 +1,265 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IEnvVarBuildPath;
+import org.eclipse.cdt.managedbuilder.core.ITool;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.runtime.CoreException;
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * This class holds the build path variable values and allows
+ * checking the stored variable values with the values of the current environment environment
+ *
+ * @since 3.0
+ *
+ */
+public class StoredBuildPathEnvironmentContainer extends
+ StorableEnvironmentLoader {
+ public static final String NODENAME = "environment"; //$NON-NLS-1$
+ public static final String NODENAME_PREFIX_CFG = "buildEnvironment"; //$NON-NLS-1$
+ public static final String NODENAME_CFG_INCLUDE = NODENAME_PREFIX_CFG + "Include"; //$NON-NLS-1$
+ public static final String NODENAME_CFG_LIBRARY = NODENAME_PREFIX_CFG + "Library"; //$NON-NLS-1$
+
+ private IConfiguration fConfiguration;
+ private StorableEnvironment fEnvironment;
+ private int fPathType;
+ private boolean fIsVariableCaseSensitive = ManagedBuildManager.getEnvironmentVariableProvider().isVariableCaseSensitive();
+
+ public StoredBuildPathEnvironmentContainer(int pathType){
+ fPathType = pathType == IEnvVarBuildPath.BUILDPATH_LIBRARY ?
+ IEnvVarBuildPath.BUILDPATH_LIBRARY : IEnvVarBuildPath.BUILDPATH_INCLUDE;
+ }
+
+ protected StorableEnvironment getEnvironment(Object context) {
+ StorableEnvironment env = null;
+ if(context instanceof IConfiguration){
+ if(fConfiguration != null && context == fConfiguration && fEnvironment != null)
+ env = fEnvironment;
+ else {
+ env = loadEnvironment(context);
+ if(env != null){
+ if(fConfiguration != null && fEnvironment != null){
+ try{
+ storeEnvironment(fEnvironment,fConfiguration,false);
+ }catch(CoreException e){
+ }
+ }
+
+ checkLoadedVarNames(env,context);
+
+ fConfiguration = (IConfiguration)context;
+ fEnvironment = env;
+ }
+ }
+ }
+ return env;
+ }
+
+ private boolean haveIdenticalValues(IBuildEnvironmentVariable var1,
+ IBuildEnvironmentVariable var2){
+ if(var1 == null)
+ return var2 == null || var2.getOperation() == IBuildEnvironmentVariable.ENVVAR_REMOVE;
+ if(var2 == null)
+ return var1 == null || var1.getOperation() == IBuildEnvironmentVariable.ENVVAR_REMOVE;
+ int op1 = var1.getOperation();
+ int op2 = var2.getOperation();
+ if(op1 == IBuildEnvironmentVariable.ENVVAR_REMOVE ||
+ op2 == IBuildEnvironmentVariable.ENVVAR_REMOVE)
+ return op1 == op2;
+
+ return maskNull(var1.getValue()).equals(maskNull(var2.getValue()));
+ }
+
+ private String maskNull(String val){
+ return val == null ? "" : val; //$NON-NLS-1$
+ }
+
+ public boolean checkBuildPathChange(EnvVarCollector existingVariables,
+ IConfiguration configuration){
+ StorableEnvironment env = getEnvironment(configuration);
+ if(env == null)
+ return false;
+ IBuildEnvironmentVariable vars[] = env.getVariables();
+ for(int i = 0; i < vars.length; i++){
+ IBuildEnvironmentVariable var = vars[i];
+ String name = var.getName();
+ IBuildEnvironmentVariable curVar = existingVariables != null ?
+ existingVariables.getVariable(name) : null;
+ if(!haveIdenticalValues(var,curVar)){
+ if(curVar == null){
+ env.createVariable(name,null,IBuildEnvironmentVariable.ENVVAR_REMOVE,null);
+ }
+ else{
+ env.createVariable(curVar.getName(),curVar.getValue(),curVar.getOperation(),curVar.getDelimiter());
+ }
+ }
+ }
+ boolean changed = env.isChanged();
+ env.setChanged(false);
+ if(changed)
+ try{
+ storeEnvironment(env,configuration,false);
+ }catch(CoreException e){
+ }
+ return changed;
+ }
+
+ /*
+ * checks whether the variable of a given name is the build path variable
+ * for the given configuration
+ * If it is, than performs a check and returns true if the variable was changed
+ * If it is not the build path variable, no check is performed and this method always
+ * returns false in this case
+ */
+ public boolean isVariableChanged(String name,
+ IBuildEnvironmentVariable variable,
+ IConfiguration configuration){
+ StorableEnvironment env = getEnvironment(configuration);
+ if(env == null)
+ return false;
+ IBuildEnvironmentVariable var = env.getVariable(name);
+ if(var == null)
+ return false;
+
+ if(haveIdenticalValues(var,variable))
+ return false;
+
+ return true;
+ }
+
+ /*
+ * synchronizes the stored variables with the ones passed to this method
+ */
+ public void synchronize(EnvVarCollector existingVariables,
+ IConfiguration configuration){
+ checkBuildPathChange(existingVariables,configuration);
+ }
+
+ private void checkLoadedVarNames(StorableEnvironment env, Object context){
+ String varNames[] = getBuildPathVarNames((IConfiguration)context, fPathType);
+ for(int i = 0; i < varNames.length; i++){
+ String name = varNames[i];
+ if(env.getVariable(name) == null)
+ env.createVariable(name,null,IBuildEnvironmentVariable.ENVVAR_REMOVE,null);
+ }
+
+ IBuildEnvironmentVariable vars[] = env.getVariables();
+ for(int i = 0; i < vars.length; i++){
+ IBuildEnvironmentVariable var = vars[i];
+ boolean validVar = false;
+ for(int j = 0; j < varNames.length; j++){
+ String varName = varNames[j];
+ if(varNamesEqual(var.getName(),varName)){
+ validVar = true;
+ break;
+ }
+ }
+ if(!validVar){
+ env.deleteVariable(var.getName());
+ }
+ }
+ }
+
+ /*
+ * returns true if the variable names are equal and false otherwise
+ */
+ private boolean varNamesEqual(String name1, String name2){
+ return fIsVariableCaseSensitive ?
+ name1.equals(name2) : name1.equalsIgnoreCase(name2);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.internal.envvar.StorableEnvironmentLoader#getSerializeInfo(java.lang.Object)
+ */
+ protected ISerializeInfo getSerializeInfo(Object context) {
+ ISerializeInfo serializeInfo = null;
+ if(context instanceof IConfiguration){
+ IConfiguration cfg = (IConfiguration)context;
+ final Preferences prefs = getConfigurationNode(cfg);
+ final String name = cfg.getId();
+ if(prefs != null && name != null)
+ serializeInfo = new ISerializeInfo(){
+ public Preferences getNode(){
+ return prefs;
+ }
+
+ public String getPrefName(){
+ return name;
+ }
+ };
+ }
+ return serializeInfo;
+ }
+
+ public void serialize(boolean force) {
+ if(fEnvironment != null){
+ try{
+ storeEnvironment(fEnvironment,fConfiguration,force);
+ }catch(CoreException e){
+ }
+ }
+ }
+
+ private Preferences getConfigurationNode(IConfiguration cfg){
+ IProject project = (IProject)cfg.getOwner();
+ if(project == null || !project.exists())
+ return null;
+
+ Preferences prefNode = new ProjectScope(project).getNode(ManagedBuilderCorePlugin.getUniqueIdentifier());
+ if(prefNode == null)
+ return null;
+
+ prefNode = prefNode.node(NODENAME);
+ if(prefNode == null)
+ return null;
+
+ if(fPathType == IEnvVarBuildPath.BUILDPATH_LIBRARY)
+ return prefNode.node(NODENAME_CFG_LIBRARY);
+ return prefNode.node(NODENAME_CFG_INCLUDE);
+ }
+
+ private String[] getBuildPathVarNames(IConfiguration configuration,int buildPathType){
+ ITool tools[] = configuration.getFilteredTools();
+ List list = new ArrayList();
+
+ for(int i = 0; i < tools.length; i++){
+ IEnvVarBuildPath pathDescriptors[] = tools[i].getEnvVarBuildPaths();
+
+ if(pathDescriptors == null || pathDescriptors.length == 0)
+ continue;
+
+ for(int j = 0; j < pathDescriptors.length; j++){
+ IEnvVarBuildPath curPathDes = pathDescriptors[j];
+ if(curPathDes.getType() != buildPathType)
+ continue;
+
+ String vars[] = curPathDes.getVariableNames();
+ if(vars == null || vars.length == 0)
+ continue;
+
+ list.addAll(Arrays.asList(vars));
+ }
+ }
+
+ return (String[])list.toArray(new String[list.size()]);
+ }
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/UserDefinedEnvironmentSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/UserDefinedEnvironmentSupplier.java
new file mode 100644
index 00000000000..92d8c54b1c2
--- /dev/null
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/envvar/UserDefinedEnvironmentSupplier.java
@@ -0,0 +1,349 @@
+/**********************************************************************
+ * Copyright (c) 2005 Intel Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Intel Corporation - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.cdt.managedbuilder.internal.envvar;
+
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
+import org.eclipse.cdt.managedbuilder.core.IManagedProject;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
+import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
+import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * This is the Environment Variable Supplier used to supply variables
+ * defined by a user
+ *
+ * @since 3.0
+ */
+public class UserDefinedEnvironmentSupplier extends
+ StorableEnvironmentLoader
+ implements IEnvironmentVariableSupplier{
+
+ public static final String NODENAME = "environment"; //$NON-NLS-1$
+ public static final String PREFNAME_WORKSPACE = "workspace"; //$NON-NLS-1$
+ public static final String PREFNAME_PROJECT = "project"; //$NON-NLS-1$
+ public static final String NODENAME_CFG = "project"; //$NON-NLS-1$
+
+ private static final String fNonOverloadableVariables[] = new String[]{
+ //users not allowed currently to override the "CWD" and "PWD" variables
+ EnvVarOperationProcessor.normalizeName("CWD"), //$NON-NLS-1$
+ EnvVarOperationProcessor.normalizeName("PWD") //$NON-NLS-1$
+ };
+
+ private StorableEnvironment fConfigurationVariables;
+ private StorableEnvironment fProjectVariables;
+ private StorableEnvironment fWorkspaceVariables;
+
+ private IConfiguration fCurrentCfg = null;
+ private IManagedProject fCurrentProj = null;
+
+ protected StorableEnvironment getEnvironment(Object context){
+ if(context == null)
+ return null;
+
+ StorableEnvironment env = null;
+ if(context instanceof IConfiguration){
+ IConfiguration newCfg = (IConfiguration)context;
+ if(fCurrentCfg == newCfg && fConfigurationVariables != null){
+ env = fConfigurationVariables;
+ }
+ else{
+ env = loadEnvironment(newCfg);
+ if(env != null){
+ if(fConfigurationVariables != null)
+ try{
+ storeEnvironment(fConfigurationVariables,fCurrentCfg,false);
+ } catch(CoreException e){
+ }
+ fConfigurationVariables = env;
+ fCurrentCfg = newCfg;
+ }
+ }
+ }
+ else if(context instanceof IManagedProject){
+ IManagedProject newProj = (IManagedProject)context;
+ if(fCurrentProj == newProj && fProjectVariables != null){
+ env = fProjectVariables;
+ }
+ else{
+ env = loadEnvironment(newProj);
+ if(env != null){
+ if(fProjectVariables != null)
+ try{
+ storeEnvironment(fProjectVariables,fCurrentProj,false);
+ } catch(CoreException e){
+ }
+ fProjectVariables = env;
+ fCurrentProj = newProj;
+ }
+ }
+ }
+ else if(context instanceof IWorkspace){
+ if(fWorkspaceVariables == null)
+ fWorkspaceVariables = loadEnvironment(context);
+ env = fWorkspaceVariables;
+ }
+
+ return env;
+ }
+
+ protected ISerializeInfo getSerializeInfo(Object context){
+ ISerializeInfo serializeInfo = null;
+
+ if(context instanceof IConfiguration){
+ IConfiguration cfg = (IConfiguration)context;
+ IManagedProject project = cfg.getManagedProject();
+
+ final Preferences prefs = project != null ? getConfigurationNode(project) : null;
+ final String name = cfg.getId();
+ if(prefs != null && name != null)
+ serializeInfo = new ISerializeInfo(){
+ public Preferences getNode(){
+ return prefs;
+ }
+
+ public String getPrefName(){
+ return name;
+ }
+ };
+ }
+ else if(context instanceof IManagedProject){
+ IManagedProject proj = (IManagedProject)context;
+ final Preferences prefs = getProjectNode(proj);
+ final String name = PREFNAME_PROJECT;
+ if(prefs != null && name != null)
+ serializeInfo = new ISerializeInfo(){
+ public Preferences getNode(){
+ return prefs;
+ }
+
+ public String getPrefName(){
+ return name;
+ }
+ };
+ }
+ else if(context instanceof IWorkspace){
+ final Preferences prefs = getWorkspaceNode();
+ final String name = PREFNAME_WORKSPACE;
+ if(prefs != null && name != null)
+ serializeInfo = new ISerializeInfo(){
+ public Preferences getNode(){
+ return prefs;
+ }
+
+ public String getPrefName(){
+ return name;
+ }
+ };
+ }
+ return serializeInfo;
+ }
+ private Preferences getConfigurationNode(IManagedProject managedProject){
+ Preferences prefNode = getProjectNode(managedProject);
+ if(prefNode == null)
+ return null;
+
+ return prefNode.node(NODENAME_CFG);
+ }
+
+ private Preferences getProjectNode(IManagedProject managedProject){
+ IProject project = (IProject)managedProject.getOwner();
+ if(!project.exists())
+ return null;
+
+ Preferences prefNode = new ProjectScope(project).getNode(ManagedBuilderCorePlugin.getUniqueIdentifier());
+ if(prefNode == null)
+ return null;
+
+ return prefNode.node(NODENAME);
+ }
+
+ private Preferences getWorkspaceNode(){
+ Preferences prefNode = new InstanceScope().getNode(ManagedBuilderCorePlugin.getUniqueIdentifier());
+ if(prefNode == null)
+ return null;
+
+ return prefNode.node(NODENAME);
+ }
+
+ public void checkInexistentConfigurations(IManagedProject managedProject){
+ Preferences prefNode = getConfigurationNode(managedProject);
+ if(prefNode == null)
+ return;
+
+ try{
+ String ids[] = prefNode.childrenNames();
+ boolean found = false;
+ for( int i = 0; i < ids.length; i++){
+ if(managedProject.getConfiguration(ids[i]) == null){
+ prefNode.remove(ids[i]);
+ found = true;
+ }
+ }
+
+ if(found)
+ prefNode.flush();
+ }
+ catch(BackingStoreException e){
+ }
+ }
+
+ public void serialize(boolean force){
+ if(fConfigurationVariables != null && fCurrentCfg != null ){
+ try{
+ storeEnvironment(fConfigurationVariables,fCurrentCfg,force);
+ } catch(CoreException e){
+
+ }
+ }
+
+ if(fProjectVariables != null && fCurrentProj != null ){
+ try{
+ storeEnvironment(fProjectVariables,fCurrentProj,force);
+ } catch(CoreException e){
+
+ }
+ }
+
+ if(fWorkspaceVariables != null){
+ try{
+ storeEnvironment(fWorkspaceVariables,ResourcesPlugin.getWorkspace(),force);
+ } catch(CoreException e){
+
+ }
+
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariable()
+ */
+ public IBuildEnvironmentVariable getVariable(String name, Object context) {
+ if(getValidName(name) == null)
+ return null;
+ StorableEnvironment env = getEnvironment(context);
+ if(env == null)
+ return null;
+ return env.getVariable(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableSupplier#getVariables()
+ */
+ public IBuildEnvironmentVariable[] getVariables(Object context) {
+ StorableEnvironment env = getEnvironment(context);
+ if(env == null)
+ return null;
+ return filterVariables(env.getVariables());
+ }
+
+ public IBuildEnvironmentVariable createVariable(String name, String value, int op, String delimiter, Object context){
+ if(getValidName(name) == null)
+ return null;
+ StorableEnvironment env = getEnvironment(context);
+ if(env == null)
+ return null;
+ IBuildEnvironmentVariable var = env.createVariable(name,value,op,delimiter);
+ setRebuildStateForContext(context);
+ return var;
+ }
+
+ public IBuildEnvironmentVariable deleteVariable(String name, Object context){
+ StorableEnvironment env = getEnvironment(context);
+ if(env == null)
+ return null;
+ IBuildEnvironmentVariable var = env.deleteVariable(name);
+ if(var != null)
+ setRebuildStateForContext(context);
+ return var;
+ }
+
+ public void deleteAll(Object context){
+ StorableEnvironment env = getEnvironment(context);
+ if(env == null)
+ return;
+
+ env.deleteAll();
+ setRebuildStateForContext(context);
+ }
+
+ protected void setRebuildStateForContext(Object context){
+ if(context == null)
+ return;
+ if(context instanceof IConfiguration){
+ ((IConfiguration)context).setRebuildState(true);
+ }
+ else if(context instanceof IManagedProject){
+ IConfiguration cfgs[] = ((IManagedProject)context).getConfigurations();
+ for(int i = 0; i < cfgs.length; i++){
+ cfgs[i].setRebuildState(true);
+ }
+ }
+ else if(context instanceof IWorkspace){
+ IProject projects[] = ((IWorkspace)context).getRoot().getProjects();
+ for(int i = 0; i < projects.length; i++){
+ if(ManagedBuildManager.manages(projects[i])){
+ IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(projects[i]);
+ if(info != null){
+ IConfiguration cfgs[] = info.getManagedProject().getConfigurations();
+ for(int j = 0; j < cfgs.length; j++){
+ cfgs[j].setRebuildState(true);
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ protected String getValidName(String name){
+ name = EnvVarOperationProcessor.normalizeName(name);
+ if(name == null)
+ return null;
+ if(fNonOverloadableVariables != null){
+ for(int i = 0; i < fNonOverloadableVariables.length; i++){
+ if(name.equals(fNonOverloadableVariables[i]))
+ return null;
+ }
+ }
+ return name;
+ }
+
+ protected IBuildEnvironmentVariable[] filterVariables(IBuildEnvironmentVariable variables[]){
+ if(variables == null || variables.length == 0)
+ return variables;
+
+ IBuildEnvironmentVariable filtered[] = new IBuildEnvironmentVariable[variables.length];
+ int filteredNum = 0;
+ for(int i = 0; i < variables.length; i++){
+ if(getValidName(variables[i].getName()) != null)
+ filtered[filteredNum++] = variables[i];
+ }
+
+ if(filteredNum != filtered.length){
+ IBuildEnvironmentVariable vars[] = new IBuildEnvironmentVariable[filteredNum];
+ for(int i = 0; i < filteredNum; i++)
+ vars[i] = filtered[i];
+ filtered = vars;
+ }
+ return filtered;
+ }
+
+}
diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java
index cbc09e5f59d..2d8175b8dbd 100644
--- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java
+++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/makegen/gnu/GnuMakefileGenerator.java
@@ -311,6 +311,8 @@ public class GnuMakefileGenerator implements IManagedBuilderMakefileGenerator {
for (int i=0; i<buildTools.length; i++) buildToolsUsed[i] = false;
// Initialize the tool info array
gnuToolInfos = new ManagedBuildGnuToolInfo[buildTools.length];
+ //set the top build dir path
+ topBuildDir = project.getFolder(info.getConfigurationName()).getFullPath();
}
/* (non-Javadoc)

Back to the top