Skip to content

Commit

Permalink
More release checks
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed May 27, 2024
1 parent 63506be commit 4f0ae8f
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,4 +42,28 @@ static Artifact resolveArtifact(org.apache.maven.model.Dependency d, List<Remote
request.setRepositories(remoteRepos);
return repoSystem.resolveArtifact(repoSession, request).getArtifact();
}

static Artifact resolveSource(org.apache.maven.model.Dependency d, List<RemoteRepository> 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<RemoteRepository> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand All @@ -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());
}

Expand Down Expand Up @@ -103,7 +108,16 @@ static Stream<Dependency> keepJerseyJars(Stream<Dependency> stream, DependencyPa
static Stream<Dependency> streamJerseyJars() throws IOException, XmlPullParserException {
Model model = getModelFromFile("pom.xml");
List<Dependency> deps = getBomPomDependencies(model);
return streamJerseyJars(deps);
}

static Stream<Dependency> streamJerseySources() throws IOException, XmlPullParserException {
Model model = getModelFromFile("pom.xml");
List<Dependency> deps = getBomPomSources(model);
return streamJerseyJars(deps);
}

private static Stream<Dependency> streamJerseyJars(List<Dependency> deps) throws IOException, XmlPullParserException {
return deps.stream()
.filter(dep -> dep.getGroupId().startsWith("org.glassfish.jersey"))
.filter(dep -> dep.getType().equals("jar"));
Expand Down Expand Up @@ -139,6 +153,15 @@ private static List<Dependency> getBomPomDependencies(Model model) throws IOExce
return bomPomModel.getDependencyManagement().getDependencies();
}

private static List<Dependency> 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("${")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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<RemoteRepository> getRemoteRepositories() throws Exception {
MavenProject project = getMavenProjectForResourceFile("/release-test-pom.xml");
List<RemoteRepository> remoteArtifactRepositories = project.getRemoteProjectRepositories();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,7 +41,15 @@ public void testLegalFiles() throws IOException, XmlPullParserException {
List<File> 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<File> jars, TestResult testResult) throws IOException {
for (File jar : jars) {
for (String filename : new String[]{LICENSE_FILE, NOTICE_FILE}) {
JarFile jarFile = new JarFile(jar);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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());
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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());
}
Expand All @@ -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<File> 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;
}

Expand Down Expand Up @@ -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")
};
}
}
}

0 comments on commit 4f0ae8f

Please sign in to comment.