1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 07:25:23 +02:00

added clean build option

fixed make target with no target
This commit is contained in:
David Inglis 2004-03-31 21:45:57 +00:00
parent affd1175f1
commit d8a96ca65d
8 changed files with 122 additions and 33 deletions

View file

@ -15,7 +15,6 @@
<requires> <requires>
<import plugin="org.eclipse.core.resources"/> <import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.cdt.core"/> <import plugin="org.eclipse.cdt.core"/>
<import plugin="org.apache.xerces"/>
<import plugin="org.eclipse.core.runtime.compatibility"/> <import plugin="org.eclipse.core.runtime.compatibility"/>
</requires> </requires>
@ -69,8 +68,8 @@
name="%makeproject.name" name="%makeproject.name"
point="org.eclipse.cdt.core.CProject"> point="org.eclipse.cdt.core.CProject">
<cproject <cproject
natureID="org.eclipse.cdt.make.core.makeNature" class="org.eclipse.cdt.make.internal.core.MakeProject"
class="org.eclipse.cdt.make.internal.core.MakeProject"> natureID="org.eclipse.cdt.make.core.makeNature">
</cproject> </cproject>
</extension> </extension>
<extension <extension

View file

@ -49,6 +49,12 @@ public interface IMakeBuilderInfo {
String getFullBuildTarget(); String getFullBuildTarget();
void setFullBuildTarget(String target) throws CoreException; void setFullBuildTarget(String target) throws CoreException;
String getCleanBuildTarget();
void setCleanBuildTarget(String target) throws CoreException;
boolean isCleanBuildEnabled();
void setCleanBuildEnable(boolean enabled) throws CoreException;
String[] getErrorParsers(); String[] getErrorParsers();
void setErrorParsers(String[] parsers) throws CoreException; void setErrorParsers(String[] parsers) throws CoreException;

View file

@ -36,10 +36,13 @@ import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
public class MakeBuilder extends ACBuilder { public class MakeBuilder extends ACBuilder {
@ -97,7 +100,29 @@ public class MakeBuilder extends ACBuilder {
return getProject().getReferencedProjects(); return getProject().getReferencedProjects();
} }
private boolean invokeMake(int kind, IMakeBuilderInfo info, IProgressMonitor monitor) {
protected void clean(IProgressMonitor monitor) throws CoreException {
final IMakeBuilderInfo info = MakeCorePlugin.createBuildInfo(getProject(), BUILDER_ID);
if (shouldBuild(CLEAN_BUILD, info)) {
Job backgroundJob = new Job("Standard Make Builder"){ //$NON-NLS-1$
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
protected IStatus run(IProgressMonitor monitor) {
invokeMake(CLEAN_BUILD, info, monitor);
IStatus returnStatus = Status.OK_STATUS;
return returnStatus;
}
};
backgroundJob.setRule(getProject());
backgroundJob.schedule();
}
}
protected boolean invokeMake(int kind, IMakeBuilderInfo info, IProgressMonitor monitor) {
boolean isClean = false; boolean isClean = false;
IProject currProject = getProject(); IProject currProject = getProject();
@ -128,7 +153,7 @@ public class MakeBuilder extends ACBuilder {
workingDirectory = currProject.getLocation(); workingDirectory = currProject.getLocation();
} }
String[] targets = getTargets(kind, info); String[] targets = getTargets(kind, info);
if (targets.length != 0 && targets[targets.length - 1].equals("clean")) //$NON-NLS-1$ if (targets.length != 0 && targets[targets.length - 1].equals(info.getCleanBuildTarget())) //$NON-NLS-1$
isClean = true; isClean = true;
String errMsg = null; String errMsg = null;
@ -257,6 +282,8 @@ public class MakeBuilder extends ACBuilder {
return info.isIncrementalBuildEnabled(); return info.isIncrementalBuildEnabled();
case IncrementalProjectBuilder.FULL_BUILD : case IncrementalProjectBuilder.FULL_BUILD :
return info.isFullBuildEnabled(); return info.isFullBuildEnabled();
case IncrementalProjectBuilder.CLEAN_BUILD :
return info.isCleanBuildEnabled();
} }
return true; return true;
} }
@ -273,6 +300,9 @@ public class MakeBuilder extends ACBuilder {
case IncrementalProjectBuilder.FULL_BUILD : case IncrementalProjectBuilder.FULL_BUILD :
targets = info.getFullBuildTarget(); targets = info.getFullBuildTarget();
break; break;
case IncrementalProjectBuilder.CLEAN_BUILD :
targets = info.getCleanBuildTarget();
break;
} }
return makeArray(targets); return makeArray(targets);
} }

View file

@ -145,6 +145,8 @@ public class MakeCorePlugin extends Plugin {
info.setIncrementalBuildTarget("all"); //$NON-NLS-1$ info.setIncrementalBuildTarget("all"); //$NON-NLS-1$
info.setFullBuildEnable(true); info.setFullBuildEnable(true);
info.setFullBuildTarget("clean all"); //$NON-NLS-1$ info.setFullBuildTarget("clean all"); //$NON-NLS-1$
info.setCleanBuildEnable(true);
info.setCleanBuildTarget("clean"); //$NON-NLS-1$
info.setErrorParsers(CCorePlugin.getDefault().getAllErrorParsersIDs()); info.setErrorParsers(CCorePlugin.getDefault().getAllErrorParsersIDs());
} catch (CoreException e) { } catch (CoreException e) {
} }

View file

@ -116,6 +116,8 @@ public class MakeProjectNature implements IProjectNature {
projectInfo.setFullBuildEnable(info.isFullBuildEnabled()); projectInfo.setFullBuildEnable(info.isFullBuildEnabled());
projectInfo.setFullBuildTarget(info.getFullBuildTarget()); projectInfo.setFullBuildTarget(info.getFullBuildTarget());
projectInfo.setCleanBuildEnable(info.isCleanBuildEnabled());
projectInfo.setCleanBuildTarget(info.getCleanBuildTarget());
projectInfo.setErrorParsers(info.getErrorParsers()); projectInfo.setErrorParsers(info.getErrorParsers());
} }

View file

@ -46,7 +46,9 @@ public class BuildInfoFactory {
static final String BUILD_TARGET_AUTO = PREFIX + ".autoBuildTarget"; //$NON-NLS-1$ static final String BUILD_TARGET_AUTO = PREFIX + ".autoBuildTarget"; //$NON-NLS-1$
static final String BUILD_TARGET_INCREMENTAL = PREFIX + ".incrementalBuildTarget"; //$NON-NLS-1$ static final String BUILD_TARGET_INCREMENTAL = PREFIX + ".incrementalBuildTarget"; //$NON-NLS-1$
static final String BUILD_TARGET_FULL = PREFIX + ".fullBuildTarget"; //$NON-NLS-1$ static final String BUILD_TARGET_FULL = PREFIX + ".fullBuildTarget"; //$NON-NLS-1$
static final String BUILD_TARGET_CLEAN = PREFIX + ".cleanBuildTarget"; //$NON-NLS-1$
static final String BUILD_FULL_ENABLED = PREFIX + ".enableFullBuild"; //$NON-NLS-1$ static final String BUILD_FULL_ENABLED = PREFIX + ".enableFullBuild"; //$NON-NLS-1$
static final String BUILD_CLEAN_ENABLED = PREFIX + ".enableCleanBuild"; //$NON-NLS-1$
static final String BUILD_INCREMENTAL_ENABLED = PREFIX + ".enabledIncrementalBuild"; //$NON-NLS-1$ static final String BUILD_INCREMENTAL_ENABLED = PREFIX + ".enabledIncrementalBuild"; //$NON-NLS-1$
static final String BUILD_AUTO_ENABLED = PREFIX + ".enableAutoBuild"; //$NON-NLS-1$ static final String BUILD_AUTO_ENABLED = PREFIX + ".enableAutoBuild"; //$NON-NLS-1$
static final String BUILD_ARGUMENTS = PREFIX + ".buildArguments"; //$NON-NLS-1$ static final String BUILD_ARGUMENTS = PREFIX + ".buildArguments"; //$NON-NLS-1$
@ -145,6 +147,14 @@ public class BuildInfoFactory {
return getString(BUILD_TARGET_FULL); return getString(BUILD_TARGET_FULL);
} }
public void setCleanBuildTarget(String target) throws CoreException {
putString(BUILD_TARGET_CLEAN, target);
}
public String getCleanBuildTarget() {
return getString(BUILD_TARGET_CLEAN);
}
public boolean getBoolean(String property) { public boolean getBoolean(String property) {
return Boolean.valueOf(getString(property)).booleanValue(); return Boolean.valueOf(getString(property)).booleanValue();
} }
@ -176,6 +186,14 @@ public class BuildInfoFactory {
return getBoolean(BUILD_FULL_ENABLED); return getBoolean(BUILD_FULL_ENABLED);
} }
public void setCleanBuildEnable(boolean enabled) throws CoreException {
putString(BUILD_CLEAN_ENABLED, new Boolean(enabled).toString());
}
public boolean isCleanBuildEnabled() {
return getBoolean(BUILD_CLEAN_ENABLED);
}
public String getBuildArguments() { public String getBuildArguments() {
return getString(BUILD_ARGUMENTS); return getString(BUILD_ARGUMENTS);
} }

View file

@ -143,6 +143,6 @@ public class MakeTarget implements IMakeTarget {
} }
public String getBuildTarget() { public String getBuildTarget() {
return target; return target != null ? target : ""; //$NON-NLS-1$
} }
} }

View file

@ -3,8 +3,10 @@ package org.eclipse.cdt.make.internal.core;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -13,6 +15,12 @@ import java.util.Map;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
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.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptor;
@ -45,7 +53,8 @@ public class ProjectTargets {
private static final String TARGET_USE_DEFAULT_CMD = "useDefaultCommand"; //$NON-NLS-1$ private static final String TARGET_USE_DEFAULT_CMD = "useDefaultCommand"; //$NON-NLS-1$
private static final String TARGET_ARGUMENTS = "buildArguments"; //$NON-NLS-1$ private static final String TARGET_ARGUMENTS = "buildArguments"; //$NON-NLS-1$
private static final String TARGET_COMMAND = "buildCommand"; //$NON-NLS-1$ private static final String TARGET_COMMAND = "buildCommand"; //$NON-NLS-1$
private static final String TARGET = "buidlTarget"; //$NON-NLS-1$ private static final String BAD_TARGET = "buidlTarget"; //$NON-NLS-1$
private static final String TARGET = "buildTarget"; //$NON-NLS-1$
private HashMap targetMap = new HashMap(); private HashMap targetMap = new HashMap();
@ -78,8 +87,9 @@ public class ProjectTargets {
extractMakeTargetsFromDocument(document, manager); extractMakeTargetsFromDocument(document, manager);
if (writeTargets) { if (writeTargets) {
try { try {
saveTargets(); Document doc = getAsXML();
} catch (IOException e) { translateDocumentToCDTProject(doc);
} catch (Exception e) {
targetFile = null; targetFile = null;
} }
if (targetFile != null) { if (targetFile != null) {
@ -192,13 +202,17 @@ public class ProjectTargets {
targetElem.appendChild(elem); targetElem.appendChild(elem);
elem.appendChild(doc.createTextNode(target.getBuildCommand().toString())); elem.appendChild(doc.createTextNode(target.getBuildCommand().toString()));
if (target.getBuildArguments().length() > 0) {
elem = doc.createElement(TARGET_ARGUMENTS); elem = doc.createElement(TARGET_ARGUMENTS);
elem.appendChild(doc.createTextNode(target.getBuildArguments())); elem.appendChild(doc.createTextNode(target.getBuildArguments()));
targetElem.appendChild(elem); targetElem.appendChild(elem);
}
if (target.getBuildTarget().length() > 0) {
elem = doc.createElement(TARGET); elem = doc.createElement(TARGET);
elem.appendChild(doc.createTextNode(target.getBuildTarget())); elem.appendChild(doc.createTextNode(target.getBuildTarget()));
targetElem.appendChild(elem); targetElem.appendChild(elem);
}
elem = doc.createElement(TARGET_STOP_ON_ERROR); elem = doc.createElement(TARGET_STOP_ON_ERROR);
elem.appendChild(doc.createTextNode(new Boolean(target.isStopOnError()).toString())); elem.appendChild(doc.createTextNode(new Boolean(target.isStopOnError()).toString()));
@ -211,19 +225,37 @@ public class ProjectTargets {
} }
public void saveTargets() throws IOException { public void saveTargets() throws IOException {
try {
Document doc = getAsXML(); Document doc = getAsXML();
//Historical method would save the output to the stream specified //Historical method would save the output to the stream specified
//translateDocumentToOutputStream(doc, output); //translateDocumentToOutputStream(doc, output);
try {
translateDocumentToCDTProject(doc); translateDocumentToCDTProject(doc);
} catch (CoreException ex) { } catch (Exception e) {
throw new IOException(ex.getMessage()); IPath targetFilePath = MakeCorePlugin.getDefault().getStateLocation().append(project.getName()).addFileExtension(
TARGETS_EXT);
File targetFile = targetFilePath.toFile();
try {
saveTargets(doc, new FileOutputStream(targetFile));
} catch (FileNotFoundException e1) {
} catch (IOException e1) {
} catch (TransformerException e1) {
}
} }
} }
protected void saveTargets(Document doc, OutputStream output) throws IOException, TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer;
transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
DOMSource source = new DOMSource(doc);
StreamResult outputTarget = new StreamResult(output);
transformer.transform(source, outputTarget);
}
/** /**
* This output method saves the information into the .cdtproject metadata * This output method saves the information into the .cdtproject metadata file.
* file.
* *
* @param doc * @param doc
* @throws IOException * @throws IOException
@ -254,8 +286,7 @@ public class ProjectTargets {
} }
/** /**
* This method parses the .cdtproject file for the XML document describing * This method parses the .cdtproject file for the XML document describing the build targets.
* the build targets.
* *
* @param input * @param input
* @return * @return
@ -274,21 +305,19 @@ public class ProjectTargets {
} catch (CoreException e) { } catch (CoreException e) {
return document; return document;
} }
Element element = rootElement.getOwnerDocument().getDocumentElement();
NodeList list = rootElement.getChildNodes(); NodeList list = rootElement.getChildNodes();
for (int i = 0; i < list.getLength(); i++) { for (int i = 0; i < list.getLength(); i++) {
if (list.item(i).getNodeType() == Node.ELEMENT_NODE) { if (list.item(i).getNodeType() == Node.ELEMENT_NODE) {
Node appendNode = document.importNode(list.item(i), true); Node appendNode = document.importNode(list.item(i), true);
document.appendChild(appendNode); document.appendChild(appendNode);
break; // show never have multiple <buildtargets> break; // should never have multiple <buildtargets>
} }
} }
return document; return document;
} }
/** /**
* This method parses the input stream for the XML document describing the * This method parses the input stream for the XML document describing the build targets.
* build targets.
* *
* @param input * @param input
* @return * @return
@ -304,8 +333,7 @@ public class ProjectTargets {
} }
/** /**
* Extract the make target information which is contained in the XML * Extract the make target information which is contained in the XML Document
* Document
* *
* @param document * @param document
*/ */
@ -344,6 +372,10 @@ public class ProjectTargets {
if (option != null) { if (option != null) {
target.setBuildArguments(option); target.setBuildArguments(option);
} }
option = getString(node, BAD_TARGET);
if (option != null) {
target.setBuildTarget(option);
}
option = getString(node, TARGET); option = getString(node, TARGET);
if (option != null) { if (option != null) {
target.setBuildTarget(option); target.setBuildTarget(option);