Browse Source

Prepare code, tests and docs for Java 18

- JDT Core dependency in pom.xml
- Constants.java
- LangUtil.java
- AjcTask.java
- messages_aspectj.properties

- XMLBasedAjcTestCaseForJava17Only.java
- XMLBasedAjcTestCaseForJava18*.java
- tests/bugs199
- tests/features199

- JavaVersionCompatibility.md
- README-199.html

- GitHub CI build

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tags/V1_9_9
Alexander Kriegisch 2 years ago
parent
commit
6dc09db0ca
32 changed files with 869 additions and 143 deletions
  1. 1
    1
      .github/workflows/maven.yml
  2. 4
    2
      bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java
  3. 1
    0
      docs/dist/doc/JavaVersionCompatibility.md
  4. 2
    7
      docs/dist/doc/README-198.html
  5. 126
    0
      docs/dist/doc/README-199.html
  6. 1
    1
      org.aspectj.ajdt.core/src/main/resources/org/aspectj/org/eclipse/jdt/internal/compiler/batch/messages_aspectj.properties
  7. 1
    1
      pom.xml
  8. 12
    3
      taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java
  9. 3
    3
      testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17Only.java
  10. 40
    0
      testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java
  11. 27
    0
      testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java
  12. 0
    0
      tests/bugs199/github_115/A.java
  13. 0
    0
      tests/bugs199/github_115/B.java
  14. 0
    0
      tests/bugs199/github_120/C.java
  15. 0
    0
      tests/bugs199/github_120/D.java
  16. 0
    0
      tests/bugs199/github_122/E.java
  17. 0
    0
      tests/bugs199/github_125/Application.java
  18. 28
    0
      tests/features199/java18/SwitchPatternPreview2Aspect.aj
  19. 31
    0
      tests/features199/java18/SwitchPatternPreview2Error.java
  20. 38
    0
      tests/features199/java18/SwitchPatternPreview2OK.java
  21. 24
    30
      tests/src/test/java/org/aspectj/systemtest/ajc198/Ajc198TestsJava.java
  22. 3
    0
      tests/src/test/java/org/aspectj/systemtest/ajc198/AllTestsAspectJ198.java
  23. 0
    27
      tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java
  24. 32
    0
      tests/src/test/java/org/aspectj/systemtest/ajc199/Ajc199TestsJava.java
  25. 31
    0
      tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java
  26. 56
    0
      tests/src/test/java/org/aspectj/systemtest/ajc199/Bugs199Tests.java
  27. 69
    0
      tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java
  28. 87
    0
      tests/src/test/java/org/aspectj/systemtest/ajc199/SanityTestsJava18.java
  29. 1
    68
      tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml
  30. 177
    0
      tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml
  31. 70
    0
      tests/src/test/resources/org/aspectj/systemtest/ajc199/sanity-tests-18.xml
  32. 4
    0
      util/src/main/java/org/aspectj/util/LangUtil.java

+ 1
- 1
.github/workflows/maven.yml View File

@@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [ 11, 17 ]
java: [ 11, 17, 18-ea ]

runs-on: ubuntu-latest


+ 4
- 2
bcel-builder/src/main/java/org/aspectj/apache/bcel/Constants.java View File

@@ -98,8 +98,10 @@ public interface Constants {
short MINOR_16 = 0;
short MAJOR_17 = 61;
short MINOR_17 = 0;
// short MAJOR_18 = 62;
// short MINOR_18 = 0;
short MAJOR_18 = 62;
short MINOR_18 = 0;
// short MAJOR_19 = 63;
// short MINOR_19 = 0;

int PREVIEW_MINOR_VERSION = 65535;


+ 1
- 0
docs/dist/doc/JavaVersionCompatibility.md View File

@@ -7,6 +7,7 @@ be easily concluded from the AspectJ version number anymore, and we are sorry fo

AspectJ version | Java version | Comments
----------------|--------------|--------
1.9.9 | 18
1.9.8 | 17 | AspectJ compiler requires JDK 11+ during build time. During runtime, AspectJ still only requires Java 8+ for both compile-time and load-time weaving. Pure Java code can be compiled down to as old as 1.3 byte code level.
1.9.7 | 15, 16
1.9.6 | 14

+ 2
- 7
docs/dist/doc/README-198.html View File

@@ -73,7 +73,8 @@
Cross-compilation to legacy JDK
</a>:
An example class which only works correctly on JDK 8 when compiled with <tt>--release 8</tt> due to API changes in
the JDK. Simply <tt>-source 8 -target 8</tt> would not be enough in this case.</li>
the JDK. Simply <tt>-source 8 -target 8</tt> would not be enough in this case.
</li>
<li>
<a href="https://github.com/eclipse/org.aspectj/tree/master/tests/features198/java17">
Pattern matching for switch
@@ -109,12 +110,6 @@
<a href="https://github.com/eclipse/org.aspectj/blob/de63b63d/tests/bugs198/github_68/Generator.java#L50-L61">
craft a condy class with ASM</a>.
</li>
<li>
Improvements for <tt>if()</tt> pointcuts in annotation syntax, see issues
<a href="https://github.com/eclipse/org.aspectj/issues/115">#115</a>,
<a href="https://github.com/eclipse/org.aspectj/issues/120">#120</a>,
<a href="https://github.com/eclipse/org.aspectj/issues/122">#122</a>.
</li>
<li>
Thanks to Andrey Turbanov for several clean code contributions and to Dmitry Mikhaylov for fixing a potential
concurrency problem.

+ 126
- 0
docs/dist/doc/README-199.html View File

@@ -0,0 +1,126 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>

<head>
<title>AspectJ 1.9.9 Readme</title>
<style type="text/css">
<!--
P { margin-left: 20px; }
PRE { margin-left: 20px; }
LI { margin-left: 20px; }
H4 { margin-left: 20px; }
H3 { margin-left: 10px; }
-->
</style>
</head>

<body>
<div align="right"><small>&copy; Copyright 2022 Contributors. All rights reserved.</small></div>

<h1>AspectJ 1.9.9</h1>

<p>
Please note that Bugzilla for issue management is deprecated and new issues should be filed as
<a href="https://github.com/eclipse/org.aspectj/issues/new">GitHub issues</a>.
The list of issues addressed for 1.9.9 can be found
<a href="https://bugs.eclipse.org/bugs/buglist.cgi?bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED&f0=OP&f1=OP&f3=CP&f4=CP&j1=OR&list_id=16866879&product=AspectJ&query_format=advanced&target_milestone=1.9.9">here for Bugzilla</a>
and <a href="https://github.com/eclipse/org.aspectj/issues?q=is%3Aissue+is%3Aclosed++milestone%3A1.9.9">here for GitHub issues</a>.
</p>

<h2>New features</h2>

<p>
AspectJ 1.9.9 supports <a href="https://openjdk.java.net/projects/jdk/18/">Java 18</a> and its final and preview
features, such as:
</p>
<ul>
<li>Pattern matching for <tt>switch</tt> (preview 2)</li>
</ul>

<h2>Improvements</h2>

<h2>Code examples</h2>

<p>
You can find some sample code in the AspectJ test suite under the respective AspectJ version in which the features
were first supported (possibly as JVM preview features):
</p>
<ul>
<li>
<a href="https://github.com/eclipse/org.aspectj/tree/master/tests/features198/java17">
Pattern matching for switch, preview 1
</a>
</li>
<li>
<a href="https://github.com/eclipse/org.aspectj/tree/master/tests/features199/java18">
Pattern matching for switch, preview 2
</a>
</li>
</ul>

<h2>Other changes and bug fixes</h2>

<ul>
<li>
Fix a bug which led to <tt>NullPointerException</tt>s if too many JAR archives were on the classpath. Too many here
means the value system property <tt>org.aspectj.weaver.openarchives</tt> (1,000 by default). The AspectJ compiler is
meant to close archives upon cache exhaustion and then re-open them if it needs them again later. Re-opening was
broken, now the compiler works reliably even for cache sizes as small as 20. See issue
<a href="https://github.com/eclipse/org.aspectj/issues/125">#125</a>.
</li>
<li>
Improvements for <tt>if()</tt> pointcuts in annotation syntax, see issues
<a href="https://github.com/eclipse/org.aspectj/issues/115">#115</a>,
<a href="https://github.com/eclipse/org.aspectj/issues/120">#120</a>,
<a href="https://github.com/eclipse/org.aspectj/issues/122">#122</a>.
</li>
<li>
Thanks to Andrey Turbanov for several clean code contributions.
</li>
</ul>

<h2>AspectJ usage hints</h2>

<h3>AspectJ compiler build system requirements</h3>

<p>
Since 1.9.7, the AspectJ compiler <tt>ajc</tt> (contained in the <tt>aspectjtools</tt> library) no longer works on
JDKs 8 to 10. The minimum compile-time requirement is now JDK 11 due to upstream changes in the Eclipse Java Compiler
(subset of JDT Core), which AspectJ is a fork of. You can still compile to legacy target versions as low as Java 1.3
when compiling plain Java code or using plain Java ITD constructs which do not require the AspectJ runtime
<tt>aspectjrt</tt>, but the compiler itself needs JDK 11+. Just like in previous AspectJ versions, both the runtime
<tt>aspectjrt</tt> and the load-time weaver <tt>aspectjweaver</tt> still only require JRE 8+.
</p>

<h3>Use LTW on Java 16+</h3>

<p>
Please note that if you want to use load-time weaving on Java 16+, the weaving agent collides with
<a href="https://openjdk.java.net/jeps/396">JEP 396 (Strongly Encapsulate JDK Internals by Default)</a> and related
subsequent JEPs. Therefore, you need to set the JVM parameter <tt>--add-opens java.base/java.lang=ALL-UNNAMED</tt> in
order to enable aspect weaving. This is due to the fact that the weaver uses internal APIs for which we have not found
an adequate replacement yet when defining classes in different classloaders.
</p>

<h3>Compile with Java preview features</h3>

<p>
For features marked as preview on a given JDK, you need to compile with <tt>ajc --enable-preview</tt> and run with
<tt>java --enable-preview</tt> on that JDK.
</p>
<p>
Please note that you cannot run code compiled with preview features on any other JDK than the one used for
compilation. For example, records compiled with preview on JDK 15 cannot be used on JDK 16 without recompilation. This
is a JVM limitation unrelated to AspectJ. Also, e.g. sealed classes are preview-1 on JDK 15 and preview-2 on JDK 16.
You still need to recompile, no matter what.
</p>

<hr>

<p>
<b>Available:</b> 1.9.9 available DD-MMM-2022
</p>

</body>

</html>

+ 1
- 1
org.aspectj.ajdt.core/src/main/resources/org/aspectj/org/eclipse/jdt/internal/compiler/batch/messages_aspectj.properties View File

@@ -1,5 +1,5 @@
compiler.name = AspectJ Compiler
compiler.version = Eclipse Compiler f8768b6899a6a2 (15Sep2021) - Java17
compiler.version = Eclipse Compiler a721c849b3f9d5 (18Mar2022) - Java18
compiler.copyright =

misc.version = {0} {1} - {2} {3}

+ 1
- 1
pom.xml View File

@@ -21,7 +21,7 @@
<maven.javadoc.skip>true</maven.javadoc.skip>

<!-- Dependency versions -->
<jdt.core.version>1.9.9-SNAPSHOT</jdt.core.version>
<jdt.core.version>1.9.9.j18-SNAPSHOT</jdt.core.version>
<asm.version>9.2</asm.version>
<lib.ant.version>1.6.3</lib.ant.version>
<lib.ant.xerces.version>2.6.2</lib.ant.xerces.version>

+ 12
- 3
taskdefs/src/main/java/org/aspectj/tools/ant/taskdefs/AjcTask.java View File

@@ -250,9 +250,18 @@ public class AjcTask extends MatchingTask {

public static final String COMMAND_EDITOR_NAME = AjcTask.class.getName() + ".COMMAND_EDITOR";

static final String[] TARGET_INPUTS = new String[] { "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9", "10", "11", "12", "13", "14", "15", "16", "17" };
static final String[] SOURCE_INPUTS = new String[] { "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9", "10", "11", "12", "13", "14", "15", "16", "17" };
static final String[] COMPLIANCE_INPUTS = new String[] { "-1.3", "-1.4", "-1.5", "-1.6", "-1.7", "-1.8", "-1.9", "-9", "-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17" };
static final String[] TARGET_INPUTS = new String[] {
"1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18"
};
static final String[] SOURCE_INPUTS = new String[] {
"1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "9",
"10", "11", "12", "13", "14", "15", "16", "17", "18"
};
static final String[] COMPLIANCE_INPUTS = new String[] {
"-1.3", "-1.4", "-1.5", "-1.6", "-1.7", "-1.8", "-1.9", "-9",
"-10", "-11", "-12", "-13", "-14", "-15", "-16", "-17", "-18"
};

private static final ICommandEditor COMMAND_EDITOR;


+ 3
- 3
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava17Only.java View File

@@ -20,21 +20,21 @@ public abstract class XMLBasedAjcTestCaseForJava17Only extends XMLBasedAjcTestCa
@Override
public void setUp() throws Exception {
// Activate this block after upgrading to JDT Core Java 18
/*
throw new IllegalStateException(
"These tests need a Java 17 level AspectJ compiler " +
"(e.g. because they use version-specific preview features). " +
"This compiler does not support preview features of a previous version anymore."
);
*/
// Activate this block before upgrading to JDT Core Java 18
/*
if (!LangUtil.is17VMOrGreater() || LangUtil.is18VMOrGreater()) {
throw new IllegalStateException(
"These tests should be run on Java 17 only " +
"(e.g. because they use version-specific preview features)"
);
}
super.setUp();
}
*/
}

}

+ 40
- 0
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18Only.java View File

@@ -0,0 +1,40 @@
/* *******************************************************************
* Copyright (c) 2021 Contributors
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
* ******************************************************************/
package org.aspectj.testing;

import org.aspectj.util.LangUtil;

/**
* Makes sure tests are running on the right level of JDK.
*
* @author Alexander Kriegisch
*/
public abstract class XMLBasedAjcTestCaseForJava18Only extends XMLBasedAjcTestCase {

@Override
public void setUp() throws Exception {
// Activate this block after upgrading to JDT Core Java 19
/*
throw new IllegalStateException(
"These tests need a Java 18 level AspectJ compiler " +
"(e.g. because they use version-specific preview features). " +
"This compiler does not support preview features of a previous version anymore."
);
*/
// Activate this block before upgrading to JDT Core Java 19
if (!LangUtil.is18VMOrGreater() || LangUtil.is19VMOrGreater()) {
throw new IllegalStateException(
"These tests should be run on Java 18 only " +
"(e.g. because they use version-specific preview features)"
);
}
super.setUp();
}

}

+ 27
- 0
testing/src/test/java/org/aspectj/testing/XMLBasedAjcTestCaseForJava18OrLater.java View File

@@ -0,0 +1,27 @@
/* *******************************************************************
* Copyright (c) 2021 Contributors
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
* ******************************************************************/
package org.aspectj.testing;

import org.aspectj.util.LangUtil;

/**
* Makes sure tests are running on the right level of JDK.
*
* @author Alexander Kriegisch
*/
public abstract class XMLBasedAjcTestCaseForJava18OrLater extends XMLBasedAjcTestCase {

@Override
public void setUp() throws Exception {
if (!LangUtil.is18VMOrGreater())
throw new IllegalStateException("These tests should be run on Java 18 or later");
super.setUp();
}

}

tests/bugs198/github_115/A.java → tests/bugs199/github_115/A.java View File


tests/bugs198/github_115/B.java → tests/bugs199/github_115/B.java View File


tests/bugs198/github_120/C.java → tests/bugs199/github_120/C.java View File


tests/bugs198/github_120/D.java → tests/bugs199/github_120/D.java View File


tests/bugs198/github_122/E.java → tests/bugs199/github_122/E.java View File


tests/bugs198/github_125/Application.java → tests/bugs199/github_125/Application.java View File


+ 28
- 0
tests/features199/java18/SwitchPatternPreview2Aspect.aj View File

@@ -0,0 +1,28 @@
import java.util.Locale;

aspect SwitchPatternPreview2Aspect {
Object around(Object o): execution(* doSomethingWithObject(*)) && args(o) {
System.out.println(
switch (o) {
case -1, 1 -> "special case:" + o;
case Integer i && i > 0 -> "positive integer: " + o;
case Integer i -> "other integer: " + o;
default -> "non-integer: " + o;
}
);
return proceed(o);
}
}

class Application {
public static void main(String[] args) {
doSomethingWithObject(-1);
doSomethingWithObject(0);
doSomethingWithObject(42);
doSomethingWithObject(-99);
doSomethingWithObject("test");
doSomethingWithObject(null);
}

public static Object doSomethingWithObject(Object o) { return o; }
}

+ 31
- 0
tests/features199/java18/SwitchPatternPreview2Error.java View File

@@ -0,0 +1,31 @@
/**
* Inspired by examples in https://openjdk.java.net/jeps/420
*/
public class SwitchPatternPreview2Error {
static void constantLabelMustAppearBeforePattern1(Object o) {
switch (o) {
case Integer i && i > 0 -> System.out.println("positive integer: " + o);
case -1, 1 -> System.out.println("special case:" + o);
case Integer i -> System.out.println("other integer: " + o);
default -> System.out.println("non-integer: " + o);
}
}

static void constantLabelMustAppearBeforePattern2(Object o) {
switch (o) {
case -1, 1 -> System.out.println("special case:" + o);
case Integer i -> System.out.println("other integer: " + o);
case Integer i && i > 0 -> System.out.println("positive integer: " + o);
default -> System.out.println("non-integer: " + o);
}
}

static void constantLabelMustAppearBeforePattern3(Object o) {
switch (o) {
case Integer i && i > 0 -> System.out.println("positive integer: " + o);
case Integer i -> System.out.println("other integer: " + o);
case -1, 1 -> System.out.println("special case:" + o);
default -> System.out.println("non-integer: " + o);
}
}
}

+ 38
- 0
tests/features199/java18/SwitchPatternPreview2OK.java View File

@@ -0,0 +1,38 @@
import java.util.List;

/**
* Inspired by examples in https://openjdk.java.net/jeps/420
*/
public class SwitchPatternPreview2OK {
public static void main(String[] args) {
constantLabelMustAppearBeforePattern(-1);
constantLabelMustAppearBeforePattern(0);
constantLabelMustAppearBeforePattern(42);
constantLabelMustAppearBeforePattern(-99);
constantLabelMustAppearBeforePattern(Integer.valueOf(123));
constantLabelMustAppearBeforePattern(null);

System.out.println(testGenericSealedExhaustive(new B<Integer>()));
}

static String constantLabelMustAppearBeforePattern(Object o) {
switch (o) {
case -1, 1 -> System.out.println("special case:" + o);
case Integer i && i > 0 -> System.out.println("positive integer: " + o);
case Integer i -> System.out.println("other integer: " + o);
default -> System.out.println("non-integer: " + o);
}
return o.toString();
}

sealed interface I<T> permits A, B {}
final static class A<X> implements I<String> {}
final static class B<Y> implements I<Y> {}

static int testGenericSealedExhaustive(I<Integer> i) {
return switch (i) {
// Exhaustive as no A case possible!
case B<Integer> bi -> 42;
};
}
}

+ 24
- 30
tests/src/test/java/org/aspectj/systemtest/ajc198/Ajc198TestsJava.java View File

@@ -17,35 +17,29 @@ import org.aspectj.testing.XMLBasedAjcTestCaseForJava17OrLater;
*/
public class Ajc198TestsJava extends XMLBasedAjcTestCaseForJava17OrLater {

public void testSealedClassWithLegalSubclasses() {
runTest("sealed class with legal subclasses");
// TODO: replace 0 by Constants.PREVIEW_MINOR_VERSION after no longer using EA
// build, but final JDK version
checkVersion("Employee", Constants.MAJOR_17, 0 /* Constants.PREVIEW_MINOR_VERSION */);
checkVersion("Manager", Constants.MAJOR_17, 0 /* Constants.PREVIEW_MINOR_VERSION */);
}

public void testSealedClassWithIllegalSubclass() {
runTest("sealed class with illegal subclass");
// TODO: replace 0 by Constants.PREVIEW_MINOR_VERSION after no longer using EA
// build, but final JDK version
checkVersion("Person", Constants.MAJOR_17, 0 /* Constants.PREVIEW_MINOR_VERSION */);
}

public void testWeaveSealedClass() {
runTest("weave sealed class");
// TODO: replace 0 by Constants.PREVIEW_MINOR_VERSION after no longer using EA
// build, but final JDK version
checkVersion("PersonAspect", Constants.MAJOR_17, 0 /* Constants.PREVIEW_MINOR_VERSION */);
}

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Ajc198TestsJava.class);
}

@Override
protected java.net.URL getSpecFile() {
return getClassResource("ajc198.xml");
}
public void testSealedClassWithLegalSubclasses() {
runTest("sealed class with legal subclasses");
checkVersion("Employee", Constants.MAJOR_17, Constants.MINOR_17);
checkVersion("Manager", Constants.MAJOR_17, Constants.MINOR_17);
}

public void testSealedClassWithIllegalSubclass() {
runTest("sealed class with illegal subclass");
checkVersion("Person", Constants.MAJOR_17, Constants.MINOR_17);
}

public void testWeaveSealedClass() {
runTest("weave sealed class");
checkVersion("PersonAspect", Constants.MAJOR_17, Constants.MINOR_17);
}

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Ajc198TestsJava.class);
}

@Override
protected java.net.URL getSpecFile() {
return getClassResource("ajc198.xml");
}

}

+ 3
- 0
tests/src/test/java/org/aspectj/systemtest/ajc198/AllTestsAspectJ198.java View File

@@ -29,9 +29,12 @@ public class AllTestsAspectJ198 {
suite.addTest(SanityTestsJava17.suite());
suite.addTest(Ajc198TestsJava.suite());
}
// Do not run tests using a previous compiler's preview features anymore. They would all fail.
/*
if (LangUtil.is17VMOrGreater() && !LangUtil.is18VMOrGreater()) {
suite.addTest(Java17PreviewFeaturesTests.suite());
}
*/
return suite;
}
}

+ 0
- 27
tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java View File

@@ -21,33 +21,6 @@ public class Bugs198Tests extends XMLBasedAjcTestCase {
runTest("ITD annotation with mandatory parameter via aspectpath");
}

public void testAnnotationStyleSpecialIfClauses() {
runTest("annotation style A");
}

public void testAnnotationStylePointcutInheritanceWithIfClauses() {
runTest("annotation style B");
}

public void testAnnotationStyleSpecialIfClauses2_gh120() {
runTest("annotation style C");
}

public void testAnnotationStyleSpecialIfClauses3_gh120() {
runTest("annotation style D");
}

public void testAnnotationStyleNegatedIf_gh122() {
runTest("annotation style negated if");
}

public void testGitHub_125() {
try (PropertyEnvironment env = ScopedSystemProperties.newPropertyEnvironment()) {
env.setProperty("org.aspectj.weaver.openarchives", "20");
runTest("compiler can re-open closed JARs");
}
}

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Bugs198Tests.class);
}

+ 32
- 0
tests/src/test/java/org/aspectj/systemtest/ajc199/Ajc199TestsJava.java View File

@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*******************************************************************************/
package org.aspectj.systemtest.ajc199;

import junit.framework.Test;
import org.aspectj.testing.XMLBasedAjcTestCase;
import org.aspectj.testing.XMLBasedAjcTestCaseForJava18OrLater;

/**
* @author Alexander Kriegisch
*/
public class Ajc199TestsJava extends XMLBasedAjcTestCaseForJava18OrLater {

public void testDummyJava18() {
runTest("dummy Java 18");
}

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Ajc199TestsJava.class);
}

@Override
protected java.net.URL getSpecFile() {
return getClassResource("ajc199.xml");
}

}

+ 31
- 0
tests/src/test/java/org/aspectj/systemtest/ajc199/AllTestsAspectJ199.java View File

@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*******************************************************************************/
package org.aspectj.systemtest.ajc199;

import junit.framework.Test;
import junit.framework.TestSuite;
import org.aspectj.util.LangUtil;

/**
* @author Alexander Kriegisch
*/
public class AllTestsAspectJ199 {

public static Test suite() {
TestSuite suite = new TestSuite("AspectJ 1.9.9 tests");
suite.addTest(Bugs199Tests.suite());
if (LangUtil.is18VMOrGreater()) {
suite.addTest(SanityTestsJava18.suite());
suite.addTest(Ajc199TestsJava.suite());
}
if (LangUtil.is18VMOrGreater() && !LangUtil.is19VMOrGreater()) {
suite.addTest(Java18PreviewFeaturesTests.suite());
}
return suite;
}
}

+ 56
- 0
tests/src/test/java/org/aspectj/systemtest/ajc199/Bugs199Tests.java View File

@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*******************************************************************************/
package org.aspectj.systemtest.ajc199;

import io.bmuskalla.system.properties.PropertyEnvironment;
import io.bmuskalla.system.properties.ScopedSystemProperties;
import junit.framework.Test;
import org.aspectj.testing.XMLBasedAjcTestCase;

/**
* @author Alexander Kriegisch
*/
public class Bugs199Tests extends XMLBasedAjcTestCase {

public void testAnnotationStyleSpecialIfClauses() {
runTest("annotation style A");
}

public void testAnnotationStylePointcutInheritanceWithIfClauses() {
runTest("annotation style B");
}

public void testAnnotationStyleSpecialIfClauses2_gh120() {
runTest("annotation style C");
}

public void testAnnotationStyleSpecialIfClauses3_gh120() {
runTest("annotation style D");
}

public void testAnnotationStyleNegatedIf_gh122() {
runTest("annotation style negated if");
}

public void testGitHub_125() {
try (PropertyEnvironment env = ScopedSystemProperties.newPropertyEnvironment()) {
env.setProperty("org.aspectj.weaver.openarchives", "20");
runTest("compiler can re-open closed JARs");
}
}

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Bugs199Tests.class);
}

@Override
protected java.net.URL getSpecFile() {
return getClassResource("ajc199.xml");
}

}

+ 69
- 0
tests/src/test/java/org/aspectj/systemtest/ajc199/Java18PreviewFeaturesTests.java View File

@@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*******************************************************************************/
package org.aspectj.systemtest.ajc199;

import junit.framework.Test;
import org.aspectj.apache.bcel.Constants;
import org.aspectj.testing.XMLBasedAjcTestCase;
import org.aspectj.testing.XMLBasedAjcTestCaseForJava18Only;

/**
* @author Alexander Kriegisch
*/
public class Java18PreviewFeaturesTests extends XMLBasedAjcTestCaseForJava18Only {

public void testSwitchPatternMatchingCaseLabelDominatedByPrecedingError() {
runTest("switch pattern matching error");
}

public void testSwitchPatternMatchingJava() {
runTest("switch pattern matching java");
checkVersion("SwitchPatternOK", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
}

public void testSwitchPatternMatchingAspect() {
runTest("switch pattern matching aspect");
checkVersion("SwitchPatternAspect", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
checkVersion("Application", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
checkVersion("Shape", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
checkVersion("S", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
}

// TODO:
// JDT Core does not seem to have implemented JEP 420 yet,
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=576746.
// Therefore, deactivate the special tests for now.
/*
public void testSwitchPatternMatchingPreview2Error() {
runTest("switch pattern matching preview 2 error");
}

public void testSwitchPatternMatchingPreview2Java() {
runTest("switch pattern matching preview 2 java");
checkVersion("SwitchPatternOK", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
}

public void testSwitchPatternMatchingPreview2Aspect() {
runTest("switch pattern matching preview 2 aspect");
checkVersion("SwitchPatternAspect", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
checkVersion("Application", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
checkVersion("Shape", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
checkVersion("S", Constants.MAJOR_18, Constants.PREVIEW_MINOR_VERSION);
}
*/

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Java18PreviewFeaturesTests.class);
}

@Override
protected java.net.URL getSpecFile() {
return getClassResource("ajc199.xml");
}

}

+ 87
- 0
tests/src/test/java/org/aspectj/systemtest/ajc199/SanityTestsJava18.java View File

@@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2021 Contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
*******************************************************************************/
package org.aspectj.systemtest.ajc199;

import junit.framework.Test;
import org.aspectj.testing.XMLBasedAjcTestCase;
import org.aspectj.testing.XMLBasedAjcTestCaseForJava18OrLater;

/*
* Some very trivial tests that help verify things are OK.
* These are a copy of the earlier Sanity Tests created for 1.6 but these supply the -17 option
* to check code generation and modification with that version specified.
*
* @author Alexander Kriegisch
*/
public class SanityTestsJava18 extends XMLBasedAjcTestCaseForJava18OrLater {

public static final int bytecode_version_for_JDK_level = 62;

// Incredibly trivial test programs that check the compiler works at all (these are easy-ish to debug)
public void testSimpleJava_A() {
runTest("simple - a");
}

public void testSimpleJava_B() {
runTest("simple - b");
}

public void testSimpleCode_C() {
runTest("simple - c");
}

public void testSimpleCode_D() {
runTest("simple - d");
}

public void testSimpleCode_E() {
runTest("simple - e");
}

public void testSimpleCode_F() {
runTest("simple - f");
}

public void testSimpleCode_G() {
runTest("simple - g");
}

public void testSimpleCode_H() {
runTest("simple - h", true);
}

public void testSimpleCode_I() {
runTest("simple - i");
}

public void testVersionCorrect1() {
runTest("simple - j");
checkVersion("A", bytecode_version_for_JDK_level, 0);
}

public void testVersionCorrect2() {
runTest("simple - k");
checkVersion("A", bytecode_version_for_JDK_level, 0);
}

public void testVersionCorrect4() {
runTest("simple - m");
// Must be 49.0 when -1.5 is specified
checkVersion("A", 49, 0);
}

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(SanityTestsJava18.class);
}

@Override
protected java.net.URL getSpecFile() {
return getClassResource("sanity-tests-18.xml");
}

}

+ 1
- 68
tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml View File

@@ -95,76 +95,9 @@
</run>
</ajc-test>

<!-- Javac/ECJ 9+ compiler option, but belated implementation in AJC 1.9.7 -->
<!-- Javac/ECJ 9+ compiler option, but belated implementation in AJC 1.9.8 -->
<ajc-test dir="features198/compiler_release" vm="9" title="compile to older JDK release">
<compile files="Buffers.java" options="--release 8"/>
</ajc-test>

<ajc-test dir="bugs198/github_115" title="annotation style A">
<compile files="A.java" options="-1.5">
<message kind="warning" line="28" text="advice defined in Azpect has not been applied [Xlint:adviceDidNotMatch]"/>
</compile>
<run class="A">
<stdout>
<line text="Azpect.before"/>
<line text="A.main"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs198/github_115" title="annotation style B">
<compile files="B.java" options="-1.5"/>
<run class="B">
<stdout>
<line text="Azpect.before"/>
<line text="B.main"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs198/github_120" title="annotation style C">
<compile files="C.java" options="-1.5"/>
<run class="C">
<stdout>
<line text="check if() pointcut running on C(1)"/>
<line text="Azpect1.beforeAdvice executing"/>
<line text="C.run() executing"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs198/github_120" title="annotation style D">
<compile files="D.java" options="-1.5"/>
<run class="D">
<stdout>
<line text="advice running"/>
<line text="D.run() executing"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs198/github_122" title="annotation style negated if">
<compile files="E.java" options="-1.5"/>
<run class="E">
<stdout>
<line text="advice running"/>
<line text="E.run() executing"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs198/github_125" title="compiler can re-open closed JARs">
<!--
Here the Java test sets system property org.aspectj.weaver.openarchives to 20 in order to provoke
open JAR limit exhaustion
-->
<compile files="Application.java" options="-1.5" />
<run class="Application">
<stdout>
<line text="Before advice"/>
<line text="Hello world!"/>
</stdout>
</run>
</ajc-test>

</suite>

+ 177
- 0
tests/src/test/resources/org/aspectj/systemtest/ajc199/ajc199.xml View File

@@ -0,0 +1,177 @@
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>


<suite>

<!-- Java 18 final: no new features, only 2nd preview for "JEP 420: Pattern Matching for switch (Second Preview)" -->
<ajc-test dir="features199/java18" vm="18" title="dummy Java 18">
</ajc-test>

<!-- Java ?? final, Java 17, 18 preview -->
<ajc-test dir="features198/java17" vm="18" title="switch pattern matching error">
<compile files="SwitchPatternError.java" options="--enable-preview -18">
<!-- TODO: Add correct compiler error message, as soon as JDT Core supports it -->
<message kind="error" file="SwitchPatternError.java" text="This case label is dominated by one of the preceding case label"/>
</compile>
</ajc-test>

<!-- Java ?? final, Java 17, 18 preview -->
<ajc-test dir="features198/java17" vm="18" title="switch pattern matching java">
<compile files="SwitchPatternOK.java" options="--enable-preview -18" />
<run class="SwitchPatternOK" vmargs="--enable-preview">
<stdout>
<line text="null" />
<line text="int 123" />
<line text="long 999" />
<line text="double 12.340000" />
<line text="String foo" />
<line text="[123, foo, 999, 12.34]" />
<line text="Non-circle" />
<line text="Small circle" />
<line text="Large circle" />
<line text="Sealed sub-class A" />
<line text="Sealed sub-class B" />
<line text="Sealed sub-record C" />
</stdout>
</run>
</ajc-test>

<!-- Java ?? final, Java 17, 18 preview -->
<ajc-test dir="features198/java17" vm="18" title="switch pattern matching aspect">
<compile files="SwitchPatternAspect.aj" options="--enable-preview -18" />
<run class="Application" vmargs="--enable-preview">
<stdout>
<line text="null" />
<line text="int 123" />
<line text="long 999" />
<line text="double 12.340000" />
<line text="String foo" />
<line text="[123, foo, 999, 12.34]" />
<line text="Non-circle" />
<line text="Small circle" />
<line text="Large circle" />
<line text="Sealed sub-class A" />
<line text="Sealed sub-class B" />
<line text="Sealed sub-record C" />
</stdout>
</run>
</ajc-test>

<!-- Java ?? final, Java 17, 18 preview -->
<ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 error">
<compile files="SwitchPatternPreview2Error.java" options="--enable-preview -18">
<!-- TODO: Add correct compiler error message, as soon as JDT Core supports it -->
<message kind="error" file="SwitchPatternError.java" text="This case label is dominated by one of the preceding case label"/>
</compile>
</ajc-test>

<!-- Java ?? final, Java 17, 18 preview -->
<ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 java">
<compile files="SwitchPatternPreview2OK.java" options="--enable-preview -18" />
<run class="SwitchPatternOK" vmargs="--enable-preview">
<stdout>
<line text="null" />
<line text="int 123" />
<line text="long 999" />
<line text="double 12.340000" />
<line text="String foo" />
<line text="[123, foo, 999, 12.34]" />
<line text="Non-circle" />
<line text="Small circle" />
<line text="Large circle" />
<line text="Sealed sub-class A" />
<line text="Sealed sub-class B" />
<line text="Sealed sub-record C" />
</stdout>
</run>
</ajc-test>

<!-- Java ?? final, Java 17, 18 preview -->
<ajc-test dir="features199/java18" vm="18" title="switch pattern matching preview 2 aspect">
<compile files="SwitchPatternPreview2Aspect.aj" options="--enable-preview -18" />
<run class="Application" vmargs="--enable-preview">
<stdout>
<line text="null" />
<line text="int 123" />
<line text="long 999" />
<line text="double 12.340000" />
<line text="String foo" />
<line text="[123, foo, 999, 12.34]" />
<line text="Non-circle" />
<line text="Small circle" />
<line text="Large circle" />
<line text="Sealed sub-class A" />
<line text="Sealed sub-class B" />
<line text="Sealed sub-record C" />
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs199/github_115" title="annotation style A">
<compile files="A.java" options="-1.5">
<message kind="warning" line="28" text="advice defined in Azpect has not been applied [Xlint:adviceDidNotMatch]"/>
</compile>
<run class="A">
<stdout>
<line text="Azpect.before"/>
<line text="A.main"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs199/github_115" title="annotation style B">
<compile files="B.java" options="-1.5"/>
<run class="B">
<stdout>
<line text="Azpect.before"/>
<line text="B.main"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs199/github_120" title="annotation style C">
<compile files="C.java" options="-1.5"/>
<run class="C">
<stdout>
<line text="check if() pointcut running on C(1)"/>
<line text="Azpect1.beforeAdvice executing"/>
<line text="C.run() executing"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs199/github_120" title="annotation style D">
<compile files="D.java" options="-1.5"/>
<run class="D">
<stdout>
<line text="advice running"/>
<line text="D.run() executing"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs199/github_122" title="annotation style negated if">
<compile files="E.java" options="-1.5"/>
<run class="E">
<stdout>
<line text="advice running"/>
<line text="E.run() executing"/>
</stdout>
</run>
</ajc-test>

<ajc-test dir="bugs199/github_125" title="compiler can re-open closed JARs">
<!--
Here the Java test sets system property org.aspectj.weaver.openarchives to 20 in order to provoke
open JAR limit exhaustion
-->
<compile files="Application.java" options="-1.5" />
<run class="Application">
<stdout>
<line text="Before advice"/>
<line text="Hello world!"/>
</stdout>
</run>
</ajc-test>

</suite>

+ 70
- 0
tests/src/test/resources/org/aspectj/systemtest/ajc199/sanity-tests-18.xml View File

@@ -0,0 +1,70 @@
<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>

<suite>

<!-- empty class -->
<ajc-test dir="bugs160/simplejava" title="simple - a">
<compile files="SimpleA.java" options="-18"/>
</ajc-test>

<!-- class with one method -->
<ajc-test dir="bugs160/simplejava" title="simple - b">
<compile files="SimpleB.java" options="-18"/>
<run class="SimpleB"/>
</ajc-test>

<!-- empty aspect -->
<ajc-test dir="bugs160/simplejava" title="simple - c">
<compile files="SimpleC.java" options="-18"/>
</ajc-test>

<!-- simple before -->
<ajc-test dir="bugs160/simplejava" title="simple - d">
<compile files="SimpleD.java" options="-18"/>
</ajc-test>

<!-- simple itd field -->
<ajc-test dir="bugs160/simplejava" title="simple - e">
<compile files="SimpleE.java" options="-18"/>
</ajc-test>

<!-- aspect with main calling a static method -->
<ajc-test dir="bugs160/simplejava" title="simple - f">
<compile files="SimpleF.java" options="-18"/>
</ajc-test>

<!-- pertarget -->
<ajc-test dir="bugs160/simplejava" title="simple - g">
<compile files="SimpleG.java" options="-18"/>
</ajc-test>

<!-- generic ctor itds -->
<ajc-test dir="bugs160/simplejava" title="simple - h">
<compile files="SimpleH.java" options="-18"/>
</ajc-test>

<!-- overriding generic itd methods -->
<ajc-test dir="bugs160/simplejava" title="simple - i">
<compile files="SimpleI.java" options="-18"/>
</ajc-test>

<!-- check class file version is 62.0 (Java 18) -->
<ajc-test dir="bugs160/simplejava" title="simple - j">
<compile files="SimpleJ.java" options="-18"/>
</ajc-test>

<!-- check class file version is 62.0 (Java 18) -->
<ajc-test dir="bugs160/simplejava" title="simple - k">
<compile files="SimpleJ.java" options="-source 18"/>
</ajc-test>

<!-- check class file version is 49.0 -->
<ajc-test dir="bugs160/simplejava" title="simple - m">
<compile files="SimpleJ.java" options="-1.5"/>
</ajc-test>

<ajc-test dir="bugs160/simplejava" title="simple - n">
<compile files="SimpleN.java" options="-18"/>
</ajc-test>

</suite>

+ 4
- 0
util/src/main/java/org/aspectj/util/LangUtil.java View File

@@ -194,6 +194,10 @@ public class LangUtil {
return 18 <= vmVersion;
}

public static boolean is19VMOrGreater() {
return 19 <= vmVersion;
}

/**
* Shorthand for "if null, throw IllegalArgumentException"
*

Loading…
Cancel
Save