]> source.dussan.org Git - aspectj.git/commitdiff
fix for 95516 (-outxml / -outxmlfile) - from Matthew.
authoraclement <aclement>
Mon, 7 Nov 2005 10:53:18 +0000 (10:53 +0000)
committeraclement <aclement>
Mon, 7 Nov 2005 10:53:18 +0000 (10:53 +0000)
13 files changed:
ajde/testsrc/org/aspectj/ajde/AjdeTests.java
ajde/testsrc/org/aspectj/ajde/OutxmlTest.java [new file with mode: 0644]
docs/devGuideDB/ajc.xml
org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java
testing/newsrc/org/aspectj/testing/CompileSpec.java
testing/newsrc/org/aspectj/testing/RunSpec.java
tests/ltw/pakkage/Aspect3.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java
tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml

index dfe880ddbfe55ee468bb740833bef0f2158eab92..461dfc52f3c345ccec10b6deeaf3cba996eaf354 100644 (file)
@@ -59,6 +59,7 @@ public class AjdeTests extends TestCase {
                suite.addTestSuite(JarManifestTest.class);
                suite.addTestSuite(ExtensionTests.class);
                suite.addTestSuite(GenericsTest.class); 
+               suite.addTestSuite(OutxmlTest.class);
                
         //$JUnit-END$
         return suite;
diff --git a/ajde/testsrc/org/aspectj/ajde/OutxmlTest.java b/ajde/testsrc/org/aspectj/ajde/OutxmlTest.java
new file mode 100644 (file)
index 0000000..2ccb66b
--- /dev/null
@@ -0,0 +1,93 @@
+/* *******************************************************************
+ * Copyright (c) 2003 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: 
+ *     Matthew Webster     initial implementation 
+ * ******************************************************************/
+package org.aspectj.ajde;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.aspectj.util.FileUtil;
+
+public class OutxmlTest extends AjdeTestCase {
+
+       public static final String PROJECT_DIR = "OutxmlTest";
+       public static final String BIN_DIR = "bin";
+       public static final String OUTJAR_NAME = "/bin/test.jar"; 
+       public static final String DEFAULT_AOPXML_NAME = "META-INF/aop.xml"; 
+       public static final String CUSTOM_AOPXML_NAME = "custom/aop.xml"; 
+
+       /*
+        * Ensure the output directory is clean
+        */
+       protected void setUp() throws Exception {
+               super.setUp(PROJECT_DIR);
+               FileUtil.deleteContents(openFile(BIN_DIR));
+       }
+
+
+       /**
+        * Aim: Test "-outxml" option produces the correct xml file
+        * 
+        */
+       public void testOutxmlToFile () {
+//             System.out.println("OutxmlTest.testOutxmlToFile() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
+               assertTrue("Build failed",doSynchronousBuild("outxml-to-file.lst"));
+               assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
+               
+               File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME);
+               assertTrue(DEFAULT_AOPXML_NAME + " missing",aopxml.exists());
+       }
+
+       /**
+        * Aim: Test "-outxmlfile filename" option produces the correct 
+        * xml file
+        * 
+        */
+       public void testOutxmlfileToFile () {
+               assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-file.lst"));
+               assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
+               
+               File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
+               assertTrue(CUSTOM_AOPXML_NAME + " missing",aopxml.exists());
+       }
+
+       /**
+        * Aim: Test "-outxmlfile filename" option produces the correct 
+        * xml entry in outjar file
+        * 
+        */
+       public void testOutxmlfileToOutjar () {
+//             System.out.println("OutxmlTest.testOutxmlToOutjar() outputpath='" + ideManager.getProjectProperties().getOutputPath() + "'");
+               File outjar = openFile(OUTJAR_NAME);
+               ideManager.getProjectProperties().setOutJar(outjar.getAbsolutePath());
+               assertTrue("Build failed",doSynchronousBuild("outxmlfile-to-outjar.lst"));
+               assertTrue("Build warnings",ideManager.getCompilationSourceLineTasks().isEmpty());
+               
+               File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME);
+               assertFalse(CUSTOM_AOPXML_NAME + " should not exisit",aopxml.exists());
+               assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME);
+       }
+
+       private void assertJarContainsEntry (File file, String entryName) {
+       
+               try {
+                       JarFile jarFile = new JarFile(file);
+                       JarEntry jarEntry = jarFile.getJarEntry(entryName);
+                       assertNotNull(entryName + " missing",jarEntry);
+               }
+               catch (IOException ex) {
+                       fail(ex.toString());
+               }
+       }
+
+}
index ea2cab2daa3844ddce05ff611211cd58a637b741..ef3438987329987ff03c4504f319b0a280d432b9 100644 (file)
         </para></listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term>-outxml</term>
+        <listitem><para>Generate aop.xml file for load-time weaving with default name.
+        </para></listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>-outxmlfile <replaceable>custom/aop.xml</replaceable></term>
+        <listitem><para>Generate aop.xml file for load-time weaving with custom name.
+        </para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term>-incremental</term>
         <listitem><para>Run the compiler continuously.
index 84498d49408bdeb6669c86bf8f6f4bb737500c35..74135e9b659945a6f64059903c7c3e9140cbf2f1 100644 (file)
@@ -492,6 +492,16 @@ public class BuildArgParser extends Main {
                                } else {
                                        showError("-outjar requires jar path argument");
                                }
+                       } else if (arg.equals("-outxml")) { 
+                buildConfig.setOutxmlName("META-INF/aop.xml");  
+                       } else if (arg.equals("-outxmlfile")) { 
+                               if (args.size() > nextArgIndex) {
+                                       String name = ((ConfigParser.Arg)args.get(nextArgIndex)).getValue();
+                       buildConfig.setOutxmlName(name);  
+                                       args.remove(args.get(nextArgIndex));
+                               } else {
+                                       showError("-outxmlfile requires file name argument");
+                               }
             } else if (arg.equals("-log")){
                                // remove it as it's already been handled in org.aspectj.tools.ajc.Main
                                args.remove(args.get(nextArgIndex));
index d5f80f1a894ab783a5c48a9016ac31f27a44dd39..8b5cf2132b65a56c0b82006017832fe528b560d4 100644 (file)
@@ -42,6 +42,7 @@ public class AjBuildConfig {
        
        private File outputDir;
        private File outputJar;
+       private String outxmlName;
        private List/*File*/ sourceRoots = new ArrayList();
        private List/*File*/ files = new ArrayList();
        private List /*File*/ binaryFiles = new ArrayList();  // .class files in indirs...
@@ -165,6 +166,10 @@ public class AjBuildConfig {
        public File getOutputJar() {
                return outputJar;
        }
+
+       public String getOutxmlName() {
+               return outxmlName;
+       }
        
        public List/*File*/ getInpath() {
                // Elements of the list are either archives (jars/zips) or directories
@@ -183,6 +188,10 @@ public class AjBuildConfig {
                this.outputJar = outputJar;
        }
 
+       public void setOutxmlName(String name) {
+               this.outxmlName = name;
+       }
+
        public void setInJars(List sourceJars) {
                this.inJars = sourceJars;
        }
index bbcb8ea9bfd9e915246cbccb22f6ba37c06fb3c5..9cb561ea295181c7a3de3483d83bc81c769f5748 100644 (file)
 package org.aspectj.ajdt.internal.core.builder;
 
 import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -125,6 +128,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
        // FIXME asc should this really be in here?
        private IHierarchy structureModel;
        public AjBuildConfig buildConfig;
+       private List aspectNames = new LinkedList();
        
        AjState state = new AjState(this);
     
@@ -281,6 +285,11 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
             state.successfulCompile(buildConfig,batch);
 
             copyResourcesToDestination();
+            
+            if (buildConfig.getOutxmlName() != null) {
+               writeOutxmlFile();
+            }
+            
             /*boolean weaved = *///weaveAndGenerateClassFiles();
             // if not weaved, then no-op build, no model changes
             // but always returns true
@@ -480,7 +489,38 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                }
        }
        
+       private void writeOutxmlFile () throws IOException {
+               String filename = buildConfig.getOutxmlName();
+//             System.err.println("? AjBuildManager.writeOutxmlFile() outxml=" + filename);
+//             System.err.println("? AjBuildManager.writeOutxmlFile() outputDir=" + buildConfig.getOutputDir());
+               
+               ByteArrayOutputStream baos = new ByteArrayOutputStream();
+               PrintStream ps = new PrintStream(baos);
+               ps.println("<aspectj>");
+               ps.println("<aspects>");
+               for (Iterator i = aspectNames.iterator(); i.hasNext();) {
+                       String name = (String)i.next();
+                       ps.println("<aspect name=\"" + name + "\"/>");
+               }
+               ps.println("</aspects>");
+               ps.println("</aspectj>");
+               ps.println();
+               ps.close();
 
+               if (zos != null) {
+                       ZipEntry newEntry = new ZipEntry(filename);
+                       
+                       zos.putNextEntry(newEntry);
+                       zos.write(baos.toByteArray());
+                       zos.closeEntry();
+               } else {
+                       OutputStream fos = 
+                               FileUtil.makeOutputStream(new File(buildConfig.getOutputDir(),filename));
+                       fos.write(baos.toByteArray());
+                       fos.close();
+               }
+       }
+       
 //     public static void dumprels() {
 //             IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
 //             int ctr = 1;
@@ -792,11 +832,13 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                        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())) {                                   
+                               if (!(unitResult.hasErrors() && !proceedOnError())) {                   
                                        Collection classFiles = unitResult.compiledTypes.values();
+                                       boolean shouldAddAspectName = (buildConfig.getOutxmlName() != null);
                                        for (Iterator iter = classFiles.iterator(); iter.hasNext();) {
                                                ClassFile classFile = (ClassFile) iter.next();                                  
                                                String filename = new String(classFile.fileName());
+                                               String classname = filename.replace('/', '.');
                                                filename = filename.replace('/', File.separatorChar) + ".class";
                                                try {
                                                        if (buildConfig.getOutputJar() == null) {
@@ -804,6 +846,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                                                        } else {
                                                                writeZipEntry(classFile,filename);
                                                        }
+                                                       if (shouldAddAspectName) addAspectName(classname);
                                                } catch (IOException ex) {
                                                        IMessage message = EclipseAdapterUtils.makeErrorMessage(
                                                                        new String(unitResult.fileName),
@@ -854,6 +897,15 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                                zos.write(classFile.getBytes());
                                zos.closeEntry();
                        }
+                       
+                       private void addAspectName (String name) {
+                               BcelWorld world = getBcelWorld();
+                               ResolvedType type = world.resolve(name);
+//                             System.err.println("? writeAspectName() type=" + type);
+                               if (type.isAspect()) {
+                                       aspectNames.add(name);
+                               }
+                       }
                };
        }
        
index a020afe9f341754ddc25ebc41c78526b593bed08..e207fe91ca7eea38acf26c2cde0ea33ab93059ab 100644 (file)
@@ -21,6 +21,8 @@ import org.aspectj.ajdt.internal.core.builder.*;
 import org.aspectj.bridge.CountingMessageHandler;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.IMessageHandler;
+import org.aspectj.bridge.IMessageHolder;
+import org.aspectj.bridge.MessageHandler;
 import org.aspectj.bridge.MessageWriter;
 import org.aspectj.testing.util.TestUtil;
 import org.aspectj.org.eclipse.jdt.core.compiler.InvalidInputException;
@@ -490,6 +492,22 @@ public class BuildArgParserTestCase extends TestCase {
                genBuildConfig(new String[] { TEST_DIR + "X.aj", TEST_DIR + "Y.aj"}, messageWriter);
        }
        
+       public void testOutxml () {
+               IMessageHolder messageHolder = new MessageHandler();
+               AjBuildConfig config = genBuildConfig(new String[] { "-outxml", "-showWeaveInfo" }, messageHolder);
+        assertTrue("Warnings: " + messageHolder,!messageHolder.hasAnyMessage(IMessage.WARNING, true));
+               assertEquals("Wrong outxml","META-INF/aop.xml",config.getOutxmlName());
+               assertTrue("Following option currupted",config.getShowWeavingInformation());
+       }
+       
+       public void testOutxmlfile () {
+               IMessageHolder messageHolder = new MessageHandler();
+               AjBuildConfig config = genBuildConfig(new String[] { "-outxmlfile", "custom/aop.xml", "-showWeaveInfo" }, messageHolder);
+        assertTrue("Warnings: " + messageHolder,!messageHolder.hasAnyMessage(IMessage.WARNING, true));
+               assertEquals("Wrong outxml","custom/aop.xml",config.getOutxmlName());
+               assertTrue("Following option currupted",config.getShowWeavingInformation());
+       }
+       
        protected void setUp() throws Exception {
                super.setUp();
        }
index 1b50387b028934a37b168e5c738dea39f9298391..6b98a682274a059df1a8605b3473df3e55e94d5e 100644 (file)
@@ -37,6 +37,7 @@ public class CompileSpec implements ITestStep {
        private String inpath;
        private String sourceroots;
        private String outjar;
+       private String outxml;
        private String xlintfile;
        private String options;
        private String baseDir;
@@ -166,6 +167,20 @@ public class CompileSpec implements ITestStep {
        public void setOutjar(String outjar) {
                this.outjar = outjar;
        }
+
+       /**
+        * @return Returns the outxml.
+        */
+       public String getOutxmlfile() {
+               return outxml;
+       }
+
+       /**
+        * @param outxml The the of the aop.xml file to generate
+        */
+       public void setOutxmlfile(String outxml) {
+               this.outxml = outxml;
+       }
        /**
         * @return Returns the sourceroots.
         */
@@ -212,6 +227,11 @@ public class CompileSpec implements ITestStep {
                        args.append(getOutjar());
                        args.append(" ");
                }
+               if (getOutxmlfile() != null) {
+                       args.append("-outxmlfile ");
+                       args.append(getOutxmlfile());
+                       args.append(" ");
+               }
                if (getOptions() != null) {
                        StringTokenizer strTok = new StringTokenizer(getOptions(),",");
                        while (strTok.hasMoreTokens()) {
index 0716b8362d5424aaf4a680d117533764caa2c1c6..891600dbf57081e4f791c0619541915ba4c79060 100644 (file)
@@ -130,6 +130,9 @@ public class RunSpec implements ITestStep {
                boolean useLtw = false;
                
                if (ltwFile != null) {
+            // TODO maw use flag rather than empty file name
+                       if (ltwFile.trim().length() == 0) return true;
+                       
                        File from = new File(baseDir,ltwFile);
                        File to = new File(sandboxDirectory,"META-INF" + File.separator + "aop.xml");
 //                     System.out.println("RunSpec.copyLtwFile() from=" + from.getAbsolutePath() + " to=" + to.getAbsolutePath());
diff --git a/tests/ltw/pakkage/Aspect3.aj b/tests/ltw/pakkage/Aspect3.aj
new file mode 100644 (file)
index 0000000..0889425
--- /dev/null
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors:
+ *   Matthew Webster   initial implementation
+ *******************************************************************************/
+package pakkage;
+
+import org.aspectj.lang.JoinPoint;
+
+public aspect Aspect3 {
+       
+               declare precedence : *, Aspect3;
+       
+               before () : execution(void Main.test2()){
+                       System.err.println("pakkage.Aspect3.before_" + thisJoinPoint.getSignature().getName());
+               }
+}
index 3a75602901385c309983003475c0bc775ce8dd54..915c557945bfcf1162fb1343f301c8ad24137384 100644 (file)
@@ -51,7 +51,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testITDCtor_pr112783()       { runTest("Problem with constructor ITDs");}
   */
   
-  //public void testPossibleStaticImports_pr113066() { runTest("possible static imports bug");}
+  public void testPossibleStaticImports_pr113066() { runTest("possible static imports bug");}
   public void testBrokenDecp_pr112476()       { runTest("binary weaving decp broken");}
   public void testUnboundFormal_pr112027()    { runTest("unexpected error unboundFormalInPC");}
   public void testNPEScopeSetup_pr115038()    { runTest("NPE in ensureScopeSetup");}
index 543d586e80aee332668e477466ea427d31dbe721..3b489cf07a496d5c7a68c6c9141f6627b182d6c3 100644 (file)
@@ -28,8 +28,15 @@ public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase {
   }
 
 
-  public void test001(){
-    runTest("Ensure 1st aspect is rewoven when weaving 2nd aspect");
-  }
+       public void test001(){
+               runTest("Ensure 1st aspect is rewoven when weaving 2nd aspect");
+       }
+
+       public void testOutxmlFile (){
+           runTest("Ensure valid aop.xml file is generated");
+       }
+       public void testOutxmlJar (){
+           runTest("Ensure valid aop.xml is generated for -outjar");
+       }
 }
 
index 0e818afbf7aa76889854c4bc1cd3c063e3e09261..34f2f3dab8d8a8f298222c9c6cdc1ac49b93b615 100644 (file)
         </run>
     </ajc-test>
 
+       <ajc-test dir="ltw"
+      title="Ensure valid aop.xml file is generated"
+      keywords="-outxml">
+        <compile
+               files="Main.java"
+                       outjar="main.jar"
+        >
+        </compile>     
+        <compile
+               classpath="main.jar"
+               files="Aspect1.aj, Aspect2.aj, pakkage/Aspect3.aj"
+               outxmlfile="META-INF/aop.xml"
+        >
+        </compile>     
+        <run class="Main" ltw="">
+               <stdout>
+                <line text="Main.main"/>
+                <line text="Main.test1"/>
+                <line text="Main.test2"/>
+            </stdout>
+               <stderr>
+                <line text="Aspect1.before_test1"/>
+                <line text="Aspect2.before_test2"/>
+                <line text="pakkage.Aspect3.before_test2"/>
+            </stderr>
+        </run>
+    </ajc-test>
+
+       <ajc-test dir="ltw"
+      title="Ensure valid aop.xml is generated for -outjar"
+      keywords="-outxml">
+        <compile
+               files="Main.java"
+                       outjar="main.jar"
+        >
+        </compile>     
+        <compile
+               classpath="main.jar"
+               files="Aspect1.aj, Aspect2.aj, pakkage/Aspect3.aj"
+               outjar="aspects.jar"
+               options="-outxml"
+        >
+        </compile>     
+        <run class="Main" ltw="">
+               <stdout>
+                <line text="Main.main"/>
+                <line text="Main.test1"/>
+                <line text="Main.test2"/>
+            </stdout>
+               <stderr>
+                <line text="Aspect1.before_test1"/>
+                <line text="Aspect2.before_test2"/>
+                <line text="pakkage.Aspect3.before_test2"/>
+            </stderr>
+        </run>
+    </ajc-test>
+