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

Internal Builder fixes/enhancements:

1. More smart error handling
2. Fix for the dir creation mechanism
This commit is contained in:
Mikhail Sennikovsky 2006-04-21 21:08:52 +00:00
parent b21c75453d
commit 064456a3b1
3 changed files with 65 additions and 33 deletions

View file

@ -19,6 +19,7 @@ import java.util.Map;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedMakeMessages;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
@ -36,6 +37,8 @@ public class CommandBuilder implements IBuildModelBuilder {
private IBuildCommand fCmd;
private Process fProcess;
private String fErrMsg;
private static final String BUILDER_MSG_HEADER = "InternalBuilder.msg.header"; //$NON-NLS-1$
private static final String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
protected class OutputStreamWrapper extends OutputStream {
private OutputStream fOut;
@ -92,31 +95,35 @@ public class CommandBuilder implements IBuildModelBuilder {
fProcess.getOutputStream().close();
} catch (IOException e) {
}
//wrapping out and err streams to avoid their closure
int st = launcher.waitAndRead(wrap(out), wrap(err),
new SubProgressMonitor(monitor,
IProgressMonitor.UNKNOWN));
switch(st){
case CommandLauncher.OK:
if(fProcess.exitValue() != 0)
status = STATUS_ERROR_BUILD;
break;
case CommandLauncher.COMMAND_CANCELED:
status = STATUS_CANCELLED;
break;
default:
status = STATUS_ERROR_LAUNCH;
fErrMsg = launcher.getErrorMessage();
break;
}
} else {
}
//wrapping out and err streams to avoid their closure
int st = launcher.waitAndRead(wrap(out), wrap(err),
new SubProgressMonitor(monitor,
IProgressMonitor.UNKNOWN));
switch(st){
case CommandLauncher.OK:
if(fProcess.exitValue() != 0)
status = STATUS_ERROR_BUILD;
break;
case CommandLauncher.COMMAND_CANCELED:
status = STATUS_CANCELLED;
fErrMsg = launcher.getErrorMessage();
if(DbgUtil.DEBUG)
DbgUtil.trace("command cancelled: " + fErrMsg); //$NON-NLS-1$
printMessage(fErrMsg, out);
break;
case CommandLauncher.ILLEGAL_COMMAND:
default:
status = STATUS_ERROR_LAUNCH;
fErrMsg = launcher.getErrorMessage();
if(DbgUtil.DEBUG)
DbgUtil.trace("error launching the command: " + fErrMsg); //$NON-NLS-1$
status = STATUS_ERROR_LAUNCH;
printMessage(fErrMsg, out);
break;
}
return status;
}
@ -137,4 +144,18 @@ public class CommandBuilder implements IBuildModelBuilder {
return (String[])list.toArray(new String[list.size()]);
}
protected void printMessage(String msg, OutputStream os){
if (os != null) {
msg = ManagedMakeMessages.getFormattedString(BUILDER_MSG_HEADER, msg) + LINE_SEPARATOR;
try {
os.write(msg.getBytes());
os.flush();
} catch (IOException e) {
// ignore;
}
}
}
}

View file

@ -47,18 +47,26 @@ public class GenDirInfo {
if(path != null
&& fProjPath.isPrefixOf(path)){
path = path.removeLastSegments(1).removeFirstSegments(1);
if(path.segmentCount() > 0 && fDirPathSet.add(path)){
IFolder folder = fProject.getFolder(path);
if(!folder.exists()){
try {
folder.create(true, true, monitor);
folder.setDerived(true);
} catch (CoreException e) {
//TODO: log the error
}
}
}
createDir(path, monitor);
}
}
protected void createDir(IPath path, IProgressMonitor monitor){
if(path.segmentCount() > 0 && fDirPathSet.add(path)){
IFolder folder = fProject.getFolder(path);
if(!folder.exists()){
createDir(path.removeLastSegments(1), monitor);
try {
folder.create(true, true, monitor);
folder.setDerived(true);
} catch (CoreException e) {
if(DbgUtil.DEBUG)
DbgUtil.trace("GenDirInfo: failed to create dir: " + e.getLocalizedMessage()); //$NON-NLS-1$
//TODO: log the error
}
}
}
}
}

View file

@ -115,4 +115,7 @@ BuildMacroStatus.value.undefined=
ResourceChangeHandler.buildInfoSerializationJob=Build Info Serialization
#ManagedBuilderCorePlugin messages
ManagedBuilderCorePlugin.resourceChangeHandlingInitializationJob=Initializing Resource Change Handling
ManagedBuilderCorePlugin.resourceChangeHandlingInitializationJob=Initializing Resource Change Handling
#Internal Builder messages
InternalBuilder.msg.header=Internal Builder: {0}