Skip to content

Commit

Permalink
Improve consistency of hooks (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Mar 8, 2023
1 parent e2258a1 commit ed585f6
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/jenkins/tools/test/hook/HpiPluginHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import org.jenkins.tools.test.exception.PluginCompatibilityTesterException;
import org.jenkins.tools.test.exception.PomExecutionException;
import org.jenkins.tools.test.maven.ExternalMavenRunner;
import org.jenkins.tools.test.maven.MavenRunner;
Expand Down Expand Up @@ -49,8 +48,7 @@ public boolean check(@NonNull BeforeExecutionContext context) {
}

@Override
public void action(@NonNull BeforeExecutionContext context)
throws PluginCompatibilityTesterException {
public void action(@NonNull BeforeExecutionContext context) {
context.getArgs().add("-Dhpi-plugin.version=3.37");
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jenkins/tools/test/hook/JacocoHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public class JacocoHook extends PluginCompatTesterHookBeforeExecution {
@Override
public boolean check(@NonNull BeforeExecutionContext context) {
Model model = context.getModel();
return "jacoco".equals(model.getArtifactId());
return "org.jenkins-ci.plugins".equals(model.getGroupId())
&& "jacoco".equals(model.getArtifactId())
&& "hpi".equals(model.getPackaging());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.File;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.maven.model.Model;
Expand All @@ -14,6 +15,9 @@ public class WarningsNGCheckoutHook extends AbstractMultiParentHook {

private static final Logger LOGGER = Logger.getLogger(WarningsNGCheckoutHook.class.getName());

private static final Set<String> ARTIFACT_IDS =
Set.of(/* localCheckoutDir */ "warnings-ng-parent", /* checkout */ "warnings-ng");

@Override
protected String getParentFolder() {
return "warnings-ng-plugin";
Expand All @@ -22,8 +26,9 @@ protected String getParentFolder() {
@Override
public boolean check(@NonNull BeforeCheckoutContext context) {
Model model = context.getModel();
return "warnings-ng-parent".equals(model.getArtifactId()) // localCheckoutDir
|| "warnings-ng".equals(model.getArtifactId()); // checkout
return "io.jenkins.plugins".equals(model.getGroupId())
&& ARTIFACT_IDS.contains(model.getArtifactId())
&& "hpi".equals(model.getPackaging());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jenkins.tools.test.hook;

import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Set;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeExecutionContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution;
Expand All @@ -10,10 +11,14 @@
@MetaInfServices(PluginCompatTesterHookBeforeExecution.class)
public class WarningsNGExecutionHook extends PluginWithFailsafeIntegrationTestsHook {

private static final Set<String> ARTIFACT_IDS =
Set.of(/* localCheckoutDir */ "warnings-ng-parent", /* checkout */ "warnings-ng");

@Override
public boolean check(@NonNull BeforeExecutionContext context) {
Model model = context.getModel();
return "warnings-ng-parent".equals(model.getArtifactId()) // localCheckoutDir
|| "warnings-ng".equals(model.getArtifactId()); // checkout
return "io.jenkins.plugins".equals(model.getGroupId())
&& ARTIFACT_IDS.contains(model.getArtifactId())
&& "hpi".equals(model.getPackaging());
}
}
21 changes: 9 additions & 12 deletions src/main/java/org/jenkins/tools/test/hook/WorkflowCpsHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@ protected String getPluginFolderName(@NonNull BeforeCheckoutContext context) {
@Override
public boolean check(@NonNull BeforeCheckoutContext context) {
Model model = context.getModel();
if (context.getPlugin() != null && context.getPlugin().version != null) {
VersionNumber pluginVersion = new VersionNumber(context.getPlugin().version);
// 2803 was the final release before it became a multi-module project.
// The history of groovy-cps history was merged into the repo, so the first multi-module
// release will be a little over 3500.
VersionNumber multiModuleSince = new VersionNumber("3500");
return "org.jenkins-ci.plugins.workflow".equals(model.getGroupId())
&& "workflow-cps".equals(model.getArtifactId())
&& pluginVersion.isNewerThan(multiModuleSince)
&& "hpi".equals(model.getPackaging());
}
return false;
VersionNumber pluginVersion = new VersionNumber(context.getPlugin().version);
// 2803 was the final release before it became a multi-module project.
// The history of groovy-cps history was merged into the repo, so the first multi-module
// release will be a little over 3500.
VersionNumber multiModuleSince = new VersionNumber("3500");
return "org.jenkins-ci.plugins.workflow".equals(model.getGroupId())
&& "workflow-cps".equals(model.getArtifactId())
&& pluginVersion.isNewerThan(multiModuleSince)
&& "hpi".equals(model.getPackaging());
}
}
2 changes: 2 additions & 0 deletions src/test/java/org/jenkins/tools/test/hook/JacocoHookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ void testCheckMethod() {
final JacocoHook hook = new JacocoHook();

Model model = new Model();
model.setGroupId("org.jenkins-ci.plugins");
model.setArtifactId("jacoco");
model.setPackaging("hpi");
BeforeExecutionContext context =
new BeforeExecutionContext(null, model, null, null, null, null, null, null);
assertTrue(hook.check(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ void testCheckMethod() {
final WarningsNGExecutionHook hook = new WarningsNGExecutionHook();

Model model = new Model();
model.setGroupId("io.jenkins.plugins");
model.setArtifactId("warnings-ng");
model.setPackaging("hpi");

BeforeExecutionContext context =
new BeforeExecutionContext(null, model, null, null, null, null, List.of(), null);
Expand Down

0 comments on commit ed585f6

Please sign in to comment.