From 0e7ac59f24f449d6d54d31634075f9bffcb57588 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Fri, 16 Apr 2021 13:52:07 +0700 Subject: [PATCH] Remove some cruft from test classes Ajc, AjcTestCase, AntSpec Signed-off-by: Alexander Kriegisch --- .../test/java/org/aspectj/tools/ajc/Ajc.java | 64 ++++--------------- .../org/aspectj/tools/ajc/AjcTestCase.java | 9 --- .../java/org/aspectj/testing/AntSpec.java | 46 ++++++------- 3 files changed, 32 insertions(+), 87 deletions(-) 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 138e6538c..b6abb38ab 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 @@ -51,64 +51,28 @@ 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"; + return File.pathSeparator + ".." +File.separator + module + File.separator + BUILD_OUTPUT_FOLDER + File.separator + "classes"; } public static final String outputFolders(String... modules) { StringBuilder s = new StringBuilder(); for (String module: modules) { - s.append(File.pathSeparator + ".." +File.separator + module + File.separator + "target" + File.separator + "classes"); + s.append(File.pathSeparator + ".." +File.separator + module + File.separator + BUILD_OUTPUT_FOLDER + File.separator + "classes"); } 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 + "lib" + File.separator + "junit" + File.separator + "junit.jar" + + outputFolder("bridge") + + outputFolder("loadtime") + + outputFolder("weaver") + + outputFolder("org.aspectj.matcher") + + outputFolder("bridge"); private CompilationResult result; private File sandbox; @@ -238,8 +202,8 @@ public class Ajc { addMessagesTo(errors, holder.getErrors()); addMessagesTo(fails, holder.getMessages(IMessage.FAIL, true)); addMessagesTo(weaves, holder.getMessages(IMessage.WEAVEINFO, false)); - String stdOut = new String(out.toByteArray()); - String stdErr = new String(err.toByteArray()); + String stdOut = out.toString(); + String stdErr = err.toString(); result = new CompilationResult(args, stdOut, stdErr, infos, errors, warnings, fails, weaves); } finally { System.setOut(systemOut); 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 e13f9e224..6a93731a5 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 @@ -77,15 +77,6 @@ public abstract class AjcTestCase extends TestCase { + 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" + File.pathSeparator + CLASSPATH_ASM_RENAMED - // When the build machine executes the tests, it is using code built into jars rather than code build into - // target/classes 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 + "util.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 + "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.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" diff --git a/testing/src/test/java/org/aspectj/testing/AntSpec.java b/testing/src/test/java/org/aspectj/testing/AntSpec.java index b87f60894..f3bf7cc44 100644 --- a/testing/src/test/java/org/aspectj/testing/AntSpec.java +++ b/testing/src/test/java/org/aspectj/testing/AntSpec.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 - * + * 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: * Alexandre Vasseur initial implementation *******************************************************************************/ @@ -53,29 +53,23 @@ import static org.aspectj.util.LangUtil.is16VMOrGreater; * Element {@code } and {@code } can be used. For now, a full match is * performed on the output of the runned target only (not the whole Ant invocation). This is experimental and you are * advised to use a {@code } task instead or a {@code } whose main throws some exception upon failure. - * + * * @author Alexandre Vasseur */ public class AntSpec implements ITestStep { - - public static final String outputFolders(String... modules) { + public static String outputFolders(String... modules) { StringBuilder s = new StringBuilder(); for (String module: modules) { s.append(File.pathSeparator + ".." +File.separator + module + File.separator + "target" + File.separator + "classes"); } return s.toString(); } - - + + // ALSO SEE AJC private final static String DEFAULT_LTW_CLASSPATH_ENTRIES = outputFolders("asm", "bridge", "loadtime", "weaver", "org.aspectj.matcher", "bcel-builder"); -// private final static String DEFAULT_LTW_CLASSPATH_ENTRIES = ".." + File.separator + "asm/bin" + File.pathSeparator + ".." -// + File.separator + "bridge/bin" + File.pathSeparator + ".." + File.separator + "loadtime/bin" + File.pathSeparator -// + ".." + File.separator + "loadtime5/bin" + File.pathSeparator + ".." + File.separator + "weaver/bin" -// + File.pathSeparator + ".." + File.separator + "org.aspectj.matcher/bin" + File.pathSeparator + ".." + File.separator -// + "lib/bcel/bcel.jar" + File.pathSeparator + ".." + File.separator + "lib/bcel/bcel-verifier.jar";; private boolean m_verbose = false; private AjcTest m_ajcTest; @@ -107,9 +101,9 @@ public class AntSpec implements ITestStep { // On Java 16+, LTW no longer works without this parameter. Add the argument here and not in AjcTestCase::run, // because even if 'useLTW' and 'useFullLTW' are not set, we might in the future have tests for weaver attachment // during runtime. See also docs/dist/doc/README-187.html. - // + // // Attention: Ant 1.6.3 under Linux neither likes "" (empty string) nor " " (space), on Windows it would not be - // a problem. So we use "_dummy" Java system properties, even though they pollute the command line. + // a problem. So we use "_dummy" Java system properties, even though they pollute the command line. p.setUserProperty("aj.addOpensKey", is16VMOrGreater() ? "--add-opens" : "-D_dummy"); p.setUserProperty("aj.addOpensValue", is16VMOrGreater() ? "java.base/java.lang=ALL-UNNAMED" : "-D_dummy"); @@ -164,18 +158,14 @@ public class AntSpec implements ITestStep { fr.close(); } } catch (Exception e) { - System.out.println("Exception whilst loading forked java task output " + e.getMessage() + "\n"); + String exceptionMessage = "Exception whilst loading forked java task output " + e.getMessage() + "\n"; + System.out.println(exceptionMessage); e.printStackTrace(); - stdout.append("Exception whilst loading forked java task output " + e.getMessage() + "\n"); + stdout.append(exceptionMessage); } - StringBuffer message = new StringBuffer(); - message.append(event.getException().toString()).append("\n"); - message.append(verboseLog); - message.append(stdout); - message.append(stderr); // AjcTestCase.fail(failMessage + "failure " + event.getException()); - AjcTestCase.fail(message.toString()); + AjcTestCase.fail(event.getException() + "\n" + verboseLog + stdout + stderr); } } @@ -239,7 +229,7 @@ public class AntSpec implements ITestStep { // WARNING: Please consider reporting this to the maintainers of org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor // WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations // WARNING: All illegal access operations will be denied in a future release - + stderr2 = stderr2.replaceAll("WARNING: An illegal reflective access operation has occurred\n",""); stderr2 = stderr2.replaceAll("WARNING: Illegal reflective access using Lookup on org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor[^\n]*\n",""); stderr2 = stderr2.replaceAll("WARNING: Please consider reporting this to the maintainers of org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor\n",""); @@ -266,7 +256,7 @@ public class AntSpec implements ITestStep { } public void setVerbose(String verbose) { - if (verbose != null && "true".equalsIgnoreCase(verbose)) { + if ("true".equalsIgnoreCase(verbose)) { m_verbose = true; } } -- 2.39.5