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

update new make plugin

This commit is contained in:
David Inglis 2003-08-14 02:11:07 +00:00
parent 80ee3e49e7
commit 36fd016fbb
7 changed files with 217 additions and 172 deletions

View file

@ -25,32 +25,34 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
public class BuildInfoFactory { public class BuildInfoFactory {
public static final String PREFIX = MakeCorePlugin.getUniqueIdentifier(); private static final String PREFIX = MakeCorePlugin.getUniqueIdentifier();
public static final String BUILD_COMMAND = PREFIX + ".buildCommand"; private static final String BUILD_COMMAND = PREFIX + ".buildCommand";
public static final String BUILD_LOCATION = PREFIX + ".buildLocation"; private static final String BUILD_LOCATION = PREFIX + ".buildLocation";
public static final String STOP_ON_ERROR = PREFIX + ".stopOnError"; private static final String STOP_ON_ERROR = PREFIX + ".stopOnError";
public static final String USE_DEFAULT_BUILD_CMD = PREFIX + ".useDefaultBuildCmd"; private static final String USE_DEFAULT_BUILD_CMD = PREFIX + ".useDefaultBuildCmd";
public static final String BUILD_TARGET_AUTO = PREFIX + ".autoBuildTarget"; private static final String BUILD_TARGET_AUTO = PREFIX + ".autoBuildTarget";
public static final String BUILD_TARGET_INCREMENTAL = PREFIX + ".incrementalBuildTarget"; private static final String BUILD_TARGET_INCREMENTAL = PREFIX + ".incrementalBuildTarget";
public static final String BUILD_TARGET_FULL = PREFIX + ".fullBuildTarget"; private static final String BUILD_TARGET_FULL = PREFIX + ".fullBuildTarget";
public static final String BUILD_FULL_ENABLED = PREFIX + ".enableFullBuild"; private static final String BUILD_FULL_ENABLED = PREFIX + ".enableFullBuild";
public static final String BUILD_INCREMENTAL_ENABLED = PREFIX + ".enabledIncrementalBuild"; private static final String BUILD_INCREMENTAL_ENABLED = PREFIX + ".enabledIncrementalBuild";
public static final String BUILD_AUTO_ENABLED = PREFIX + ".enableAutoBuild"; private static final String BUILD_AUTO_ENABLED = PREFIX + ".enableAutoBuild";
public static final String BUILD_ARGUMENTS = PREFIX + ".buildArguments"; private static final String BUILD_ARGUMENTS = PREFIX + ".buildArguments";
public abstract static class Store implements IMakeBuilderInfo, IScannerInfo { private abstract static class Store implements IMakeBuilderInfo, IScannerInfo {
// List of include paths // List of include paths
protected List pathList; protected List pathList;
protected List symbolList; protected List symbolList;
public void setUseDefaultBuildCmd(boolean on) { public void setUseDefaultBuildCmd(boolean on) throws CoreException {
putValue(USE_DEFAULT_BUILD_CMD, new Boolean(on).toString()); putValue(USE_DEFAULT_BUILD_CMD, new Boolean(on).toString());
} }
@ -61,7 +63,7 @@ public class BuildInfoFactory {
return getBoolean(USE_DEFAULT_BUILD_CMD); return getBoolean(USE_DEFAULT_BUILD_CMD);
} }
public void setBuildCommand(IPath location) { public void setBuildCommand(IPath location) throws CoreException {
putValue(BUILD_COMMAND, location.toString()); putValue(BUILD_COMMAND, location.toString());
} }
@ -100,7 +102,7 @@ public class BuildInfoFactory {
protected abstract String getBuilderID(); protected abstract String getBuilderID();
public void setBuildLocation(IPath location) { public void setBuildLocation(IPath location) throws CoreException {
putValue(BUILD_LOCATION, location.toString()); putValue(BUILD_LOCATION, location.toString());
} }
@ -109,7 +111,7 @@ public class BuildInfoFactory {
return new Path(location == null ? "" : location); return new Path(location == null ? "" : location);
} }
public void setStopOnError(boolean enabled) { public void setStopOnError(boolean enabled) throws CoreException {
putValue(STOP_ON_ERROR, new Boolean(enabled).toString()); putValue(STOP_ON_ERROR, new Boolean(enabled).toString());
} }
@ -117,7 +119,7 @@ public class BuildInfoFactory {
return getBoolean(STOP_ON_ERROR); return getBoolean(STOP_ON_ERROR);
} }
public void setAutoBuildTarget(String target) { public void setAutoBuildTarget(String target) throws CoreException {
putValue(BUILD_TARGET_AUTO, target); putValue(BUILD_TARGET_AUTO, target);
} }
@ -125,7 +127,7 @@ public class BuildInfoFactory {
return getString(BUILD_TARGET_AUTO); return getString(BUILD_TARGET_AUTO);
} }
public void setIncrementalBuildTarget(String target) { public void setIncrementalBuildTarget(String target) throws CoreException {
putValue(BUILD_TARGET_INCREMENTAL, target); putValue(BUILD_TARGET_INCREMENTAL, target);
} }
@ -133,7 +135,7 @@ public class BuildInfoFactory {
return getString(BUILD_TARGET_INCREMENTAL); return getString(BUILD_TARGET_INCREMENTAL);
} }
public void setFullBuildTarget(String target) { public void setFullBuildTarget(String target) throws CoreException {
putValue(BUILD_TARGET_FULL, target); putValue(BUILD_TARGET_FULL, target);
} }
@ -157,7 +159,7 @@ public class BuildInfoFactory {
* @see org.eclipse.cdt.core.build.managed.IScannerInfo#getIncludePaths() * @see org.eclipse.cdt.core.build.managed.IScannerInfo#getIncludePaths()
*/ */
public String[] getIncludePaths() { public String[] getIncludePaths() {
return (String[]) getPathList().toArray(new String[getPathList().size()]); return (String[])getPathList().toArray(new String[getPathList().size()]);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -194,7 +196,7 @@ public class BuildInfoFactory {
} }
public String[] getPreprocessorSymbols() { public String[] getPreprocessorSymbols() {
return (String[]) getSymbolList().toArray(new String[getSymbolList().size()]); return (String[])getSymbolList().toArray(new String[getSymbolList().size()]);
} }
protected List getSymbolList() { protected List getSymbolList() {
@ -208,10 +210,10 @@ public class BuildInfoFactory {
return Boolean.valueOf(getString(property)).booleanValue(); return Boolean.valueOf(getString(property)).booleanValue();
} }
public abstract void putValue(String name, String value); public abstract void putValue(String name, String value) throws CoreException;
public abstract String getString(String property); public abstract String getString(String property);
public void setAutoBuildEnable(boolean enabled) { public void setAutoBuildEnable(boolean enabled) throws CoreException {
putValue(BUILD_AUTO_ENABLED, new Boolean(enabled).toString()); putValue(BUILD_AUTO_ENABLED, new Boolean(enabled).toString());
} }
@ -219,7 +221,7 @@ public class BuildInfoFactory {
return getBoolean(BUILD_AUTO_ENABLED); return getBoolean(BUILD_AUTO_ENABLED);
} }
public void setIncrementalBuildEnable(boolean enabled) { public void setIncrementalBuildEnable(boolean enabled) throws CoreException {
putValue(BUILD_INCREMENTAL_ENABLED, new Boolean(enabled).toString()); putValue(BUILD_INCREMENTAL_ENABLED, new Boolean(enabled).toString());
} }
@ -227,7 +229,7 @@ public class BuildInfoFactory {
return getBoolean(BUILD_INCREMENTAL_ENABLED); return getBoolean(BUILD_INCREMENTAL_ENABLED);
} }
public void setFullBuildEnable(boolean enabled) { public void setFullBuildEnable(boolean enabled) throws CoreException {
putValue(BUILD_FULL_ENABLED, new Boolean(enabled).toString()); putValue(BUILD_FULL_ENABLED, new Boolean(enabled).toString());
} }
@ -239,65 +241,69 @@ public class BuildInfoFactory {
return getString(BUILD_ARGUMENTS); return getString(BUILD_ARGUMENTS);
} }
public void setBuildArguments(String args) { public void setBuildArguments(String args) throws CoreException {
putValue(BUILD_ARGUMENTS, args); putValue(BUILD_ARGUMENTS, args);
} }
} }
public static class Preference extends Store { private static class Preference extends Store {
private Preferences prefs; private Preferences prefs;
private String builderID; private String builderID;
private boolean useDefaults;
public Preference(Preferences prefs, String builderID) { public Preference(Preferences prefs, String builderID, boolean useDefaults) {
this.prefs = prefs; this.prefs = prefs;
this.builderID = builderID; this.builderID = builderID;
this.useDefaults = useDefaults;
} }
public void putValue(String name, String value) { public void putValue(String name, String value) {
prefs.setValue(name, value); if (useDefaults) {
prefs.setDefault(name, value);
} else {
prefs.setValue(name, value);
}
} }
public String getString(String property) { public String getString(String property) {
if (useDefaults) {
return prefs.getDefaultString(property);
}
return prefs.getString(property); return prefs.getString(property);
} }
public void setDefault(String name, String value) {
prefs.setDefault(name, value);
}
protected String getBuilderID() { protected String getBuilderID() {
return builderID; return builderID;
} }
} }
public static class BuildProperty extends Store { private static class BuildProperty extends Store {
private IProject project; private IProject project;
private String builderID; private String builderID;
private Map args;
public BuildProperty(IProject project, String builderID) {
public BuildProperty(IProject project, String builderID) throws CoreException {
this.project = project; this.project = project;
this.builderID = builderID; this.builderID = builderID;
ICommand builder;
builder = MakeProjectNature.getBuildSpec(project, builderID);
if (builder == null) {
throw new CoreException(
new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, "Missing Builder: " + builderID, null));
}
args = builder.getArguments();
} }
public void putValue(String name, String value) { public void putValue(String name, String value) throws CoreException {
try { ICommand builder = MakeProjectNature.getBuildSpec(project, builderID);
ICommand builder = MakeProjectNature.getBuildSpec(project); args.put(name, value);
Map args = builder.getArguments(); builder.setArguments(args);
args.put(name, value); project.setDescription(project.getDescription(), null);
builder.setArguments(args);
} catch (CoreException e) {
}
} }
public String getString(String name) { public String getString(String name) {
ICommand builder; String value = (String)args.get(name);
try { return value == null ? "" : value;
builder = MakeProjectNature.getBuildSpec(project);
Map args = builder.getArguments();
return (String) args.get(name);
} catch (CoreException e) {
}
return null;
} }
public String getBuilderID() { public String getBuilderID() {
@ -305,7 +311,7 @@ public class BuildInfoFactory {
} }
} }
public static class BuildArguments extends Store { private static class BuildArguments extends Store {
private Map args; private Map args;
private String builderID; private String builderID;
@ -315,10 +321,11 @@ public class BuildInfoFactory {
} }
public void putValue(String name, String value) { public void putValue(String name, String value) {
args.put(name, value);
} }
public String getString(String name) { public String getString(String name) {
return (String) args.get(name); return (String)args.get(name);
} }
public String getBuilderID() { public String getBuilderID() {
@ -326,28 +333,15 @@ public class BuildInfoFactory {
} }
} }
public static IMakeBuilderInfo create(Preferences prefs, String builderID) { public static IMakeBuilderInfo create(Preferences prefs, String builderID, boolean useDefaults) {
return new BuildInfoFactory.Preference(prefs, builderID); return new BuildInfoFactory.Preference(prefs, builderID, useDefaults);
} }
public static IMakeBuilderInfo create(IProject project, String builderID) { public static IMakeBuilderInfo create(IProject project, String builderID) throws CoreException {
return new BuildInfoFactory.BuildProperty(project, builderID); return new BuildInfoFactory.BuildProperty(project, builderID);
} }
public static IMakeBuilderInfo create(Map args, String builderID) { public static IMakeBuilderInfo create(Map args, String builderID) {
return new BuildInfoFactory.BuildArguments(args, builderID); return new BuildInfoFactory.BuildArguments(args, builderID);
} }
public static void initializeDefaultPreferences(Preferences prefs) {
prefs.setDefault(BUILD_COMMAND, "make");
prefs.setDefault(BUILD_LOCATION, "");
prefs.setDefault(STOP_ON_ERROR, new Boolean(false).toString());
prefs.setDefault(USE_DEFAULT_BUILD_CMD, new Boolean(true).toString());
prefs.setDefault(BUILD_AUTO_ENABLED, new Boolean(false).toString());
prefs.setDefault(BUILD_FULL_ENABLED, new Boolean(true).toString());
prefs.setDefault(BUILD_INCREMENTAL_ENABLED, new Boolean(true).toString());
prefs.setDefault(BUILD_TARGET_AUTO, "all");
prefs.setDefault(BUILD_TARGET_INCREMENTAL, "all");
prefs.setDefault(BUILD_TARGET_FULL, "clean all");
}
} }

View file

@ -11,6 +11,7 @@ package org.eclipse.cdt.make.core;
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
***********************************************************************/ ***********************************************************************/
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
public interface IMakeBuilderInfo { public interface IMakeBuilderInfo {
@ -30,21 +31,20 @@ public interface IMakeBuilderInfo {
public String[] getPreprocessorSymbols(); public String[] getPreprocessorSymbols();
public String[] getIncludePaths(); public String[] getIncludePaths();
void setBuildLocation(IPath location); void setBuildLocation(IPath location) throws CoreException;
void setStopOnError(boolean on); void setStopOnError(boolean on) throws CoreException;
void setUseDefaultBuildCmd(boolean on); void setUseDefaultBuildCmd(boolean on) throws CoreException;
void setBuildCommand(IPath command); void setBuildCommand(IPath command) throws CoreException;
void setBuildArguments(String args); void setBuildArguments(String args) throws CoreException;
void setAutoBuildEnable(boolean enabled); void setAutoBuildEnable(boolean enabled) throws CoreException;
void setAutoBuildTarget(String target); void setAutoBuildTarget(String target) throws CoreException;
void setIncrementalBuildEnable(boolean enabled); void setIncrementalBuildEnable(boolean enabled) throws CoreException;
void setIncrementalBuildTarget(String target); void setIncrementalBuildTarget(String target) throws CoreException;
void setFullBuildEnable(boolean enabled); void setFullBuildEnable(boolean enabled) throws CoreException;
void setFullBuildTarget(String target); void setFullBuildTarget(String target) throws CoreException;
public void setPreprocessorSymbols(String[] symbols); public void setPreprocessorSymbols(String[] symbols);
public void setIncludePaths(String[] paths); public void setIncludePaths(String[] paths);
} }

View file

@ -58,28 +58,17 @@ public class MakeBuildManager extends AbstractCExtension implements IScannerInfo
private static IMakeBuilderInfo findBuildInfo(IResource resource, boolean create) throws CoreException { private static IMakeBuilderInfo findBuildInfo(IResource resource, boolean create) throws CoreException {
IMakeBuilderInfo buildInfo = null; IMakeBuilderInfo buildInfo = null;
// See if there's already one associated with the resource for this session // See if there's already one associated with the resource for this session
try { buildInfo = (IMakeBuilderInfo)resource.getSessionProperty(buildInfoProperty);
buildInfo = (IMakeBuilderInfo)resource.getSessionProperty(buildInfoProperty);
} catch (CoreException e) {
}
// Try to load one for the project // Try to load one for the project
if (buildInfo == null && resource instanceof IProject) { if (buildInfo == null && resource instanceof IProject) {
try { buildInfo = loadBuildInfo((IProject)resource);
buildInfo = loadBuildInfo((IProject)resource);
} catch (CoreException e) {
}
} }
// There is nothing persisted for the session, or saved in a file so // There is nothing persisted for the session, or saved in a file so
// create a build info object // create a build info object
if (buildInfo == null && create) { if (buildInfo != null) {
buildInfo = BuildInfoFactory.create((IProject)resource, MakeBuilder.BUILDER_ID); ((IProject)resource).setSessionProperty(buildInfoProperty, buildInfo);
try {
((IProject)resource).setSessionProperty(buildInfoProperty, buildInfo);
} catch (CoreException e) {
buildInfo = null;
}
} }
return buildInfo; return buildInfo;
} }
@ -185,7 +174,6 @@ public class MakeBuildManager extends AbstractCExtension implements IScannerInfo
} }
buildInfo.setIncludePaths((String[]) includes.toArray(new String[includes.size()])); buildInfo.setIncludePaths((String[]) includes.toArray(new String[includes.size()]));
buildInfo.setPreprocessorSymbols((String[]) symbols.toArray(new String[symbols.size()])); buildInfo.setPreprocessorSymbols((String[]) symbols.toArray(new String[symbols.size()]));
project.setSessionProperty(buildInfoProperty, buildInfo);
return buildInfo; return buildInfo;
} }

View file

@ -16,7 +16,9 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPluginDescriptor; import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Plugin;
/** /**
@ -81,8 +83,22 @@ public class MakeCorePlugin extends Plugin {
} }
return getDefault().getDescriptor().getUniqueIdentifier(); return getDefault().getDescriptor().getUniqueIdentifier();
} }
protected void initializeDefaultPluginPreferences() { protected void initializeDefaultPluginPreferences() {
BuildInfoFactory.initializeDefaultPreferences(getPluginPreferences()); IMakeBuilderInfo info = BuildInfoFactory.create(getPluginPreferences(), MakeBuilder.BUILDER_ID, true);
try {
info.setBuildCommand(new Path("make"));
info.setBuildLocation(new Path(""));
info.setStopOnError(false);
info.setUseDefaultBuildCmd(true);
info.setAutoBuildEnable(false);
info.setAutoBuildTarget("all");
info.setIncrementalBuildEnable(true);
info.setIncrementalBuildTarget("all");
info.setFullBuildEnable(true);
info.setFullBuildTarget("clean all");
} catch (CoreException e) {
}
getPluginPreferences().setDefault(CCorePlugin.PREF_BINARY_PARSER, CCorePlugin.PLUGIN_ID + ".ELF"); getPluginPreferences().setDefault(CCorePlugin.PREF_BINARY_PARSER, CCorePlugin.PLUGIN_ID + ".ELF");
} }
} }

View file

@ -39,21 +39,17 @@ public class MakeProjectNature implements IProjectNature {
project.setDescription(description, monitor); project.setDescription(description, monitor);
} }
public static ICommand getBuildSpec(IProject project) throws CoreException { public static ICommand getBuildSpec(IProject project, String builderID) throws CoreException {
IProjectDescription description = project.getDescription(); IProjectDescription description = project.getDescription();
ICommand[] commands = description.getBuildSpec(); ICommand[] commands = description.getBuildSpec();
for (int i = 0; i < commands.length; ++i) { for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(MakeBuilder.BUILDER_ID)) { if (commands[i].getBuilderName().equals(builderID)) {
return commands[i]; return commands[i];
} }
} }
return null; return null;
} }
public void addToBuildSpec(String builderID, IProgressMonitor mon) throws CoreException {
addToBuildSpec(getProject(), builderID, mon);
}
/** /**
* Adds a builder to the build spec for the given project. * Adds a builder to the build spec for the given project.
*/ */
@ -79,15 +75,11 @@ public class MakeProjectNature implements IProjectNature {
} }
} }
public void removeBuildSpec(IProgressMonitor mon) throws CoreException {
removeFromBuildSpec(MakeBuilder.BUILDER_ID, mon);
}
/** /**
* Removes the given builder from the build spec for the given project. * Removes the given builder from the build spec for the given project.
*/ */
public void removeFromBuildSpec(String builderID, IProgressMonitor mon) throws CoreException { public static void removeFromBuildSpec(IProject project, String builderID, IProgressMonitor mon) throws CoreException {
IProjectDescription description = getProject().getDescription(); IProjectDescription description = project.getDescription();
ICommand[] commands = description.getBuildSpec(); ICommand[] commands = description.getBuildSpec();
for (int i = 0; i < commands.length; ++i) { for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(builderID)) { if (commands[i].getBuilderName().equals(builderID)) {
@ -98,15 +90,19 @@ public class MakeProjectNature implements IProjectNature {
break; break;
} }
} }
getProject().setDescription(description, mon); project.setDescription(description, mon);
}
public void addBuildSpec() throws CoreException {
addToBuildSpec(getProject(), MakeBuilder.BUILDER_ID, null);
} }
/** /**
* @see IProjectNature#configure * @see IProjectNature#configure
*/ */
public void configure() throws CoreException { public void configure() throws CoreException {
addToBuildSpec(MakeBuilder.BUILDER_ID, null); addBuildSpec();
IMakeBuilderInfo info = BuildInfoFactory.create(MakeCorePlugin.getDefault().getPluginPreferences(), MakeBuilder.BUILDER_ID); IMakeBuilderInfo info = BuildInfoFactory.create(MakeCorePlugin.getDefault().getPluginPreferences(), MakeBuilder.BUILDER_ID, false);
fBuildInfo.setBuildLocation(info.getBuildLocation()); fBuildInfo.setBuildLocation(info.getBuildLocation());
@ -124,11 +120,15 @@ public class MakeProjectNature implements IProjectNature {
fBuildInfo.setFullBuildTarget(info.getFullBuildTarget()); fBuildInfo.setFullBuildTarget(info.getFullBuildTarget());
} }
public void removeBuildSpec() throws CoreException {
removeFromBuildSpec(getProject(), MakeBuilder.BUILDER_ID, null);
}
/** /**
* @see IProjectNature#deconfigure * @see IProjectNature#deconfigure
*/ */
public void deconfigure() throws CoreException { public void deconfigure() throws CoreException {
removeFromBuildSpec(MakeBuilder.BUILDER_ID, null); removeBuildSpec();
} }
/** /**
@ -148,5 +148,4 @@ public class MakeProjectNature implements IProjectNature {
} catch (CoreException e) { } catch (CoreException e) {
} }
} }
} }

View file

@ -268,6 +268,7 @@ public class BuildPathInfoBlock extends AbstractCOptionPage {
if (getContainer().getProject() != null) { if (getContainer().getProject() != null) {
// dinglis-TODO: set list to preference settings // dinglis-TODO: set list to preference settings
} }
getContainer().updateContainer();
} }
/* /*
@ -363,8 +364,6 @@ public class BuildPathInfoBlock extends AbstractCOptionPage {
* @see org.eclipse.cdt.ui.wizards.IWizardTab#getControl(org.eclipse.swt.widgets.Composite) * @see org.eclipse.cdt.ui.wizards.IWizardTab#getControl(org.eclipse.swt.widgets.Composite)
*/ */
public void createControl(Composite parent) { public void createControl(Composite parent) {
this.shell = parent.getShell();
// Create the composite control for the tab // Create the composite control for the tab
int tabColumns = 3; int tabColumns = 3;
Font font = parent.getFont(); Font font = parent.getFont();

View file

@ -21,7 +21,6 @@ import org.eclipse.core.runtime.Preferences;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Button;
@ -31,6 +30,7 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
public class SettingsBlock extends AbstractCOptionPage { public class SettingsBlock extends AbstractCOptionPage {
@ -60,22 +60,22 @@ public class SettingsBlock extends AbstractCOptionPage {
private static final String KEEP_ARG = "keep"; //$NON-NLS-1$ private static final String KEEP_ARG = "keep"; //$NON-NLS-1$
private static final String STOP_ARG = "stop"; //$NON-NLS-1$ private static final String STOP_ARG = "stop"; //$NON-NLS-1$
protected RadioButtonsArea stopRadioButtons; private RadioButtonsArea stopRadioButtons;
protected Button defButton; private Button defButton;
protected Text cmdText; private Text buildCommand;
protected Text makeDirText; private Text buildLocation;
private Text targetFull; private Text targetFull;
private Text targetIncr; private Text targetIncr;
private Text targetAuto; private Text targetAuto;
private Button fFullButton; private Button fullButton;
private Button fIncrButton; private Button incrButton;
private Button fAutoButton; private Button autoButton;
private IMakeBuilderInfo fBuildInfo; private IMakeBuilderInfo fBuildInfo;
private Preferences fPrefs; private Preferences fPrefs;
private String fBuilderID; private String fBuilderID;
public SettingsBlock(Preferences prefs, String builderID) { public SettingsBlock(Preferences prefs, String builderID) {
super(MakeUIPlugin.getResourceString(MAKE_LABEL)); super(MakeUIPlugin.getResourceString(MAKE_LABEL));
setDescription(MakeUIPlugin.getResourceString(MAKE_MESSAGE)); setDescription(MakeUIPlugin.getResourceString(MAKE_MESSAGE));
@ -110,11 +110,11 @@ public class SettingsBlock extends AbstractCOptionPage {
defButton.addSelectionListener(new SelectionAdapter() { defButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
if (defButton.getSelection() == true) { if (defButton.getSelection() == true) {
cmdText.setEnabled(false); buildCommand.setEnabled(false);
stopRadioButtons.setEnabled(true); stopRadioButtons.setEnabled(true);
getContainer().updateContainer(); getContainer().updateContainer();
} else { } else {
cmdText.setEnabled(true); buildCommand.setEnabled(true);
stopRadioButtons.setEnabled(false); stopRadioButtons.setEnabled(false);
getContainer().updateContainer(); getContainer().updateContainer();
} }
@ -126,25 +126,27 @@ public class SettingsBlock extends AbstractCOptionPage {
Label label = ControlFactory.createLabel(group, MakeUIPlugin.getResourceString(MAKE_CMD_LABEL)); Label label = ControlFactory.createLabel(group, MakeUIPlugin.getResourceString(MAKE_CMD_LABEL));
((GridData) (label.getLayoutData())).horizontalAlignment = GridData.BEGINNING; ((GridData) (label.getLayoutData())).horizontalAlignment = GridData.BEGINNING;
((GridData) (label.getLayoutData())).grabExcessHorizontalSpace = false; ((GridData) (label.getLayoutData())).grabExcessHorizontalSpace = false;
cmdText = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER); buildCommand = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER);
((GridData) (cmdText.getLayoutData())).horizontalAlignment = GridData.FILL; ((GridData) (buildCommand.getLayoutData())).horizontalAlignment = GridData.FILL;
((GridData) (cmdText.getLayoutData())).grabExcessHorizontalSpace = true; ((GridData) (buildCommand.getLayoutData())).grabExcessHorizontalSpace = true;
cmdText.addListener(SWT.Modify, new Listener() { buildCommand.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event e) { public void handleEvent(Event e) {
getContainer().updateContainer(); getContainer().updateContainer();
} }
}); });
if (fBuildInfo.getBuildCommand() != null) { if (fBuildInfo.getBuildCommand() != null) {
StringBuffer cmd = new StringBuffer(fBuildInfo.getBuildCommand().toOSString()); StringBuffer cmd = new StringBuffer(fBuildInfo.getBuildCommand().toOSString());
String args = fBuildInfo.getBuildArguments(); if (!fBuildInfo.isDefaultBuildCmd()) {
if ( args != null && !args.equals("")) { String args = fBuildInfo.getBuildArguments();
cmd.append(" "); if (args != null && !args.equals("")) {
cmd.append(args); cmd.append(" ");
cmd.append(args);
}
} }
cmdText.setText(cmd.toString()); buildCommand.setText(cmd.toString());
} }
if (fBuildInfo.isDefaultBuildCmd()) { if (fBuildInfo.isDefaultBuildCmd()) {
cmdText.setEnabled(false); buildCommand.setEnabled(false);
} else { } else {
stopRadioButtons.setEnabled(false); stopRadioButtons.setEnabled(false);
} }
@ -154,9 +156,9 @@ public class SettingsBlock extends AbstractCOptionPage {
protected void createWorkBenchBuildControls(Composite parent) { protected void createWorkBenchBuildControls(Composite parent) {
SelectionAdapter selectionAdapter = new SelectionAdapter() { SelectionAdapter selectionAdapter = new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
targetAuto.setEnabled(fAutoButton.getSelection()); targetAuto.setEnabled(autoButton.getSelection());
targetFull.setEnabled(fFullButton.getSelection()); targetFull.setEnabled(fullButton.getSelection());
targetIncr.setEnabled(fIncrButton.getSelection()); targetIncr.setEnabled(incrButton.getSelection());
getContainer().updateContainer(); getContainer().updateContainer();
} }
@ -171,23 +173,23 @@ public class SettingsBlock extends AbstractCOptionPage {
label.setText(MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_TYPE)); label.setText(MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_TYPE));
label = new Label(group, SWT.NONE); label = new Label(group, SWT.NONE);
label.setText(MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_TARGET)); label.setText(MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_TARGET));
fAutoButton = ControlFactory.createCheckBox(group, MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_AUTO)); autoButton = ControlFactory.createCheckBox(group, MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_AUTO));
fAutoButton.addSelectionListener(selectionAdapter); autoButton.addSelectionListener(selectionAdapter);
fAutoButton.setSelection(fBuildInfo.isAutoBuildEnable()); autoButton.setSelection(fBuildInfo.isAutoBuildEnable());
targetAuto = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER); targetAuto = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER);
targetAuto.setText(fBuildInfo.getAutoBuildTarget()); targetAuto.setText(fBuildInfo.getAutoBuildTarget());
((GridData) (targetAuto.getLayoutData())).horizontalAlignment = GridData.FILL; ((GridData) (targetAuto.getLayoutData())).horizontalAlignment = GridData.FILL;
((GridData) (targetAuto.getLayoutData())).grabExcessHorizontalSpace = true; ((GridData) (targetAuto.getLayoutData())).grabExcessHorizontalSpace = true;
fIncrButton = ControlFactory.createCheckBox(group, MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_INCR)); incrButton = ControlFactory.createCheckBox(group, MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_INCR));
fIncrButton.addSelectionListener(selectionAdapter); incrButton.addSelectionListener(selectionAdapter);
fIncrButton.setSelection(fBuildInfo.isIncrementalBuildEnabled()); incrButton.setSelection(fBuildInfo.isIncrementalBuildEnabled());
targetIncr = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER); targetIncr = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER);
targetIncr.setText(fBuildInfo.getIncrementalBuildTarget()); targetIncr.setText(fBuildInfo.getIncrementalBuildTarget());
((GridData) (targetIncr.getLayoutData())).horizontalAlignment = GridData.FILL; ((GridData) (targetIncr.getLayoutData())).horizontalAlignment = GridData.FILL;
((GridData) (targetIncr.getLayoutData())).grabExcessHorizontalSpace = true; ((GridData) (targetIncr.getLayoutData())).grabExcessHorizontalSpace = true;
fFullButton = ControlFactory.createCheckBox(group, MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_FULL)); fullButton = ControlFactory.createCheckBox(group, MakeUIPlugin.getResourceString(MAKE_WORKBENCH_BUILD_FULL));
fFullButton.addSelectionListener(selectionAdapter); fullButton.addSelectionListener(selectionAdapter);
fFullButton.setSelection(fBuildInfo.isFullBuildEnabled()); fullButton.setSelection(fBuildInfo.isFullBuildEnabled());
targetFull = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER); targetFull = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER);
targetFull.setText(fBuildInfo.getFullBuildTarget()); targetFull.setText(fBuildInfo.getFullBuildTarget());
((GridData) (targetFull.getLayoutData())).horizontalAlignment = GridData.FILL; ((GridData) (targetFull.getLayoutData())).horizontalAlignment = GridData.FILL;
@ -205,28 +207,38 @@ public class SettingsBlock extends AbstractCOptionPage {
Label label = ControlFactory.createLabel(group, MakeUIPlugin.getResourceString(MAKE_BUILD_DIR_LABEL)); Label label = ControlFactory.createLabel(group, MakeUIPlugin.getResourceString(MAKE_BUILD_DIR_LABEL));
((GridData) (label.getLayoutData())).horizontalAlignment = GridData.BEGINNING; ((GridData) (label.getLayoutData())).horizontalAlignment = GridData.BEGINNING;
((GridData) (label.getLayoutData())).grabExcessHorizontalSpace = false; ((GridData) (label.getLayoutData())).grabExcessHorizontalSpace = false;
makeDirText = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER); buildLocation = ControlFactory.createTextField(group, SWT.SINGLE | SWT.BORDER);
((GridData) (makeDirText.getLayoutData())).horizontalAlignment = GridData.FILL; ((GridData) (buildLocation.getLayoutData())).horizontalAlignment = GridData.FILL;
((GridData) (makeDirText.getLayoutData())).grabExcessHorizontalSpace = true; ((GridData) (buildLocation.getLayoutData())).grabExcessHorizontalSpace = true;
makeDirText.addListener(SWT.Modify, new Listener() { buildLocation.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event e) { public void handleEvent(Event e) {
getContainer().updateContainer(); getContainer().updateContainer();
} }
}); });
Button browse = new Button(group, SWT.NONE); Button browse = new Button(group, SWT.NONE);
browse.setText(MakeUIPlugin.getResourceString(MAKE_BUILD_DIR_BROWSE)); browse.setText(MakeUIPlugin.getResourceString(MAKE_BUILD_DIR_BROWSE));
browse.addSelectionListener(new SelectionListener() { browse.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) { public void widgetSelected(SelectionEvent e) {
ContainerSelectionDialog dialog =
new ContainerSelectionDialog(getShell(), getContainer().getProject(), false, null);
dialog.open();
Object[] result = dialog.getResult();
} }
}); });
makeDirText.setText(fBuildInfo.getBuildLocation().toOSString()); buildLocation.setText(fBuildInfo.getBuildLocation().toOSString());
} }
public void createControl(Composite parent) { public void createControl(Composite parent) {
Composite composite = ControlFactory.createComposite(parent, 1); Composite composite = ControlFactory.createComposite(parent, 1);
setControl(composite);
if (fBuildInfo == null) {
ControlFactory.createEmptySpace(composite);
ControlFactory.createLabel(composite, "Missing builder information on project.");
return;
}
createSettingControls(composite); createSettingControls(composite);
createBuildCmdControls(composite); createBuildCmdControls(composite);
createWorkBenchBuildControls(composite); createWorkBenchBuildControls(composite);
@ -234,12 +246,10 @@ public class SettingsBlock extends AbstractCOptionPage {
if (getContainer().getProject() != null) { if (getContainer().getProject() != null) {
createBuilderWorkingDirControls(composite); createBuilderWorkingDirControls(composite);
} }
setControl(composite);
} }
public boolean isValid() { public boolean isValid() {
if (defButton.getSelection() != true) { if (defButton != null && defButton.getSelection() != true) {
String cmd = getBuildLine(); String cmd = getBuildLine();
if (cmd == null || cmd.length() == 0) { if (cmd == null || cmd.length() == 0) {
return false; return false;
@ -257,7 +267,7 @@ public class SettingsBlock extends AbstractCOptionPage {
if (getContainer().getProject() != null) { if (getContainer().getProject() != null) {
info = BuildInfoFactory.create(getContainer().getProject(), fBuilderID); info = BuildInfoFactory.create(getContainer().getProject(), fBuilderID);
} else { } else {
info = BuildInfoFactory.create(fPrefs, fBuilderID); info = BuildInfoFactory.create(fPrefs, fBuilderID, false);
} }
info.setStopOnError(isStopOnError()); info.setStopOnError(isStopOnError());
info.setUseDefaultBuildCmd(useDefaultBuildCmd()); info.setUseDefaultBuildCmd(useDefaultBuildCmd());
@ -284,13 +294,49 @@ public class SettingsBlock extends AbstractCOptionPage {
} }
info.setBuildArguments(args); info.setBuildArguments(args);
} }
info.setAutoBuildEnable(autoButton.getSelection());
info.setAutoBuildTarget(targetAuto.getText().trim());
info.setIncrementalBuildEnable(incrButton.getSelection());
info.setIncrementalBuildTarget(targetIncr.getText().trim());
info.setFullBuildEnable(fullButton.getSelection());
info.setFullBuildTarget(targetFull.getText().trim());
info.setBuildLocation(new Path(buildLocation.getText().trim()));
} }
public void performDefaults() { public void performDefaults() {
IMakeBuilderInfo info;
if (getContainer().getProject() != null) { if (getContainer().getProject() != null) {
info = BuildInfoFactory.create(fPrefs, fBuilderID, false);
} else { } else {
info = BuildInfoFactory.create(fPrefs, fBuilderID, true);
} }
if (info.isStopOnError())
stopRadioButtons.setSelectValue(STOP_ARG);
else
stopRadioButtons.setSelectValue(KEEP_ARG);
if (info.getBuildCommand() != null) {
StringBuffer cmd = new StringBuffer(info.getBuildCommand().toOSString());
if (!info.isDefaultBuildCmd()) {
String args = info.getBuildArguments();
if (args != null && !args.equals("")) {
cmd.append(" ");
cmd.append(args);
}
}
buildCommand.setText(cmd.toString());
}
if (info.isDefaultBuildCmd()) {
buildCommand.setEnabled(false);
} else {
stopRadioButtons.setEnabled(false);
}
defButton.setSelection(info.isDefaultBuildCmd());
autoButton.setSelection(info.isAutoBuildEnable());
targetAuto.setText(info.getAutoBuildTarget());
incrButton.setSelection(info.isIncrementalBuildEnabled());
targetIncr.setText(info.getIncrementalBuildTarget());
fullButton.setSelection(info.isFullBuildEnabled());
targetFull.setText(info.getFullBuildTarget());
} }
private boolean isStopOnError() { private boolean isStopOnError() {
@ -302,8 +348,8 @@ public class SettingsBlock extends AbstractCOptionPage {
} }
private String getBuildLine() { private String getBuildLine() {
if (cmdText != null) { if (buildCommand != null) {
String cmd = cmdText.getText(); String cmd = buildCommand.getText();
if (cmd != null) if (cmd != null)
return cmd.trim(); return cmd.trim();
} }
@ -313,14 +359,17 @@ public class SettingsBlock extends AbstractCOptionPage {
public void setContainer(ICOptionContainer container) { public void setContainer(ICOptionContainer container) {
super.setContainer(container); super.setContainer(container);
if (getContainer().getProject() != null) { if (getContainer().getProject() != null) {
fBuildInfo = BuildInfoFactory.create(getContainer().getProject(), fBuilderID); try {
fBuildInfo = BuildInfoFactory.create(getContainer().getProject(), fBuilderID);
} catch (CoreException e) {
}
} else { } else {
fBuildInfo = BuildInfoFactory.create(fPrefs, fBuilderID); fBuildInfo = BuildInfoFactory.create(fPrefs, fBuilderID, false);
} }
} }
public String getErrorMessage() { public String getErrorMessage() {
if (defButton.getSelection() != true) { if (!useDefaultBuildCmd()) {
String cmd = getBuildLine(); String cmd = getBuildLine();
if (cmd == null || cmd.length() == 0) { if (cmd == null || cmd.length() == 0) {
return "Must enter a build command"; return "Must enter a build command";