* ******************************************************************/
package org.aspectj.tools.ajdoc;
+import org.aspectj.bridge.IMessage;
+
/**
* Wrapper for ajdoc's use of the AspectJ compiler.
*
public static boolean hasErrors() {
return INSTANCE.ourHandler.getErrors().length > 0;
}
+
+ public static IMessage[] getErrors() {
+ return INSTANCE.ourHandler.getErrors();
+ }
}
" -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";
}
}
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) {
import java.io.FileFilter;
+import org.aspectj.bridge.IMessage;
import org.aspectj.bridge.Version;
import org.aspectj.util.FileUtil;
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
if (CompilerWrapper.hasErrors()) {
System.out.println(FAIL_MESSAGE);
aborted = true;
+ errors = CompilerWrapper.getErrors();
return;
}
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;
}
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" ) ) {
|| 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 );
static void displayHelpAndExit(String message) {
+ shownAjdocUsageMessage = true;
if (message != null) {
System.err.println(message);
System.err.println();
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
--- /dev/null
+public aspect AdviceDidNotMatch {
+
+ before() : execution(* *.*(..)) {
+ }
+
+}
--- /dev/null
+public class C {
+
+ public void foo() {
+ }
+
+}
--- /dev/null
+to regenerate the jar files contained in this project:
+
+1. ajc AdviceDidNotMatch.aj -outjar simple.jar
--- /dev/null
+adviceDidNotMatch=error
--- /dev/null
+public class C {
+
+}
import java.io.File;
import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
import junit.framework.AssertionFailedError;
import junit.framework.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.
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);
+ }
}
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;
}
--- /dev/null
+/********************************************************************
+ * 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());
+ }
+
+}