mirror of https://github.com/apache/maven.git
o Extended metadata resolution group to also hold managed version map. This can save us another trip through the project builder when transitively resolving say plugin dependencies. We already need to build the project to grab the direct dependencies so we can as well grab the managed ones while we're there
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@801738 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
026328be02
commit
4397321a10
|
@ -177,6 +177,19 @@ public final class ArtifactUtils
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <K, T extends Map<K, Artifact>> T copyArtifacts( Map<K, ? extends Artifact> from, T to )
|
||||||
|
{
|
||||||
|
if ( from != null )
|
||||||
|
{
|
||||||
|
for ( Map.Entry<K, ? extends Artifact> entry : from.entrySet() )
|
||||||
|
{
|
||||||
|
to.put( entry.getKey(), ArtifactUtils.copyArtifact( entry.getValue() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
private static <T> List<T> copyList( List<T> original )
|
private static <T> List<T> copyList( List<T> original )
|
||||||
{
|
{
|
||||||
List<T> copy = null;
|
List<T> copy = null;
|
||||||
|
|
|
@ -24,11 +24,16 @@ import java.util.List;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public interface ArtifactMetadataSource
|
public interface ArtifactMetadataSource
|
||||||
extends org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource
|
extends org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ResolutionGroup retrieve( MetadataResolutionRequest request )
|
||||||
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||||
throws ArtifactMetadataRetrievalException;
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ package org.apache.maven.artifact.metadata;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
@ -25,8 +26,17 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
public class ResolutionGroup
|
public class ResolutionGroup
|
||||||
extends org.apache.maven.repository.legacy.metadata.ResolutionGroup
|
extends org.apache.maven.repository.legacy.metadata.ResolutionGroup
|
||||||
{
|
{
|
||||||
public ResolutionGroup( Artifact pomArtifact, Set<Artifact> artifacts, List<ArtifactRepository> resolutionRepositories )
|
|
||||||
|
public ResolutionGroup( Artifact pomArtifact, Set<Artifact> artifacts,
|
||||||
|
List<ArtifactRepository> resolutionRepositories )
|
||||||
{
|
{
|
||||||
super( pomArtifact, artifacts, resolutionRepositories );
|
super( pomArtifact, artifacts, resolutionRepositories );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup( Artifact pomArtifact, Set<Artifact> artifacts, Map<String, Artifact> managedVersions,
|
||||||
|
List<ArtifactRepository> resolutionRepositories )
|
||||||
|
{
|
||||||
|
super( pomArtifact, artifacts, managedVersions, resolutionRepositories );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
|
import org.apache.maven.artifact.metadata.ResolutionGroup;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.metadata.Metadata;
|
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
||||||
|
@ -37,6 +38,8 @@ import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.repository.legacy.WagonManager;
|
import org.apache.maven.repository.legacy.WagonManager;
|
||||||
import org.apache.maven.repository.legacy.metadata.ArtifactMetadata;
|
import org.apache.maven.repository.legacy.metadata.ArtifactMetadata;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver;
|
import org.apache.maven.repository.legacy.resolver.conflict.ConflictResolver;
|
||||||
import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager;
|
import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager;
|
||||||
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
import org.apache.maven.wagon.ResourceDoesNotExistException;
|
||||||
|
@ -412,9 +415,23 @@ public class DefaultArtifactResolver
|
||||||
|
|
||||||
if ( request.isResolveTransitively() )
|
if ( request.isResolveTransitively() )
|
||||||
{
|
{
|
||||||
|
MetadataResolutionRequest metadataRequest = new DefaultMetadataResolutionRequest();
|
||||||
|
|
||||||
|
metadataRequest.setArtifact( rootArtifact );
|
||||||
|
metadataRequest.setLocalRepository( localRepository );
|
||||||
|
metadataRequest.setRemoteRepositories( remoteRepositories );
|
||||||
|
metadataRequest.setResolveManagedVersions( managedVersions == null );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Set<Artifact> directArtifacts = source.retrieve( rootArtifact, localRepository, remoteRepositories ).getArtifacts();
|
ResolutionGroup resolutionGroup = source.retrieve( metadataRequest );
|
||||||
|
|
||||||
|
if ( managedVersions == null )
|
||||||
|
{
|
||||||
|
managedVersions = resolutionGroup.getManagedVersions();
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Artifact> directArtifacts = resolutionGroup.getArtifacts();
|
||||||
|
|
||||||
if ( artifacts == null || artifacts.isEmpty() )
|
if ( artifacts == null || artifacts.isEmpty() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,6 +34,10 @@ import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||||
*/
|
*/
|
||||||
public interface ArtifactMetadataSource
|
public interface ArtifactMetadataSource
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ResolutionGroup retrieve( MetadataResolutionRequest request )
|
||||||
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||||
throws ArtifactMetadataRetrievalException;
|
throws ArtifactMetadataRetrievalException;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
package org.apache.maven.repository.legacy.metadata;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.repository.ArtifactRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forms a request to retrieve artifact metadata.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public class DefaultMetadataResolutionRequest
|
||||||
|
implements MetadataResolutionRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
private Artifact artifact;
|
||||||
|
|
||||||
|
private ArtifactRepository localRepository;
|
||||||
|
|
||||||
|
private List<ArtifactRepository> remoteRepositories;
|
||||||
|
|
||||||
|
private boolean resolveManagedVersions;
|
||||||
|
|
||||||
|
public Artifact getArtifact()
|
||||||
|
{
|
||||||
|
return artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultMetadataResolutionRequest setArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
this.artifact = artifact;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtifactRepository getLocalRepository()
|
||||||
|
{
|
||||||
|
return localRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultMetadataResolutionRequest setLocalRepository( ArtifactRepository localRepository )
|
||||||
|
{
|
||||||
|
this.localRepository = localRepository;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ArtifactRepository> getRemoteRepositories()
|
||||||
|
{
|
||||||
|
return remoteRepositories;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultMetadataResolutionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
|
||||||
|
{
|
||||||
|
this.remoteRepositories = remoteRepositories;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResolveManagedVersions()
|
||||||
|
{
|
||||||
|
return resolveManagedVersions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataResolutionRequest setResolveManagedVersions( boolean resolveManagedVersions )
|
||||||
|
{
|
||||||
|
this.resolveManagedVersions = resolveManagedVersions;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,96 @@
|
||||||
|
package org.apache.maven.repository.legacy.metadata;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.repository.ArtifactRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Forms a request to retrieve artifact metadata.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public interface MetadataResolutionRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the artifact to resolve metadata for.
|
||||||
|
*
|
||||||
|
* @return The artifact to resolve metadata for or {@code null} if not set.
|
||||||
|
*/
|
||||||
|
Artifact getArtifact();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the artifact for which to resolve metadata.
|
||||||
|
*
|
||||||
|
* @param artifact The artifact for which to resolve metadata.
|
||||||
|
* @return This request, never {@code null}.
|
||||||
|
*/
|
||||||
|
MetadataResolutionRequest setArtifact( Artifact artifact );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the local repository to use for the resolution.
|
||||||
|
*
|
||||||
|
* @return The local repository to use for the resolution or {@code null} if not set.
|
||||||
|
*/
|
||||||
|
ArtifactRepository getLocalRepository();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the local repository to use for the resolution.
|
||||||
|
*
|
||||||
|
* @param localRepository The local repository to use for the resolution.
|
||||||
|
* @return This request, never {@code null}.
|
||||||
|
*/
|
||||||
|
MetadataResolutionRequest setLocalRepository( ArtifactRepository localRepository );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the remote repositories to use for the resolution.
|
||||||
|
*
|
||||||
|
* @return The remote repositories to use for the resolution or {@code null} if not set.
|
||||||
|
*/
|
||||||
|
List<ArtifactRepository> getRemoteRepositories();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the remote repository to use for the resolution.
|
||||||
|
*
|
||||||
|
* @param remoteRepositories The remote repository to use for the resolution.
|
||||||
|
* @return This request, never {@code null}.
|
||||||
|
*/
|
||||||
|
MetadataResolutionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the managed version information should be retrieved.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the dependency management information should be retrieved, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
boolean isResolveManagedVersions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables/disables resolution of the dependency manageemnt information.
|
||||||
|
*
|
||||||
|
* @param resolveManagedVersions {@code true} if the dependency management information should be retrieved, {@code
|
||||||
|
* false} otherwise.
|
||||||
|
* @return This request, never {@code null}.
|
||||||
|
*/
|
||||||
|
MetadataResolutionRequest setResolveManagedVersions( boolean resolveManagedVersions );
|
||||||
|
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ package org.apache.maven.repository.legacy.metadata;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
@ -34,12 +35,20 @@ public class ResolutionGroup
|
||||||
|
|
||||||
private final Artifact pomArtifact;
|
private final Artifact pomArtifact;
|
||||||
|
|
||||||
public ResolutionGroup( Artifact pomArtifact,
|
private final Map<String, Artifact> managedVersions;
|
||||||
Set<Artifact> artifacts,
|
|
||||||
|
public ResolutionGroup( Artifact pomArtifact, Set<Artifact> artifacts,
|
||||||
|
List<ArtifactRepository> resolutionRepositories )
|
||||||
|
{
|
||||||
|
this( pomArtifact, artifacts, null, resolutionRepositories );
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup( Artifact pomArtifact, Set<Artifact> artifacts, Map<String, Artifact> managedVersions,
|
||||||
List<ArtifactRepository> resolutionRepositories )
|
List<ArtifactRepository> resolutionRepositories )
|
||||||
{
|
{
|
||||||
this.pomArtifact = pomArtifact;
|
this.pomArtifact = pomArtifact;
|
||||||
this.artifacts = artifacts;
|
this.artifacts = artifacts;
|
||||||
|
this.managedVersions = managedVersions;
|
||||||
this.resolutionRepositories = resolutionRepositories;
|
this.resolutionRepositories = resolutionRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,4 +67,9 @@ public class ResolutionGroup
|
||||||
return resolutionRepositories;
|
return resolutionRepositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Artifact> getManagedVersions()
|
||||||
|
{
|
||||||
|
return managedVersions;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,11 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
|
||||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource;
|
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
import org.apache.maven.repository.legacy.metadata.ResolutionGroup;
|
import org.apache.maven.repository.legacy.metadata.ResolutionGroup;
|
||||||
|
|
||||||
/** @author Jason van Zyl */
|
/** @author Jason van Zyl */
|
||||||
|
@ -64,4 +64,11 @@ public class SimpleArtifactMetadataSource
|
||||||
{
|
{
|
||||||
return artifact;
|
return artifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup retrieve( MetadataResolutionRequest request )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
|
||||||
|
@ -73,4 +74,11 @@ public class TestMetadataSource
|
||||||
{
|
{
|
||||||
return artifact;
|
return artifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup retrieve( MetadataResolutionRequest request )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||||
import org.apache.maven.artifact.metadata.ResolutionGroup;
|
import org.apache.maven.artifact.metadata.ResolutionGroup;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
|
|
||||||
// It would be cool if there was a hook that i could use to setup a test environment.
|
// It would be cool if there was a hook that i could use to setup a test environment.
|
||||||
// I want to setup a local/remote repositories for testing but i don't want to have
|
// I want to setup a local/remote repositories for testing but i don't want to have
|
||||||
|
@ -223,6 +224,12 @@ public class ArtifactResolverTest
|
||||||
{
|
{
|
||||||
return artifact;
|
return artifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup retrieve( MetadataResolutionRequest request )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ArtifactResolutionResult result = null;
|
ArtifactResolutionResult result = null;
|
||||||
|
|
|
@ -47,6 +47,7 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
|
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
import org.apache.maven.repository.legacy.resolver.LegacyArtifactCollector;
|
import org.apache.maven.repository.legacy.resolver.LegacyArtifactCollector;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
|
||||||
|
@ -975,5 +976,11 @@ public class DefaultArtifactCollectorTest
|
||||||
{
|
{
|
||||||
return artifact;
|
return artifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup retrieve( MetadataResolutionRequest request )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||||
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataRetrievalException;
|
||||||
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource;
|
import org.apache.maven.repository.legacy.metadata.ArtifactMetadataSource;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
import org.apache.maven.repository.legacy.metadata.ResolutionGroup;
|
import org.apache.maven.repository.legacy.metadata.ResolutionGroup;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
@ -76,4 +77,11 @@ public class TestMetadataSource
|
||||||
{
|
{
|
||||||
return artifact;
|
return artifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup retrieve( MetadataResolutionRequest request )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories() );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,5 +25,9 @@ import org.apache.maven.model.Dependency;
|
||||||
|
|
||||||
public interface ArtifactWithDependencies
|
public interface ArtifactWithDependencies
|
||||||
{
|
{
|
||||||
|
|
||||||
List<Dependency> getDependencies();
|
List<Dependency> getDependencies();
|
||||||
|
|
||||||
|
List<Dependency> getManagedDependencies();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.project.artifact;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -38,17 +39,21 @@ public class DefaultMavenMetadataCache
|
||||||
public static class CacheKey
|
public static class CacheKey
|
||||||
{
|
{
|
||||||
private final Artifact artifact;
|
private final Artifact artifact;
|
||||||
|
private final boolean resolveManagedVersions;
|
||||||
private final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
|
private final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
public CacheKey( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
public CacheKey( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository,
|
||||||
|
List<ArtifactRepository> remoteRepositories )
|
||||||
{
|
{
|
||||||
this.artifact = ArtifactUtils.copyArtifact( artifact );
|
this.artifact = ArtifactUtils.copyArtifact( artifact );
|
||||||
|
this.resolveManagedVersions = resolveManagedVersions;
|
||||||
this.repositories.add( localRepository );
|
this.repositories.add( localRepository );
|
||||||
this.repositories.addAll( remoteRepositories );
|
this.repositories.addAll( remoteRepositories );
|
||||||
|
|
||||||
int hash = 17;
|
int hash = 17;
|
||||||
hash = hash * 31 + artifactHashCode( artifact );
|
hash = hash * 31 + artifactHashCode( artifact );
|
||||||
|
hash = hash * 31 + ( resolveManagedVersions ? 1 : 2 );
|
||||||
hash = hash * 31 + repositories.hashCode();
|
hash = hash * 31 + repositories.hashCode();
|
||||||
this.hashCode = hash;
|
this.hashCode = hash;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +79,8 @@ public class DefaultMavenMetadataCache
|
||||||
|
|
||||||
CacheKey other = (CacheKey) o;
|
CacheKey other = (CacheKey) o;
|
||||||
|
|
||||||
return artifactEquals( artifact, other.artifact ) && repositories.equals( other.repositories );
|
return artifactEquals( artifact, other.artifact ) && resolveManagedVersions == other.resolveManagedVersions
|
||||||
|
&& repositories.equals( other.repositories );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,17 +127,24 @@ public class DefaultMavenMetadataCache
|
||||||
{
|
{
|
||||||
private Artifact pomArtifact;
|
private Artifact pomArtifact;
|
||||||
private List<Artifact> artifacts;
|
private List<Artifact> artifacts;
|
||||||
|
private Map<String, Artifact> managedVersions;
|
||||||
private List<ArtifactRepository> remoteRepositories;
|
private List<ArtifactRepository> remoteRepositories;
|
||||||
|
|
||||||
private long length;
|
private long length;
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
|
|
||||||
CacheRecord(Artifact pomArtifact, Set<Artifact> artifacts, List<ArtifactRepository> remoteRepositories)
|
CacheRecord(Artifact pomArtifact, Set<Artifact> artifacts, Map<String, Artifact> managedVersions, List<ArtifactRepository> remoteRepositories)
|
||||||
{
|
{
|
||||||
this.pomArtifact = ArtifactUtils.copyArtifact( pomArtifact );
|
this.pomArtifact = ArtifactUtils.copyArtifact( pomArtifact );
|
||||||
this.artifacts = ArtifactUtils.copyArtifacts( artifacts, new ArrayList<Artifact>() );
|
this.artifacts = ArtifactUtils.copyArtifacts( artifacts, new ArrayList<Artifact>() );
|
||||||
this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
|
this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
|
||||||
|
|
||||||
|
this.managedVersions = managedVersions;
|
||||||
|
if ( managedVersions != null )
|
||||||
|
{
|
||||||
|
this.managedVersions =
|
||||||
|
ArtifactUtils.copyArtifacts( managedVersions, new LinkedHashMap<String, Artifact>() );
|
||||||
|
}
|
||||||
|
|
||||||
File pomFile = pomArtifact.getFile();
|
File pomFile = pomArtifact.getFile();
|
||||||
if ( pomFile != null && pomFile.canRead() )
|
if ( pomFile != null && pomFile.canRead() )
|
||||||
|
@ -156,6 +169,11 @@ public class DefaultMavenMetadataCache
|
||||||
return artifacts;
|
return artifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, Artifact> getManagedVersions()
|
||||||
|
{
|
||||||
|
return managedVersions;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ArtifactRepository> getRemoteRepositories()
|
public List<ArtifactRepository> getRemoteRepositories()
|
||||||
{
|
{
|
||||||
return remoteRepositories;
|
return remoteRepositories;
|
||||||
|
@ -175,18 +193,24 @@ public class DefaultMavenMetadataCache
|
||||||
|
|
||||||
protected Map<CacheKey, CacheRecord> cache = new HashMap<CacheKey, CacheRecord>();
|
protected Map<CacheKey, CacheRecord> cache = new HashMap<CacheKey, CacheRecord>();
|
||||||
|
|
||||||
public ResolutionGroup get( Artifact artifact, ArtifactRepository localRepository,
|
public ResolutionGroup get( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository,
|
||||||
List<ArtifactRepository> remoteRepositories )
|
List<ArtifactRepository> remoteRepositories )
|
||||||
{
|
{
|
||||||
CacheKey cacheKey = new CacheKey( artifact, localRepository, remoteRepositories );
|
CacheKey cacheKey = new CacheKey( artifact, resolveManagedVersions, localRepository, remoteRepositories );
|
||||||
|
|
||||||
CacheRecord cacheRecord = cache.get( cacheKey );
|
CacheRecord cacheRecord = cache.get( cacheKey );
|
||||||
|
|
||||||
if ( cacheRecord != null && !cacheRecord.isStale() )
|
if ( cacheRecord != null && !cacheRecord.isStale() )
|
||||||
{
|
{
|
||||||
Artifact pomArtifact = ArtifactUtils.copyArtifact( cacheRecord.getArtifact() );
|
Artifact pomArtifact = ArtifactUtils.copyArtifact( cacheRecord.getArtifact() );
|
||||||
Set<Artifact> artifacts = ArtifactUtils.copyArtifacts( cacheRecord.getArtifacts(), new LinkedHashSet<Artifact>() );
|
Set<Artifact> artifacts =
|
||||||
return new ResolutionGroup( pomArtifact, artifacts , cacheRecord.getRemoteRepositories() );
|
ArtifactUtils.copyArtifacts( cacheRecord.getArtifacts(), new LinkedHashSet<Artifact>() );
|
||||||
|
Map<String, Artifact> managedVersions = cacheRecord.getManagedVersions();
|
||||||
|
if ( managedVersions != null )
|
||||||
|
{
|
||||||
|
managedVersions = ArtifactUtils.copyArtifacts( managedVersions, new LinkedHashMap<String, Artifact>() );
|
||||||
|
}
|
||||||
|
return new ResolutionGroup( pomArtifact, artifacts, managedVersions, cacheRecord.getRemoteRepositories() );
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.remove( cacheKey );
|
cache.remove( cacheKey );
|
||||||
|
@ -194,11 +218,13 @@ public class DefaultMavenMetadataCache
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void put( Artifact artifact, ArtifactRepository localRepository,
|
public void put( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository,
|
||||||
List<ArtifactRepository> remoteRepositories, ResolutionGroup result )
|
List<ArtifactRepository> remoteRepositories, ResolutionGroup result )
|
||||||
{
|
{
|
||||||
CacheKey cacheKey = new CacheKey( artifact, localRepository, remoteRepositories );
|
CacheKey cacheKey = new CacheKey( artifact, resolveManagedVersions, localRepository, remoteRepositories );
|
||||||
CacheRecord cacheRecord = new CacheRecord( result.getPomArtifact(), result.getArtifacts(), result.getResolutionRepositories() );
|
CacheRecord cacheRecord =
|
||||||
|
new CacheRecord( result.getPomArtifact(), result.getArtifacts(), result.getManagedVersions(),
|
||||||
|
result.getResolutionRepositories() );
|
||||||
|
|
||||||
cache.put( cacheKey, cacheRecord );
|
cache.put( cacheKey, cacheRecord );
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,10 @@ import org.apache.maven.artifact.metadata.ResolutionGroup;
|
||||||
public interface MavenMetadataCache
|
public interface MavenMetadataCache
|
||||||
{
|
{
|
||||||
|
|
||||||
ResolutionGroup get( Artifact artifact, ArtifactRepository localRepository,
|
ResolutionGroup get( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository,
|
||||||
List<ArtifactRepository> remoteRepositories );
|
List<ArtifactRepository> remoteRepositories );
|
||||||
|
|
||||||
void put( Artifact artifact, ArtifactRepository localRepository,
|
void put( Artifact artifact, boolean resolveManagedVersions, ArtifactRepository localRepository,
|
||||||
List<ArtifactRepository> remoteRepositories, ResolutionGroup result );
|
List<ArtifactRepository> remoteRepositories, ResolutionGroup result );
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
|
@ -19,8 +19,10 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
@ -42,6 +44,7 @@ import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
|
import org.apache.maven.model.DependencyManagement;
|
||||||
import org.apache.maven.model.DistributionManagement;
|
import org.apache.maven.model.DistributionManagement;
|
||||||
import org.apache.maven.model.Exclusion;
|
import org.apache.maven.model.Exclusion;
|
||||||
import org.apache.maven.model.Relocation;
|
import org.apache.maven.model.Relocation;
|
||||||
|
@ -51,6 +54,7 @@ import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.ProjectBuilder;
|
import org.apache.maven.project.ProjectBuilder;
|
||||||
import org.apache.maven.project.ProjectBuildingException;
|
import org.apache.maven.project.ProjectBuildingException;
|
||||||
import org.apache.maven.project.ProjectBuildingRequest;
|
import org.apache.maven.project.ProjectBuildingRequest;
|
||||||
|
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
@ -83,7 +87,22 @@ public class MavenMetadataSource
|
||||||
@Requirement
|
@Requirement
|
||||||
private MavenMetadataCache cache;
|
private MavenMetadataCache cache;
|
||||||
|
|
||||||
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
public ResolutionGroup retrieve( MetadataResolutionRequest request )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
return retrieve( request.getArtifact(), request.getLocalRepository(), request.getRemoteRepositories(),
|
||||||
|
request.isResolveManagedVersions() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
|
||||||
|
List<ArtifactRepository> remoteRepositories )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
return retrieve( artifact, localRepository, remoteRepositories, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
|
||||||
|
List<ArtifactRepository> remoteRepositories, boolean resolveManagedVersions )
|
||||||
throws ArtifactMetadataRetrievalException
|
throws ArtifactMetadataRetrievalException
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
@ -95,7 +114,7 @@ public class MavenMetadataSource
|
||||||
return new ResolutionGroup( null, null, null );
|
return new ResolutionGroup( null, null, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolutionGroup cached = cache.get( artifact, localRepository, remoteRepositories );
|
ResolutionGroup cached = cache.get( artifact, resolveManagedVersions, localRepository, remoteRepositories );
|
||||||
|
|
||||||
if ( cached != null )
|
if ( cached != null )
|
||||||
{
|
{
|
||||||
|
@ -104,6 +123,8 @@ public class MavenMetadataSource
|
||||||
|
|
||||||
List<Dependency> dependencies;
|
List<Dependency> dependencies;
|
||||||
|
|
||||||
|
List<Dependency> managedDependencies = null;
|
||||||
|
|
||||||
Artifact pomArtifact;
|
Artifact pomArtifact;
|
||||||
|
|
||||||
//TODO: Not even sure this is really required as the project will be cached in the builder, we'll see this
|
//TODO: Not even sure this is really required as the project will be cached in the builder, we'll see this
|
||||||
|
@ -113,6 +134,8 @@ public class MavenMetadataSource
|
||||||
pomArtifact = artifact;
|
pomArtifact = artifact;
|
||||||
|
|
||||||
dependencies = ( (ArtifactWithDependencies) artifact ).getDependencies();
|
dependencies = ( (ArtifactWithDependencies) artifact ).getDependencies();
|
||||||
|
|
||||||
|
managedDependencies = ( (ArtifactWithDependencies) artifact ).getManagedDependencies();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -135,6 +158,9 @@ public class MavenMetadataSource
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dependencies = rel.project.getDependencies();
|
dependencies = rel.project.getDependencies();
|
||||||
|
|
||||||
|
DependencyManagement depMngt = rel.project.getDependencyManagement();
|
||||||
|
managedDependencies = ( depMngt != null ) ? depMngt.getDependencies() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,74 +170,81 @@ public class MavenMetadataSource
|
||||||
{
|
{
|
||||||
artifacts = new LinkedHashSet<Artifact>();
|
artifacts = new LinkedHashSet<Artifact>();
|
||||||
|
|
||||||
ArtifactFilter dependencyFilter = artifact.getDependencyFilter();
|
for ( Dependency dependency : dependencies )
|
||||||
|
|
||||||
for ( Dependency d : dependencies )
|
|
||||||
{
|
{
|
||||||
String effectiveScope = getEffectiveScope( d.getScope(), artifact.getScope() );
|
Artifact dependencyArtifact = createDependencyArtifact( dependency, artifact, pomArtifact );
|
||||||
|
|
||||||
if ( effectiveScope != null )
|
if ( dependencyArtifact != null )
|
||||||
{
|
{
|
||||||
Artifact dependencyArtifact;
|
|
||||||
|
|
||||||
VersionRange versionRange;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
|
|
||||||
}
|
|
||||||
catch ( InvalidVersionSpecificationException e )
|
|
||||||
{
|
|
||||||
throw new ArtifactMetadataRetrievalException( "Invalid version for dependency "
|
|
||||||
+ d.getManagementKey() + ": " + e.getMessage(), e, pomArtifact );
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencyArtifact =
|
|
||||||
repositorySystem.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange,
|
|
||||||
d.getType(), d.getClassifier(), effectiveScope,
|
|
||||||
d.isOptional() );
|
|
||||||
|
|
||||||
if ( dependencyFilter == null || dependencyFilter.include( dependencyArtifact ) )
|
|
||||||
{
|
|
||||||
dependencyArtifact.setOptional( d.isOptional() );
|
|
||||||
|
|
||||||
if ( Artifact.SCOPE_SYSTEM.equals( effectiveScope ) )
|
|
||||||
{
|
|
||||||
dependencyArtifact.setFile( new File( d.getSystemPath() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
ArtifactFilter newFilter = dependencyFilter;
|
|
||||||
|
|
||||||
if ( !d.getExclusions().isEmpty() )
|
|
||||||
{
|
|
||||||
List<String> exclusions = new ArrayList<String>();
|
|
||||||
|
|
||||||
for ( Exclusion e : d.getExclusions() )
|
|
||||||
{
|
|
||||||
exclusions.add( e.getGroupId() + ":" + e.getArtifactId() );
|
|
||||||
}
|
|
||||||
|
|
||||||
newFilter = new ExcludesArtifactFilter( exclusions );
|
|
||||||
if ( dependencyFilter != null )
|
|
||||||
{
|
|
||||||
newFilter = new AndArtifactFilter( Arrays.asList( dependencyFilter, newFilter ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencyArtifact.setDependencyFilter( newFilter );
|
|
||||||
|
|
||||||
artifacts.add( dependencyArtifact );
|
artifacts.add( dependencyArtifact );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, Artifact> managedVersions = null;
|
||||||
|
|
||||||
|
if ( managedDependencies != null && resolveManagedVersions )
|
||||||
|
{
|
||||||
|
managedVersions = new HashMap<String, Artifact>();
|
||||||
|
|
||||||
|
for ( Dependency managedDependency : managedDependencies )
|
||||||
|
{
|
||||||
|
Artifact managedArtifact = createDependencyArtifact( managedDependency, null, pomArtifact );
|
||||||
|
|
||||||
|
managedVersions.put( managedDependency.getManagementKey(), managedArtifact );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolutionGroup result = new ResolutionGroup( pomArtifact, artifacts, remoteRepositories );
|
ResolutionGroup result = new ResolutionGroup( pomArtifact, artifacts, managedVersions, remoteRepositories );
|
||||||
|
|
||||||
cache.put( artifact, localRepository, remoteRepositories, result );
|
cache.put( artifact, resolveManagedVersions, localRepository, remoteRepositories, result );
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Artifact createDependencyArtifact( Dependency dependency, Artifact owner, Artifact pom )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
String effectiveScope = getEffectiveScope( dependency.getScope(), ( owner != null ) ? owner.getScope() : null );
|
||||||
|
|
||||||
|
if ( effectiveScope == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionRange versionRange;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() );
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
throw new ArtifactMetadataRetrievalException( "Invalid version for dependency "
|
||||||
|
+ dependency.getManagementKey() + ": " + e.getMessage(), e, pom );
|
||||||
|
}
|
||||||
|
|
||||||
|
Artifact dependencyArtifact =
|
||||||
|
repositorySystem.createDependencyArtifact( dependency.getGroupId(), dependency.getArtifactId(),
|
||||||
|
versionRange, dependency.getType(), dependency.getClassifier(),
|
||||||
|
effectiveScope, dependency.isOptional() );
|
||||||
|
|
||||||
|
ArtifactFilter dependencyFilter = ( owner != null ) ? owner.getDependencyFilter() : null;
|
||||||
|
|
||||||
|
if ( dependencyFilter != null && !dependencyFilter.include( dependencyArtifact ) )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Artifact.SCOPE_SYSTEM.equals( effectiveScope ) )
|
||||||
|
{
|
||||||
|
dependencyArtifact.setFile( new File( dependency.getSystemPath() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencyArtifact.setDependencyFilter( createDependencyFilter( dependency, dependencyFilter ) );
|
||||||
|
|
||||||
|
return dependencyArtifact;
|
||||||
|
}
|
||||||
|
|
||||||
private String getEffectiveScope( String originalScope, String inheritedScope )
|
private String getEffectiveScope( String originalScope, String inheritedScope )
|
||||||
{
|
{
|
||||||
String effectiveScope = Artifact.SCOPE_RUNTIME;
|
String effectiveScope = Artifact.SCOPE_RUNTIME;
|
||||||
|
@ -253,6 +286,30 @@ public class MavenMetadataSource
|
||||||
return effectiveScope;
|
return effectiveScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArtifactFilter createDependencyFilter( Dependency dependency, ArtifactFilter inheritedFilter )
|
||||||
|
{
|
||||||
|
ArtifactFilter effectiveFilter = inheritedFilter;
|
||||||
|
|
||||||
|
if ( !dependency.getExclusions().isEmpty() )
|
||||||
|
{
|
||||||
|
List<String> exclusions = new ArrayList<String>();
|
||||||
|
|
||||||
|
for ( Exclusion e : dependency.getExclusions() )
|
||||||
|
{
|
||||||
|
exclusions.add( e.getGroupId() + ':' + e.getArtifactId() );
|
||||||
|
}
|
||||||
|
|
||||||
|
effectiveFilter = new ExcludesArtifactFilter( exclusions );
|
||||||
|
|
||||||
|
if ( inheritedFilter != null )
|
||||||
|
{
|
||||||
|
effectiveFilter = new AndArtifactFilter( Arrays.asList( inheritedFilter, effectiveFilter ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return effectiveFilter;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
public List<ArtifactVersion> retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||||
throws ArtifactMetadataRetrievalException
|
throws ArtifactMetadataRetrievalException
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.project.artifact;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
@ -46,6 +47,11 @@ public class PluginArtifact
|
||||||
return plugin.getDependencies();
|
return plugin.getDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Dependency> getManagedDependencies()
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
static class PluginArtifactHandler
|
static class PluginArtifactHandler
|
||||||
implements ArtifactHandler
|
implements ArtifactHandler
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,11 +19,13 @@ package org.apache.maven.project.artifact;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.DefaultArtifact;
|
import org.apache.maven.artifact.DefaultArtifact;
|
||||||
import org.apache.maven.artifact.handler.ArtifactHandler;
|
import org.apache.maven.artifact.handler.ArtifactHandler;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
|
import org.apache.maven.model.DependencyManagement;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
public class ProjectArtifact
|
public class ProjectArtifact
|
||||||
|
@ -50,6 +52,12 @@ public class ProjectArtifact
|
||||||
return project.getDependencies();
|
return project.getDependencies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Dependency> getManagedDependencies()
|
||||||
|
{
|
||||||
|
DependencyManagement depMngt = project.getDependencyManagement();
|
||||||
|
return ( depMngt != null ) ? depMngt.getDependencies() : Collections.<Dependency> emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
static class PomArtifactHandler
|
static class PomArtifactHandler
|
||||||
implements ArtifactHandler
|
implements ArtifactHandler
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,8 +71,8 @@ public class DefaultMavenMetadataCacheTest
|
||||||
assertNotSame( lr1, lr2 );
|
assertNotSame( lr1, lr2 );
|
||||||
assertNotSame( rr1, rr2 );
|
assertNotSame( rr1, rr2 );
|
||||||
|
|
||||||
CacheKey k1 = new CacheKey( a1, lr1, Collections.singletonList( rr1 ) );
|
CacheKey k1 = new CacheKey( a1, false, lr1, Collections.singletonList( rr1 ) );
|
||||||
CacheKey k2 = new CacheKey( a2, lr2, Collections.singletonList( rr2 ) );
|
CacheKey k2 = new CacheKey( a2, false, lr2, Collections.singletonList( rr2 ) );
|
||||||
|
|
||||||
assertEquals(k1.hashCode(), k2.hashCode());
|
assertEquals(k1.hashCode(), k2.hashCode());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue