mirror of https://github.com/apache/maven.git
[MNG-4561] [regression] network settings are not applied to repositories from plugin dependencies
[MNG-4528] [regression] mvn deploy ignores proxy settings o Revised original solution to generally exclude wagons pulled in transitively via Maven core artifacts git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@909934 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fd5683b936
commit
862e8875d1
|
@ -25,7 +25,6 @@ import java.util.HashSet;
|
|||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
||||
|
|
|
@ -29,14 +29,11 @@ import java.io.PrintStream;
|
|||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.apache.maven.ArtifactFilterManager;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
|
@ -45,11 +42,8 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
|||
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.classrealm.ClassRealmManager;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.monitor.logging.DefaultLog;
|
||||
import org.apache.maven.plugin.ContextEnabled;
|
||||
|
@ -120,15 +114,15 @@ public class DefaultMavenPluginManager
|
|||
@Requirement
|
||||
private ResolutionErrorHandler resolutionErrorHandler;
|
||||
|
||||
@Requirement
|
||||
private ArtifactFilterManager artifactFilterManager;
|
||||
|
||||
@Requirement
|
||||
private PluginDescriptorCache pluginDescriptorCache;
|
||||
|
||||
@Requirement
|
||||
private PluginRealmCache pluginRealmCache;
|
||||
|
||||
@Requirement
|
||||
private PluginDependenciesResolver pluginDependenciesResolver;
|
||||
|
||||
private PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
|
||||
|
||||
public synchronized PluginDescriptor getPluginDescriptor( Plugin plugin, RepositoryRequest repositoryRequest )
|
||||
|
@ -409,90 +403,7 @@ public class DefaultMavenPluginManager
|
|||
ArtifactFilter dependencyFilter )
|
||||
throws PluginResolutionException
|
||||
{
|
||||
Set<Artifact> overrideArtifacts = new LinkedHashSet<Artifact>();
|
||||
for ( Dependency dependency : plugin.getDependencies() )
|
||||
{
|
||||
overrideArtifacts.add( repositorySystem.createDependencyArtifact( dependency ) );
|
||||
}
|
||||
|
||||
ArtifactFilter collectionFilter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM );
|
||||
|
||||
/*
|
||||
* NOTE: This is a hack to support maven-deploy-plugin:[2.2.1,2.4] which has dependencies on old/buggy wagons.
|
||||
* Under our class loader hierarchy those would take precedence over the wagons from the distro, causing grief
|
||||
* due to their bugs (e.g. MNG-4528).
|
||||
*/
|
||||
if ( "maven-deploy-plugin".equals( plugin.getArtifactId() )
|
||||
&& "org.apache.maven.plugins".equals( plugin.getGroupId() ) )
|
||||
{
|
||||
collectionFilter =
|
||||
new AndArtifactFilter( Arrays.asList( collectionFilter,
|
||||
new ExclusionSetFilter( new String[] { "maven-core" } ) ) );
|
||||
}
|
||||
|
||||
ArtifactFilter resolutionFilter = artifactFilterManager.getCoreArtifactFilter();
|
||||
|
||||
if ( dependencyFilter != null )
|
||||
{
|
||||
resolutionFilter = new AndArtifactFilter( Arrays.asList( resolutionFilter, dependencyFilter ) );
|
||||
}
|
||||
|
||||
request.setArtifact( pluginArtifact );
|
||||
request.setArtifactDependencies( overrideArtifacts );
|
||||
request.setCollectionFilter( collectionFilter );
|
||||
request.setResolutionFilter( resolutionFilter );
|
||||
request.setResolveRoot( true );
|
||||
request.setResolveTransitively( true );
|
||||
|
||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||
try
|
||||
{
|
||||
resolutionErrorHandler.throwErrors( request, result );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new PluginResolutionException( plugin, e );
|
||||
}
|
||||
|
||||
List<Artifact> pluginArtifacts = new ArrayList<Artifact>( result.getArtifacts() );
|
||||
|
||||
addPlexusUtils( pluginArtifacts, plugin, request );
|
||||
|
||||
return pluginArtifacts;
|
||||
}
|
||||
|
||||
// backward-compatibility with Maven 2.x
|
||||
private void addPlexusUtils( List<Artifact> pluginArtifacts, Plugin plugin, RepositoryRequest repositoryRequest )
|
||||
throws PluginResolutionException
|
||||
{
|
||||
for ( Artifact artifact : pluginArtifacts )
|
||||
{
|
||||
if ( "org.codehaus.plexus:plexus-utils:jar".equals( artifact.getDependencyConflictId() ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Artifact plexusUtils =
|
||||
repositorySystem.createArtifact( "org.codehaus.plexus", "plexus-utils", "1.1", Artifact.SCOPE_RUNTIME,
|
||||
"jar" );
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest( repositoryRequest );
|
||||
request.setArtifact( plexusUtils );
|
||||
request.setResolveRoot( true );
|
||||
request.setResolveTransitively( false );
|
||||
|
||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||
try
|
||||
{
|
||||
resolutionErrorHandler.throwErrors( request, result );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new PluginResolutionException( plugin, e );
|
||||
}
|
||||
|
||||
pluginArtifacts.add( plexusUtils );
|
||||
return pluginDependenciesResolver.resolve( plugin, pluginArtifact, request, dependencyFilter );
|
||||
}
|
||||
|
||||
public <T> T getConfiguredMojo( Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution )
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
package org.apache.maven.plugin.internal;
|
||||
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.ArtifactFilterManager;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.PluginResolutionException;
|
||||
import org.apache.maven.repository.RepositorySystem;
|
||||
import org.codehaus.plexus.component.annotations.Component;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
|
||||
/**
|
||||
* Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility class that
|
||||
* is only public for technical reasons, it is not part of the public API. In particular, this class can be changed or
|
||||
* deleted without prior notice.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
@Component( role = PluginDependenciesResolver.class )
|
||||
public class DefaultPluginDependenciesResolver
|
||||
implements PluginDependenciesResolver
|
||||
{
|
||||
|
||||
@Requirement
|
||||
protected RepositorySystem repositorySystem;
|
||||
|
||||
@Requirement
|
||||
private ResolutionErrorHandler resolutionErrorHandler;
|
||||
|
||||
@Requirement
|
||||
private ArtifactFilterManager artifactFilterManager;
|
||||
|
||||
public List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
|
||||
ArtifactFilter dependencyFilter )
|
||||
throws PluginResolutionException
|
||||
{
|
||||
if ( pluginArtifact == null )
|
||||
{
|
||||
pluginArtifact = repositorySystem.createPluginArtifact( plugin );
|
||||
}
|
||||
|
||||
Set<Artifact> overrideArtifacts = new LinkedHashSet<Artifact>();
|
||||
for ( Dependency dependency : plugin.getDependencies() )
|
||||
{
|
||||
overrideArtifacts.add( repositorySystem.createDependencyArtifact( dependency ) );
|
||||
}
|
||||
|
||||
ArtifactFilter collectionFilter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM );
|
||||
|
||||
ArtifactFilter resolutionFilter = artifactFilterManager.getCoreArtifactFilter();
|
||||
|
||||
PluginDependencyResolutionListener listener = new PluginDependencyResolutionListener( resolutionFilter );
|
||||
|
||||
if ( dependencyFilter != null )
|
||||
{
|
||||
resolutionFilter = new AndArtifactFilter( Arrays.asList( resolutionFilter, dependencyFilter ) );
|
||||
}
|
||||
|
||||
request.setArtifact( pluginArtifact );
|
||||
request.setArtifactDependencies( overrideArtifacts );
|
||||
request.setCollectionFilter( collectionFilter );
|
||||
request.setResolutionFilter( resolutionFilter );
|
||||
request.setResolveRoot( true );
|
||||
request.setResolveTransitively( true );
|
||||
request.addListener( listener );
|
||||
|
||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||
|
||||
try
|
||||
{
|
||||
resolutionErrorHandler.throwErrors( request, result );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new PluginResolutionException( plugin, e );
|
||||
}
|
||||
|
||||
List<Artifact> pluginArtifacts = new ArrayList<Artifact>( result.getArtifacts() );
|
||||
|
||||
listener.removeBannedDependencies( pluginArtifacts );
|
||||
|
||||
addPlexusUtils( pluginArtifacts, plugin, request );
|
||||
|
||||
return pluginArtifacts;
|
||||
}
|
||||
|
||||
// backward-compatibility with Maven 2.x
|
||||
private void addPlexusUtils( List<Artifact> pluginArtifacts, Plugin plugin, RepositoryRequest repositoryRequest )
|
||||
throws PluginResolutionException
|
||||
{
|
||||
for ( Artifact artifact : pluginArtifacts )
|
||||
{
|
||||
if ( "org.codehaus.plexus:plexus-utils:jar".equals( artifact.getDependencyConflictId() ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Artifact plexusUtils =
|
||||
repositorySystem.createArtifact( "org.codehaus.plexus", "plexus-utils", "1.1", Artifact.SCOPE_RUNTIME,
|
||||
"jar" );
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest( repositoryRequest );
|
||||
request.setArtifact( plexusUtils );
|
||||
request.setResolveRoot( true );
|
||||
request.setResolveTransitively( false );
|
||||
|
||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||
try
|
||||
{
|
||||
resolutionErrorHandler.throwErrors( request, result );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new PluginResolutionException( plugin, e );
|
||||
}
|
||||
|
||||
pluginArtifacts.add( plexusUtils );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.apache.maven.plugin.internal;
|
||||
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.plugin.PluginResolutionException;
|
||||
|
||||
/**
|
||||
* Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility interface
|
||||
* that is only public for technical reasons, it is not part of the public API. In particular, this interface can be
|
||||
* changed or deleted without prior notice.
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
public interface PluginDependenciesResolver
|
||||
{
|
||||
|
||||
/**
|
||||
* Resolves the runtime dependencies of the specified plugin.
|
||||
*
|
||||
* @param plugin The plugin for which to resolve the dependencies, must not be {@code null}.
|
||||
* @param pluginArtifact The plugin's main artifact, may be {@code null}.
|
||||
* @param request A prepopulated resolution request that will be completed and used for the resolution, must not be
|
||||
* {@code null}.
|
||||
* @param dependencyFilter A filter to exclude artifacts from resolution, may be {@code null}.
|
||||
* @return The list of artifacts denoting the resolved plugin class path, never {@code null}.
|
||||
* @throws PluginResolutionException If any dependency could not be resolved.
|
||||
*/
|
||||
List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
|
||||
ArtifactFilter dependencyFilter )
|
||||
throws PluginResolutionException;
|
||||
|
||||
}
|
|
@ -0,0 +1,157 @@
|
|||
package org.apache.maven.plugin.internal;
|
||||
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.resolver.ResolutionListener;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.VersionRange;
|
||||
|
||||
/**
|
||||
* Assists in detecting wagon providers brought into the plugin class path via legacy Maven core artifacts (e.g.
|
||||
* maven-core:2.0.6) and excluding them. A plugin should be able to explicitly declare dependencies on specific wagons
|
||||
* for its use. However, the (old) wagons pulled in transitively via legacy Maven core artifacts are usually not
|
||||
* intended as dependencies and more importantly screw up artifact resolution because they would get preferred over the
|
||||
* core wagon versions. This is a hack to provide backward-compat with Maven 2 (MNG-4528, MNG-4561).
|
||||
*
|
||||
* @author Benjamin Bentmann
|
||||
*/
|
||||
class PluginDependencyResolutionListener
|
||||
implements ResolutionListener
|
||||
{
|
||||
|
||||
private ArtifactFilter coreFilter;
|
||||
|
||||
private LinkedList<Artifact> coreArtifacts = new LinkedList<Artifact>();
|
||||
|
||||
private Artifact wagonProvider;
|
||||
|
||||
private Map<Artifact, Object> bannedArtifacts = new IdentityHashMap<Artifact, Object>();
|
||||
|
||||
public PluginDependencyResolutionListener( ArtifactFilter coreFilter )
|
||||
{
|
||||
this.coreFilter = coreFilter;
|
||||
}
|
||||
|
||||
public void removeBannedDependencies( Collection<Artifact> artifacts )
|
||||
{
|
||||
if ( !bannedArtifacts.isEmpty() && artifacts != null )
|
||||
{
|
||||
for ( Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); )
|
||||
{
|
||||
Artifact artifact = it.next();
|
||||
if ( bannedArtifacts.containsKey( artifact ) )
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void startProcessChildren( Artifact artifact )
|
||||
{
|
||||
if ( wagonProvider == null )
|
||||
{
|
||||
if ( isLegacyCoreArtifact( artifact ) )
|
||||
{
|
||||
coreArtifacts.addFirst( artifact );
|
||||
}
|
||||
else if ( !coreArtifacts.isEmpty() && isWagonProvider( artifact ) )
|
||||
{
|
||||
wagonProvider = artifact;
|
||||
bannedArtifacts.put( artifact, null );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLegacyCoreArtifact( Artifact artifact )
|
||||
{
|
||||
String version = artifact.getVersion();
|
||||
return version != null && version.startsWith( "2." ) && !coreFilter.include( artifact );
|
||||
}
|
||||
|
||||
public void endProcessChildren( Artifact artifact )
|
||||
{
|
||||
if ( wagonProvider == artifact )
|
||||
{
|
||||
wagonProvider = null;
|
||||
}
|
||||
else if ( coreArtifacts.peek() == artifact )
|
||||
{
|
||||
coreArtifacts.removeFirst();
|
||||
}
|
||||
}
|
||||
|
||||
public void includeArtifact( Artifact artifact )
|
||||
{
|
||||
if ( wagonProvider != null )
|
||||
{
|
||||
bannedArtifacts.put( artifact, null );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isWagonProvider( Artifact artifact )
|
||||
{
|
||||
if ( "org.apache.maven.wagon".equals( artifact.getGroupId() ) )
|
||||
{
|
||||
return artifact.getArtifactId().startsWith( "wagon-" );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void manageArtifact( Artifact artifact, Artifact replacement )
|
||||
{
|
||||
}
|
||||
|
||||
public void omitForCycle( Artifact artifact )
|
||||
{
|
||||
}
|
||||
|
||||
public void omitForNearer( Artifact omitted, Artifact kept )
|
||||
{
|
||||
}
|
||||
|
||||
public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange )
|
||||
{
|
||||
}
|
||||
|
||||
public void selectVersionFromRange( Artifact artifact )
|
||||
{
|
||||
}
|
||||
|
||||
public void testArtifact( Artifact node )
|
||||
{
|
||||
}
|
||||
|
||||
public void updateScope( Artifact artifact, String scope )
|
||||
{
|
||||
}
|
||||
|
||||
public void updateScopeCurrentPom( Artifact artifact, String ignoredScope )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -28,22 +28,16 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.ArtifactFilterManager;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.InvalidRepositoryException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
|
||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.classrealm.ClassRealmManager;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Dependency;
|
||||
import org.apache.maven.model.Extension;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
@ -51,6 +45,7 @@ import org.apache.maven.model.Repository;
|
|||
import org.apache.maven.plugin.ExtensionRealmCache;
|
||||
import org.apache.maven.plugin.PluginArtifactsCache;
|
||||
import org.apache.maven.plugin.PluginResolutionException;
|
||||
import org.apache.maven.plugin.internal.PluginDependenciesResolver;
|
||||
import org.apache.maven.plugin.version.DefaultPluginVersionRequest;
|
||||
import org.apache.maven.plugin.version.PluginVersionRequest;
|
||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||
|
@ -95,15 +90,12 @@ public class DefaultProjectBuildingHelper
|
|||
@Requirement
|
||||
private RepositorySystem repositorySystem;
|
||||
|
||||
@Requirement
|
||||
private ResolutionErrorHandler resolutionErrorHandler;
|
||||
|
||||
@Requirement
|
||||
private ArtifactFilterManager artifactFilterManager;
|
||||
|
||||
@Requirement
|
||||
private PluginVersionResolver pluginVersionResolver;
|
||||
|
||||
@Requirement
|
||||
private PluginDependenciesResolver pluginDependenciesResolver;
|
||||
|
||||
private ExtensionDescriptorBuilder extensionDescriptorBuilder = new ExtensionDescriptorBuilder();
|
||||
|
||||
public List<ArtifactRepository> createArtifactRepositories( List<Repository> pomRepositories,
|
||||
|
@ -270,14 +262,15 @@ public class DefaultProjectBuildingHelper
|
|||
exportedArtifacts.put( extensionRealm, extensionDescriptor.getExportedArtifacts() );
|
||||
}
|
||||
|
||||
if ( !plugin.isExtensions() && artifacts.size() == 1 && artifacts.get( 0 ).getFile() != null )
|
||||
if ( !plugin.isExtensions() && artifacts.size() == 2 && artifacts.get( 0 ).getFile() != null
|
||||
&& "plexus-utils".equals( artifacts.get( 1 ).getArtifactId() ) )
|
||||
{
|
||||
/*
|
||||
* This is purely for backward-compat with 2.x where <extensions> consisting of a single artifact where
|
||||
* loaded into the core and hence available to plugins, in contrast to bigger extensions that were
|
||||
* loaded into a dedicated realm which is invisible to plugins.
|
||||
* loaded into a dedicated realm which is invisible to plugins (MNG-2749).
|
||||
*/
|
||||
publicArtifacts.addAll( artifacts );
|
||||
publicArtifacts.add( artifacts.get( 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,43 +332,12 @@ public class DefaultProjectBuildingHelper
|
|||
ProjectBuildingRequest request )
|
||||
throws PluginResolutionException
|
||||
{
|
||||
Artifact extensionArtifact = repositorySystem.createPluginArtifact( extensionPlugin );
|
||||
|
||||
Set<Artifact> overrideArtifacts = new LinkedHashSet<Artifact>();
|
||||
for ( Dependency dependency : extensionPlugin.getDependencies() )
|
||||
{
|
||||
overrideArtifacts.add( repositorySystem.createDependencyArtifact( dependency ) );
|
||||
}
|
||||
|
||||
ArtifactFilter collectionFilter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM );
|
||||
|
||||
ArtifactFilter resolutionFilter = artifactFilterManager.getCoreArtifactFilter();
|
||||
|
||||
ArtifactResolutionRequest artifactRequest = new ArtifactResolutionRequest( repositoryRequest );
|
||||
artifactRequest.setArtifact( extensionArtifact );
|
||||
artifactRequest.setArtifactDependencies( overrideArtifacts );
|
||||
artifactRequest.setCollectionFilter( collectionFilter );
|
||||
artifactRequest.setResolutionFilter( resolutionFilter );
|
||||
artifactRequest.setResolveRoot( true );
|
||||
artifactRequest.setResolveTransitively( true );
|
||||
artifactRequest.setServers( request.getServers() );
|
||||
artifactRequest.setMirrors( request.getMirrors() );
|
||||
artifactRequest.setProxies( request.getProxies() );
|
||||
|
||||
ArtifactResolutionResult result = repositorySystem.resolve( artifactRequest );
|
||||
|
||||
try
|
||||
{
|
||||
resolutionErrorHandler.throwErrors( artifactRequest, result );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new PluginResolutionException( extensionPlugin, e );
|
||||
}
|
||||
|
||||
List<Artifact> extensionArtifacts = new ArrayList<Artifact>( result.getArtifacts() );
|
||||
|
||||
return extensionArtifacts;
|
||||
return pluginDependenciesResolver.resolve( extensionPlugin, null, artifactRequest, null );
|
||||
}
|
||||
|
||||
public void selectProjectRealm( MavenProject project )
|
||||
|
|
Loading…
Reference in New Issue