From 4f0ae8f111aa97cf529714c643996f566bd68a7b Mon Sep 17 00:00:00 2001 From: jansupol Date: Mon, 27 May 2024 22:04:09 +0200 Subject: [PATCH] More release checks Signed-off-by: jansupol --- .../test/artifacts/ClassVersionChecker.java | 11 +++- .../test/artifacts/DependencyResolver.java | 26 ++++++++- .../jersey/test/artifacts/MavenUtil.java | 29 ++++++++-- .../artifacts/DownloadBomPomDependencies.java | 26 ++++++++- .../test/artifacts/LegalDocsIncludedTest.java | 10 +++- .../jersey/test/artifacts/ManifestTest.java | 22 +++++++- .../test/artifacts/MultiReleaseTest.java | 54 ++++++++++++++++++- 7 files changed, 167 insertions(+), 11 deletions(-) diff --git a/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/ClassVersionChecker.java b/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/ClassVersionChecker.java index 743d609627..8a97941ab0 100644 --- a/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/ClassVersionChecker.java +++ b/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/ClassVersionChecker.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -27,7 +27,14 @@ class ClassVersionChecker { static TestResult checkClassVersion(JarFile jar, JarEntry entry, Properties properties) throws IOException { final String jerseyVersion = MavenUtil.getJerseyVersion(properties); - final int minVersion = jerseyVersion.startsWith("3.1") ? 11 : 8; + final int minVersion; + if (jerseyVersion.startsWith("4")) { + minVersion = 17; + } else if (jerseyVersion.startsWith("3.1")) { + minVersion = 11; + } else { + minVersion = 8; + } return checkClassVersion(jar.getInputStream(entry), jar.getName() + File.separator + entry.getName(), minVersion); } diff --git a/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/DependencyResolver.java b/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/DependencyResolver.java index b1a7ee3bba..eeea9822e6 100644 --- a/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/DependencyResolver.java +++ b/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/DependencyResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -42,4 +42,28 @@ static Artifact resolveArtifact(org.apache.maven.model.Dependency d, List remoteRepos, + RepositorySystem repoSystem, RepositorySystemSession repoSession) + throws ArtifactResolutionException { + DefaultArtifact artifact = new DefaultArtifact( + d.getGroupId(), d.getArtifactId(), "sources", d.getType(), d.getVersion() + ); + ArtifactRequest request = new ArtifactRequest(); + request.setArtifact(artifact); + request.setRepositories(remoteRepos); + return repoSystem.resolveArtifact(repoSession, request).getArtifact(); + } + + static Artifact resolveJavadoc(org.apache.maven.model.Dependency d, List remoteRepos, + RepositorySystem repoSystem, RepositorySystemSession repoSession) + throws ArtifactResolutionException { + DefaultArtifact artifact = new DefaultArtifact( + d.getGroupId(), d.getArtifactId(), "javadoc", d.getType(), d.getVersion() + ); + ArtifactRequest request = new ArtifactRequest(); + request.setArtifact(artifact); + request.setRepositories(remoteRepos); + return repoSystem.resolveArtifact(repoSession, request).getArtifact(); + } } \ No newline at end of file diff --git a/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/MavenUtil.java b/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/MavenUtil.java index 20e77377b7..98d4616fcf 100644 --- a/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/MavenUtil.java +++ b/tests/release-test/src/main/java/org/glassfish/jersey/test/artifacts/MavenUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.List; import java.util.Properties; +import java.util.stream.Collectors; import java.util.stream.Stream; public final class MavenUtil { @@ -37,7 +38,7 @@ public final class MavenUtil { private static final String PROJECT_VERSION = "project.version"; static File getArtifactJar(File repositoryRoot, Dependency dependency, Properties properties) { - return getArtifactFile(repositoryRoot, dependency, properties, "jar"); + return getArtifactFile(repositoryRoot, dependency, properties, dependency.getType()); } private static File getArtifactFile(File repositoryRoot, Dependency dependency, Properties properties, String extension) { @@ -52,7 +53,11 @@ private static File getArtifactFile(File repositoryRoot, Dependency dependency, } String version = MavenUtil.getDependencyVersion(dependency, properties); fileSuffix.append(version).append(File.separator); - fileSuffix.append(dependency.getArtifactId()).append('-').append(version).append(".").append(extension); + fileSuffix.append(dependency.getArtifactId()).append('-').append(version); + if (dependency.getClassifier() != null) { + fileSuffix.append('-').append(dependency.getClassifier()); + } + fileSuffix.append(".").append(extension); return new File(repositoryRoot, fileSuffix.toString()); } @@ -103,7 +108,16 @@ static Stream keepJerseyJars(Stream stream, DependencyPa static Stream streamJerseyJars() throws IOException, XmlPullParserException { Model model = getModelFromFile("pom.xml"); List deps = getBomPomDependencies(model); + return streamJerseyJars(deps); + } + static Stream streamJerseySources() throws IOException, XmlPullParserException { + Model model = getModelFromFile("pom.xml"); + List deps = getBomPomSources(model); + return streamJerseyJars(deps); + } + + private static Stream streamJerseyJars(List deps) throws IOException, XmlPullParserException { return deps.stream() .filter(dep -> dep.getGroupId().startsWith("org.glassfish.jersey")) .filter(dep -> dep.getType().equals("jar")); @@ -139,6 +153,15 @@ private static List getBomPomDependencies(Model model) throws IOExce return bomPomModel.getDependencyManagement().getDependencies(); } + private static List getBomPomSources(Model model) throws XmlPullParserException, IOException { + return getBomPomDependencies(model).stream() + .map(dependency -> { + dependency.setClassifier("sources"); + return dependency; + }) + .collect(Collectors.toList()); + } + static String getJerseyVersion(Properties properties) { String property = properties.getProperty(JERSEY_VERSION); // when it is in the pom.file if (property == null || property.startsWith("${")) { diff --git a/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/DownloadBomPomDependencies.java b/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/DownloadBomPomDependencies.java index 99c94eee3b..6a74f0787c 100644 --- a/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/DownloadBomPomDependencies.java +++ b/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/DownloadBomPomDependencies.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -58,6 +58,12 @@ public void testDownloadBomPomDependencies() throws Exception { Artifact m = mavenEnvironment.resolveArtifact(member); System.out.append("Resolved ").append(member.getGroupId()).append(":").append(member.getArtifactId()).append(":") .append(member.getVersion()).append(" to ").println(m.getFile().getName()); + m = mavenEnvironment.resolveSource(member); + System.out.append("Resolved sources ").append(member.getGroupId()).append(":").append(member.getArtifactId()) + .append(":").append(member.getVersion()).append(" to ").println(m.getFile().getName()); + m = mavenEnvironment.resolveJavadoc(member); + System.out.append("Resolved javadoc ").append(member.getGroupId()).append(":").append(member.getArtifactId()) + .append(":").append(member.getVersion()).append(" to ").println(m.getFile().getName()); } } @@ -74,6 +80,14 @@ public void testDownloadNonBomPomDependencies() throws Exception { System.out.append("Resolved ").append(dependency.getGroupId()).append(":") .append(dependency.getArtifactId()).append(":") .append(dependency.getVersion()).append(" to ").println(m.getFile().getName()); + m = mavenEnvironment.resolveSource(dependency); + System.out.append("Resolved source ").append(dependency.getGroupId()).append(":") + .append(dependency.getArtifactId()).append(":") + .append(dependency.getVersion()).append(" to ").println(m.getFile().getName()); + m = mavenEnvironment.resolveJavadoc(dependency); + System.out.append("Resolved javadoc ").append(dependency.getGroupId()).append(":") + .append(dependency.getArtifactId()).append(":") + .append(dependency.getVersion()).append(" to ").println(m.getFile().getName()); } } @@ -102,6 +116,16 @@ Artifact resolveArtifact(Dependency dependency) throws ArtifactResolutionExcepti return DependencyResolver.resolveArtifact(dependency, remoteRepos, repositorySystem, repoSession); } + Artifact resolveSource(Dependency dependency) throws ArtifactResolutionException { + dependency.setVersion(jerseyVersion); + return DependencyResolver.resolveSource(dependency, remoteRepos, repositorySystem, repoSession); + } + + Artifact resolveJavadoc(Dependency dependency) throws ArtifactResolutionException { + dependency.setVersion(jerseyVersion); + return DependencyResolver.resolveJavadoc(dependency, remoteRepos, repositorySystem, repoSession); + } + private List getRemoteRepositories() throws Exception { MavenProject project = getMavenProjectForResourceFile("/release-test-pom.xml"); List remoteArtifactRepositories = project.getRemoteProjectRepositories(); diff --git a/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/LegalDocsIncludedTest.java b/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/LegalDocsIncludedTest.java index 74e0281a84..8c784af933 100644 --- a/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/LegalDocsIncludedTest.java +++ b/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/LegalDocsIncludedTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -41,7 +41,15 @@ public void testLegalFiles() throws IOException, XmlPullParserException { List jars = MavenUtil.streamJerseyJars() .map(dependency -> MavenUtil.getArtifactJar(localRepository, dependency, properties)) .collect(Collectors.toList()); + testLegalFiles(jars, testResult); + jars = MavenUtil.streamJerseySources() + .map(dependency -> MavenUtil.getArtifactJar(localRepository, dependency, properties)) + .collect(Collectors.toList()); + testLegalFiles(jars, testResult); + } + + private void testLegalFiles(List jars, TestResult testResult) throws IOException { for (File jar : jars) { for (String filename : new String[]{LICENSE_FILE, NOTICE_FILE}) { JarFile jarFile = new JarFile(jar); diff --git a/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/ManifestTest.java b/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/ManifestTest.java index 0c77d69c3c..a5208681dc 100644 --- a/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/ManifestTest.java +++ b/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/ManifestTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -25,6 +25,7 @@ import java.util.Properties; import java.util.jar.JarFile; import java.util.stream.Collectors; +import java.util.zip.ZipEntry; public class ManifestTest { private static final File localRepository = MavenUtil.getLocalMavenRepository(); @@ -63,6 +64,25 @@ public void testHasOsgiManifest() throws IOException, XmlPullParserException { } } + for (File jar : jars) { + JarFile jarFile = new JarFile(jar); + String value = jarFile.getManifest().getMainAttributes().getValue("Multi-Release"); +// System.out.append("Accessing META-INF/versions").append(" of ").println(jar.getName()); + ZipEntry versions = jarFile.getEntry("META-INF/versions/"); + if (versions != null) { + if (!"true".equals(value)) { + testResult.exception().append("'Multi-Release: true' not set for ").println(jar.getName()); + } else { + testResult.ok().append("'Multi-Release: true' set for ").println(jar.getName()); + } + } else { + if ("true".equals(value)) { + testResult.exception().append("'Multi-Release: true' SET for ").println(jar.getName()); + } + } + + } + //Assertions.assertTrue(testResult.result(), "Some error occurred, see previous messages"); Assert.assertTrue("Some error occurred, see previous messages", testResult.result()); } diff --git a/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/MultiReleaseTest.java b/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/MultiReleaseTest.java index 288932a58c..317118d207 100644 --- a/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/MultiReleaseTest.java +++ b/tests/release-test/src/test/java/org/glassfish/jersey/test/artifacts/MultiReleaseTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -40,12 +40,14 @@ public class MultiReleaseTest { private static final DependencyPair[] jdk11multiRelease = jdk11multiRelease(properties); private static final DependencyPair[] jdk12multiRelease = jdk12multiRelease(properties); private static final DependencyPair[] jdk17multiRelease = jdk17multiRelease(properties); + private static final DependencyPair[] jdk21multiRelease = jdk21multiRelease(properties); @Test public void testIsJdkMultiRelease() throws IOException, XmlPullParserException { TestResult result = testJdkVersions("11", jdk11multiRelease); result.append(testJdkVersions("12", jdk12multiRelease)); result.append(testJdkVersions("17", jdk17multiRelease)); + result.append(testJdkVersions("21", jdk21multiRelease)); //Assertions.assertTrue(result.result(), "Some error occurred, see previous messages"); Assert.assertTrue("Some error occurred, see previous messages", result.result()); } @@ -54,6 +56,7 @@ private static TestResult testJdkVersions(String version, DependencyPair... depe throws XmlPullParserException, IOException { final TestResult result = new TestResult(); if (dependencies == null || dependencies.length == 0) { + System.out.append("No dependencies found for jdk ").println(version); return result; } @@ -81,6 +84,7 @@ private static TestResult testJdkVersions(String version, DependencyPair... depe result.exception().append("Not a multirelease jar ").append(jar.getName()).println("!"); } ZipEntry versions = jarFile.getEntry("META-INF/versions/" + version); + System.out.append("Accessing META-INF/versions/").append(version).append(" of ").println(jar.getName()); if (versions == null) { result.exception().append("No classes for JDK ").append(version).append(" for ").println(jar.getName()); } @@ -95,6 +99,26 @@ private static TestResult testJdkVersions(String version, DependencyPair... depe result.append(ClassVersionChecker.checkClassVersion(jarFile, jarEntry, properties)); } + // Verify that number of multirelease jars matches the expected dependencies + StringBuilder multi = new StringBuilder(); + int multiCnt = 0; + List allFiles = MavenUtil.streamJerseyJars() + .map(dependency -> MavenUtil.getArtifactJar(localRepository, dependency, properties)) + .collect(Collectors.toList()); + for (File jar : files) { + JarFile jarFile = new JarFile(jar); + if (jarFile.isMultiRelease()) { + multiCnt++; + multi.append("Multirelease jar ").append(jar.getName()).append('\n'); + } + } + if (files.size() == multiCnt) { + result.ok().println("There is expected number of multirelease jars"); + } else { + result.exception().println("There is unexpected number of multirelease jars:"); + result.exception().append(multi).println(""); + } + return result; } @@ -136,12 +160,38 @@ private static DependencyPair[] jdk12multiRelease(Properties properties) { private static DependencyPair[] jdk17multiRelease(Properties properties) { String jerseyVersion = MavenUtil.getJerseyVersion(properties); - if (jerseyVersion.startsWith("3")) { + if (jerseyVersion.startsWith("3.0")) { + return new DependencyPair[] { + new DependencyPair("org.glassfish.jersey.connectors", "jersey-helidon-connector"), + new DependencyPair("org.glassfish.jersey.ext", "jersey-spring6") + }; + } else if (jerseyVersion.startsWith("3")) { return new DependencyPair[] { new DependencyPair("org.glassfish.jersey.connectors", "jersey-helidon-connector"), + new DependencyPair("org.glassfish.jersey.connectors", "jersey-jetty-connector"), + new DependencyPair("org.glassfish.jersey.connectors", "jersey-jetty-http2-connector"), + new DependencyPair("org.glassfish.jersey.containers", "jersey-container-jetty-http"), + new DependencyPair("org.glassfish.jersey.containers", "jersey-container-jetty-http2"), + new DependencyPair("org.glassfish.jersey.test-framework.providers", "jersey-test-framework-provider-jetty"), + new DependencyPair("org.glassfish.jersey.test-framework.providers", + "jersey-test-framework-provider-jetty-http2"), new DependencyPair("org.glassfish.jersey.ext", "jersey-spring6") }; } return new DependencyPair[]{}; } + + private static DependencyPair[] jdk21multiRelease(Properties properties) { + String jerseyVersion = MavenUtil.getJerseyVersion(properties); + if (jerseyVersion.startsWith("4")) { + return new DependencyPair[]{ + new DependencyPair("org.glassfish.jersey.core", "jersey-common") + }; + } else { + return new DependencyPair[]{ + new DependencyPair("org.glassfish.jersey.bundles", "jaxrs-ri"), + new DependencyPair("org.glassfish.jersey.core", "jersey-common") + }; + } + } }