Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Feb 14, 2023
1 parent 1280538 commit 4c5608c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ print-java-home:
.PHONY: demo
demo: target/plugins-compat-tester-cli.jar $(WAR_PATH) print-java-home
java -jar target/plugins-compat-tester-cli.jar \
-workDirectory $(CURDIR)/work \
-mvn $(MVN_EXECUTABLE) \
-war $(CURDIR)/$(WAR_PATH) \
-includePlugins $(PLUGIN_NAME) \
--working-dir $(CURDIR)/work \
--mvn $(MVN_EXECUTABLE) \
--war $(CURDIR)/$(WAR_PATH) \
--include-plugins $(PLUGIN_NAME) \
$(EXTRA_OPTS)

# We do not automatically rebuild Docker here
Expand Down
24 changes: 6 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ The PCT cli supports to pass a war file containing plugins (generated with Custo
the plugins is infered from the war file contents.

In such scenarios is tipical to want to run the PCT for all plugins contained in the war file, to avoid having to spawn a new docker container for each plugin
you can use the env variables `DO_NOT_OVERRIDE_PCT_CHECKOUT=true` and `FAIL_ON_ERROR=false` to let the PCT CLI (instead of the `run-pct` script) checkout the proper
you can use the env variables `DO_NOT_OVERRIDE_PCT_CHECKOUT=true` to let the PCT CLI (instead of the `run-pct` script) checkout the proper
versions of the plugins and make sure the PCT does not stop before testing all plugins.

By using those env variables you can pass a comma separated list of plugins ids using the `ARTIFACT_ID` env variable

```shell
docker run -ti --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -v my/jenkins.war:/pct/jenkins.war:ro -e ARTIFACT_ID=ssh-slaves,credentials -e DO_NOT_OVERRIDE_PCT_CHECKOUT=true -e FAIL_ON_ERROR=false jenkins/pct
docker run -ti --rm -v maven-repo:/root/.m2 -v $(pwd)/out:/pct/out -v my/jenkins.war:/pct/jenkins.war:ro -e ARTIFACT_ID=ssh-slaves,credentials -e DO_NOT_OVERRIDE_PCT_CHECKOUT=true -e jenkins/pct
```

#### Configuration
Expand Down Expand Up @@ -97,28 +97,16 @@ PCT offers the CLI interface which can be used to run PCT locally.

```shell
java -jar target/plugins-compat-tester-cli.jar \
-workDirectory $(pwd)/tmp/work \
-includePlugins ${PLUGIN_ARTIFACT_ID} \
-war jenkins.war -localCheckoutDir ${PLUGIN_SRC} \
-mvn ${PATH_TO_MAVEN}
--working-dir $(pwd)/tmp/work \
--include-plugins ${PLUGIN_ARTIFACT_ID} \
--war jenkins.war --local-checkout-dir ${PLUGIN_SRC} \
--mvn ${PATH_TO_MAVEN}
```

You can run the CLI with the `-help` argument to get a full list of supported options.

:exclamation: For the moment testing more than one plugin at once requires plugins to be released, so for testing SNAPSHOTS you need to execute the last step for every plugin you want to test*

### Running PCT with a BOM file

Plugin Compat Tester supports running test suites using a BOM file as source of truth as follows:

```shell
java -jar target/plugins-compat-tester-cli.jar \
-workDirectory $(pwd)/tmp/work \
-includePlugins ${PLUGIN_ARTIFACT_ID} \
-bom ${BOM_FILE_LOCATION} \
-mvn ${PATH_TO_MAVEN}
```

### Running PCT with custom Java versions

You can run the example by running the following command:
Expand Down
9 changes: 4 additions & 5 deletions src/main/docker/run-pct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ if [ "${SHOULD_CHECKOUT}" -eq 1 ] && [ -z "${DO_NOT_OVERRIDE_PCT_CHECKOUT}" ] ;
mvn -B clean -s "${MVN_SETTINGS_FILE}"
fi
mv "${TMP_CHECKOUT_DIR}" "${PCT_TMP}/localCheckoutDir/${ARTIFACT_ID}"
LOCAL_CHECKOUT_ARG="-localCheckoutDir ${PCT_TMP}/localCheckoutDir/${ARTIFACT_ID}"
LOCAL_CHECKOUT_ARG="--local-checkout-dir ${PCT_TMP}/localCheckoutDir/${ARTIFACT_ID}"
fi


Expand All @@ -157,11 +157,10 @@ fi
pctExitCode=0
echo java ${JAVA_OPTS} ${extra_java_opts[@]} \
-jar /pct/pct-cli.jar \
-workDirectory "${PCT_TMP}/work" ${WAR_PATH_OPT} \
${FAIL_ON_ERROR_ARG}\
--working-dir "${PCT_TMP}/work" ${WAR_PATH_OPT} \
${LOCAL_CHECKOUT_ARG} \
-includePlugins "${ARTIFACT_ID}" \
-m2SettingsFile "${MVN_SETTINGS_FILE}" \
--include-plugins "${ARTIFACT_ID}" \
--maven-settings "${MVN_SETTINGS_FILE}" \
"$@" \
"|| echo \$? > /pct/tmp/pct_exit_code" > /pct/tmp/pct_command
chmod +x /pct/tmp/pct_command
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jenkins/tools/test/PluginCompatTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public PluginCompatTester(PluginCompatTesterConfig config) {
this.config = config;
runner =
new ExternalMavenRunner(
config.getExternalMaven(), config.getM2Settings(), config.getMavenArgs());
config.getExternalMaven(), config.getMavenSettings(), config.getMavenArgs());
}

public void testPlugins() throws PluginCompatibilityTesterException {
Expand Down Expand Up @@ -138,13 +138,13 @@ && localCheckoutProvided()
PluginCompatibilityTesterException lastException = null;
LOGGER.log(Level.INFO, "Starting plugin tests on core coordinates {0}", coreCoordinates);
for (UpdateSite.Plugin plugin : data.plugins.values()) {
if (config.getIncludePlugins() != null
if (!config.getIncludePlugins().isEmpty()
&& !config.getIncludePlugins().contains(plugin.name.toLowerCase())) {
LOGGER.log(Level.FINE, "Plugin {0} not in included plugins; skipping", plugin.name);
continue;
}

if (config.getExcludePlugins() != null
if (!config.getExcludePlugins().isEmpty()
&& config.getExcludePlugins().contains(plugin.name.toLowerCase())) {
LOGGER.log(Level.INFO, "Plugin {0} in excluded plugins; skipping", plugin.name);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class PluginCompatTesterCli implements Callable<Integer> {
@CommandLine.Option(
names = "--maven-settings",
description = "Settings file to use when executing Maven.")
private File m2Settings;
private File mavenSettings;

@CheckForNull
@CommandLine.Option(
Expand Down Expand Up @@ -182,7 +182,7 @@ public Integer call() throws PluginCompatibilityTesterException {
}
config.setFallbackGitHubOrganization(fallbackGitHubOrganization);
config.setExternalMaven(externalMaven);
config.setM2Settings(m2Settings);
config.setMavenSettings(mavenSettings);
if (mavenProperties != null) {
config.setMavenProperties(mavenProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@ public Map<String, Object> action(Map<String, Object> moreInfo) throws PomExecut

runner =
new ExternalMavenRunner(
config.getExternalMaven(), config.getM2Settings(), config.getMavenArgs());
config.getExternalMaven(), config.getMavenSettings(), config.getMavenArgs());

File pluginDir = (File) moreInfo.get("pluginDir");
LOGGER.log(Level.INFO, "Plugin dir is {0}", pluginDir);

File localCheckoutDir = config.getLocalCheckoutDir();
if (localCheckoutDir != null) {
Path pluginSourcesDir = localCheckoutDir.toPath();
boolean isMultipleLocalPlugins =
config.getIncludePlugins() != null && config.getIncludePlugins().size() > 1;
boolean isMultipleLocalPlugins = config.getIncludePlugins().size() > 1;
// We are running for local changes, let's copy the .eslintrc file if we can. If we
// are using localCheckoutDir with multiple plugins the .eslintrc must be located at
// the top level. If not it must be located on the parent of the localCheckoutDir.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ExternalMavenRunner implements MavenRunner {

@CheckForNull private final File externalMaven;

@CheckForNull private final File m2Settings;
@CheckForNull private final File mavenSettings;

@NonNull private final List<String> mavenArgs;

Expand All @@ -42,10 +42,10 @@ public class ExternalMavenRunner implements MavenRunner {
*/
public ExternalMavenRunner(
@CheckForNull File externalMaven,
@CheckForNull File m2Settings,
@CheckForNull File mavenSettings,
@NonNull List<String> mavenArgs) {
this.externalMaven = externalMaven;
this.m2Settings = m2Settings;
this.mavenSettings = mavenSettings;
this.mavenArgs = mavenArgs;
}

Expand All @@ -63,9 +63,9 @@ public void run(
cmd.add("-V"); // --show-version
cmd.add("-e"); // --errors
cmd.add("-ntp"); // --no-transfer-progress
if (m2Settings != null) {
if (mavenSettings != null) {
cmd.add("-s");
cmd.add(m2Settings.toString());
cmd.add(mavenSettings.toString());
}
for (Map.Entry<String, String> entry : properties.entrySet()) {
cmd.add("-D" + entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class PluginCompatTesterConfig {

// Path for maven settings file where repository will be provided allowing to
// download jenkins-core artifact (and dependencies)
@CheckForNull private File m2Settings;
@CheckForNull private File mavenSettings;

@NonNull private Map<String, String> mavenProperties = Map.of();

Expand Down Expand Up @@ -147,12 +147,12 @@ public void setExternalMaven(@CheckForNull File externalMaven) {
}

@CheckForNull
public File getM2Settings() {
return m2Settings;
public File getMavenSettings() {
return mavenSettings;
}

public void setM2Settings(@CheckForNull File m2Settings) {
this.m2Settings = m2Settings;
public void setMavenSettings(@CheckForNull File mavenSettings) {
this.mavenSettings = mavenSettings;
}

@NonNull
Expand Down

0 comments on commit 4c5608c

Please sign in to comment.