From 4172b282a73f694e7cfad4d27c8407995423ec1f Mon Sep 17 00:00:00 2001 From: wisberg Date: Wed, 30 Apr 2003 02:26:16 +0000 Subject: [PATCH] - incremental support - buildStructure test API now builds everything - removed unused code from pre-IMessage days --- .../ajde/internal/AspectJBuildManager.java | 291 +++--------------- 1 file changed, 37 insertions(+), 254 deletions(-) diff --git a/ajde/src/org/aspectj/ajde/internal/AspectJBuildManager.java b/ajde/src/org/aspectj/ajde/internal/AspectJBuildManager.java index 541cef80c..7835109db 100644 --- a/ajde/src/org/aspectj/ajde/internal/AspectJBuildManager.java +++ b/ajde/src/org/aspectj/ajde/internal/AspectJBuildManager.java @@ -32,6 +32,7 @@ import org.aspectj.ajde.ProjectPropertiesAdapter; import org.aspectj.ajde.TaskListManager; import org.aspectj.asm.StructureNode; import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.Message; import org.aspectj.bridge.SourceLocation; import org.aspectj.util.ConfigParser; @@ -50,8 +51,9 @@ public class AspectJBuildManager implements BuildManager { private BuildOptionsAdapter buildOptions = null; private ArrayList compilerListeners = new ArrayList(); private String configFile = ""; + private String lastConfigFile = null; private int lastCompileTime = 50; - private boolean buildStrucutreOnly = false; + private boolean buildStructureOnly = false; public AspectJBuildManager( TaskListManager compilerMessages, @@ -63,26 +65,43 @@ public class AspectJBuildManager implements BuildManager { this.compiler = new CompilerAdapter(); } + public void buildFresh() { + dobuild(true); + } + + /** this implementation just builds all */ + public void buildStructure() { + dobuild(true); + } + public void build() { - if (Ajde.getDefault().getConfigurationManager().getActiveConfigFile() == null) { - Ajde.getDefault().getErrorHandler().handleWarning("Nothing to compile, please add a \".lst\" file."); - return; - } else { - build(Ajde.getDefault().getConfigurationManager().getActiveConfigFile()); - } + dobuild(false); + } + + protected void dobuild(boolean fresh) { + dobuild(Ajde.getDefault().getConfigurationManager().getActiveConfigFile(), fresh); } - public void buildStructure() { - buildStrucutreOnly = true; - build(); - } + public void buildFresh(String configFile) { + dobuild(configFile, true); + } public void build(String configFile) { - buildStrucutreOnly = false; + dobuild(configFile, false); + } + + protected void dobuild(String configFile, boolean fresh) { if (configFile == null) { - Ajde.getDefault().getErrorHandler().handleWarning("Please add a configuration file to compile."); - } else { + Ajde.getDefault().getErrorHandler().handleWarning("Please select a build configuration file."); + } else { + this.lastConfigFile = this.configFile; this.configFile = configFile; + if (!fresh && !configFile.equals(lastConfigFile)) { + fresh = true; + } + if (fresh) { + this.compiler.nextBuildFresh(); + } CompilerThread compilerThread = new CompilerThread(); compilerThread.start(); } @@ -94,10 +113,6 @@ public class AspectJBuildManager implements BuildManager { } } -// public CompilerAdapter getCurrCompiler() { -// return currCompiler; -// } - public boolean isStructureDirty() { if (compiler != null) { return compiler.isStructureDirty(); @@ -140,61 +155,13 @@ public class AspectJBuildManager implements BuildManager { } } - /** - * @todo use structured error messages instead - */ - private void displayMessages(CompileResult compileResult) { - String[] descriptions = compileResult.getDescriptions(); - String[] files = compileResult.getfiles(); - Integer[] lineNumbers = compileResult.getLineNumbers(); - if (descriptions.length == 0 && compileResult.getResult().trim() != "") { - //compilerMessages.addSourcelineTask(compileResult.getResult(), "", 0, 0, TaskListManager.ERROR_MESSAGE); - compilerMessages.addSourcelineTask( - compileResult.getResult(), - new SourceLocation(null, 0, 0), - IMessage.ERROR); - return; - } - - for ( int i = 0; i < descriptions.length && - i < files.length && - i < lineNumbers.length; i++ ) { - String message = ""; - if (files[i] != "") { - message += "\"" + files[i] + "\": "; - } - if (lineNumbers[i].intValue() != -1 && lineNumbers[i].intValue() != 0) { - message += descriptions[i] + ", at line: " + lineNumbers[i]; - } else { - message += descriptions[i]; - } - - if (message.startsWith("Nothing to compile.")) { - message = "Nothing to compile, please select the project, package(s), or class(es) to compile."; - } - - IMessage.Kind kind = IMessage.ERROR; - if (descriptions[i].endsWith("(warning)")) kind = IMessage.WARNING; - - compilerMessages.addSourcelineTask( - message, - new SourceLocation(new File(files[i]), lineNumbers[i].intValue(), 0), - kind); - - StructureNode node = Ajde.getDefault().getStructureModelManager().getStructureModel().findNodeForSourceLine( - files[i], - lineNumbers[i].intValue() - ); - - if (node != null) { - node.setMessage(new Message(message, kind, null, null)); - } - } - } + public BuildOptionsAdapter getBuildOptions() { + return buildOptions; + } /** - * @todo clean up this mess. + * run compiler in a separate thread */ public class CompilerThread extends Thread { @@ -220,30 +187,6 @@ public class AspectJBuildManager implements BuildManager { + pe.getFile().getPath() + ", line number: " + pe.getLine()); -// } -// catch (ExitRequestException ere) { -// if (ere.getValue() == 0) { -// notifyCompileAborted(configFile, "Build cancelled by user."); -// } else { -// Ajde.getDefault().getErrorHandler().handleWarning("Compile could not complete. See the console for more details. " -// + "If no console is available re-launch the application from the command line."); -// } -// } catch (InternalCompilerError compilerError) { -// if (compilerError.uncaughtThrowable instanceof OutOfMemoryError) { -// Ajde.getDefault().getErrorHandler().handleError("Out of memory. " -// + "Increase memory by setting the -Xmx parameter that this VM was launched with.\n" -// + "Note that some AJDE structure persists across compiles." , -// compilerError.uncaughtThrowable); -// } else if (compilerError.uncaughtThrowable instanceof MissingRuntimeError) { -// Ajde.getDefault().getErrorHandler().handleWarning("Compilation aborted because the AspectJ runtime was not found. " -// + "Please place aspectjrt.jar in the lib/ext directory."); -// } else if (compilerError.uncaughtThrowable instanceof BadRuntimeError) { -// Ajde.getDefault().getErrorHandler().handleWarning("Compilation aborted because an out-of-date version of " + -// "the AspectJ runtime was found. " -// + "Please place a current version of aspectjrt.jar in the lib/ext directory."); -// } else { -// Ajde.getDefault().getErrorHandler().handleError("Compile error.", compilerError.uncaughtThrowable); -// } } catch (Throwable e) { Ajde.getDefault().getErrorHandler().handleError("Compile error, caught Throwable: " + e.toString(), e); } finally { @@ -297,165 +240,5 @@ public class AspectJBuildManager implements BuildManager { else { return s; } } } - - public BuildOptionsAdapter getBuildOptions() { - return buildOptions; - } - -// private void setCompilerOptions(AjdeCompiler compiler) { -// String nonstandardOptions = buildOptions.getNonStandardOptions(); -// if (nonstandardOptions != null && !nonstandardOptions.trim().equals("")) { -// StringTokenizer st = new StringTokenizer(nonstandardOptions, " "); -// while (st.hasMoreTokens()) { -// String flag = (String)st.nextToken(); -// compiler.getOptions().set(flag.substring(1, flag.length()), Boolean.TRUE); -// } -// } -// -// if (Ajde.getDefault().getProjectProperties().getOutputPath() != null -// && !compiler.getOptions().XtargetNearSource) { -// compiler.getOptions().outputDir = new File(Ajde.getDefault().getProjectProperties().getOutputPath()); -// } -// if (Ajde.getDefault().getProjectProperties().getBootClasspath() != null) { -// compiler.getOptions().bootclasspath = Ajde.getDefault().getProjectProperties().getBootClasspath(); -// } -// if (Ajde.getDefault().getProjectProperties().getClasspath() != null) { -// compiler.getOptions().classpath = Ajde.getDefault().getProjectProperties().getClasspath(); -// } -// if (buildOptions.getWorkingOutputPath() != null) { -// compiler.getOptions().workingDir = new File(buildOptions.getWorkingOutputPath()); -// } -//// if (buildOptions.getCharacterEncoding() != null) { -//// compiler.getOptions().encoding = buildOptions.getCharacterEncoding(); -//// } -// -// compiler.getOptions().lenient = buildOptions.getLenientSpecMode(); -// compiler.getOptions().strict = buildOptions.getStrictSpecMode(); -// compiler.getOptions().usejavac = buildOptions.getUseJavacMode(); -// compiler.getOptions().porting = buildOptions.getPortingMode(); -// compiler.getOptions().preprocess = buildOptions.getPreprocessMode(); -// -// if (buildOptions.getSourceOnePointFourMode()) { -// compiler.getOptions().source = "1.4"; -// } -// } - - static class CompileResult { - private String[] files = null; - private Integer[] lineNumbers = null; - private String[] descriptions = null; - private String resultString = ""; - private boolean resultContainsErrors = false; - - /** - * Parses out warning messages, error messages, "file not found" messages, javac "Note:" messages. - * - * @todo get error message structure directly from compiler - */ - public CompileResult( String result ) - { - resultString = result; - - BufferedReader reader = new BufferedReader( new StringReader( result ) ); - Vector fileV = new Vector(); - Vector lineV = new Vector(); - Vector descV = new Vector(); - try { - for (String line = reader.readLine(); line != null; line = reader.readLine()) { - String originalLine = line; - String description = ""; - String file = ""; - Integer lineNo = new Integer(0); - int index = line.indexOf( ":", 2 ); // @todo skip the initial drive ":" (fix, Windows only) - try { - if (line.indexOf("Note: ") != -1) { - int index1 = line.indexOf(".java"); - if (index1 != -1) { - description = line.substring(index1+5) + " (warning)"; - file = line.substring("Note: ".length(), index1+5); - lineNo = new Integer(0); - } else { - description = line + " (warning)"; - file = ""; - lineNo = new Integer(-1); - } - } - else if (line.indexOf("file not found: ") != -1) { - description = "file not found: "; - file = line.substring("file not found: ".length()); - lineNo = new Integer(0); - } - else if (index != -1 && line.indexOf( "java" ) != -1) { - file = line.substring( 0, index ); - line = line.substring( index+1 ); - - index = line.indexOf( ":" ); - lineNo = new Integer( Integer.parseInt( line.substring( 0, index ) ) ) ; - line = line.substring( index+1 ); - - if (!resultContainsErrors) { - if (!line.endsWith("(warning)")) { - resultContainsErrors = true; - } - } - description = line.substring( line.indexOf( ":" ) + 2 ); - } - } catch (Exception e) { - description = "Internal ajc message: " + originalLine; - file = ""; - lineNo = new Integer(-1); - } - if (description.trim() != "") { - descV.addElement(description); - fileV.addElement(file); - lineV.addElement(lineNo); - } - } - } - catch ( IOException ioe ) { - resultString = "ERROR: could not parse result at line for string: " + result; - } - files = new String[fileV.size()]; - lineNumbers = new Integer[lineV.size()]; - descriptions = new String[descV.size()]; - fileV.copyInto(files); - lineV.copyInto(lineNumbers); - descV.copyInto(descriptions); - } - - public String toString() - { - return resultString; - } - - public String[] getfiles() - { - return files; - } - - public Integer[] getLineNumbers() - { - return lineNumbers; - } - - public String[] getDescriptions() - { - return descriptions; - } - - public String getResult() - { - return resultString; - } - - public boolean containsErrors() { - return resultContainsErrors; - } - } } -class ConfigFileDoesNotExistException extends Exception { - public ConfigFileDoesNotExistException(String filePath) { - super(filePath); - } -} -- 2.39.5