]> source.dussan.org Git - aspectj.git/commitdiff
245566: introduced name environment sharing across compiles through the state object
authoraclement <aclement>
Fri, 29 Aug 2008 21:18:33 +0000 (21:18 +0000)
committeraclement <aclement>
Fri, 29 Aug 2008 21:18:33 +0000 (21:18 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java

index 4b9ae7575f9a552905a76ced9dc095b837eb3b4a..f1df1d0287e0f3374c01d6394b051076db99f5c0 100644 (file)
@@ -374,6 +374,12 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                return ret;
        }
 
+       /**
+        * Open an output jar file in which to write the compiler output.
+        * 
+        * @param outJar the jar file to open
+        * @return true if successful
+        */
        private boolean openOutputStream(File outJar) {
                try {
                        OutputStream os = FileUtil.makeOutputStream(buildConfig.getOutputJar());
@@ -389,8 +395,9 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
 
        private void closeOutputStream(File outJar) {
                try {
-                       if (zos != null)
+                       if (zos != null) {
                                zos.close();
+                       }
                        zos = null;
 
                        /* Ensure we don't write an incomplete JAR bug-71339 */
@@ -856,37 +863,11 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                }
        }
 
-       // 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 = buildConfig.getOptions().defaultEncoding;
-               if ("".equals(defaultEncoding)) //$NON-NLS-1$
+               if ("".equals(defaultEncoding)) {//$NON-NLS-1$
                        defaultEncoding = null; //$NON-NLS-1$   
+               }
                // Bug 46671: We need an array as long as the number of elements in the classpath - *even though* not every
                // element of the classpath is likely to be a directory. If we ensure every element of the array is set to
                // only look for BINARY, then we make sure that for any classpath element that is a directory, we won't build
@@ -938,36 +919,42 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                        sourceFileCount = files.size();
                        progressListener.setText("compiling source files");
                }
-               // System.err.println("got files: " + files);
+
+               // Translate from strings to File objects
                String[] filenames = new String[files.size()];
-               int ii = 0;
+               int idx = 0;
                for (Iterator fIterator = files.iterator(); fIterator.hasNext();) {
                        File f = (File) fIterator.next();
-                       filenames[ii++] = f.getPath();
+                       filenames[idx++] = f.getPath();
                }
 
-               List cps = buildConfig.getFullClasspath();
-               Dump.saveFullClasspath(cps);
-               String[] classpaths = new String[cps.size()];
-               for (int i = 0; i < cps.size(); i++) {
-                       classpaths[i] = (String) cps.get(i);
+               environment = state.getNameEnvironment();
+
+               boolean environmentNeedsRebuilding = false;
+
+               // Might be a bit too cautious, but let us see how it goes
+               if (buildConfig.getChanged() != AjBuildConfig.NO_CHANGES) {
+                       environmentNeedsRebuilding = true;
                }
 
-               // System.out.println("compiling");
-               environment = getLibraryAccess(classpaths, filenames);
+               if (environment == null || environmentNeedsRebuilding) {
+                       List cps = buildConfig.getFullClasspath();
+                       Dump.saveFullClasspath(cps);
+                       String[] classpaths = new String[cps.size()];
+                       for (int i = 0; i < cps.size(); i++) {
+                               classpaths[i] = (String) cps.get(i);
+                       }
+                       environment = new StatefulNameEnvironment(getLibraryAccess(classpaths, filenames), state.getClassNameToFileMap(), state);
+                       state.setNameEnvironment(environment);
 
-               // if (!state.getClassNameToFileMap().isEmpty()) { // see pr133532 (disabled to state can be used to answer questions)
-               environment = new StatefulNameEnvironment(environment, state.getClassNameToFileMap(), state);
-               // }
+               }
 
                org.aspectj.ajdt.internal.compiler.CompilerAdapter.setCompilerAdapterFactory(this);
                org.aspectj.org.eclipse.jdt.internal.compiler.Compiler compiler = new org.aspectj.org.eclipse.jdt.internal.compiler.Compiler(
                                environment, DefaultErrorHandlingPolicies.proceedWithAllProblems(), buildConfig.getOptions().getMap(),
                                getBatchRequestor(), getProblemFactory());
 
-               CompilerOptions options = compiler.options;
-
-               options.produceReferenceInfo = true; // TODO turn off when not needed
+               compiler.options.produceReferenceInfo = true; // TODO turn off when not needed
 
                try {
                        compiler.compile(getCompilationUnits(filenames));
@@ -977,8 +964,8 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour
                // cleanup
                org.aspectj.ajdt.internal.compiler.CompilerAdapter.setCompilerAdapterFactory(null);
                AnonymousClassPublisher.aspectOf().setAnonymousClassCreationListener(null);
-               environment.cleanup();
-               environment = null;
+               // environment.cleanup();
+               // environment = null;
        }
 
        /*
index 9ef6ddce4b78534357e74fc110cfe333ea72e802..18c0ce42e0db95718adc1c6ca5e2563d287eea24 100644 (file)
@@ -44,6 +44,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFormatExcepti
 import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryField;
 import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryMethod;
 import org.aspectj.org.eclipse.jdt.internal.compiler.env.IBinaryType;
+import org.aspectj.org.eclipse.jdt.internal.compiler.env.INameEnvironment;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
 import org.aspectj.org.eclipse.jdt.internal.core.builder.ReferenceCollection;
 import org.aspectj.org.eclipse.jdt.internal.core.builder.StringSet;
@@ -74,6 +75,7 @@ public class AjState implements CompilerConfigurationChangeFlags {
 
        private AjBuildManager buildManager;
        private boolean couldBeSubsequentIncrementalBuild = false;
+       private INameEnvironment nameEnvironment;
 
        private IHierarchy structureModel;
        private IRelationshipMap relmap;
@@ -1690,4 +1692,12 @@ public class AjState implements CompilerConfigurationChangeFlags {
        public AjBuildManager getAjBuildManager() {
                return buildManager;
        }
+
+       public INameEnvironment getNameEnvironment() {
+               return this.nameEnvironment;
+       }
+
+       public void setNameEnvironment(INameEnvironment nameEnvironment) {
+               this.nameEnvironment = nameEnvironment;
+       }
 }