@@ -148,7 +148,7 @@ public class StructureUtil { | |||
if (node.getParameterTypes() != null) { | |||
sb.append('('); | |||
for (int i = 0; i < node.getParameterTypes().size(); i++) { | |||
sb.append((String) node.getParameterTypes().get(i)); | |||
sb.append(String.valueOf(node.getParameterTypes().get(i))); | |||
sb.append(' '); | |||
sb.append((String) node.getParameterNames().get(i)); | |||
if (i < node.getParameterTypes().size() - 1) { |
@@ -429,5 +429,9 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase { | |||
return null; | |||
} | |||
protected File getClassResource(String resourceName) { | |||
return new File(getClass().getResource(resourceName).getFile()); | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
package test; | |||
import java.lang.annotation.ElementType; | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.RetentionPolicy; | |||
import java.lang.annotation.Target; | |||
@Retention(RetentionPolicy.CLASS) | |||
@Target(ElementType.METHOD) | |||
public @interface Event { | |||
enum Order { | |||
Before, | |||
After | |||
} | |||
Order value() default Order.Before; | |||
boolean treadSafe() default false; | |||
} |
@@ -0,0 +1,253 @@ | |||
package test; | |||
import javax.annotation.Generated; | |||
import javax.annotation.processing.AbstractProcessor; | |||
import javax.annotation.processing.RoundEnvironment; | |||
import javax.annotation.processing.SupportedSourceVersion; | |||
import javax.lang.model.SourceVersion; | |||
import javax.lang.model.element.*; | |||
import javax.lang.model.type.TypeMirror; | |||
import javax.tools.Diagnostic; | |||
import javax.tools.FileObject; | |||
import javax.tools.JavaFileObject; | |||
import javax.tools.StandardLocation; | |||
import java.io.BufferedWriter; | |||
import java.io.IOException; | |||
import java.util.*; | |||
@SupportedSourceVersion(SourceVersion.RELEASE_7) | |||
public final class SimpleProcessor extends AbstractProcessor { | |||
private final Map<TypeElement, List<Item>> collectedElements = new HashMap<>(); | |||
private static String callbacksClassName(TypeElement ce) { | |||
return ce.getSimpleName() + "Callbacks"; | |||
} | |||
private static String capitalize(String str) { | |||
char[] chars = str.toCharArray(); | |||
return String.valueOf(chars[0]).toUpperCase() + String.valueOf(Arrays.copyOfRange(chars, 1, chars.length)); | |||
} | |||
private static String callbacksSubClassName(Item item) { | |||
return "On" + capitalize(item.element.getSimpleName().toString()); | |||
} | |||
private static String callbackName(TypeElement ce, Item item) { | |||
return callbacksClassName(ce) + '.' + callbacksSubClassName(item); | |||
} | |||
private static String eventName(TypeElement ce, Item item) { | |||
return ce.getSimpleName() + fieldName(item); | |||
} | |||
private static String fieldName(Item item) { | |||
return "On" + capitalize(item.element.getSimpleName().toString()) + "Event"; | |||
} | |||
private static String toString(VariableElement var, boolean printNames) { | |||
final StringBuilder builder = new StringBuilder(); | |||
if (printNames) { | |||
for (final AnnotationMirror annotation : var.getAnnotationMirrors()) | |||
builder.append(annotation).append(' '); | |||
} | |||
builder.append(var.asType()); | |||
if (printNames) | |||
builder.append(' ').append(var); | |||
return builder.toString(); | |||
} | |||
private static void generateEmit(BufferedWriter bw, TypeElement ce, Item item) throws IOException { | |||
bw.append(" private static void emit(").append(eventName(ce, item)).append(" event, ").append(ce.getSimpleName()).append(" emmiter"); | |||
for (final VariableElement variableElement : item.element.getParameters()) | |||
bw.append(", ").append(toString(variableElement, true)); | |||
bw.append(") {\n"); | |||
bw.append(" final Collection<").append(callbackName(ce, item)).append("> callbacksSafe = event.callbacks;\n"); | |||
bw.append(" if (callbacksSafe == null)\n"); | |||
bw.append(" return;\n"); | |||
bw.append(" for (final ").append(callbackName(ce, item)).append(" callback : new ArrayList<>(callbacksSafe))\n"); | |||
bw.append(" callback.changed(emmiter"); | |||
for (final VariableElement variableElement : item.element.getParameters()) | |||
bw.append(", ").append(variableElement.getSimpleName()); | |||
bw.append(");\n"); | |||
bw.append(" }\n"); | |||
bw.newLine(); | |||
} | |||
private static void generateEvent(BufferedWriter bw, TypeElement ce, Item item) throws IOException { | |||
bw.append(" public static final class ").append(eventName(ce, item)).append(" {\n"); | |||
bw.append(" private Collection<").append(callbackName(ce, item)).append("> callbacks = null;\n"); | |||
bw.append("\n"); | |||
bw.append(" ").append(eventName(ce, item)).append("() {\n"); | |||
bw.append(" }\n"); | |||
bw.append("\n"); | |||
bw.append(" public void add(").append(callbackName(ce, item)).append(" callback) {\n"); | |||
bw.append(" Collection<").append(callbackName(ce, item)).append("> callbacksSafe = callbacks;\n"); | |||
bw.append(" if (callbacksSafe == null) {\n"); | |||
bw.append(" callbacksSafe = new ArrayList<>(1);\n"); | |||
bw.append(" callbacks = callbacksSafe;\n"); | |||
bw.append(" }\n"); | |||
bw.append(" callbacksSafe.add(callback);\n"); | |||
bw.append(" }\n"); | |||
bw.append("\n"); | |||
bw.append(" public void clean() {\n"); | |||
bw.append(" callbacks = null;\n"); | |||
bw.append(" }\n"); | |||
bw.append(" }"); | |||
bw.newLine(); | |||
bw.newLine(); | |||
} | |||
private static void generateField(BufferedWriter bw, TypeElement ce, Item item) throws IOException { | |||
bw.append(" @SuppressWarnings(\"PublicField\")\n"); | |||
bw.append(" public final ").append(eventName(ce, item)).append(' ').append(ce.getQualifiedName()).append('.').append(fieldName(item)) | |||
.append(" = new ").append(eventName(ce, item)).append("();\n"); | |||
bw.newLine(); | |||
} | |||
private static void generatePointcut(BufferedWriter bw, TypeElement ce, Item item) throws IOException { | |||
bw.append(" ").append(item.description.value().name().toLowerCase()).append("(): execution(").append(item.element.getReturnType().toString()).append(' ').append(ce.getQualifiedName()).append('.') | |||
.append(item.element.getSimpleName()).append('('); | |||
for (final Iterator<? extends TypeParameterElement> i = item.element.getTypeParameters().iterator(); i.hasNext(); ) { | |||
bw.append(i.next().getSimpleName()); | |||
if (i.hasNext()) | |||
bw.append(", "); | |||
} | |||
bw.append(")) {\n"); | |||
bw.append(" final ").append(ce.getQualifiedName()).append(" emmiter = (").append(ce.getQualifiedName()).append(") thisJoinPoint.getThis();\n"); | |||
bw.append(" emit(emmiter.").append(fieldName(item)).append(", emmiter"); | |||
final List<? extends VariableElement> parameters = item.element.getParameters(); | |||
for (int i = 0, s = parameters.size(); i < s; i++) { | |||
final VariableElement element = parameters.get(i); | |||
final TypeMirror type = element.asType(); | |||
bw.append(", ").append('(').append(type.toString()).append(") thisJoinPoint.getArgs()[").append(Integer.toString(i)).append(']'); | |||
} | |||
bw.append(");\n"); | |||
bw.append(" }"); | |||
bw.newLine(); | |||
bw.newLine(); | |||
} | |||
@Override | |||
public Set<String> getSupportedAnnotationTypes() { | |||
return Collections.singleton(Event.class.getName()); | |||
} | |||
@Override | |||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { | |||
if (roundEnv.processingOver()) { | |||
generateAll(); | |||
return true; | |||
} | |||
for (final Element elem : roundEnv.getElementsAnnotatedWith(Event.class)) { | |||
final Event description = elem.getAnnotation(Event.class); | |||
if (description == null) | |||
continue; | |||
if (elem.getKind() == ElementKind.FIELD) { | |||
// TODO(yushkovskiy): implement this | |||
continue; | |||
} | |||
if (elem.getKind() != ElementKind.METHOD) | |||
continue; | |||
final ExecutableElement exeElement = (ExecutableElement) elem; | |||
final Element enclosingElement = exeElement.getEnclosingElement(); | |||
final TypeElement classElement = (TypeElement) enclosingElement; | |||
List<Item> items = collectedElements.get(classElement); | |||
if (items == null) { | |||
items = new ArrayList<>(); | |||
collectedElements.put(classElement, items); | |||
} | |||
items.add(new Item(exeElement, description)); | |||
} | |||
return true; // no further processing of this annotation type | |||
} | |||
private void generateCallbacks(TypeElement ce, List<Item> items) throws IOException { | |||
final PackageElement packageElement = (PackageElement) ce.getEnclosingElement(); | |||
final JavaFileObject jfo = processingEnv.getFiler().createSourceFile(packageElement.getQualifiedName().toString() + '.' + callbacksClassName(ce)); | |||
try (final BufferedWriter bw = new BufferedWriter(jfo.openWriter())) { | |||
bw.append("package ").append(packageElement.getQualifiedName()).append(";"); | |||
bw.newLine(); | |||
bw.newLine(); | |||
bw.append("/**\n").append(" * Events' callbacks for ").append(ce.getQualifiedName()).append(".\n").append(" *\n").append(" * @author ").append(SimpleProcessor.class.getCanonicalName()).append("\n").append(" */"); | |||
bw.newLine(); | |||
bw.append("public final class ").append(callbacksClassName(ce)).append(" {"); | |||
bw.newLine(); | |||
for (final Item item : items) { | |||
bw.append(" public interface ").append(callbacksSubClassName(item)).append(" {\n"); | |||
bw.append(" void changed(").append(ce.getSimpleName()).append(" emmiter"); | |||
for (final VariableElement var : item.element.getParameters()) | |||
bw.append(", ").append(toString(var, true)); | |||
bw.append(");\n"); | |||
bw.append(" }"); | |||
bw.newLine(); | |||
bw.newLine(); | |||
} | |||
bw.append("}"); | |||
bw.newLine(); | |||
bw.newLine(); | |||
} | |||
} | |||
private void generateAll() { | |||
for (final Map.Entry<TypeElement, List<Item>> entry : collectedElements.entrySet()) { | |||
final TypeElement classElement = entry.getKey(); | |||
final PackageElement packageElement = (PackageElement) classElement.getEnclosingElement(); | |||
try { | |||
final FileObject jfo = processingEnv.getFiler().createResource( | |||
StandardLocation.SOURCE_OUTPUT, | |||
packageElement.getQualifiedName(), | |||
classElement.getSimpleName() + "EventsAspect.aj"); | |||
try (final BufferedWriter bw = new BufferedWriter(jfo.openWriter())) { | |||
bw.append("package ").append(packageElement.getQualifiedName()).append(";"); | |||
bw.newLine(); | |||
bw.append("import java.util.ArrayList;\n"); | |||
bw.append("import java.util.Collection;"); | |||
bw.newLine(); | |||
bw.newLine(); | |||
bw.append("/**\n").append(" * Events for ").append(classElement.getQualifiedName()).append(".\n").append(" *\n").append(" * @author ").append(SimpleProcessor.class.getCanonicalName()).append("\n").append(" */"); | |||
bw.newLine(); | |||
bw.append("@").append(Generated.class.getCanonicalName()).append("(\"").append(SimpleProcessor.class.getCanonicalName()).append("\")"); | |||
bw.newLine(); | |||
bw.append("final aspect ").append(classElement.getSimpleName()).append("EventsAspect").append(" {"); | |||
bw.newLine(); | |||
bw.newLine(); | |||
generateCallbacks(classElement, entry.getValue()); | |||
for (final Item item : entry.getValue()) { | |||
generateEvent(bw, classElement, item); | |||
generateEmit(bw, classElement, item); | |||
generateField(bw, classElement, item); | |||
generatePointcut(bw, classElement, item); | |||
} | |||
bw.append("}"); | |||
bw.newLine(); | |||
bw.newLine(); | |||
} | |||
} catch (final Throwable e) { | |||
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage()); | |||
} | |||
} | |||
} | |||
private static final class Item { | |||
private final ExecutableElement element; | |||
private final Event description; | |||
private Item(ExecutableElement element, Event description) { | |||
this.element = element; | |||
this.description = description; | |||
} | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
package test; | |||
public class Some { | |||
public static void main(String[] args) { | |||
Some some = new Some(); | |||
some.OnMethod1Event.add((emmiter) -> { | |||
System.out.println("callback registered from before aspect"); | |||
}); | |||
some.method1(); | |||
} | |||
@Event(Event.Order.Before) | |||
public void method1() { | |||
System.out.println("method1 is invoked"); | |||
} | |||
} |
@@ -23,7 +23,7 @@ public class Ajc10xTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc10x/ajc10x.xml"); | |||
return getClassResource("ajc10x.xml"); | |||
} | |||
public void test001() { |
@@ -22,7 +22,7 @@ public class Ajc11Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc11/ajc11.xml"); | |||
return getClassResource("ajc11.xml"); | |||
} | |||
public void test001() { |
@@ -20,7 +20,7 @@ public class Ajc120Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc120/ajc120.xml"); | |||
return getClassResource("ajc120.xml"); | |||
} | |||
@@ -25,7 +25,7 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc121/ajc121.xml"); | |||
return getClassResource("ajc121.xml"); | |||
} | |||
@@ -49,7 +49,7 @@ public class AccBridgeMethods extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
@@ -31,7 +31,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
public void testMixingCodeStyles_pr121385() { |
@@ -28,7 +28,7 @@ public class AnnotationBinding extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
// /////////////////////////////////// @ANNOTATION and CALL |
@@ -27,7 +27,7 @@ public class AnnotationPointcutsTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
// before(): call(@SimpleAnnotation * *(..)) { } |
@@ -26,7 +26,7 @@ public class AnnotationRuntimeTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
// No longer a limitation ASC 31Jan05 |
@@ -35,7 +35,7 @@ public class AnnotationsBinaryWeaving extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
// Cannot make ITD (c/m/f) on an annotation |
@@ -27,7 +27,7 @@ public class Autoboxing extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
public void testSimpleBoxing() { |
@@ -63,7 +63,7 @@ public class CovarianceTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
private boolean verbose = false; | |||
@@ -28,7 +28,7 @@ public class DeclareAnnotationTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
// parsing the various forms of declare @ |
@@ -37,7 +37,7 @@ public class Enums extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
// Cannot make ITDC on an enum |
@@ -36,7 +36,7 @@ public class GenericITDsDesign extends XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
private void verifyDebugString(ResolvedMember theMember, String string) { |
@@ -185,7 +185,7 @@ public class GenericsTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
public void testITDReturningParameterizedType() { |
@@ -23,7 +23,7 @@ public class HasMember extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
public void testSimpleDecPHasMethod() { |
@@ -27,7 +27,7 @@ public class MigrationTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
/** | |||
* Compile a simple java class with an aspect library built with aspectj 1.2.1 - this |
@@ -26,7 +26,7 @@ public class PerTypeWithinTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
/** | |||
@@ -67,10 +67,10 @@ public class PerTypeWithinTests extends XMLBasedAjcTestCase { | |||
* infrastructure is properly hidden in ajc$ or synthetic members) | |||
*/ | |||
public void testPervasivenessOfWeaving() { | |||
CompilationResult cR = ajc(new File("../tests/java5/pertypewithin"),new String[]{"U.java","-showWeaveInfo"}); | |||
CompilationResult cR = ajc(new File("tests/java5/pertypewithin"),new String[]{"U.java","-showWeaveInfo"}); | |||
int weavingMessagesFromNormalDeploymentModel = cR.getWeaveMessages().size(); | |||
cR = ajc(new File("../tests/java5/pertypewithin"),new String[]{"V.java","-showWeaveInfo"}); | |||
cR = ajc(new File("tests/java5/pertypewithin"),new String[]{"V.java","-showWeaveInfo"}); | |||
int weavingMessagesFromPerTypeWithin = cR.getWeaveMessages().size(); | |||
assertEquals("Expected same number of messages regardless of perclause", |
@@ -16,7 +16,7 @@ public class RuntimeAnnotations extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
public void test01() { |
@@ -23,7 +23,7 @@ public class StaticImports extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
public void testImportStaticSystemDotOut() { |
@@ -23,7 +23,7 @@ public class SuppressedWarnings extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
// Check basic suppression |
@@ -30,7 +30,7 @@ public class VarargsTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml"); | |||
return getClassResource("ajc150.xml"); | |||
} | |||
// check when signature is from a call PCD |
@@ -6,7 +6,7 @@ | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* initial development Jonas Bonér, Alexandre Vasseur | |||
* initial development Jonas Bon�r, Alexandre Vasseur | |||
*******************************************************************************/ | |||
package org.aspectj.systemtest.ajc150.ataspectj; | |||
@@ -28,7 +28,7 @@ public class AtAjAnnotationGenTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml"); | |||
return getClassResource("annotationgen.xml"); | |||
} | |||
public void testSimpleAspect() { |
@@ -28,7 +28,7 @@ public class AtAjLTWTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml"); | |||
return getClassResource("ltw.xml"); | |||
} | |||
public void testRunThemAllWithJavacCompiledAndLTW() { |
@@ -22,7 +22,7 @@ import org.aspectj.testing.XMLBasedAjcTestCase; | |||
public class AtAjMisuseTests extends XMLBasedAjcTestCase { | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml"); | |||
return getClassResource("misuse.xml"); | |||
} | |||
public static Test suite() { |
@@ -29,7 +29,7 @@ public class AtAjSyntaxTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml"); | |||
return getClassResource("syntax.xml"); | |||
} | |||
public void testSimpleBefore() { |
@@ -13,7 +13,7 @@ public class LTWServerTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml"); | |||
return getClassResource("ltw.xml"); | |||
} | |||
public void testServerWithHelloWorld () { |
@@ -27,7 +27,7 @@ public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml"); | |||
return getClassResource("ltw.xml"); | |||
} | |||
public void testInclusionAndPattern() { |
@@ -1,5 +1,5 @@ | |||
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[ | |||
<!ENTITY tests SYSTEM "../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml"> | |||
<!ENTITY tests SYSTEM "tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml"> | |||
]> | |||
<!-- Load-time weaving tests --> |
@@ -279,7 +279,7 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc151/ajc151.xml"); | |||
return getClassResource("ajc151.xml"); | |||
} | |||
} |
@@ -83,7 +83,7 @@ public class AtAroundTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc151/ataround.xml"); | |||
return getClassResource("ataround.xml"); | |||
} | |||
} |
@@ -119,7 +119,7 @@ public class NewarrayJoinpointTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml"); | |||
return getClassResource("newarray_joinpoint.xml"); | |||
} | |||
} |
@@ -31,7 +31,7 @@ public class SerialVersionUIDTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc151/serialversionuid.xml"); | |||
return getClassResource("serialversionuid.xml"); | |||
} | |||
} |
@@ -378,7 +378,7 @@ public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc152/ajc152.xml"); | |||
return getClassResource("ajc152.xml"); | |||
} | |||
} |
@@ -255,7 +255,7 @@ public class SynchronizationTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc152/synchronization.xml"); | |||
return getClassResource("synchronization.xml"); | |||
} | |||
} |
@@ -301,7 +301,7 @@ public class SynchronizationTransformTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc152/synchronization.xml"); | |||
return getClassResource("synchronization.xml"); | |||
} | |||
public void tearDown() { |
@@ -502,7 +502,7 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc153/ajc153.xml"); | |||
return getClassResource("ajc153.xml"); | |||
} | |||
} |
@@ -547,7 +547,7 @@ public class JDTLikeHandleProviderTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc153/jdtlikehandleprovider.xml"); | |||
return getClassResource("jdtlikehandleprovider.xml"); | |||
} | |||
} |
@@ -13,7 +13,7 @@ public class LTWServer153Tests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc153/ajc153.xml"); | |||
return getClassResource("ajc153.xml"); | |||
} | |||
public void testHandleDuplicateConfiguration_pr157474 () { |
@@ -84,6 +84,6 @@ public class PipeliningTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
return XMLBasedAjcTestCase.loadSuite(PipeliningTests.class); | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc153/pipelining.xml"); | |||
return getClassResource("pipelining.xml"); | |||
} | |||
} |
@@ -354,7 +354,7 @@ public class Ajc154Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc154/ajc154.xml"); | |||
return getClassResource("ajc154.xml"); | |||
} | |||
// --- |
@@ -148,7 +148,7 @@ public class Ajc160Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc160/ajc160.xml"); | |||
return getClassResource("ajc160.xml"); | |||
} | |||
} |
@@ -50,6 +50,6 @@ public class AnnotationValueMatchingTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc160/annotationValueMatching.xml"); | |||
return getClassResource("annotationValueMatching.xml"); | |||
} | |||
} |
@@ -28,7 +28,7 @@ public class NewFeatures extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc160/newfeatures-tests.xml"); | |||
return getClassResource("newfeatures-tests.xml"); | |||
} | |||
@@ -93,6 +93,6 @@ public class ParameterAnnotationMatchingTests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc160/parameterAnnotations.xml"); | |||
return getClassResource("parameterAnnotations.xml"); | |||
} | |||
} |
@@ -156,7 +156,7 @@ public class SanityTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc160/sanity-tests.xml"); | |||
return getClassResource("sanity-tests.xml"); | |||
} | |||
} |
@@ -198,7 +198,7 @@ public class Ajc161Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc161/ajc161.xml"); | |||
return getClassResource("ajc161.xml"); | |||
} | |||
} |
@@ -67,6 +67,6 @@ public class OptimizedAnnotationFieldBinding extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc161/annotationFieldBinding.xml"); | |||
return getClassResource("annotationFieldBinding.xml"); | |||
} | |||
} |
@@ -61,7 +61,7 @@ public class Ajc1610Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc1610/ajc1610.xml"); | |||
return getClassResource("ajc1610.xml"); | |||
} | |||
} |
@@ -145,7 +145,7 @@ public class NewFeatures extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc1610/newfeatures-tests.xml"); | |||
return getClassResource("newfeatures-tests.xml"); | |||
} | |||
} |
@@ -123,7 +123,7 @@ public class Ajc1611Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc1611/ajc1611.xml"); | |||
return getClassResource("ajc1611.xml"); | |||
} | |||
} |
@@ -71,7 +71,7 @@ public class NewFeatures extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml"); | |||
return getClassResource("newfeatures-tests.xml"); | |||
} | |||
} |
@@ -414,7 +414,7 @@ public class Ajc1612Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc1612/ajc1612.xml"); | |||
return getClassResource("ajc1612.xml"); | |||
} | |||
} |
@@ -217,7 +217,7 @@ public class Ajc162Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc162/ajc162.xml"); | |||
return getClassResource("ajc162.xml"); | |||
} | |||
} |
@@ -306,7 +306,7 @@ public class Ajc163Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc163/ajc163.xml"); | |||
return getClassResource("ajc163.xml"); | |||
} | |||
// --- |
@@ -417,7 +417,7 @@ public class Ajc164Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc164/ajc164.xml"); | |||
return getClassResource("ajc164.xml"); | |||
} | |||
private IProgramElement findElementAtLine(IProgramElement whereToLook, int line) { |
@@ -151,7 +151,7 @@ public class DeclareMixinTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml"); | |||
return getClassResource("declareMixin.xml"); | |||
} | |||
} |
@@ -33,7 +33,7 @@ public class JointpointIdTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc164/joinpointid.xml"); | |||
return getClassResource("joinpointid.xml"); | |||
} | |||
} |
@@ -116,7 +116,7 @@ public class Ajc165Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc165/ajc165.xml"); | |||
return getClassResource("ajc165.xml"); | |||
} | |||
} |
@@ -99,7 +99,7 @@ public class Ajc166Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc166/ajc166.xml"); | |||
return getClassResource("ajc166.xml"); | |||
} | |||
} |
@@ -83,7 +83,7 @@ public class Ajc167Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc167/ajc167.xml"); | |||
return getClassResource("ajc167.xml"); | |||
} | |||
} |
@@ -78,7 +78,7 @@ public class OverweavingTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc167/overweaving.xml"); | |||
return getClassResource("overweaving.xml"); | |||
} | |||
} |
@@ -247,7 +247,7 @@ public class Ajc169Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc169/ajc169.xml"); | |||
return getClassResource("ajc169.xml"); | |||
} | |||
} |
@@ -208,7 +208,7 @@ public class IntertypeTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc169/intertype.xml"); | |||
return getClassResource("intertype.xml"); | |||
} | |||
} |
@@ -238,7 +238,7 @@ public class TransparentWeavingTests extends org.aspectj.testing.XMLBasedAjcTest | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc169/transparentweaving.xml"); | |||
return getClassResource("transparentweaving.xml"); | |||
} | |||
} |
@@ -69,7 +69,7 @@ public class Ajc171Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc171/ajc171.xml"); | |||
return getClassResource("ajc171.xml"); | |||
} | |||
} |
@@ -204,7 +204,7 @@ public class Ajc172Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc172/ajc172.xml"); | |||
return getClassResource("ajc172.xml"); | |||
} | |||
} |
@@ -78,7 +78,7 @@ public class Ajc173Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc173/ajc173.xml"); | |||
return getClassResource("ajc173.xml"); | |||
} | |||
} |
@@ -90,7 +90,7 @@ public class Ajc174Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc174/ajc174.xml"); | |||
return getClassResource("ajc174.xml"); | |||
} | |||
} |
@@ -36,7 +36,7 @@ public class Ajc175Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc175/ajc175.xml"); | |||
return getClassResource("ajc175.xml"); | |||
} | |||
public static void main(String[] args) { |
@@ -53,7 +53,7 @@ public class Ajc180Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc180/ajc180.xml"); | |||
return getClassResource("ajc180.xml"); | |||
} | |||
} |
@@ -60,7 +60,7 @@ public class Ajc181Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
@Override | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/ajc181/ajc181.xml"); | |||
return getClassResource("ajc181.xml"); | |||
} | |||
} |
@@ -12,6 +12,7 @@ package org.aspectj.systemtest.ajc181; | |||
import junit.framework.Test; | |||
import junit.framework.TestSuite; | |||
import org.aspectj.systemtest.apt.AptTests; | |||
public class AllTestsAspectJ181 { | |||
@@ -19,6 +20,7 @@ public class AllTestsAspectJ181 { | |||
TestSuite suite = new TestSuite("AspectJ 1.8.1 tests"); | |||
// $JUnit-BEGIN$ | |||
suite.addTest(Ajc181Tests.suite()); | |||
suite.addTest(AptTests.suite()); | |||
// $JUnit-END$ | |||
return suite; | |||
} |
@@ -0,0 +1,25 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2014 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://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial API and implementation | |||
*******************************************************************************/ | |||
package org.aspectj.systemtest.apt; | |||
import junit.framework.Test; | |||
import junit.framework.TestSuite; | |||
public class AllTestsApt { | |||
public static Test suite() { | |||
TestSuite suite = new TestSuite("Annotation processing tests"); | |||
// $JUnit-BEGIN$ | |||
suite.addTest(AptTests.suite()); | |||
// $JUnit-END$ | |||
return suite; | |||
} | |||
} |
@@ -0,0 +1,51 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2014 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://www.eclipse.org/legal/epl-v10.html | |||
* | |||
* Contributors: | |||
* Andy Clement - initial API and implementation | |||
*******************************************************************************/ | |||
package org.aspectj.systemtest.apt; | |||
import junit.framework.Test; | |||
import org.aspectj.apache.bcel.classfile.Method; | |||
import org.aspectj.testing.XMLBasedAjcTestCase; | |||
import java.io.File; | |||
import java.nio.file.Files; | |||
/** | |||
* Annotation processing tool tests. | |||
* | |||
* @author Sergey Stupin. | |||
*/ | |||
public class AptTests extends XMLBasedAjcTestCase { | |||
public void testAptWithSpecifiedProcessor() { | |||
runTest("annotation processing with specified processor"); | |||
} | |||
/** | |||
* SPI - http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html | |||
*/ | |||
public void testAptUsingSPI() { | |||
runTest("annotation processing in action using SPI"); | |||
} | |||
public void testDisabledApt() { | |||
runTest("disabled annotation processing"); | |||
} | |||
public static Test suite() { | |||
return XMLBasedAjcTestCase.loadSuite(AptTests.class); | |||
} | |||
@Override | |||
protected File getSpecFile() { | |||
return getClassResource("apt-spec.xml"); | |||
} | |||
} |
@@ -0,0 +1,88 @@ | |||
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]> | |||
<suite> | |||
<ajc-test dir="apt" title="annotation processing with specified processor"> | |||
<compile options="-1.8" files="processor/Event.java processor/SimpleProcessor.java" | |||
outjar="annotation_processor.jar"/> | |||
<!-- | |||
SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation: | |||
- {className}EventsAspect.aj - this file describes aspect with advices to weaving method annotated with @Event. | |||
- {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example: | |||
public final class SomeCallbacks { | |||
public interface OnMethod1 { | |||
void changed(Some emmiter); | |||
} | |||
} | |||
--> | |||
<compile options="-1.8 -processor test.SimpleProcessor -s generated -showWeaveInfo" files="src/Some.java" | |||
classpath="annotation_processor.jar" outjar="code.jar"> | |||
<message kind="weave" | |||
text="Type 'test.Some' (Some.java) has intertyped field from 'test.SomeEventsAspect' (SomeEventsAspect.aj:'test.SomeEventsAspect$SomeOnMethod1Event test.Some.OnMethod1Event')"/> | |||
<message kind="weave" | |||
text="Join point 'method-execution(void test.Some.method1())' in Type 'test.Some' (Some.java:14) advised by before advice from 'test.SomeEventsAspect' (SomeEventsAspect.aj:44)"/> | |||
</compile> | |||
<run class="test.Some"> | |||
<stdout> | |||
<line text="callback registered from before aspect"/> | |||
<line text="method1 is invoked"/> | |||
</stdout> | |||
</run> | |||
</ajc-test> | |||
<ajc-test dir="apt" title="annotation processing in action using SPI"> | |||
<!-- | |||
what is SPI is described here - http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html | |||
--> | |||
<!--<compile options="-1.8" files="processor/Event.java processor/SimpleProcessor.java" outjar="annotation_processors_with_spi.jar"/>--> | |||
<compile options="-1.8 -sourceroots processor" inpath="processor/" outjar="annotation_processor.jar"/> | |||
<!-- | |||
SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation: | |||
- {className}EventsAspect.aj - this file describes aspect with advices to weaving method annotated with @Event. | |||
- {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example: | |||
public final class SomeCallbacks { | |||
public interface OnMethod1 { | |||
void changed(Some emmiter); | |||
} | |||
} | |||
--> | |||
<!--apt_service_description.jar contains only SPI descrition file - META-INF/services/javax.annotation.processing.Processor--> | |||
<compile options="-1.8 -s generated -showWeaveInfo" files="src/Some.java" | |||
classpath="annotation_processor.jar;apt_service_description.jar" outjar="code.jar"> | |||
<message kind="weave" | |||
text="Type 'test.Some' (Some.java) has intertyped field from 'test.SomeEventsAspect' (SomeEventsAspect.aj:'test.SomeEventsAspect$SomeOnMethod1Event test.Some.OnMethod1Event')"/> | |||
<message kind="weave" | |||
text="Join point 'method-execution(void test.Some.method1())' in Type 'test.Some' (Some.java:14) advised by before advice from 'test.SomeEventsAspect' (SomeEventsAspect.aj:44)"/> | |||
</compile> | |||
<run class="test.Some"> | |||
<stdout> | |||
<line text="callback registered from before aspect"/> | |||
<line text="method1 is invoked"/> | |||
</stdout> | |||
</run> | |||
</ajc-test> | |||
<ajc-test dir="apt" title="disabled annotation processing"> | |||
<compile options="-1.8" files="processor/Event.java processor/SimpleProcessor.java" | |||
outjar="annotation_processor.jar"/> | |||
<!-- | |||
SimpleProcessor should generate 2 files for each java class that utilizes @Event annotation: | |||
- {className}EventsAspect.aj - this file describes aspect with advices to weaving method annotated with @Event. | |||
- {className}Callbacks.java - this file contains callback interfaces for methods annotated with @Event. Example: | |||
public final class SomeCallbacks { | |||
public interface OnMethod1 { | |||
void changed(Some emmiter); | |||
} | |||
} | |||
--> | |||
<compile options="-1.8 -s generated -showWeaveInfo -proc:none" files="src/Some.java" | |||
classpath="annotation_processor.jar" outjar="code.jar"> | |||
<!--field was not injected, so error should occur--> | |||
<message kind="error" text="OnMethod1Event cannot be resolved or is not a field"/> | |||
</compile> | |||
</ajc-test> | |||
</suite> |
@@ -20,7 +20,7 @@ public class AspectPathTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/aspectpath/aspectpath.xml"); | |||
return getClassResource("aspectpath.xml"); | |||
} | |||
@@ -20,7 +20,7 @@ public class BaseTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/base/baseTests.xml"); | |||
return getClassResource("baseTests.xml"); | |||
} | |||
@@ -20,7 +20,7 @@ public class DesignTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/design/design.xml"); | |||
return getClassResource("design.xml"); | |||
} | |||
@@ -25,7 +25,7 @@ public class IncrementalTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/incremental/incremental.xml"); | |||
return getClassResource("incremental.xml"); | |||
} | |||
@@ -24,7 +24,7 @@ public class IncrementalModelTests extends org.aspectj.testing.XMLBasedAjcTestCa | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/incremental/model/incremental-model.xml"); | |||
return getClassResource("incremental-model.xml"); | |||
} | |||
// This first test doesnt do a lot currently, but is ready too... |
@@ -20,7 +20,7 @@ public class InPathTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/inpath/inpath.xml"); | |||
return getClassResource("inpath.xml"); | |||
} | |||
@@ -23,7 +23,7 @@ public class Java14Tests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/java14/java14.xml"); | |||
return getClassResource("java14.xml"); | |||
} | |||
@@ -87,7 +87,7 @@ public class Model5Tests extends ModelTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/model/model.xml"); | |||
return getClassResource("model.xml"); | |||
} | |||
} |
@@ -108,7 +108,7 @@ public class ModelTests extends ModelTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/model/model.xml"); | |||
return getClassResource("model.xml"); | |||
} | |||
} |
@@ -20,7 +20,7 @@ public class OptionsTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/options/options.xml"); | |||
return getClassResource("options.xml"); | |||
} | |||
@@ -20,7 +20,7 @@ public class AjcPre10xTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/pre10x/pre10x.xml"); | |||
return getClassResource("pre10x.xml"); | |||
} | |||
@@ -20,7 +20,7 @@ public class SUIDTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/serialVerUID/serialVerUID.xml"); | |||
return getClassResource("serialVerUID.xml"); | |||
} | |||
@@ -23,7 +23,7 @@ public class TracingTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/tracing/tracing.xml"); | |||
return getClassResource("tracing.xml"); | |||
} | |||
public void testTracing () { |
@@ -23,7 +23,7 @@ public class XLint5Tests extends XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/xlint/xlint.xml"); | |||
return getClassResource("xlint.xml"); | |||
} | |||
public void testBug99136(){ |
@@ -23,7 +23,7 @@ public class XLintTests extends org.aspectj.testing.XMLBasedAjcTestCase { | |||
} | |||
protected File getSpecFile() { | |||
return new File("../tests/src/org/aspectj/systemtest/xlint/xlint.xml"); | |||
return getClassResource("xlint.xml"); | |||
} | |||
@@ -245,7 +245,7 @@ public class FileUtil { | |||
/** | |||
* Extract the name of a class from the path to its file. If the basedir is null, then the class is assumed to be in the default | |||
* package unless the classFile has one of the top-level suffixes { com, org, java, javax } as a parent directory. | |||
* | |||
* | |||
* @param basedir the File of the base directory (prefix of classFile) | |||
* @param classFile the File of the class to extract the name for | |||
* @throws IllegalArgumentException if classFile is null or does not end with ".class" or a non-null basedir is not a prefix of | |||
@@ -288,7 +288,7 @@ public class FileUtil { | |||
/** | |||
* Normalize path for comparisons by rendering absolute, clipping basedir prefix, trimming and changing '\\' to '/' | |||
* | |||
* | |||
* @param file the File with the path to normalize | |||
* @param basedir the File for the prefix of the file to normalize - ignored if null | |||
* @return "" if null or normalized path otherwise | |||
@@ -310,7 +310,7 @@ public class FileUtil { | |||
/** | |||
* Render a set of files to String as a path by getting absolute paths of each and delimiting with infix. | |||
* | |||
* | |||
* @param files the File[] to flatten - may be null or empty | |||
* @param infix the String delimiter internally between entries (if null, then use File.pathSeparator). (alias to | |||
* <code>flatten(getAbsolutePaths(files), infix)</code> | |||
@@ -325,7 +325,7 @@ public class FileUtil { | |||
/** | |||
* Flatten File[] to String. | |||
* | |||
* | |||
* @param files the File[] of paths to flatten - null ignored | |||
* @param infix the String infix to use - null treated as File.pathSeparator | |||
*/ | |||
@@ -352,7 +352,7 @@ public class FileUtil { | |||
/** | |||
* Normalize path for comparisons by rendering absolute trimming and changing '\\' to '/' | |||
* | |||
* | |||
* @return "" if null or normalized path otherwise | |||
*/ | |||
public static String normalizedPath(File file) { | |||
@@ -372,7 +372,7 @@ public class FileUtil { | |||
/** | |||
* Get best File for the first-readable path in input paths, treating entries prefixed "sp:" as system property keys. Safe to | |||
* call in static initializers. | |||
* | |||
* | |||
* @param paths the String[] of paths to check. | |||
* @return null if not found, or valid File otherwise | |||
*/ | |||
@@ -410,7 +410,7 @@ public class FileUtil { | |||
/** | |||
* Render as best file, canonical or absolute. | |||
* | |||
* | |||
* @param file the File to get the best File for (not null) | |||
* @return File of the best-available path | |||
* @throws IllegalArgumentException if file is null | |||
@@ -430,7 +430,7 @@ public class FileUtil { | |||
/** | |||
* Render as best path, canonical or absolute. | |||
* | |||
* | |||
* @param file the File to get the path for (not null) | |||
* @return String of the best-available path | |||
* @throws IllegalArgumentException if file is null | |||
@@ -464,7 +464,7 @@ public class FileUtil { | |||
/** | |||
* Recursively delete the contents of dir, but not the dir itself | |||
* | |||
* | |||
* @return the total number of files deleted | |||
*/ | |||
public static int deleteContents(File dir) { | |||
@@ -474,7 +474,7 @@ public class FileUtil { | |||
/** | |||
* Recursively delete some contents of dir, but not the dir itself. This deletes any subdirectory which is empty after its files | |||
* are deleted. | |||
* | |||
* | |||
* @return the total number of files deleted | |||
*/ | |||
public static int deleteContents(File dir, FileFilter filter) { | |||
@@ -484,7 +484,7 @@ public class FileUtil { | |||
/** | |||
* Recursively delete some contents of dir, but not the dir itself. If deleteEmptyDirs is true, this deletes any subdirectory | |||
* which is empty after its files are deleted. | |||
* | |||
* | |||
* @param dir the File directory (if a file, the the file is deleted) | |||
* @return the total number of files deleted | |||
*/ | |||
@@ -499,21 +499,28 @@ public class FileUtil { | |||
dir.delete(); | |||
return 1; | |||
} | |||
String[] fromFiles = dir.list(); | |||
int result = 0; | |||
for (int i = 0; i < fromFiles.length; i++) { | |||
String string = fromFiles[i]; | |||
File file = new File(dir, string); | |||
if ((null == filter) || filter.accept(file)) { | |||
if (file.isDirectory()) { | |||
result += deleteContents(file, filter, deleteEmptyDirs); | |||
if (deleteEmptyDirs && (0 == file.list().length)) { | |||
file.delete(); | |||
} | |||
} else { | |||
/* boolean ret = */file.delete(); | |||
result++; | |||
} | |||
String[] fromFiles = dir.list(); | |||
if (fromFiles == null) { | |||
return 0; | |||
} | |||
int result = 0; | |||
for (int i = 0; i < fromFiles.length; i++) { | |||
String string = fromFiles[i]; | |||
File file = new File(dir, string); | |||
if ((null == filter) || filter.accept(file)) { | |||
if (file.isDirectory()) { | |||
result += deleteContents(file, filter, deleteEmptyDirs); | |||
String[] fileContent = file.list(); | |||
if (deleteEmptyDirs && | |||
fileContent != null && | |||
0 == fileContent.length) { | |||
file.delete(); | |||
} | |||
} else { | |||
/* boolean ret = */ | |||
file.delete(); | |||
result++; | |||
} | |||
} | |||
} | |||
return result; | |||
@@ -521,7 +528,7 @@ public class FileUtil { | |||
/** | |||
* Copy contents of fromDir into toDir | |||
* | |||
* | |||
* @param fromDir must exist and be readable | |||
* @param toDir must exist or be creatable and be writable | |||
* @return the total number of files copied | |||
@@ -534,7 +541,7 @@ public class FileUtil { | |||
* Recursively copy files in fromDir (with any fromSuffix) to toDir, replacing fromSuffix with toSuffix if any. This silently | |||
* ignores dirs and files that are not readable but throw IOException for directories that are not writable. This does not clean | |||
* out the original contents of toDir. (subdirectories are not renamed per directory rules) | |||
* | |||
* | |||
* @param fromSuffix select files with this suffix - select all if null or empty | |||
* @param toSuffix replace fromSuffix with toSuffix in the destination file name - ignored if null or empty, appended to name if | |||
* fromSuffix is null or empty | |||
@@ -584,7 +591,7 @@ public class FileUtil { | |||
* ignores dirs and files that are not readable but throw IOException for directories that are not writable. This does not clean | |||
* out the original contents of toDir. (subdirectories are not renamed per directory rules) This calls any delegate | |||
* FilenameFilter to collect any selected file. | |||
* | |||
* | |||
* @param fromSuffix select files with this suffix - select all if null or empty | |||
* @param toSuffix replace fromSuffix with toSuffix in the destination file name - ignored if null or empty, appended to name if | |||
* fromSuffix is null or empty | |||
@@ -641,7 +648,7 @@ public class FileUtil { | |||
/** | |||
* Recursively list files in srcDir. | |||
* | |||
* | |||
* @return ArrayList with String paths of File under srcDir (relative to srcDir) | |||
*/ | |||
public static String[] listFiles(File srcDir) { | |||
@@ -661,7 +668,7 @@ public class FileUtil { | |||
/** | |||
* Recursively list files in srcDir. | |||
* | |||
* | |||
* @return ArrayList with String paths of File under srcDir (relative to srcDir) | |||
*/ | |||
public static File[] listFiles(File srcDir, FileFilter fileFilter) { | |||
@@ -674,7 +681,7 @@ public class FileUtil { | |||
/** | |||
* Recursively list .class files in specified directory | |||
* | |||
* | |||
* @return List of File objects | |||
*/ | |||
public static List<File> listClassFiles(File dir) { | |||
@@ -687,7 +694,7 @@ public class FileUtil { | |||
/** | |||
* Convert String[] paths to File[] as offset of base directory | |||
* | |||
* | |||
* @param basedir the non-null File base directory for File to create with paths | |||
* @param paths the String[] of paths to create | |||
* @return File[] with same length as paths | |||
@@ -698,7 +705,7 @@ public class FileUtil { | |||
/** | |||
* Convert String[] paths to File[] as offset of base directory | |||
* | |||
* | |||
* @param basedir the non-null File base directory for File to create with paths | |||
* @param paths the String[] of paths to create | |||
* @param suffixes the String[] of suffixes to limit sources to - ignored if null | |||
@@ -731,7 +738,7 @@ public class FileUtil { | |||
/** | |||
* Create a new File, resolving paths ".." and "." specially. | |||
* | |||
* | |||
* @param dir the File for the parent directory of the file | |||
* @param path the path in the parent directory (filename only?) | |||
* @return File for the new file. | |||
@@ -755,7 +762,7 @@ public class FileUtil { | |||
* Copy files from source dir into destination directory, creating any needed directories. This differs from copyDir in not | |||
* being recursive; each input with the source dir creates a full path. However, if the source is a directory, it is copied as | |||
* such. | |||
* | |||
* | |||
* @param srcDir an existing, readable directory containing relativePaths files | |||
* @param relativePaths a set of paths relative to srcDir to readable File to copy | |||
* @param destDir an existing, writable directory to copy files to | |||
@@ -785,7 +792,7 @@ public class FileUtil { | |||
/** | |||
* Copy fromFile to toFile, handling file-file, dir-dir, and file-dir copies. | |||
* | |||
* | |||
* @param fromFile the File path of the file or directory to copy - must be readable | |||
* @param toFile the File path of the target file or directory - must be writable (will be created if it does not exist) | |||
*/ | |||
@@ -825,7 +832,7 @@ public class FileUtil { | |||
/** | |||
* Ensure that the parent directory to path can be written. If the path has a null parent, DEFAULT_PARENT is tested. If the path | |||
* parent does not exist, this tries to create it. | |||
* | |||
* | |||
* @param path the File path whose parent should be writable | |||
* @return the File path of the writable parent directory | |||
* @throws IllegalArgumentException if parent cannot be written or path is null. | |||
@@ -845,7 +852,7 @@ public class FileUtil { | |||
/** | |||
* Copy file to file. | |||
* | |||
* | |||
* @param fromFile the File to copy (readable, non-null file) | |||
* @param toFile the File to copy to (non-null, parent dir exists) | |||
* @throws IOException | |||
@@ -896,7 +903,7 @@ public class FileUtil { | |||
/** | |||
* Make a new child directory of parent | |||
* | |||
* | |||
* @param parent a File for the parent (writable) | |||
* @param child a prefix for the child directory | |||
* @return a File dir that exists with parentDir as the parent file or null | |||
@@ -924,7 +931,7 @@ public class FileUtil { | |||
/** | |||
* Make a new temporary directory in the same directory that the system uses for temporary files, or if that files, in the | |||
* current directory. | |||
* | |||
* | |||
* @param name the preferred (simple) name of the directory - may be null. | |||
* @return File of an existing new temp dir, or null if unable to create | |||
*/ | |||
@@ -963,7 +970,7 @@ public class FileUtil { | |||
/** | |||
* Get URL for a File. This appends "/" for directories. prints errors to System.err | |||
* | |||
* | |||
* @param file the File to convert to URL (not null) | |||
*/ | |||
@SuppressWarnings("deprecation") | |||
@@ -988,7 +995,7 @@ public class FileUtil { | |||
/** | |||
* Write contents to file, returning null on success or error message otherwise. This tries to make any necessary parent | |||
* directories first. | |||
* | |||
* | |||
* @param file the File to write (not null) | |||
* @param contents the String to write (use "" if null) | |||
* @return String null on no error, error otherwise | |||
@@ -1221,7 +1228,7 @@ public class FileUtil { | |||
/** | |||
* Do line-based search for literal text in source files, returning file:line where found. | |||
* | |||
* | |||
* @param sought the String text to seek in the file | |||
* @param sources the List of String paths to the source files | |||
* @param listAll if false, only list first match in file | |||
@@ -1248,7 +1255,7 @@ public class FileUtil { | |||
* Do line-based search for literal text in source file, returning line where found as a String in the form | |||
* {sourcePath}:line:column submitted to the collecting parameter sink. Any error is rendered to String and returned as the | |||
* result. | |||
* | |||
* | |||
* @param sought the String text to seek in the file | |||
* @param sources the List of String paths to the source files | |||
* @param listAll if false, only list first match in file | |||
@@ -1305,7 +1312,7 @@ public class FileUtil { | |||
/** | |||
* Sleep until after the last last-modified stamp from the files. | |||
* | |||
* | |||
* @param files the File[] of files to inspect for last modified times (this ignores null or empty files array and null or | |||
* non-existing components of files array) | |||
* @return true if succeeded without 100 interrupts | |||
@@ -1402,7 +1409,7 @@ public class FileUtil { | |||
return url.toURI().getPath(); | |||
} catch (URISyntaxException e) { | |||
System.err.println("Warning!! Malformed URL may cause problems: "+url); // TODO: Better way to report this? | |||
// In this case it was likely not using properly escaped | |||
// In this case it was likely not using properly escaped | |||
// characters so we just use the 'bad' method that doesn't decode | |||
// special chars | |||
return url.getPath(); | |||
@@ -1411,7 +1418,7 @@ public class FileUtil { | |||
/** | |||
* A pipe when run reads from an input stream to an output stream, optionally sleeping between reads. | |||
* | |||
* | |||
* @see #copyStream(InputStream, OutputStream) | |||
*/ | |||
public static class Pipe implements Runnable { | |||
@@ -1437,7 +1444,7 @@ public class FileUtil { | |||
/** | |||
* alias for <code>Pipe(in, out, 100l, false, false)</code> | |||
* | |||
* | |||
* @param in the InputStream source to read | |||
* @param out the OutputStream sink to write | |||
*/ | |||
@@ -1523,7 +1530,7 @@ public class FileUtil { | |||
/** | |||
* Tell the pipe to halt the next time it gains control. | |||
* | |||
* | |||
* @param wait if true, this waits synchronously until pipe is done | |||
* @param finishStream if true, then continue until a read from the input stream returns no bytes, then halt. | |||
* @return true if <code>run()</code> will return the next time it gains control |