Skip to content

Commit

Permalink
Get rid of Reflections in PluginCompatTesterHooks (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Mar 3, 2023
1 parent 7273098 commit fc5b653
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 155 deletions.
29 changes: 3 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,9 @@
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
<exclusions>
<exclusion>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</exclusion>
</exclusions>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -192,23 +186,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- Version specified in parent POM -->
<configuration>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>${picocli.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/jenkins/tools/test/PluginCompatTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ public PluginCompatTester(PluginCompatTesterConfig config) {
public void testPlugins() throws PluginCompatibilityTesterException {
PluginCompatTesterHooks pcth =
new PluginCompatTesterHooks(
config.getHookPrefixes(),
config.getExternalHooksJars(),
config.getExcludeHooks());
config.getExternalHooksJars(), config.getExcludeHooks());
// Determine the plugin data

// Scan bundled plugins. If there is any bundled plugin, only these plugins will be taken
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/org/jenkins/tools/test/PluginCompatTesterCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,6 @@ public class PluginCompatTesterCli implements Callable<Integer> {
"Comma-separated list of arguments to pass to Maven (like -Pxxx; not to be confused with Java arguments or Maven properties). These arguments will be passed to Maven both during compilation and when running tests.")
private List<String> mavenArgs;

@CheckForNull
@CommandLine.Option(
names = "--hook-prefixes",
split = ",",
arity = "1",
paramLabel = "prefix",
description = "Comma-separated list of prefixes of extra hook classes.")
private List<String> hookPrefixes;

@CheckForNull
@CommandLine.Option(
names = "--external-hooks-jars",
Expand Down Expand Up @@ -189,9 +180,6 @@ public Integer call() throws PluginCompatibilityTesterException {
if (mavenArgs != null) {
config.setMavenArgs(mavenArgs);
}
if (hookPrefixes != null) {
config.setHookPrefixes(hookPrefixes);
}
if (externalHooksJars != null) {
config.setExternalHooksJars(externalHooksJars);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
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;
import org.kohsuke.MetaInfServices;

/**
* Custom execution hook for plugins whose parent is {@code org.jvnet.hudson.plugins:analysis-pom}.
* These plugins use Maven Failsafe Plugin in their test suites.
*/
@MetaInfServices(PluginCompatTesterHookBeforeExecution.class)
public class AnalysisPomExecutionHook extends PluginWithFailsafeIntegrationTestsHook {

private static final Set<String> ARTIFACT_IDS =
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jenkins/tools/test/hook/AwsJavaSdkHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class AwsJavaSdkHook extends AbstractMultiParentHook {

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jenkins/tools/test/hook/BlueOceanHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

/** Workaround for the Blue Ocean plugins since they are stored in a central repository. */
@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class BlueOceanHook extends AbstractMultiParentHook {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class ConfigurationAsCodeHook extends AbstractMultiParentHook {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import java.util.Set;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

/**
* Workaround for the Pipeline: Declarative plugins since they are stored in a central repository.
*/
@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class DeclarativePipelineHook extends AbstractMultiParentHook {

private static final Set<String> ARTIFACT_IDS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import java.util.Set;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

/**
* Workaround for the Declarative Pipeline Migration Assistant plugins since they are stored in a
* central repository.
*/
@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class DeclarativePipelineMigrationHook extends AbstractMultiParentHook {

private static final Set<String> ARTIFACT_IDS =
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jenkins/tools/test/hook/HpiPluginHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jenkins.tools.test.model.PluginCompatTesterConfig;
import org.jenkins.tools.test.model.hook.BeforeExecutionContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution;
import org.kohsuke.MetaInfServices;

/**
* The {@code overrideWar} option is available in HPI Plugin 3.29 or later, but many plugins under
Expand All @@ -24,6 +25,7 @@
* the managed set are using a plugin parent POM with HPI Plugin 3.29 or later (i.e., plugin parent
* POM 4.44 or later), this can be deleted.
*/
@MetaInfServices(PluginCompatTesterHookBeforeExecution.class)
public class HpiPluginHook extends PluginCompatTesterHookBeforeExecution {

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/jenkins/tools/test/hook/JacocoHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeExecutionContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution;
import org.kohsuke.MetaInfServices;

/**
* Workaround for JaCoCo plugin since it needs execute the jacoco:prepare-agent goal before
* execution.
*/
@MetaInfServices(PluginCompatTesterHookBeforeExecution.class)
public class JacocoHook extends PluginCompatTesterHookBeforeExecution {

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jenkins/tools/test/hook/MinaSshdApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class MinaSshdApi extends AbstractMultiParentHook {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.jenkins.tools.test.model.hook.PluginCompatTesterHooks;
import org.jenkins.tools.test.model.hook.Stage;
import org.jenkins.tools.test.model.hook.StageContext;
import org.kohsuke.MetaInfServices;

@MetaInfServices(PluginCompatTesterHookBeforeCompile.class)
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "intended behavior")
public class MultiParentCompileHook extends PluginCompatTesterHookBeforeCompile {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import java.util.Set;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class PipelineStageViewHook extends AbstractMultiParentHook {

private static final Set<String> ARTIFACT_IDS =
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/jenkins/tools/test/hook/SwarmHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class SwarmHook extends AbstractMultiParentHook {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import java.util.logging.Logger;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class WarningsNGCheckoutHook extends AbstractMultiParentHook {

private static final Logger LOGGER = Logger.getLogger(WarningsNGCheckoutHook.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeExecutionContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeExecution;
import org.kohsuke.MetaInfServices;

/** Workaround for Warnings NG plugin since it needs execute integration tests. */
@MetaInfServices(PluginCompatTesterHookBeforeExecution.class)
public class WarningsNGExecutionHook extends PluginWithFailsafeIntegrationTestsHook {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import hudson.util.VersionNumber;
import org.apache.maven.model.Model;
import org.jenkins.tools.test.model.hook.BeforeCheckoutContext;
import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout;
import org.kohsuke.MetaInfServices;

@MetaInfServices(PluginCompatTesterHookBeforeCheckout.class)
public class WorkflowCpsHook extends AbstractMultiParentHook {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -73,9 +72,6 @@ public class PluginCompatTesterConfig {

@NonNull private List<String> mavenArgs = List.of();

// Classpath prefixes of the extra hooks
@NonNull private List<String> hookPrefixes = List.of("org.jenkins");

// External hooks jar files path locations
@NonNull private List<File> externalHooksJars = List.of();

Expand Down Expand Up @@ -173,19 +169,6 @@ public void setMavenArgs(@NonNull List<String> mavenArgs) {
this.mavenArgs = List.copyOf(mavenArgs);
}

@NonNull
public List<String> getHookPrefixes() {
return hookPrefixes;
}

public void setHookPrefixes(@NonNull List<String> hookPrefixes) {
// Want to also process the default
List<String> combined = new ArrayList<>();
combined.addAll(this.hookPrefixes);
combined.addAll(hookPrefixes);
this.hookPrefixes = List.copyOf(combined);
}

@NonNull
public List<File> getExternalHooksJars() {
return externalHooksJars;
Expand Down
Loading

0 comments on commit fc5b653

Please sign in to comment.