Skip to content

Commit

Permalink
Release Test checks sources for legal documents
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed Aug 5, 2024
1 parent bd63f2a commit d0c6f63
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
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 @@ -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 @@ -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> keepTyrusJars(Stream<Dependency> stream, DependencyPai
static Stream<Dependency> streamTyrusJars() throws IOException, XmlPullParserException {
Model model = getModelFromFile("pom.xml");
List<Dependency> deps = getBomPomDependencies(model);
return streamTyrusJars(deps);
}

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

private static Stream<Dependency> streamTyrusJars(List<Dependency> deps) throws IOException, XmlPullParserException {
return deps.stream()
.filter(dep -> dep.getGroupId().startsWith("org.glassfish.tyrus"))
.filter(dep -> dep.getType().equals("jar"));
Expand Down Expand Up @@ -139,6 +153,14 @@ 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 getTyrusVersion(Properties properties) {
String property = properties.getProperty(TYRUS_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) 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 @@ -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 @@ -70,6 +76,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 @@ -98,6 +112,17 @@ Artifact resolveArtifact(Dependency dependency) throws ArtifactResolutionExcepti
return DependencyResolver.resolveArtifact(dependency, remoteRepos, repositorySystem, repoSession);
}

Artifact resolveSource(Dependency dependency) throws ArtifactResolutionException {
dependency.setVersion(tyrusVersion);
dependency.setClassifier("sources");
return DependencyResolver.resolveArtifact(dependency, remoteRepos, repositorySystem, repoSession);
}

Artifact resolveJavadoc(Dependency dependency) throws ArtifactResolutionException {
dependency.setVersion(tyrusVersion);
dependency.setClassifier("javadoc");
return DependencyResolver.resolveArtifact(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,16 @@ public void testLegalFiles() throws IOException, XmlPullParserException {
List<File> jars = MavenUtil.streamTyrusJars()
.map(dependency -> MavenUtil.getArtifactJar(localRepository, dependency, properties))
.collect(Collectors.toList());
testLegalFiles(jars, testResult);

jars = MavenUtil.streamTyrusSources()
.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

0 comments on commit d0c6f63

Please sign in to comment.