1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +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.core.CommandLauncher;
import org.eclipse.cdt.managedbuilder.buildmodel.IBuildCommand; 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.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.core.runtime.SubProgressMonitor;
@ -36,6 +37,8 @@ public class CommandBuilder implements IBuildModelBuilder {
private IBuildCommand fCmd; private IBuildCommand fCmd;
private Process fProcess; private Process fProcess;
private String fErrMsg; 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 { protected class OutputStreamWrapper extends OutputStream {
private OutputStream fOut; private OutputStream fOut;
@ -92,31 +95,35 @@ public class CommandBuilder implements IBuildModelBuilder {
fProcess.getOutputStream().close(); fProcess.getOutputStream().close();
} catch (IOException e) { } catch (IOException e) {
} }
//wrapping out and err streams to avoid their closure }
int st = launcher.waitAndRead(wrap(out), wrap(err),
new SubProgressMonitor(monitor, //wrapping out and err streams to avoid their closure
IProgressMonitor.UNKNOWN)); int st = launcher.waitAndRead(wrap(out), wrap(err),
switch(st){ new SubProgressMonitor(monitor,
case CommandLauncher.OK: IProgressMonitor.UNKNOWN));
if(fProcess.exitValue() != 0) switch(st){
status = STATUS_ERROR_BUILD; case CommandLauncher.OK:
break; if(fProcess.exitValue() != 0)
case CommandLauncher.COMMAND_CANCELED: status = STATUS_ERROR_BUILD;
status = STATUS_CANCELLED; break;
break; case CommandLauncher.COMMAND_CANCELED:
default: status = STATUS_CANCELLED;
status = STATUS_ERROR_LAUNCH; fErrMsg = launcher.getErrorMessage();
fErrMsg = launcher.getErrorMessage(); if(DbgUtil.DEBUG)
break; DbgUtil.trace("command cancelled: " + fErrMsg); //$NON-NLS-1$
}
} else { printMessage(fErrMsg, out);
break;
case CommandLauncher.ILLEGAL_COMMAND:
default:
status = STATUS_ERROR_LAUNCH;
fErrMsg = launcher.getErrorMessage(); fErrMsg = launcher.getErrorMessage();
if(DbgUtil.DEBUG) if(DbgUtil.DEBUG)
DbgUtil.trace("error launching the command: " + fErrMsg); //$NON-NLS-1$ DbgUtil.trace("error launching the command: " + fErrMsg); //$NON-NLS-1$
status = STATUS_ERROR_LAUNCH; printMessage(fErrMsg, out);
break;
} }
return status; return status;
} }
@ -137,4 +144,18 @@ public class CommandBuilder implements IBuildModelBuilder {
return (String[])list.toArray(new String[list.size()]); 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 if(path != null
&& fProjPath.isPrefixOf(path)){ && fProjPath.isPrefixOf(path)){
path = path.removeLastSegments(1).removeFirstSegments(1); path = path.removeLastSegments(1).removeFirstSegments(1);
if(path.segmentCount() > 0 && fDirPathSet.add(path)){ createDir(path, monitor);
IFolder folder = fProject.getFolder(path);
if(!folder.exists()){
try {
folder.create(true, true, monitor);
folder.setDerived(true);
} catch (CoreException e) {
//TODO: log the error
}
}
}
} }
} }
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

@ -116,3 +116,6 @@ ResourceChangeHandler.buildInfoSerializationJob=Build Info Serialization
#ManagedBuilderCorePlugin messages #ManagedBuilderCorePlugin messages
ManagedBuilderCorePlugin.resourceChangeHandlingInitializationJob=Initializing Resource Change Handling ManagedBuilderCorePlugin.resourceChangeHandlingInitializationJob=Initializing Resource Change Handling
#Internal Builder messages
InternalBuilder.msg.header=Internal Builder: {0}