mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 03:15:33 +02:00
- update progress monitor to show complete build command
- update progress monitor to normailize over each build.
This commit is contained in:
parent
becb0a5d20
commit
44e85901c9
5 changed files with 106 additions and 73 deletions
|
@ -37,6 +37,7 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.QualifiedName;
|
||||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
|
||||
public class MakeBuilder extends ACBuilder {
|
||||
|
@ -129,9 +130,6 @@ public class MakeBuilder extends ACBuilder {
|
|||
if (targets.length != 0 && targets[targets.length - 1].equals("clean")) //$NON-NLS-1$
|
||||
isClean = true;
|
||||
|
||||
// Before launching give visual cues via the monitor
|
||||
monitor.subTask(MakeCorePlugin.getResourceString("MakeBuilder.Invoking_Command") + buildCommand.toString()); //$NON-NLS-1$
|
||||
|
||||
String errMsg = null;
|
||||
CommandLauncher launcher = new CommandLauncher();
|
||||
// Print the command for visual interaction.
|
||||
|
@ -168,14 +166,17 @@ public class MakeBuilder extends ACBuilder {
|
|||
System.arraycopy(targets, 0, buildArguments, newArgs.length, targets.length);
|
||||
}
|
||||
}
|
||||
if (true) {
|
||||
// MakeRecon recon = new MakeRecon(buildCommand, buildArguments, env, workingDirectory, makeMonitor, cos);
|
||||
// recon.invokeMakeRecon();
|
||||
// cos = recon;
|
||||
cos = new StreamMonitor(new SubProgressMonitor(monitor, 100), cos);
|
||||
QualifiedName qName = new QualifiedName(MakeCorePlugin.getUniqueIdentifier(), "progressMonitor");
|
||||
Integer last = (Integer)getProject().getSessionProperty(qName);
|
||||
if (last == null) {
|
||||
last = new Integer(100);
|
||||
}
|
||||
StreamMonitor streamMon = new StreamMonitor(new SubProgressMonitor(monitor, 100), cos, last.intValue());
|
||||
ErrorParserManager epm = new ErrorParserManager(getProject(), this, info.getErrorParsers());
|
||||
epm.setOutputStream(cos);
|
||||
epm.setOutputStream(streamMon);
|
||||
OutputStream stdout = epm.getOutputStream();
|
||||
OutputStream stderr = epm.getOutputStream();
|
||||
Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory);
|
||||
|
@ -186,6 +187,8 @@ public class MakeBuilder extends ACBuilder {
|
|||
p.getOutputStream().close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
// Before launching give visual cues via the monitor
|
||||
monitor.subTask(MakeCorePlugin.getResourceString("MakeBuilder.Invoking_Command") + launcher.getCommandLine()); //$NON-NLS-1$
|
||||
if (launcher.waitAndRead(stdout, stderr, new SubProgressMonitor(monitor, 0))
|
||||
!= CommandLauncher.OK)
|
||||
errMsg = launcher.getErrorMessage();
|
||||
|
@ -201,7 +204,7 @@ public class MakeBuilder extends ACBuilder {
|
|||
} else {
|
||||
errMsg = launcher.getErrorMessage();
|
||||
}
|
||||
// makeMonitor.done();
|
||||
getProject().setSessionProperty(qName, !monitor.isCanceled() && !isClean ? new Integer(streamMon.getWorkDone()) : null);
|
||||
|
||||
if (errMsg != null) {
|
||||
StringBuffer buf = new StringBuffer(buildCommand.toString() + " "); //$NON-NLS-1$
|
||||
|
|
|
@ -60,7 +60,8 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI
|
|||
|
||||
public MakeScannerInfo getMakeScannerInfo(IProject project, boolean cacheInfo) throws CoreException {
|
||||
MakeScannerInfo scannerInfo = null;
|
||||
// See if there's already one associated with the resource for this session
|
||||
// See if there's already one associated with the resource for this
|
||||
// session
|
||||
scannerInfo = (MakeScannerInfo)project.getSessionProperty(scannerInfoProperty);
|
||||
|
||||
// Try to load one for the project
|
||||
|
@ -98,12 +99,14 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI
|
|||
}
|
||||
ListIterator iter = listeners.listIterator();
|
||||
while (iter.hasNext()) {
|
||||
((IScannerInfoChangeListener)iter.next()).changeNotification(project, (IScannerInfo)info);
|
||||
((IScannerInfoChangeListener)iter.next()).changeNotification(project, info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.parser.IScannerInfoProvider#getScannerInformation(org.eclipse.core.resources.IResource)
|
||||
*/
|
||||
public IScannerInfo getScannerInformation(IResource resource) {
|
||||
|
@ -117,8 +120,8 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI
|
|||
|
||||
/*
|
||||
* Loads the build file and parses the nodes for build information. The
|
||||
* information is then associated with the resource for the duration of
|
||||
* the session.
|
||||
* information is then associated with the resource for the duration of the
|
||||
* session.
|
||||
*/
|
||||
private MakeScannerInfo loadScannerInfo(IProject project) throws CoreException {
|
||||
ICDescriptor descriptor = CCorePlugin.getDefault().getCProjectDescription(project);
|
||||
|
@ -143,11 +146,11 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI
|
|||
|
||||
/**
|
||||
* The build model manager for standard builds only caches the build
|
||||
* information for a resource on a per-session basis. This method
|
||||
* allows clients of the build model manager to programmatically
|
||||
* remove the association between the resource and the information
|
||||
* while the reource is still open or in the workspace. The Eclipse core
|
||||
* will take care of removing it if a resource is closed or deleted.
|
||||
* information for a resource on a per-session basis. This method allows
|
||||
* clients of the build model manager to programmatically remove the
|
||||
* association between the resource and the information while the reource
|
||||
* is still open or in the workspace. The Eclipse core will take care of
|
||||
* removing it if a resource is closed or deleted.
|
||||
*
|
||||
* @param resource
|
||||
*/
|
||||
|
@ -159,17 +162,18 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI
|
|||
}
|
||||
|
||||
/**
|
||||
* Persists build-specific information in the build file. Build
|
||||
* information for standard make projects consists of preprocessor
|
||||
* symbols and includes paths. Other project-related information is
|
||||
* stored in the persistent properties of the project.
|
||||
* Persists build-specific information in the build file. Build information
|
||||
* for standard make projects consists of preprocessor symbols and includes
|
||||
* paths. Other project-related information is stored in the persistent
|
||||
* properties of the project.
|
||||
*
|
||||
* @param project
|
||||
*/
|
||||
static void updateScannerInfo(MakeScannerInfo scannerInfo) throws CoreException {
|
||||
IProject project = scannerInfo.getProject();
|
||||
|
||||
// See if there's already one associated with the resource for this session
|
||||
// See if there's already one associated with the resource for this
|
||||
// session
|
||||
if (project.getSessionProperty(scannerInfoProperty) != null) {
|
||||
project.setSessionProperty(scannerInfoProperty, scannerInfo);
|
||||
}
|
||||
|
@ -208,8 +212,11 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI
|
|||
notifyInfoListeners(project, scannerInfo);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerInfoProvider#subscribe(org.eclipse.core.resources.IResource, org.eclipse.cdt.core.parser.IScannerInfoChangeListener)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.parser.IScannerInfoProvider#subscribe(org.eclipse.core.resources.IResource,
|
||||
* org.eclipse.cdt.core.parser.IScannerInfoChangeListener)
|
||||
*/
|
||||
public synchronized void subscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
IResource project = null;
|
||||
|
@ -234,8 +241,11 @@ public class MakeScannerProvider extends AbstractCExtension implements IScannerI
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.IScannerInfoProvider#unsubscribe(org.eclipse.core.resources.IResource, org.eclipse.cdt.core.parser.IScannerInfoChangeListener)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.cdt.core.parser.IScannerInfoProvider#unsubscribe(org.eclipse.core.resources.IResource,
|
||||
* org.eclipse.cdt.core.parser.IScannerInfoChangeListener)
|
||||
*/
|
||||
public synchronized void unsubscribe(IResource resource, IScannerInfoChangeListener listener) {
|
||||
IResource project = null;
|
||||
|
|
|
@ -187,7 +187,6 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
|
|||
MakeCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MakeTargetVisitor implements IResourceDeltaVisitor {
|
||||
|
@ -210,6 +209,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
|
|||
}
|
||||
} else if (deltaKind == IResourceDelta.REMOVED) {
|
||||
if (fProjects.contains(project)) {
|
||||
deleteTargets(project);
|
||||
fProjects.remove(project);
|
||||
notifyListeners(new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_REMOVED, project));
|
||||
}
|
||||
|
@ -217,6 +217,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
|
|||
if (0 != (flags & IResourceDelta.DESCRIPTION)) {
|
||||
if (fProjects.contains(project) && !hasTargetBuilder(project)) {
|
||||
fProjects.remove(project);
|
||||
projectMap.remove(project);
|
||||
notifyListeners(new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_REMOVED, project));
|
||||
} else if (!fProjects.contains(project) && hasTargetBuilder(project)) {
|
||||
fProjects.add(project);
|
||||
|
@ -226,6 +227,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
|
|||
if (0 != (flags & IResourceDelta.OPEN)) {
|
||||
if (!project.isOpen() && fProjects.contains(project)) {
|
||||
fProjects.remove(project);
|
||||
projectMap.remove(project);
|
||||
notifyListeners(new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_REMOVED, project));
|
||||
} else if (project.isOpen() && hasTargetBuilder(project) && !fProjects.contains(project)) {
|
||||
fProjects.add(project);
|
||||
|
@ -240,7 +242,9 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
|
|||
}
|
||||
|
||||
protected void writeTargets(ProjectTargets projectTargets) throws CoreException {
|
||||
IPath targetFilePath = MakeCorePlugin.getDefault().getStateLocation().append(projectTargets.getProject().getName()).addFileExtension(TARGETS_EXT);
|
||||
IPath targetFilePath =
|
||||
MakeCorePlugin.getDefault().getStateLocation().append(projectTargets.getProject().getName()).addFileExtension(
|
||||
TARGETS_EXT);
|
||||
File targetFile = targetFilePath.toFile();
|
||||
try {
|
||||
FileOutputStream file = new FileOutputStream(targetFile);
|
||||
|
@ -249,11 +253,11 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
|
|||
throw new CoreException(
|
||||
new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, "Error writing target file", e));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected ProjectTargets readTargets(IProject project) {
|
||||
IPath targetFilePath = MakeCorePlugin.getDefault().getStateLocation().append(project.getName()).addFileExtension(TARGETS_EXT);
|
||||
IPath targetFilePath =
|
||||
MakeCorePlugin.getDefault().getStateLocation().append(project.getName()).addFileExtension(TARGETS_EXT);
|
||||
File targetFile = targetFilePath.toFile();
|
||||
ProjectTargets projectTargets = null;
|
||||
if (targetFile.exists()) {
|
||||
|
@ -267,7 +271,16 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
|
|||
}
|
||||
projectMap.put(project, projectTargets);
|
||||
return projectTargets;
|
||||
}
|
||||
|
||||
protected void deleteTargets(IProject project) {
|
||||
IPath targetFilePath =
|
||||
MakeCorePlugin.getDefault().getStateLocation().append(project.getName()).addFileExtension(TARGETS_EXT);
|
||||
File targetFile = targetFilePath.toFile();
|
||||
if (targetFile.exists()) {
|
||||
targetFile.delete();
|
||||
}
|
||||
projectMap.remove(project);
|
||||
}
|
||||
|
||||
protected void initializeBuilders() {
|
||||
|
|
|
@ -239,5 +239,4 @@ public class ProjectTargets {
|
|||
SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(new OutputStreamWriter(output, "UTF8"), format);
|
||||
serializer.asDOMSerializer().serialize(doc);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,28 +19,32 @@ public class StreamMonitor extends OutputStream {
|
|||
|
||||
IProgressMonitor monitor;
|
||||
OutputStream console;
|
||||
public static final int TOTAL_WORK = 10;
|
||||
private int halfWay = TOTAL_WORK / 2;
|
||||
private int currentIncrement = 1;
|
||||
public final int fTotalWork;
|
||||
private int halfWay;
|
||||
private int currentIncrement = 2;
|
||||
private int nextProgress = currentIncrement;
|
||||
private int worked = 0;
|
||||
|
||||
public StreamMonitor(IProgressMonitor mon, OutputStream cos) {
|
||||
public StreamMonitor(IProgressMonitor mon, OutputStream cos, int totalWork) {
|
||||
monitor = mon;
|
||||
console = cos;
|
||||
monitor.beginTask("", TOTAL_WORK);
|
||||
fTotalWork = totalWork;
|
||||
halfWay = fTotalWork / 2;
|
||||
monitor.beginTask("", fTotalWork);
|
||||
}
|
||||
|
||||
private void progressUpdate() {
|
||||
if (--nextProgress <= 0) {
|
||||
//we have exhausted the current increment, so report progress
|
||||
if (fTotalWork > worked) {
|
||||
monitor.worked(1);
|
||||
}
|
||||
worked++;
|
||||
if (worked >= halfWay) {
|
||||
//we have passed the current halfway point, so double the
|
||||
//increment and reset the halfway point.
|
||||
currentIncrement *= 2;
|
||||
halfWay += (TOTAL_WORK - halfWay) / 2;
|
||||
halfWay += (fTotalWork - halfWay) / 2;
|
||||
}
|
||||
//reset the progress counter to another full increment
|
||||
nextProgress = currentIncrement;
|
||||
|
@ -91,4 +95,8 @@ public class StreamMonitor extends OutputStream {
|
|||
}
|
||||
progressUpdate();
|
||||
}
|
||||
|
||||
public int getWorkDone() {
|
||||
return worked;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue