Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Inglis2005-03-24 12:37:27 -0500
committerDavid Inglis2005-03-24 12:37:27 -0500
commit58e5610d98e9fb14c98c938417d662d5c2faa8a7 (patch)
tree0646fe3ab9de7e96bb629e5aaeffa1f24cfb59bb
parent6bcf0f580b648338eeb907ca9caf0fac5b2cf9ad (diff)
downloadorg.eclipse.cdt-58e5610d98e9fb14c98c938417d662d5c2faa8a7.tar.gz
org.eclipse.cdt-58e5610d98e9fb14c98c938417d662d5c2faa8a7.tar.xz
org.eclipse.cdt-58e5610d98e9fb14c98c938417d662d5c2faa8a7.zip
added environment APIs to target and build info
enable variable support in builder arguments, environment and targets make builder is now "configurable"
-rw-r--r--build/org.eclipse.cdt.make.core/plugin.xml7
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeBuilderInfo.java3
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTarget.java9
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java59
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeProjectNature.java7
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/BuildInfoFactory.java38
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java27
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java4
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/PreferenceInitializer.java1
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java2
10 files changed, 120 insertions, 37 deletions
diff --git a/build/org.eclipse.cdt.make.core/plugin.xml b/build/org.eclipse.cdt.make.core/plugin.xml
index 69c21ff16e9..d75946bb66d 100644
--- a/build/org.eclipse.cdt.make.core/plugin.xml
+++ b/build/org.eclipse.cdt.make.core/plugin.xml
@@ -16,6 +16,7 @@
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.cdt.core"/>
<import plugin="org.eclipse.core.runtime"/>
+ <import plugin="org.eclipse.core.variables"/>
</requires>
@@ -52,9 +53,9 @@
name="%builderMake.name"
point="org.eclipse.core.resources.builders">
<builder
- hasNature="true">
- <run
- class="org.eclipse.cdt.make.core.MakeBuilder">
+ hasNature="true"
+ isConfigurable="true">
+ <run class="org.eclipse.cdt.make.core.MakeBuilder">
<parameter
name="defaultCommand"
value="make">
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeBuilderInfo.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeBuilderInfo.java
index 81c5196ef7a..f6f1501d45a 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeBuilderInfo.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeBuilderInfo.java
@@ -60,4 +60,7 @@ public interface IMakeBuilderInfo {
Map getEnvironment();
void setEnvironment(Map env) throws CoreException;
+
+ boolean appendEnvironment();
+ void setAppendEnvironment(boolean append) throws CoreException;
}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTarget.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTarget.java
index cd1622fb5b7..cbf333d674a 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTarget.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTarget.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.make.core;
+import java.util.Map;
+
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
@@ -31,12 +33,19 @@ public interface IMakeTarget extends IAdaptable {
IPath getBuildCommand();
void setBuildCommand(IPath command) throws CoreException;
+
String getBuildArguments();
void setBuildArguments(String arguments) throws CoreException;
void setRunAllBuilders(boolean runAllBuilders);
boolean runAllBuilders();
+ void setBuildEnvironment(Map env) throws CoreException;
+ Map getBuildEnvironment();
+
+ void setAppendEnvironment(boolean append) throws CoreException;
+ boolean isAppendEnvironment();
+
/**
* Get the target build container.
*
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java
index 2f563968961..677875180ea 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeBuilder.java
@@ -13,9 +13,10 @@ package org.eclipse.cdt.make.core;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
-import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
import java.util.Map;
-import java.util.Properties;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CommandLauncher;
@@ -40,10 +41,13 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.osgi.service.environment.Constants;
public class MakeBuilder extends ACBuilder {
@@ -144,20 +148,39 @@ public class MakeBuilder extends ACBuilder {
launcher.showCommand(true);
// Set the environmennt, some scripts may need the CWD var to be set.
- Properties props = launcher.getEnvironment();
- props.putAll(info.getEnvironment());
- props.put("CWD", workingDirectory.toOSString()); //$NON-NLS-1$
- props.put("PWD", workingDirectory.toOSString()); //$NON-NLS-1$
- 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$
+ HashMap envMap = new HashMap();
+ if (info.appendEnvironment()) {
+ envMap.putAll(launcher.getEnvironment());
+ }
+ envMap.put("CWD", workingDirectory.toOSString()); //$NON-NLS-1$
+ envMap.put("PWD", workingDirectory.toOSString()); //$NON-NLS-1$
+ // Add variables from build info
+ Map userEnv = info.getEnvironment();
+ Iterator iter= userEnv.entrySet().iterator();
+ boolean win32= Platform.getOS().equals(Constants.OS_WIN32);
+ while (iter.hasNext()) {
+ Map.Entry entry= (Map.Entry) iter.next();
+ String key= (String) entry.getKey();
+ if (win32) {
+ // Win32 vars are case insensitive. Uppercase everything so
+ // that (for example) "pAtH" will correctly replace "PATH"
+ key= key.toUpperCase();
}
- env = (String[]) envList.toArray(new String[envList.size()]);
+ String value = (String) entry.getValue();
+ // translate any string substitution variables
+ String translated = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(value);
+ envMap.put(key, translated);
+ }
+
+ iter= envMap.entrySet().iterator();
+ List strings= new ArrayList(envMap.size());
+ while (iter.hasNext()) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ StringBuffer buffer= new StringBuffer((String) entry.getKey());
+ buffer.append('=').append((String) entry.getValue());
+ strings.add(buffer.toString());
}
+ String[] env = (String[]) strings.toArray(new String[strings.size()]);
String[] buildArguments = targets;
if (info.isDefaultBuildCmd()) {
if (!info.isStopOnError()) {
@@ -168,7 +191,8 @@ public class MakeBuilder extends ACBuilder {
} else {
String args = info.getBuildArguments();
if (args != null && !args.equals("")) { //$NON-NLS-1$
- String[] newArgs = makeArray(args);
+ String translated = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(args);
+ String[] newArgs = makeArray(translated);
buildArguments = new String[targets.length + newArgs.length];
System.arraycopy(newArgs, 0, buildArguments, 0, newArgs.length);
System.arraycopy(targets, 0, buildArguments, newArgs.length, targets.length);
@@ -273,7 +297,7 @@ public class MakeBuilder extends ACBuilder {
return true;
}
- protected String[] getTargets(int kind, IMakeBuilderInfo info) {
+ protected String[] getTargets(int kind, IMakeBuilderInfo info) throws CoreException {
String targets = ""; //$NON-NLS-1$
switch (kind) {
case IncrementalProjectBuilder.AUTO_BUILD :
@@ -289,7 +313,8 @@ public class MakeBuilder extends ACBuilder {
targets = info.getCleanBuildTarget();
break;
}
- return makeArray(targets);
+ String translated = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(targets);
+ return makeArray(translated);
}
// Turn the string into an array.
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeProjectNature.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeProjectNature.java
index c203610a2ab..62b9679c129 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeProjectNature.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeProjectNature.java
@@ -36,7 +36,7 @@ public class MakeProjectNature implements IProjectNature {
project.setDescription(description, monitor);
}
- public static ICommand getBuildSpec(IProjectDescription description, String builderID) throws CoreException {
+ public static ICommand getBuildSpec(IProjectDescription description, String builderID) {
ICommand[] commands = description.getBuildSpec();
for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(builderID)) {
@@ -50,8 +50,7 @@ public class MakeProjectNature implements IProjectNature {
* Update the Java command in the build spec (replace existing one if present,
* add one first if none).
*/
- public static IProjectDescription setBuildSpec(IProjectDescription description, ICommand newCommand)
- throws CoreException {
+ public static IProjectDescription setBuildSpec(IProjectDescription description, ICommand newCommand) {
ICommand[] oldCommands = description.getBuildSpec();
ICommand oldCommand = getBuildSpec(description, newCommand.getBuilderName());
@@ -149,6 +148,8 @@ public class MakeProjectNature implements IProjectNature {
projectInfo.setCleanBuildEnable(info.isCleanBuildEnabled());
projectInfo.setCleanBuildTarget(info.getCleanBuildTarget());
projectInfo.setErrorParsers(info.getErrorParsers());
+ projectInfo.setAppendEnvironment(info.appendEnvironment());
+ projectInfo.setEnvironment(info.getEnvironment());
}
public void removeBuildSpec() throws CoreException {
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/BuildInfoFactory.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/BuildInfoFactory.java
index 4a26a8a70c2..dab59d8edde 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/BuildInfoFactory.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/BuildInfoFactory.java
@@ -25,6 +25,7 @@ import org.eclipse.cdt.make.core.MakeProjectNature;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@@ -54,8 +55,10 @@ public class BuildInfoFactory {
static final String BUILD_AUTO_ENABLED = PREFIX + ".enableAutoBuild"; //$NON-NLS-1$
static final String BUILD_ARGUMENTS = PREFIX + ".buildArguments"; //$NON-NLS-1$
static final String ENVIRONMENT = PREFIX + ".environment"; //$NON-NLS-1$
+ static final String BUILD_APPEND_ENVIRONMENT = ".append_environment"; //$NON-NLS-1$
+
+ private abstract static class AbstractBuildInfo implements IMakeBuilderInfo {
- private abstract static class Store implements IMakeBuilderInfo {
public void setUseDefaultBuildCmd(boolean on) throws CoreException {
putString(USE_DEFAULT_BUILD_CMD, new Boolean(on).toString());
@@ -232,6 +235,17 @@ public class BuildInfoFactory {
putString(ENVIRONMENT, encodeMap(env));
}
+ public boolean appendEnvironment() {
+ if (getString(BUILD_APPEND_ENVIRONMENT).length() > 0) {
+ return getBoolean(BUILD_APPEND_ENVIRONMENT);
+ }
+ return true;
+ }
+
+ public void setAppendEnvironment(boolean append) throws CoreException {
+ putString(BUILD_APPEND_ENVIRONMENT, new Boolean(append).toString());
+ }
+
protected Map decodeMap(String value) {
Map map = new HashMap();
StringBuffer envStr = new StringBuffer(value);
@@ -298,12 +312,12 @@ public class BuildInfoFactory {
}
}
- private static class Preference extends Store {
+ private static class BuildInfoPreference extends AbstractBuildInfo {
private Preferences prefs;
private String builderID;
private boolean useDefaults;
- Preference(Preferences prefs, String builderID, boolean useDefaults) {
+ BuildInfoPreference(Preferences prefs, String builderID, boolean useDefaults) {
this.prefs = prefs;
this.builderID = builderID;
this.useDefaults = useDefaults;
@@ -329,12 +343,12 @@ public class BuildInfoFactory {
}
}
- private static class BuildProperty extends Store {
+ private static class BuildInfoProject extends AbstractBuildInfo {
private IProject project;
private String builderID;
private Map args;
- BuildProperty(IProject project, String builderID) throws CoreException {
+ BuildInfoProject(IProject project, String builderID) throws CoreException {
this.project = project;
this.builderID = builderID;
ICommand builder;
@@ -354,6 +368,10 @@ public class BuildInfoFactory {
ICommand builder = MakeProjectNature.getBuildSpec(description, builderID);
args.put(name, value);
builder.setArguments(args);
+ builder.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, isAutoBuildEnable());
+ builder.setBuilding(IncrementalProjectBuilder.FULL_BUILD, isFullBuildEnabled());
+ builder.setBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD, isIncrementalBuildEnabled());
+ builder.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD, isCleanBuildEnabled());
MakeProjectNature.setBuildSpec(description, builder);
project.setDescription(description, null);
}
@@ -368,11 +386,11 @@ public class BuildInfoFactory {
}
}
- private static class BuildArguments extends Store {
+ private static class BuildInfoMap extends AbstractBuildInfo {
private Map args;
private String builderID;
- BuildArguments(Map args, String builderID) {
+ BuildInfoMap(Map args, String builderID) {
this.args = args;
this.builderID = builderID;
}
@@ -391,14 +409,14 @@ public class BuildInfoFactory {
}
public static IMakeBuilderInfo create(Preferences prefs, String builderID, boolean useDefaults) {
- return new BuildInfoFactory.Preference(prefs, builderID, useDefaults);
+ return new BuildInfoFactory.BuildInfoPreference(prefs, builderID, useDefaults);
}
public static IMakeBuilderInfo create(IProject project, String builderID) throws CoreException {
- return new BuildInfoFactory.BuildProperty(project, builderID);
+ return new BuildInfoFactory.BuildInfoProject(project, builderID);
}
public static IMakeBuilderInfo create(Map args, String builderID) {
- return new BuildInfoFactory.BuildArguments(args, builderID);
+ return new BuildInfoFactory.BuildInfoMap(args, builderID);
}
}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java
index efaea92781c..d4fe9f1abc5 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java
@@ -11,6 +11,7 @@
package org.eclipse.cdt.make.internal.core;
import java.util.HashMap;
+import java.util.Map;
import org.eclipse.cdt.make.core.IMakeBuilderInfo;
import org.eclipse.cdt.make.core.IMakeTarget;
@@ -41,6 +42,8 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
boolean runAllBuidlers = true;
private String targetBuilderID;
private IContainer container;
+ private boolean appendEnvironment;
+ private Map buildEnvironment;
MakeTarget(MakeTargetManager manager, IProject project, String targetBuilderID, String name) throws CoreException {
this.manager = manager;
@@ -51,6 +54,8 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
buildArguments = info.getBuildArguments();
isDefaultBuildCmd = info.isDefaultBuildCmd();
isStopOnError = info.isStopOnError();
+ appendEnvironment = info.appendEnvironment();
+ buildEnvironment = info.getEnvironment();
}
public void setContainer(IContainer container) {
@@ -105,6 +110,24 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
manager.updateTarget(this);
}
+ public Map getBuildEnvironment() {
+ return buildEnvironment;
+ }
+
+ public void setBuildEnvironment(Map env) throws CoreException {
+ buildEnvironment = new HashMap(env);
+ manager.updateTarget(this);
+ }
+
+ public boolean isAppendEnvironment() {
+ return appendEnvironment;
+ }
+
+ public void setAppendEnvironment(boolean append) throws CoreException {
+ appendEnvironment = append;
+ manager.updateTarget(this);
+ }
+
public IContainer getContainer() {
return container;
}
@@ -120,7 +143,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
}
public int hashCode() {
- return container.hashCode() * 17 + name.hashCode();
+ return container.hashCode() * 17 + name != null ? name.hashCode(): 0;
}
public void build(IProgressMonitor monitor) throws CoreException {
@@ -139,6 +162,8 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
info.setStopOnError(isStopOnError);
info.setFullBuildEnable(true);
info.setFullBuildTarget(target);
+ info.setEnvironment(buildEnvironment);
+ info.setAppendEnvironment(appendEnvironment);
if (container != null) {
info.setBuildLocation(container.getFullPath());
}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java
index 05eff7b1128..b7749fa080b 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java
@@ -128,7 +128,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
return projectTargets.findTarget(container, name);
}
- public IProject[] getTargetBuilderProjects() throws CoreException {
+ public IProject[] getTargetBuilderProjects() {
return (IProject[])fProjects.toArray(new IProject[fProjects.size()]);
}
@@ -264,7 +264,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
projectTargets.saveTargets();
}
- protected ProjectTargets readTargets(IProject project) throws CoreException {
+ protected ProjectTargets readTargets(IProject project) {
ProjectTargets projectTargets = new ProjectTargets(this, project);
projectMap.put(project, projectTargets);
return projectTargets;
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/PreferenceInitializer.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/PreferenceInitializer.java
index 661fbf380b8..8a036bfb8d4 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/PreferenceInitializer.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/PreferenceInitializer.java
@@ -41,6 +41,7 @@ public class PreferenceInitializer extends AbstractPreferenceInitializer {
info.setFullBuildTarget("clean all"); //$NON-NLS-1$
info.setCleanBuildEnable(true);
info.setCleanBuildTarget("clean"); //$NON-NLS-1$
+ info.setAppendEnvironment(true);
info.setErrorParsers(CCorePlugin.getDefault().getAllErrorParsersIDs());
} catch (CoreException e) {
}
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java
index 8f60ac7ba1e..0a6c58653fc 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java
@@ -68,7 +68,7 @@ public class ProjectTargets {
private IProject project;
- public ProjectTargets(MakeTargetManager manager, IProject project) throws CoreException {
+ public ProjectTargets(MakeTargetManager manager, IProject project) {
boolean writeTargets = false;
File targetFile = null;

Back to the top