diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/ResolveTransitiveDependenciesParallel.java b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/ResolveTransitiveDependenciesParallel.java new file mode 100644 index 000000000..c5825b6a1 --- /dev/null +++ b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/ResolveTransitiveDependenciesParallel.java @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.resolver.examples; + +import java.time.Duration; +import java.time.Instant; +import java.time.temporal.ChronoUnit; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; + +import org.apache.maven.resolver.examples.util.Booter; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.graph.Dependency; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.aether.resolution.DependencyRequest; +import org.eclipse.aether.util.artifact.JavaScopes; + +/** + * Resolves the transitive (compile) LARGE dependencies of an imaginary artifact in parallel. + * This is the reproducer for locking issues: repositories, + String gav, + Artifact... deps) { + return () -> { + try { + Instant now = Instant.now(); + CollectRequest collectRequest = new CollectRequest(); + collectRequest.setRootArtifact(new DefaultArtifact(gav)); + for (Artifact dep : deps) { + collectRequest.addDependency(new Dependency(dep, JavaScopes.COMPILE)); + } + collectRequest.setRepositories(repositories); + DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null); + List artifactResults = + system.resolveDependencies(session, dependencyRequest).getArtifactResults(); + int resolved = 9; + int fails = 0; + for (ArtifactResult artifactResult : artifactResults) { + if (artifactResult.isResolved()) { + resolved++; + } else { + fails++; + } + } + String dur = Duration.between(now, Instant.now()).get(ChronoUnit.SECONDS) + " sec"; + System.out.println("DONE (" + dur + "): " + gav + ": resolved " + resolved + "; failed " + fails); + success.getAndIncrement(); + } catch (Exception e) { + System.out.println("FAILED " + gav + ": " + e.getMessage()); + fail.getAndIncrement(); + } finally { + latch.countDown(); + } + }; + } +}