mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
fixed auto builds so project that are not involved dont build
This commit is contained in:
parent
9fba9c63e0
commit
c35aafd192
3 changed files with 88 additions and 51 deletions
|
@ -1,3 +1,8 @@
|
|||
2002-11-20 David Inglis
|
||||
* src/.../internal/core/CBuilder.java
|
||||
fix AUTO_BUILDs so that the builder only builds when the resources change
|
||||
in the project.
|
||||
|
||||
2002-11-20 David Inglis
|
||||
* plugin.xml
|
||||
fixed bug #26640
|
||||
|
|
|
@ -21,7 +21,7 @@ public class ConsoleOutputStream extends OutputStream {
|
|||
}
|
||||
|
||||
|
||||
public String readBuffer() {
|
||||
public synchronized String readBuffer() {
|
||||
String buf = fBuffer.toString();
|
||||
fBuffer.setLength(0);
|
||||
return buf;
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.eclipse.cdt.core.resources.MakeUtil;
|
|||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IResourceDelta;
|
||||
import org.eclipse.core.resources.IResourceDeltaVisitor;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -33,63 +35,87 @@ import org.eclipse.core.runtime.OperationCanceledException;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
|
||||
|
||||
|
||||
public class CBuilder extends ACBuilder {
|
||||
|
||||
private static final String BUILD_ERROR= "CBuilder.build_error";
|
||||
|
||||
|
||||
private static final String BUILD_ERROR = "CBuilder.build_error";
|
||||
|
||||
public CBuilder() {
|
||||
}
|
||||
|
||||
public IPath getWorkingDirectory() {
|
||||
IProject currProject= getProject();
|
||||
IPath workingDirectory = new Path(MakeUtil.getSessionBuildDir((IResource)currProject));
|
||||
public IPath getWorkingDirectory() {
|
||||
IProject currProject = getProject();
|
||||
IPath workingDirectory = new Path(MakeUtil.getSessionBuildDir((IResource) currProject));
|
||||
if (workingDirectory.isEmpty())
|
||||
workingDirectory = currProject.getLocation();
|
||||
return workingDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
public class MyResourceDeltaVisitor implements IResourceDeltaVisitor {
|
||||
boolean bContinue;
|
||||
|
||||
public boolean visit(IResourceDelta delta) throws CoreException {
|
||||
IResource resource = delta.getResource();
|
||||
if (resource != null && resource.getProject() == getProject()) {
|
||||
bContinue = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean shouldBuild() {
|
||||
return bContinue;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @see IncrementalProjectBuilder#build
|
||||
*/
|
||||
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
|
||||
boolean isClean = invokeMake((kind == IncrementalProjectBuilder.FULL_BUILD), monitor);
|
||||
if ( isClean ) {
|
||||
forgetLastBuiltState();
|
||||
*/
|
||||
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
|
||||
boolean bPerformBuild = true;
|
||||
if (kind == IncrementalProjectBuilder.AUTO_BUILD) {
|
||||
MyResourceDeltaVisitor vis = new MyResourceDeltaVisitor();
|
||||
IResourceDelta delta = getDelta(getProject());
|
||||
if (delta != null ) {
|
||||
delta.accept(vis);
|
||||
bPerformBuild = vis.shouldBuild();
|
||||
} else
|
||||
bPerformBuild = false;
|
||||
}
|
||||
if ( bPerformBuild ) {
|
||||
boolean isClean = invokeMake((kind == IncrementalProjectBuilder.FULL_BUILD), monitor);
|
||||
if (isClean) {
|
||||
forgetLastBuiltState();
|
||||
}
|
||||
}
|
||||
checkCancel(monitor);
|
||||
return getProject().getReferencedProjects();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean invokeMake(boolean fullBuild, IProgressMonitor monitor) {
|
||||
boolean isClean = false;
|
||||
boolean fatalBuild = false;
|
||||
boolean isCanceled = false;
|
||||
IProject currProject= getProject();
|
||||
IProject currProject = getProject();
|
||||
SubProgressMonitor subMonitor = null;
|
||||
|
||||
if (monitor == null) {
|
||||
monitor= new NullProgressMonitor();
|
||||
monitor = new NullProgressMonitor();
|
||||
}
|
||||
monitor.beginTask("Invoking the C Builder: " + currProject.getName(), IProgressMonitor.UNKNOWN);
|
||||
|
||||
try {
|
||||
CProjectNature nature= (CProjectNature)currProject.getNature(CProjectNature.C_NATURE_ID);
|
||||
IPath makepath= nature.getBuildCommand();
|
||||
CProjectNature nature = (CProjectNature) currProject.getNature(CProjectNature.C_NATURE_ID);
|
||||
IPath makepath = nature.getBuildCommand();
|
||||
if (!makepath.isEmpty()) {
|
||||
IConsole console = CCorePlugin.getDefault().getConsole();
|
||||
console.start(currProject);
|
||||
|
||||
ConsoleOutputStream cos = console.getOutputStream();
|
||||
|
||||
|
||||
// remove all markers for this project
|
||||
removeAllMarkers(currProject);
|
||||
|
||||
IPath workingDirectory= getWorkingDirectory();
|
||||
String[] userArgs= parseArguments(fullBuild, nature.getIncrBuildArguments());
|
||||
if ( userArgs.length != 0 && userArgs[userArgs.length-1].equals("clean") )
|
||||
IPath workingDirectory = getWorkingDirectory();
|
||||
String[] userArgs = parseArguments(fullBuild, nature.getIncrBuildArguments());
|
||||
if (userArgs.length != 0 && userArgs[userArgs.length - 1].equals("clean"))
|
||||
isClean = true;
|
||||
// Before launching give visual cues via the monitor
|
||||
subMonitor = new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN);
|
||||
|
@ -104,23 +130,23 @@ public class CBuilder extends ACBuilder {
|
|||
Properties props = launcher.getEnvironment();
|
||||
props.put("CWD", workingDirectory.toOSString());
|
||||
props.put("PWD", workingDirectory.toOSString());
|
||||
String[] env= null;
|
||||
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));
|
||||
String key = (String) names.nextElement();
|
||||
envList.add(key + "=" + props.getProperty(key));
|
||||
}
|
||||
env = (String []) envList.toArray(new String [envList.size()]);
|
||||
env = (String[]) envList.toArray(new String[envList.size()]);
|
||||
}
|
||||
ErrorParserManager epm= new ErrorParserManager(this);
|
||||
ErrorParserManager epm = new ErrorParserManager(this);
|
||||
epm.setOutputStream(cos);
|
||||
|
||||
|
||||
launcher.execute(makepath, userArgs, env, workingDirectory);
|
||||
if (launcher.waitAndRead(epm.getOutputStream(), epm.getOutputStream(), subMonitor) != CommandLauncher.OK)
|
||||
errMsg = launcher.getErrorMessage();
|
||||
|
||||
|
||||
isCanceled = monitor.isCanceled();
|
||||
monitor.setCanceled(false);
|
||||
subMonitor = new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN);
|
||||
|
@ -128,7 +154,8 @@ public class CBuilder extends ACBuilder {
|
|||
|
||||
try {
|
||||
currProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
catch (CoreException e) {
|
||||
}
|
||||
|
||||
subMonitor = new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN);
|
||||
|
@ -137,8 +164,8 @@ public class CBuilder extends ACBuilder {
|
|||
fatalBuild = epm.reportProblems();
|
||||
|
||||
if (errMsg != null) {
|
||||
String errorDesc= CCorePlugin.getFormattedString(BUILD_ERROR, makepath.toString());
|
||||
StringBuffer buf= new StringBuffer(errorDesc);
|
||||
String errorDesc = CCorePlugin.getFormattedString(BUILD_ERROR, makepath.toString());
|
||||
StringBuffer buf = new StringBuffer(errorDesc);
|
||||
buf.append(System.getProperty("line.separator", "\n"));
|
||||
buf.append("(").append(errMsg).append(")");
|
||||
cos.write(buf.toString().getBytes());
|
||||
|
@ -149,7 +176,8 @@ public class CBuilder extends ACBuilder {
|
|||
subMonitor.done();
|
||||
monitor.setCanceled(isCanceled);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
monitor.done();
|
||||
|
@ -165,19 +193,21 @@ public class CBuilder extends ACBuilder {
|
|||
}
|
||||
|
||||
private String[] parseArguments(boolean fullBuild, String override_args) {
|
||||
ArrayList list= new ArrayList();
|
||||
ArrayList list = new ArrayList();
|
||||
IProject currProject = getProject();
|
||||
try {
|
||||
CProjectNature nature= (CProjectNature)currProject.getNature(CProjectNature.C_NATURE_ID);
|
||||
CProjectNature nature = (CProjectNature) currProject.getNature(CProjectNature.C_NATURE_ID);
|
||||
if (nature.isDefaultBuildCmd()) {
|
||||
if (!nature.isStopOnError()) {
|
||||
list.add("-k");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
String[] ovrd_args = makeArray(nature.getFullBuildArguments());
|
||||
list.addAll(Arrays.asList(ovrd_args));
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
catch (CoreException e) {
|
||||
}
|
||||
|
||||
String sessionTarget = MakeUtil.getSessionTarget((IResource) currProject);
|
||||
|
@ -194,11 +224,11 @@ public class CBuilder extends ACBuilder {
|
|||
|
||||
return (String[]) list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
|
||||
// Turn the string into an array.
|
||||
String[] makeArray(String string) {
|
||||
string.trim();
|
||||
char []array = string.toCharArray();
|
||||
string.trim();
|
||||
char[] array = string.toCharArray();
|
||||
ArrayList aList = new ArrayList();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
boolean inComment = false;
|
||||
|
@ -207,22 +237,24 @@ public class CBuilder extends ACBuilder {
|
|||
if (array[i] == '"' || array[i] == '\'') {
|
||||
if (i > 0 && array[i - 1] == '\\') {
|
||||
inComment = false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
inComment = !inComment;
|
||||
}
|
||||
}
|
||||
if (c == ' ' && !inComment) {
|
||||
aList.add(buffer.toString());
|
||||
buffer = new StringBuffer();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
buffer.append(c);
|
||||
}
|
||||
}
|
||||
if (buffer.length() > 0)
|
||||
aList.add(buffer.toString());
|
||||
return (String[])aList.toArray(new String[aList.size()]);
|
||||
return (String[]) aList.toArray(new String[aList.size()]);
|
||||
}
|
||||
|
||||
|
||||
//private void clearConsole(final IDocument doc) {
|
||||
// Display.getDefault().syncExec(new Runnable() {
|
||||
// public void run() {
|
||||
|
@ -230,12 +262,12 @@ public class CBuilder extends ACBuilder {
|
|||
// }
|
||||
// });
|
||||
//}
|
||||
|
||||
|
||||
private void removeAllMarkers(IProject currProject) throws CoreException {
|
||||
IWorkspace workspace= currProject.getWorkspace();
|
||||
|
||||
IWorkspace workspace = currProject.getWorkspace();
|
||||
|
||||
// remove all markers
|
||||
IMarker[] markers= currProject.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
|
||||
IMarker[] markers = currProject.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
|
||||
if (markers != null) {
|
||||
workspace.deleteMarkers(markers);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue