diff --git a/tests/release-test/pom.xml b/tests/release-test/pom.xml index e9d42d2eaa..75ea7c6d9c 100644 --- a/tests/release-test/pom.xml +++ b/tests/release-test/pom.xml @@ -106,6 +106,12 @@ ${maven.version} provided + + org.apache.httpcomponents + httpclient + ${httpclient.version} + test + org.apache.maven.plugin-testing 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 01ba01e812..99c94eee3b 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 @@ -21,6 +21,7 @@ import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.impl.DefaultServiceLocator; import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.spi.connector.RepositoryConnectorFactory; import org.eclipse.aether.spi.connector.transport.TransporterFactory; import org.eclipse.aether.transport.http.HttpTransporterFactory; @@ -51,60 +52,97 @@ public class DownloadBomPomDependencies extends AbstractMojoTestCase { @Test public void testDownloadBomPomDependencies() throws Exception { -// RepositorySystem repositorySystem = (RepositorySystem) lookup(RepositorySystem.class.getName()); - DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); - locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); - locator.addService(TransporterFactory.class, HttpTransporterFactory.class); - RepositorySystem repositorySystem = locator.getService(RepositorySystem.class); - - RepositorySystemSession repoSession = getRepoSession(repositorySystem); - List remoteRepos = getRemoteRepositories(repoSession); - - Properties properties = MavenUtil.getMavenProperties(); - String jerseyVersion = MavenUtil.getJerseyVersion(properties); + MavenEnvironment mavenEnvironment = new MavenEnvironment(); List memberDeps = MavenUtil.streamJerseyJars().collect(Collectors.toList()); for (Dependency member : memberDeps) { - member.setVersion(jerseyVersion); - Artifact m = DependencyResolver.resolveArtifact(member, remoteRepos, repositorySystem, repoSession); + 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()); } } - private List getRemoteRepositories(RepositorySystemSession session) throws Exception { - File pom = lookupResourcesPom("/release-test-pom.xml"); - MavenExecutionRequest request = new DefaultMavenExecutionRequest(); - request.setPom(pom); - request.addActiveProfile("staging"); - ProjectBuildingRequest buildingRequest = request - .getProjectBuildingRequest() - .setRepositorySession(session) - .setResolveDependencies(true); - - ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); - ProjectBuildingResult projectBuildingResult = projectBuilder.build(pom, buildingRequest); - MavenProject project = projectBuildingResult.getProject(); - - List remoteArtifactRepositories = project.getRemoteProjectRepositories(); - return remoteArtifactRepositories; - } + @Test + public void testDownloadNonBomPomDependencies() throws Exception { + MavenEnvironment mavenEnvironment = new MavenEnvironment(); + MavenProject project = mavenEnvironment.getMavenProjectForResourceFile("/non-bom-pom-deps.xml"); + for (Dependency dependency : project.getDependencies()) { + if (dependency.getArtifactId().contains("jackson1") && mavenEnvironment.jerseyVersion.startsWith("3")) { + continue; + } - private static RepositorySystemSession getRepoSession(RepositorySystem repositorySystem) { - DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); - LocalRepository localRepo = new LocalRepository(MavenUtil.getLocalMavenRepository().getAbsolutePath()); - session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepo)); - return session; + Artifact m = mavenEnvironment.resolveArtifact(dependency); + System.out.append("Resolved ").append(dependency.getGroupId()).append(":") + .append(dependency.getArtifactId()).append(":") + .append(dependency.getVersion()).append(" to ").println(m.getFile().getName()); + } } - private static File lookupResourcesPom(String pomFile) throws URISyntaxException { - URL resource = DownloadBomPomDependencies.class.getResource(pomFile); - if (resource == null) { - throw new IllegalStateException("Pom file " + pomFile + " was not located on classpath!"); + private class MavenEnvironment { + private final RepositorySystem repositorySystem; + private final RepositorySystemSession repoSession; + private final List remoteRepos; + private final String jerseyVersion; + + MavenEnvironment() throws Exception { + DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); + locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); + locator.addService(TransporterFactory.class, HttpTransporterFactory.class); + + repositorySystem = locator.getService(RepositorySystem.class); + repoSession = getRepoSession(); + + remoteRepos = getRemoteRepositories(); + + Properties properties = MavenUtil.getMavenProperties(); + jerseyVersion = MavenUtil.getJerseyVersion(properties); + } + + Artifact resolveArtifact(Dependency dependency) throws ArtifactResolutionException { + dependency.setVersion(jerseyVersion); + return DependencyResolver.resolveArtifact(dependency, remoteRepos, repositorySystem, repoSession); + } + + private List getRemoteRepositories() throws Exception { + MavenProject project = getMavenProjectForResourceFile("/release-test-pom.xml"); + List remoteArtifactRepositories = project.getRemoteProjectRepositories(); + return remoteArtifactRepositories; + } + + private MavenProject getMavenProjectForResourceFile(String resourceFile) + throws Exception { + File pom = lookupResourcesPom(resourceFile); + MavenExecutionRequest request = new DefaultMavenExecutionRequest(); + request.setPom(pom); + request.addActiveProfile("staging"); + ProjectBuildingRequest buildingRequest = request + .getProjectBuildingRequest() + .setRepositorySession(repoSession) + .setResolveDependencies(true); + + ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); + ProjectBuildingResult projectBuildingResult = projectBuilder.build(pom, buildingRequest); + MavenProject project = projectBuildingResult.getProject(); + + return project; } - File file = new File(resource.toURI()); - if (!file.exists()) { - throw new IllegalStateException("Cannot locate test pom xml file!"); + + private RepositorySystemSession getRepoSession() { + DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); + LocalRepository localRepo = new LocalRepository(MavenUtil.getLocalMavenRepository().getAbsolutePath()); + session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepo)); + return session; + } + + private File lookupResourcesPom(String pomFile) throws URISyntaxException { + URL resource = DownloadBomPomDependencies.class.getResource(pomFile); + if (resource == null) { + throw new IllegalStateException("Pom file " + pomFile + " was not located on classpath!"); + } + File file = new File(resource.toURI()); + if (!file.exists()) { + throw new IllegalStateException("Cannot locate test pom xml file!"); + } + return file; } - return file; } } diff --git a/tests/release-test/src/test/resources/non-bom-pom-deps.xml b/tests/release-test/src/test/resources/non-bom-pom-deps.xml new file mode 100644 index 0000000000..7ced6b0ded --- /dev/null +++ b/tests/release-test/src/test/resources/non-bom-pom-deps.xml @@ -0,0 +1,77 @@ + + + + + 4.0.0 + + + org.eclipse.ee4j + project + 1.0.8 + + + org.glassfish.jersey.tests + release-test-test + 0.0.1-SNAPSHOT + + + + org.glassfish.jersey.media + jersey-media-json-jackson1 + 2.27 + + + org.glassfish.jersey.security + oauth1-client + 2.27 + + + org.glassfish.jersey.security + oauth1-server + 2.27 + + + org.glassfish.jersey.security + oauth1-signature + 2.27 + + + org.glassfish.jersey.incubator + jersey-injectless-client + 2.27 + + + org.glassfish.jersey.incubator + jersey-open-tracing + 2.27 + + + org.glassfish.jersey.media + jersey-media-kryo + 2.27 + + + org.glassfish.jersey.ext + jersey-declarative-linking + 2.27 + + + + \ No newline at end of file diff --git a/tests/release-test/src/test/resources/release-test-pom.xml b/tests/release-test/src/test/resources/release-test-pom.xml index d8aa48608e..4fac65202a 100644 --- a/tests/release-test/src/test/resources/release-test-pom.xml +++ b/tests/release-test/src/test/resources/release-test-pom.xml @@ -1,7 +1,7 @@