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