From 2db71d83fff33d3f8722670321c3034f4f3dc1a7 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Mon, 30 Jan 2023 11:07:13 -0800 Subject: [PATCH] Remove `NonStandardTagHook` (#416) --- README.md | 19 --- .../tools/test/hook/NonStandardTagHook.java | 91 --------------- .../nonstandardtagplugins.properties | 5 - .../tools/test/NonStandardTagHookTest.java | 110 ------------------ .../nonstandardtagplugins.properties | 6 - 5 files changed, 231 deletions(-) delete mode 100644 src/main/java/org/jenkins/tools/test/hook/NonStandardTagHook.java delete mode 100644 src/main/resources/nonstandardtagplugins.properties delete mode 100644 src/test/java/org/jenkins/tools/test/NonStandardTagHookTest.java delete mode 100644 src/test/resources/nonstandardtagplugins.properties diff --git a/README.md b/README.md index fd7d98c04..2258aa4b7 100644 --- a/README.md +++ b/README.md @@ -176,25 +176,6 @@ but only if the group ID could be inferred by other means: either that plugin being included in the `-war`, or no `-war` being passed but the plugin being present on the update center. -### Running the PCT for plugins not following standard tag - -If a plugin does not follow the standard tagging of the Jenkins community the PCT will not be able to -find and checkout the proper code from github. For those cases the PCT provides a hook that will override the -default checkout mechanism. - -This hook reads the property file [nonstandardtagplugins.properties](./plugins-compat-tester/src/main/resources/) to get the information about the tag format used for the affected plugins. Each plugin that wishes to use this mechanism -has to add a new property with the artifactId of the plugin as key and a value compatible with [String.format](https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#format-java.lang.String-java.lang.Object...-) the only argument -allowed for the format string is the version to chekout. - -You can also specify a minimum version for the plugin to be processed by the hook, for that you add a new entry in the aforementioned properties file with the key `artifactId-minimumVersion` and value -the lowest version of the plugin for the hook to activate, if you do that the hook will ignore any run of the plugin if the specified version is lower than the one in the properties file. - -``` -electricflow=cloudbees-flow-%s -electricflow-minimumVersion=1.1.8 -``` - - ## Developer Info ### Debugging PCT in Docker diff --git a/src/main/java/org/jenkins/tools/test/hook/NonStandardTagHook.java b/src/main/java/org/jenkins/tools/test/hook/NonStandardTagHook.java deleted file mode 100644 index bca77e314..000000000 --- a/src/main/java/org/jenkins/tools/test/hook/NonStandardTagHook.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.jenkins.tools.test.hook; - -import hudson.model.UpdateSite; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.jenkins.tools.test.PluginCompatTester; -import org.jenkins.tools.test.model.PluginCompatTesterConfig; -import org.jenkins.tools.test.model.PomData; -import org.jenkins.tools.test.model.comparators.VersionComparator; -import org.jenkins.tools.test.model.hook.PluginCompatTesterHookBeforeCheckout; - -/** - * This hook allows plugins using a non-standard tag format on GitHub to be checked out. - * - *

The affected plugins are loaded from a properties file whose key is the {@code artifactId} and - * whose value is a string to be formatted for the tag value. This value will be calculated using - * {@link String#format(String, Object...)} passing the current version as the only parameter. - */ -public class NonStandardTagHook extends PluginCompatTesterHookBeforeCheckout { - - private static final Logger LOGGER = Logger.getLogger(NonStandardTagHook.class.getName()); - - private final Properties affectedPlugins; - private final List transformedPlugins = new LinkedList<>(); - private final VersionComparator comparator = new VersionComparator(); - private static final String MINIMUM_VERSION_SUFFIX = "-minimumVersion"; - - public NonStandardTagHook() { - affectedPlugins = new Properties(); - try (InputStream inputStream = ClassLoader.getSystemResourceAsStream("nonstandardtagplugins.properties")) { - affectedPlugins.load(inputStream); - affectedPlugins.keySet().forEach(e -> { - if (!e.toString().contains(MINIMUM_VERSION_SUFFIX)) { - transformedPlugins.add(e.toString()); - } - }); - } catch (IOException e) { - LOGGER.log(Level.WARNING, "NonStandardTagHook was not able to load affected plugins; continuing", e); - } - } - - @Override - public boolean check(Map info) { - UpdateSite.Plugin plugin = (UpdateSite.Plugin) info.get("plugin"); - boolean definedPlugin = affectedPlugins.containsKey(plugin.name); - String minimumVersion= affectedPlugins.getProperty(plugin.name + MINIMUM_VERSION_SUFFIX); - boolean correctVersion = minimumVersion == null || comparator.compare(minimumVersion, plugin.version) <= 0; - return definedPlugin && correctVersion; - } - - @Override - public Map action(Map info) throws Exception { - PluginCompatTesterConfig config = (PluginCompatTesterConfig)info.get("config"); - PomData pomData = (PomData)info.get("pomData"); - UpdateSite.Plugin plugin = (UpdateSite.Plugin) info.get("plugin"); - - // We should not execute the hook if using localCheckoutDir - boolean shouldExecuteHook = config.getLocalCheckoutDir() == null || !config.getLocalCheckoutDir().exists(); - - if (shouldExecuteHook) { - LOGGER.log(Level.INFO, "Executing {0} for {1}", new Object[]{this.getClass().getSimpleName(), pomData.artifactId}); - - // Checkout to the parent directory. All other processes will be on the child directory - File checkoutPath = new File(config.workDirectory.getAbsolutePath() + "/" + pomData.artifactId); - - String scmTag = String.format(affectedPlugins.get(pomData.artifactId).toString(), plugin.version); - PluginCompatTester pct = new PluginCompatTester(config); - pct.cloneFromSCM(pomData, plugin.name, plugin.version, checkoutPath, scmTag); - - // Checkout already happened, don't run through again - info.put("runCheckout", false); - info.put("checkoutDir", checkoutPath); - info.put("pluginDir", checkoutPath); - } - return info; - - } - - @Override - public List transformedPlugins() { - return Collections.unmodifiableList(transformedPlugins); - } -} diff --git a/src/main/resources/nonstandardtagplugins.properties b/src/main/resources/nonstandardtagplugins.properties deleted file mode 100644 index 8b027e995..000000000 --- a/src/main/resources/nonstandardtagplugins.properties +++ /dev/null @@ -1,5 +0,0 @@ -electricflow=cloudbees-flow-%s -electricflow-minimumVersion=1.1.8 -github=v%s -warnings-ng=v%s -warnings-ng-minimumVersion=8.4.1.1 \ No newline at end of file diff --git a/src/test/java/org/jenkins/tools/test/NonStandardTagHookTest.java b/src/test/java/org/jenkins/tools/test/NonStandardTagHookTest.java deleted file mode 100644 index dba83545e..000000000 --- a/src/test/java/org/jenkins/tools/test/NonStandardTagHookTest.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.jenkins.tools.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import hudson.model.UpdateSite; -import java.io.File; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; -import org.jenkins.tools.test.hook.NonStandardTagHook; -import org.jenkins.tools.test.model.MavenCoordinates; -import org.jenkins.tools.test.model.PluginCompatTesterConfig; -import org.jenkins.tools.test.model.PomData; -import org.jenkins.tools.test.model.TestStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -public class NonStandardTagHookTest { - - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); - - - @Test - public void testConstruction() { - NonStandardTagHook hook = new NonStandardTagHook(); - List transformedPlugins = hook.transformedPlugins(); - assertNotNull("The list of transformed plugins must be non null", transformedPlugins); - assertEquals("List of affected plugins must be of size 4", 4, transformedPlugins.size()); - assertTrue("One element in transformedPlugins must be 'artifactID'", transformedPlugins.contains("artifactID")); - } - - @Test - public void testCheckMethod() { - NonStandardTagHook hook = new NonStandardTagHook(); - Map info = new HashMap<>(); - JSONObject pluginData = new JSONObject(); - pluginData.put("name", "electricflow"); - pluginData.put("version", "1.1.8"); - pluginData.put("url", "example.com"); - pluginData.put("dependencies", new JSONArray()); - UpdateSite.Plugin plugin = new UpdateSite.Plugin("NO Source", pluginData); - info.put("plugin", plugin); - try { - assertTrue("Check should be true", hook.check(info)); - } catch (Exception e) { - fail("Exception calling check method " + e.getMessage()); - } - } - - @Test - public void testCheckMethodWithMinimumVersion() { - NonStandardTagHook hook = new NonStandardTagHook(); - Map info = new HashMap<>(); - JSONObject pluginData = new JSONObject(); - pluginData.put("name", "electricflow"); - pluginData.put("version", "1.1.7"); - pluginData.put("url", "example.com"); - pluginData.put("dependencies", new JSONArray()); - UpdateSite.Plugin plugin = new UpdateSite.Plugin("NO Source", pluginData); - info.put("plugin", plugin); - try { - assertFalse("Check should be false", hook.check(info)); - } catch (Exception e) { - fail("Exception calling check method " + e.getMessage()); - } - } - - @Test - public void testActuallyPerformsTheCheckoutWithVersionGreaterThanMinimum() { - - try { - PluginCompatTesterConfig config = new PluginCompatTesterConfig(testFolder.getRoot(), - new File("../reports/PluginCompatReport.xml"), - new File(getClass().getResource("m2-settings.xml").toURI())); - config.setIncludePlugins(List.of("electricflow")); - config.setSkipTestCache(true); - config.setCacheThresholdStatus(TestStatus.TEST_FAILURES); - config.setTestCacheTimeout(345600000); - config.setParentVersion("1.410"); - config.setGenerateHtmlReport(true); - - Map info = new HashMap<>(); - PomData data = new PomData("electricflow", "hpi", "scm:git:git://github.com/jenkinsci/electricflow-plugin.git", "cloudbees-flow-1.1.8", new MavenCoordinates("org.jenkins-ci.plugins", "electricflow", "1.1.8"), "org.jenkins-ci.plugins"); - info.put("pomData", data); - JSONObject pluginData = new JSONObject(); - pluginData.put("name", "electricflow"); - pluginData.put("version", "1.1.8"); - pluginData.put("url", "example.com"); - pluginData.put("dependencies", new JSONArray()); - UpdateSite.Plugin plugin = new UpdateSite.Plugin("NO Source", pluginData); - info.put("plugin", plugin); - info.put("config", config); - - - NonStandardTagHook hook = new NonStandardTagHook(); - Map returnedConfig = hook.action(info); - assertEquals("RunCheckout should be false", Boolean.FALSE, returnedConfig.get("runCheckout")); - } catch (Exception e) { - fail("No exception should be thrown when invoking the hook for valid data but got: " + e); - } - } -} diff --git a/src/test/resources/nonstandardtagplugins.properties b/src/test/resources/nonstandardtagplugins.properties deleted file mode 100644 index b4e984ccc..000000000 --- a/src/test/resources/nonstandardtagplugins.properties +++ /dev/null @@ -1,6 +0,0 @@ -artifactID=artifactId-%s -electricflow=cloudbees-flow-%s -electricflow-minimumVersion=1.1.8 -github=v%s -warnings-ng=v%s -warnings-ng-minimumVersion=8.4.1.1 \ No newline at end of file