diff --git a/README.adoc b/README.adoc index e6d01fff0..fdb9f77d3 100644 --- a/README.adoc +++ b/README.adoc @@ -242,11 +242,3 @@ Once update site JSON files are generated, configure Jenkins to download them in Either set up a local HTTP server so the URL would be something like `+http://localhost:8000/update-center.json+`, or specify a `file://` URL like `+file:///Users/yourname/git/update-center2/www2/update-center.json+` NOTE: For historical reason, the configured URL points to `update-center.json`, but the file actually downloaded by Jenkins (at least up to 2.235 as of this writing) is `update-center.json.html`. - -=== Filtering Java versions - -The `--java-version ` CLI argument can be used to filter plugins based on their minimum Java version requirement. -By default such filtering happens based on the `Minimum-Java-Version` manifest entry provided in Plugin HPIs starting from https://github.com/jenkinsci/maven-hpi-plugin#30-2018-12-05[Maven HPI Plugin 3.0] and https://github.com/jenkinsci/plugin-pom/blob/master/CHANGELOG.md#329[Plugin POM 3.29]. - -Plugin HPIs without `Minimum-Java-Version` will be accepted by default. -If you want to create an update center for old Java, use the `--limit-plugin-core-dependency` option to set the filter for core dependencies in plugins. diff --git a/src/main/java/io/jenkins/update_center/HPI.java b/src/main/java/io/jenkins/update_center/HPI.java index ca40ba546..b42c0b61e 100644 --- a/src/main/java/io/jenkins/update_center/HPI.java +++ b/src/main/java/io/jenkins/update_center/HPI.java @@ -26,7 +26,6 @@ import com.alibaba.fastjson.annotation.JSONField; import com.google.common.annotations.VisibleForTesting; import hudson.util.VersionNumber; -import io.jenkins.update_center.util.JavaSpecificationVersion; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.dom4j.Document; @@ -44,7 +43,6 @@ import org.owasp.html.Sanitizers; import org.xml.sax.SAXException; -import javax.annotation.CheckForNull; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -121,22 +119,6 @@ public String getCompatibleSinceVersion() throws IOException { return getManifestAttributes().getValue("Compatible-Since-Version"); } - /** - * Gets Minimum Java Version required by the plugin. - * This uses the value of the {@code Minimum-Java-Version} manifest entry - * @return Minimum Java Version or {@code null} if it is unknown - * @throws IOException Manifest read error - */ - @CheckForNull - public JavaSpecificationVersion getMinimumJavaVersion() throws IOException { - String manifestEntry = getManifestAttributes().getValue("Minimum-Java-Version"); - if (StringUtils.isNotBlank(manifestEntry)) { - return new JavaSpecificationVersion(manifestEntry); - } - - return null; - } - public List getDependencies() throws IOException { String deps = getManifestAttributes().getValue("Plugin-Dependencies"); if(deps==null) return Collections.emptyList(); diff --git a/src/main/java/io/jenkins/update_center/Main.java b/src/main/java/io/jenkins/update_center/Main.java index d76765922..07bdab341 100644 --- a/src/main/java/io/jenkins/update_center/Main.java +++ b/src/main/java/io/jenkins/update_center/Main.java @@ -36,12 +36,9 @@ import io.jenkins.update_center.wrappers.StableWarMavenRepository; import io.jenkins.update_center.wrappers.VersionCappedMavenRepository; import org.apache.commons.io.IOUtils; -import io.jenkins.update_center.filters.JavaVersionPluginFilter; import io.jenkins.update_center.json.PluginVersionsRoot; import io.jenkins.update_center.json.ReleaseHistoryRoot; import io.jenkins.update_center.json.UpdateCenterRoot; -import io.jenkins.update_center.util.JavaSpecificationVersion; -import io.jenkins.update_center.wrappers.FilteringRepository; import io.jenkins.update_center.wrappers.TruncatedMavenRepository; import io.jenkins.update_center.wrappers.AllowedArtifactsListMavenRepository; import org.kohsuke.args4j.ClassParser; @@ -98,9 +95,6 @@ public class Main { @Option(name = "--with-experimental", usage = "Include experimental alpha/beta releases") public boolean includeExperimental; - @Option(name = "--java-version", usage = "Target Java version for the update center. Plugins will be excluded if their minimum Java version does not match. If not set, required Java version will be ignored") - @CheckForNull public String javaVersion; - @Option(name = "--max-plugins", usage = "For testing purposes: Limit the number of plugins included to the specified number.") @CheckForNull public Integer maxPlugins; @@ -349,9 +343,6 @@ private MavenRepository createRepository() throws Exception { VersionNumber vc = capCore == null ? null : new VersionNumber(capCore); repo = new VersionCappedMavenRepository(vp, vc).withBaseRepository(repo); } - if (javaVersion != null) { - repo = new FilteringRepository().withPluginFilter(new JavaVersionPluginFilter(new JavaSpecificationVersion(this.javaVersion))).withBaseRepository(repo); - } return repo; } diff --git a/src/main/java/io/jenkins/update_center/PluginUpdateCenterEntry.java b/src/main/java/io/jenkins/update_center/PluginUpdateCenterEntry.java index 815ab0533..ddba0bcc5 100644 --- a/src/main/java/io/jenkins/update_center/PluginUpdateCenterEntry.java +++ b/src/main/java/io/jenkins/update_center/PluginUpdateCenterEntry.java @@ -2,7 +2,6 @@ import com.alibaba.fastjson.annotation.JSONField; import hudson.util.VersionNumber; -import io.jenkins.update_center.util.JavaSpecificationVersion; import javax.annotation.CheckForNull; import java.io.IOException; @@ -129,11 +128,6 @@ public String getCompatibleSinceVersion() throws IOException { return latestOffered.getCompatibleSinceVersion(); } - public String getMinimumJavaVersion() throws IOException { - final JavaSpecificationVersion minimumJavaVersion = latestOffered.getMinimumJavaVersion(); - return minimumJavaVersion == null ? null : minimumJavaVersion.toString(); - } - public String getBuildDate() throws IOException { return latestOffered.getTimestampAsString(); } diff --git a/src/main/java/io/jenkins/update_center/filters/JavaVersionPluginFilter.java b/src/main/java/io/jenkins/update_center/filters/JavaVersionPluginFilter.java deleted file mode 100644 index 18dfce713..000000000 --- a/src/main/java/io/jenkins/update_center/filters/JavaVersionPluginFilter.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2018 CloudBees, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.jenkins.update_center.filters; - -import hudson.util.VersionNumber; -import io.jenkins.update_center.PluginFilter; -import io.jenkins.update_center.HPI; -import io.jenkins.update_center.util.JavaSpecificationVersion; - -import javax.annotation.Nonnull; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * @author Oleg Nenashev - */ -public class JavaVersionPluginFilter implements PluginFilter { - - private static final Logger LOGGER = Logger.getLogger(JavaVersionPluginFilter.class.getName()); - - /** - * Java version, with which the plugin should be compatible. - */ - @Nonnull - private final VersionNumber javaVersion; - - public JavaVersionPluginFilter(@Nonnull JavaSpecificationVersion javaVersion) { - this.javaVersion = javaVersion; - } - - @Override - public boolean shouldIgnore(@Nonnull HPI hpi) { - final JavaSpecificationVersion pluginJavaVersion; - try { - pluginJavaVersion = hpi.getMinimumJavaVersion(); - } catch (IOException e) { - LOGGER.log(Level.FINE, - String.format("Minimum Java Version cannot be determined for %s, will accept it", hpi), - e); - return false; - } - if (pluginJavaVersion == null) { - LOGGER.log(Level.FINE, "Minimum Java Version cannot be determined for {0}, will accept it", hpi); - return false; - } - - if (javaVersion.isOlderThan(pluginJavaVersion)) { - LOGGER.log(Level.INFO, "Ignoring {0}:{1}. Java version {2} is required, but it is newer than the target version {3}", - new Object[] {hpi.artifact.artifactId, hpi.getVersion(), pluginJavaVersion, javaVersion}); - return true; - } - LOGGER.log(Level.FINEST, "Accepting {0}:{1}. It requires Java version {2}, which is compliant with {3}", - new Object[] {hpi.artifact.artifactId, hpi.getVersion(), pluginJavaVersion, javaVersion}); - return false; - } -} diff --git a/src/main/java/io/jenkins/update_center/util/JavaSpecificationVersion.java b/src/main/java/io/jenkins/update_center/util/JavaSpecificationVersion.java deleted file mode 100644 index ab1a489e5..000000000 --- a/src/main/java/io/jenkins/update_center/util/JavaSpecificationVersion.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2018 CloudBees, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.jenkins.update_center.util; - -import hudson.util.VersionNumber; - -import javax.annotation.Nonnull; - -//TODO: Move it to the VersionNumber lib - -/** - * Java Version Specification. - * Implemented according to https://openjdk.java.net/jeps/223 - * @author Oleg Nenashev - */ -public class JavaSpecificationVersion extends VersionNumber { - - public static final JavaSpecificationVersion JAVA_5 = new JavaSpecificationVersion("1.5"); - public static final JavaSpecificationVersion JAVA_6 = new JavaSpecificationVersion("1.6"); - public static final JavaSpecificationVersion JAVA_7 = new JavaSpecificationVersion("1.7"); - public static final JavaSpecificationVersion JAVA_8 = new JavaSpecificationVersion("1.8"); - public static final JavaSpecificationVersion JAVA_9 = new JavaSpecificationVersion("9"); - public static final JavaSpecificationVersion JAVA_10 = new JavaSpecificationVersion("10"); - public static final JavaSpecificationVersion JAVA_11 = new JavaSpecificationVersion("11"); - public static final JavaSpecificationVersion JAVA_12 = new JavaSpecificationVersion("12"); - - /** - * Constructor which automatically normalizes version strings. - * @param version Java specification version, should follow JEP-223 or the previous format. - * @throws NumberFormatException Illegal Java specification version number - */ - public JavaSpecificationVersion(@Nonnull String version) - throws NumberFormatException { - super(normalizeVersion(version)); - } - - @Nonnull - private static String normalizeVersion(@Nonnull String input) - throws NumberFormatException { - input = input.trim(); - if (input.startsWith("1.")) { - String[] split = input.split("\\."); - if (split.length != 2) { - throw new NumberFormatException("Old java.specification.version: There should be exactly one dot and something after it"); - } - input = split[1]; - } - - int majorVersion = Integer.parseInt(input); - if (majorVersion > 8) { - return input; - } else { - return "1." + input; - } - } - - -} diff --git a/src/test/java/ListPluginsAndVersionsJava6.java b/src/test/java/ListPluginsAndVersionsJava6.java deleted file mode 100644 index e83a0d85f..000000000 --- a/src/test/java/ListPluginsAndVersionsJava6.java +++ /dev/null @@ -1,30 +0,0 @@ -import io.jenkins.update_center.BaseMavenRepository; -import io.jenkins.update_center.DefaultMavenRepositoryBuilder; -import io.jenkins.update_center.HPI; -import io.jenkins.update_center.MavenRepository; -import io.jenkins.update_center.Plugin; -import io.jenkins.update_center.filters.JavaVersionPluginFilter; -import io.jenkins.update_center.util.JavaSpecificationVersion; -import io.jenkins.update_center.wrappers.FilteringRepository; - -import java.util.Collection; - -/** - * Test program that lists all the plugin names and their versions. - * - * @author Kohsuke Kawaguchi - */ -public class ListPluginsAndVersionsJava6 { - public static void main(String[] args) throws Exception{ - BaseMavenRepository r = DefaultMavenRepositoryBuilder.getInstance(); - MavenRepository f = new FilteringRepository().withPluginFilter(new JavaVersionPluginFilter(JavaSpecificationVersion.JAVA_6)).withBaseRepository(r); - - System.out.println(f.getJenkinsWarsByVersionNumber().firstKey()); - - Collection all = f.listJenkinsPlugins(); - for (Plugin p : all) { - HPI hpi = p.getLatest(); - System.out.printf("%s\t%s\n", p.getArtifactId(), hpi.toString()); - } - } -} diff --git a/src/test/java/io/jenkins/update_center/util/JavaSpecificationVersionTest.java b/src/test/java/io/jenkins/update_center/util/JavaSpecificationVersionTest.java deleted file mode 100644 index 704e9b325..000000000 --- a/src/test/java/io/jenkins/update_center/util/JavaSpecificationVersionTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2018 CloudBees, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package io.jenkins.update_center.util; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Tests for {@link JavaSpecificationVersion}. - */ -public class JavaSpecificationVersionTest { - - @Test - public void shouldParseValidNumbersCorrectly() { - assertSpecEquals(JavaSpecificationVersion.JAVA_6, "1.6"); - assertSpecEquals(JavaSpecificationVersion.JAVA_7, "1.7"); - assertSpecEquals(JavaSpecificationVersion.JAVA_8, "1.8"); - assertSpecEquals(JavaSpecificationVersion.JAVA_9, "9"); - assertSpecEquals(JavaSpecificationVersion.JAVA_10, "10"); - assertSpecEquals(JavaSpecificationVersion.JAVA_11, "11"); - } - - @Test - public void shouldParseOldSpecCorrectly() { - assertSpecEquals(JavaSpecificationVersion.JAVA_9, "1.9"); - assertSpecEquals(JavaSpecificationVersion.JAVA_10, "1.10"); - assertSpecEquals(JavaSpecificationVersion.JAVA_11, "1.11"); - assertSpecEquals(JavaSpecificationVersion.JAVA_12, "1.12"); - } - - @Test - public void shouldResolveIncorrectSpecs() { - assertSpecEquals(JavaSpecificationVersion.JAVA_8, "8"); - assertSpecEquals(JavaSpecificationVersion.JAVA_7, "7"); - assertSpecEquals(JavaSpecificationVersion.JAVA_5, "5"); - } - - @Test - public void shouldCompareVersionsProperly() { - Assert.assertTrue(JavaSpecificationVersion.JAVA_5.isOlderThan(JavaSpecificationVersion.JAVA_6)); - Assert.assertTrue(JavaSpecificationVersion.JAVA_6.isOlderThan(JavaSpecificationVersion.JAVA_7)); - Assert.assertTrue(JavaSpecificationVersion.JAVA_7.isOlderThan(JavaSpecificationVersion.JAVA_8)); - Assert.assertTrue(JavaSpecificationVersion.JAVA_8.isOlderThan(JavaSpecificationVersion.JAVA_9)); - Assert.assertTrue(JavaSpecificationVersion.JAVA_8.isNewerThan(JavaSpecificationVersion.JAVA_7)); - Assert.assertTrue(JavaSpecificationVersion.JAVA_9.isOlderThan(JavaSpecificationVersion.JAVA_10)); - Assert.assertTrue(JavaSpecificationVersion.JAVA_10.isOlderThan(JavaSpecificationVersion.JAVA_11)); - Assert.assertTrue(JavaSpecificationVersion.JAVA_10.isNewerThan(JavaSpecificationVersion.JAVA_8)); - } - - public void assertSpecEquals(JavaSpecificationVersion version, String value) { - JavaSpecificationVersion actualSpec = new JavaSpecificationVersion(value); - Assert.assertEquals("Wrong Java version", version, actualSpec); - } - - public void assertOlder(JavaSpecificationVersion version1, JavaSpecificationVersion version2) { - Assert.assertTrue(String.format("Version %s should be older than %s", version1, version2), - version1.isOlderThan(version2)); - } - - public void assertNewer(JavaSpecificationVersion version1, JavaSpecificationVersion version2) { - Assert.assertTrue(String.format("Version %s should be newer than %s", version1, version2), - version1.isNewerThan(version2)); - } -} diff --git a/src/test/java/io/jenkins/update_center/util/JavaVersionPluginFilterTest.java b/src/test/java/io/jenkins/update_center/util/JavaVersionPluginFilterTest.java deleted file mode 100644 index 9423c9229..000000000 --- a/src/test/java/io/jenkins/update_center/util/JavaVersionPluginFilterTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.jenkins.update_center.util; - -import io.jenkins.update_center.ArtifactCoordinates; -import io.jenkins.update_center.filters.JavaVersionPluginFilter; -import org.junit.Assert; -import org.junit.Test; -import io.jenkins.update_center.HPI; - -import javax.annotation.CheckForNull; - -public class JavaVersionPluginFilterTest { - private static class MockHPI extends HPI { - - private final JavaSpecificationVersion minimumJavaVersion; - - public MockHPI(ArtifactCoordinates info, JavaSpecificationVersion minimumJavaVersion) throws Exception { - super(null, info, null); - this.minimumJavaVersion = minimumJavaVersion; - } - - @CheckForNull - @Override - public JavaSpecificationVersion getMinimumJavaVersion() { - return minimumJavaVersion; - } - } - - @Test - public void testFilter() throws Exception { - ArtifactCoordinates info = new ArtifactCoordinates(null, "test-plugin", "1.0", null); - JavaSpecificationVersion version11 = new JavaSpecificationVersion("11"); - JavaSpecificationVersion version8 = new JavaSpecificationVersion("1.8"); - JavaSpecificationVersion version7 = new JavaSpecificationVersion("1.7"); - HPI java11Hpi = new MockHPI(info, version11); - HPI undefinedJavaHpi = new MockHPI(info, null); - - Assert.assertFalse(new JavaVersionPluginFilter(version11).shouldIgnore(java11Hpi)); - Assert.assertTrue(new JavaVersionPluginFilter(version8).shouldIgnore(java11Hpi)); - Assert.assertTrue(new JavaVersionPluginFilter(version7).shouldIgnore(java11Hpi)); - - Assert.assertFalse(new JavaVersionPluginFilter(version11).shouldIgnore(undefinedJavaHpi)); - Assert.assertFalse(new JavaVersionPluginFilter(version8).shouldIgnore(undefinedJavaHpi)); - Assert.assertFalse(new JavaVersionPluginFilter(version7).shouldIgnore(undefinedJavaHpi)); - } -}