From 92a9d99937725875881b691085fdbf3332917f6e Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Mon, 27 Jun 2016 15:49:09 -0700 Subject: [PATCH] Fix classpath for tests on Java9 --- .../ajde/core/TestCompilerConfiguration.java | 12 ++- .../aspectj/tools/ajdoc/AjdocTestCase.java | 8 +- .../compiler/batch/BasicCommandTestCase.java | 7 +- .../compiler/batch/CommandTestCase.java | 8 +- .../org/aspectj/tools/ajc/AjcTestCase.java | 79 ++++++++++--------- .../testing/drivers/HarnessSelectionTest.java | 3 +- .../taskdefs/AjcTaskCompileCommandTest.java | 7 +- 7 files changed, 81 insertions(+), 43 deletions(-) diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/TestCompilerConfiguration.java b/ajde.core/testsrc/org/aspectj/ajde/core/TestCompilerConfiguration.java index c3a46c047..2265014f9 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/TestCompilerConfiguration.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/TestCompilerConfiguration.java @@ -22,6 +22,7 @@ import java.util.Set; import org.aspectj.tools.ajc.AjcTests; import org.aspectj.util.FileUtil; +import org.aspectj.util.LangUtil; /** * Test implementation of ICompilerConfiguration. Allows users to configure the settings via setter methods. By default returns null @@ -58,8 +59,15 @@ public class TestCompilerConfiguration implements ICompilerConfiguration { } public String getClasspath() { - return projectPath + File.pathSeparator + System.getProperty("sun.boot.class.path") + File.pathSeparator - + AjcTests.aspectjrtClasspath(); + StringBuilder classpath = new StringBuilder(); + classpath.append(projectPath); + if (LangUtil.is19VMOrGreater()) { + classpath.append(File.pathSeparator).append(LangUtil.getJrtFsFilePath()); + } else { + classpath.append(File.pathSeparator).append(System.getProperty("sun.boot.class.path")); + } + classpath.append(File.pathSeparator).append(AjcTests.aspectjrtClasspath()); + return classpath.toString(); } public Set getInpath() { diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java index 2db299f37..d75f8cb64 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java @@ -19,6 +19,7 @@ import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.aspectj.tools.ajc.Ajc; +import org.aspectj.util.LangUtil; /** * This class is the super class of all Ajdoc tests. It creates a sandbox directory and provides utility methods for copying over @@ -202,7 +203,12 @@ public class AjdocTestCase extends TestCase { args[1] = "-source"; args[2] = sourceLevel; args[3] = "-classpath"; - args[4] = AjdocTests.ASPECTJRT_PATH.getPath(); + StringBuilder classpath = new StringBuilder(); + if (LangUtil.is19VMOrGreater()) { + classpath.append(LangUtil.getJrtFsFilePath()).append(File.pathSeparator); + } + classpath.append(AjdocTests.ASPECTJRT_PATH.getPath()); + args[4] = classpath.toString(); args[5] = "-d"; args[6] = getAbsolutePathOutdir(); // args[7] = "-Xset:minimalModel=false"; diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java index 08a5252a6..62b1ef67e 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/BasicCommandTestCase.java @@ -22,6 +22,7 @@ import org.aspectj.ajdt.ajc.AjdtCommand; import org.aspectj.bridge.ICommand; //import org.aspectj.bridge.IMessage; import org.aspectj.bridge.MessageHandler; +import org.aspectj.util.LangUtil; /** * @author hugunin @@ -71,6 +72,7 @@ public class BasicCommandTestCase extends CommandTestCase { public void testThisAndModifiers() { checkCompile("src1/ThisAndModifiers.java", NO_ERRORS); } + public void testDeclares() { checkCompile("src1/Declares.java", new int[] {2}); } @@ -98,7 +100,10 @@ public class BasicCommandTestCase extends CommandTestCase { args.add(getSandboxName()); args.add("-classpath"); - args.add(getRuntimeClasspath() + File.pathSeparator + "../lib/junit/junit.jar;../testing-client/bin"); + StringBuilder classpath = new StringBuilder(); + classpath.append(getRuntimeClasspath()); + classpath.append(File.pathSeparator).append("../lib/junit/junit.jar;../testing-client/bin"); + args.add(classpath.toString()); args.add("-Xlint:error"); args.add(AjdtAjcTests.TESTDATA_PATH + "/src1/Xlint.java"); diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java index a586f8c7d..23e589080 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/CommandTestCase.java @@ -31,6 +31,7 @@ import org.aspectj.bridge.MessageHandler; import org.aspectj.testing.util.TestUtil; import org.aspectj.tools.ajc.Ajc; import org.aspectj.tools.ajc.AjcTests; +import org.aspectj.util.LangUtil; import org.aspectj.weaver.bcel.LazyClassGen; public abstract class CommandTestCase extends TestCase { @@ -175,7 +176,12 @@ public abstract class CommandTestCase extends TestCase { /** get the location of the org.aspectj.lang & runtime classes */ protected static String getRuntimeClasspath() { - return AjcTests.aspectjrtClasspath(); + StringBuilder classpath = new StringBuilder(); + if (LangUtil.is19VMOrGreater()) { + classpath.append(LangUtil.getJrtFsFilePath()).append(File.pathSeparator); + } + classpath.append(AjcTests.aspectjrtClasspath()); + return classpath.toString(); } protected String getSandboxName() { diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java index f0af8da50..5c4ee012b 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java @@ -35,6 +35,7 @@ import junit.framework.TestCase; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; import org.aspectj.testing.util.TestUtil; +import org.aspectj.util.LangUtil; /** * A TestCase class that acts as the superclass for all test cases wishing to drive the ajc compiler. @@ -610,13 +611,11 @@ public class AjcTestCase extends TestCase { getAnyJars(ajc.getSandboxDirectory(), cp); URLClassLoader sandboxLoader; - URLClassLoader testLoader = (URLClassLoader) getClass().getClassLoader(); - ClassLoader parentLoader = testLoader.getParent(); - - + ClassLoader parentLoader = getClass().getClassLoader().getParent(); /* Sandbox -> AspectJ -> Extension -> Bootstrap */ if ( !useFullLTW && useLTW) { + URLClassLoader testLoader = (URLClassLoader) getClass().getClassLoader(); /* * Create a new AspectJ class loader using the existing test CLASSPATH and any missing Java 5 projects */ @@ -851,38 +850,46 @@ public class AjcTestCase extends TestCase { * @param args the String[] args to fix up * @return the String[] args to use */ - protected String[] fixupArgs(String[] args) { - if (null == args) { - return null; - } - int cpIndex = -1; - boolean hasruntime = false; - for (int i = 0; i < args.length - 1; i++) { - args[i] = adaptToPlatform(args[i]); - if ("-classpath".equals(args[i])) { - cpIndex = i; - args[i + 1] = substituteSandbox(args[i + 1]); - String next = args[i + 1]; - hasruntime = ((null != next) && (-1 != next.indexOf("aspectjrt.jar"))); - } - } - if (-1 == cpIndex) { - String[] newargs = new String[args.length + 2]; - newargs[0] = "-classpath"; - newargs[1] = TestUtil.aspectjrtPath().getPath(); - System.arraycopy(args, 0, newargs, 2, args.length); - args = newargs; - } else { - if (!hasruntime) { - cpIndex++; - String[] newargs = new String[args.length]; - System.arraycopy(args, 0, newargs, 0, args.length); - newargs[cpIndex] = args[cpIndex] + File.pathSeparator + TestUtil.aspectjrtPath().getPath(); - args = newargs; - } - } - return args; - } + protected String[] fixupArgs(String[] args) { + if (null == args) { + return null; + } + int cpIndex = -1; + boolean hasruntime = false; + for (int i = 0; i < args.length - 1; i++) { + args[i] = adaptToPlatform(args[i]); + if ("-classpath".equals(args[i])) { + cpIndex = i; + args[i + 1] = substituteSandbox(args[i + 1]); + String next = args[i + 1]; + hasruntime = ((null != next) && (-1 != next.indexOf("aspectjrt.jar"))); + } + } + if (-1 == cpIndex) { + String[] newargs = new String[args.length + 2]; + newargs[0] = "-classpath"; + newargs[1] = TestUtil.aspectjrtPath().getPath(); + System.arraycopy(args, 0, newargs, 2, args.length); + args = newargs; + cpIndex = 1; + } else { + if (!hasruntime) { + cpIndex++; + String[] newargs = new String[args.length]; + System.arraycopy(args, 0, newargs, 0, args.length); + newargs[cpIndex] = args[cpIndex] + File.pathSeparator + TestUtil.aspectjrtPath().getPath(); + args = newargs; + } + } + boolean needsJRTFS = LangUtil.is19VMOrGreater(); + if (needsJRTFS) { + if (args[cpIndex].indexOf(LangUtil.JRT_FS) == -1) { + String jrtfsPath = LangUtil.getJrtFsFilePath(); + args[cpIndex] = jrtfsPath + File.pathSeparator + args[cpIndex]; + } + } + return args; +} private String adaptToPlatform(String s) { String ret = s.replace(';', File.pathSeparatorChar); diff --git a/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessSelectionTest.java b/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessSelectionTest.java index 9f50d0ff1..ac937ac44 100644 --- a/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessSelectionTest.java +++ b/testing-drivers/testsrc/org/aspectj/testing/drivers/HarnessSelectionTest.java @@ -18,6 +18,7 @@ import org.aspectj.bridge.MessageHandler; import org.aspectj.bridge.MessageUtil; import org.aspectj.testing.harness.bridge.AbstractRunSpec; import org.aspectj.testing.harness.bridge.AjcTest; +import org.aspectj.testing.harness.bridge.IRunSpec; import org.aspectj.testing.run.IRunStatus; import org.aspectj.testing.run.RunValidator; import org.aspectj.testing.util.BridgeUtil; @@ -298,7 +299,7 @@ public class HarnessSelectionTest extends TestCase { runtime.setOptions(options); AjcTest.Suite.Spec spec = getSpec(suiteFile); assertNotNull(spec); - ArrayList kids = spec.getChildren(); + ArrayList kids = spec.getChildren(); assertNotNull(kids); if ((suiteFile == SELECT) && (17 != kids.size())) { assertTrue("expected 17 kids, got " + kids.size(), false); diff --git a/testing/testsrc/org/aspectj/testing/taskdefs/AjcTaskCompileCommandTest.java b/testing/testsrc/org/aspectj/testing/taskdefs/AjcTaskCompileCommandTest.java index 6ab5a386b..42a2063a4 100644 --- a/testing/testsrc/org/aspectj/testing/taskdefs/AjcTaskCompileCommandTest.java +++ b/testing/testsrc/org/aspectj/testing/taskdefs/AjcTaskCompileCommandTest.java @@ -44,7 +44,12 @@ public class AjcTaskCompileCommandTest extends TestCase { list.add("-d"); list.add(getClassesDir().getAbsolutePath()); list.add("-classpath"); - list.add(Globals.F_aspectjrt_jar.getAbsolutePath()); + StringBuilder classpath = new StringBuilder(); + classpath.append(Globals.F_aspectjrt_jar.getAbsolutePath()); + if (LangUtil.is19VMOrGreater()) { + classpath.append(File.pathSeparator).append(LangUtil.getJrtFsFilePath()); + } + list.add(classpath.toString()); } static boolean doWait(IMessageHolder holder, int seconds, int timeout) { -- 2.39.5