1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

added environment APIs to target and build info

enable variable support in builder arguments, environment and targets
make builder is now "configurable"
This commit is contained in:
David Inglis 2005-03-24 17:37:27 +00:00
parent 6bcf0f580b
commit 58e5610d98
10 changed files with 121 additions and 38 deletions

View file

@ -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">

View file

@ -60,4 +60,7 @@ public interface IMakeBuilderInfo {
Map getEnvironment();
void setEnvironment(Map env) throws CoreException;
boolean appendEnvironment();
void setAppendEnvironment(boolean append) throws CoreException;
}

View file

@ -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.
*

View file

@ -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$
}
env = (String[]) envList.toArray(new String[envList.size()]);
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();
}
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.

View file

@ -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 {

View file

@ -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);
}
}

View file

@ -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());
}

View file

@ -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;

View file

@ -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) {
}

View file

@ -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;