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:
parent
affd1175f1
commit
d8a96ca65d
8 changed files with 122 additions and 33 deletions
|
@ -15,7 +15,6 @@
|
|||
<requires>
|
||||
<import plugin="org.eclipse.core.resources"/>
|
||||
<import plugin="org.eclipse.cdt.core"/>
|
||||
<import plugin="org.apache.xerces"/>
|
||||
<import plugin="org.eclipse.core.runtime.compatibility"/>
|
||||
</requires>
|
||||
|
||||
|
@ -69,8 +68,8 @@
|
|||
name="%makeproject.name"
|
||||
point="org.eclipse.cdt.core.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>
|
||||
</extension>
|
||||
<extension
|
||||
|
|
|
@ -49,6 +49,12 @@ public interface IMakeBuilderInfo {
|
|||
String getFullBuildTarget();
|
||||
void setFullBuildTarget(String target) throws CoreException;
|
||||
|
||||
String getCleanBuildTarget();
|
||||
void setCleanBuildTarget(String target) throws CoreException;
|
||||
|
||||
boolean isCleanBuildEnabled();
|
||||
void setCleanBuildEnable(boolean enabled) throws CoreException;
|
||||
|
||||
String[] getErrorParsers();
|
||||
void setErrorParsers(String[] parsers) throws CoreException;
|
||||
|
||||
|
|
|
@ -36,10 +36,13 @@ import org.eclipse.core.resources.IncrementalProjectBuilder;
|
|||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
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.QualifiedName;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
|
||||
public class MakeBuilder extends ACBuilder {
|
||||
|
||||
|
@ -97,7 +100,29 @@ public class MakeBuilder extends ACBuilder {
|
|||
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;
|
||||
IProject currProject = getProject();
|
||||
|
||||
|
@ -128,7 +153,7 @@ public class MakeBuilder extends ACBuilder {
|
|||
workingDirectory = currProject.getLocation();
|
||||
}
|
||||
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;
|
||||
|
||||
String errMsg = null;
|
||||
|
@ -257,6 +282,8 @@ public class MakeBuilder extends ACBuilder {
|
|||
return info.isIncrementalBuildEnabled();
|
||||
case IncrementalProjectBuilder.FULL_BUILD :
|
||||
return info.isFullBuildEnabled();
|
||||
case IncrementalProjectBuilder.CLEAN_BUILD :
|
||||
return info.isCleanBuildEnabled();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -273,6 +300,9 @@ public class MakeBuilder extends ACBuilder {
|
|||
case IncrementalProjectBuilder.FULL_BUILD :
|
||||
targets = info.getFullBuildTarget();
|
||||
break;
|
||||
case IncrementalProjectBuilder.CLEAN_BUILD :
|
||||
targets = info.getCleanBuildTarget();
|
||||
break;
|
||||
}
|
||||
return makeArray(targets);
|
||||
}
|
||||
|
|
|
@ -145,6 +145,8 @@ public class MakeCorePlugin extends Plugin {
|
|||
info.setIncrementalBuildTarget("all"); //$NON-NLS-1$
|
||||
info.setFullBuildEnable(true);
|
||||
info.setFullBuildTarget("clean all"); //$NON-NLS-1$
|
||||
info.setCleanBuildEnable(true);
|
||||
info.setCleanBuildTarget("clean"); //$NON-NLS-1$
|
||||
info.setErrorParsers(CCorePlugin.getDefault().getAllErrorParsersIDs());
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
|
|
|
@ -116,6 +116,8 @@ public class MakeProjectNature implements IProjectNature {
|
|||
|
||||
projectInfo.setFullBuildEnable(info.isFullBuildEnabled());
|
||||
projectInfo.setFullBuildTarget(info.getFullBuildTarget());
|
||||
projectInfo.setCleanBuildEnable(info.isCleanBuildEnabled());
|
||||
projectInfo.setCleanBuildTarget(info.getCleanBuildTarget());
|
||||
projectInfo.setErrorParsers(info.getErrorParsers());
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,9 @@ public class BuildInfoFactory {
|
|||
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_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_CLEAN_ENABLED = PREFIX + ".enableCleanBuild"; //$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_ARGUMENTS = PREFIX + ".buildArguments"; //$NON-NLS-1$
|
||||
|
@ -145,6 +147,14 @@ public class BuildInfoFactory {
|
|||
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) {
|
||||
return Boolean.valueOf(getString(property)).booleanValue();
|
||||
}
|
||||
|
@ -176,6 +186,14 @@ public class BuildInfoFactory {
|
|||
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() {
|
||||
return getString(BUILD_ARGUMENTS);
|
||||
}
|
||||
|
|
|
@ -143,6 +143,6 @@ public class MakeTarget implements IMakeTarget {
|
|||
}
|
||||
|
||||
public String getBuildTarget() {
|
||||
return target;
|
||||
return target != null ? target : ""; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package org.eclipse.cdt.make.internal.core;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
@ -13,6 +15,12 @@ import java.util.Map;
|
|||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
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.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_ARGUMENTS = "buildArguments"; //$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();
|
||||
|
||||
|
@ -78,8 +87,9 @@ public class ProjectTargets {
|
|||
extractMakeTargetsFromDocument(document, manager);
|
||||
if (writeTargets) {
|
||||
try {
|
||||
saveTargets();
|
||||
} catch (IOException e) {
|
||||
Document doc = getAsXML();
|
||||
translateDocumentToCDTProject(doc);
|
||||
} catch (Exception e) {
|
||||
targetFile = null;
|
||||
}
|
||||
if (targetFile != null) {
|
||||
|
@ -192,13 +202,17 @@ public class ProjectTargets {
|
|||
targetElem.appendChild(elem);
|
||||
elem.appendChild(doc.createTextNode(target.getBuildCommand().toString()));
|
||||
|
||||
elem = doc.createElement(TARGET_ARGUMENTS);
|
||||
elem.appendChild(doc.createTextNode(target.getBuildArguments()));
|
||||
targetElem.appendChild(elem);
|
||||
if (target.getBuildArguments().length() > 0) {
|
||||
elem = doc.createElement(TARGET_ARGUMENTS);
|
||||
elem.appendChild(doc.createTextNode(target.getBuildArguments()));
|
||||
targetElem.appendChild(elem);
|
||||
}
|
||||
|
||||
elem = doc.createElement(TARGET);
|
||||
elem.appendChild(doc.createTextNode(target.getBuildTarget()));
|
||||
targetElem.appendChild(elem);
|
||||
if (target.getBuildTarget().length() > 0) {
|
||||
elem = doc.createElement(TARGET);
|
||||
elem.appendChild(doc.createTextNode(target.getBuildTarget()));
|
||||
targetElem.appendChild(elem);
|
||||
}
|
||||
|
||||
elem = doc.createElement(TARGET_STOP_ON_ERROR);
|
||||
elem.appendChild(doc.createTextNode(new Boolean(target.isStopOnError()).toString()));
|
||||
|
@ -211,19 +225,37 @@ public class ProjectTargets {
|
|||
}
|
||||
|
||||
public void saveTargets() throws IOException {
|
||||
Document doc = getAsXML();
|
||||
//Historical method would save the output to the stream specified
|
||||
//translateDocumentToOutputStream(doc, output);
|
||||
try {
|
||||
Document doc = getAsXML();
|
||||
//Historical method would save the output to the stream specified
|
||||
//translateDocumentToOutputStream(doc, output);
|
||||
translateDocumentToCDTProject(doc);
|
||||
} catch (CoreException ex) {
|
||||
throw new IOException(ex.getMessage());
|
||||
} catch (Exception e) {
|
||||
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
|
||||
* file.
|
||||
* This output method saves the information into the .cdtproject metadata file.
|
||||
*
|
||||
* @param doc
|
||||
* @throws IOException
|
||||
|
@ -254,8 +286,7 @@ public class ProjectTargets {
|
|||
}
|
||||
|
||||
/**
|
||||
* This method parses the .cdtproject file for the XML document describing
|
||||
* the build targets.
|
||||
* This method parses the .cdtproject file for the XML document describing the build targets.
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
|
@ -269,26 +300,24 @@ public class ProjectTargets {
|
|||
descriptor = CCorePlugin.getDefault().getCProjectDescription(getProject());
|
||||
|
||||
rootElement = descriptor.getProjectData(MAKE_TARGET_KEY);
|
||||
} catch ( ParserConfigurationException e) {
|
||||
} catch (ParserConfigurationException e) {
|
||||
return document;
|
||||
} catch ( CoreException e) {
|
||||
} catch (CoreException e) {
|
||||
return document;
|
||||
}
|
||||
Element element = rootElement.getOwnerDocument().getDocumentElement();
|
||||
NodeList list = rootElement.getChildNodes();
|
||||
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);
|
||||
document.appendChild(appendNode);
|
||||
break; // show never have multiple <buildtargets>
|
||||
break; // should never have multiple <buildtargets>
|
||||
}
|
||||
}
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method parses the input stream for the XML document describing the
|
||||
* build targets.
|
||||
* This method parses the input stream for the XML document describing the build targets.
|
||||
*
|
||||
* @param input
|
||||
* @return
|
||||
|
@ -304,8 +333,7 @@ public class ProjectTargets {
|
|||
}
|
||||
|
||||
/**
|
||||
* Extract the make target information which is contained in the XML
|
||||
* Document
|
||||
* Extract the make target information which is contained in the XML Document
|
||||
*
|
||||
* @param document
|
||||
*/
|
||||
|
@ -344,6 +372,10 @@ public class ProjectTargets {
|
|||
if (option != null) {
|
||||
target.setBuildArguments(option);
|
||||
}
|
||||
option = getString(node, BAD_TARGET);
|
||||
if (option != null) {
|
||||
target.setBuildTarget(option);
|
||||
}
|
||||
option = getString(node, TARGET);
|
||||
if (option != null) {
|
||||
target.setBuildTarget(option);
|
||||
|
|
Loading…
Add table
Reference in a new issue