diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/ConcurrencySignatureTestRunner.java b/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/ConcurrencySignatureTestRunner.java index 451a5813..6bdd6bb8 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/ConcurrencySignatureTestRunner.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/ConcurrencySignatureTestRunner.java @@ -113,7 +113,7 @@ protected String getClasspath() { // Get JDK modules from jimage // Add JDK classes to classpath - File jimageOutput = new File(getTestInfo().getJImageDir()); + File jimageOutput = new File(SigTestData.getJImageDir()); for (String module : jdkModules) { Path modulePath = Paths.get(jimageOutput.getAbsolutePath(), module); if (Files.isDirectory(modulePath)) { @@ -227,9 +227,9 @@ public void signatureTest() throws Fault { log.info("Exception while creating temp files :" + ex); } - String[] packagesUnderTest = getPackages(getTestInfo().getVehicle()); - String[] classesUnderTest = getClasses(getTestInfo().getVehicle()); - String optionalPkgToIgnore = getTestInfo().getOptionalTechPackagesToIgnore(); + String[] packagesUnderTest = getPackages(SigTestData.getVehicle()); + String[] classesUnderTest = getClasses(SigTestData.getVehicle()); + String optionalPkgToIgnore = SigTestData.getOptionalTechPackagesToIgnore(); // unlisted optional packages are technology packages for those optional // technologies (e.g. jsr-88) that might not have been specified by the @@ -243,7 +243,7 @@ public void signatureTest() throws Fault { Properties sysProps = System.getProperties(); String version = (String) sysProps.get("java.version"); if (!version.startsWith("1.")) { - String jimageDir = getTestInfo().getJImageDir(); + String jimageDir = SigTestData.getJImageDir(); File f = new File(jimageDir); f.mkdirs(); diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTest.java b/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTest.java index 686db173..191aca8f 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTest.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTest.java @@ -68,7 +68,7 @@ protected SignatureTestDriver getSigTestDriver() { * @return String The path and name of the package list file. */ protected String getPackageFile() { - return getSigTestDriver().getPackageFileImpl(testInfo.getBinDir()); + return getSigTestDriver().getPackageFileImpl(SigTestData.getBinDir()); } /** @@ -85,7 +85,7 @@ protected String getPackageFile() { * @return String The path and name of the signature map file. */ protected String getMapFile() { - return getSigTestDriver().getMapFileImpl(testInfo.getBinDir()); + return getSigTestDriver().getMapFileImpl(SigTestData.getBinDir()); } /** @@ -98,7 +98,7 @@ protected String getMapFile() { * @return String The signature repository directory. */ protected String getRepositoryDir() { - return getSigTestDriver().getRepositoryDirImpl(testInfo.getTSHome()); + return getSigTestDriver().getRepositoryDirImpl(SigTestData.getTSHome()); } /** @@ -155,8 +155,6 @@ protected String[] getClasses() { } // END getClasses - private SigTestData testInfo; // holds the bin.dir property - /** * Called by the test framework to initialize this test. The method simply * retrieves some state information that is necessary to run the test when when @@ -168,7 +166,6 @@ protected String[] getClasses() { public void setup() { try { System.out.println("$$$ SigTest.setup() called"); - this.testInfo = new SigTestData(); System.out.println("$$$ SigTest.setup() complete"); } catch (Exception e) { System.out.println("Unexpected exception " + e.getMessage()); diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTestData.java b/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTestData.java index 36e8d351..f386aa3b 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTestData.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTestData.java @@ -27,51 +27,51 @@ * setup phase. This allows us to keep the passed data separate and reuse the * data between the signature test framework base classes. */ -public class SigTestData { +public final class SigTestData { - private Properties props; - - public SigTestData() { - this.props = System.getProperties(); + private SigTestData() { + // Helper class } - public String getVehicle() { + private static Properties props = System.getProperties(); + + public static String getVehicle() { return props.getProperty("vehicle", ""); } - public String getBinDir() { + public static String getBinDir() { return props.getProperty("bin.dir", ""); } - public String getTSHome() { + public static String getTSHome() { return props.getProperty("ts_home", ""); } - public String getTestClasspath() { + public static String getTestClasspath() { return props.getProperty("sigTestClasspath", ""); } - public String getJavaeeLevel() { + public static String getJavaeeLevel() { return props.getProperty("javaee.level", ""); } - public String getCurrentKeywords() { + public static String getCurrentKeywords() { return props.getProperty("current.keywords", ""); } - public String getProperty(final String prop) { + public static String getProperty(final String prop) { return props.getProperty(prop); } - public String getOptionalTechPackagesToIgnore() { + public static String getOptionalTechPackagesToIgnore() { return props.getProperty("optional.tech.packages.to.ignore", ""); } - public String getJtaJarClasspath() { + public static String getJtaJarClasspath() { return props.getProperty("jtaJarClasspath", ""); } - public String getJImageDir() { + public static String getJImageDir() { return props.getProperty("jimage.dir", ""); } } // end class SigTestData diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTestEE.java b/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTestEE.java index e2ef3813..bc01aee9 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTestEE.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/common/signature/SigTestEE.java @@ -67,7 +67,7 @@ protected SignatureTestDriver getSigTestDriver() { * @return String The path and name of the package list file. */ protected String getPackageFile() { - return getSigTestDriver().getPackageFileImpl(testInfo.getBinDir()); + return getSigTestDriver().getPackageFileImpl(SigTestData.getBinDir()); } /** @@ -84,7 +84,7 @@ protected String getPackageFile() { * @return String The path and name of the signature map file. */ protected String getMapFile() { - return getSigTestDriver().getMapFileImpl(testInfo.getBinDir()); + return getSigTestDriver().getMapFileImpl(SigTestData.getBinDir()); } /** @@ -97,7 +97,7 @@ protected String getMapFile() { * @return String The signature repository directory. */ protected String getRepositoryDir() { - return getSigTestDriver().getRepositoryDirImpl(testInfo.getTSHome()); + return getSigTestDriver().getRepositoryDirImpl(SigTestData.getTSHome()); } /** @@ -182,8 +182,6 @@ protected String[] getClasses(final String vehicleName) { } // END getClasses - private SigTestData testInfo; // holds the bin.dir and vehicle properties - /** * Called by the test framework to initialize this test. The method simply * retrieves some state information that is necessary to run the test when when @@ -192,21 +190,12 @@ protected String[] getClasses(final String vehicleName) { public void setup() { try { System.out.println("$$$ SigTestEE.setup() called"); - this.testInfo = new SigTestData(); System.out.println("$$$ SigTestEE.setup() complete"); } catch (Exception e) { System.out.println("Unexpected exception " + e.getMessage()); } } - protected SigTestData getTestInfo() { - if (testInfo == null) { - setup(); - } - - return testInfo; - } - /** * Called by the test framework to run this test. This method utilizes the state * information set in the setup method to run the signature tests. All signature @@ -220,11 +209,11 @@ public void signatureTest() throws Fault { SigTestResult results = null; String mapFile = getMapFile(); String repositoryDir = getRepositoryDir(); - String[] packages = getPackages(testInfo.getVehicle()); - String[] classes = getClasses(testInfo.getVehicle()); + String[] packages = getPackages(SigTestData.getVehicle()); + String[] classes = getClasses(SigTestData.getVehicle()); String packageFile = getPackageFile(); - String testClasspath = testInfo.getTestClasspath(); - String optionalPkgToIgnore = testInfo.getOptionalTechPackagesToIgnore(); + String testClasspath = SigTestData.getTestClasspath(); + String optionalPkgToIgnore = SigTestData.getOptionalTechPackagesToIgnore(); // unlisted optional packages are technology packages for those optional // technologies (e.g. jsr-88) that might not have been specified by the @@ -238,7 +227,7 @@ public void signatureTest() throws Fault { Properties sysProps = System.getProperties(); String version = (String) sysProps.get("java.version"); if (!version.startsWith("1.")) { - String jimageDir = testInfo.getJImageDir(); + String jimageDir = SigTestData.getJImageDir(); File f = new File(jimageDir); f.mkdirs(); diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKArchiveProcessor.java b/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKArchiveProcessor.java index ccb468d1..bb63d448 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKArchiveProcessor.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKArchiveProcessor.java @@ -15,6 +15,7 @@ */ package ee.jakarta.tck.concurrent.framework.arquillian.extensions; +import java.util.Arrays; import java.util.List; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -24,11 +25,14 @@ import org.jboss.arquillian.test.spi.TestClass; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.container.ClassContainer; +import org.jboss.shrinkwrap.api.container.ResourceContainer; import org.jboss.shrinkwrap.api.spec.EnterpriseArchive; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.jboss.shrinkwrap.api.spec.WebArchive; +import ee.jakarta.tck.concurrent.common.signature.ConcurrencySignatureTestRunner; import ee.jakarta.tck.concurrent.framework.junit.anno.Common; +import ee.jakarta.tck.concurrent.framework.junit.anno.Signature; /** * This extension will intercept archives before they are deployed to the @@ -39,9 +43,16 @@ public class TCKArchiveProcessor implements ApplicationArchiveProcessor { @Override public void process(final Archive applicationArchive, final TestClass testClass) { - String applicationName = applicationArchive.getName() == null ? applicationArchive.getId() + String applicationName = applicationArchive.getName() == null + ? applicationArchive.getId() : applicationArchive.getName(); + + appendCommonPackages(applicationArchive, testClass, applicationName); + appendSignaturePackages(applicationArchive, testClass, applicationName); + } + + private static void appendCommonPackages(final Archive applicationArchive, final TestClass testClass, final String applicationName) { if (!testClass.isAnnotationPresent(Common.class)) { return; } @@ -59,6 +70,33 @@ public void process(final Archive applicationArchive, final TestClass testCla packages.stream().forEach(pkg -> ((ClassContainer) applicationArchive).addPackage(pkg)); } + } + + private static void appendSignaturePackages(final Archive applicationArchive, final TestClass testClass, final String applicationName) { + + if (!testClass.isAnnotationPresent(Signature.class)) { + return; + } + + final boolean isJava21orAbove = Integer.parseInt(System.getProperty("java.specification.version")) >= 21; + final Package signaturePackage = ConcurrencySignatureTestRunner.class.getPackage(); + if (applicationArchive instanceof ClassContainer) { + log.info("Application Archive [" + applicationName + "] is being appended with packages [" + + signaturePackage + ", com.sun.tdk, org.netbeans.apitest]"); + log.info("Application Archive [" + applicationName + "] is being appended with resources " + + Arrays.asList(ConcurrencySignatureTestRunner.SIG_RESOURCES)); + ((ClassContainer) applicationArchive).addPackage(signaturePackage); + // These are the packages from the sig-test plugin that are needed to run the test. + ((ClassContainer) applicationArchive).addPackages(true, "com.sun.tdk", "org.netbeans.apitest"); + ((ResourceContainer) applicationArchive).addAsResources(signaturePackage, + ConcurrencySignatureTestRunner.SIG_MAP_NAME, ConcurrencySignatureTestRunner.SIG_PKG_NAME); + ((ResourceContainer) applicationArchive).addAsResource(signaturePackage, + // Get local resource based on JDK level + isJava21orAbove ? ConcurrencySignatureTestRunner.SIG_FILE_NAME + "_21" + : ConcurrencySignatureTestRunner.SIG_FILE_NAME + "_17", + // Target same package as test + signaturePackage.getName().replace(".", "/") + "/" + ConcurrencySignatureTestRunner.SIG_FILE_NAME); + } } } diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKLoadableExtension.java b/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKLoadableExtension.java index c83067fa..7c387efa 100644 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKLoadableExtension.java +++ b/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKLoadableExtension.java @@ -27,7 +27,6 @@ public class TCKLoadableExtension implements LoadableExtension { @Override public void register(final ExtensionBuilder builder) { builder.service(ApplicationArchiveProcessor.class, TCKArchiveProcessor.class); - builder.service(ApplicationArchiveProcessor.class, TCKSignatureProcessor.class); builder.service(AuxiliaryArchiveAppender.class, TCKFrameworkAppender.class); } } diff --git a/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKSignatureProcessor.java b/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKSignatureProcessor.java deleted file mode 100644 index f2aa28eb..00000000 --- a/tck/src/main/java/ee/jakarta/tck/concurrent/framework/arquillian/extensions/TCKSignatureProcessor.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ -package ee.jakarta.tck.concurrent.framework.arquillian.extensions; - -import java.util.Arrays; -import java.util.logging.Logger; - -import org.jboss.arquillian.container.test.spi.client.deployment.ApplicationArchiveProcessor; -import org.jboss.arquillian.test.spi.TestClass; -import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.container.ClassContainer; -import org.jboss.shrinkwrap.api.container.ResourceContainer; - -import ee.jakarta.tck.concurrent.common.signature.ConcurrencySignatureTestRunner; -import ee.jakarta.tck.concurrent.framework.junit.anno.Full; -import ee.jakarta.tck.concurrent.framework.junit.anno.Signature; - -/** - * This extension will intercept archives before they are deployed to the - * container and append the signature files. - */ -public class TCKSignatureProcessor implements ApplicationArchiveProcessor { - private static final Logger log = Logger.getLogger(TCKSignatureProcessor.class.getCanonicalName()); - - private static final Package signaturePackage = ConcurrencySignatureTestRunner.class.getPackage(); - - @Override - public void process(final Archive applicationArchive, final TestClass testClass) { - String applicationName = applicationArchive.getName() == null ? applicationArchive.getId() - : applicationArchive.getName(); - - if (!testClass.isAnnotationPresent(Signature.class)) { - return; - } - - if (testClass.isAnnotationPresent(Full.class)) { - throw new RuntimeException("Signature tests must be run using the @Web annotation"); - } - - boolean isJava21orAbove = Integer.parseInt(System.getProperty("java.specification.version")) >= 21; - - if (applicationArchive instanceof ClassContainer) { - log.info("Application Archive [" + applicationName + "] is being appended with packages [" - + signaturePackage + "]"); - log.info("Application Archive [" + applicationName + "] is being appended with resources " - + Arrays.asList(ConcurrencySignatureTestRunner.SIG_RESOURCES)); - ((ClassContainer) applicationArchive).addPackage(signaturePackage); - ((ResourceContainer) applicationArchive).addAsResources(signaturePackage, - ConcurrencySignatureTestRunner.SIG_MAP_NAME, ConcurrencySignatureTestRunner.SIG_PKG_NAME); - ((ResourceContainer) applicationArchive).addAsResource(signaturePackage, - // Get local resource based on JDK level - isJava21orAbove ? ConcurrencySignatureTestRunner.SIG_FILE_NAME + "_21" - : ConcurrencySignatureTestRunner.SIG_FILE_NAME + "_17", - // Target same package as test - signaturePackage.getName().replace(".", "/") + "/" + ConcurrencySignatureTestRunner.SIG_FILE_NAME); - } - - } -}