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

Require a minimum version of the Jenkins Test Harness #489

Closed
wants to merge 5 commits into from
Closed
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
@@ -0,0 +1,27 @@
package org.jenkins.tools.test.hook;

import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution;
import org.kohsuke.MetaInfServices;

/**
* Recent core versions require a relatively recent Jenkins Test Harness, so ensure that a minimum
* supported version is in place.
*/
@MetaInfServices(PluginCompatTesterHookBeforeExecution.class)
public class JenkinsTestHarnessHook extends PropertyVersionHook {

@Override
public String getProperty() {
return "jenkins-test-harness.version";
}

@Override
public String getMinimumVersion() {
return "1903.vf505ecb_63589";
}

@Override
public String getMinimumPluginParentPomVersion() {
return "4.48";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jenkins.tools.test.hook;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.util.VersionNumber;
import java.io.File;
Expand Down Expand Up @@ -31,6 +32,16 @@ public abstract class PropertyVersionHook extends PluginCompatTesterHookBeforeEx
*/
public abstract String getMinimumVersion();

/**
* The minimum plugin parent POM version needed. If the plugin under test is on an older plugin
* parent POM, the property will not be updated. Return {@code null} to skip the minimum plugin
* POM version check.
*/
@CheckForNull
public String getMinimumPluginParentPomVersion() {
return null;
}

@Override
public boolean check(@NonNull BeforeExecutionContext context) {
PluginCompatTesterConfig config = context.getConfig();
Expand All @@ -42,6 +53,16 @@ public boolean check(@NonNull BeforeExecutionContext context) {
File pluginDir = context.getPluginDir();
if (pluginDir != null) {
try {
if (getMinimumPluginParentPomVersion() != null) {
String pluginParentPomVersion = getPluginParentPomVersion(pluginDir, runner);
if (pluginParentPomVersion == null) {
return false;
}
if (new VersionNumber(pluginParentPomVersion)
.isOlderThan(new VersionNumber(getMinimumPluginParentPomVersion()))) {
return false;
}
}
String version = getPropertyVersion(pluginDir, getProperty(), runner);
return new VersionNumber(version)
.isOlderThan(new VersionNumber(getMinimumVersion()));
Expand All @@ -57,6 +78,22 @@ public void action(@NonNull BeforeExecutionContext context) {
context.getArgs().add(String.format("-D%s=%s", getProperty(), getMinimumVersion()));
}

@CheckForNull
private static String getPluginParentPomVersion(File pluginPath, MavenRunner runner)
throws PomExecutionException {
String cur;
for (cur = "project.parent"; ; cur += ".parent") {
String groupId = getPropertyVersion(pluginPath, cur + ".groupId", runner);
String artifactId = getPropertyVersion(pluginPath, cur + ".artifactId", runner);
if (groupId == null || artifactId == null) {
return null;
}
if (groupId.equals("org.jenkins-ci.plugins") && artifactId.equals("plugin")) {
return getPropertyVersion(pluginPath, cur + ".version", runner);
}
}
}

private static String getPropertyVersion(File pluginPath, String property, MavenRunner runner)
throws PomExecutionException {
Path log = pluginPath.toPath().resolve(property + ".log");
Expand All @@ -73,6 +110,6 @@ private static String getPropertyVersion(File pluginPath, String property, Maven
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return output;
return "null object or invalid expression".equals(output) ? null : output;
}
}