]> source.dussan.org Git - aspectj.git/commitdiff
132591 - Duplicate exception with aop.xml file on aspectpath
authormwebster <mwebster>
Fri, 2 Jun 2006 12:47:08 +0000 (12:47 +0000)
committermwebster <mwebster>
Fri, 2 Jun 2006 12:47:08 +0000 (12:47 +0000)
ajde/testdata/OutxmlTest/outxml-to-outjar-with-aop_xml.lst [new file with mode: 0644]
ajde/testdata/OutxmlTest/src-resources/META-INF/aop.xml [new file with mode: 0644]
ajde/testsrc/org/aspectj/ajde/NullIdeProperties.java
ajde/testsrc/org/aspectj/ajde/OutxmlTest.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java

diff --git a/ajde/testdata/OutxmlTest/outxml-to-outjar-with-aop_xml.lst b/ajde/testdata/OutxmlTest/outxml-to-outjar-with-aop_xml.lst
new file mode 100644 (file)
index 0000000..87c9802
--- /dev/null
@@ -0,0 +1 @@
+-outxml
diff --git a/ajde/testdata/OutxmlTest/src-resources/META-INF/aop.xml b/ajde/testdata/OutxmlTest/src-resources/META-INF/aop.xml
new file mode 100644 (file)
index 0000000..77505c7
--- /dev/null
@@ -0,0 +1,2 @@
+<aspectj>
+</aspectj>
\ No newline at end of file
index dd06f9ecaa390d5609b438ffc75ce5f07adde6d4..5a38d443dca0eda0f05a2fc2963b465f639ca47e 100644 (file)
@@ -120,19 +120,32 @@ public class NullIdeProperties implements ProjectPropertiesAdapter {
     }
     
        public Map getSourcePathResources() {
-               File srcBase = new File(getProjectSourcePath());
-               File[] fromResources = FileUtil.listFiles(srcBase, new FileFilter() {
-                       public boolean accept(File pathname) {
-                               String name = pathname.getName().toLowerCase();
-                               return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj");
-                       }
-               });
                Map map = new HashMap();
-               for (int i = 0; i < fromResources.length; i++) {
-                       String normPath = FileUtil.normalizedPath(fromResources[i] ,srcBase);
-                       map.put(normPath, fromResources[i]);
 
+               /* Allow the user to override the testProjectPath by using sourceRoots */ 
+               File[] srcBase;
+               if (sourceRoots == null || sourceRoots.isEmpty()) {
+                       srcBase = new File[] { new File(getProjectSourcePath()) };
+               }
+               else {
+                       srcBase = new File[sourceRoots.size()];
+                       sourceRoots.toArray(srcBase);
+               }
+               
+               for (int j = 0; j < srcBase.length; j++) {
+                       File[] fromResources = FileUtil.listFiles(srcBase[j], new FileFilter() {
+                               public boolean accept(File pathname) {
+                                       String name = pathname.getName().toLowerCase();
+                                       return !name.endsWith(".class") && !name.endsWith(".java") && !name.endsWith(".aj");
+                               }
+                       });
+                       for (int i = 0; i < fromResources.length; i++) {
+                               String normPath = FileUtil.normalizedPath(fromResources[i] ,srcBase[j]);
+                               map.put(normPath, fromResources[i]);
+
+                       }
                }
+               
                return map;
        }
 
index ca01e4c78234a06b940f7774383918916dba9669..b4fff912b6c8f4f9fef7d4a04a2604dad1297bb6 100644 (file)
@@ -13,6 +13,9 @@ package org.aspectj.ajde;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 
@@ -103,6 +106,30 @@ public class OutxmlTest extends AjdeTestCase {
                assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME);
        }
 
+       /**
+        * Aim: Test "-outxml" option produces a warning if "META-INF/aop.xml 
+        * already exists in source
+        * 
+        */
+       public void testOutxmlToOutjarWithAop_xml () {
+               File f = new File( AjdeTests.testDataPath(PROJECT_DIR + "/src-resources"));
+               Set roots = new HashSet();
+               roots.add(f);
+               ideManager.getProjectProperties().setSourceRoots(roots);
+               File outjar = openFile(OUTJAR_NAME);
+               ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
+               assertTrue("Build failed: " + ideManager.getCompilationSourceLineTasks(),doSynchronousBuild("outxml-to-outjar-with-aop_xml.lst"));
+//             assertTrue("Build warnings: " + ideManager.getCompilationSourceLineTasks(),ideManager.getCompilationSourceLineTasks().isEmpty());
+               assertFalse("Build warnings for exisiting resource expected",ideManager.getCompilationSourceLineTasks().isEmpty());
+               List msgs = NullIdeManager.getIdeManager().getCompilationSourceLineTasks();
+               String msg = ((NullIdeTaskListManager.SourceLineTask)msgs.get(0)).message.getMessage();
+               assertTrue("Wrong message: " + msg,msg.startsWith("-outxml/-outxmlfile option ignored because resource already exists:"));
+               
+               File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
+               assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists());
+               assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME);
+       }
+
        private void assertJarContainsEntry (File file, String entryName) {
        
                try {
index eb02ba5c7283dc80ddd32887e27243e894d7b2e2..d2b09def22fdd5a8c772ca53430d874141425a1d 100644 (file)
@@ -132,6 +132,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
        // FIXME asc should this really be in here?
        private IHierarchy structureModel;
        public AjBuildConfig buildConfig;
+       private boolean ignoreOutxml;
        
        AjState state = new AjState(this);
     
@@ -495,6 +496,14 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                        handler.handleMessage(msg);
                        return;
                }
+               if (filename.equals(buildConfig.getOutxmlName())) {
+                       ignoreOutxml = true;
+                       IMessage msg = new Message("-outxml/-outxmlfile option ignored because resource already exists: '" + filename + "'",
+                                          IMessage.WARNING,
+                                          null,
+                                          new SourceLocation(srcLocation,0));
+                       handler.handleMessage(msg);
+               }
                if (zos != null) {
                        ZipEntry newEntry = new ZipEntry(filename);  //??? get compression scheme right
                        
@@ -555,6 +564,8 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
        }
        
        private void writeOutxmlFile () throws IOException {
+               if (ignoreOutxml) return;
+               
                String filename = buildConfig.getOutxmlName();
 //             System.err.println("? AjBuildManager.writeOutxmlFile() outxml=" + filename);
 //             System.err.println("? AjBuildManager.writeOutxmlFile() outputDir=" + buildConfig.getOutputDir());