Skip to content

Commit

Permalink
Remove -testJDKHome argument (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Feb 7, 2023
1 parent 6a1f927 commit 2d0bdae
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 142 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ demo: target/plugins-compat-tester-cli.jar $(WAR_PATH) print-java-home
-workDirectory $(CURDIR)/work \
-mvn $(MVN_EXECUTABLE) \
-war $(CURDIR)/$(WAR_PATH) \
-testJDKHome "$(TEST_JDK_HOME)" \
-includePlugins $(PLUGIN_NAME) \
$(EXTRA_OPTS)

Expand Down
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ java -jar target/plugins-compat-tester-cli.jar \

### Running PCT with custom Java versions

Plugin compat tester supports running Test Suites with a Java version different
from the one being used to run PCT and build the plugins.
For example, such mode can be used to run tests with JDK11 starting from Jenkins 2.163.

Two options can be passed to PCT CLI for such purpose:

* `testJDKHome` - A path to JDK HOME to be used for running tests in plugins

You can run the example by running the following command:

make demo TEST_JDK_HOME=${YOUR_JDK_HOME} PLUGIN_NAME=git
Expand Down
1 change: 0 additions & 1 deletion src/main/docker/run-pct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ echo java ${JAVA_OPTS} ${extra_java_opts[@]} \
${LOCAL_CHECKOUT_ARG} \
-includePlugins "${ARTIFACT_ID}" \
-m2SettingsFile "${MVN_SETTINGS_FILE}" \
-testJDKHome "${TEST_JDK_HOME}" \
"$@" \
"|| echo \$? > /pct/tmp/pct_exit_code" > /pct/tmp/pct_command
chmod +x /pct/tmp/pct_command
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/jenkins/tools/test/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ public class CliOptions {
"A WAR file to scan for plugins rather than looking in the update center.")
private File war;

@CheckForNull
@Parameter(
names = "-testJDKHome",
description = "A path to JDK HOME to be used for running tests in plugins.")
private File testJDKHome;

@Parameter(
names = "-workDirectory",
required = true,
Expand Down Expand Up @@ -218,11 +212,6 @@ public boolean isPrintHelp() {
return printHelp;
}

@CheckForNull
public File getTestJDKHome() {
return testJDKHome;
}

public boolean isFailFast() {
return failFast;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ public static void main(String[] args) throws PluginCompatibilityTesterException
if (options.getLocalCheckoutDir() != null && !options.getLocalCheckoutDir().isEmpty()) {
config.setLocalCheckoutDir(options.getLocalCheckoutDir());
}
if (options.getTestJDKHome() != null) {
config.setTestJDKHome(options.getTestJDKHome());
}
if (options.getFallbackGitHubOrganization() != null) {
config.setFallbackGitHubOrganization(options.getFallbackGitHubOrganization());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jenkins.tools.test.util.StreamGobbler;

/**
* POJO used to configure Plugin Compatibility Tester execution
Expand All @@ -61,9 +59,6 @@ public class PluginCompatTesterConfig {
// The megawar
private File war;

/** A Java HOME to be used for running tests in plugins. */
@CheckForNull private File testJDKHome;

@CheckForNull private File externalMaven;

// List of plugin artifact ids on which tests will be performed
Expand Down Expand Up @@ -132,11 +127,6 @@ public File getM2SettingsFile() {
return m2SettingsFile;
}

@CheckForNull
public File getTestJDKHome() {
return testJDKHome;
}

public List<String> getExcludePlugins() {
return excludePlugins;
}
Expand Down Expand Up @@ -219,108 +209,9 @@ public Map<String, String> retrieveMavenProperties() throws IOException {
}
}

// Read other explicit CLI arguments

// Override JDK if passed explicitly
if (testJDKHome != null) {
if (!testJDKHome.exists() || !testJDKHome.isDirectory()) {
throw new IOException("Wrong Test JDK Home passed as a parameter: " + testJDKHome);
}

if (res.containsKey("jvm")) {
LOGGER.log(
Level.WARNING,
"Maven properties already contain the 'jvm' argument; "
+ "overriding the previous test JDK home value '"
+ res.get("jvm")
+ "' by the explicit argument: "
+ testJDKHome);
} else {
LOGGER.log(Level.INFO, "Using custom test JDK home: {0}", testJDKHome);
}
final String javaCmdAbsolutePath = getTestJavaCommandPath();
res.put("jvm", javaCmdAbsolutePath);
}

return res;
}

@CheckForNull
private String getTestJavaCommandPath() {
if (testJDKHome == null) {
return null;
}
return new File(testJDKHome, "bin/java").getAbsolutePath();
}

/**
* Gets the Java version used for testing, using the binary path to the <code>java</code>
* command.
*
* @return a string identifying the jvm in use
*/
public String getTestJavaVersion() throws IOException {
String javaCmdAbsolutePath = getTestJavaCommandPath();
if (javaCmdAbsolutePath == null) {
LOGGER.log(Level.INFO, "Test JDK home unset; using Java from PATH");
javaCmdAbsolutePath = "java";
}
final Process process =
new ProcessBuilder()
.command(javaCmdAbsolutePath, "-XshowSettings:properties", "-version")
.redirectErrorStream(true)
.start();
StreamGobbler gobbler = new StreamGobbler(process.getInputStream());
gobbler.start();
try {
int exitStatus = process.waitFor();
gobbler.join();
if (exitStatus != 0) {
throw new IOException(
"java -XshowSettings:properties -version failed with exit status "
+ exitStatus
+ ": "
+ gobbler.getOutput().trim());
}
} catch (InterruptedException e) {
throw new IOException("interrupted while getting Java version", e);
}
final String javaVersionOutput = gobbler.getOutput().trim();
final String[] lines = javaVersionOutput.split("[\\r\\n]+");
for (String line : lines) {
String trimmed = line.trim();
if (trimmed.contains("java.specification.version")) {
// java.specification.version = version
return trimmed.split("=")[1].trim();
}
}
// Default to fullversion output as before
final Process process2 =
new ProcessBuilder()
.command(javaCmdAbsolutePath, "-fullversion")
.redirectErrorStream(true)
.start();
StreamGobbler gobbler2 = new StreamGobbler(process2.getInputStream());
gobbler2.start();
try {
int exitStatus2 = process2.waitFor();
gobbler2.join();
if (exitStatus2 != 0) {
throw new IOException(
"java -fullversion failed with exit status "
+ exitStatus2
+ ": "
+ gobbler2.getOutput().trim());
}
} catch (InterruptedException e) {
throw new IOException("interrupted while getting full Java version", e);
}
final String javaVersionOutput2 = gobbler2.getOutput().trim();
// Expected format is something like openjdk full version "1.8.0_181-8u181-b13-2~deb9u1-b13"
// We shorten it by removing the "full version" in the middle
return javaVersionOutput2.replace(" full version ", " ").replaceAll("\"", "");
}

public File getWar() {
return war;
}
Expand Down Expand Up @@ -355,15 +246,6 @@ public void setExternalHooksJars(List<File> externalHooksJars) {
this.externalHooksJars = externalHooksJars;
}

/**
* Sets JDK Home for tests
*
* @param testJDKHome JDK home to be used. {@code null} for using default system one.
*/
public void setTestJDKHome(@CheckForNull File testJDKHome) {
this.testJDKHome = testJDKHome;
}

public File getLocalCheckoutDir() {
return localCheckoutDir;
}
Expand Down

0 comments on commit 2d0bdae

Please sign in to comment.