]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 112736
authoraclement <aclement>
Mon, 28 Nov 2005 12:58:59 +0000 (12:58 +0000)
committeraclement <aclement>
Mon, 28 Nov 2005 12:58:59 +0000 (12:58 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AbstractStateListener.java [new file with mode: 0644]
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjState.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/IStateListener.java
tests/src/org/aspectj/systemtest/incremental/IncrementalTests.java
tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java
tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java

diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AbstractStateListener.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AbstractStateListener.java
new file mode 100644 (file)
index 0000000..b92f806
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2005 IBM and other contributors
+ * 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: 
+ *     Andy Clement     initial implementation 
+ * ******************************************************************/
+package org.aspectj.ajdt.internal.core.builder;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Subtypes can override whatever they want...
+ * 
+ * @author AndyClement
+ *
+ */
+public abstract class AbstractStateListener implements IStateListener {
+
+       public void detectedClassChangeInThisDir(File f) {      }
+
+       public void aboutToCompareClasspaths(List oldClasspath, List newClasspath) {    }
+
+       public void pathChangeDetected() {      }
+
+       public void detectedAspectDeleted(File f) {     }
+
+       public void buildSuccessful(boolean wasFullBuild) {     }
+
+}
index 4e9c5552e2a138ce1a208779fab2397d7a6abf11..613b2baf5b5fcf13c7e3dcfe72e7843894819032 100644 (file)
@@ -38,6 +38,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFormatExcepti
 import org.aspectj.org.eclipse.jdt.internal.core.builder.ReferenceCollection;
 import org.aspectj.org.eclipse.jdt.internal.core.builder.StringSet;
 import org.aspectj.util.FileUtil;
+import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.bcel.BcelWeaver;
 import org.aspectj.weaver.bcel.BcelWorld;
 import org.aspectj.weaver.bcel.UnwovenClassFile;
@@ -147,11 +148,44 @@ public class AjState {
                addedBinaryFiles.removeAll(oldBinaryFiles);
                deletedBinaryFiles = new HashSet(oldBinaryFiles);
                deletedBinaryFiles.removeAll(newBinaryFiles);
+                       
+               boolean couldStillBeIncremental = processDeletedFiles(deletedFiles);
+               
+               if (!couldStillBeIncremental) return false;
                
                this.newBuildConfig = newBuildConfig;
                
                return true;
        }
+               
+       /**
+        * Checks if any of the files in the set passed in contains an aspect declaration.  If one is found
+        * then we start the process of batch building, i.e. we remove all the results of the last build,
+        * call any registered listener to tell them whats happened and return false.
+        * 
+        * @return false if we discovered an aspect declaration
+        */
+    private boolean processDeletedFiles(Set deletedFiles) {
+               for (Iterator iter = deletedFiles.iterator(); iter.hasNext();) {
+                       File  aDeletedFile = (File ) iter.next();
+                       InterimCompilationResult cr = (InterimCompilationResult)resultsFromFile.get(aDeletedFile);
+                       if (cr!=null) {
+                               Map compiledTypes = cr.result().compiledTypes;
+                               if (compiledTypes!=null) {
+                                       for (Iterator iterator = compiledTypes.keySet().iterator(); iterator.hasNext();) {
+                                               char[] className = (char[])iterator.next();
+                                               ResolvedType rt = world.resolve(new String(className).replace('/','.'));
+                                               if (rt.isAspect()) { 
+                                                       removeAllResultsOfLastBuild();
+                                                       if (stateListener!=null) stateListener.detectedAspectDeleted(aDeletedFile);
+                                                       return false;
+                                               }
+                                       }
+                               }
+                       }
+               }
+               return true;
+    }
        
        private Collection getModifiedFiles() {         
                return getModifiedFiles(lastSuccessfulBuildTime);
index 6739aa958fa7070a0da0f2d421ebe2928b0a6e5c..f88501a838e292a026e28b0ec0cf637d3cd68881 100644 (file)
@@ -32,6 +32,12 @@ public interface IStateListener {
        public void aboutToCompareClasspaths(List oldClasspath, List newClasspath);
 
        public void pathChangeDetected();
+       
+       /**
+        * Called if state processing detects a file was deleted that contained an aspect declaration.
+        * Incremental compilation will not be attempted if this occurs.
+        */
+       public void detectedAspectDeleted(File f);
 
        public void buildSuccessful(boolean wasFullBuild);
 
index 7294c54cb49e3af19b3d1829536597979accd343..9be1dbd4c1a4f73b498931e1f28434b97a6a2e45 100644 (file)
@@ -14,8 +14,8 @@ import java.util.List;
 
 import junit.framework.Test;
 
+import org.aspectj.ajdt.internal.core.builder.AbstractStateListener;
 import org.aspectj.ajdt.internal.core.builder.AjState;
-import org.aspectj.ajdt.internal.core.builder.IStateListener;
 import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class IncrementalTests extends org.aspectj.testing.XMLBasedAjcTestCase {
@@ -112,7 +112,7 @@ public class IncrementalTests extends org.aspectj.testing.XMLBasedAjcTestCase {
    * being on the classpath.  This test verifies the fix is OK
    */
   public void testIncrementalOKWithOutputPathOnClasspath() throws Exception {
-         class MyStateListener implements IStateListener {
+         class MyStateListener extends AbstractStateListener {
            public boolean pathChange = false;
                public void pathChangeDetected() {pathChange = true;}
                public void aboutToCompareClasspaths(List oldClasspath, List newClasspath) {}
index 118d5421190fb0619d023071f8a02077bc4e84f5..f7a1ef17ea9768745f31630c64ee020afc85417a 100644 (file)
@@ -29,8 +29,8 @@ import org.aspectj.ajde.BuildProgressMonitor;
 import org.aspectj.ajde.ErrorHandler;
 import org.aspectj.ajde.ProjectPropertiesAdapter;
 import org.aspectj.ajde.TaskListManager;
+import org.aspectj.ajdt.internal.core.builder.AbstractStateListener;
 import org.aspectj.ajdt.internal.core.builder.AjState;
-import org.aspectj.ajdt.internal.core.builder.IStateListener;
 import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
 import org.aspectj.asm.AsmManager;
 import org.aspectj.bridge.IMessage;
@@ -694,7 +694,7 @@ public class AjdeInteractionTestbed extends TestCase {
                }
        }
        
-       static class MyStateListener implements IStateListener {
+       static class MyStateListener extends AbstractStateListener {
                
                private static MyStateListener _instance = new MyStateListener();
                private MyStateListener() {reset();}
index 075840131240c5fd22e02a78036992db1e3cb3ff..df3255e7d2586e4385f4cb916df0ec24f9c8a053 100644 (file)
@@ -368,17 +368,17 @@ public class MultiProjectIncrementalTests extends AjdeInteractionTestbed {
                                        .getMessage());
        }
 
-//     public void testPr112736() {
-//             AjdeInteractionTestbed.VERBOSE = true;
-//             initialiseProject("PR112736");
-//             build("PR112736");
-//             checkWasFullBuild();
-//             String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR112736" + File.separatorChar + "src" + File.separatorChar + "pack" + File.separatorChar + "A.java";
-//             (new File(fileC2)).delete();
-//             alter("PR112736","inc1");
-//             build("PR112736");
-//             checkWasntFullBuild();
-//     }
+       public void testPr112736() {
+               AjdeInteractionTestbed.VERBOSE = true;
+               initialiseProject("PR112736");
+               build("PR112736");
+               checkWasFullBuild();
+               String fileC2 = getWorkingDir().getAbsolutePath() + File.separatorChar + "PR112736" + File.separatorChar + "src" + File.separatorChar + "pack" + File.separatorChar + "A.java";
+               (new File(fileC2)).delete();
+               alter("PR112736","inc1");
+               build("PR112736");
+               checkWasFullBuild();
+       }
        
        
        // other possible tests: