]> source.dussan.org Git - aspectj.git/commitdiff
tests and fixes for 148906: Support -Xlintfile for ajdoc
authoraclement <aclement>
Mon, 23 Oct 2006 12:49:11 +0000 (12:49 +0000)
committeraclement <aclement>
Mon, 23 Oct 2006 12:49:11 +0000 (12:49 +0000)
13 files changed:
ajdoc/src/org/aspectj/tools/ajdoc/CompilerWrapper.java
ajdoc/src/org/aspectj/tools/ajdoc/Config.java
ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java
ajdoc/src/org/aspectj/tools/ajdoc/Main.java
ajdoc/testdata/pr148906/AdviceDidNotMatch.aj [new file with mode: 0644]
ajdoc/testdata/pr148906/C.java [new file with mode: 0644]
ajdoc/testdata/pr148906/README.txt [new file with mode: 0644]
ajdoc/testdata/pr148906/Xlint.properties [new file with mode: 0644]
ajdoc/testdata/pr148906/simple.jar [new file with mode: 0644]
ajdoc/testdata/pr160302/C.java [new file with mode: 0644]
ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/BugTests.java [new file with mode: 0644]

index 8c4e90d5b915a46b34a426e62ba130d7d4788b97..cf8c15edf1bde506e7412ad7bf057dbf4d19fd31 100644 (file)
@@ -11,6 +11,8 @@
  * ******************************************************************/
  package org.aspectj.tools.ajdoc;
 
+import org.aspectj.bridge.IMessage;
+
 /**
  * Wrapper for ajdoc's use of the AspectJ compiler.
  * 
@@ -29,4 +31,8 @@ public class CompilerWrapper extends org.aspectj.tools.ajc.Main {
        public static boolean hasErrors() {
                return INSTANCE.ourHandler.getErrors().length > 0;
        }
+       
+       public static IMessage[] getErrors() {
+               return INSTANCE.ourHandler.getErrors();
+       }
 }
index aaa214fcfe0ab12b1685b65c865ed1662e1d337e..eeea9d9c93f8b9f3bcb992de96b560876186f96a 100644 (file)
@@ -36,9 +36,11 @@ interface Config {
                                "  -argfile <file>           Build config file (wildcards not supported)\n" +
                                "  -verbose                  Output messages about what Javadoc is doing\n" +
                                "  -v                        Print out the version of ajdoc\n" +
-                                                          "  -source <version>         set source level (1.3, 1.4 or 1.5)" +
+                                                          "  -source <version>         set source level (1.3, 1.4 or 1.5)\n" +
+                                                          "\n" +
+                               "as well as the AspectJ Compiler options.\n" +
                                "\n"+
                                "If an argument is of the form @<filename>, the file will be interpreted as\n"+
-                               "a line delimited set of arguments to insert into the argument list.";
+                               "a line delimited set of arguments to insert into the argument list.\n";
 
 }
index e4225caf5fe97d303c482b73d85fde47fb4ea247..fd9821f92245fa5680f4e33ab59432ceb69d9dc5 100644 (file)
@@ -431,12 +431,24 @@ class HtmlDecorator {
     }
 
     private static boolean isAboveVisibility(IProgramElement element) {
-        return 
-            (docVisibilityModifier.equals("private")) || // everything
-            (docVisibilityModifier.equals("package") && element.getAccessibility().equals(IProgramElement.Accessibility.PACKAGE)) || // package
-            (docVisibilityModifier.equals("protected") && (element.getAccessibility().equals(IProgramElement.Accessibility.PROTECTED) ||
-                    element.getAccessibility().equals(IProgramElement.Accessibility.PUBLIC))) ||
-            (docVisibilityModifier.equals("public") && element.getAccessibility().equals(IProgramElement.Accessibility.PUBLIC));
+       IProgramElement.Accessibility acc = element.getAccessibility();
+       if (docVisibilityModifier.equals("private")) {
+               // show all classes and members
+                       return true;
+               } else if (docVisibilityModifier.equals("package")) {
+                       // show package, protected and public classes and members
+                       return acc.equals(IProgramElement.Accessibility.PACKAGE) 
+                                       || acc.equals(IProgramElement.Accessibility.PROTECTED)
+                                       || acc.equals(IProgramElement.Accessibility.PUBLIC);    
+               } else if (docVisibilityModifier.equals("protected")) {
+                       // show protected and public classes and members
+                       return acc.equals(IProgramElement.Accessibility.PROTECTED)
+                                       || acc.equals(IProgramElement.Accessibility.PUBLIC);    
+               } else if (docVisibilityModifier.equals("public")){
+                       // show public classes and members
+                       return acc.equals(IProgramElement.Accessibility.PUBLIC);
+               }
+       return false;
     }
 
     private static String genAccessibility(IProgramElement decl) {
index c6e1dcb77cff3698951bdafcae120460b1810c94..913e07992ff6a84b3c3fd8cdc6ab47a256679bbf 100644 (file)
@@ -19,6 +19,7 @@ import java.util.*;
 
 import java.io.FileFilter;
 
+import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.Version;
 import org.aspectj.util.FileUtil;
 
@@ -64,6 +65,8 @@ public class Main implements Config {
     private static boolean deleteTempFilesOnExit = true;
     
        private static boolean aborted = false;
+       private static IMessage[] errors;
+       private static boolean shownAjdocUsageMessage = false;
        
        // creating a local variable to enable us to create the ajdocworkingdir
        // in a local sandbox during testing
@@ -117,6 +120,7 @@ public class Main implements Config {
             if (CompilerWrapper.hasErrors()) {
                System.out.println(FAIL_MESSAGE);
                aborted = true;
+               errors = CompilerWrapper.getErrors();
                return;
             }    
 
@@ -454,11 +458,7 @@ public class Main implements Config {
         for (int i = 0; i < vargs.size() ; i++) {
             String arg = (String)vargs.get(i);  
             ignoreArg = false;
-            if ( addNextToAJCOptions ) {
-                ajcOptions.addElement( arg );
-                addNextToAJCOptions = false;
-            }
-            if ( addNextAsDocDir ) {
+            if (addNextAsDocDir) {
                 docDir = arg;
                 addNextAsDocDir = false;
             }
@@ -521,7 +521,7 @@ public class Main implements Config {
                System.out.println("> Ignoring unsupported option: -use");
             } else if (arg.equals("-splitindex")) {
                // passed to javadoc
-            } else if (arg.startsWith("-") || addNextAsOption) {
+            } else if (arg.startsWith("-") || addNextAsOption || addNextToAJCOptions) {
                 if ( arg.equals( "-private" ) ) {
                     docModifier = "private";
                 } else if ( arg.equals( "-package" ) ) {
@@ -553,8 +553,25 @@ public class Main implements Config {
                        || arg.equals("-noindex")) {
                        // pass through 
                        //System.err.println("> ignoring unsupported option: " + arg);
-                } else if ( addNextAsOption ) {
-                    //  pass through
+                } else if (addNextToAJCOptions || addNextAsOption) {
+                       // deal with these two options together even though effectively
+                       // just falling through if addNextAsOption is true. Otherwise
+                       // will have to ensure check "addNextToAJCOptions" before
+                       // "addNextAsOption" so as the options are added to the 
+                       // correct lists.
+                       if (addNextToAJCOptions) {
+                       ajcOptions.addElement(arg);
+                       if (!arg.startsWith("-")) {
+                               addNextToAJCOptions = false;
+                                       }
+                       if (!addNextAsOption) {
+                                               continue;
+                                       }                                               
+                                       }
+                } else if (arg.startsWith("-")) {
+                       ajcOptions.addElement(arg);
+                                       addNextToAJCOptions = true;
+                                       continue;
                 } else {
                        System.err.println("> unrecognized argument: " + arg);
                     displayHelpAndExit( null );
@@ -672,6 +689,7 @@ public class Main implements Config {
 
 
     static void displayHelpAndExit(String message) {
+       shownAjdocUsageMessage = true;
         if (message != null) {
                        System.err.println(message);
                        System.err.println();
@@ -712,6 +730,14 @@ public class Main implements Config {
                return aborted;
        }
        
+       public static IMessage[] getErrors() {
+               return errors;
+       }
+       
+       public static boolean hasShownAjdocUsageMessage() {
+               return shownAjdocUsageMessage;
+       }
+       
        /**
         * Sets the output working dir to be <fullyQualifiedOutputDir>\ajdocworkingdir
         * Useful in testing to redirect the ajdocworkingdir to the sandbox
diff --git a/ajdoc/testdata/pr148906/AdviceDidNotMatch.aj b/ajdoc/testdata/pr148906/AdviceDidNotMatch.aj
new file mode 100644 (file)
index 0000000..79d540c
--- /dev/null
@@ -0,0 +1,6 @@
+public aspect AdviceDidNotMatch {
+       
+       before() : execution(* *.*(..)) {
+       }
+       
+}
diff --git a/ajdoc/testdata/pr148906/C.java b/ajdoc/testdata/pr148906/C.java
new file mode 100644 (file)
index 0000000..7602c1f
--- /dev/null
@@ -0,0 +1,6 @@
+public class C {
+       
+       public void foo() {
+       }
+       
+}
diff --git a/ajdoc/testdata/pr148906/README.txt b/ajdoc/testdata/pr148906/README.txt
new file mode 100644 (file)
index 0000000..8c6e818
--- /dev/null
@@ -0,0 +1,3 @@
+to regenerate the jar files contained in this project:
+
+1. ajc AdviceDidNotMatch.aj -outjar simple.jar
diff --git a/ajdoc/testdata/pr148906/Xlint.properties b/ajdoc/testdata/pr148906/Xlint.properties
new file mode 100644 (file)
index 0000000..dad74d9
--- /dev/null
@@ -0,0 +1 @@
+adviceDidNotMatch=error
diff --git a/ajdoc/testdata/pr148906/simple.jar b/ajdoc/testdata/pr148906/simple.jar
new file mode 100644 (file)
index 0000000..d951bbc
Binary files /dev/null and b/ajdoc/testdata/pr148906/simple.jar differ
diff --git a/ajdoc/testdata/pr160302/C.java b/ajdoc/testdata/pr160302/C.java
new file mode 100644 (file)
index 0000000..b76d8d6
--- /dev/null
@@ -0,0 +1,3 @@
+public class C {
+       
+}
index 27979b925a44cf34098ebb482c277fe4551b3185..8c7c05d9ce3d628c692a97dd5a00585df2a5415a 100644 (file)
@@ -12,6 +12,8 @@ package org.aspectj.tools.ajdoc;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
 
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
@@ -155,6 +157,36 @@ public class AjdocTestCase extends TestCase{
         org.aspectj.tools.ajdoc.Main.main(args);
        }
        
+       /**
+        * Run the ajdoc command with the default visibility
+        * and source level, the given input files and the given
+        * aspectj options
+        */
+       public void runAjdoc(File[] inputFiles, String sourceLevel, String[] ajOptions) {
+               if (inputFiles.length == 0) {
+                       fail("need to pass some files into ajdoc");
+               } 
+               if (!sourceLevel.equals("1.3")
+                               && !sourceLevel.equals("1.4")
+                               && !sourceLevel.equals("1.5")) {
+                       fail("need to pass ajdoc '1.3', '1.4', or '1.5' as the source level");
+               }
+               String[] args = new String[6 + inputFiles.length + ajOptions.length];
+               args[0] = "-source";
+               args[1] = sourceLevel;
+               args[2] = "-classpath";
+               args[3] = AjdocTests.ASPECTJRT_PATH.getPath();
+               args[4] = "-d";
+               args[5] = getAbsolutePathOutdir();
+               for (int i = 0; i < ajOptions.length; i++) {
+                       args[6 + i] = ajOptions[i];
+               }
+               for (int i = 0; i < inputFiles.length; i++) {
+                       args[6 + i +ajOptions.length] = inputFiles[i].getAbsolutePath();
+               }
+        org.aspectj.tools.ajdoc.Main.main(args);               
+       }
+       
        /**
         * Run the ajdoc command with the given visibility argument,
         * the given source level argument and the given input files. 
@@ -263,4 +295,18 @@ public class AjdocTestCase extends TestCase{
                args[7] = "@" + getAbsoluteProjectDir() + File.separatorChar + lstFile;
         org.aspectj.tools.ajdoc.Main.main(args);
        }
+       
+       /**
+        * Run the ajdoc command with the given options
+        */
+       public void runAjdoc(List options) {
+               String[] args = new String[options.size()];
+               int i = 0;                
+               for (Iterator iter = options.iterator(); iter.hasNext();) {
+                       String element = (String) iter.next();
+                       args[i] = element;
+                       i++;
+               }
+               org.aspectj.tools.ajdoc.Main.main(args);
+       }
 }
index f9d50e56fa5e3461439d792a679644f1d8f64033..6debbe13b880b39308af183ffd0bb3d594f71fed 100644 (file)
@@ -44,7 +44,8 @@ public class AjdocTests extends TestCase {
         suite.addTestSuite(FullyQualifiedArgumentTest.class);
         suite.addTestSuite(EnumTest.class);
         suite.addTestSuite(PointcutVisibilityTest.class);
-        suite.addTestSuite(ExecutionTestCase.class);// !!! must be last because it exists
+        suite.addTestSuite(ExecutionTestCase.class); 
+        suite.addTestSuite(BugTests.class);
         //$JUnit-END$
         return suite;
     }
diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/BugTests.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/BugTests.java
new file mode 100644 (file)
index 0000000..eeb8f14
--- /dev/null
@@ -0,0 +1,133 @@
+/********************************************************************
+ * Copyright (c) 2006 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: IBM Corporation - initial API and implementation 
+ *                              Helen Hawkins   - initial version
+ *******************************************************************/
+package org.aspectj.tools.ajdoc;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BugTests extends AjdocTestCase {
+
+       public void testPr160302() throws Exception {
+               initialiseProject("pr160302");
+               File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
+               runAjdoc(files);
+               assertFalse("expected clean build of project but found that build aborted",Main.hasAborted());
+               File html = new File(getAbsolutePathOutdir() + File.separator + "C.html");
+               if (html == null || !html.exists()) {
+                       fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?");
+               }
+               assertFalse("expected all decorating tags to be removed but found that they" +
+                               " weren't",AjdocOutputChecker.containsString(html, Config.DECL_ID_STRING));
+       }
+       
+       /**
+        * Passing the "-Xlint:error" option through to the compiler should
+        * cause the ajc build to fail because the advice did not match
+        */
+       public void testPr148906_1() {
+               initialiseProject("pr148906");
+               File[] files = {new File(getAbsoluteProjectDir() + "/AdviceDidNotMatch.aj")};
+               String[] ajOptions = {new String("-Xlint:error")};
+               runAjdoc(files,"1.5",ajOptions);
+               assertTrue("expected ajc to fail but it did not", Main.hasAborted());
+               assertEquals("expected ajc to fail with an adviceDidNotMatch error but it" +
+                               " failed instead with " + Main.getErrors()[0].getMessage(),
+                               "advice defined in AdviceDidNotMatch has not been applied [Xlint:adviceDidNotMatch]",
+                               Main.getErrors()[0].getMessage());
+       }
+
+       /**
+        * Passing the "-Xlintfile" option through to the compiler should
+        * cause the ajc build to fail because the advice did not match
+        */
+       public void testPr148906_2() {
+               initialiseProject("pr148906");
+               File[] files = {new File(getAbsoluteProjectDir() + "/AdviceDidNotMatch.aj")};
+               String[] ajOptions = {new String("-Xlintfile"), new String(getAbsoluteProjectDir() + File.separator + "Xlint.properties")};
+               runAjdoc(files,"1.5",ajOptions);
+               assertTrue("expected ajc to fail but it did not", Main.hasAborted());
+               assertEquals("expected ajc to fail with an adviceDidNotMatch error but it" +
+                               " failed instead with " + Main.getErrors()[0].getMessage(),
+                               "advice defined in AdviceDidNotMatch has not been applied [Xlint:adviceDidNotMatch]",
+                               Main.getErrors()[0].getMessage());
+       }
+       
+       /**
+        * Passing the -aspectpath option though to the compiler should
+        * result in relationships being displayed
+        */
+       public void testPr148906_3() throws Exception {
+               initialiseProject("pr148906");
+               File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
+               String[] ajOptions = {new String("-aspectpath"), new String(getAbsoluteProjectDir() + File.separator + "simple.jar")};
+               runAjdoc(files,"1.5",ajOptions);
+               assertFalse("expected clean build of project but found that build aborted",Main.hasAborted());
+               File html = new File(getAbsolutePathOutdir() + File.separator + "C.html");
+               if (html == null || !html.exists()) {
+                       fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?");
+               }
+               assertTrue("expected to find 'Advised by' in the html output but did " +
+                               " not",AjdocOutputChecker.containsString(html, 
+                                               HtmlDecorator.HtmlRelationshipKind.ADVISED_BY.getName()));
+       }
+       
+       /**
+        * Passing an option starting with "-" that doesn't require a second entry 
+        * should mean everything is correctly given to the compiler. For example:
+        * '-outxml -aspectpath <file>" should mean both '-outxml' and the aspectpath
+        * options are given correctly.
+        */
+       public void testPr148906_4() throws Exception {
+               initialiseProject("pr148906");
+               File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
+               String[] ajOptions = {new String("-outxml"),new String("-aspectpath"), new String(getAbsoluteProjectDir() + File.separator + "simple.jar")};
+               runAjdoc(files,"1.5",ajOptions);
+               assertFalse("expected clean build of project but found that build aborted",Main.hasAborted());
+               File html = new File(getAbsolutePathOutdir() + File.separator + "C.html");
+               if (html == null || !html.exists()) {
+                       fail("couldn't find " + getAbsolutePathOutdir() + File.separator + "C.html - were there javadoc/compilation errors?");
+               }
+               assertTrue("expected to find 'Advised by' in the html output but did " +
+                               " not",AjdocOutputChecker.containsString(html, 
+                                               HtmlDecorator.HtmlRelationshipKind.ADVISED_BY.getName()));
+               File aopFile = new File(getAbsolutePathOutdir() + File.separator 
+                               + "META-INF" + File.separator + "aop-ajc.xml");
+               assertTrue("couldn't find " + getAbsolutePathOutdir() + File.separator 
+                               + "META-INF" + File.separator + "aop-ajc.xml" , 
+                               aopFile != null && aopFile.exists());
+       }       
+       
+       /**
+        * Passing bogus option to ajc
+        */
+       public void testPr148906_5() throws Exception {
+               initialiseProject("pr148906");
+               File[] files = {new File(getAbsoluteProjectDir() + "/C.java")};
+               String[] ajOptions = {new String("-bogus")};
+               runAjdoc(files,"1.5",ajOptions);
+               assertTrue("expected build of project to abort",Main.hasAborted());
+       }
+       
+       /**
+        * Not passing any files to ajdoc should result in both the ajdoc
+        * and ajc usage messages
+        */
+       public void testPr148906_6() throws Exception {
+               initialiseProject("pr148906");
+               List options = new ArrayList();
+               options.add("-verbose");
+               runAjdoc(options);
+               assertTrue("expected the ajdoc usage message to be reported",Main.hasShownAjdocUsageMessage());
+               assertTrue("expected build of project to abort",Main.hasAborted());             
+       }
+       
+}