This is an automated email from the ASF dual-hosted git repository. tibordigana pushed a commit to branch buildfix in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit f5fa57ca558bee21ef29ca91758bf59bcbfd4820 Author: tibordigana <[email protected]> AuthorDate: Sun Jul 14 10:44:34 2019 +0200 temporal fix for hanging Maven builds --- .../src/it/resolve-artifact/invoker.properties | 19 +++++++ .../eclipse/aether/internal/impl/collect/Args.java | 4 +- .../aether/internal/impl/collect/DataPool.java | 62 +++++++++++++--------- .../impl/collect/DefaultDependencyCollector.java | 10 ++-- 4 files changed, 61 insertions(+), 34 deletions(-) diff --git a/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/it/resolve-artifact/invoker.properties b/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/it/resolve-artifact/invoker.properties new file mode 100644 index 0000000..c256d0f --- /dev/null +++ b/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/it/resolve-artifact/invoker.properties @@ -0,0 +1,19 @@ +# +# 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. +# +invoker.maven.version=3.5.0+ diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/Args.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/Args.java index e2c1229..56f7250 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/Args.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/Args.java @@ -27,7 +27,7 @@ import org.eclipse.aether.collection.CollectRequest; import org.eclipse.aether.util.ConfigUtils; import org.eclipse.aether.util.graph.manager.DependencyManagerUtils; -class Args +final class Args { final RepositorySystemSession session; @@ -42,7 +42,7 @@ class Args final NodeStack nodes; - final DefaultDependencyCollectionContext collectionContext; + final DefaultDependencyCollectionContext collectionContext; // unused ??? final DefaultVersionFilterContext versionContext; diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java index 10e9ab6..fedcc3a 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java @@ -20,11 +20,11 @@ package org.eclipse.aether.internal.impl.collect; */ import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -61,24 +61,28 @@ final class DataPool private static final String DESCRIPTORS = DataPool.class.getName() + "$Descriptors"; - public static final Future<ArtifactDescriptorResult> NO_DESCRIPTOR = + static final Future<ArtifactDescriptorResult> NO_DESCRIPTOR = new FutureResult<>( new ArtifactDescriptorResult( new ArtifactDescriptorRequest() ) ); - private ObjectPool<Artifact> artifacts; + private final ObjectPool<Artifact> artifacts; - private ObjectPool<Dependency> dependencies; + private final ObjectPool<Dependency> dependencies; - private Map<Object, Descriptor> descriptors; + private final Map<Object, Descriptor> descriptors; - private Map<Object, Constraint> constraints = new HashMap<>(); + private final Map<Object, Constraint> constraints = new ConcurrentHashMap<>(); - private Map<Object, List<DependencyNode>> nodes = new HashMap<>( 256 ); + private final Map<Object, List<DependencyNode>> nodes = new ConcurrentHashMap<>( 256 ); @SuppressWarnings( "unchecked" ) DataPool( RepositorySystemSession session ) { RepositoryCache cache = session.getCache(); + ObjectPool<Artifact> artifacts = null; + ObjectPool<Dependency> dependencies = null; + Map<Object, Descriptor> descriptors = null; + if ( cache != null ) { artifacts = (ObjectPool<Artifact>) cache.get( session, ARTIFACT_POOL ); @@ -95,6 +99,8 @@ final class DataPool } } + this.artifacts = artifacts; + if ( dependencies == null ) { dependencies = new ObjectPool<>(); @@ -104,6 +110,8 @@ final class DataPool } } + this.dependencies = dependencies; + if ( descriptors == null ) { descriptors = Collections.synchronizedMap( new WeakHashMap<Object, Descriptor>( 256 ) ); @@ -112,24 +120,26 @@ final class DataPool cache.put( session, DESCRIPTORS, descriptors ); } } + + this.descriptors = descriptors; } - public Artifact intern( Artifact artifact ) + Artifact intern( Artifact artifact ) { return artifacts.intern( artifact ); } - public Dependency intern( Dependency dependency ) + Dependency intern( Dependency dependency ) { return dependencies.intern( dependency ); } - public Object toKey( ArtifactDescriptorRequest request ) + Object toKey( ArtifactDescriptorRequest request ) { return request.getArtifact(); } - public Future<ArtifactDescriptorResult> getDescriptor( Object key, ArtifactDescriptorRequest request ) + Future<ArtifactDescriptorResult> getDescriptor( Object key, ArtifactDescriptorRequest request ) { Descriptor descriptor = descriptors.get( key ); if ( descriptor != null ) @@ -139,22 +149,22 @@ final class DataPool return null; } - public void putDescriptor( Object key, Future<ArtifactDescriptorResult> futureResult ) + void putDescriptor( Object key, Future<ArtifactDescriptorResult> futureResult ) { descriptors.put( key, new GoodDescriptor( futureResult ) ); } - public void putDescriptor( Object key, ArtifactDescriptorException exception ) + void putDescriptor( Object key, ArtifactDescriptorException exception ) // unused param ???, type better method name { descriptors.put( key, BadDescriptor.INSTANCE ); } - public Object toKey( VersionRangeRequest request ) + Object toKey( VersionRangeRequest request ) { return new ConstraintKey( request ); } - public VersionRangeResult getConstraint( Object key, VersionRangeRequest request ) + VersionRangeResult getConstraint( Object key, VersionRangeRequest request ) { Constraint constraint = constraints.get( key ); if ( constraint != null ) @@ -164,33 +174,33 @@ final class DataPool return null; } - public void putConstraint( Object key, VersionRangeResult result ) + void putConstraint( Object key, VersionRangeResult result ) { constraints.put( key, new Constraint( result ) ); } - public Object toKey( Artifact artifact, DefaultDependencyCollectionContext context ) + Object toKey( Artifact artifact, DefaultDependencyCollectionContext context ) { return new GraphKey( artifact, context.getRepositories(), context.getDepSelector(), context.getDepManager(), context.getDepTraverser(), context.getVerFilter() ); } - public List<DependencyNode> getChildren( Object key ) + List<DependencyNode> getChildren( Object key ) { return nodes.get( key ); } - public void putChildren( Object key, List<DependencyNode> children ) + void putChildren( Object key, List<DependencyNode> children ) { nodes.put( key, children ); } - abstract static class Descriptor + private abstract static class Descriptor { public abstract Future<ArtifactDescriptorResult> toResult( ArtifactDescriptorRequest request ); } - static final class GoodDescriptor + private static final class GoodDescriptor extends Descriptor { Future<ArtifactDescriptorResult> futureResult; @@ -247,7 +257,7 @@ final class DataPool } } - static final class BadDescriptor + private static final class BadDescriptor extends Descriptor { static final BadDescriptor INSTANCE = new BadDescriptor(); @@ -258,7 +268,7 @@ final class DataPool } } - static final class Constraint + private static final class Constraint { final VersionRepo[] repositories; @@ -276,7 +286,7 @@ final class DataPool } } - public VersionRangeResult toResult( VersionRangeRequest request ) + VersionRangeResult toResult( VersionRangeRequest request ) { VersionRangeResult result = new VersionRangeResult( request ); for ( VersionRepo vr : repositories ) @@ -302,7 +312,7 @@ final class DataPool } } - static final class ConstraintKey + private static final class ConstraintKey { private final Artifact artifact; @@ -376,7 +386,7 @@ final class DataPool } } - static final class GraphKey + private static final class GraphKey { private final Artifact artifact; diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DefaultDependencyCollector.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DefaultDependencyCollector.java index 9d37435..d4647e4 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DefaultDependencyCollector.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DefaultDependencyCollector.java @@ -36,10 +36,9 @@ import static java.util.Objects.requireNonNull; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.Future; -import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.inject.Named; @@ -147,9 +146,8 @@ public class DefaultDependencyCollector { int numThreads = ConfigUtils.getInteger( session, DEFAULT_THREADS, CONFIG_PROP_THREADS ); LOGGER.debug( "{} = {} ", CONFIG_PROP_THREADS, numThreads ); - ThreadPoolExecutor executor = new ThreadPoolExecutor( - numThreads, numThreads, 3L, TimeUnit.SECONDS, - new LinkedBlockingQueue<Runnable>(), new WorkerThreadFactory( "artifact-descriptor-resolver" ) ); + ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newCachedThreadPool( + new WorkerThreadFactory( "artifact-descriptor-resolver" ) ); try { return collectDependenciesWithExecutor( session, request, executor ); @@ -517,7 +515,7 @@ public class DefaultDependencyCollector } } - private boolean processDependencyVersion( DependencyContext dc ) + private boolean processDependencyVersion( DependencyContext dc ) // warning - returned value is never used !!! { Args args = dc.context.getArgs(); Results results = dc.context.getResults();
