Skip to content

Commit

Permalink
Merge pull request #372 from basil/excludeHooks
Browse files Browse the repository at this point in the history
Support for excluding hooks
  • Loading branch information
imonteroperez authored Jul 25, 2022
2 parents f1cc529 + 23e2bcb commit 8349eac
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class CliOptions {
"If not set, see includePlugins behaviour.")
private String excludePlugins = null;

@Parameter(names = "-excludeHooks",
description = "Comma separated list of hooks to NOT execute.\n" +
"If not set, all hooks will be executed.")
private String excludeHooks = null;

@Parameter(names = "-fallbackGitHubOrganization",
description = "Include an alternative organization to use as a fallback to download the plugin.\n" +
"It is useful to use your own fork releases for an specific plugin if the " +
Expand Down Expand Up @@ -205,6 +210,10 @@ public String getExcludePlugins() {
return excludePlugins;
}

public String getExcludeHooks() {
return excludeHooks;
}

public String getFallbackGitHubOrganization() {
return fallbackGitHubOrganization;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ public static void main(String[] args) throws IOException, PlexusContainerExcept
if(options.getExcludePlugins() != null && !options.getExcludePlugins().isEmpty()){
config.setExcludePlugins(Arrays.asList(options.getExcludePlugins().toLowerCase().split(",")));
}
if(options.getExcludeHooks() != null && !options.getExcludeHooks().isEmpty()){
config.setExcludeHooks(Arrays.asList(options.getExcludeHooks().split(",")));
}
if(options.getSkipTestCache() != null){
config.setSkipTestCache(Boolean.parseBoolean(options.getSkipTestCache()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public class PluginCompatTesterConfig {
// If null, tests will be performed on every includePlugins found
private List<String> excludePlugins = null;

// List of hooks that will not be executed
// If null, all hooks will be executed
private List<String> excludeHooks = null;

// URL to be used as an alternative to download plugin source from fallback
// organtizations, like your own fork
private String fallbackGitHubOrganization = null;
Expand Down Expand Up @@ -247,6 +251,14 @@ public void setExcludePlugins(List<String> excludePlugins) {
this.excludePlugins = excludePlugins;
}

public List<String> getExcludeHooks() {
return excludeHooks;
}

public void setExcludeHooks(List<String> excludeHooks) {
this.excludeHooks = excludeHooks;
}

public String getFallbackGitHubOrganization() {
return fallbackGitHubOrganization;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PluginCompatTesterHooks {
private Set<ClassLoader> classLoaders = new HashSet<>(Collections.singletonList(PluginCompatTesterHooks.class.getClassLoader()));
private List<String> hookPrefixes = new ArrayList<>();
private static Map<String, Map<String, Queue<PluginCompatTesterHook>>> hooksByType = new HashMap<>();
private List<String> excludeHooks = new ArrayList<>();

/**
* Create and prepopulate the various hooks for this run of Plugin Compatibility Tester.
Expand All @@ -44,9 +45,16 @@ public PluginCompatTesterHooks(List<String> extraPrefixes) {
}

public PluginCompatTesterHooks(List<String> extraPrefixes, List<File> externalJars) throws MalformedURLException {
this(extraPrefixes, externalJars, Collections.emptyList());
}

public PluginCompatTesterHooks(List<String> extraPrefixes, List<File> externalJars, List<String> excludeHooks) throws MalformedURLException {
setupPrefixes(extraPrefixes);
setupExternalClassLoaders(externalJars);
setupHooksByType();
if (excludeHooks != null) {
this.excludeHooks.addAll(excludeHooks);
}
}

private void setupHooksByType() {
Expand Down Expand Up @@ -95,7 +103,7 @@ private Map<String, Object> runHooks(String stage, Map<String, Object> elements)
for(PluginCompatTesterHook hook : beforeHooks) {
try {
System.out.println("Processing " + hook.getClass().getName());
if(hook.check(elements)) {
if(!excludeHooks.contains(hook.getClass().getName()) && hook.check(elements)) {
elements = hook.action(elements);
hook.validate(elements);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import org.jenkins.tools.test.exception.PluginSourcesUnavailableException;
import org.jenkins.tools.test.exception.PomExecutionException;
import org.jenkins.tools.test.exception.ExecutedTestNamesSolverException;
import org.jenkins.tools.test.hook.TransformPom;
import org.jenkins.tools.test.maven.ExternalMavenRunner;
import org.jenkins.tools.test.model.MavenBom;
import org.jenkins.tools.test.maven.MavenRunner;
Expand Down Expand Up @@ -176,7 +177,7 @@ public PluginCompatReport testPlugins()
splitCycles = HISTORICAL_SPLIT_CYCLES;
}

PluginCompatTesterHooks pcth = new PluginCompatTesterHooks(config.getHookPrefixes(), config.getExternalHooksJars());
PluginCompatTesterHooks pcth = new PluginCompatTesterHooks(config.getHookPrefixes(), config.getExternalHooksJars(), config.getExcludeHooks());
// Providing XSL Stylesheet along xml report file
if(config.reportFile != null){
if(config.isProvideXslReport()){
Expand Down Expand Up @@ -561,7 +562,9 @@ private TestExecutionResult testPluginAgainst(MavenCoordinates coreCoordinates,
// Much simpler to do use the parent POM to set up the test classpath.
MavenPom pom = new MavenPom(pluginCheckoutDir);
try {
if (config.getExcludeHooks() != null && !config.getExcludeHooks().contains(TransformPom.class.getName())) {
addSplitPluginDependencies(plugin.name, mconfig, pluginCheckoutDir, pom, otherPlugins, pluginGroupIds, coreCoordinates.version, overridenPlugins, parentFolder);
}
} catch (PomTransformationException x) {
throw x;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private PluginCompatTesterConfig getConfig(List<String> includedPlugins) throws

config.setIncludePlugins(includedPlugins);
config.setExcludePlugins(Collections.emptyList());
config.setExcludeHooks(Collections.emptyList());
config.setSkipTestCache(true);
config.setCacheThresholdStatus(TestStatus.TEST_FAILURES);
config.setTestCacheTimeout(345600000);
Expand Down

0 comments on commit 8349eac

Please sign in to comment.