1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

added a stream monitor so that we can fuge that we are getting progress

This commit is contained in:
David Inglis 2003-10-08 18:25:46 +00:00
parent 3804b80669
commit 943f1dbc94
3 changed files with 299 additions and 15 deletions

View file

@ -19,11 +19,11 @@ import java.util.Properties;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.core.ConsoleOutputStream;
import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.resources.ACBuilder;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.make.internal.core.StreamMonitor;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
@ -99,7 +99,7 @@ public class MakeBuilder extends ACBuilder {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(MakeCorePlugin.getResourceString("MakeBuilder.Invoking_Make_Builder") + currProject.getName(), IProgressMonitor.UNKNOWN); //$NON-NLS-1$
monitor.beginTask(MakeCorePlugin.getResourceString("MakeBuilder.Invoking_Make_Builder") + currProject.getName(), 100); //$NON-NLS-1$
try {
IPath buildCommand = info.getBuildCommand();
@ -107,7 +107,7 @@ public class MakeBuilder extends ACBuilder {
IConsole console = CCorePlugin.getDefault().getConsole();
console.start(currProject);
ConsoleOutputStream cos = console.getOutputStream();
OutputStream cos = console.getOutputStream();
// remove all markers for this project
removeAllMarkers(currProject);
@ -115,11 +115,11 @@ public class MakeBuilder extends ACBuilder {
IPath workingDirectory = null;
if (!info.getBuildLocation().isEmpty()) {
IResource res = currProject.getParent().findMember(info.getBuildLocation());
if ( res instanceof IContainer && res.exists()) {
if (res instanceof IContainer && res.exists()) {
workingDirectory = res.getLocation();
}
}
if ( workingDirectory == null) {
if (workingDirectory == null) {
workingDirectory = currProject.getLocation();
}
String[] targets = getTargets(kind, info);
@ -148,27 +148,32 @@ public class MakeBuilder extends ACBuilder {
}
env = (String[]) envList.toArray(new String[envList.size()]);
}
ErrorParserManager epm = new ErrorParserManager(getProject(), this, info.getErrorParsers());
epm.setOutputStream(cos);
OutputStream stdout = epm.getOutputStream();
OutputStream stderr = epm.getOutputStream();
String[] buildArguments = targets;
if (info.isDefaultBuildCmd()) {
if ( !info.isStopOnError()) {
if (!info.isStopOnError()) {
buildArguments = new String[targets.length + 1];
buildArguments[0] = "-k"; //$NON-NLS-1$
System.arraycopy(targets, 0, buildArguments, 1, targets.length);
}
} else {
String args = info.getBuildArguments();
if ( args != null && !args.equals("")) { //$NON-NLS-1$
String[] newArgs = makeArray(args);
if (args != null && !args.equals("")) { //$NON-NLS-1$
String[] newArgs = makeArray(args);
buildArguments = new String[targets.length + newArgs.length];
System.arraycopy(newArgs, 0, buildArguments, 0, newArgs.length);
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);
}
ErrorParserManager epm = new ErrorParserManager(getProject(), this, info.getErrorParsers());
epm.setOutputStream(cos);
OutputStream stdout = epm.getOutputStream();
OutputStream stderr = epm.getOutputStream();
Process p = launcher.execute(buildCommand, buildArguments, env, workingDirectory);
if (p != null) {
try {
@ -177,9 +182,9 @@ public class MakeBuilder extends ACBuilder {
p.getOutputStream().close();
} catch (IOException e) {
}
if (launcher.waitAndRead(stdout, stderr, new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN)) != CommandLauncher.OK)
if (launcher.waitAndRead(stdout, stderr, new SubProgressMonitor(monitor, 0))
!= CommandLauncher.OK)
errMsg = launcher.getErrorMessage();
monitor.subTask(MakeCorePlugin.getResourceString("MakeBuilder.Updating_project")); //$NON-NLS-1$
try {
@ -192,6 +197,7 @@ public class MakeBuilder extends ACBuilder {
} else {
errMsg = launcher.getErrorMessage();
}
// makeMonitor.done();
if (errMsg != null) {
StringBuffer buf = new StringBuffer(buildCommand.toString() + " "); //$NON-NLS-1$
@ -213,6 +219,7 @@ public class MakeBuilder extends ACBuilder {
monitor.subTask(MakeCorePlugin.getResourceString("MakeBuilder.Creating_Markers")); //$NON-NLS-1$
epm.reportProblems();
cos.close();
}
} catch (Exception e) {
CCorePlugin.log(e);

View file

@ -0,0 +1,183 @@
/**********************************************************************
* Copyright (c) 2002,2003 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.make.internal.core;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringReader;
import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
public class MakeRecon extends OutputStream {
IPath make;
String[] args;
String[] environ;
IPath directory;
IProgressMonitor monitor;
OutputStream console;
BufferedReader log;
StringBuffer currentLine;
String expectation;
public MakeRecon(
IPath buildCommand,
String[] buildArguments,
String[] env,
IPath workingDirectory,
IProgressMonitor mon,
OutputStream cos) {
make = buildCommand;
if (buildArguments != null) {
args = new String[buildArguments.length + 1];
args[0] = "-n";
System.arraycopy(buildArguments, 0, args, 1, buildArguments.length);
} else {
args = new String[] { "-n" };
}
environ = env;
directory = workingDirectory;
monitor = mon;
console = cos;
currentLine = new StringBuffer();
}
public void invokeMakeRecon() {
int i = 0;
String[] array = new String[args.length + 1];
array[0] = make.toOSString();
System.arraycopy(args, 0, array, 1, args.length);
Process p;
try {
p = ProcessFactory.getFactory().exec(array, environ, directory.toFile());
InputStream in = p.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
// Swallow the output
String line;
StringBuffer sb = new StringBuffer();
try {
while ((line = reader.readLine()) != null) {
sb.append(line).append('\n');
i++;
}
} catch (IOException e) {
}
try {
in.close();
} catch (IOException e) {
}
p.destroy();
log = new BufferedReader(new StringReader(sb.toString()));
} catch (IOException e1) {
i = IProgressMonitor.UNKNOWN;
}
if (monitor != null) {
monitor.beginTask("", i);
}
}
/**
* @see java.io.OutputStream#close()
*/
public void close() throws IOException {
if (console != null) {
console.close();
}
}
/**
* @see java.io.OutputStream#flush()
*/
public void flush() throws IOException {
if (console != null) {
console.flush();
}
}
/**
* @see java.io.OutputStream#write(int)
*/
public synchronized void write(int b) throws IOException {
currentLine.append((char) b);
checkProgress(false);
if (console != null) {
console.write(b);
}
}
/**
* @see java.io.OutputStream#write(...)
*/
public synchronized void write(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if (off != 0 || (len < 0) || (len > b.length)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
currentLine.append(new String(b, 0, len));
checkProgress(false);
if (console != null) {
console.write(b, off, len);
}
}
private void checkProgress(boolean flush) {
String buffer = currentLine.toString();
int i = 0;
while ((i = buffer.indexOf("\n")) != -1) {
String line = buffer.substring(0, i).trim(); // get rid of any trailing \r
processLine(line);
buffer = buffer.substring(i + 1); // skip the \n and advance
}
currentLine.setLength(0);
if (flush) {
if (buffer.length() > 0) {
processLine(buffer);
}
} else {
currentLine.append(buffer);
}
}
private void processLine(String line) {
if (expectation == null) {
try {
expectation = log.readLine();
if (expectation != null) {
String show;
if (expectation.length() > 150) {
show = expectation.substring(0, 150);
} else {
show = expectation;
}
monitor.subTask(show);
}
} catch (IOException e) {
}
if (expectation == null) {
expectation = "";
}
}
if (expectation.startsWith(line)) {
expectation = null;
if (monitor != null) {
monitor.worked(1);
}
}
}
}

View file

@ -0,0 +1,94 @@
/**********************************************************************
* Copyright (c) 2002,2003 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.make.internal.core;
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.core.runtime.IProgressMonitor;
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;
private int nextProgress = currentIncrement;
private int worked = 0;
public StreamMonitor(IProgressMonitor mon, OutputStream cos) {
monitor = mon;
console = cos;
monitor.beginTask("", TOTAL_WORK);
}
private void progressUpdate() {
if (--nextProgress <= 0) {
//we have exhausted the current increment, so report progress
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;
}
//reset the progress counter to another full increment
nextProgress = currentIncrement;
}
}
/**
* @see java.io.OutputStream#close()
*/
public void close() throws IOException {
if (console != null) {
console.close();
}
monitor.done();
}
/**
* @see java.io.OutputStream#flush()
*/
public void flush() throws IOException {
if (console != null) {
console.flush();
}
}
/**
* @see java.io.OutputStream#write(int)
*/
public synchronized void write(int b) throws IOException {
if (console != null) {
console.write(b);
}
progressUpdate();
}
/**
* @see java.io.OutputStream#write(...)
*/
public synchronized void write(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if (off != 0 || (len < 0) || (len > b.length)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
if (console != null) {
console.write(b, off, len);
}
progressUpdate();
}
}