From ab2150f267eef2ec565cc596b2e0e0412a3bd290 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 13 Jan 2006 14:44:59 +0000 Subject: [PATCH] ajdoc changes - moving to using a sandbox for testing, plus other bits and pieces - see pr121711 - from Helen. --- .../aspectj/tools/ajdoc/HtmlDecorator.java | 55 ++-- ajdoc/src/org/aspectj/tools/ajdoc/Main.java | 39 ++- ajdoc/testdata/coverage/foo/PlainJava.java | 2 +- ajdoc/testdata/declareForms/AnnotationTest.aj | 14 + .../testdata/declareForms/DeclareCoverage2.aj | 46 +++ .../tools/ajdoc/AjdocOutputChecker.java | 208 ++++++++++++ .../aspectj/tools/ajdoc/AjdocTestCase.java | 276 ++++++++++++++++ .../org/aspectj/tools/ajdoc/AjdocTests.java | 1 + .../aspectj/tools/ajdoc/CoverageTestCase.java | 298 +++++++++++++----- .../aspectj/tools/ajdoc/DeclareFormsTest.java | 92 ++++-- .../org/aspectj/tools/ajdoc/EnumTest.java | 71 +---- .../tools/ajdoc/ExecutionTestCase.java | 18 +- .../ajdoc/FullyQualifiedArgumentTest.java | 111 ++----- .../org/aspectj/tools/ajdoc/ITDTest.java | 289 ++++------------- .../aspectj/tools/ajdoc/JDKVersionTest.java | 3 +- .../aspectj/tools/ajdoc/PatternsTestCase.java | 11 +- .../tools/ajdoc/PointcutVisibilityTest.java | 91 +++++- .../aspectj/tools/ajdoc/SpacewarTestCase.java | 47 +-- 18 files changed, 1088 insertions(+), 584 deletions(-) create mode 100644 ajdoc/testdata/declareForms/AnnotationTest.aj create mode 100644 ajdoc/testdata/declareForms/DeclareCoverage2.aj create mode 100644 ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java create mode 100644 ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java index 4b8b679cf..db148e599 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -207,24 +207,36 @@ class HtmlDecorator { else { decorateMemberDocumentation(decl, fileContents, index); } - } - - // Change "Class" to "Aspect" - // HACK: depends on matching presence of advice or pointcut summary - int classStartIndex = fileContents.toString().indexOf("
\nClass "); - int pointcutSummaryIndex = fileContents.toString().indexOf(POINTCUT_SUMMARY); - int adviceSummaryIndex = fileContents.toString().indexOf(ADVICE_SUMMARY); - if (classStartIndex != -1 && - (adviceSummaryIndex != -1 || pointcutSummaryIndex != -1)) { - int classEndIndex = fileContents.toString().indexOf("", classStartIndex); - if (classStartIndex != -1 && classEndIndex != -1) { - String classLine = fileContents.toString().substring(classStartIndex, classEndIndex); - String aspectLine = "
\n" + "Aspect " + classLine.substring(11, classLine.length()); - fileContents.delete(classStartIndex, classEndIndex); - fileContents.insert(classStartIndex, aspectLine); + // Change "Class" to "Aspect" + // moved this here because then can use the IProgramElement.Kind + // rather than checking to see if there's advice - this fixes + // the case with an inner aspect not having the title "Aspect" + if(decl.getKind().equals(IProgramElement.Kind.ASPECT) + && file.getName().indexOf(decl.toSignatureString()) != -1) { + int classStartIndex = fileContents.toString().indexOf("
\nClass "); + if (classStartIndex != -1) { + int classEndIndex = fileContents.toString().indexOf("", classStartIndex); + if (classStartIndex != -1 && classEndIndex != -1) { + String classLine = fileContents.toString().substring(classStartIndex, classEndIndex); + String aspectLine = "
\n" + "Aspect " + classLine.substring(11, classLine.length()); + fileContents.delete(classStartIndex, classEndIndex); + fileContents.insert(classStartIndex, aspectLine); + } + } + int secondClassStartIndex = fileContents.toString().indexOf("class "); + if (secondClassStartIndex != -1) { + String name = decl.toSignatureString(); + int classEndIndex = fileContents.indexOf(name + "
"); + if (secondClassStartIndex != -1 && classEndIndex != -1) { + StringBuffer sb = new StringBuffer(fileContents.toString(). + substring(secondClassStartIndex,classEndIndex)); + sb.replace(0,5,"aspect"); + fileContents.delete(secondClassStartIndex, classEndIndex); + fileContents.insert(secondClassStartIndex, sb.toString()); + } + } } - } - + } file.delete(); FileOutputStream fos = new FileOutputStream( file ); fos.write( fileContents.toString().getBytes() ); @@ -460,9 +472,12 @@ class HtmlDecorator { if (!decl.getKind().equals(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR)) { entry += "  "; } - entry += generateSignatures(decl) + - "

" + - generateAffects(decl, true) + + // if we're not a declare statement then we need to generate the signature. + // If we did this for declare statements we get two repeated lines + if (!decl.getKind().isDeclare()) { + entry += generateSignatures(decl) + "

"; + } + entry += generateAffects(decl, true) + generateDetailsComment(decl); } diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/Main.java b/ajdoc/src/org/aspectj/tools/ajdoc/Main.java index 6f7226966..e0000cb25 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/Main.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/Main.java @@ -66,6 +66,10 @@ public class Main implements Config { private static boolean deleteTempFilesOnExit = true; private static boolean aborted = false; + + // creating a local variable to enable us to create the ajdocworkingdir + // in a local sandbox during testing + private static String outputWorkingDir = Config.WORKING_DIR; public static void clearState() { symbolManager = null; @@ -102,8 +106,8 @@ public class Main implements Config { File[] signatureFiles = new File[filenames.size()]; try { // create the workingdir if it doesn't exist - if ( !(new File( Config.WORKING_DIR ).isDirectory()) ) { - File dir = new File( Config.WORKING_DIR ); + if ( !(new File( outputWorkingDir ).isDirectory()) ) { + File dir = new File( outputWorkingDir ); dir.mkdir(); if (deleteTempFilesOnExit) dir.deleteOnExit(); } @@ -171,7 +175,7 @@ public class Main implements Config { javadocargs = new String[numExtraArgs + options.size() + packageList.size() + fileList.size() ]; javadocargs[0] = "-sourcepath"; - javadocargs[1] = Config.WORKING_DIR; + javadocargs[1] = outputWorkingDir; int argIndex = 2; if (authorStandardDocletSwitch) { javadocargs[argIndex] = "-author"; @@ -321,7 +325,7 @@ public class Main implements Config { String filename = ""; if ( packageName != null ) { - String pathName = Config.WORKING_DIR + '/' + packageName.replace('.', '/'); + String pathName = outputWorkingDir + '/' + packageName.replace('.', '/'); File packageDir = new File(pathName); if ( !packageDir.exists() ) { packageDir.mkdirs(); @@ -329,11 +333,11 @@ public class Main implements Config { } //verifyPackageDirExists(packageName, null); packageName = packageName.replace( '.','/' ); // !!! - filename = Config.WORKING_DIR + Config.DIR_SEP_CHAR + packageName + + filename = outputWorkingDir + Config.DIR_SEP_CHAR + packageName + Config.DIR_SEP_CHAR + inputFile.getName(); } else { - filename = Config.WORKING_DIR + Config.DIR_SEP_CHAR + inputFile.getName(); + filename = outputWorkingDir + Config.DIR_SEP_CHAR + inputFile.getName(); } File signatureFile = new File( filename ); if (deleteTempFilesOnExit) signatureFile.deleteOnExit(); @@ -436,7 +440,7 @@ public class Main implements Config { static String getSourcepathAsString() { String cPath = ""; for (int i = 0; i < sourcepath.size(); i++) { - cPath += (String)sourcepath.elementAt(i) + Config.DIR_SEP_CHAR + Config.WORKING_DIR; + cPath += (String)sourcepath.elementAt(i) + Config.DIR_SEP_CHAR + outputWorkingDir; if (i != sourcepath.size()-1) { cPath += File.pathSeparator; } @@ -731,6 +735,27 @@ public class Main implements Config { public static boolean hasAborted() { return aborted; } + + /** + * Sets the output working dir to be \ajdocworkingdir + * Useful in testing to redirect the ajdocworkingdir to the sandbox + */ + public static void setOutputWorkingDir(String fullyQulifiedOutputDir) { + if (fullyQulifiedOutputDir == null) { + resetOutputWorkingDir(); + } else { + outputWorkingDir = fullyQulifiedOutputDir + File.separatorChar + + Config.WORKING_DIR; + } + } + + /** + * Resets the output working dir to be the default which is + * \ajdocworkingdir + */ + public static void resetOutputWorkingDir() { + outputWorkingDir = Config.WORKING_DIR; + } } diff --git a/ajdoc/testdata/coverage/foo/PlainJava.java b/ajdoc/testdata/coverage/foo/PlainJava.java index 3c1314cb5..00ebfc12f 100644 --- a/ajdoc/testdata/coverage/foo/PlainJava.java +++ b/ajdoc/testdata/coverage/foo/PlainJava.java @@ -23,7 +23,7 @@ public class PlainJava { return i; } - static private class Bar { + static private class ClassBar { static private class Baz { diff --git a/ajdoc/testdata/declareForms/AnnotationTest.aj b/ajdoc/testdata/declareForms/AnnotationTest.aj new file mode 100644 index 000000000..28a72736a --- /dev/null +++ b/ajdoc/testdata/declareForms/AnnotationTest.aj @@ -0,0 +1,14 @@ +package foo; + +@interface MyAnnotation { +} + +public aspect AnnotationTest { + + declare @type : C : @MyAnnotation; + +} + +class C { + +} diff --git a/ajdoc/testdata/declareForms/DeclareCoverage2.aj b/ajdoc/testdata/declareForms/DeclareCoverage2.aj new file mode 100644 index 000000000..6300298e9 --- /dev/null +++ b/ajdoc/testdata/declareForms/DeclareCoverage2.aj @@ -0,0 +1,46 @@ +package foo; + +public aspect DeclareCoverage2 { + + pointcut illegalNewFigElt(): call(Point.new(..)) && !withincode(* *.doIt(..)); + + declare error: illegalNewFigElt(): "Illegal constructor call."; + declare warning: call(* Point.setX(..)): "Illegal call."; + + declare parents: Point extends java.io.Serializable; + declare parents: Line implements java.util.Observable; + declare soft: SizeException : call(* Point.getX()); + declare precedence: DeclareCoverage2, InterTypeDecCoverage, *; +} + +aspect InterTypeDecCoverage {} + +class Point { + + int x = 2; + public void setX(int x) { + this.x = x; + } + + public int getX() { + return x; + } +} + +class Line { +} + +class SizeException extends Throwable { } + +class Main { + + public static void main(String[] args) { + } + + public void doIt() { + Point p = new Point(); + p.setX(3); + p.getX(); + } + +} diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java new file mode 100644 index 000000000..0022265e1 --- /dev/null +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java @@ -0,0 +1,208 @@ +/******************************************************************** + * 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: IBM Corporation - initial API and implementation + * Helen Hawkins - iniital version + *******************************************************************/ +package org.aspectj.tools.ajdoc; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +/** + * Helper class to check whether the ajdoc contains the expected + * information. + */ +public class AjdocOutputChecker { + + /** + * Checks whether the given html file contains the required String. + * + * @param htmlFile + * @param requiredString + * @return true if the file contains the given string or + * false otherwise (or if the file is null or not an html file) + * @throws Exception + */ + public static boolean containsString(File htmlFile, + String requiredString) throws Exception { + if ((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html")) { + return false; + } + BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); + String line = reader.readLine(); + while (line != null) { + if (line.indexOf(requiredString) != -1) { + reader.close(); + return true; + } + line = reader.readLine(); + } + reader.close(); + return false; + } + + /** + * Returns those strings from the given array which aren't in the + * html file + * + * @param htmlFile + * @param an array of requiredStrings + * @return a List of those strings not found + * @throws Exception + */ + public static List /*String*/ getMissingStringsInFile(File htmlFile, + String[] requiredStrings) throws Exception { + List missingStrings = new ArrayList(); + for (int i = 0; i < requiredStrings.length; i++) { + String string = requiredStrings[i]; + if (!containsString(htmlFile,string)) { + missingStrings.add(string); + } + } + return missingStrings; + } + + /** + * Checks whether the section of the html file contains the + * required String + * + * @param htmlFile + * @param requiredString + * @param sectionHeader + * @return true if the file contains the given string within the + * required section or false otherwise (or if the file is null or + * not an html file) + * @throws Exception + */ + public static boolean containsStringWithinSection(File htmlFile, + String requiredString, String sectionHeader) throws Exception { + if ((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html")) { + return false; + } + BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); + String line = reader.readLine(); + while (line != null) { + if (line.indexOf(sectionHeader) != -1) { + String nextLine = reader.readLine(); + while (nextLine != null && + (nextLine.indexOf("========") == -1)) { + if (nextLine.indexOf(requiredString) != -1) { + reader.close(); + return true; + } + nextLine = reader.readLine(); + } + reader.close(); + return false; + } + line = reader.readLine(); + } + reader.close(); + return false; + } + + /** + * Returns those strings from the given array which aren't in the + * ajdoc html file + * + * @param htmlFile + * @param an array of requiredStrings + * @param sectionHeader + * @return List of those requiredStrings not found + * @throws Exception + */ + public static List /*String*/ getMissingStringsInSection(File htmlFile, + String[] requiredStrings, String sectionHeader) throws Exception { + List missingStrings = new ArrayList(); + for (int i = 0; i < requiredStrings.length; i++) { + String string = requiredStrings[i]; + if (!containsStringWithinSection(htmlFile,string,sectionHeader)) { + missingStrings.add(string); + } + } + return missingStrings; + } + + /** + * Checks whether the given strings appear one after the other in the + * ajdoc html file + * + * @param htmlFile + * @param firstString + * @param secondString expected to follow the firstString + * @return true if secondString appears after firstString, false otherwise + * @throws Exception + */ + public static boolean fileContainsConsecutiveStrings(File htmlFile, + String firstString, String secondString ) throws Exception { + if ((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html")) { + return false; + } + BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); + String line = reader.readLine(); + while (line != null) { + if (line.indexOf(firstString) != -1) { + if ( (line.indexOf(secondString) != -1 + && line.indexOf(secondString) > line.indexOf(firstString)) + || reader.readLine().indexOf(secondString) != -1) { + reader.close(); + return true; + } + reader.close(); + return false; + } + line = reader.readLine(); + } + reader.close(); + return false; + } + + /** + * Checks whether the given strings appear one after the other in the + * given section of the ajdoc html file + * + * @param htmlFile + * @param firstString + * @param secondString expected to follow the firstString + * @param sectionHeader + * @return true if secondString appears after firstString, false otherwise + * @throws Exception + */ + public static boolean sectionContainsConsecutiveStrings(File htmlFile, + String firstString, String secondString, String sectionHeader) throws Exception { + if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) { + return false; + } + BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); + String line = reader.readLine(); + while (line != null) { + if (line.indexOf(sectionHeader) != -1) { + String nextLine = reader.readLine(); + while (nextLine != null && (nextLine.indexOf("========") == -1)) { + if (nextLine.indexOf(firstString) != -1) { + if ( (nextLine.indexOf(secondString) != -1 + && nextLine.indexOf(secondString) > nextLine.indexOf(firstString)) + || reader.readLine().indexOf(secondString) != -1) { + reader.close(); + return true; + } + } + nextLine = reader.readLine(); + } + reader.close(); + return false; + } + line = reader.readLine(); + } + reader.close(); + return false; + } +} diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java new file mode 100644 index 000000000..372c9c637 --- /dev/null +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java @@ -0,0 +1,276 @@ +/******************************************************************** + * 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: IBM Corporation - initial API and implementation + * Helen Hawkins - iniital version + *******************************************************************/ +package org.aspectj.tools.ajdoc; + +import java.io.File; +import java.io.IOException; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; + +/** + * This class is the super class of all Ajdoc tests. It creates + * a sandbox directory and provides utility methods for + * copying over the test projects and running the ajdoc command + */ +public class AjdocTestCase extends TestCase{ + + public final static String testdataSrcDir = "../ajdoc/testdata"; + protected static File sandboxDir; + private static final String SANDBOX_NAME = "ajcSandbox"; + private String docOutdir, projectDir; + + + protected void setUp() throws Exception { + super.setUp(); + docOutdir = null; + projectDir = null; + // Create a sandbox in which to work + createEmptySandbox(); + // create the ajdocworkdingdir in the sandbox + Main.setOutputWorkingDir(getWorkingDir().getAbsolutePath()); + } + + protected void tearDown() throws Exception { + super.tearDown(); + // reset where ajdocworkingdir is created + Main.resetOutputWorkingDir(); + } + + // Taken from AjdeInteractionTestbed + private void createEmptySandbox() { + String os = System.getProperty("os.name"); + File tempDir = null; + // AMC - I did this rather than use the JDK default as I hate having to go look + // in c:\documents and settings\......... for the results of a failed test. + if (os.startsWith("Windows")) { + //Alex: try D first since NTFS on mine while FAT leads to failure.. + tempDir = new File("D:\\temp"); + if (!tempDir.exists()) { + tempDir = new File("C:\\temp"); + if (!tempDir.exists()) { + tempDir.mkdir(); + } + } + } else { + tempDir = new File("/tmp"); + } + File sandboxRoot = new File(tempDir,SANDBOX_NAME); + if (!sandboxRoot.exists()) { + sandboxRoot.mkdir(); + } + + org.aspectj.util.FileUtil.deleteContents(sandboxRoot); + + try { + sandboxDir = File.createTempFile("ajcTest",".tmp",sandboxRoot); + sandboxDir.delete(); + sandboxDir.mkdir(); + } catch (IOException ioEx) { + throw new AssertionFailedError("Unable to create sandbox directory for test"); + } + } + + /** + * Fill in the working directory with the project files and + * create a doc top level directory in which to generate + * the ajdoc output. + */ + public void initialiseProject(String projectName) { + File projectSrc=new File(testdataSrcDir + File.separatorChar + projectName); + File destination=new File(getWorkingDir(),projectName); + if (!destination.exists()) {destination.mkdir();} + copy(projectSrc,destination); + projectDir = destination.getAbsolutePath(); + + File docDestination = new File(getWorkingDir().toString() + File.separatorChar + projectName,"doc"); + if (!docDestination.exists()) {docDestination.mkdir();} + docOutdir = docDestination.getAbsolutePath(); + } + + /** + * @return the working directory + */ + protected File getWorkingDir() { + return sandboxDir; + } + + /** + * @return the absolute path of the project directory + * for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject + */ + protected String getAbsoluteProjectDir() { + return projectDir; + } + + /** + * @return the absolute path of the doc output directory + * for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject\doc + */ + protected String getAbsolutePathOutdir() { + return docOutdir; + } + + /** + * Copy the contents of some directory to another location - the + * copy is recursive. + */ + private void copy(File from, File to) { + String contents[] = from.list(); + if (contents==null) return; + for (int i = 0; i < contents.length; i++) { + String string = contents[i]; + File f = new File(from,string); + File t = new File(to,string); + + if (f.isDirectory()) { + t.mkdir(); + copy(f,t); + } else if (f.isFile()) { + try { + org.aspectj.util.FileUtil.copyFile(f,t); + } catch (IOException e) { + throw new AssertionFailedError("Unable to copy " + f + " to " + t); + } + } + } + } + + /** + * Run the ajdoc command with the given visibility argument, + * the default source level and the given input files. + */ + public void runAjdoc(String visibility, File[] inputFiles) { + if (!visibility.equals("public") + && !visibility.equals("protected") + && !visibility.equals("private")) { + fail("need to pass 'public','protected' or 'private' visibility to ajdoc"); + } + if (inputFiles.length == 0) { + fail("need to pass some files into ajdoc"); + } + String[] args = new String[5 + inputFiles.length]; + args[0] = "-" + visibility; + args[1] = "-classpath"; + args[2] = AjdocTests.ASPECTJRT_PATH.getPath(); + args[3] = "-d"; + args[4] = getAbsolutePathOutdir(); + for (int i = 0; i < inputFiles.length; i++) { + args[5+i] = inputFiles[i].getAbsolutePath(); + } + org.aspectj.tools.ajdoc.Main.main(args); + } + + /** + * Run the ajdoc command with the default visibility + * and source level and the given input files. + */ + public void runAjdoc(File[] inputFiles) { + if (inputFiles.length == 0) { + fail("need to pass some files into ajdoc"); + } + String[] args = new String[4 + inputFiles.length]; + args[0] = "-classpath"; + args[1] = AjdocTests.ASPECTJRT_PATH.getPath(); + args[2] = "-d"; + args[3] = getAbsolutePathOutdir(); + for (int i = 0; i < inputFiles.length; i++) { + args[4+i] = 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. + */ + public void runAjdoc(String visibility, String sourceLevel, File[] inputFiles) { + if (!visibility.equals("public") + && !visibility.equals("protected") + && !visibility.equals("private")) { + fail("need to pass 'public','protected' or 'private' visibility to 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"); + } + if (inputFiles.length == 0) { + fail("need to pass some files into ajdoc"); + } + for (int i = 0; i < inputFiles.length; i++) { + if (!inputFiles[i].exists()) { + fail(inputFiles[i].getAbsolutePath() + " does not exist"); + } + } + + String[] args = new String[7 + inputFiles.length]; + args[0] = "-" + visibility; + args[1] = "-source"; + args[2] = sourceLevel; + args[3] = "-classpath"; + args[4] = AjdocTests.ASPECTJRT_PATH.getPath(); + args[5] = "-d"; + args[6] = getAbsolutePathOutdir(); + for (int i = 0; i < inputFiles.length; i++) { + args[7+i] = inputFiles[i].getAbsolutePath(); + } + org.aspectj.tools.ajdoc.Main.main(args); + } + + /** + * Run the ajdoc command with the given visibility argument, + * the default source level and the given input directories. + */ + public void runAjdoc(String visibility, String[] directoryNames) { + if (!visibility.equals("public") + && !visibility.equals("protected") + && !visibility.equals("private")) { + fail("need to pass 'public','protected' or 'private' visibility to ajdoc"); + } + if (directoryNames.length == 0) { + fail("need to pass some directories into ajdoc"); + } + String[] args = new String[7 + directoryNames.length]; + args[0] = "-" + visibility; + args[1] = "-classpath"; + args[2] = AjdocTests.ASPECTJRT_PATH.getPath(); + args[3] = "-d"; + args[4] = getAbsolutePathOutdir(); + args[5] = "-sourcepath"; + args[6] = getAbsoluteProjectDir(); + for (int i = 0; i < directoryNames.length; i++) { + args[7+i] = directoryNames[i]; + } + org.aspectj.tools.ajdoc.Main.main(args); + } + + /** + * Run the ajdoc command with the default visibility and + * source level and the given input directories. + */ + public void runAjdoc(String[] directoryNames) { + if (directoryNames.length == 0) { + fail("need to pass some directories into ajdoc"); + } + String[] args = new String[6 + directoryNames.length]; + args[0] = "-classpath"; + args[1] = AjdocTests.ASPECTJRT_PATH.getPath(); + args[2] = "-d"; + args[3] = getAbsolutePathOutdir(); + args[4] = "-sourcepath"; + args[5] = getAbsoluteProjectDir(); + for (int i = 0; i < directoryNames.length; i++) { + args[6+i] = directoryNames[i]; + } + org.aspectj.tools.ajdoc.Main.main(args); + } +} diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java index 129f18a78..f9d50e56f 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java @@ -43,6 +43,7 @@ public class AjdocTests extends TestCase { suite.addTestSuite(ITDTest.class); suite.addTestSuite(FullyQualifiedArgumentTest.class); suite.addTestSuite(EnumTest.class); + suite.addTestSuite(PointcutVisibilityTest.class); suite.addTestSuite(ExecutionTestCase.class);// !!! must be last because it exists //$JUnit-END$ return suite; diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java index b6f03d3c7..4b57d4978 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java @@ -12,35 +12,25 @@ package org.aspectj.tools.ajdoc; import java.io.File; +import java.util.List; -import junit.framework.TestCase; - -import org.aspectj.util.FileUtil; /** * A long way to go until full coverage, but this is the place to add more. * * @author Mik Kersten */ -public class CoverageTestCase extends TestCase { - - protected File file0 = new File("../ajdoc/testdata/coverage/InDefaultPackage.java"); - protected File file1 = new File("../ajdoc/testdata/coverage/foo/ClassA.java"); - protected File aspect1 = new File("../ajdoc/testdata/coverage/foo/UseThisAspectForLinkCheck.aj"); - protected File file2 = new File("../ajdoc/testdata/coverage/foo/InterfaceI.java"); - protected File file3 = new File("../ajdoc/testdata/coverage/foo/PlainJava.java"); - protected File file4 = new File("../ajdoc/testdata/coverage/foo/ModelCoverage.java"); - protected File file5 = new File("../ajdoc/testdata/coverage/fluffy/Fluffy.java"); - protected File file6 = new File("../ajdoc/testdata/coverage/fluffy/bunny/Bunny.java"); - protected File file7 = new File("../ajdoc/testdata/coverage/fluffy/bunny/rocks/Rocks.java"); - protected File file8 = new File("../ajdoc/testdata/coverage/fluffy/bunny/rocks/UseThisAspectForLinkCheckToo.java"); - protected File file9 = new File("../ajdoc/testdata/coverage/foo/PkgVisibleClass.java"); - protected File file10 = new File("../ajdoc/testdata/coverage/foo/NoMembers.java"); +public class CoverageTestCase extends AjdocTestCase { - protected File outdir; + protected File file0,file1,aspect1,file2,file3,file4,file5,file6,file7,file8,file9,file10; + + protected void setUp() throws Exception { + super.setUp(); + initialiseProject("coverage"); + createFiles(); + } public void testOptions() { - outdir.delete(); String[] args = { "-private", "-encoding", @@ -52,77 +42,235 @@ public class CoverageTestCase extends TestCase { "-classpath", AjdocTests.ASPECTJRT_PATH.getPath(), "-d", - outdir.getAbsolutePath(), + getAbsolutePathOutdir(), file0.getAbsolutePath(), }; org.aspectj.tools.ajdoc.Main.main(args); assertTrue(true); } - public void testCoveragePublicMode() { - outdir.delete(); - String[] args = { - "-public", - "-source", - "1.4", - "-classpath", - AjdocTests.ASPECTJRT_PATH.getPath(), - "-d", - outdir.getAbsolutePath(), - file3.getAbsolutePath(), - file9.getAbsolutePath() - }; - org.aspectj.tools.ajdoc.Main.main(args); + /** + * Test the "-public" argument + */ + public void testCoveragePublicMode() throws Exception { + File[] files = {file3,file9}; + runAjdoc("public","1.4",files); + + // have passed the "public" modifier as well as + // one public and one package visible class. There + // should only be ajdoc for the public class + File htmlFile = new File(getAbsolutePathOutdir() + "/foo/PkgVisibleClass.html"); + assertFalse("ajdoc for PkgVisibleClass shouldn't exist because passed" + + " the 'public' flag to ajdoc",htmlFile.exists()); + + htmlFile = new File(getAbsolutePathOutdir() + "/foo/PlainJava.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + + " - were there compilation errors?"); + } + + // check there's no private fields within the file, that + // the file contains the getI() method but doesn't contain + // the private ClassBar, Bazz and Jazz classes. + String[] strings = { "private", "getI()","ClassBar", "Bazz", "Jazz"}; + List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); + assertEquals("There should be 4 missing strings",4,missing.size()); + assertTrue(htmlFile.getName() + " should not contain the private modifier",missing.contains("private")); + assertTrue(htmlFile.getName() + " should not contain the private ClassBar class",missing.contains("ClassBar")); + assertTrue(htmlFile.getName() + " should not contain the private Bazz class",missing.contains("Bazz")); + assertTrue(htmlFile.getName() + " should not contain the private Jazz class",missing.contains("Jazz")); + } + + /** + * Test that the ajdoc for an inner aspect is entitled "Aspect" rather + * than "Class", but that the enclosing class is still "Class" + */ + public void testInnerAspect() throws Exception { + File[] files = {file1, file2}; + runAjdoc("private","1.4",files); + + File htmlFile = new File(getAbsolutePathOutdir() + "/foo/ClassA.InnerAspect.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + + " - were there compilation errors?"); + } + + // ensure that the file is entitled "Aspect ClassA.InnerAspect" rather + // than "Class ClassA.InnerAspect" + String[] strings = { "Aspect ClassA.InnerAspect", + "

static aspect ClassA.InnerAspect
extends java.lang.Object", + "Class ClassA.InnerAspect", + "
static class ClassA.InnerAspect
extends java.lang.Object"}; + List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); + assertEquals("There should be 2 missing strings",2,missing.size()); + assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class ClassA.InnerAspect")); + assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class ClassA.InnerAspect
extends java.lang.Object")); + + // get the html file for the enclosing class + File htmlFileClass = new File(getAbsolutePathOutdir() + "/foo/ClassA.html"); + if (htmlFileClass == null || !htmlFileClass.exists()) { + fail("couldn't find " + htmlFileClass.getAbsolutePath() + + " - were there compilation errors?"); + } + + // ensure that the file is entitled "Class ClassA" and + // has not been changed to "Aspect ClassA" + String[] classStrings = { "Class ClassA", + "public abstract class ClassA
extends java.lang.Object
", + "Aspect ClassA", + "public abstract aspect ClassA
extends java.lang.Object
"}; + List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); + assertEquals("There should be 2 missing strings",2,classMissing.size()); + assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect ClassA")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("public abstract aspect ClassA
extends java.lang.Object
")); + } + + /** + * Test that all the different types of advice appear + * with the named pointcut in it's description + */ + public void testAdviceNamingCoverage() throws Exception { + File[] files = {file4}; + runAjdoc("private","1.4",files); + + File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdviceNamingCoverage.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + + " - were there compilation errors?"); + } + + String[] strings = { + "after(): named..", + "afterReturning(int, int): namedWithArgs..", + "afterThrowing(): named..", + "before(): named..", + "around(int): namedWithOneArg..", + "before(int):", + "before(int): named()..", + "before():"}; + List missing = AjdocOutputChecker.getMissingStringsInSection( + htmlFile, strings,"ADVICE DETAIL SUMMARY"); + assertTrue(htmlFile.getName() + " should contain all advice in the Advice Detail section",missing.isEmpty()); + missing = AjdocOutputChecker.getMissingStringsInSection( + htmlFile,strings,"ADVICE SUMMARY"); + assertTrue(htmlFile.getName() + " should contain all advice in the Advice Summary section",missing.isEmpty()); + } + + /** + * Test that all the advises relationships appear in the + * Advice Detail and Advice Summary sections and that + * the links are correct + */ + public void testAdvisesRelationshipCoverage() throws Exception { + File[] files = {file4}; + runAjdoc("private","1.4",files); + + File htmlFile = new File(getAbsolutePathOutdir() + "/foo/AdvisesRelationshipCoverage.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?"); + } + + String[] strings = { + "before(): methodExecutionP..", + "Advises:before(): constructorExecutionP..", + "Advises:before(): callConstructorP..", + "Advises:before(): getP..", + "Advises:before(): setP..", + "Advises:foo.Point, foo.Point.Point(), foo.Point.setX, before(): initializationP..", + "Advises:before(): staticinitializationP..", + "Advises:before(): handlerP..", + "Advises:C.y") != -1) { - containsITDFAsHeader = true; - } - if (nextLine.indexOf("public C.C") != -1 ) { - containsCorrectConstInfo = true; - } - if (nextLine.indexOf("package void") != -1 ) { - containsPackageVoid = true; - } - nextLine = readerA.readLine(); - } - assertTrue("Declare detail summary should contain the 'private int' " + - "modifiers", containsPrivateInt); - assertTrue("Declare detail summary should contain the 'public java." + - "lang.String' return type",containsPublicString); - assertTrue("Declare detail summary should have 'C.y' as one header", - containsITDFAsHeader); - assertTrue("Declare detail summary should have 'public C.C' for the " + - "ITD constructor", containsCorrectConstInfo); - assertFalse("Declare detail summary should not have 'package void' in it", - containsPackageVoid); - - // we may have hit the "inter-type field summary" so set this to - // be the next line we look at. - lineA = nextLine; - } else if (lineA.indexOf("DECLARE SUMMARY") != -1) { - containsDeclareSummary = true; - boolean containsPrivate = false; - boolean containsInt = false; - boolean containsString = false; - boolean containsPublic = false; - boolean containsPackageVoid = false; - // walk through the information in this section - String nextLine = readerA.readLine(); - while(nextLine != null && (nextLine.indexOf("========") == -1)) { - if (nextLine.indexOf("private") != -1) { - containsPrivate = true; - } - if (nextLine.indexOf("int") != -1) { - containsInt = true; - } - if (nextLine.indexOf("public") != -1) { - containsPublic = true; - } - if (nextLine.indexOf("String") != -1) { - containsString = true; - } - if (nextLine.indexOf("package void") != -1) { - containsPackageVoid = true; - } - nextLine = readerA.readLine(); - } - assertTrue("Declare summary should contain the 'private' modifier",containsPrivate); - assertTrue("Declare summary should contain the 'int' return type",containsInt); - assertFalse("Declare summary should not contain the 'public' modifier",containsPublic); - assertTrue("Declare summary should contain the 'String' return type",containsString); - assertFalse("Declare summary should not have 'package void' in it", - containsPackageVoid); - - // we may have hit the "Declare Details" so set this to - // be the next line we look at. - lineA = nextLine; - } else { - lineA = readerA.readLine(); - } - } - readerA.close(); + // check that A is an Aspect + assertTrue(htmlA.getAbsolutePath() + " should have Aspect A as it's title", + AjdocOutputChecker.containsString(htmlA,"Aspect A")); + + // check the contents of the declare detail summary + String[] stringsA = { "private int", + "public java.lang.String", + "

C.y

", + "public C.C", + "package void"}; + missing = AjdocOutputChecker.getMissingStringsInSection(htmlA,stringsA,"DECLARE DETAIL SUMMARY"); + assertEquals("There should be one missing string ",1,missing.size()); + assertEquals("the 'package' and 'void' modifiers shouldn't appear in the 'Declare Detail' section of the ajdoc", + "package void", missing.get(0)); - assertTrue("should have put Declare Detail information into " + - "../ajdoc/testdata/pr119453/doc/pack/A.html", containsDeclareDetail); - assertTrue("should have put Declare Summary information into " + - "../ajdoc/testdata/pr119453/doc/pack/A.html", containsDeclareSummary); - - } - + // check the contents of the declare summary + String[] stringsA2 = {"private", "int", "public", "String", "package void"}; + missing = AjdocOutputChecker.getMissingStringsInSection(htmlA,stringsA2,"DECLARE SUMMARY"); + assertEquals("There should be two missing strings ",2,missing.size()); + assertTrue("the public modifier shouldn't appear in the 'Declare Summary' section of the ajdoc", missing.contains("public")); + assertTrue("the 'package' and 'void' modifiers shouldn't appear in the 'Declare Summary' section of the ajdoc", missing.contains("package void")); + } + } diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/JDKVersionTest.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/JDKVersionTest.java index e4ac675cd..7a48b2c37 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/JDKVersionTest.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/JDKVersionTest.java @@ -3,12 +3,11 @@ */ package org.aspectj.tools.ajdoc; -import junit.framework.TestCase; /** * @author Mik Kersten */ -public class JDKVersionTest extends TestCase { +public class JDKVersionTest extends AjdocTestCase { // public void testIsUsing1point4() { // String v = System.getProperty("java.class.version","44.0"); diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/PatternsTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/PatternsTestCase.java index d0dd93a16..552ffa533 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/PatternsTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/PatternsTestCase.java @@ -14,14 +14,12 @@ package org.aspectj.tools.ajdoc; import java.io.File; -import junit.framework.TestCase; - /** * A long way to go until full coverage, but this is the place to add more. * * @author Mik Kersten */ -public class PatternsTestCase extends TestCase { +public class PatternsTestCase extends AjdocTestCase { public void testSimpleExample() { @@ -90,11 +88,4 @@ public class PatternsTestCase extends TestCase { org.aspectj.tools.ajdoc.Main.main(args); } - protected void setUp() throws Exception { - super.setUp(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } } diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java index 7a5d34a33..38789e4d2 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java @@ -4,26 +4,85 @@ package org.aspectj.tools.ajdoc; import java.io.File; - -import junit.framework.TestCase; +import java.util.List; /** * @author Mik Kersten */ -public class PointcutVisibilityTest extends TestCase { - - protected File file1 = new File("../ajdoc/testdata/bug82340/Pointcuts.java"); - protected File outdir = new File("../ajdoc/testdata/bug82340/doc"); +public class PointcutVisibilityTest extends AjdocTestCase { + + /** + * Test that passing the "public" argument only shows + * public pointcuts in the ajdoc + */ + public void testCoveragePublicMode() throws Exception { + initialiseProject("bug82340"); + File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "Pointcuts.java")}; + runAjdoc("public",files); + + // ajdoc for Pointcut.java should contain info about + // the public pointcuts but not the protected and + // private one (since "public" was an argument) + // Check that this is the case...... + File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Pointcuts.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?"); + } + // check the contents of the pointcut summary + String[] strings = { "privatePointcut","protectedPointcut","publicPointcut"}; + List missing = AjdocOutputChecker.getMissingStringsInSection(htmlFile,strings,"POINTCUT SUMMARY"); + assertEquals("There should be two missing strings",2,missing.size()); + assertTrue("passing the 'public' argument means the private pointcut shouldn't appear in the ajdoc", missing.contains("privatePointcut")); + assertTrue("passing the 'public' argument means the protected pointcut shouldn't appear in the ajdoc", missing.contains("protectedPointcut")); + } - public void testCoveragePublicMode() { - outdir.delete(); - String[] args = { - "-XajdocDebug", - "-protected", - "-d", - outdir.getAbsolutePath(), - file1.getAbsolutePath() - }; - org.aspectj.tools.ajdoc.Main.main(args); + /** + * Test that passing the "protected" argument only shows + * public and protected pointcuts in the ajdoc + */ + public void testCoverageProtectedMode() throws Exception { + initialiseProject("bug82340"); + File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "Pointcuts.java")}; + runAjdoc("protected",files); + + // ajdoc for Pointcut.java should contain info about + // the public and protected pointcuts but not the + // private one (since "protected" was an argument) + // Check that this is the case...... + File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Pointcuts.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?"); + } + // check the contents of the pointcut summary + String[] strings = { "privatePointcut","protectedPointcut","publicPointcut"}; + List missing = AjdocOutputChecker.getMissingStringsInSection(htmlFile,strings,"POINTCUT SUMMARY"); + assertEquals("There should be one missing strings",1,missing.size()); + assertEquals("passing the 'protected' argument means the private pointcut shouldn't appear in the ajdoc", + "privatePointcut", missing.get(0)); } + + /** + * Test that passing the "private" argument shows all + * pointcuts (public, protected and private) in the ajdoc + */ + public void testCoveragePrivateMode() throws Exception { + initialiseProject("bug82340"); + File[] files = {new File(getAbsoluteProjectDir() + File.separatorChar + "Pointcuts.java")}; + runAjdoc("private",files); + + // ajdoc for Pointcut.java should contain info about + // the public, protected and private pointcuts + // (since "private" was an argument) + // Check that this is the case...... + File htmlFile = new File(getAbsolutePathOutdir() + "/foo/Pointcuts.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?"); + } + // check the contents of the pointcut summary + String[] strings = { "privatePointcut","protectedPointcut","publicPointcut"}; + List missing = AjdocOutputChecker.getMissingStringsInSection(htmlFile,strings,"POINTCUT SUMMARY"); + assertTrue("passing the 'private' modifier means that private, protected and public " + + "pointcuts should appear in the ajdoc",missing.isEmpty()); + } + } diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/SpacewarTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/SpacewarTestCase.java index 0825ade26..b6aa0c4b8 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/SpacewarTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/SpacewarTestCase.java @@ -11,58 +11,25 @@ * ******************************************************************/ package org.aspectj.tools.ajdoc; -import java.io.File; - -import junit.framework.TestCase; /** * @author Mik Kersten */ -public class SpacewarTestCase extends TestCase { +public class SpacewarTestCase extends AjdocTestCase { + + private String[] dirs = {"spacewar","coordination"}; protected void setUp() throws Exception { super.setUp(); - new File("../ajdoc/testdata/spacewar/docdir").delete(); + initialiseProject("spacewar"); } public void testSimpleExample() { - File outdir = new File("testdata/spacewar/docdir"); - File sourcepath = new File("testdata/spacewar"); - - String[] args = { - "-classpath", - AjdocTests.ASPECTJRT_PATH.getPath(), - "-d", - outdir.getAbsolutePath(), - "-sourcepath", - sourcepath.getAbsolutePath(), - "spacewar", - "coordination" }; - - org.aspectj.tools.ajdoc.Main.main(args); - assertTrue(true); + runAjdoc(dirs); } public void testPublicModeExample() { - File outdir = new File("../ajdoc/testdata/spacewar/docdir"); - File sourcepath = new File("../ajdoc/testdata/spacewar"); - - String[] args = { - "-public", - "-classpath", - AjdocTests.ASPECTJRT_PATH.getPath(), - "-d", - outdir.getAbsolutePath(), - "-sourcepath", - sourcepath.getAbsolutePath(), - "spacewar", - "coordination" }; - - org.aspectj.tools.ajdoc.Main.main(args); - assertTrue(true); - } - - protected void tearDown() throws Exception { - super.tearDown(); + runAjdoc("public",dirs); } + } -- 2.39.5