diff options
author | acolyer <acolyer> | 2004-03-15 15:11:16 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2004-03-15 15:11:16 +0000 |
commit | 2ed4c9f470df51b8621edda4451ad1768c36c1d5 (patch) | |
tree | 88c417ea4dab864f82c3155d4c35cd259d8ea04a /org.aspectj.ajdt.core | |
parent | 40680b6fe4d28b2d061fc4cf9b3efa6640c12f44 (diff) | |
download | aspectj-2ed4c9f470df51b8621edda4451ad1768c36c1d5.tar.gz aspectj-2ed4c9f470df51b8621edda4451ad1768c36c1d5.zip |
move weaving to inside of the compiler.compile loop.
ensure messages are associated with source wherever possible
Diffstat (limited to 'org.aspectj.ajdt.core')
4 files changed, 414 insertions, 185 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index 93cad315d..4b128b17c 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -16,14 +16,20 @@ package org.aspectj.ajdt.internal.core.builder; import java.io.*; import java.util.*; import java.util.jar.*; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; -import org.aspectj.ajdt.internal.compiler.AjCompiler; +import org.aspectj.ajdt.internal.compiler.AjCompilerAdapter; +import org.aspectj.ajdt.internal.compiler.IIntermediateResultsRequestor; +import org.aspectj.ajdt.internal.compiler.IOutputClassFileNameProvider; +import org.aspectj.ajdt.internal.compiler.InterimCompilationResult; import org.aspectj.ajdt.internal.compiler.lookup.*; import org.aspectj.ajdt.internal.compiler.problem.AjProblemReporter; import org.aspectj.asm.*; //import org.aspectj.asm.internal.*; import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.*; +import org.aspectj.util.FileUtil; import org.aspectj.weaver.World; import org.aspectj.weaver.bcel.*; import org.eclipse.jdt.core.compiler.*; @@ -36,12 +42,17 @@ import org.eclipse.jdt.internal.compiler.parser.Parser; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; //import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; -public class AjBuildManager { +public class AjBuildManager implements IOutputClassFileNameProvider,ICompilerAdapterFactory { + private static final String CANT_WRITE_RESULT = "unable to write compilation result"; static final boolean FAIL_IF_RUNTIME_NOT_FOUND = false; private IProgressListener progressListener = null; private int compiledCount; private int sourceFileCount; + + private ZipOutputStream zos; + private boolean batchCompile = true; + private INameEnvironment environment; private IHierarchy structureModel; public AjBuildConfig buildConfig; @@ -84,6 +95,8 @@ public class AjBuildManager { IMessageHandler baseHandler, boolean batch) throws IOException, AbortException { + batchCompile = batch; + try { if (batch) { this.state = new AjState(this); @@ -108,7 +121,11 @@ public class AjBuildManager { // if (batch) { setBuildConfig(buildConfig); //} - setupModel(); +// if (batch) { +// if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) { + setupModel(); +// } +// } if (batch) { initBcelWorld(handler); } @@ -116,6 +133,11 @@ public class AjBuildManager { return false; } + if (buildConfig.getOutputJar() != null) { + OutputStream os = FileUtil.makeOutputStream(buildConfig.getOutputJar()); + zos = new ZipOutputStream(os); + } + if (batch) { // System.err.println("XXXX batch: " + buildConfig.getFiles()); if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) { @@ -153,7 +175,8 @@ public class AjBuildManager { // have to tell state we succeeded or next is not incremental state.successfulCompile(buildConfig); - /*boolean weaved = */weaveAndGenerateClassFiles(); + copyResourcesToDestination(); + /*boolean weaved = *///weaveAndGenerateClassFiles(); // if not weaved, then no-op build, no model changes // but always returns true // XXX weaved not in Mik's incremental @@ -162,9 +185,20 @@ public class AjBuildManager { } return !handler.hasErrors(); } finally { + if (zos != null) { + zos.close(); + } handler = null; } } + + private void copyResourcesToDestination() throws IOException { + if (buildConfig.getOutputJar() != null) { + bcelWeaver.dumpResourcesToOutJar(zos); + } else { + bcelWeaver.dumpResourcesToOutPath(); + } + } /** * Responsible for managing the ASM model between builds. Contains the policy for @@ -172,8 +206,8 @@ public class AjBuildManager { * * TODO: implement incremental policy. */ - private void setupModel() { - String rootLabel = "<root>"; + private void setupModel() { + String rootLabel = "<root>"; IHierarchy model = AsmManager.getDefault().getHierarchy(); AsmManager.getDefault().getRelationshipMap().clear(); @@ -197,6 +231,7 @@ public class AjBuildManager { bcelWorld.setXnoInline(buildConfig.isXnoInline()); bcelWorld.setXlazyTjp(buildConfig.isXlazyTjp()); bcelWeaver = new BcelWeaver(bcelWorld); + state.binarySourceFiles = new HashMap(); for (Iterator i = buildConfig.getAspectpath().iterator(); i.hasNext();) { File f = (File) i.next(); @@ -218,12 +253,14 @@ public class AjBuildManager { //??? incremental issues for (Iterator i = buildConfig.getInJars().iterator(); i.hasNext(); ) { File inJar = (File)i.next(); - bcelWeaver.addJarFile(inJar, buildConfig.getOutputDir(),false); + List unwovenClasses = bcelWeaver.addJarFile(inJar, buildConfig.getOutputDir(),false); + state.binarySourceFiles.put(inJar.getPath(), unwovenClasses); } for (Iterator i = buildConfig.getInpath().iterator(); i.hasNext(); ) { File inPathElement = (File)i.next(); - bcelWeaver.addJarFile(inPathElement,buildConfig.getOutputDir(),true); + List unwovenClasses = bcelWeaver.addJarFile(inPathElement,buildConfig.getOutputDir(),true); + state.binarySourceFiles.put(inPathElement.getPath(),unwovenClasses); // good enough for ajc to lump these together } if (buildConfig.getSourcePathResources() != null) { @@ -252,32 +289,32 @@ public class AjBuildManager { } } - public boolean weaveAndGenerateClassFiles() throws IOException { - handler.handleMessage(MessageUtil.info("weaving")); - if (progressListener != null) progressListener.setText("weaving aspects"); - bcelWeaver.setProgressListener(progressListener, 0.5, 0.5/state.addedClassFiles.size()); - //!!! doesn't provide intermediate progress during weaving - // XXX add all aspects even during incremental builds? - addAspectClassFilesToWeaver(state.addedClassFiles); - if (buildConfig.isNoWeave()) { - if (buildConfig.getOutputJar() != null) { - bcelWeaver.dumpUnwoven(buildConfig.getOutputJar()); - } else { - bcelWeaver.dumpUnwoven(); - bcelWeaver.dumpResourcesToOutPath(); - } - } else { - if (buildConfig.getOutputJar() != null) { - bcelWeaver.weave(buildConfig.getOutputJar()); - } else { - bcelWeaver.weave(); - bcelWeaver.dumpResourcesToOutPath(); - } - } - if (progressListener != null) progressListener.setProgress(1.0); - return true; - //return messageAdapter.getErrorCount() == 0; //!javaBuilder.notifier.anyErrors(); - } +// public boolean weaveAndGenerateClassFiles() throws IOException { +// handler.handleMessage(MessageUtil.info("weaving")); +// if (progressListener != null) progressListener.setText("weaving aspects"); +// bcelWeaver.setProgressListener(progressListener, 0.5, 0.5/state.addedClassFiles.size()); +// //!!! doesn't provide intermediate progress during weaving +// // XXX add all aspects even during incremental builds? +// addAspectClassFilesToWeaver(state.addedClassFiles); +// if (buildConfig.isNoWeave()) { +// if (buildConfig.getOutputJar() != null) { +// bcelWeaver.dumpUnwoven(buildConfig.getOutputJar()); +// } else { +// bcelWeaver.dumpUnwoven(); +// bcelWeaver.dumpResourcesToOutPath(); +// } +// } else { +// if (buildConfig.getOutputJar() != null) { +// bcelWeaver.weave(buildConfig.getOutputJar()); +// } else { +// bcelWeaver.weave(); +// bcelWeaver.dumpResourcesToOutPath(); +// } +// } +// if (progressListener != null) progressListener.setProgress(1.0); +// return true; +// //return messageAdapter.getErrorCount() == 0; //!javaBuilder.notifier.anyErrors(); +// } public FileSystem getLibraryAccess(String[] classpaths, String[] filenames) { String defaultEncoding = (String) buildConfig.getJavaOptions().get(CompilerOptions.OPTION_Encoding); @@ -352,42 +389,20 @@ public class AjBuildManager { } //System.out.println("compiling"); - INameEnvironment environment = getLibraryAccess(classpaths, filenames); + environment = getLibraryAccess(classpaths, filenames); if (!state.classesFromName.isEmpty()) { environment = new StatefulNameEnvironment(environment, state.classesFromName); } - AjCompiler compiler = new AjCompiler( - environment, - DefaultErrorHandlingPolicies.proceedWithAllProblems(), - buildConfig.getJavaOptions(), - getBatchRequestor(), - getProblemFactory()); - - - AjProblemReporter pr = - new AjProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), - compiler.options, getProblemFactory()); - - compiler.problemReporter = pr; - - AjLookupEnvironment le = - new AjLookupEnvironment(compiler, compiler.options, pr, environment); - EclipseFactory factory = new EclipseFactory(le); -// ew.setLint(bcelWorld.getLint()); -// ew.setXnoInline(buildConfig.isXnoInline()); - le.factory = factory; - pr.factory = factory; - le.factory.buildManager = this; - - compiler.lookupEnvironment = le; + org.eclipse.jdt.internal.compiler.Compiler.setCompilerAdapterFactory(this); + org.eclipse.jdt.internal.compiler.Compiler compiler = + new org.eclipse.jdt.internal.compiler.Compiler(environment, + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + buildConfig.getJavaOptions(), + getBatchRequestor(), + getProblemFactory()); - compiler.parser = - new Parser( - pr, - compiler.options.parseLiteralExpressionsAsConstants); - CompilerOptions options = compiler.options; options.produceReferenceInfo(true); //TODO turn off when not needed @@ -396,75 +411,138 @@ public class AjBuildManager { // cleanup environment.cleanup(); + environment = null; } /* * Answer the component to which will be handed back compilation results from the compiler */ - public ICompilerRequestor getBatchRequestor() { - return new ICompilerRequestor() { + public IIntermediateResultsRequestor getInterimResultRequestor() { + return new IIntermediateResultsRequestor() { int lineDelta = 0; - public void acceptResult(CompilationResult compilationResult) { + public void acceptResult(InterimCompilationResult result) { if (progressListener != null) { compiledCount++; progressListener.setProgress((compiledCount/2.0)/sourceFileCount); - progressListener.setText("compiled: " + new String(compilationResult.getFileName())); + progressListener.setText("compiled: " + result.fileName()); + } + state.noteResult(result); + } + }; + } + + public ICompilerRequestor getBatchRequestor() { + return new ICompilerRequestor() { + + public void acceptResult(CompilationResult unitResult) { + // end of compile, must now write the results to the output destination + // this is either a jar file or a file in a directory + if (!(unitResult.hasErrors() && !proceedOnError())) { + Enumeration classFiles = unitResult.compiledTypes.elements(); + while (classFiles.hasMoreElements()) { + ClassFile classFile = (ClassFile) classFiles.nextElement(); + String filename = new String(classFile.fileName()); + filename = filename.replace('/', File.separatorChar) + ".class"; + try { + if (buildConfig.getOutputJar() == null) { + writeDirectoryEntry(unitResult, classFile,filename); + } else { + writeZipEntry(classFile,filename); + } + } catch (IOException ex) { + IMessage message = EclipseAdapterUtils.makeErrorMessage( + unitResult.compilationUnit, + CANT_WRITE_RESULT, + ex); + handler.handleMessage(message); + } + + } } - if (compilationResult.hasProblems() || compilationResult.hasTasks()) { - IProblem[] problems = compilationResult.getAllProblems(); + if (unitResult.hasProblems() || unitResult.hasTasks()) { + IProblem[] problems = unitResult.getAllProblems(); for (int i=0; i < problems.length; i++) { IMessage message = - EclipseAdapterUtils.makeMessage(compilationResult.compilationUnit, problems[i]); + EclipseAdapterUtils.makeMessage(unitResult.compilationUnit, problems[i]); handler.handleMessage(message); } } - outputClassFiles(compilationResult); - } - }; - } - - private boolean proceedOnError() { - return true; //??? - } - public void outputClassFiles(CompilationResult unitResult) { - if (unitResult == null) return; - - String sourceFileName = new String(unitResult.fileName); - if (!(unitResult.hasErrors() && !proceedOnError())) { - List unwovenClassFiles = new ArrayList(); - Enumeration classFiles = unitResult.compiledTypes.elements(); - while (classFiles.hasMoreElements()) { - ClassFile classFile = (ClassFile) classFiles.nextElement(); - String filename = new String(classFile.fileName()); - filename = filename.replace('/', File.separatorChar) + ".class"; - + } + + private void writeDirectoryEntry( + CompilationResult unitResult, + ClassFile classFile, + String filename) + throws IOException { File destinationPath = buildConfig.getOutputDir(); + String outFile; if (destinationPath == null) { - filename = new File(filename).getName(); - filename = new File(extractDestinationPathFromSourceFile(unitResult), filename).getPath(); + outFile = new File(filename).getName(); + outFile = new File(extractDestinationPathFromSourceFile(unitResult), outFile).getPath(); } else { - filename = new File(destinationPath, filename).getPath(); + outFile = new File(destinationPath, filename).getPath(); } + BufferedOutputStream os = + FileUtil.makeOutputStream(new File(outFile)); + os.write(classFile.getBytes()); + os.close(); + } + + private void writeZipEntry(ClassFile classFile, String name) + throws IOException { + name = name.replace(File.separatorChar,'/'); + ZipEntry newEntry = new ZipEntry(name); //??? get compression scheme right - //System.out.println("classfile: " + filename); - unwovenClassFiles.add(new UnwovenClassFile(filename, classFile.getBytes())); + zos.putNextEntry(newEntry); + zos.write(classFile.getBytes()); + zos.closeEntry(); } - state.noteClassesFromFile(unitResult, sourceFileName, unwovenClassFiles); -// System.out.println("file: " + sourceFileName); -// for (int i=0; i < unitResult.simpleNameReferences.length; i++) { -// System.out.println("simple: " + new String(unitResult.simpleNameReferences[i])); -// } -// for (int i=0; i < unitResult.qualifiedReferences.length; i++) { -// System.out.println("qualified: " + -// new String(CharOperation.concatWith(unitResult.qualifiedReferences[i], '/'))); -// } - } else { - state.noteClassesFromFile(null, sourceFileName, Collections.EMPTY_LIST); - } + }; } - + + protected boolean proceedOnError() { + return true; //??? + } + +// public void noteClassFiles(AjCompiler.InterimResult result) { +// if (result == null) return; +// CompilationResult unitResult = result.result; +// String sourceFileName = result.fileName(); +// if (!(unitResult.hasErrors() && !proceedOnError())) { +// List unwovenClassFiles = new ArrayList(); +// Enumeration classFiles = unitResult.compiledTypes.elements(); +// while (classFiles.hasMoreElements()) { +// ClassFile classFile = (ClassFile) classFiles.nextElement(); +// String filename = new String(classFile.fileName()); +// filename = filename.replace('/', File.separatorChar) + ".class"; +// +// File destinationPath = buildConfig.getOutputDir(); +// if (destinationPath == null) { +// filename = new File(filename).getName(); +// filename = new File(extractDestinationPathFromSourceFile(unitResult), filename).getPath(); +// } else { +// filename = new File(destinationPath, filename).getPath(); +// } +// +// //System.out.println("classfile: " + filename); +// unwovenClassFiles.add(new UnwovenClassFile(filename, classFile.getBytes())); +// } +// state.noteClassesFromFile(unitResult, sourceFileName, unwovenClassFiles); +//// System.out.println("file: " + sourceFileName); +//// for (int i=0; i < unitResult.simpleNameReferences.length; i++) { +//// System.out.println("simple: " + new String(unitResult.simpleNameReferences[i])); +//// } +//// for (int i=0; i < unitResult.qualifiedReferences.length; i++) { +//// System.out.println("qualified: " + +//// new String(CharOperation.concatWith(unitResult.qualifiedReferences[i], '/'))); +//// } +// } else { +// state.noteClassesFromFile(null, sourceFileName, Collections.EMPTY_LIST); +// } +// } +// private void setBuildConfig(AjBuildConfig buildConfig) { this.buildConfig = buildConfig; @@ -564,5 +642,57 @@ public class AjBuildManager { public void setProgressListener(IProgressListener progressListener) { this.progressListener = progressListener; } + + + /* (non-Javadoc) + * @see org.aspectj.ajdt.internal.compiler.AjCompiler.IOutputClassFileNameProvider#getOutputClassFileName(char[]) + */ + public String getOutputClassFileName(char[] eclipseClassFileName, CompilationResult result) { + String filename = new String(eclipseClassFileName); + filename = filename.replace('/', File.separatorChar) + ".class"; + File destinationPath = buildConfig.getOutputDir(); + String outFile; + if (destinationPath == null) { + outFile = new File(filename).getName(); + outFile = new File(extractDestinationPathFromSourceFile(result), outFile).getPath(); + } else { + outFile = new File(destinationPath, filename).getPath(); + } + return outFile; + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.ICompilerAdapterFactory#getAdapter(org.eclipse.jdt.internal.compiler.Compiler) + */ + public ICompilerAdapter getAdapter(org.eclipse.jdt.internal.compiler.Compiler forCompiler) { + // complete compiler config and return a suitable adapter... + AjProblemReporter pr = + new AjProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), + forCompiler.options, getProblemFactory()); + + forCompiler.problemReporter = pr; + + AjLookupEnvironment le = + new AjLookupEnvironment(forCompiler, forCompiler.options, pr, environment); + EclipseFactory factory = new EclipseFactory(le); + le.factory = factory; + pr.factory = factory; + le.factory.buildManager = this; + + forCompiler.lookupEnvironment = le; + + forCompiler.parser = + new Parser( + pr, + forCompiler.options.parseLiteralExpressionsAsConstants); + + return new AjCompilerAdapter(forCompiler,batchCompile,bcelWorld,bcelWeaver, + factory, + getInterimResultRequestor(),this, + state.binarySourceFiles, + state.resultsFromFile.values(), + buildConfig.isNoWeave()); + } + } // class AjBuildManager diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java index db7ea2ab0..206bcec1a 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.aspectj.ajdt.internal.compiler.InterimCompilationResult; import org.aspectj.weaver.bcel.UnwovenClassFile; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; @@ -43,9 +44,10 @@ public class AjState { AjBuildConfig buildConfig; AjBuildConfig newBuildConfig; - Map/*<File, List<UnwovenClassFile>*/ classesFromFile = new HashMap(); +// Map/*<File, List<UnwovenClassFile>*/ classesFromFile = new HashMap(); + Map/*<File, CompilationResult*/ resultsFromFile = new HashMap(); Map/*<File, ReferenceCollection>*/ references = new HashMap(); - + Map/*File, List<UnwovenClassFile>*/ binarySourceFiles = new HashMap(); Map/*<String, UnwovenClassFile>*/ classesFromName = new HashMap(); ArrayList/*<String>*/ qualifiedStrings; @@ -143,13 +145,12 @@ public class AjState { File deletedFile = (File)i.next(); //System.out.println("deleting: " + deletedFile); addDependentsOf(deletedFile); - List unwovenClassFiles = (List)classesFromFile.get(deletedFile); - classesFromFile.remove(deletedFile); + InterimCompilationResult intRes = (InterimCompilationResult) resultsFromFile.get(deletedFile); + resultsFromFile.remove(deletedFile); //System.out.println("deleting: " + unwovenClassFiles); - if (unwovenClassFiles == null) continue; - for (Iterator j = unwovenClassFiles.iterator(); j.hasNext(); ) { - UnwovenClassFile classFile = (UnwovenClassFile)j.next(); - deleteClassFile(classFile); + if (intRes == null) continue; + for (int j=0; j<intRes.unwovenClassFiles().length; j++ ) { + deleteClassFile(intRes.unwovenClassFiles()[j]); } } } @@ -164,82 +165,151 @@ public class AjState { //!!! might be okay to ignore } } + + public void noteResult(InterimCompilationResult result) { + File sourceFile = new File(result.fileName()); + CompilationResult cr = result.result(); - public void noteClassesFromFile(CompilationResult result, String sourceFileName, List unwovenClassFiles) { - File sourceFile = new File(sourceFileName); - if (result != null) { - references.put(sourceFile, new ReferenceCollection(result.qualifiedReferences, result.simpleNameReferences)); + references.put(sourceFile, new ReferenceCollection(cr.qualifiedReferences, cr.simpleNameReferences)); } - - List previous = (List)classesFromFile.get(sourceFile); - List newClassFiles = new ArrayList(); - for (Iterator i = unwovenClassFiles.iterator(); i.hasNext();) { - UnwovenClassFile cf = (UnwovenClassFile) i.next(); - cf = writeClassFile(cf, findAndRemoveClassFile(cf.getClassName(), previous)); - newClassFiles.add(cf); - classesFromName.put(cf.getClassName(), cf); + + InterimCompilationResult previous = (InterimCompilationResult) resultsFromFile.get(sourceFile); + UnwovenClassFile[] unwovenClassFiles = result.unwovenClassFiles(); + for (int i = 0; i < unwovenClassFiles.length; i++) { + UnwovenClassFile lastTimeRound = removeFromPreviousIfPresent(unwovenClassFiles[i],previous); + recordClassFile(unwovenClassFiles[i],lastTimeRound); + classesFromName.put(unwovenClassFiles[i].getClassName(),unwovenClassFiles[i]); } - - if (previous != null && !previous.isEmpty()) { - for (Iterator i = previous.iterator(); i.hasNext();) { - UnwovenClassFile cf = (UnwovenClassFile) i.next(); - deleteClassFile(cf); + + if (previous != null) { + for (int i = 0; i < previous.unwovenClassFiles().length; i++) { + if (previous.unwovenClassFiles()[i] != null) { + deleteClassFile(previous.unwovenClassFiles()[i]); + } } } + resultsFromFile.put(sourceFile, result); - classesFromFile.put(sourceFile, newClassFiles); } - - private UnwovenClassFile findAndRemoveClassFile(String name, List previous) { + + private UnwovenClassFile removeFromPreviousIfPresent(UnwovenClassFile cf, InterimCompilationResult previous) { if (previous == null) return null; - for (Iterator i = previous.iterator(); i.hasNext();) { - UnwovenClassFile cf = (UnwovenClassFile) i.next(); - if (cf.getClassName().equals(name)) { - i.remove(); - return cf; - } + UnwovenClassFile[] unwovenClassFiles = previous.unwovenClassFiles(); + for (int i = 0; i < unwovenClassFiles.length; i++) { + UnwovenClassFile candidate = unwovenClassFiles[i]; + if ((candidate != null) && candidate.getFilename().equals(cf.getFilename())) { + unwovenClassFiles[i] = null; + return candidate; + } } return null; } + + private void recordClassFile(UnwovenClassFile thisTime, UnwovenClassFile lastTime) { + if (simpleStrings == null) return; // batch build - private UnwovenClassFile writeClassFile(UnwovenClassFile cf, UnwovenClassFile previous) { - if (simpleStrings == null) { // batch build - addedClassFiles.add(cf); - return cf; + if (lastTime == null) { + addDependentsOf(thisTime.getClassName()); + return; } - - try { - if (previous == null) { - addedClassFiles.add(cf); - addDependentsOf(cf.getClassName()); - return cf; - } - - byte[] oldBytes = previous.getBytes(); - byte[] newBytes = cf.getBytes(); - //if (this.compileLoop > 1) { // only optimize files which were recompiled during the dependent pass, see 33990 - notEqual : if (newBytes.length == oldBytes.length) { - for (int i = newBytes.length; --i >= 0;) { - if (newBytes[i] != oldBytes[i]) break notEqual; - } - //addedClassFiles.add(previous); //!!! performance wasting - buildManager.bcelWorld.addSourceObjectType(previous.getJavaClass()); - return previous; // bytes are identical so skip them + + byte[] newBytes = thisTime.getBytes(); + byte[] oldBytes = lastTime.getBytes(); + boolean bytesEqual = (newBytes.length == oldBytes.length); + for (int i = 0; (i < oldBytes.length) && bytesEqual; i++) { + if (newBytes[i] != oldBytes[i]) bytesEqual = false; + } + if (!bytesEqual) { + try { + ClassFileReader reader = new ClassFileReader(oldBytes, lastTime.getFilename().toCharArray()); + // ignore local types since they're only visible inside a single method + if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) { + addDependentsOf(lastTime.getClassName()); } - //} - ClassFileReader reader = new ClassFileReader(oldBytes, previous.getFilename().toCharArray()); - // ignore local types since they're only visible inside a single method - if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) { - addDependentsOf(cf.getClassName()); - } - } catch (ClassFormatException e) { - addDependentsOf(cf.getClassName()); + } catch (ClassFormatException e) { + addDependentsOf(lastTime.getClassName()); + } } - addedClassFiles.add(cf); - return cf; } + +// public void noteClassesFromFile(CompilationResult result, String sourceFileName, List unwovenClassFiles) { +// File sourceFile = new File(sourceFileName); +// +// if (result != null) { +// references.put(sourceFile, new ReferenceCollection(result.qualifiedReferences, result.simpleNameReferences)); +// } +// +// List previous = (List)classesFromFile.get(sourceFile); +// List newClassFiles = new ArrayList(); +// for (Iterator i = unwovenClassFiles.iterator(); i.hasNext();) { +// UnwovenClassFile cf = (UnwovenClassFile) i.next(); +// cf = writeClassFile(cf, findAndRemoveClassFile(cf.getClassName(), previous)); +// newClassFiles.add(cf); +// classesFromName.put(cf.getClassName(), cf); +// } +// +// if (previous != null && !previous.isEmpty()) { +// for (Iterator i = previous.iterator(); i.hasNext();) { +// UnwovenClassFile cf = (UnwovenClassFile) i.next(); +// deleteClassFile(cf); +// } +// } +// +// classesFromFile.put(sourceFile, newClassFiles); +// resultsFromFile.put(sourceFile, result); +// } +// +// private UnwovenClassFile findAndRemoveClassFile(String name, List previous) { +// if (previous == null) return null; +// for (Iterator i = previous.iterator(); i.hasNext();) { +// UnwovenClassFile cf = (UnwovenClassFile) i.next(); +// if (cf.getClassName().equals(name)) { +// i.remove(); +// return cf; +// } +// } +// return null; +// } +// +// private UnwovenClassFile writeClassFile(UnwovenClassFile cf, UnwovenClassFile previous) { +// if (simpleStrings == null) { // batch build +// addedClassFiles.add(cf); +// return cf; +// } +// +// try { +// if (previous == null) { +// addedClassFiles.add(cf); +// addDependentsOf(cf.getClassName()); +// return cf; +// } +// +// byte[] oldBytes = previous.getBytes(); +// byte[] newBytes = cf.getBytes(); +// //if (this.compileLoop > 1) { // only optimize files which were recompiled during the dependent pass, see 33990 +// notEqual : if (newBytes.length == oldBytes.length) { +// for (int i = newBytes.length; --i >= 0;) { +// if (newBytes[i] != oldBytes[i]) break notEqual; +// } +// //addedClassFiles.add(previous); //!!! performance wasting +// buildManager.bcelWorld.addSourceObjectType(previous.getJavaClass()); +// return previous; // bytes are identical so skip them +// } +// //} +// ClassFileReader reader = new ClassFileReader(oldBytes, previous.getFilename().toCharArray()); +// // ignore local types since they're only visible inside a single method +// if (!(reader.isLocal() || reader.isAnonymous()) && reader.hasStructuralChanges(newBytes)) { +// addDependentsOf(cf.getClassName()); +// } +// } catch (ClassFormatException e) { +// addDependentsOf(cf.getClassName()); +// } +// addedClassFiles.add(cf); +// return cf; +// } + private static StringSet makeStringSet(List strings) { StringSet ret = new StringSet(strings.size()); for (Iterator iter = strings.iterator(); iter.hasNext();) { @@ -309,12 +379,11 @@ public class AjState { } protected void addDependentsOf(File sourceFile) { - List l = (List)classesFromFile.get(sourceFile); - if (l == null) return; + InterimCompilationResult intRes = (InterimCompilationResult)resultsFromFile.get(sourceFile); + if (intRes == null) return; - for (Iterator i = l.iterator(); i.hasNext();) { - UnwovenClassFile cf = (UnwovenClassFile) i.next(); - addDependentsOf(cf.getClassName()); + for (int i = 0; i < intRes.unwovenClassFiles().length; i++) { + addDependentsOf(intRes.unwovenClassFiles()[i].getClassName()); } } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java index d93d6e8cf..e75143db5 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java @@ -21,7 +21,6 @@ import org.aspectj.bridge.Message; import org.aspectj.bridge.SourceLocation; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; -import org.eclipse.jdt.internal.compiler.util.Util; /** * @@ -42,7 +41,8 @@ public class EclipseAdapterUtils { if ((startPosition > endPosition) || ((startPosition <= 0) && (endPosition <= 0))) - return Util.bind("problem.noSourceInformation"); //$NON-NLS-1$ + //return Util.bind("problem.noSourceInformation"); //$NON-NLS-1$ + return "(no source information available)"; final char SPACE = '\u0020'; final char MARK = '^'; @@ -99,7 +99,7 @@ public class EclipseAdapterUtils { } } //mark the error position - for (int i = startPosition; + for (int i = startPosition + trimLeftIndex; // AMC if we took stuff off the start, take it into account! i <= (endPosition >= source.length ? source.length - 1 : endPosition); i++) underneath[pos++] = MARK; @@ -127,9 +127,29 @@ public class EclipseAdapterUtils { */ public static IMessage makeMessage(ICompilationUnit unit, IProblem problem) { ISourceLocation sourceLocation = makeSourceLocation(unit, problem); - return new Message(problem.getMessage(), sourceLocation, problem.isError()); + IProblem[] seeAlso = problem.seeAlso(); + ISourceLocation[] seeAlsoLocations = new ISourceLocation[seeAlso.length]; + for (int i = 0; i < seeAlso.length; i++) { + seeAlsoLocations[i] = new SourceLocation(new File(new String(seeAlso[i].getOriginatingFileName())), + seeAlso[i].getSourceLineNumber()); + + } + IMessage msg = new Message(problem.getMessage(), + problem.getSupplementaryMessageInfo(), + problem.isError() ? IMessage.ERROR : IMessage.WARNING, + sourceLocation, + null, + seeAlsoLocations); + return msg; } + public static IMessage makeErrorMessage(ICompilationUnit unit, String text, Exception ex) { + ISourceLocation loc = new SourceLocation(new File(new String(unit.getFileName())), + 0,0,0,""); + IMessage msg = new Message(text,IMessage.ERROR,ex,loc); + return msg; + } + private EclipseAdapterUtils() { } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java b/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java index e77a9f5a6..9d1fe890f 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/tools/ajc/Main.java @@ -425,7 +425,9 @@ public class Main { String name = file.getName(); if (!toString || (-1 == text.indexOf(name))) { sb.append(FileUtil.getBestPath(file)); - sb.append(":" + loc.getLine()); + if (loc.getLine() > 0) { + sb.append(":" + loc.getLine()); + } int col = loc.getColumn(); if (0 < col) { sb.append(":" + col); @@ -435,6 +437,14 @@ public class Main { } context = loc.getContext(); } + + // per Wes' suggestion on dev... + if (message.getKind() == IMessage.ERROR) { + sb.append("error "); + } else if (message.getKind() == IMessage.WARNING) { + sb.append("warning "); + } + sb.append(text); if (null != context) { sb.append(LangUtil.EOL); |