From 369889296e77e8694912303ca558abdaad98b931 Mon Sep 17 00:00:00 2001 From: Igor Fedorenko Date: Tue, 25 Nov 2014 15:50:12 -0500 Subject: [PATCH] introduced RepositorySessionDecorator Signed-off-by: Igor Fedorenko --- .../DefaultProjectDependenciesResolver.java | 23 +++++++++--- .../project/RepositorySessionDecorator.java | 36 +++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/project/RepositorySessionDecorator.java diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java index 2a6be6d23b..1287eb14c6 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java @@ -21,6 +21,7 @@ package org.apache.maven.project; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.maven.RepositoryUtils; @@ -66,15 +67,21 @@ public class DefaultProjectDependenciesResolver @Requirement private RepositorySystem repoSystem; + @Requirement + private List decorators; + public DependencyResolutionResult resolve( DependencyResolutionRequest request ) throws DependencyResolutionException { - RequestTrace trace = RequestTrace.newChild( null, request ); + final RequestTrace trace = RequestTrace.newChild( null, request ); - DefaultDependencyResolutionResult result = new DefaultDependencyResolutionResult(); + final DefaultDependencyResolutionResult result = new DefaultDependencyResolutionResult(); - MavenProject project = request.getMavenProject(); + final MavenProject project = request.getMavenProject(); + final DependencyFilter filter = request.getResolutionFilter(); RepositorySystemSession session = request.getRepositorySession(); + ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry(); + if ( logger.isDebugEnabled() && session.getConfigProperties().get( DependencyManagerUtils.CONFIG_PROP_VERBOSE ) == null ) { @@ -82,9 +89,15 @@ public class DefaultProjectDependenciesResolver verbose.setConfigProperty( DependencyManagerUtils.CONFIG_PROP_VERBOSE, Boolean.TRUE ); session = verbose; } - DependencyFilter filter = request.getResolutionFilter(); - ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry(); + for ( RepositorySessionDecorator decorator : decorators ) + { + RepositorySystemSession decorated = decorator.decorate( project, session ); + if ( decorated != null ) + { + session = decorated; + } + } CollectRequest collect = new CollectRequest(); collect.setRootArtifact( RepositoryUtils.toArtifact( project.getArtifact() ) ); diff --git a/maven-core/src/main/java/org/apache/maven/project/RepositorySessionDecorator.java b/maven-core/src/main/java/org/apache/maven/project/RepositorySessionDecorator.java new file mode 100644 index 0000000000..679ee00885 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/project/RepositorySessionDecorator.java @@ -0,0 +1,36 @@ +package org.apache.maven.project; + +/* + * 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. + */ + +import org.eclipse.aether.RepositorySystemSession; + +/** + * Component interface that allows per-project customization of Aether repository system sessions. + * + * @since 3.2.4 + * @provisional This interface is part of work in progress and can be changed or removed without notice. + */ +public interface RepositorySessionDecorator +{ + /** + * Returns possibly {@code null} Aether repository system session to be used to resolve project dependencies. + */ + RepositorySystemSession decorate( MavenProject project, RepositorySystemSession session ); +}