diff options
author | Andy Clement <aclement@pivotal.io> | 2019-01-21 10:20:04 -0800 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-01-21 10:20:04 -0800 |
commit | 8755f774ae286eefbe3826dab592f1a22d0f6b95 (patch) | |
tree | cdfbe8acbd5530538d0d933230f4db7f09516e92 /tests | |
parent | f6d0013eb2cddf9946ab07d0a4e129cc9c0869bb (diff) | |
download | aspectj-8755f774ae286eefbe3826dab592f1a22d0f6b95.tar.gz aspectj-8755f774ae286eefbe3826dab592f1a22d0f6b95.zip |
389678: Better support for overweaving
More testcases for overweaving and better handling of WeaverStateInfo
to avoid the dreaded problems deserialized the 'special key' used
to store diffs.
With these changes once a class is woven via overweaving we switch
the diff we store in the weaverstateinfo to 0 byte array (indicating
overweaving happened for later weavers that see it). We also stop
writing the special 'key' into the attribute and avoid looking-for
and attempting to replace it at the end of weaving.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc193/Ajc193Tests.java | 68 | ||||
-rw-r--r-- | tests/src/org/aspectj/systemtest/ajc193/ajc193.xml | 118 |
2 files changed, 185 insertions, 1 deletions
diff --git a/tests/src/org/aspectj/systemtest/ajc193/Ajc193Tests.java b/tests/src/org/aspectj/systemtest/ajc193/Ajc193Tests.java index 255d7d871..801dd12f6 100644 --- a/tests/src/org/aspectj/systemtest/ajc193/Ajc193Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc193/Ajc193Tests.java @@ -9,8 +9,10 @@ package org.aspectj.systemtest.ajc193; import java.io.File; +import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.testing.XMLBasedAjcTestCase; import org.aspectj.testing.XMLBasedAjcTestCaseForJava10OrLater; +import org.aspectj.weaver.WeaverStateInfo; import junit.framework.Test; @@ -19,8 +21,72 @@ import junit.framework.Test; */ public class Ajc193Tests extends XMLBasedAjcTestCaseForJava10OrLater { + public void testComplexOverweaving1() { + // This is the same code as the other test but overweaving OFF + runTest("overweaving"); + } + + public void testComplexOverweaving2() throws Exception { + // This is the same code as the other test but overweaving ON + runTest("overweaving 2"); + // Asserting the weaver state info in the tests that will drive overweaving behaviour: + + // After step 1 of the test, MyAspect will have been applied. + JavaClass jc = getClassFrom(new File(ajc.getSandboxDirectory(),"ow1.jar"), "Application"); + WeaverStateInfo wsi = getWeaverStateInfo(jc); + assertEquals("[LMyAspect;]", wsi.getAspectsAffectingType().toString()); + assertTrue(wsi.getUnwovenClassFileData().length>0); + + // After overweaving, MyAspect2 should also be getting applied but the unwovenclassfile + // data has been blanked out - because we can no longer use it, only overweaving is possible + // once one overweaving step is done + jc = getClassFrom(ajc.getSandboxDirectory(), "Application"); + wsi = getWeaverStateInfo(jc); + assertEquals("[LMyAspect2;, LMyAspect;]", wsi.getAspectsAffectingType().toString()); + assertEquals(0,wsi.getUnwovenClassFileData().length); + } + + // Two steps of overweaving + public void testComplexOverweaving3() throws Exception { + // This is the same code as the other test but overweaving ON + runTest("overweaving 3"); + // Asserting the weaver state info in the tests that will drive overweaving behaviour: + + // After step 1 of the test, MyAspect will have been applied. + JavaClass jc = getClassFrom(new File(ajc.getSandboxDirectory(),"ow1.jar"), "Application"); + WeaverStateInfo wsi = getWeaverStateInfo(jc); + assertEquals("[LMyAspect;]", wsi.getAspectsAffectingType().toString()); + assertTrue(wsi.getUnwovenClassFileData().length>0); + + // After overweaving, MyAspect2 should also be getting applied but the unwovenclassfile + // data has been blanked out - because we can no longer use it, only overweaving is possible + // once one overweaving step is done + jc = getClassFrom(new File(ajc.getSandboxDirectory(),"ow3.jar"), "Application"); + wsi = getWeaverStateInfo(jc); + assertEquals("[LMyAspect2;, LMyAspect;]", wsi.getAspectsAffectingType().toString()); + assertEquals(0,wsi.getUnwovenClassFileData().length); + + jc = getClassFrom(ajc.getSandboxDirectory(), "Application"); + wsi = getWeaverStateInfo(jc); + assertEquals("[LMyAspect3;, LMyAspect2;, LMyAspect;]", wsi.getAspectsAffectingType().toString()); + assertEquals(0,wsi.getUnwovenClassFileData().length); + } + + // overweaving then attempt non overweaving - should fail + public void testComplexOverweaving4() throws Exception { + // This is the same code as the other test but overweaving ON + runTest("overweaving 4"); + // Asserting the weaver state info in the tests that will drive overweaving behaviour: + + // After step 1 of the test, MyAspect will have been applied. + JavaClass jc = getClassFrom(new File(ajc.getSandboxDirectory(),"ow1.jar"), "Application"); + WeaverStateInfo wsi = getWeaverStateInfo(jc); + assertEquals("[LMyAspect;]", wsi.getAspectsAffectingType().toString()); + assertTrue(wsi.getUnwovenClassFileData().length>0); + } + // Altered version of this test from org.aspectj.systemtest.ajc150.Enums for 542682 - public void decpOnEnumNotAllowed_xlints() { + public void testDecpOnEnumNotAllowed_xlints() { runTest("wildcard enum match in itd"); } diff --git a/tests/src/org/aspectj/systemtest/ajc193/ajc193.xml b/tests/src/org/aspectj/systemtest/ajc193/ajc193.xml index d5ed0f1c1..f391c50d7 100644 --- a/tests/src/org/aspectj/systemtest/ajc193/ajc193.xml +++ b/tests/src/org/aspectj/systemtest/ajc193/ajc193.xml @@ -2,6 +2,124 @@ <suite> + <ajc-test dir="bugs193/389678" vm="1.8" title="overweaving"> + <compile files="OverWeave_1/src/Application.java,OverWeave_1/src/MyAspect.aj" options="-showWeaveInfo -1.8" outjar="ow1.jar"> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect' (MyAspect.aj:2)"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect' (MyAspect.aj:2)"/> + </compile> + <compile files="OverWeave_2/src/MyAspect2.aj" options="-1.8" outjar="ow2.jar"> + <message kind="warning" text="advice defined in MyAspect2 has not been applied"/> + </compile> + <compile inpath="ow1.jar" aspectpath="ow2.jar" options="-1.8 -showWeaveInfo"> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect2' (ow2.jar!MyAspect2.class:2(from MyAspect2.aj))"/> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect' (ow1.jar!MyAspect.class:2(from MyAspect.aj))"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect2' (ow2.jar!MyAspect2.class:2(from MyAspect2.aj))"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect' (ow1.jar!MyAspect.class:2(from MyAspect.aj))"/> + </compile> + <run class="Application" classpath="ow2.jar"> + <stdout> + <line text="MyAspect -> execution(void Application.main(String[]))"/> + <line text="MyAspect2 -> execution(void Application.main(String[]))"/> + <line text="MyAspect -> execution(void Application.sayHelloTo(String))"/> + <line text="MyAspect2 -> execution(void Application.sayHelloTo(String))"/> + <line text="Hello world!"/> + </stdout> + </run> + </ajc-test> + + <ajc-test dir="bugs193/389678" vm="1.8" title="overweaving 2"> + <compile files="OverWeave_1/src/Application.java,OverWeave_1/src/MyAspect.aj" options="-showWeaveInfo -1.8" outjar="ow1.jar"> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect' (MyAspect.aj:2)"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect' (MyAspect.aj:2)"/> + </compile> + <compile files="OverWeave_2/src/MyAspect2.aj" options="-1.8" outjar="ow2.jar"> + <message kind="warning" text="advice defined in MyAspect2 has not been applied"/> + </compile> + <compile inpath="ow1.jar" aspectpath="ow2.jar" options="-showWeaveInfo -1.8 -Xset:overWeaving=true"> + <!-- this is a bit unfortunate, basically MyAspect is not being re-applied because of overweaving + so we get a message that it hasn't been applied. But really it doesn't need to be. --> + <message kind="warning" text="advice defined in MyAspect has not been applied"/> +<!-- These two don't come out because we are using overweaving to apply MyAspect2 where MyAspect is already applied. + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect' (ow1.jar!MyAspect.class:2(from MyAspect.aj))"/> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect' (ow1.jar!MyAspect.class:2(from MyAspect.aj))"/> +--> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect2' (ow2.jar!MyAspect2.class:2(from MyAspect2.aj))"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect2' (ow2.jar!MyAspect2.class:2(from MyAspect2.aj))"/> + </compile> + <run class="Application" classpath="ow2.jar"> + <stdout> + <!-- notice order change to overweaving usage --> + <line text="MyAspect2 -> execution(void Application.main(String[]))"/> + <line text="MyAspect -> execution(void Application.main(String[]))"/> + <line text="MyAspect2 -> execution(void Application.sayHelloTo(String))"/> + <line text="MyAspect -> execution(void Application.sayHelloTo(String))"/> + <line text="Hello world!"/> + </stdout> + </run> + </ajc-test> + + <ajc-test dir="bugs193/389678" vm="1.8" title="overweaving 3"> + <compile files="OverWeave_1/src/Application.java,OverWeave_1/src/MyAspect.aj" options="-showWeaveInfo -1.8" outjar="ow1.jar"> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect' (MyAspect.aj:2)"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect' (MyAspect.aj:2)"/> + </compile> + <compile files="OverWeave_2/src/MyAspect2.aj" options="-1.8" outjar="ow2.jar"> + <message kind="warning" text="advice defined in MyAspect2 has not been applied"/> + </compile> + <compile files="OverWeave_4/src/MyAspect3.aj" options="-1.8" outjar="ow4.jar"> + <message kind="warning" text="advice defined in MyAspect3 has not been applied"/> + </compile> + <compile inpath="ow1.jar" aspectpath="ow2.jar" options="-showWeaveInfo -1.8 -Xset:overWeaving=true" outjar="ow3.jar"> + <!-- this is a bit unfortunate, basically MyAspect is not being re-applied because of overweaving + so we get a message that it hasn't been applied. But really it doesn't need to be. --> + <message kind="warning" text="advice defined in MyAspect has not been applied"/> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect2' (ow2.jar!MyAspect2.class:2(from MyAspect2.aj))"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect2' (ow2.jar!MyAspect2.class:2(from MyAspect2.aj))"/> + </compile> + <compile inpath="ow3.jar" aspectpath="ow4.jar" options="-showWeaveInfo -1.8 -Xset:overWeaving=true"> + <!-- this is a bit unfortunate, basically MyAspect is not being re-applied because of overweaving + so we get a message that it hasn't been applied. But really it doesn't need to be. --> + <message kind="warning" text="advice defined in MyAspect has not been applied"/> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect3' (ow4.jar!MyAspect3.class:2(from MyAspect3.aj))"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect3' (ow4.jar!MyAspect3.class:2(from MyAspect3.aj))"/> + </compile> + <run class="Application" classpath="ow2.jar"> + <stdout> + <line text="MyAspect3 -> execution(void Application.main(String[]))"/> + <line text="MyAspect2 -> execution(void Application.main(String[]))"/> + <line text="MyAspect -> execution(void Application.main(String[]))"/> + <line text="MyAspect3 -> execution(void Application.sayHelloTo(String))"/> + <line text="MyAspect2 -> execution(void Application.sayHelloTo(String))"/> + <line text="MyAspect -> execution(void Application.sayHelloTo(String))"/> + <line text="Hello world!"/> + </stdout> + </run> + </ajc-test> + + <ajc-test dir="bugs193/389678" vm="1.8" title="overweaving 4"> + <compile files="OverWeave_1/src/Application.java,OverWeave_1/src/MyAspect.aj" options="-showWeaveInfo -1.8" outjar="ow1.jar"> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect' (MyAspect.aj:2)"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect' (MyAspect.aj:2)"/> + </compile> + <compile files="OverWeave_2/src/MyAspect2.aj" options="-1.8" outjar="ow2.jar"> + <message kind="warning" text="advice defined in MyAspect2 has not been applied"/> + </compile> + <compile files="OverWeave_4/src/MyAspect3.aj" options="-1.8" outjar="ow4.jar"> + <message kind="warning" text="advice defined in MyAspect3 has not been applied"/> + </compile> + <compile inpath="ow1.jar" aspectpath="ow2.jar" options="-showWeaveInfo -1.8 -Xset:overWeaving=true" outjar="ow3.jar"> + <!-- this is a bit unfortunate, basically MyAspect is not being re-applied because of overweaving + so we get a message that it hasn't been applied. But really it doesn't need to be. --> + <message kind="warning" text="advice defined in MyAspect has not been applied"/> + <message kind="weave" text="Join point 'method-execution(void Application.main(java.lang.String[]))' in Type 'Application' (Application.java:2) advised by before advice from 'MyAspect2' (ow2.jar!MyAspect2.class:2(from MyAspect2.aj))"/> + <message kind="weave" text="Join point 'method-execution(void Application.sayHelloTo(java.lang.String))' in Type 'Application' (Application.java:6) advised by before advice from 'MyAspect2' (ow2.jar!MyAspect2.class:2(from MyAspect2.aj))"/> + </compile> + <compile inpath="ow3.jar" aspectpath="ow4.jar:ow2.jar" options="-1.8"> + <message kind="error" text="the type Application was previously subject to overweaving and after that can only be woven again in overweaving mode"/> + <message kind="error" text="the type MyAspect was previously subject to overweaving and after that can only be woven again in overweaving mode"/> + </compile> + </ajc-test> + <ajc-test dir="bugs193/542682" vm="1.5" title="wildcard enum match in itd"> <compile files="SimpleEnum.java,SimpleEnum2.java,EnumAspect04.aj" options="-1.5"> <message kind="warning" line="8" text="enum type SimpleEnum2 matches a declare parents type pattern but is being ignored"/> |