diff options
author | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-14 23:00:48 +0200 |
---|---|---|
committer | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-14 23:00:48 +0200 |
commit | 17c4c44c4cd0051b2a0884cd70bdbd9ac3d15b0f (patch) | |
tree | 897e1ed0d6314c4769dcadd1f2fed4e4a54d0377 | |
parent | 05f797adde987f614684cb70999be99c549d6826 (diff) | |
parent | dbbbac8dbd25a19c56568623b823eba4e6e2906a (diff) | |
download | aspectj-17c4c44c4cd0051b2a0884cd70bdbd9ac3d15b0f.tar.gz aspectj-17c4c44c4cd0051b2a0884cd70bdbd9ac3d15b0f.zip |
Merge branch 'master' of github.com:eclipse/org.aspectj into remove-old-version-checks
22 files changed, 371 insertions, 398 deletions
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ebfdd0a30..ab26f1db3 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -14,13 +14,16 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - java: [ 1.8, 11 ] + java: [ 8, 9, 10, 11, 12, 13, 14 ] steps: - uses: actions/checkout@v2 - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@v1 with: java-version: ${{ matrix.java }} + - run: java -version + - run: mvn --version - name: Build with Maven - run: mvn -B package --file pom.xml + run: mvn -Dorg.aspectj.tools.ajc.Ajc.verbose=false -B package --file pom.xml diff --git a/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java b/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java index 6547d101c..49948db46 100644 --- a/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java +++ b/ajde.core/src/main/java/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java @@ -1,11 +1,11 @@ /******************************************************************** - * Copyright (c) 2007 Contributors. All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://eclipse.org/legal/epl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation * Helen Hawkins - initial version (bug 148190) *******************************************************************/ package org.aspectj.ajde.core.internal; @@ -13,7 +13,6 @@ package org.aspectj.ajde.core.internal; import java.io.File; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -70,7 +69,7 @@ public class AjdeCoreBuildManager { /** * Execute a full or incremental build - * + * * @param fullBuild true if requesting a full build, false if requesting to try an incremental build */ public void performBuild(boolean fullBuild) { @@ -160,12 +159,12 @@ public class AjdeCoreBuildManager { private String getFormattedOptionsString() { ICompilerConfiguration compilerConfig = compiler.getCompilerConfiguration(); return "Building with settings: " + "\n-> output paths: " - + formatCollection(compilerConfig.getOutputLocationManager().getAllOutputLocations()) + "\n-> classpath: " - + compilerConfig.getClasspath() + "\n-> -inpath " + formatCollection(compilerConfig.getInpath()) + "\n-> -outjar " - + formatOptionalString(compilerConfig.getOutJar()) + "\n-> -aspectpath " - + formatCollection(compilerConfig.getAspectPath()) + "\n-> -sourcePathResources " - + formatMap(compilerConfig.getSourcePathResources()) + "\n-> non-standard options: " - + compilerConfig.getNonStandardOptions() + "\n-> javaoptions:" + formatMap(compilerConfig.getJavaOptionsMap()); + + formatCollection(compilerConfig.getOutputLocationManager().getAllOutputLocations()) + "\n-> classpath: " + + compilerConfig.getClasspath() + "\n-> -inpath " + formatCollection(compilerConfig.getInpath()) + "\n-> -outjar " + + formatOptionalString(compilerConfig.getOutJar()) + "\n-> -aspectpath " + + formatCollection(compilerConfig.getAspectPath()) + "\n-> -sourcePathResources " + + formatMap(compilerConfig.getSourcePathResources()) + "\n-> non-standard options: " + + compilerConfig.getNonStandardOptions() + "\n-> javaoptions:" + formatMap(compilerConfig.getJavaOptionsMap()); } private String formatCollection(Collection<?> options) { @@ -209,7 +208,7 @@ public class AjdeCoreBuildManager { /** * Generate a new AjBuildConfig from the compiler configuration associated with this AjdeCoreBuildManager or from a * configuration file. - * + * * @return null if invalid configuration, corresponding AjBuildConfig otherwise */ public AjBuildConfig generateAjBuildConfig() { diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/TestBuildProgressMonitor.java b/ajde.core/src/test/java/org/aspectj/ajde/core/TestBuildProgressMonitor.java index f732d2acb..5269a586a 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/TestBuildProgressMonitor.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/TestBuildProgressMonitor.java @@ -1,11 +1,11 @@ /******************************************************************** - * Copyright (c) 2007 Contributors. All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://eclipse.org/legal/epl-v10.html - * - * Contributors: IBM Corporation - initial API and implementation + * Copyright (c) 2007 Contributors. All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation * Helen Hawkins - initial version *******************************************************************/ package org.aspectj.ajde.core; @@ -19,19 +19,20 @@ import java.util.List; * after a specified string has been printed. */ public class TestBuildProgressMonitor implements IBuildProgressMonitor { - + + private static boolean verbose = System.getProperty("aspectj.tests.verbose","false").equalsIgnoreCase("true"); private static boolean debugTests = false; - + public int numWovenClassMessages = 0; - public int numWovenAspectMessages = 0; - public int numCompiledMessages = 0; - + public int numWovenAspectMessages = 0; + public int numCompiledMessages = 0; + private String programmableString; private int count; private List<String> messagesReceived = new ArrayList<>(); private int currentVal; private boolean isCancelRequested = false; - + public void finish(boolean wasFullBuild) { System.out.println("build finished. Was full build: " + wasFullBuild); } @@ -45,14 +46,16 @@ public class TestBuildProgressMonitor implements IBuildProgressMonitor { } public void setProgressText(String text) { - System.out.println("progress text: " + text); + if (verbose) { + System.out.println("progress text: " + text); + } String newText = text+" [Percentage="+currentVal+"%]"; messagesReceived.add(newText); if (text.startsWith("woven aspect ")) numWovenAspectMessages++; if (text.startsWith("woven class ")) numWovenClassMessages++; if (text.startsWith("compiled:")) numCompiledMessages++; if (programmableString != null - && text.contains(programmableString)) { + && text.contains(programmableString)) { count--; if (count==0) { if (debugTests) System.out.println("Just got message '"+newText+"' - asking build to cancel"); @@ -63,7 +66,9 @@ public class TestBuildProgressMonitor implements IBuildProgressMonitor { } public void begin() { - System.out.println("build started"); + if (verbose) { + System.out.println("build started"); + } currentVal = 0; } @@ -72,7 +77,7 @@ public class TestBuildProgressMonitor implements IBuildProgressMonitor { programmableString = string; this.count = count; } - + public boolean containsMessage(String prefix,String distinguishingMarks) { for (String element: messagesReceived) { if (element.startsWith(prefix) && @@ -80,12 +85,14 @@ public class TestBuildProgressMonitor implements IBuildProgressMonitor { } return false; } - + public void dumpMessages() { - System.out.println("ProgressMonitorMessages"); + if (verbose) { + System.out.println("ProgressMonitorMessages"); + } for (String element: messagesReceived) { System.out.println(element); } } - + } diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/OutxmlTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/OutxmlTest.java index 6434629bf..64417e84c 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/OutxmlTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/OutxmlTest.java @@ -1,11 +1,11 @@ /******************************************************************** - * Copyright (c) 2003 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: + * Copyright (c) 2003 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: * Matthew Webster initial implementation * Helen Hawkins Converted to new interface (bug 148190) *******************************************************************/ @@ -29,9 +29,9 @@ public class OutxmlTest extends AjdeCoreTestCase { public static final String PROJECT_DIR = "OutxmlTest"; public static final String BIN_DIR = "bin"; - public static final String OUTJAR_NAME = "/bin/test.jar"; - public static final String DEFAULT_AOPXML_NAME = Constants.AOP_AJC_XML; - public static final String CUSTOM_AOPXML_NAME = "custom/aop.xml"; + public static final String OUTJAR_NAME = "/bin/test.jar"; + public static final String DEFAULT_AOPXML_NAME = Constants.AOP_AJC_XML; + public static final String CUSTOM_AOPXML_NAME = "custom/aop.xml"; private String[] files = new String[]{ "src" + File.separator + "TestAbstractAspect.aj", @@ -39,7 +39,7 @@ public class OutxmlTest extends AjdeCoreTestCase { "src" + File.separator + "TestConcreteAspect.aj", "src" + File.separator + "TestInterface.java" }; - + private TestMessageHandler handler; private TestCompilerConfiguration compilerConfig; @@ -56,7 +56,7 @@ public class OutxmlTest extends AjdeCoreTestCase { handler = null; compilerConfig = null; } - + /** * Aim: Test "-outxml" option produces the correct xml file */ @@ -65,31 +65,31 @@ public class OutxmlTest extends AjdeCoreTestCase { compilerConfig.setNonStandardOptions("-outxml"); doBuild(true); assertTrue("Expected no compiler errors or warnings but found " - + handler.getMessages(), handler.getMessages().isEmpty()); + + handler.getMessages(), handler.getMessages().isEmpty()); File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME); assertTrue(DEFAULT_AOPXML_NAME + " missing",aopxml.exists()); } - + /** - * Aim: Test "-outxmlfile filename" option produces the correct + * Aim: Test "-outxmlfile filename" option produces the correct * xml file - * + * */ public void testOutxmlfileToFile () { compilerConfig.setProjectSourceFiles(getSourceFileList(files)); compilerConfig.setNonStandardOptions("-outxmlfile custom/aop.xml"); doBuild(true); assertTrue("Expected no compiler errors or warnings but found " - + handler.getMessages(), handler.getMessages().isEmpty()); - + + handler.getMessages(), handler.getMessages().isEmpty()); + File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME); assertTrue(CUSTOM_AOPXML_NAME + " missing",aopxml.exists()); } /** - * Aim: Test "-outxml" option produces the correct + * Aim: Test "-outxml" option produces the correct * xml entry in outjar file - * + * */ public void testOutxmlToOutjar () { File outjar = openFile(OUTJAR_NAME); @@ -98,44 +98,44 @@ public class OutxmlTest extends AjdeCoreTestCase { compilerConfig.setNonStandardOptions("-outxml"); doBuild(true); assertTrue("Expected no compiler errors or warnings but found " - + handler.getMessages(), handler.getMessages().isEmpty()); - + + handler.getMessages(), handler.getMessages().isEmpty()); + File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME); assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists()); assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME); } /** - * Aim: Test "-outxml" option produces a warning if "META-INF/aop.xml + * Aim: Test "-outxml" option produces a warning if "META-INF/aop.xml * already exists in source - * + * */ public void testOutxmlToOutjarWithAop_xml () { File f = new File( getAbsoluteProjectDir() + File.separator + "src-resources" + File.separator + "testjar.jar"); Set<File> roots = new HashSet<>(); roots.add(f); compilerConfig.setInpath(roots); - + File outjar = openFile(OUTJAR_NAME); compilerConfig.setOutjar(outjar.getAbsolutePath()); compilerConfig.setNonStandardOptions("-outxml"); doBuild(true); assertFalse("Expected compiler errors or warnings but didn't find any " + handler.getMessages(), handler.getMessages().isEmpty()); - + List<TestMessage> msgs = handler.getMessages(); - String msg = ((TestMessageHandler.TestMessage)msgs.get(0)).getContainedMessage().getMessage(); + String msg = msgs.get(0).getContainedMessage().getMessage(); String exp = "-outxml/-outxmlfile option ignored because resource already exists:"; assertTrue("Expected message to start with : " + exp + " but found message " + msg,msg.startsWith(exp)); - + File aopxml = openFile(BIN_DIR + "/" + DEFAULT_AOPXML_NAME); assertFalse(DEFAULT_AOPXML_NAME + " should not exisit",aopxml.exists()); assertJarContainsEntry(outjar,DEFAULT_AOPXML_NAME); } - + /** - * Aim: Test "-outxmlfile filename" option produces the correct + * Aim: Test "-outxmlfile filename" option produces the correct * xml entry in outjar file */ public void testOutxmlfileToOutjar () { @@ -145,17 +145,15 @@ public class OutxmlTest extends AjdeCoreTestCase { compilerConfig.setNonStandardOptions("-outxmlfile custom/aop.xml"); doBuild(true); assertTrue("Expected no compiler errors or warnings but found " - + handler.getMessages(), handler.getMessages().isEmpty()); - + + handler.getMessages(), handler.getMessages().isEmpty()); + File aopxml = openFile(BIN_DIR + "/" + CUSTOM_AOPXML_NAME); assertFalse(CUSTOM_AOPXML_NAME + " should not exisit",aopxml.exists()); assertJarContainsEntry(outjar,CUSTOM_AOPXML_NAME); } private void assertJarContainsEntry (File file, String entryName) { - - try { - JarFile jarFile = new JarFile(file); + try (JarFile jarFile = new JarFile(file)) { JarEntry jarEntry = jarFile.getJarEntry(entryName); assertNotNull(entryName + " missing",jarEntry); } diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java index 3bd3fbdb6..c5fa43e16 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/ShowWeaveMessagesTest.java @@ -1,12 +1,12 @@ /* ******************************************************************* * Copyright (c) 2004 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: + * 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 version * Helen Hawkins Converted to new interface (bug 148190) * ******************************************************************/ @@ -19,7 +19,6 @@ import java.io.FileWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.Hashtable; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -35,24 +34,24 @@ import org.aspectj.util.LangUtil; * Weaving messages are complicated things. There are multiple places where weaving takes place and the places vary depending on * whether we are doing a binary weave or going from source. All places that output weaving messages are tagged: // TAG: * WeavingMessage so you can easily find them! - * + * * Advice is the simplest to deal with as that is advice weaving is always done in the weaver. - * + * * Next is intertype declarations. These are also always done in the weaver but in the case of a binary weave we don't know the * originating source line for the ITD. - * + * * Finally, declares. Declare Parents: extends Can only be done when going from source, if attempted by a binary weave then an error * message (compiler limitation) is produced. Declare Parents: implements Is (currently!) done at both compile time and weave time. * If going from source then the message is produced by the code in the compiler. if going from binary then the message is produced * by the weaver. Declare Soft: Comes out with 'advice' as a special kind of advice: softener advice - * - * + * + * * Q: Where are the messages turned on/off? A: It is a bit messy. See BuildArgParser.genBuildConfig(). Basically that method is the * first time we parse the option set. Whether weaving messages are on or off is stored in the build config. As soon as we have * parser the options and determined that weave messages are on, we grab the top level message handler and tell it not to ignore * WeaveInfo messages. - * - * + * + * * TODO - Other forms of declare? Do they need messages? e.g. declare precedence * */ public class ShowWeaveMessagesTest extends AjdeCoreTestCase { diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmDeclarationsTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmDeclarationsTest.java index 7a2ec9fc5..6112e67a3 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmDeclarationsTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmDeclarationsTest.java @@ -1,11 +1,11 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * 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 - * + * 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 + * * ******************************************************************/ package org.aspectj.ajde.core.tests.model; @@ -19,7 +19,7 @@ import org.aspectj.asm.IProgramElement; public class AsmDeclarationsTest extends AjdeCoreTestCase { - private AsmManager manager = null; + // private AsmManager manager = null; private IHierarchy model = null; private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" }; @@ -33,7 +33,7 @@ public class AsmDeclarationsTest extends AjdeCoreTestCase { compilerConfig.setProjectSourceFiles(getSourceFileList(files)); compilerConfig.setNonStandardOptions("-Xset:minimalModel=false"); doBuild(); - manager = AsmManager.lastActiveStructureModel; + // manager = AsmManager.lastActiveStructureModel; model = AsmManager.lastActiveStructureModel.getHierarchy(); } @@ -72,10 +72,10 @@ public class AsmDeclarationsTest extends AjdeCoreTestCase { public void testFileInPackageAndDefaultPackage() { IProgramElement root = model.getRoot(); assertEquals(root.toLabelString(), "coverage"); - IProgramElement pkg = (IProgramElement) root.getChildren().get(1); + IProgramElement pkg = root.getChildren().get(1); assertEquals(pkg.toLabelString(), "pkg"); - assertEquals(((IProgramElement) pkg.getChildren().get(0)).toLabelString(), "InPackage.java"); - assertEquals(((IProgramElement) ((IProgramElement) root.getChildren().get(0)).getChildren().get(0)).toLabelString(), + assertEquals(pkg.getChildren().get(0).toLabelString(), "InPackage.java"); + assertEquals(root.getChildren().get(0).getChildren().get(0).toLabelString(), "ModelCoverage.java"); } @@ -105,9 +105,9 @@ public class AsmDeclarationsTest extends AjdeCoreTestCase { // check the next two relative to this one int declareIndex = decParentsNode.getParent().getChildren().indexOf(decParentsNode); String decParentsPtnMessage = "declare parents: extends Observable"; - assertEquals(decParentsPtnMessage, ((IProgramElement) aspect.getChildren().get(declareIndex + 1)).toLabelString()); + assertEquals(decParentsPtnMessage, aspect.getChildren().get(declareIndex + 1).toLabelString()); String decParentsTPMessage = "declare parents: extends Observable"; - assertEquals(decParentsTPMessage, ((IProgramElement) aspect.getChildren().get(declareIndex + 2)).toLabelString()); + assertEquals(decParentsTPMessage, aspect.getChildren().get(declareIndex + 2).toLabelString()); String decSoftMessage = "declare soft: SizeException"; IProgramElement decSoftNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_SOFT, "declare soft"); diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmRelationshipsTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmRelationshipsTest.java index 4feefedcb..093de8cb7 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmRelationshipsTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/AsmRelationshipsTest.java @@ -1,17 +1,16 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * 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 - * + * 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 + * * ******************************************************************/ package org.aspectj.ajde.core.tests.model; import java.io.File; -import java.util.Iterator; import java.util.List; import org.aspectj.ajde.core.AjdeCoreTestCase; diff --git a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/StructureModelTest.java b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/StructureModelTest.java index 739daee32..6f06a1aa0 100644 --- a/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/StructureModelTest.java +++ b/ajde.core/src/test/java/org/aspectj/ajde/core/tests/model/StructureModelTest.java @@ -1,13 +1,13 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * 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: - * Xerox/PARC initial implementation + * 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: + * Xerox/PARC initial implementation * AMC 21.01.2003 fixed for new source location in eclipse.org * Helen Hawkins Converted to new interface (bug 148190) * ******************************************************************/ @@ -15,7 +15,6 @@ package org.aspectj.ajde.core.tests.model; import java.io.File; import java.io.IOException; -import java.util.Iterator; import org.aspectj.ajde.core.AjdeCoreTestCase; import org.aspectj.ajde.core.TestCompilerConfiguration; @@ -57,7 +56,7 @@ public class StructureModelTest extends AjdeCoreTestCase { File testFile = openFile("figures" + File.separator + "Figure.java"); IProgramElement node = manager.getHierarchy().findElementForSourceFile(testFile.getAbsolutePath()); assertTrue("find result", node != null); - String child = ((IProgramElement) node.getChildren().get(2)).getName(); + String child = node.getChildren().get(2).getName(); assertTrue("expected Figure got child " + child, child.equals("Figure")); } @@ -65,9 +64,9 @@ public class StructureModelTest extends AjdeCoreTestCase { File testFile = openFile("figures" + File.separator + "Main.java"); IProgramElement node = manager.getHierarchy().findElementForSourceFile(testFile.getAbsolutePath()); assertTrue("find result", node != null); - IProgramElement pNode = (IProgramElement) (node).getChildren().get(3); + IProgramElement pNode = (node).getChildren().get(3); assertEquals(IProgramElement.Kind.ASPECT, pNode.getKind()); - IProgramElement pointcut = (IProgramElement) pNode.getChildren().get(0); + IProgramElement pointcut = pNode.getChildren().get(0); assertTrue("kind", pointcut.getKind().equals(IProgramElement.Kind.POINTCUT)); assertTrue("found node: " + pointcut.getName(), pointcut.toLabelString().equals("testptct()")); } diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/JavadocRunner.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/JavadocRunner.java index 64e53eead..adf22bf12 100644 --- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/JavadocRunner.java +++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/JavadocRunner.java @@ -14,8 +14,6 @@ package org.aspectj.tools.ajdoc; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.List; import java.util.Vector; @@ -30,77 +28,6 @@ import javax.tools.ToolProvider; */ class JavadocRunner { - static boolean has14ToolsAvailable() { - try { - Class jdMainClass = com.sun.tools.javadoc.Main.class; - Class[] paramTypes = new Class[] { String[].class }; - jdMainClass.getMethod("execute", paramTypes); - } catch (NoClassDefFoundError e) { - return false; - } catch (UnsupportedClassVersionError e) { - return false; - } catch (NoSuchMethodException e) { - return false; - } - return true; - } - - static void callJavadoc(String[] javadocargs) { - // final SecurityManager defaultSecurityManager = System.getSecurityManager(); - // - // System.setSecurityManager( new SecurityManager() { - // public void checkExit(int status) { - // if (status == 0) { - // throw new SecurityException(); - // } - // else { - // System.setSecurityManager(defaultSecurityManager); - // //System.out.println("Error: javadoc exited unexpectedly"); - // System.exit(0); - // throw new SecurityException(); - // } - // } - // public void checkPermission( java.security.Permission permission ) { - // if ( defaultSecurityManager != null ) - // defaultSecurityManager.checkPermission( permission ); - // } - // public void checkPermission( java.security.Permission permission, - // Object context ) { - // if ( defaultSecurityManager != null ) - // defaultSecurityManager.checkPermission( permission, context ); - // } - // } ); - - try { - // for JDK 1.4 and above call the execute method... - Class jdMainClass = com.sun.tools.javadoc.Main.class; - Method executeMethod = null; - try { - Class[] paramTypes = new Class[] { String[].class }; - executeMethod = jdMainClass.getMethod("execute", paramTypes); - } catch (NoSuchMethodException e) { - com.sun.tools.javadoc.Main.main(javadocargs); - // throw new UnsupportedOperationException("ajdoc requires a tools library from JDK 1.4 or later."); - } - try { - executeMethod.invoke(null, new Object[] { javadocargs }); - } catch (IllegalArgumentException e1) { - throw new RuntimeException("Failed to invoke javadoc"); - } catch (IllegalAccessException e1) { - throw new RuntimeException("Failed to invoke javadoc"); - } catch (InvocationTargetException e1) { - throw new RuntimeException("Failed to invoke javadoc"); - } - // main method is documented as calling System.exit() - which stops us dead in our tracks - // com.sun.tools.javadoc.Main.main( javadocargs ); - } catch (SecurityException se) { - // Do nothing since we expect it to be thrown - // System.out.println( ">> se: " + se.getMessage() ); - } - // Set the security manager back - // System.setSecurityManager(defaultSecurityManager); - } - public static void callJavadocViaToolProvider(Vector<String> options, List<String> files) { DocumentationTool doctool = ToolProvider.getSystemDocumentationTool(); StandardJavaFileManager fm = doctool.getStandardFileManager(null, null, null); diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java index 2b2a24a26..26857b41c 100644 --- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java +++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/Main.java @@ -35,7 +35,6 @@ import org.aspectj.asm.AsmManager; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.Version; import org.aspectj.util.FileUtil; -import org.aspectj.util.LangUtil; /** * This is an old implementation of ajdoc that does not use an OO style. However, it does the job, and should serve to evolve a @@ -104,11 +103,6 @@ public class Main implements Config { public static void main(String[] args) { clearState(); - if (!JavadocRunner.has14ToolsAvailable()) { - System.err.println("ajdoc requires a JDK 1.4 or later tools jar - exiting"); - aborted = true; - return; - } // STEP 1: parse the command line and do other global setup sourcepath.addElement("."); // add the current directory to the classapth @@ -267,11 +261,9 @@ public class Main implements Config { for (int k = 0; k < fileList.size(); k++) { javadocargs[numExtraArgs + options.size() + packageList.size() + k] = fileList.elementAt(k); } - if (LangUtil.is19VMOrGreater()) { - options = new Vector<>(); - for (String a: javadocargs) { - options.add(a); - } + options = new Vector<>(); + for (String a: javadocargs) { + options.add(a); } } else { javadocargs = new String[options.size() + signatureFiles.length]; @@ -285,11 +277,7 @@ public class Main implements Config { files.add(StructureUtil.translateAjPathName(signatureFile.getCanonicalPath())); } } - if (LangUtil.is19VMOrGreater()) { - JavadocRunner.callJavadocViaToolProvider(options, files); - } else { - JavadocRunner.callJavadoc(javadocargs); - } + JavadocRunner.callJavadocViaToolProvider(options, files); } /** diff --git a/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java b/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java index cd5590914..125a9e95c 100644 --- a/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java +++ b/loadtime/src/test/java/org/aspectj/weaver/loadtime/JRockitAgentTest.java @@ -54,7 +54,7 @@ public class JRockitAgentTest extends TestCase { } public void testJrockitRecursionProtection() { - if (LangUtil.is11VMOrGreater()) { + if (LangUtil.is19VMOrGreater()) { // Skip test, not castable to URLClassLoader return; } diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java index 088ff78f9..15fdf0d9f 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/Ajc.java @@ -1,13 +1,13 @@ /* ******************************************************************* * Copyright (c) 2004 IBM Corporation - * 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: - * Adrian Colyer, + * 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: + * Adrian Colyer, * ******************************************************************/ package org.aspectj.tools.ajc; @@ -17,12 +17,9 @@ import java.io.FilenameFilter; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; -import junit.framework.AssertionFailedError; - import org.aspectj.asm.AsmManager; import org.aspectj.asm.IProgramElement; import org.aspectj.asm.IRelationship; @@ -31,9 +28,9 @@ import org.aspectj.asm.internal.Relationship; import org.aspectj.bridge.AbortException; import org.aspectj.bridge.ICommand; import org.aspectj.bridge.IMessage; +import org.aspectj.bridge.IMessage.Kind; import org.aspectj.bridge.IMessageHandler; import org.aspectj.bridge.MessageHandler; -import org.aspectj.bridge.IMessage.Kind; import org.aspectj.bridge.context.CompilationAndWeavingContext; import org.aspectj.testing.util.TestUtil; import org.aspectj.util.FileUtil; @@ -45,13 +42,13 @@ import org.aspectj.util.FileUtil; * The expected usage of Ajc is through the TestCase superclass, AjcTestCase, which provides helper methods that conveniently drive * the base functions exposed by this class. * </p> - * + * * @see org.aspectj.tools.ajc.AjcTestCase */ public class Ajc { private static final String BUILD_OUTPUT_FOLDER = "target"; - + public static final String outputFolder(String module) { return File.pathSeparator + ".." +File.separator + module + File.separator + "target" + File.separator + "classes"; } @@ -63,54 +60,54 @@ public class Ajc { } return s.toString(); } - + // ALSO SEE ANTSPEC AND AJCTESTCASE - private static final String TESTER_PATH = outputFolder("testing-client") + outputFolder("runtime") + outputFolder("bcel-builder") -// + File.pathSeparator + ".." + File.separator + "runtime" + File.separator + BUILD_OUTPUT_FOLDER // -// + File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + BUILD_OUTPUT_FOLDER // - + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "junit" + File.separator + "junit.jar" // -// + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "bcel" + File.separator + "bcel.jar" // -// + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "bcel" + File.separator -// + "bcel-verifier.jar" + - - + outputFolder("bridge") - + outputFolder("loadtime") - + outputFolder("weaver") - + outputFolder("org.aspectj.matcher") - + outputFolder("bridge"); -// File.pathSeparator + ".." + File.separator + "bridge" + File.separator + "bin" + File.pathSeparator + ".." -// + File.separator + "loadtime" + File.separator + "bin" + File.pathSeparator -// + ".." -// + File.separator -// + "weaver" -// + File.separator -// + "bin" -// + File.pathSeparator -// + ".." -// + File.separator -// + "weaver5" -// + File.separator -// + "bin" -// + File.pathSeparator -// + ".." -// + File.separator -// + "org.aspectj.matcher" -// + File.separator -// + "bin" - - // When the build machine executes the tests, it is using code built into jars rather than code build into - // bin directories. This means for the necessary types to be found we have to put these jars on the classpath: -// + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "bridge.jar" -// + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator -// + "org.aspectj.matcher.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" -// + File.separator + "util.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" -// + File.separator + "loadtime.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" -// + File.separator + "weaver.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" -// + File.separator + "weaver5.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" -// + File.separator + "asm.jar" + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" -// + File.separator + "testing-client.jar" -// // hmmm, this next one should perhaps point to an aj-build jar... -// + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "aspectjrt.jar"; + private static final String TESTER_PATH = outputFolder("testing-client") + outputFolder("runtime") + outputFolder("bcel-builder") + // + File.pathSeparator + ".." + File.separator + "runtime" + File.separator + BUILD_OUTPUT_FOLDER // + // + File.pathSeparator + ".." + File.separator + "aspectj5rt" + File.separator + BUILD_OUTPUT_FOLDER // + + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "junit" + File.separator + "junit.jar" // + // + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "bcel" + File.separator + "bcel.jar" // + // + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "bcel" + File.separator + // + "bcel-verifier.jar" + + + + outputFolder("bridge") + + outputFolder("loadtime") + + outputFolder("weaver") + + outputFolder("org.aspectj.matcher") + + outputFolder("bridge"); + // File.pathSeparator + ".." + File.separator + "bridge" + File.separator + "bin" + File.pathSeparator + ".." + // + File.separator + "loadtime" + File.separator + "bin" + File.pathSeparator + // + ".." + // + File.separator + // + "weaver" + // + File.separator + // + "bin" + // + File.pathSeparator + // + ".." + // + File.separator + // + "weaver5" + // + File.separator + // + "bin" + // + File.pathSeparator + // + ".." + // + File.separator + // + "org.aspectj.matcher" + // + File.separator + // + "bin" + + // When the build machine executes the tests, it is using code built into jars rather than code build into + // bin directories. This means for the necessary types to be found we have to put these jars on the classpath: + // + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + "bridge.jar" + // + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + File.separator + // + "org.aspectj.matcher.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + // + File.separator + "util.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + // + File.separator + "loadtime.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + // + File.separator + "weaver.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + // + File.separator + "weaver5.jar" + File.pathSeparator + ".." + File.separator + "aj-build" + File.separator + "jars" + // + File.separator + "asm.jar" + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + // + File.separator + "testing-client.jar" + // // hmmm, this next one should perhaps point to an aj-build jar... + // + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "aspectjrt.jar"; private CompilationResult result; private File sandbox; @@ -120,7 +117,7 @@ public class Ajc { private int incrementalStage = 10; private boolean shouldEmptySandbox = true; private final AjcCommandController controller; - private static boolean verbose = System.getProperty("org.aspectj.tools.ajc.Ajc.verbose", "true").equals("true"); + public static boolean verbose = System.getProperty("aspectj.tests.verbose", "true").equals("true"); /** * Constructs a new Ajc instance, with a new AspectJ compiler inside. @@ -156,16 +153,16 @@ public class Ajc { * </p> * <p> * For example, given a baseDir of "tests/pr12345" and a compile command: "ajc src/A.java src/B.java", the files in - * + * * <pre> * tests/pr12345/ * src/ * A.java * B.java * </pre> - * + * * are copied to: - * + * * <pre> * ajcSandbox/ajcTestxxx.tmp/ * src/ @@ -185,7 +182,7 @@ public class Ajc { * <ul> * </ul> * </p> - * + * * @param args The compiler arguments. * @return a CompilationResult object with all the messages produced by the compiler, a description of the ajc command that was * issued, and the standard output and error of the compile (excluding messages which are provided separately) @@ -272,7 +269,7 @@ public class Ajc { * Throws an IllegalStateException if you try and call this method without first doing a compile that specified the -incremental * option. * </p> - * + * * @return A CompilationResult giving the results of the most recent increment. * @throws IOException */ @@ -408,10 +405,10 @@ public class Ajc { String relativeToPath = (fromParent != null) ? (fromParent.getPath() + File.separator) : ""; if (baseDir != null) { from = new File(baseDir, from.getPath()); -// if (ensureDirsExist) { -// File toMkdir = (ret.getPath().endsWith(".jar") || ret.getPath().endsWith(".zip"))?ret.getParentFile():ret; -// toMkdir.mkdirs(); -// } + // if (ensureDirsExist) { + // File toMkdir = (ret.getPath().endsWith(".jar") || ret.getPath().endsWith(".zip"))?ret.getParentFile():ret; + // toMkdir.mkdirs(); + // } } if (!from.exists()) return ret; @@ -421,6 +418,7 @@ public class Ajc { if (from.isFile()) { final String prefix = from.getName().substring(0, from.getName().lastIndexOf('.')); String[] toCopy = from.getParentFile().list(new FilenameFilter() { + @Override public boolean accept(File dir, String name) { if (name.indexOf('.') == -1) return false; @@ -488,9 +486,10 @@ class AjcCommandController extends Main.CommandController { /* * (non-Javadoc) - * + * * @see org.aspectj.tools.ajc.Main.CommandController#doRepeatCommand() */ + @Override boolean doRepeatCommand(ICommand command) { this.command = command; return false; // ensure that control returns to caller @@ -498,9 +497,10 @@ class AjcCommandController extends Main.CommandController { /* * (non-Javadoc) - * + * * @see org.aspectj.tools.ajc.Main.CommandController#running() */ + @Override public boolean running() { return false; // so that we can come back for more... } @@ -514,6 +514,7 @@ class AjcCommandController extends Main.CommandController { class AbortInterceptor implements IMessageHandler { + @Override public boolean handleMessage(IMessage message) throws AbortException { if (message.getKind() == IMessage.ABORT) { System.err.println("***** Abort Message Received ******"); @@ -527,15 +528,18 @@ class AbortInterceptor implements IMessageHandler { return false; } + @Override public boolean isIgnoring(Kind kind) { if (kind != IMessage.ABORT) return true; return false; } + @Override public void dontIgnore(Kind kind) { } + @Override public void ignore(Kind kind) { } } diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java index 5488ab1b2..d5238b477 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java @@ -26,7 +26,6 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; @@ -117,7 +116,7 @@ public abstract class AjcTestCase extends TestCase { public final static PrintStream out = System.out; private final static DelegatingOutputStream delegatingErr; private final static DelegatingOutputStream delegatingOut; - public final static boolean DEFAULT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose", true); + public final static boolean DEFAULT_VERBOSE = getBoolean("aspectj.tests.verbose", true); public final static boolean DEFAULT_ERR_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.err", DEFAULT_VERBOSE); public final static boolean DEFAULT_OUT_VERBOSE = getBoolean("org.aspectj.tools.ajc.AjcTestCase.verbose.out", DEFAULT_VERBOSE); @@ -673,7 +672,9 @@ public abstract class AjcTestCase extends TestCase { cp.append(TestUtil.aspectjrtPath().getPath()).append(File.pathSeparator); } String command = LangUtil.getJavaExecutable().getAbsolutePath() + " " +vmargs+ (cp.length()==0?"":" -classpath " + cp) + " -p "+mp+" --module "+moduleName ; - System.out.println("Command is "+command); + if (Ajc.verbose) { + System.out.println("Command is "+command); + } // Command is executed using ProcessBuilder to allow setting CWD for ajc sandbox compliance ProcessBuilder pb = new ProcessBuilder(tokenizeCommand(command)); pb.directory( new File(ajc.getSandboxDirectory().getAbsolutePath())); @@ -697,7 +698,9 @@ public abstract class AjcTestCase extends TestCase { cp.append(File.pathSeparator).append(TestUtil.aspectjrtPath().getPath()); } String command = LangUtil.getJavaExecutable().getAbsolutePath() + " " +vmargs+ (cp.length()==0?"":" -classpath " + cp) + " " + className ; - System.out.println("Command is "+command); + if (Ajc.verbose) { + System.out.println("\nCommand is "+command); + } // Command is executed using ProcessBuilder to allow setting CWD for ajc sandbox compliance ProcessBuilder pb = new ProcessBuilder(tokenizeCommand(command)); pb.directory( new File(ajc.getSandboxDirectory().getAbsolutePath())); @@ -756,6 +759,7 @@ public abstract class AjcTestCase extends TestCase { Class<?> toRun = sandboxLoader.loadClass(className); Method mainMethod = toRun.getMethod("main", new Class[] { String[].class }); + mainMethod.invoke(null, new Object[] { args }); } catch (ClassNotFoundException cnf) { fail("Can't find class: " + className); @@ -803,15 +807,21 @@ public abstract class AjcTestCase extends TestCase { PrintWriter stdOutWriter = new PrintWriter(baosOut); PrintWriter stdErrWriter = new PrintWriter(baosErr); + if (Ajc.verbose) { + System.out.println(); + } while ((line = stdInput.readLine()) != null) { stdOutWriter.println(line); - System.out.println(line); + if (Ajc.verbose) { + System.out.println(line); + } } stdOutWriter.flush(); while ((line = stdError.readLine()) != null) { stdErrWriter.println(line); - System.err.println(line); - + if (Ajc.verbose) { + System.err.println(line); + } } stdErrWriter.flush(); diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/CompilationResult.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/CompilationResult.java index a7d661038..047879a32 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/CompilationResult.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/CompilationResult.java @@ -1,18 +1,17 @@ /* ******************************************************************* * Copyright (c) 2004 IBM Corporation - * 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: - * Adrian Colyer, + * 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: + * Adrian Colyer, * ******************************************************************/ package org.aspectj.tools.ajc; import java.util.Collections; -import java.util.Iterator; import java.util.List; import org.aspectj.bridge.IMessage; @@ -20,7 +19,7 @@ import org.aspectj.bridge.IMessage; /** * Utility class that makes the results of a compiler run available. * <p> - * Instances of this class are returned by the Ajc.compile() and + * Instances of this class are returned by the Ajc.compile() and * doIncrementalCompile() methods (and the AjcTestCase.ajc() wrapper). * </p> * <p> @@ -33,7 +32,7 @@ import org.aspectj.bridge.IMessage; * </p> */ public class CompilationResult { - + private String[] args; private String stdOut; private String stdErr; @@ -46,7 +45,7 @@ public class CompilationResult { /** * Build a compilation result - called by the Ajc.compile and * Ajc.doIncrementalCompile methods. Should be no need for you - * to construct an instance yourself. + * to construct an instance yourself. */ protected CompilationResult( String[] args, @@ -62,24 +61,24 @@ public class CompilationResult { this.stdErr = stdErr; this.infoMessages = (infoMessages == null) ? Collections.<IMessage>emptyList() : infoMessages; this.errorMessages = (errorMessages == null) ? Collections.<IMessage>emptyList() : errorMessages; - this.warningMessages = (warningMessages == null) ? Collections.<IMessage>emptyList() : warningMessages; - this.failMessages = (failMessages == null) ? Collections.<IMessage>emptyList() : failMessages; - this.weaveMessages = (weaveMessages == null) ? Collections.<IMessage>emptyList() : weaveMessages; + this.warningMessages = (warningMessages == null) ? Collections.<IMessage>emptyList() : warningMessages; + this.failMessages = (failMessages == null) ? Collections.<IMessage>emptyList() : failMessages; + this.weaveMessages = (weaveMessages == null) ? Collections.<IMessage>emptyList() : weaveMessages; } - + /** * The arguments that were passed to the compiler. */ public String[] getArgs() { return args; } /** - * The standard output written by the compiler, excluding any messages. + * The standard output written by the compiler, excluding any messages. */ public String getStandardOutput() { return stdOut; } /** - * The standard error written by the compiler, excluding any messages. + * The standard error written by the compiler, excluding any messages. */ public String getStandardError() { return stdErr; } - + /** * True if the compiler issued any messages of any kind. */ @@ -104,7 +103,7 @@ public class CompilationResult { * True if the compiler issued one or more weave info messages. */ public boolean hasWeaveMessages() { return !weaveMessages.isEmpty(); } - + /** * The informational messages produced by the compiler. The list * entries are the <code>IMessage</code> objects created during the @@ -145,9 +144,9 @@ public class CompilationResult { * @see org.aspectj.tools.ajc.AjcTestCase */ public List<IMessage> getFailMessages() { return failMessages; } - + public List<IMessage> getWeaveMessages() { return weaveMessages; } - + /** * Returns string containing message count summary, list of messages * by type, and the actual ajc compilation command that was issued. @@ -171,7 +170,7 @@ public class CompilationResult { buff.append(" fail, )"); buff.append(weaveMessages.size()); buff.append(" weaveInfo"); - } + } buff.append("\n"); int msgNo = 1; for (IMessage failMessage : failMessages) { diff --git a/testing/src/test/java/org/aspectj/testing/OutputSpec.java b/testing/src/test/java/org/aspectj/testing/OutputSpec.java index 62a22cb80..ca7d0f232 100644 --- a/testing/src/test/java/org/aspectj/testing/OutputSpec.java +++ b/testing/src/test/java/org/aspectj/testing/OutputSpec.java @@ -36,7 +36,12 @@ public class OutputSpec { private boolean matchesThisVm(String vm) { // vm might be 1.2, 1.3, 1.4, 1.5 or 1.9 possibly with a '+' in there // For now assume + is attached to there only being one version, like "9+" - if (vm.contains(LangUtil.getVmVersionString())) { + // System.out.println("Checking "+vm+" for "+LangUtil.getVmVersionString()); + String v = LangUtil.getVmVersionString(); + if (v.endsWith(".0")) { + v = v.substring(0,v.length()-2); + } + if (vm.contains(v)) { return true; } if (vm.endsWith("+")) { diff --git a/testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java b/testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java index 92aaec667..ea88c49f1 100644 --- a/testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java +++ b/testing/src/test/java/org/aspectj/testing/harness/bridge/JavaRun.java @@ -834,13 +834,11 @@ public class JavaRun implements IAjcRun { throw new ExitCalledException(exitCode); } } - @Override public void checkAwtEventQueueAccess() { if ((null != runThread) && runThread.equals(Thread.currentThread())) { throw new AwtUsedException(); } } - @Override public void checkSystemClipboardAccess() { // permit } @@ -885,7 +883,6 @@ public class JavaRun implements IAjcRun { @Override public void checkListen(int arg0) { } - @Override public void checkMemberAccess(Class arg0, int arg1) { } @Override @@ -930,7 +927,6 @@ public class JavaRun implements IAjcRun { @Override public void checkSetFactory() { } - @Override public boolean checkTopLevelWindow(Object arg0) { return true; } diff --git a/tests/bugs170/xmldefs/Hello5.java b/tests/bugs170/xmldefs/Hello5.java index 361415a3e..62efc30e1 100644 --- a/tests/bugs170/xmldefs/Hello5.java +++ b/tests/bugs170/xmldefs/Hello5.java @@ -26,7 +26,7 @@ public class Hello5 { System.out.println("Annotation count is "+annos.length); for (Annotation anno: la) { - System.out.println(anno); + print(anno); } } } catch (Exception e) { @@ -34,6 +34,15 @@ public class Hello5 { } } + static void print(Annotation anno) { + if (anno instanceof AnnoDouble) { + AnnoDouble ad = ((AnnoDouble)anno); + System.out.println("@AnnoDouble(value="+ad.value()+",ddd="+ad.ddd()+")"); + } else { + System.out.println(anno); + } + } + static class AnnoComparator implements Comparator<Annotation> { public int compare(Annotation a, Annotation b) { return a.toString().compareTo(b.toString()); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc195/AllTestsAspectJ195.java b/tests/src/test/java/org/aspectj/systemtest/ajc195/AllTestsAspectJ195.java index f8a95a28a..81bba9000 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc195/AllTestsAspectJ195.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc195/AllTestsAspectJ195.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.aspectj.systemtest.ajc195; +import org.aspectj.util.LangUtil; + import junit.framework.Test; import junit.framework.TestSuite; @@ -18,7 +20,9 @@ public class AllTestsAspectJ195 { public static Test suite() { TestSuite suite = new TestSuite("AspectJ 1.9.5 tests"); suite.addTest(Ajc195Tests.suite()); - suite.addTest(SanityTestsJava13.suite()); + if (LangUtil.is13VMOrGreater()) { + suite.addTest(SanityTestsJava13.suite()); + } return suite; } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java b/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java index 1c8e725f0..0cdfe9290 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc196/AllTestsAspectJ196.java @@ -7,6 +7,8 @@ *******************************************************************************/ package org.aspectj.systemtest.ajc196; +import org.aspectj.util.LangUtil; + import junit.framework.Test; import junit.framework.TestSuite; @@ -17,8 +19,10 @@ public class AllTestsAspectJ196 { public static Test suite() { TestSuite suite = new TestSuite("AspectJ 1.9.6 tests"); - suite.addTest(Ajc196Tests.suite()); - suite.addTest(SanityTestsJava14.suite()); + if (LangUtil.is14VMOrGreater()) { + suite.addTest(Ajc196Tests.suite()); + suite.addTest(SanityTestsJava14.suite()); + } return suite; } } diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java index 58ab1959d..5cfb4b1a7 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java @@ -1,11 +1,11 @@ /******************************************************************** - * Copyright (c) 2005 Contributors.All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://eclipse.org/legal/epl-v10.html - * - * Contributors: + * Copyright (c) 2005 Contributors.All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: * Andy Clement initial implementation * Helen Hawkins Converted to new interface (bug 148190) *******************************************************************/ @@ -15,7 +15,6 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -35,14 +34,14 @@ import junit.framework.TestCase; /** * This class uses Ajde in the same way that an IDE (e.g. AJDT) does. - * + * * The build is driven through 'doBuild(projectName)' but the build can be configured by the methods beginning 'configure***'. * Information about what happened during a build is accessible through the get*, was*, print* public methods... - * + * */ public class AjdeInteractionTestbed extends TestCase { - public static boolean VERBOSE = false; // do you want the gory details? + public static boolean VERBOSE = System.getProperty("aspectj.tests.verbose","true").equalsIgnoreCase("true"); public static String testdataSrcDir = "../tests/multiIncremental"; protected static File sandboxDir; @@ -552,5 +551,5 @@ public class AjdeInteractionTestbed extends TestCase { decisions.append(s).append("\n"); log(s); } - }; + } }
\ No newline at end of file diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc170/ajc170.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc170/ajc170.xml index f372197c0..fde9ff259 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc170/ajc170.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc170/ajc170.xml @@ -204,7 +204,7 @@ <line text="Annotation count is 4"/> <line text="@AnnoChar(value=z, ccc=a)" vm="1.2,1.3,1.4,1.5,1.6,1.7,1.8"/> <line text="@AnnoChar(value='z', ccc='a')" vm="9+"/> - <line text="@AnnoDouble(value=99.0, ddd=3.0)"/> + <line text="@AnnoDouble(value=99.0,ddd=3.0)"/> <line text="@AnnoFloat(value=6.0, fff=4.0)" vm="1.2,1.3,1.4,1.5,1.6,1.7,1.8"/> <line text="@AnnoFloat(value=6.0f, fff=4.0f)" vm="9+"/> <line text="@AnnoShort(value=8, sss=3)"/> diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java index 8bd479332..bbad8ed6a 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelClassWeaver.java @@ -94,7 +94,7 @@ class BcelClassWeaver implements IClassWeaver { private static Trace trace = TraceFactory.getTraceFactory().getTrace(BcelClassWeaver.class); // Name of helper method generated by JDT compiler. Javac uses a separate inner class. - private static final String SWITCH_TABLE_SYNTHETIC_METHOD_PREFIX = "$SWITCH_TABLE$"; + private static final String SWITCH_TABLE_SYNTHETIC_METHOD_PREFIX = "$SWITCH_TABLE$"; public static boolean weave(BcelWorld world, LazyClassGen clazz, List<ShadowMunger> shadowMungers, List<ConcreteTypeMunger> typeMungers, List<ConcreteTypeMunger> lateTypeMungers, boolean inReweavableMode) { @@ -783,7 +783,6 @@ class BcelClassWeaver implements IClassWeaver { return false; // dont bother if we are an interface } - boolean didSomething = false; // set if we build any bridge methods // So what methods do we have right now in this class? List<LazyMethodGen> methods = clazz.getMethodGens(); @@ -796,6 +795,7 @@ class BcelClassWeaver implements IClassWeaver { methodsSet.add(sb.toString()); // e.g. "foo(Ljava/lang/String;)V" } + List<BridgeMethodDescriptor> bridges = null; // Now go through all the methods in this type for (LazyMethodGen bridgeToCandidate : methods) { // This is the local method that we *might* have to bridge to @@ -835,9 +835,12 @@ class BcelClassWeaver implements IClassWeaver { if (world.forDEBUG_bridgingCode) { System.err.println("Bridging:bridging to '" + overriddenMethod + "'"); } - createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod); + if (bridges== null) { + bridges = new ArrayList<>(); + } + bridges.add(new BridgeMethodDescriptor(bridgeToCandidate, overriddenMethod)); + //createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod); methodsSet.add(key); - didSomething = true; } } } @@ -856,9 +859,12 @@ class BcelClassWeaver implements IClassWeaver { String key = new StringBuffer().append(overriddenMethod.getName()).append(overriddenMethod.getSignatureErased()).toString(); // pr237419 boolean alreadyHaveABridgeMethod = methodsSet.contains(key); if (!alreadyHaveABridgeMethod) { - createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod); + if (bridges== null) { + bridges = new ArrayList<>(); + } + bridges.add(new BridgeMethodDescriptor(bridgeToCandidate, overriddenMethod)); + // createBridgeMethod(world, bridgeToCandidate, clazz, overriddenMethod); methodsSet.add(key); - didSomething = true; if (world.forDEBUG_bridgingCode) { System.err.println("Bridging:bridging to " + overriddenMethod); } @@ -867,7 +873,25 @@ class BcelClassWeaver implements IClassWeaver { } } - return didSomething; + if (bridges != null) { + for (BridgeMethodDescriptor bmDescriptor: bridges) { + createBridgeMethod(world, bmDescriptor.bridgeToCandidate, clazz, bmDescriptor.overriddenMethod); + } + } + + return bridges!=null && !bridges.isEmpty(); + } + + static class BridgeMethodDescriptor { + + final LazyMethodGen bridgeToCandidate; + final ResolvedMember overriddenMethod; + + public BridgeMethodDescriptor(LazyMethodGen bridgeToCandidate, ResolvedMember overriddenMethod) { + this.bridgeToCandidate = bridgeToCandidate; + this.overriddenMethod = overriddenMethod; + } + } // **************************** end of bridge method creation code ***************** @@ -909,9 +933,9 @@ class BcelClassWeaver implements IClassWeaver { for (LazyMethodGen method: addedLazyMethodGens) { // They have no resolvedmember of their own, conjure one up for matching purposes ResolvedMember resolvedmember = - new ResolvedMemberImpl(ResolvedMember.METHOD,method.getEnclosingClass().getType(),method.getAccessFlags(), - BcelWorld.fromBcel(method.getReturnType()),method.getName(), - BcelWorld.fromBcel(method.getArgumentTypes()),UnresolvedType.forNames(method.getDeclaredExceptions())); + new ResolvedMemberImpl(ResolvedMember.METHOD,method.getEnclosingClass().getType(),method.getAccessFlags(), + BcelWorld.fromBcel(method.getReturnType()),method.getName(), + BcelWorld.fromBcel(method.getArgumentTypes()),UnresolvedType.forNames(method.getDeclaredExceptions())); resolvedmember.setAnnotationTypes(method.getAnnotationTypes()); resolvedmember.setAnnotations(method.getAnnotations()); @@ -1119,7 +1143,7 @@ class BcelClassWeaver implements IClassWeaver { WeaveMessage.WEAVEMESSAGE_ANNOTATES, new String[] { sig.toString(), loc.toString(), decaM.getAnnotationString(), methodName.startsWith("<init>") ? "constructor" : "method", decaM.getAspect().toString(), - Utility.beautifyLocation(decaM.getSourceLocation()) })); + Utility.beautifyLocation(decaM.getSourceLocation()) })); } } @@ -1548,9 +1572,9 @@ class BcelClassWeaver implements IClassWeaver { world.getMessageHandler().handleMessage( WeaveMessage.constructWeavingMessage( isRemove ? WeaveMessage.WEAVEMESSAGE_REMOVES_ANNOTATION : WeaveMessage.WEAVEMESSAGE_ANNOTATES, - new String[] { theField.getFieldAsIs().toString() + "' of type '" + clazz.getName(), - clazz.getFileName(), decaf.getAnnotationString(), "field", decaf.getAspect().toString(), - Utility.beautifyLocation(decaf.getSourceLocation()) })); + new String[] { theField.getFieldAsIs().toString() + "' of type '" + clazz.getName(), + clazz.getFileName(), decaf.getAnnotationString(), "field", decaf.getAspect().toString(), + Utility.beautifyLocation(decaf.getSourceLocation()) })); } } @@ -2214,53 +2238,53 @@ class BcelClassWeaver implements IClassWeaver { cpi.setIndex(recipientCpg.addConstant(donorCpg.getConstant(cpi.getIndex()), donorCpg)); } // May need to copy bootstrapmethods across too. -// if (fresh instanceof InvokeDynamic) { -// InvokeDynamic id = (InvokeDynamic)fresh; -// ConstantInvokeDynamic cid = (ConstantInvokeDynamic)donorCpg.getConstant(src.getInstruction().getIndex()); -// int bmaIndex = cid.getBootstrapMethodAttrIndex(); -// if (bootstrapMethods == null) { -// Collection<Attribute> attributes = donor.getEnclosingClass().getAttributes(); -// if (attributes != null) { -// for (Attribute attribute: attributes) { -// if (attribute instanceof BootstrapMethods) { -// bootstrapMethods = (BootstrapMethods)attribute; -// } -// } -// } -// BootstrapMethods.BootstrapMethod bootstrapMethod = -// bootstrapMethods.getBootstrapMethods()[bmaIndex]; -// ConstantMethodHandle methodhandle = (ConstantMethodHandle)donorCpg.getConstant(bootstrapMethod.getBootstrapMethodRef()); -// int bootstrapMethodArguments[] = bootstrapMethod.getBootstrapArguments(); -// -// // Finally have all we need to build the new one... -// -// int newMethodHandleIndex = recipientCpg.addConstant(methodhandle, donorCpg); -// int[] newMethodArguments = new int[bootstrapMethodArguments.length]; -// for (int a=0; a<bootstrapMethodArguments.length; a++) { -// newMethodArguments[a] = recipientCpg.addConstant(donorCpg.getConstant(bootstrapMethodArguments[a]),donorCpg); -// } -// BootstrapMethods.BootstrapMethod newBootstrapMethod = -// new BootstrapMethods.BootstrapMethod(newMethodHandleIndex,newMethodArguments); -// -// Collection<Attribute> newAttributes = recipient.getEnclosingClass().getAttributes(); -// BootstrapMethods newBootstrapMethods = null; -// for (Attribute attr: newAttributes) { -// if (attr instanceof BootstrapMethods) { -// newBootstrapMethods = (BootstrapMethods)newBootstrapMethods; -// } -// } -// if (newBootstrapMethods == null) { -// newBootstrapMethods = -// new BootstrapMethods(recipientCpg.addUtf8("BootstrapMethods"), -// 2+newBootstrapMethod.getLength(), -// new BootstrapMethods.BootstrapMethod[] {newBootstrapMethod}, -// recipientCpg); -// recipient.getEnclosingClass().addAttribute(newBootstrapMethods); -// } -// TODO need to copy over lambda$0 support methods too... -// } -// -// } + // if (fresh instanceof InvokeDynamic) { + // InvokeDynamic id = (InvokeDynamic)fresh; + // ConstantInvokeDynamic cid = (ConstantInvokeDynamic)donorCpg.getConstant(src.getInstruction().getIndex()); + // int bmaIndex = cid.getBootstrapMethodAttrIndex(); + // if (bootstrapMethods == null) { + // Collection<Attribute> attributes = donor.getEnclosingClass().getAttributes(); + // if (attributes != null) { + // for (Attribute attribute: attributes) { + // if (attribute instanceof BootstrapMethods) { + // bootstrapMethods = (BootstrapMethods)attribute; + // } + // } + // } + // BootstrapMethods.BootstrapMethod bootstrapMethod = + // bootstrapMethods.getBootstrapMethods()[bmaIndex]; + // ConstantMethodHandle methodhandle = (ConstantMethodHandle)donorCpg.getConstant(bootstrapMethod.getBootstrapMethodRef()); + // int bootstrapMethodArguments[] = bootstrapMethod.getBootstrapArguments(); + // + // // Finally have all we need to build the new one... + // + // int newMethodHandleIndex = recipientCpg.addConstant(methodhandle, donorCpg); + // int[] newMethodArguments = new int[bootstrapMethodArguments.length]; + // for (int a=0; a<bootstrapMethodArguments.length; a++) { + // newMethodArguments[a] = recipientCpg.addConstant(donorCpg.getConstant(bootstrapMethodArguments[a]),donorCpg); + // } + // BootstrapMethods.BootstrapMethod newBootstrapMethod = + // new BootstrapMethods.BootstrapMethod(newMethodHandleIndex,newMethodArguments); + // + // Collection<Attribute> newAttributes = recipient.getEnclosingClass().getAttributes(); + // BootstrapMethods newBootstrapMethods = null; + // for (Attribute attr: newAttributes) { + // if (attr instanceof BootstrapMethods) { + // newBootstrapMethods = (BootstrapMethods)newBootstrapMethods; + // } + // } + // if (newBootstrapMethods == null) { + // newBootstrapMethods = + // new BootstrapMethods(recipientCpg.addUtf8("BootstrapMethods"), + // 2+newBootstrapMethod.getLength(), + // new BootstrapMethods.BootstrapMethod[] {newBootstrapMethod}, + // recipientCpg); + // recipient.getEnclosingClass().addAttribute(newBootstrapMethods); + // } + // TODO need to copy over lambda$0 support methods too... + // } + // + // } } if (src.getInstruction() == Range.RANGEINSTRUCTION) { dest = ret.append(Range.RANGEINSTRUCTION); @@ -2653,7 +2677,7 @@ class BcelClassWeaver implements IClassWeaver { return false; } if (mg.getName().startsWith(SWITCH_TABLE_SYNTHETIC_METHOD_PREFIX) - && Objects.equals(mg.getReturnType().getSignature(), "[I")) { + && Objects.equals(mg.getReturnType().getSignature(), "[I")) { // this is a synthetic switch helper, should be skipped (since it's not 'declared') return false; } @@ -3239,7 +3263,7 @@ class BcelClassWeaver implements IClassWeaver { && s.charAt(4) == 'a' && (s.equals("org.aspectj.runtime.internal.CFlowCounter") || s.equals("org.aspectj.runtime.internal.CFlowStack") || s - .equals("org.aspectj.runtime.reflect.Factory"))) { + .equals("org.aspectj.runtime.reflect.Factory"))) { proceed = false; } else { if (methodName.equals("aspectOf")) { |