Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to add ear lib to appclient classpath #1653

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
import java.util.logging.Logger;

/**
* A base class that uses the {@link Runtime#exec(String[], String[], File)} method to launch a Jakarta EE appclient.
* Vendors override this class to provide implementations of:
* {@link #getAppClientCommand()} - the command line expected to invoke your Application Client main
* {@link #getAppClientEnv()} - optional environment variables that should be provided when running the Application client
* {@link #getAppClientDir()} - optional directory from which the appclient process should run
* A class that uses the {@link Runtime#exec(String[], String[], File)} method to launch a Jakarta EE appclient.
* Vendors configure the appclient via the {@link AppClientProtocolConfiguration} class using the
* protocol element of the arquillian.xml file.
*/
public class AppClientCmd {
private static final Logger LOGGER = Logger.getLogger(AppClientCmd.class.getName());
Expand All @@ -47,6 +45,7 @@ public class AppClientCmd {
private String[] clientEnvp = null;
private File clientDir = null;
private String clientEarDir;
private String clientEarLibClasspath;
private CompletableFuture<Process> onExit;


Expand All @@ -59,6 +58,7 @@ public AppClientCmd(AppClientProtocolConfiguration config) {
clientEnvp = config.clientEnvAsArray();
clientDir = config.clientDirAsFile();
clientEarDir = config.getClientEarDir();
clientEarLibClasspath = config.clientEarLibClasspath();
}

public boolean waitForExit(long timeout, TimeUnit units) throws InterruptedException {
Expand Down Expand Up @@ -114,7 +114,6 @@ public void run(String vehicleArchiveName, String clientAppArchive, String... ad

ArrayList<String> cmdList = new ArrayList<String>();


// Need to replace any property refs on command line
File earDir = new File(clientEarDir);
if(earDir.isAbsolute()) {
Expand All @@ -135,21 +134,32 @@ public void run(String vehicleArchiveName, String clientAppArchive, String... ad
arg = arg.replaceAll("\\$\\{clientAppArchive}", clientAppArchive);
cmdLine[n] = arg;
}

if(arg.contains("${clientEarLibClasspath}")) {
arg = arg.replaceAll("\\$\\{clientEarLibClasspath}", clientEarLibClasspath);
cmdLine[n] = arg;
}
}
// Replace any ${clientEarLibClasspath} in the client ENV
for(int n = 0; n < clientEnvp.length; n++) {
String env = clientEnvp[n];
if(env.contains("${clientEarLibClasspath}")) {
String env2 = env.replaceAll("\\$\\{clientEarLibClasspath}", clientEarLibClasspath);
LOGGER.info("Replaced clientEarLibClasspath in "+env2);
clientEnvp[n] = env2;
}
}

// Split the command line into individual arguments based on spaces
for (int n = 0; n < cmdLine.length; n ++) {
String arg = cmdLine[n];
cmdList.addAll(Arrays.asList(cmdLine[n].split(" ")));
}

// Add any additional args
if (additionalArgs != null) {
String[] newCmdLine = new String[cmdLine.length + additionalArgs.length];
System.arraycopy(cmdLine, 0, newCmdLine, 0, cmdLine.length);
System.arraycopy(additionalArgs, 0, newCmdLine, cmdLine.length, additionalArgs.length);
cmdLine = newCmdLine;
cmdList.addAll(Arrays.asList(additionalArgs));

}

appClientProcess = Runtime.getRuntime().exec(cmdList.toArray(new String[0]), clientEnvp, clientDir);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tck.arquillian.protocol.appclient;

import org.jboss.arquillian.container.spi.client.deployment.Deployment;
import org.jboss.arquillian.container.test.spi.client.protocol.ProtocolConfiguration;
import tck.arquillian.protocol.common.ProtocolCommonConfig;

Expand Down Expand Up @@ -117,7 +118,12 @@ public String getClientCmdLineString() {
* the parsed command line array elements are trimmed of leading and trailing whitespace.
* The command line should be filtered against the ts.jte file if it contains any property references. In addition
* to ts.jte property references, the command line can contain ${clientEarDir} which will be replaced with the
* #clientEarDir value. Any ${vehicleArchiveName} ref will be replaced with the vehicleArchiveName passed to the
* #clientEarDir value. Any ${vehicleArchiveName} ref will be replaced with the vehicle archive name extracted by
* {@link tck.arquillian.protocol.common.TsTestPropsBuilder#vehicleArchiveName(Deployment)}.
* Any ${clientAppArchive} ref will be replaced with the clientAppArchive extracted by the
* {@link AppClientDeploymentPackager} processing of the target appclient ear.
* Any ${clientEarLibClasspath} ref will be replaced with the classpath of the client ear lib directory if
* {@link #unpackClientEar} is true and the clientEarDir/lib directory exists.
* @param clientCmdLineString
*/
public void setClientCmdLineString(String clientCmdLineString) {
Expand Down Expand Up @@ -146,6 +152,12 @@ public void setClientDir(String clientDir) {
public String getClientEarDir() {
return clientEarDir;
}
/**
* Set the directory to extract the final appclient ear test artifact. The default is "target/appclient".
* Any ${clientEarDir} ref in the {@link #clientCmdLineString} will be replaced with the clientEarDir
* value.
* @param clientEarDir
*/
public void setClientEarDir(String clientEarDir) {
this.clientEarDir = clientEarDir;
}
Expand Down Expand Up @@ -188,6 +200,26 @@ public File clientDirAsFile() {
return dir;
}

/**
* If #unpackClientEar is true, and clientEarDir/lib exists, then this method returns the contents
* of the clientEarDir/lib as a classpath string
* @return a classpath string for the client ear lib directory
*/
public String clientEarLibClasspath() {
StringBuilder cp = new StringBuilder();
File libDir = new File(clientEarDir, "lib");
if (unpackClientEar && libDir.exists()) {
File[] jars = libDir.listFiles();
for (File jar : jars) {
if (!cp.isEmpty()) {
cp.append(File.pathSeparator);
}
cp.append(jar.getAbsolutePath());
}
}
return cp.toString();
}

/**
* Parse the clientCmdLineString into an array of strings using the cmdLineArgSeparator. This calls String#split on the
* clientCmdLineString and then trims each element of the resulting array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class TsTestPropsBuilder {

/**
* Get the deployment vehicle archive name from the deployment archive. This needs to be a vehicle deployment
* for the result to be value.
* for the result to be valid.
* @param deployment - current test deployment
* @return base vehicle archive name
*/
Expand Down
6 changes: 3 additions & 3 deletions glassfish-runner/assembly-tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
<properties>
<arquillian.junit>1.9.1.Final</arquillian.junit>
<exec.asadmin>${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin</exec.asadmin>
<!-- Use JDK17 to run with GF 8.0.0-JDK17-M5 -->
<glassfish.version>8.0.0-JDK17-M7</glassfish.version>
<glassfish.home>${project.build.directory}/${glassfish.toplevel.dir}</glassfish.home>
<!-- Use JDK21 to run with GF 8.0.0-M5 -->
<!-- <glassfish.version>8.0.0-M5</glassfish.version> -->
<glassfish.toplevel.dir>glassfish8</glassfish.toplevel.dir>
<!-- Use JDK17 to run with GF 8.0.0-JDK17-M5 -->
<glassfish.version>8.0.0-JDK17-M7</glassfish.version>
<jakarta.platform.version>11.0.0-M2</jakarta.platform.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
<tck.artifactId>assembly-tck</tck.artifactId>
<tck.version>11.0.0-SNAPSHOT</tck.version>
<ts.home>./jakartaeetck</ts.home>
<version.jakarta.tck>11.0.0-SNAPSHOT</version.jakarta.tck>
<version.jakarta.tck.arquillian>1.0.0-M17</version.jakarta.tck.arquillian>
<version.jakarta.tck.arquillian>${project.version}</version.jakarta.tck.arquillian>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<!-- <property name="clientEnvString">PATH=${env.PATH};LD_LIBRARY_PATH=${glassfish.home}/lib;AS_DEBUG=true;
APPCPATH=${glassfish.home}/glassfish/lib/arquillian-protocol-lib.jar:${glassfish.home}/glassfish/lib/tck-porting-lib.jar:target/appclient/lib/arquillian-core.jar:target/appclient/lib/arquillian-junit5.jar:${glassfish.home}/glassfish/modules/security.jar</property> -->
<property name="clientEnvString">AS_JAVA=${env.JAVA_HOME};PATH=${env.PATH};LD_LIBRARY_PATH=${glassfish.home}/lib;AS_DEBUG=true;
APPCPATH=target/lib/libutil.jar:target/lib/arquillian-protocol-lib.jar:target/lib/tck-porting-lib.jar:target/appclient/lib/arquillian-core.jar:target/appclient/lib/arquillian-junit5.jar:${glassfish.home}/glassfish/modules/security.jar:${glassfish.home}/glassfish/lib/gf-client.jar</property>
APPCPATH=${clientEarLibClasspath}:target/lib/libutil.jar:target/lib/arquillian-protocol-lib.jar:target/lib/tck-porting-lib.jar:target/appclient/lib/arquillian-core.jar:target/appclient/lib/arquillian-junit5.jar:${glassfish.home}/glassfish/modules/security.jar:${glassfish.home}/glassfish/lib/gf-client.jar</property>
<property name="clientDir">${project.basedir}</property>
<property name="workDir">/tmp</property>
<property name="tsJteFile">jakartaeetck/bin/ts.jte</property>
Expand Down