Skip to content

Commit

Permalink
[JENKINS-62658] Support mvn process-test-classes for multi-module p…
Browse files Browse the repository at this point in the history
…lugins
  • Loading branch information
basil committed Mar 25, 2023
1 parent 2a63b3c commit 3a5dee3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
70 changes: 59 additions & 11 deletions src/main/java/org/jenkins/tools/test/PluginCompatTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,41 @@ private void testRepositoryAgainst(
// (which we do not care about for this purpose); and ensures that we are testing a
// plugin binary as close as possible to what was actually released. We also skip
// potential javadoc execution to avoid general test failure.
runner.run(
Map.of("maven.javadoc.skip", "true"),
pluginCheckoutDir,
buildLogFile,
"clean",
// TODO: find a way to deal with multi-module projects without using "install"
getProjectModules(pluginCheckoutDir, runner).isEmpty()
? "process-test-classes"
: "install",
"-Pquick-build");

Map<String, String> properties = new LinkedHashMap<>();
properties.put("maven.javadoc.skip", "true");

// TODO delete after maven-hpi-plugin 3.40 is adopted by these plugins
Set<String> outdatedMultiModule =
Set.of(
"io.jenkins.configuration-as-code:parent",
"io.jenkins.plugins.mina-sshd-api:mina-sshd-api-parent",
"org.jenkins-ci.plugins.aws-java-sdk:aws-java-sdk-parent",
"org.jenkinsci.plugins:pipeline-model-parent",
"org.jenkins-ci.plugins.pipeline-stage-view:parent-pom",
"org.jenkins-ci.plugins.to-declarative:declarative-pipeline-migration-assistant-parent",
"org.jenkins-ci.plugins.workflow:workflow-cps-parent");
if (outdatedMultiModule.contains(model.getGroupId() + ":" + model.getArtifactId())) {
properties.put("hpi-plugin.version", "3.40");
}

/*
* For multi-module projects where one plugin depends on another plugin in the same multi-module project, pass
* -Dset.changelist for incrementals releases so that Maven can find the first module when compiling the classes
* for the second module.
*/
boolean setChangelist = false;
if (!localCheckoutProvided() && !getProjectModules(pluginCheckoutDir, runner).isEmpty()) {
String projectVersion = getProjectVersion(pluginCheckoutDir, runner);
if (projectVersion.endsWith("999999-SNAPSHOT")
&& !model.getVersion().equals(projectVersion)) {
setChangelist = true;
}
}
if (setChangelist) {
properties.put("set.changelist", "true");
}
runner.run(properties, pluginCheckoutDir, buildLogFile, "clean", "process-test-classes");

List<String> args = new ArrayList<>();
args.add("hpi:resolve-test-dependencies");
Expand All @@ -419,7 +444,7 @@ private void testRepositoryAgainst(
new MavenPom(pluginCheckoutDir));
pcth.runBeforeExecution(forExecutionHooks);

Map<String, String> properties = new LinkedHashMap<>(config.getMavenProperties());
properties = new LinkedHashMap<>(config.getMavenProperties());
properties.put("overrideWar", config.getWar().toString());
properties.put("jenkins.version", coreCoordinates.getVersion());
properties.put("useUpperBounds", "true");
Expand All @@ -434,6 +459,9 @@ private void testRepositoryAgainst(
*/
properties.put("upperBoundsExcludes", "javax.servlet:servlet-api");
}
if (setChangelist) {
properties.put("set.changelist", "true");
}

// Execute with tests
runner.run(
Expand Down Expand Up @@ -688,6 +716,25 @@ static UpdateSite.Data scanWAR(File war, String pluginRegExp) {
return new UpdateSite.Data(core, plugins);
}

private static String getProjectVersion(File pluginPath, MavenRunner runner)
throws PomExecutionException {
Path log = pluginPath.toPath().resolve("project.version.log");
runner.run(
Map.of("expression", "project.version", "output", log.toAbsolutePath().toString()),
pluginPath,
null,
"-q",
"help:evaluate");
String output;
try {
output = Files.readString(log, Charset.defaultCharset()).trim();
Files.deleteIfExists(log);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return output;
}

private static List<String> getProjectModules(File pluginPath, MavenRunner runner)
throws PomExecutionException {
Path log = pluginPath.toPath().resolve("project.modules.log");
Expand All @@ -700,6 +747,7 @@ private static List<String> getProjectModules(File pluginPath, MavenRunner runne
List<String> output;
try {
output = Files.readAllLines(log, Charset.defaultCharset());
Files.deleteIfExists(log);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/jenkins/tools/test/hook/HpiPluginHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public boolean check(@NonNull BeforeExecutionContext context) {
if (pluginDir != null) {
try {
String version = getHpiPluginVersion(pluginDir, runner);
// TODO pending release of "multimodule" branch in "maven-hpi-plugin"
return new VersionNumber(version)
.isOlderThan(new VersionNumber("3.40-rc1394.915b_0b_17732d"));
return new VersionNumber(version).isOlderThan(new VersionNumber("3.37"));
} catch (PomExecutionException e) {
return false;
}
Expand All @@ -51,8 +49,7 @@ public boolean check(@NonNull BeforeExecutionContext context) {

@Override
public void action(@NonNull BeforeExecutionContext context) {
// TODO pending release of "multimodule" branch in "maven-hpi-plugin"
context.getArgs().add("-Dhpi-plugin.version=3.40-rc1394.915b_0b_17732d");
context.getArgs().add("-Dhpi-plugin.version=3.37");
}

private static String getHpiPluginVersion(File pluginPath, MavenRunner runner)
Expand All @@ -67,6 +64,7 @@ private static String getHpiPluginVersion(File pluginPath, MavenRunner runner)
List<String> output;
try {
output = Files.readAllLines(log.toPath(), Charset.defaultCharset());
Files.delete(log.toPath());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down

0 comments on commit 3a5dee3

Please sign in to comment.