mirror of https://github.com/apache/maven.git
[MNG-4756] Aether integration
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@988749 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c85a6a4ec2
commit
6c37a89744
|
@ -13,7 +13,7 @@ The Apache Software Foundation (http://www.apache.org/).
|
||||||
This product includes software (Plexus and Classworlds) developed by
|
This product includes software (Plexus and Classworlds) developed by
|
||||||
The Codehaus Foundation (http://www.codehaus.org/).
|
The Codehaus Foundation (http://www.codehaus.org/).
|
||||||
|
|
||||||
This product includes software (Spice, Plexus Ciper and Sec Dispatcher) developed by
|
This product includes software (Aether, Spice, Plexus Ciper and Sec Dispatcher) developed by
|
||||||
Sonatype Inc. (http://www.sonatype.org/).
|
Sonatype Inc. (http://www.sonatype.org/).
|
||||||
|
|
||||||
This product includes software (NekoHTML) developed by
|
This product includes software (NekoHTML) developed by
|
||||||
|
|
|
@ -59,6 +59,10 @@
|
||||||
<groupId>org.apache.maven.wagon</groupId>
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
<artifactId>wagon-file</artifactId>
|
<artifactId>wagon-file</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sonatype.aether</groupId>
|
||||||
|
<artifactId>aether-connector-wagon</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -195,7 +195,7 @@ Do you want to continue?</input>
|
||||||
<modello file="maven-model-builder/src/main/mdo/profiles.mdo" />
|
<modello file="maven-model-builder/src/main/mdo/profiles.mdo" />
|
||||||
<modello file="maven-settings/src/main/mdo/settings.mdo" version="1.1.0" />
|
<modello file="maven-settings/src/main/mdo/settings.mdo" version="1.1.0" />
|
||||||
<modello file="maven-core/src/main/mdo/toolchains.mdo" />
|
<modello file="maven-core/src/main/mdo/toolchains.mdo" />
|
||||||
<modello file="maven-repository-metadata/src/main/mdo/metadata.mdo" />
|
<modello file="maven-repository-metadata/src/main/mdo/metadata.mdo" version="1.1.0" />
|
||||||
<modello file="maven-compat/src/main/mdo/profiles.mdo" />
|
<modello file="maven-compat/src/main/mdo/profiles.mdo" />
|
||||||
<modello file="maven-compat/src/main/mdo/paramdoc.mdo" />
|
<modello file="maven-compat/src/main/mdo/paramdoc.mdo" />
|
||||||
</target>
|
</target>
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven</artifactId>
|
||||||
|
<version>3.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>maven-aether-provider</artifactId>
|
||||||
|
|
||||||
|
<name>Maven Aether Provider</name>
|
||||||
|
<description>
|
||||||
|
This module provides extensions to Aether for utilizing the Maven POM and Maven metadata.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-model-builder</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-repository-metadata</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sonatype.aether</groupId>
|
||||||
|
<artifactId>aether-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sonatype.aether</groupId>
|
||||||
|
<artifactId>aether-util</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sonatype.aether</groupId>
|
||||||
|
<artifactId>aether-impl</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-component-annotations</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-component-metadata</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,449 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.maven.model.DependencyManagement;
|
||||||
|
import org.apache.maven.model.DistributionManagement;
|
||||||
|
import org.apache.maven.model.License;
|
||||||
|
import org.apache.maven.model.Model;
|
||||||
|
import org.apache.maven.model.Relocation;
|
||||||
|
import org.apache.maven.model.Repository;
|
||||||
|
import org.apache.maven.model.building.DefaultModelBuilderFactory;
|
||||||
|
import org.apache.maven.model.building.DefaultModelBuildingRequest;
|
||||||
|
import org.apache.maven.model.building.FileModelSource;
|
||||||
|
import org.apache.maven.model.building.ModelBuilder;
|
||||||
|
import org.apache.maven.model.building.ModelBuildingException;
|
||||||
|
import org.apache.maven.model.building.ModelBuildingRequest;
|
||||||
|
import org.apache.maven.model.building.ModelProblem;
|
||||||
|
import org.apache.maven.model.resolution.UnresolvableModelException;
|
||||||
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
import org.sonatype.aether.RepositoryException;
|
||||||
|
import org.sonatype.aether.RepositoryListener;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.artifact.ArtifactType;
|
||||||
|
import org.sonatype.aether.artifact.ArtifactTypeRegistry;
|
||||||
|
import org.sonatype.aether.graph.Dependency;
|
||||||
|
import org.sonatype.aether.graph.Exclusion;
|
||||||
|
import org.sonatype.aether.impl.ArtifactDescriptorReader;
|
||||||
|
import org.sonatype.aether.impl.ArtifactResolver;
|
||||||
|
import org.sonatype.aether.impl.RemoteRepositoryManager;
|
||||||
|
import org.sonatype.aether.impl.VersionResolver;
|
||||||
|
import org.sonatype.aether.transfer.ArtifactNotFoundException;
|
||||||
|
import org.sonatype.aether.util.artifact.ArtifactProperties;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifactType;
|
||||||
|
import org.sonatype.aether.util.artifact.SubArtifact;
|
||||||
|
import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.RepositoryPolicy;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactDescriptorException;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactDescriptorRequest;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactDescriptorResult;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactRequest;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactResolutionException;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactResult;
|
||||||
|
import org.sonatype.aether.resolution.VersionRequest;
|
||||||
|
import org.sonatype.aether.resolution.VersionResolutionException;
|
||||||
|
import org.sonatype.aether.spi.locator.Service;
|
||||||
|
import org.sonatype.aether.spi.locator.ServiceLocator;
|
||||||
|
import org.sonatype.aether.spi.log.Logger;
|
||||||
|
import org.sonatype.aether.spi.log.NullLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
@Component( role = ArtifactDescriptorReader.class )
|
||||||
|
public class DefaultArtifactDescriptorReader
|
||||||
|
implements ArtifactDescriptorReader, Service
|
||||||
|
{
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private Logger logger = NullLogger.INSTANCE;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private RemoteRepositoryManager remoteRepositoryManager;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private VersionResolver versionResolver;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private ArtifactResolver artifactResolver;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private ModelBuilder modelBuilder;
|
||||||
|
|
||||||
|
public void initService( ServiceLocator locator )
|
||||||
|
{
|
||||||
|
setLogger( locator.getService( Logger.class ) );
|
||||||
|
setRemoteRepositoryManager( locator.getService( RemoteRepositoryManager.class ) );
|
||||||
|
setVersionResolver( locator.getService( VersionResolver.class ) );
|
||||||
|
setArtifactResolver( locator.getService( ArtifactResolver.class ) );
|
||||||
|
modelBuilder = locator.getService( ModelBuilder.class );
|
||||||
|
if ( modelBuilder == null )
|
||||||
|
{
|
||||||
|
setModelBuilder( new DefaultModelBuilderFactory().newInstance() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultArtifactDescriptorReader setLogger( Logger logger )
|
||||||
|
{
|
||||||
|
this.logger = ( logger != null ) ? logger : NullLogger.INSTANCE;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultArtifactDescriptorReader setRemoteRepositoryManager( RemoteRepositoryManager remoteRepositoryManager )
|
||||||
|
{
|
||||||
|
if ( remoteRepositoryManager == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "remote repository manager has not been specified" );
|
||||||
|
}
|
||||||
|
this.remoteRepositoryManager = remoteRepositoryManager;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultArtifactDescriptorReader setVersionResolver( VersionResolver versionResolver )
|
||||||
|
{
|
||||||
|
if ( versionResolver == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "version resolver has not been specified" );
|
||||||
|
}
|
||||||
|
this.versionResolver = versionResolver;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultArtifactDescriptorReader setArtifactResolver( ArtifactResolver artifactResolver )
|
||||||
|
{
|
||||||
|
if ( artifactResolver == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "artifact resolver has not been specified" );
|
||||||
|
}
|
||||||
|
this.artifactResolver = artifactResolver;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultArtifactDescriptorReader setModelBuilder( ModelBuilder modelBuilder )
|
||||||
|
{
|
||||||
|
if ( modelBuilder == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "model builder has not been specified" );
|
||||||
|
}
|
||||||
|
this.modelBuilder = modelBuilder;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession session,
|
||||||
|
ArtifactDescriptorRequest request )
|
||||||
|
throws ArtifactDescriptorException
|
||||||
|
{
|
||||||
|
ArtifactDescriptorResult result = new ArtifactDescriptorResult( request );
|
||||||
|
|
||||||
|
Model model = loadPom( session, request, result );
|
||||||
|
|
||||||
|
if ( model != null )
|
||||||
|
{
|
||||||
|
ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry();
|
||||||
|
|
||||||
|
for ( Repository r : model.getRepositories() )
|
||||||
|
{
|
||||||
|
result.addRepository( convert( r ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( org.apache.maven.model.Dependency dependency : model.getDependencies() )
|
||||||
|
{
|
||||||
|
result.addDependency( convert( dependency, stereotypes ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
DependencyManagement mngt = model.getDependencyManagement();
|
||||||
|
if ( mngt != null )
|
||||||
|
{
|
||||||
|
for ( org.apache.maven.model.Dependency dependency : mngt.getDependencies() )
|
||||||
|
{
|
||||||
|
result.addManagedDependency( convert( dependency, stereotypes ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> properties = new LinkedHashMap<String, Object>();
|
||||||
|
|
||||||
|
List<License> licenses = model.getLicenses();
|
||||||
|
properties.put( "license.count", Integer.valueOf( licenses.size() ) );
|
||||||
|
for ( int i = 0; i < licenses.size(); i++ )
|
||||||
|
{
|
||||||
|
License license = licenses.get( i );
|
||||||
|
properties.put( "license." + i + ".name", license.getName() );
|
||||||
|
properties.put( "license." + i + ".url", license.getUrl() );
|
||||||
|
properties.put( "license." + i + ".comments", license.getComments() );
|
||||||
|
properties.put( "license." + i + ".distribution", license.getDistribution() );
|
||||||
|
}
|
||||||
|
|
||||||
|
result.setProperties( properties );
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Model loadPom( RepositorySystemSession session, ArtifactDescriptorRequest request,
|
||||||
|
ArtifactDescriptorResult result )
|
||||||
|
throws ArtifactDescriptorException
|
||||||
|
{
|
||||||
|
Set<String> visited = new LinkedHashSet<String>();
|
||||||
|
for ( Artifact artifact = request.getArtifact();; )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
VersionRequest versionRequest =
|
||||||
|
new VersionRequest( artifact, request.getRepositories(), request.getRequestContext() );
|
||||||
|
versionResolver.resolveVersion( session, versionRequest );
|
||||||
|
}
|
||||||
|
catch ( VersionResolutionException e )
|
||||||
|
{
|
||||||
|
result.addException( e );
|
||||||
|
throw new ArtifactDescriptorException( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !visited.add( artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion() ) )
|
||||||
|
{
|
||||||
|
RepositoryException exception =
|
||||||
|
new RepositoryException( "Artifact relocations form a cycle: " + visited );
|
||||||
|
invalidDescriptor( session, artifact, exception );
|
||||||
|
if ( session.isIgnoreInvalidArtifactDescriptor() )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
result.addException( exception );
|
||||||
|
throw new ArtifactDescriptorException( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
Artifact pomArtifact = artifact;
|
||||||
|
if ( pomArtifact.getClassifier().length() > 0 || !"pom".equals( pomArtifact.getExtension() ) )
|
||||||
|
{
|
||||||
|
pomArtifact = new SubArtifact( artifact, "", "pom" );
|
||||||
|
}
|
||||||
|
|
||||||
|
ArtifactResult resolveResult;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ArtifactRequest resolveRequest =
|
||||||
|
new ArtifactRequest( pomArtifact, request.getRepositories(), request.getRequestContext() );
|
||||||
|
resolveResult = artifactResolver.resolveArtifact( session, resolveRequest );
|
||||||
|
pomArtifact = resolveResult.getArtifact();
|
||||||
|
result.setRepository( resolveResult.getRepository() );
|
||||||
|
}
|
||||||
|
catch ( ArtifactResolutionException e )
|
||||||
|
{
|
||||||
|
if ( e.getCause() instanceof ArtifactNotFoundException )
|
||||||
|
{
|
||||||
|
missingDescriptor( session, artifact );
|
||||||
|
if ( session.isIgnoreMissingArtifactDescriptor() )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.addException( e );
|
||||||
|
throw new ArtifactDescriptorException( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
Model model;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest();
|
||||||
|
modelRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
|
||||||
|
modelRequest.setProcessPlugins( false );
|
||||||
|
modelRequest.setTwoPhaseBuilding( false );
|
||||||
|
modelRequest.setSystemProperties( toProperties( session.getSystemProperties() ) );
|
||||||
|
modelRequest.setUserProperties( toProperties( session.getUserProperties() ) );
|
||||||
|
modelRequest.setModelCache( DefaultModelCache.newInstance( session ) );
|
||||||
|
modelRequest.setModelResolver( new DefaultModelResolver( session, request.getRequestContext(),
|
||||||
|
artifactResolver, remoteRepositoryManager,
|
||||||
|
request.getRepositories() ) );
|
||||||
|
if ( resolveResult.getRepository() instanceof WorkspaceRepository )
|
||||||
|
{
|
||||||
|
modelRequest.setPomFile( pomArtifact.getFile() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modelRequest.setModelSource( new FileModelSource( pomArtifact.getFile() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
model = modelBuilder.build( modelRequest ).getEffectiveModel();
|
||||||
|
}
|
||||||
|
catch ( ModelBuildingException e )
|
||||||
|
{
|
||||||
|
for ( ModelProblem problem : e.getProblems() )
|
||||||
|
{
|
||||||
|
if ( problem.getException() instanceof UnresolvableModelException )
|
||||||
|
{
|
||||||
|
result.addException( problem.getException() );
|
||||||
|
throw new ArtifactDescriptorException( result );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
invalidDescriptor( session, artifact, e );
|
||||||
|
if ( session.isIgnoreInvalidArtifactDescriptor() )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
result.addException( e );
|
||||||
|
throw new ArtifactDescriptorException( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
Relocation relocation = getRelocation( model );
|
||||||
|
|
||||||
|
if ( relocation != null )
|
||||||
|
{
|
||||||
|
result.addRelocation( artifact );
|
||||||
|
artifact =
|
||||||
|
new RelocatedArtifact( artifact, relocation.getGroupId(), relocation.getArtifactId(),
|
||||||
|
relocation.getVersion() );
|
||||||
|
result.setArtifact( artifact );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Properties toProperties( Map<String, String> map )
|
||||||
|
{
|
||||||
|
Properties props = new Properties();
|
||||||
|
if ( map != null )
|
||||||
|
{
|
||||||
|
props.putAll( map );
|
||||||
|
}
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Relocation getRelocation( Model model )
|
||||||
|
{
|
||||||
|
Relocation relocation = null;
|
||||||
|
DistributionManagement distMngt = model.getDistributionManagement();
|
||||||
|
if ( distMngt != null )
|
||||||
|
{
|
||||||
|
relocation = distMngt.getRelocation();
|
||||||
|
}
|
||||||
|
return relocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dependency convert( org.apache.maven.model.Dependency dependency, ArtifactTypeRegistry stereotypes )
|
||||||
|
{
|
||||||
|
ArtifactType stereotype = stereotypes.get( dependency.getType() );
|
||||||
|
if ( stereotype == null )
|
||||||
|
{
|
||||||
|
stereotype = new DefaultArtifactType( dependency.getType() );
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean system = dependency.getSystemPath() != null && dependency.getSystemPath().length() > 0;
|
||||||
|
|
||||||
|
Map<String, String> props = null;
|
||||||
|
if ( system )
|
||||||
|
{
|
||||||
|
props = Collections.singletonMap( ArtifactProperties.LACKS_DESCRIPTOR, Boolean.TRUE.toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
Artifact artifact =
|
||||||
|
new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null,
|
||||||
|
dependency.getVersion(), props, stereotype );
|
||||||
|
|
||||||
|
if ( system )
|
||||||
|
{
|
||||||
|
artifact = artifact.setFile( new File( dependency.getSystemPath() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Exclusion> exclusions = new ArrayList<Exclusion>( dependency.getExclusions().size() );
|
||||||
|
for ( org.apache.maven.model.Exclusion exclusion : dependency.getExclusions() )
|
||||||
|
{
|
||||||
|
exclusions.add( convert( exclusion ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
Dependency result = new Dependency( artifact, dependency.getScope(), dependency.isOptional(), exclusions );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Exclusion convert( org.apache.maven.model.Exclusion exclusion )
|
||||||
|
{
|
||||||
|
return new Exclusion( exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*" );
|
||||||
|
}
|
||||||
|
|
||||||
|
static RemoteRepository convert( Repository repository )
|
||||||
|
{
|
||||||
|
RemoteRepository result =
|
||||||
|
new RemoteRepository( repository.getId(), repository.getLayout(), repository.getUrl() );
|
||||||
|
result.setPolicy( true, convert( repository.getSnapshots() ) );
|
||||||
|
result.setPolicy( false, convert( repository.getReleases() ) );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RepositoryPolicy convert( org.apache.maven.model.RepositoryPolicy policy )
|
||||||
|
{
|
||||||
|
boolean enabled = true;
|
||||||
|
String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
|
||||||
|
String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
|
||||||
|
|
||||||
|
if ( policy != null )
|
||||||
|
{
|
||||||
|
enabled = policy.isEnabled();
|
||||||
|
if ( policy.getUpdatePolicy() != null )
|
||||||
|
{
|
||||||
|
updates = policy.getUpdatePolicy();
|
||||||
|
}
|
||||||
|
if ( policy.getChecksumPolicy() != null )
|
||||||
|
{
|
||||||
|
checksums = policy.getChecksumPolicy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RepositoryPolicy( enabled, updates, checksums );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void missingDescriptor( RepositorySystemSession session, Artifact artifact )
|
||||||
|
{
|
||||||
|
RepositoryListener listener = session.getRepositoryListener();
|
||||||
|
if ( listener != null )
|
||||||
|
{
|
||||||
|
DefaultRepositoryEvent event = new DefaultRepositoryEvent( session, artifact );
|
||||||
|
listener.artifactDescriptorMissing( event );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void invalidDescriptor( RepositorySystemSession session, Artifact artifact, Exception exception )
|
||||||
|
{
|
||||||
|
RepositoryListener listener = session.getRepositoryListener();
|
||||||
|
if ( listener != null )
|
||||||
|
{
|
||||||
|
DefaultRepositoryEvent event = new DefaultRepositoryEvent( session, artifact );
|
||||||
|
event.setException( exception );
|
||||||
|
listener.artifactDescriptorInvalid( event );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,119 @@
|
||||||
|
package org.apache.maven.repository.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 org.apache.maven.model.building.ModelCache;
|
||||||
|
import org.sonatype.aether.RepositoryCache;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A model builder cache backed by the repository system cache.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
class DefaultModelCache
|
||||||
|
implements ModelCache
|
||||||
|
{
|
||||||
|
|
||||||
|
private final RepositorySystemSession session;
|
||||||
|
|
||||||
|
private final RepositoryCache cache;
|
||||||
|
|
||||||
|
public static ModelCache newInstance( RepositorySystemSession session )
|
||||||
|
{
|
||||||
|
if ( session.getCache() == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new DefaultModelCache( session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DefaultModelCache( RepositorySystemSession session )
|
||||||
|
{
|
||||||
|
this.session = session;
|
||||||
|
this.cache = session.getCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get( String groupId, String artifactId, String version, String tag )
|
||||||
|
{
|
||||||
|
return cache.get( session, new Key( groupId, artifactId, version, tag ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put( String groupId, String artifactId, String version, String tag, Object data )
|
||||||
|
{
|
||||||
|
cache.put( session, new Key( groupId, artifactId, version, tag ), data );
|
||||||
|
}
|
||||||
|
|
||||||
|
static class Key
|
||||||
|
{
|
||||||
|
|
||||||
|
private final String groupId;
|
||||||
|
|
||||||
|
private final String artifactId;
|
||||||
|
|
||||||
|
private final String version;
|
||||||
|
|
||||||
|
private final String tag;
|
||||||
|
|
||||||
|
private final int hash;
|
||||||
|
|
||||||
|
public Key( String groupId, String artifactId, String version, String tag )
|
||||||
|
{
|
||||||
|
this.groupId = groupId;
|
||||||
|
this.artifactId = artifactId;
|
||||||
|
this.version = version;
|
||||||
|
this.tag = tag;
|
||||||
|
|
||||||
|
int h = 17;
|
||||||
|
h = h * 31 + this.groupId.hashCode();
|
||||||
|
h = h * 31 + this.artifactId.hashCode();
|
||||||
|
h = h * 31 + this.version.hashCode();
|
||||||
|
h = h * 31 + this.tag.hashCode();
|
||||||
|
hash = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object obj )
|
||||||
|
{
|
||||||
|
if ( this == obj )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ( null == obj || !getClass().equals( obj.getClass() ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Key that = (Key) obj;
|
||||||
|
return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId )
|
||||||
|
&& version.equals( that.version ) && tag.equals( that.tag );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,128 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.maven.model.Repository;
|
||||||
|
import org.apache.maven.model.building.FileModelSource;
|
||||||
|
import org.apache.maven.model.building.ModelSource;
|
||||||
|
import org.apache.maven.model.resolution.InvalidRepositoryException;
|
||||||
|
import org.apache.maven.model.resolution.ModelResolver;
|
||||||
|
import org.apache.maven.model.resolution.UnresolvableModelException;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.impl.ArtifactResolver;
|
||||||
|
import org.sonatype.aether.impl.RemoteRepositoryManager;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactRequest;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactResolutionException;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A model resolver to assist building of dependency POMs. This resolver gives priority to those repositories that have
|
||||||
|
* been initially specified and repositories discovered in dependency POMs are recessively merged into the search chain.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
* @see DefaultArtifactDescriptorReader
|
||||||
|
*/
|
||||||
|
class DefaultModelResolver
|
||||||
|
implements ModelResolver
|
||||||
|
{
|
||||||
|
|
||||||
|
private final RepositorySystemSession session;
|
||||||
|
|
||||||
|
private final String context;
|
||||||
|
|
||||||
|
private List<RemoteRepository> repositories;
|
||||||
|
|
||||||
|
private final ArtifactResolver resolver;
|
||||||
|
|
||||||
|
private final RemoteRepositoryManager remoteRepositoryManager;
|
||||||
|
|
||||||
|
private final Set<String> repositoryIds;
|
||||||
|
|
||||||
|
public DefaultModelResolver( RepositorySystemSession session, String context, ArtifactResolver resolver,
|
||||||
|
RemoteRepositoryManager remoteRepositoryManager, List<RemoteRepository> repositories )
|
||||||
|
{
|
||||||
|
this.session = session;
|
||||||
|
this.context = context;
|
||||||
|
this.resolver = resolver;
|
||||||
|
this.remoteRepositoryManager = remoteRepositoryManager;
|
||||||
|
this.repositories = repositories;
|
||||||
|
this.repositoryIds = new HashSet<String>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private DefaultModelResolver( DefaultModelResolver original )
|
||||||
|
{
|
||||||
|
this.session = original.session;
|
||||||
|
this.context = original.context;
|
||||||
|
this.resolver = original.resolver;
|
||||||
|
this.remoteRepositoryManager = original.remoteRepositoryManager;
|
||||||
|
this.repositories = original.repositories;
|
||||||
|
this.repositoryIds = new HashSet<String>( original.repositoryIds );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRepository( Repository repository )
|
||||||
|
throws InvalidRepositoryException
|
||||||
|
{
|
||||||
|
if ( !repositoryIds.add( repository.getId() ) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<RemoteRepository> newRepositories =
|
||||||
|
Collections.singletonList( DefaultArtifactDescriptorReader.convert( repository ) );
|
||||||
|
|
||||||
|
this.repositories =
|
||||||
|
remoteRepositoryManager.aggregateRepositories( session, repositories, newRepositories, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelResolver newCopy()
|
||||||
|
{
|
||||||
|
return new DefaultModelResolver( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
public ModelSource resolveModel( String groupId, String artifactId, String version )
|
||||||
|
throws UnresolvableModelException
|
||||||
|
{
|
||||||
|
Artifact pomArtifact = new DefaultArtifact( groupId, artifactId, "", "pom", version );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ArtifactRequest request = new ArtifactRequest( pomArtifact, repositories, context );
|
||||||
|
pomArtifact = resolver.resolveArtifact( session, request ).getArtifact();
|
||||||
|
}
|
||||||
|
catch ( ArtifactResolutionException e )
|
||||||
|
{
|
||||||
|
throw new UnresolvableModelException( "Failed to resolve POM for " + groupId + ":" + artifactId + ":"
|
||||||
|
+ version + " due to " + e.getMessage(), groupId, artifactId, version, e );
|
||||||
|
}
|
||||||
|
|
||||||
|
File pomFile = pomArtifact.getFile();
|
||||||
|
|
||||||
|
return new FileModelSource( pomFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package org.apache.maven.repository.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 org.sonatype.aether.impl.ArtifactDescriptorReader;
|
||||||
|
import org.sonatype.aether.impl.MetadataGeneratorFactory;
|
||||||
|
import org.sonatype.aether.impl.VersionRangeResolver;
|
||||||
|
import org.sonatype.aether.impl.VersionResolver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple service locator that is already setup with all components from this library. To acquire a complete
|
||||||
|
* repository system, clients need to add some repository connectors for remote transfers. <em>Note:</em> This component
|
||||||
|
* is meant to assists those clients that employ the repository systems outside of an IoC container, Maven plugins
|
||||||
|
* should instead always use regular dependency injection to acquire the repository system.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public class DefaultServiceLocator
|
||||||
|
extends org.sonatype.aether.impl.internal.DefaultServiceLocator
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new service locator that already knows about all service implementations included this library.
|
||||||
|
*/
|
||||||
|
public DefaultServiceLocator()
|
||||||
|
{
|
||||||
|
addService( ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class );
|
||||||
|
addService( VersionResolver.class, DefaultVersionResolver.class );
|
||||||
|
addService( VersionRangeResolver.class, DefaultVersionRangeResolver.class );
|
||||||
|
addService( MetadataGeneratorFactory.class, SnapshotMetadataGeneratorFactory.class );
|
||||||
|
addService( MetadataGeneratorFactory.class, VersionsMetadataGeneratorFactory.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,269 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||||
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
|
import org.sonatype.aether.RepositoryListener;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
|
||||||
|
import org.sonatype.aether.util.metadata.DefaultMetadata;
|
||||||
|
import org.sonatype.aether.util.version.GenericVersionScheme;
|
||||||
|
import org.sonatype.aether.version.InvalidVersionSpecificationException;
|
||||||
|
import org.sonatype.aether.version.Version;
|
||||||
|
import org.sonatype.aether.version.VersionConstraint;
|
||||||
|
import org.sonatype.aether.version.VersionRange;
|
||||||
|
import org.sonatype.aether.version.VersionScheme;
|
||||||
|
import org.sonatype.aether.impl.MetadataResolver;
|
||||||
|
import org.sonatype.aether.impl.VersionRangeResolver;
|
||||||
|
import org.sonatype.aether.metadata.Metadata;
|
||||||
|
import org.sonatype.aether.repository.ArtifactRepository;
|
||||||
|
import org.sonatype.aether.repository.LocalRepositoryManager;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceReader;
|
||||||
|
import org.sonatype.aether.resolution.MetadataRequest;
|
||||||
|
import org.sonatype.aether.resolution.MetadataResult;
|
||||||
|
import org.sonatype.aether.resolution.VersionRangeRequest;
|
||||||
|
import org.sonatype.aether.resolution.VersionRangeResolutionException;
|
||||||
|
import org.sonatype.aether.resolution.VersionRangeResult;
|
||||||
|
import org.sonatype.aether.spi.locator.Service;
|
||||||
|
import org.sonatype.aether.spi.locator.ServiceLocator;
|
||||||
|
import org.sonatype.aether.spi.log.Logger;
|
||||||
|
import org.sonatype.aether.spi.log.NullLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
@Component( role = VersionRangeResolver.class )
|
||||||
|
public class DefaultVersionRangeResolver
|
||||||
|
implements VersionRangeResolver, Service
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String MAVEN_METADATA_XML = "maven-metadata.xml";
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private Logger logger = NullLogger.INSTANCE;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private MetadataResolver metadataResolver;
|
||||||
|
|
||||||
|
public void initService( ServiceLocator locator )
|
||||||
|
{
|
||||||
|
setLogger( locator.getService( Logger.class ) );
|
||||||
|
setMetadataResolver( locator.getService( MetadataResolver.class ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultVersionRangeResolver setLogger( Logger logger )
|
||||||
|
{
|
||||||
|
this.logger = ( logger != null ) ? logger : NullLogger.INSTANCE;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultVersionRangeResolver setMetadataResolver( MetadataResolver metadataResolver )
|
||||||
|
{
|
||||||
|
if ( metadataResolver == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "metadata resolver has not been specified" );
|
||||||
|
}
|
||||||
|
this.metadataResolver = metadataResolver;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request )
|
||||||
|
throws VersionRangeResolutionException
|
||||||
|
{
|
||||||
|
VersionRangeResult result = new VersionRangeResult( request );
|
||||||
|
|
||||||
|
VersionScheme versionScheme = new GenericVersionScheme();
|
||||||
|
|
||||||
|
VersionConstraint versionConstraint;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
versionConstraint = versionScheme.parseVersionConstraint( request.getArtifact().getVersion() );
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
result.addException( e );
|
||||||
|
throw new VersionRangeResolutionException( result );
|
||||||
|
}
|
||||||
|
|
||||||
|
result.setVersionConstraint( versionConstraint );
|
||||||
|
|
||||||
|
if ( versionConstraint.getRanges().isEmpty() )
|
||||||
|
{
|
||||||
|
result.addVersion( versionConstraint.getVersion() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Map<String, ArtifactRepository> versionIndex =
|
||||||
|
getVersions( session, result, request, getNature( session, versionConstraint.getRanges() ) );
|
||||||
|
|
||||||
|
List<Version> versions = new ArrayList<Version>();
|
||||||
|
for ( Map.Entry<String, ArtifactRepository> v : versionIndex.entrySet() )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Version ver = versionScheme.parseVersion( v.getKey() );
|
||||||
|
if ( versionConstraint.containsVersion( ver ) )
|
||||||
|
{
|
||||||
|
versions.add( ver );
|
||||||
|
result.setRepository( ver, v.getValue() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( InvalidVersionSpecificationException e )
|
||||||
|
{
|
||||||
|
result.addException( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort( versions );
|
||||||
|
result.setVersions( versions );
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, ArtifactRepository> getVersions( RepositorySystemSession session, VersionRangeResult result,
|
||||||
|
VersionRangeRequest request, Metadata.Nature nature )
|
||||||
|
{
|
||||||
|
Map<String, ArtifactRepository> versionIndex = new HashMap<String, ArtifactRepository>();
|
||||||
|
|
||||||
|
Metadata metadata =
|
||||||
|
new DefaultMetadata( request.getArtifact().getGroupId(), request.getArtifact().getArtifactId(),
|
||||||
|
MAVEN_METADATA_XML, nature );
|
||||||
|
|
||||||
|
List<MetadataRequest> metadataRequests = new ArrayList<MetadataRequest>( request.getRepositories().size() );
|
||||||
|
for ( RemoteRepository repository : request.getRepositories() )
|
||||||
|
{
|
||||||
|
MetadataRequest metadataRequest = new MetadataRequest( metadata, repository, request.getRequestContext() );
|
||||||
|
metadataRequest.setDeleteLocalCopyIfMissing( true );
|
||||||
|
metadataRequests.add( metadataRequest );
|
||||||
|
}
|
||||||
|
List<MetadataResult> metadataResults = metadataResolver.resolveMetadata( session, metadataRequests );
|
||||||
|
|
||||||
|
WorkspaceReader workspace = session.getWorkspaceReader();
|
||||||
|
if ( workspace != null )
|
||||||
|
{
|
||||||
|
List<String> versions = workspace.findVersions( request.getArtifact() );
|
||||||
|
for ( String version : versions )
|
||||||
|
{
|
||||||
|
versionIndex.put( version, workspace.getRepository() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
|
||||||
|
File localMetadataFile = new File( lrm.getRepository().getBasedir(), lrm.getPathForLocalMetadata( metadata ) );
|
||||||
|
if ( localMetadataFile.isFile() )
|
||||||
|
{
|
||||||
|
metadata = metadata.setFile( localMetadataFile );
|
||||||
|
Versioning versioning = readVersions( session, metadata, result );
|
||||||
|
for ( String version : versioning.getVersions() )
|
||||||
|
{
|
||||||
|
if ( !versionIndex.containsKey( version ) )
|
||||||
|
{
|
||||||
|
versionIndex.put( version, lrm.getRepository() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( MetadataResult metadataResult : metadataResults )
|
||||||
|
{
|
||||||
|
result.addException( metadataResult.getException() );
|
||||||
|
Versioning versioning = readVersions( session, metadataResult.getMetadata(), result );
|
||||||
|
for ( String version : versioning.getVersions() )
|
||||||
|
{
|
||||||
|
if ( !versionIndex.containsKey( version ) )
|
||||||
|
{
|
||||||
|
versionIndex.put( version, metadataResult.getRequest().getRepository() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return versionIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Metadata.Nature getNature( RepositorySystemSession session, Collection<VersionRange> ranges )
|
||||||
|
{
|
||||||
|
for ( VersionRange range : ranges )
|
||||||
|
{
|
||||||
|
if ( range.acceptsSnapshots() )
|
||||||
|
{
|
||||||
|
return Metadata.Nature.RELEASE_OR_SNAPSHOT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Metadata.Nature.RELEASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Versioning readVersions( RepositorySystemSession session, Metadata metadata, VersionRangeResult result )
|
||||||
|
{
|
||||||
|
Versioning versioning = null;
|
||||||
|
|
||||||
|
FileInputStream fis = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ( metadata != null && metadata.getFile() != null )
|
||||||
|
{
|
||||||
|
fis = new FileInputStream( metadata.getFile() );
|
||||||
|
org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false );
|
||||||
|
versioning = m.getVersioning();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( FileNotFoundException e )
|
||||||
|
{
|
||||||
|
// tolerable
|
||||||
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
invalidMetadata( session, metadata, e );
|
||||||
|
result.addException( e );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close( fis );
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( versioning != null ) ? versioning : new Versioning();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void invalidMetadata( RepositorySystemSession session, Metadata metadata, Exception exception )
|
||||||
|
{
|
||||||
|
RepositoryListener listener = session.getRepositoryListener();
|
||||||
|
if ( listener != null )
|
||||||
|
{
|
||||||
|
DefaultRepositoryEvent event = new DefaultRepositoryEvent( session, metadata );
|
||||||
|
event.setException( exception );
|
||||||
|
listener.metadataInvalid( event );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,487 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.SnapshotVersion;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||||
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
import org.sonatype.aether.RepositoryCache;
|
||||||
|
import org.sonatype.aether.RepositoryListener;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
|
||||||
|
import org.sonatype.aether.util.metadata.DefaultMetadata;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.impl.MetadataResolver;
|
||||||
|
import org.sonatype.aether.impl.VersionResolver;
|
||||||
|
import org.sonatype.aether.impl.internal.CacheUtils;
|
||||||
|
import org.sonatype.aether.metadata.Metadata;
|
||||||
|
import org.sonatype.aether.repository.ArtifactRepository;
|
||||||
|
import org.sonatype.aether.repository.LocalRepositoryManager;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceReader;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
||||||
|
import org.sonatype.aether.resolution.MetadataRequest;
|
||||||
|
import org.sonatype.aether.resolution.MetadataResult;
|
||||||
|
import org.sonatype.aether.resolution.VersionRequest;
|
||||||
|
import org.sonatype.aether.resolution.VersionResolutionException;
|
||||||
|
import org.sonatype.aether.resolution.VersionResult;
|
||||||
|
import org.sonatype.aether.spi.locator.Service;
|
||||||
|
import org.sonatype.aether.spi.locator.ServiceLocator;
|
||||||
|
import org.sonatype.aether.spi.log.Logger;
|
||||||
|
import org.sonatype.aether.spi.log.NullLogger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
@Component( role = VersionResolver.class )
|
||||||
|
public class DefaultVersionResolver
|
||||||
|
implements VersionResolver, Service
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String MAVEN_METADATA_XML = "maven-metadata.xml";
|
||||||
|
|
||||||
|
private static final String RELEASE = "RELEASE";
|
||||||
|
|
||||||
|
private static final String LATEST = "LATEST";
|
||||||
|
|
||||||
|
private static final String SNAPSHOT = "SNAPSHOT";
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private Logger logger = NullLogger.INSTANCE;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private MetadataResolver metadataResolver;
|
||||||
|
|
||||||
|
public void initService( ServiceLocator locator )
|
||||||
|
{
|
||||||
|
setLogger( locator.getService( Logger.class ) );
|
||||||
|
setMetadataResolver( locator.getService( MetadataResolver.class ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultVersionResolver setLogger( Logger logger )
|
||||||
|
{
|
||||||
|
this.logger = ( logger != null ) ? logger : NullLogger.INSTANCE;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultVersionResolver setMetadataResolver( MetadataResolver metadataResolver )
|
||||||
|
{
|
||||||
|
if ( metadataResolver == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "metadata resolver has not been specified" );
|
||||||
|
}
|
||||||
|
this.metadataResolver = metadataResolver;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VersionResult resolveVersion( RepositorySystemSession session, VersionRequest request )
|
||||||
|
throws VersionResolutionException
|
||||||
|
{
|
||||||
|
Artifact artifact = request.getArtifact();
|
||||||
|
|
||||||
|
String version = artifact.getVersion();
|
||||||
|
|
||||||
|
VersionResult result = new VersionResult( request );
|
||||||
|
|
||||||
|
Key cacheKey = null;
|
||||||
|
RepositoryCache cache = session.getCache();
|
||||||
|
if ( cache != null )
|
||||||
|
{
|
||||||
|
cacheKey = new Key( session, request );
|
||||||
|
|
||||||
|
Object obj = cache.get( session, cacheKey );
|
||||||
|
if ( obj instanceof Record )
|
||||||
|
{
|
||||||
|
Record record = (Record) obj;
|
||||||
|
result.setVersion( record.version );
|
||||||
|
result.setRepository( CacheUtils.getRepository( session, request.getRepositories(), record.repoClass,
|
||||||
|
record.repoId ) );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Metadata metadata;
|
||||||
|
|
||||||
|
if ( RELEASE.equals( version ) )
|
||||||
|
{
|
||||||
|
metadata =
|
||||||
|
new DefaultMetadata( artifact.getGroupId(), artifact.getArtifactId(), MAVEN_METADATA_XML,
|
||||||
|
Metadata.Nature.RELEASE );
|
||||||
|
}
|
||||||
|
else if ( LATEST.equals( version ) )
|
||||||
|
{
|
||||||
|
metadata =
|
||||||
|
new DefaultMetadata( artifact.getGroupId(), artifact.getArtifactId(), MAVEN_METADATA_XML,
|
||||||
|
Metadata.Nature.RELEASE_OR_SNAPSHOT );
|
||||||
|
}
|
||||||
|
else if ( version.endsWith( SNAPSHOT ) )
|
||||||
|
{
|
||||||
|
WorkspaceReader workspace = session.getWorkspaceReader();
|
||||||
|
if ( workspace != null && workspace.findVersions( artifact ).contains( version ) )
|
||||||
|
{
|
||||||
|
metadata = null;
|
||||||
|
result.setRepository( workspace.getRepository() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
metadata =
|
||||||
|
new DefaultMetadata( artifact.getGroupId(), artifact.getArtifactId(), version, MAVEN_METADATA_XML,
|
||||||
|
Metadata.Nature.SNAPSHOT );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
metadata = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( metadata == null )
|
||||||
|
{
|
||||||
|
result.setVersion( version );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
List<MetadataRequest> metadataRequests = new ArrayList<MetadataRequest>( request.getRepositories().size() );
|
||||||
|
for ( RemoteRepository repository : request.getRepositories() )
|
||||||
|
{
|
||||||
|
MetadataRequest metadataRequest =
|
||||||
|
new MetadataRequest( metadata, repository, request.getRequestContext() );
|
||||||
|
metadataRequest.setDeleteLocalCopyIfMissing( true );
|
||||||
|
metadataRequest.setFavorLocalRepository( true );
|
||||||
|
metadataRequests.add( metadataRequest );
|
||||||
|
}
|
||||||
|
List<MetadataResult> metadataResults = metadataResolver.resolveMetadata( session, metadataRequests );
|
||||||
|
|
||||||
|
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
|
||||||
|
File localMetadataFile =
|
||||||
|
new File( lrm.getRepository().getBasedir(), lrm.getPathForLocalMetadata( metadata ) );
|
||||||
|
if ( localMetadataFile.isFile() )
|
||||||
|
{
|
||||||
|
metadata = metadata.setFile( localMetadataFile );
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, VersionInfo> infos = new HashMap<String, VersionInfo>();
|
||||||
|
merge( artifact, infos, readVersions( session, metadata, result ),
|
||||||
|
session.getLocalRepositoryManager().getRepository() );
|
||||||
|
|
||||||
|
for ( MetadataResult metadataResult : metadataResults )
|
||||||
|
{
|
||||||
|
result.addException( metadataResult.getException() );
|
||||||
|
merge( artifact, infos, readVersions( session, metadataResult.getMetadata(), result ),
|
||||||
|
metadataResult.getRequest().getRepository() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( RELEASE.equals( version ) )
|
||||||
|
{
|
||||||
|
resolve( result, infos, RELEASE );
|
||||||
|
}
|
||||||
|
else if ( LATEST.equals( version ) )
|
||||||
|
{
|
||||||
|
if ( !resolve( result, infos, LATEST ) )
|
||||||
|
{
|
||||||
|
resolve( result, infos, RELEASE );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( result.getVersion() != null && result.getVersion().endsWith( SNAPSHOT ) )
|
||||||
|
{
|
||||||
|
VersionRequest subRequest = new VersionRequest();
|
||||||
|
subRequest.setArtifact( artifact.setVersion( result.getVersion() ) );
|
||||||
|
if ( result.getRepository() instanceof RemoteRepository )
|
||||||
|
{
|
||||||
|
subRequest.setRepositories( Collections.singletonList( (RemoteRepository) result.getRepository() ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
subRequest.setRepositories( request.getRepositories() );
|
||||||
|
}
|
||||||
|
VersionResult subResult = resolveVersion( session, subRequest );
|
||||||
|
result.setVersion( subResult.getVersion() );
|
||||||
|
result.setRepository( subResult.getRepository() );
|
||||||
|
for ( Exception exception : subResult.getExceptions() )
|
||||||
|
{
|
||||||
|
result.addException( exception );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( !resolve( result, infos, SNAPSHOT + artifact.getClassifier() )
|
||||||
|
&& !resolve( result, infos, SNAPSHOT ) )
|
||||||
|
{
|
||||||
|
result.setVersion( version );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isEmpty( result.getVersion() ) )
|
||||||
|
{
|
||||||
|
throw new VersionResolutionException( result );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( cacheKey != null && metadata != null )
|
||||||
|
{
|
||||||
|
cache.put( session, cacheKey, new Record( result.getVersion(), result.getRepository() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean resolve( VersionResult result, Map<String, VersionInfo> infos, String key )
|
||||||
|
{
|
||||||
|
VersionInfo info = infos.get( key );
|
||||||
|
if ( info != null )
|
||||||
|
{
|
||||||
|
result.setVersion( info.version );
|
||||||
|
result.setRepository( info.repository );
|
||||||
|
}
|
||||||
|
return info != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Versioning readVersions( RepositorySystemSession session, Metadata metadata, VersionResult result )
|
||||||
|
{
|
||||||
|
Versioning versioning = null;
|
||||||
|
|
||||||
|
FileInputStream fis = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ( metadata != null && metadata.getFile() != null )
|
||||||
|
{
|
||||||
|
fis = new FileInputStream( metadata.getFile() );
|
||||||
|
org.apache.maven.artifact.repository.metadata.Metadata m = new MetadataXpp3Reader().read( fis, false );
|
||||||
|
versioning = m.getVersioning();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch ( FileNotFoundException e )
|
||||||
|
{
|
||||||
|
// tolerable
|
||||||
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
invalidMetadata( session, metadata, e );
|
||||||
|
result.addException( e );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close( fis );
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( versioning != null ) ? versioning : new Versioning();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void invalidMetadata( RepositorySystemSession session, Metadata metadata, Exception exception )
|
||||||
|
{
|
||||||
|
RepositoryListener listener = session.getRepositoryListener();
|
||||||
|
if ( listener != null )
|
||||||
|
{
|
||||||
|
DefaultRepositoryEvent event = new DefaultRepositoryEvent( session, metadata );
|
||||||
|
event.setException( exception );
|
||||||
|
listener.metadataInvalid( event );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void merge( Artifact artifact, Map<String, VersionInfo> infos, Versioning versioning,
|
||||||
|
ArtifactRepository repository )
|
||||||
|
{
|
||||||
|
if ( StringUtils.isNotEmpty( versioning.getRelease() ) )
|
||||||
|
{
|
||||||
|
merge( RELEASE, infos, versioning.getLastUpdated(), versioning.getRelease(), repository );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( StringUtils.isNotEmpty( versioning.getLatest() ) )
|
||||||
|
{
|
||||||
|
merge( LATEST, infos, versioning.getLastUpdated(), versioning.getLatest(), repository );
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean mainSnapshot = false;
|
||||||
|
for ( SnapshotVersion sv : versioning.getSnapshotVersions() )
|
||||||
|
{
|
||||||
|
if ( StringUtils.isNotEmpty( sv.getVersion() ) )
|
||||||
|
{
|
||||||
|
mainSnapshot |= sv.getClassifier().length() <= 0;
|
||||||
|
merge( SNAPSHOT + sv.getClassifier(), infos, sv.getUpdated(), sv.getVersion(), repository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Snapshot snapshot = versioning.getSnapshot();
|
||||||
|
if ( !mainSnapshot && snapshot != null )
|
||||||
|
{
|
||||||
|
String version = artifact.getVersion();
|
||||||
|
if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 )
|
||||||
|
{
|
||||||
|
String qualifier = snapshot.getTimestamp() + '-' + snapshot.getBuildNumber();
|
||||||
|
version = version.substring( 0, version.length() - SNAPSHOT.length() ) + qualifier;
|
||||||
|
}
|
||||||
|
merge( SNAPSHOT, infos, versioning.getLastUpdated(), version, repository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void merge( String key, Map<String, VersionInfo> infos, String timestamp, String version,
|
||||||
|
ArtifactRepository repository )
|
||||||
|
{
|
||||||
|
VersionInfo info = infos.get( key );
|
||||||
|
if ( info == null )
|
||||||
|
{
|
||||||
|
info = new VersionInfo( timestamp, version, repository );
|
||||||
|
infos.put( key, info );
|
||||||
|
}
|
||||||
|
else if ( info.isOutdated( timestamp ) )
|
||||||
|
{
|
||||||
|
info.version = version;
|
||||||
|
info.repository = repository;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class VersionInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
String timestamp;
|
||||||
|
|
||||||
|
String version;
|
||||||
|
|
||||||
|
ArtifactRepository repository;
|
||||||
|
|
||||||
|
public VersionInfo( String timestamp, String version, ArtifactRepository repository )
|
||||||
|
{
|
||||||
|
this.timestamp = ( timestamp != null ) ? timestamp : "";
|
||||||
|
this.version = version;
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOutdated( String timestamp )
|
||||||
|
{
|
||||||
|
return timestamp != null && timestamp.compareTo( this.timestamp ) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Key
|
||||||
|
{
|
||||||
|
|
||||||
|
private final String groupId;
|
||||||
|
|
||||||
|
private final String artifactId;
|
||||||
|
|
||||||
|
private final String version;
|
||||||
|
|
||||||
|
private final String context;
|
||||||
|
|
||||||
|
private final File localRepo;
|
||||||
|
|
||||||
|
private final WorkspaceRepository workspace;
|
||||||
|
|
||||||
|
private final List<RemoteRepository> repositories;
|
||||||
|
|
||||||
|
private final int hashCode;
|
||||||
|
|
||||||
|
public Key( RepositorySystemSession session, VersionRequest request )
|
||||||
|
{
|
||||||
|
groupId = request.getArtifact().getGroupId();
|
||||||
|
artifactId = request.getArtifact().getArtifactId();
|
||||||
|
version = request.getArtifact().getVersion();
|
||||||
|
context = request.getRequestContext();
|
||||||
|
localRepo = session.getLocalRepository().getBasedir();
|
||||||
|
workspace = CacheUtils.getWorkspace( session );
|
||||||
|
repositories = new ArrayList<RemoteRepository>( request.getRepositories().size() );
|
||||||
|
for ( RemoteRepository repository : request.getRepositories() )
|
||||||
|
{
|
||||||
|
if ( repository.isRepositoryManager() )
|
||||||
|
{
|
||||||
|
repositories.addAll( repository.getMirroredRepositories() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
repositories.add( repository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int hash = 17;
|
||||||
|
hash = hash * 31 + groupId.hashCode();
|
||||||
|
hash = hash * 31 + artifactId.hashCode();
|
||||||
|
hash = hash * 31 + version.hashCode();
|
||||||
|
hash = hash * 31 + localRepo.hashCode();
|
||||||
|
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
|
||||||
|
hashCode = hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object obj )
|
||||||
|
{
|
||||||
|
if ( obj == this )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if ( obj == null || !getClass().equals( obj.getClass() ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Key that = (Key) obj;
|
||||||
|
return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId )
|
||||||
|
&& version.equals( that.version ) && context.equals( that.context )
|
||||||
|
&& localRepo.equals( that.localRepo ) && CacheUtils.eq( workspace, that.workspace )
|
||||||
|
&& CacheUtils.repositoriesEquals( repositories, that.repositories );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Record
|
||||||
|
{
|
||||||
|
final String version;
|
||||||
|
|
||||||
|
final String repoId;
|
||||||
|
|
||||||
|
final Class<?> repoClass;
|
||||||
|
|
||||||
|
public Record( String version, ArtifactRepository repository )
|
||||||
|
{
|
||||||
|
this.version = version;
|
||||||
|
if ( repository != null )
|
||||||
|
{
|
||||||
|
repoId = repository.getId();
|
||||||
|
repoClass = repository.getClass();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
repoId = null;
|
||||||
|
repoClass = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
final class LocalSnapshotMetadata
|
||||||
|
extends MavenMetadata
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Artifact artifact;
|
||||||
|
|
||||||
|
public LocalSnapshotMetadata( Artifact artifact )
|
||||||
|
{
|
||||||
|
super( createMetadata( artifact ), null );
|
||||||
|
this.artifact = artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalSnapshotMetadata( Artifact artifact, File file )
|
||||||
|
{
|
||||||
|
super( createMetadata( artifact ), file );
|
||||||
|
this.artifact = artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Metadata createMetadata( Artifact artifact )
|
||||||
|
{
|
||||||
|
Snapshot snapshot = new Snapshot();
|
||||||
|
snapshot.setLocalCopy( true );
|
||||||
|
Versioning versioning = new Versioning();
|
||||||
|
versioning.setSnapshot( snapshot );
|
||||||
|
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
metadata.setModelVersion( "1.0.0" );
|
||||||
|
metadata.setVersioning( versioning );
|
||||||
|
metadata.setGroupId( artifact.getGroupId() );
|
||||||
|
metadata.setArtifactId( artifact.getArtifactId() );
|
||||||
|
metadata.setVersion( artifact.getBaseVersion() );
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MavenMetadata setFile( File file )
|
||||||
|
{
|
||||||
|
return new LocalSnapshotMetadata( artifact, file );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getKey()
|
||||||
|
{
|
||||||
|
return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getKey( Artifact artifact )
|
||||||
|
{
|
||||||
|
return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupId()
|
||||||
|
{
|
||||||
|
return artifact.getGroupId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtifactId()
|
||||||
|
{
|
||||||
|
return artifact.getArtifactId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return artifact.getBaseVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Nature getNature()
|
||||||
|
{
|
||||||
|
return Nature.SNAPSHOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package org.apache.maven.repository.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.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.impl.MetadataGenerator;
|
||||||
|
import org.sonatype.aether.installation.InstallRequest;
|
||||||
|
import org.sonatype.aether.metadata.Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
class LocalSnapshotMetadataGenerator
|
||||||
|
implements MetadataGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
private Map<Object, LocalSnapshotMetadata> snapshots;
|
||||||
|
|
||||||
|
public LocalSnapshotMetadataGenerator( RepositorySystemSession session, InstallRequest request )
|
||||||
|
{
|
||||||
|
snapshots = new LinkedHashMap<Object, LocalSnapshotMetadata>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<? extends Metadata> prepare( Collection<? extends Artifact> artifacts )
|
||||||
|
{
|
||||||
|
for ( Artifact artifact : artifacts )
|
||||||
|
{
|
||||||
|
if ( artifact.isSnapshot() )
|
||||||
|
{
|
||||||
|
Object key = LocalSnapshotMetadata.getKey( artifact );
|
||||||
|
LocalSnapshotMetadata snapshotMetadata = snapshots.get( key );
|
||||||
|
if ( snapshotMetadata == null )
|
||||||
|
{
|
||||||
|
snapshotMetadata = new LocalSnapshotMetadata( artifact );
|
||||||
|
snapshots.put( key, snapshotMetadata );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Artifact transformArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
return artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<? extends Metadata> finish( Collection<? extends Artifact> artifacts )
|
||||||
|
{
|
||||||
|
return snapshots.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,171 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.Writer;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
|
||||||
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
|
import org.codehaus.plexus.util.ReaderFactory;
|
||||||
|
import org.codehaus.plexus.util.WriterFactory;
|
||||||
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
import org.sonatype.aether.RepositoryException;
|
||||||
|
import org.sonatype.aether.metadata.MergeableMetadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
abstract class MavenMetadata
|
||||||
|
implements MergeableMetadata
|
||||||
|
{
|
||||||
|
|
||||||
|
private final File file;
|
||||||
|
|
||||||
|
protected Metadata metadata;
|
||||||
|
|
||||||
|
private boolean merged;
|
||||||
|
|
||||||
|
protected MavenMetadata( Metadata metadata, File file )
|
||||||
|
{
|
||||||
|
this.metadata = metadata;
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return "maven-metadata.xml";
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getFile()
|
||||||
|
{
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void merge( File existing, File result )
|
||||||
|
throws RepositoryException
|
||||||
|
{
|
||||||
|
Metadata recessive = read( existing );
|
||||||
|
|
||||||
|
merge( recessive );
|
||||||
|
|
||||||
|
write( result, metadata );
|
||||||
|
|
||||||
|
merged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMerged()
|
||||||
|
{
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void merge( Metadata recessive )
|
||||||
|
{
|
||||||
|
Versioning versioning = recessive.getVersioning();
|
||||||
|
if ( versioning != null )
|
||||||
|
{
|
||||||
|
versioning.setLastUpdated( null );
|
||||||
|
}
|
||||||
|
|
||||||
|
Metadata dominant = metadata;
|
||||||
|
|
||||||
|
versioning = dominant.getVersioning();
|
||||||
|
if ( versioning != null )
|
||||||
|
{
|
||||||
|
versioning.updateTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
dominant.merge( recessive );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Metadata read( File metadataFile )
|
||||||
|
throws RepositoryException
|
||||||
|
{
|
||||||
|
if ( metadataFile.length() <= 0 )
|
||||||
|
{
|
||||||
|
return new Metadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
Reader reader = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
reader = ReaderFactory.newXmlReader( metadataFile );
|
||||||
|
return new MetadataXpp3Reader().read( reader, false );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryException( "Could not read metadata " + metadataFile + ": " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
catch ( XmlPullParserException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryException( "Could not parse metadata " + metadataFile + ": " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close( reader );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void write( File metadataFile, Metadata metadata )
|
||||||
|
throws RepositoryException
|
||||||
|
{
|
||||||
|
Writer writer = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
metadataFile.getParentFile().mkdirs();
|
||||||
|
writer = WriterFactory.newXmlWriter( metadataFile );
|
||||||
|
new MetadataXpp3Writer().write( writer, metadata );
|
||||||
|
}
|
||||||
|
catch ( IOException e )
|
||||||
|
{
|
||||||
|
throw new RepositoryException( "Could not write metadata " + metadataFile + ": " + e.getMessage(), e );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtil.close( writer );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
StringBuilder buffer = new StringBuilder( 128 );
|
||||||
|
if ( getGroupId().length() > 0 )
|
||||||
|
{
|
||||||
|
buffer.append( getGroupId() );
|
||||||
|
}
|
||||||
|
if ( getArtifactId().length() > 0 )
|
||||||
|
{
|
||||||
|
buffer.append( ':' ).append( getArtifactId() );
|
||||||
|
}
|
||||||
|
if ( getVersion().length() > 0 )
|
||||||
|
{
|
||||||
|
buffer.append( ':' ).append( getVersion() );
|
||||||
|
}
|
||||||
|
buffer.append( '/' ).append( getType() );
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package org.apache.maven.repository.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 org.sonatype.aether.collection.DependencyGraphTransformer;
|
||||||
|
import org.sonatype.aether.collection.DependencyManager;
|
||||||
|
import org.sonatype.aether.collection.DependencySelector;
|
||||||
|
import org.sonatype.aether.collection.DependencyTraverser;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifactType;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifactTypeRegistry;
|
||||||
|
import org.sonatype.aether.util.graph.manager.ClassicDependencyManager;
|
||||||
|
import org.sonatype.aether.util.graph.selector.AndDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.ExclusionDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.OptionalDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.ScopeDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.ConflictMarker;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.NearestVersionConflictResolver;
|
||||||
|
import org.sonatype.aether.util.graph.traverser.FatArtifactTraverser;
|
||||||
|
import org.sonatype.aether.util.repository.DefaultAuthenticationSelector;
|
||||||
|
import org.sonatype.aether.util.repository.DefaultMirrorSelector;
|
||||||
|
import org.sonatype.aether.util.repository.DefaultProxySelector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simplistic repository system session that mimics Maven's behavior to help third-party developers that want to embed
|
||||||
|
* Maven's dependency resolution into their own applications. <strong>Warning:</strong> This class is not intended for
|
||||||
|
* usage by Maven plugins, those should always acquire the current repository system session via parameter injection.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public class MavenRepositorySystemSession
|
||||||
|
extends DefaultRepositorySystemSession
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Maven-like repository system session by initializing the session with values typical for
|
||||||
|
* Maven-based resolution.
|
||||||
|
*/
|
||||||
|
public MavenRepositorySystemSession()
|
||||||
|
{
|
||||||
|
setMirrorSelector( new DefaultMirrorSelector() );
|
||||||
|
setAuthenticationSelector( new DefaultAuthenticationSelector() );
|
||||||
|
setProxySelector( new DefaultProxySelector() );
|
||||||
|
|
||||||
|
DependencyTraverser depTraverser = new FatArtifactTraverser();
|
||||||
|
setDependencyTraverser( depTraverser );
|
||||||
|
|
||||||
|
DependencyManager depManager = new ClassicDependencyManager();
|
||||||
|
setDependencyManager( depManager );
|
||||||
|
|
||||||
|
DependencySelector depFilter =
|
||||||
|
new AndDependencySelector( new ScopeDependencySelector( "test", "provided" ),
|
||||||
|
new OptionalDependencySelector(), new ExclusionDependencySelector() );
|
||||||
|
setDependencySelector( depFilter );
|
||||||
|
|
||||||
|
DependencyGraphTransformer transformer =
|
||||||
|
new ChainedDependencyGraphTransformer( new ConflictMarker(), new JavaEffectiveScopeCalculator(),
|
||||||
|
new NearestVersionConflictResolver(),
|
||||||
|
new JavaDependencyContextRefiner() );
|
||||||
|
setDependencyGraphTransformer( transformer );
|
||||||
|
|
||||||
|
DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
|
||||||
|
stereotypes.add( new DefaultArtifactType( "pom" ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "maven-plugin", "jar", "", "java" ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "jar", "jar", "", "java" ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "ejb", "jar", "", "java" ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "ejb-client", "jar", "client", "java" ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "test-jar", "jar", "tests", "java" ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "javadoc", "jar", "javadoc", "java" ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "java-source", "jar", "sources", "java", false, false ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "war", "war", "", "java", false, true ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "ear", "ear", "", "java", false, true ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "rar", "rar", "", "java", false, true ) );
|
||||||
|
stereotypes.add( new DefaultArtifactType( "par", "par", "", "java", false, true ) );
|
||||||
|
setArtifactTypeRegistry( stereotypes );
|
||||||
|
|
||||||
|
setIgnoreInvalidArtifactDescriptor( true );
|
||||||
|
setIgnoreMissingArtifactDescriptor( true );
|
||||||
|
|
||||||
|
setSystemProps( System.getProperties() );
|
||||||
|
setConfigProps( System.getProperties() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.util.artifact.AbstractArtifact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
final class RelocatedArtifact
|
||||||
|
extends AbstractArtifact
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Artifact artifact;
|
||||||
|
|
||||||
|
private final String groupId;
|
||||||
|
|
||||||
|
private final String artifactId;
|
||||||
|
|
||||||
|
private final String version;
|
||||||
|
|
||||||
|
public RelocatedArtifact( Artifact artifact, String groupId, String artifactId, String version )
|
||||||
|
{
|
||||||
|
if ( artifact == null )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( "no artifact specified" );
|
||||||
|
}
|
||||||
|
this.artifact = artifact;
|
||||||
|
this.groupId = ( groupId != null && groupId.length() > 0 ) ? groupId : null;
|
||||||
|
this.artifactId = ( artifactId != null && artifactId.length() > 0 ) ? artifactId : null;
|
||||||
|
this.version = ( version != null && version.length() > 0 ) ? version : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupId()
|
||||||
|
{
|
||||||
|
if ( groupId != null )
|
||||||
|
{
|
||||||
|
return groupId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return artifact.getGroupId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtifactId()
|
||||||
|
{
|
||||||
|
if ( artifactId != null )
|
||||||
|
{
|
||||||
|
return artifactId;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return artifact.getArtifactId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
if ( version != null )
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return artifact.getVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBaseVersion()
|
||||||
|
{
|
||||||
|
return toBaseVersion( getVersion() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSnapshot()
|
||||||
|
{
|
||||||
|
return isSnapshot( getVersion() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClassifier()
|
||||||
|
{
|
||||||
|
return artifact.getClassifier();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExtension()
|
||||||
|
{
|
||||||
|
return artifact.getExtension();
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getFile()
|
||||||
|
{
|
||||||
|
return artifact.getFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProperty( String key, String defaultValue )
|
||||||
|
{
|
||||||
|
return artifact.getProperty( key, defaultValue );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getProperties()
|
||||||
|
{
|
||||||
|
return artifact.getProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,196 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.SnapshotVersion;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
final class RemoteSnapshotMetadata
|
||||||
|
extends MavenMetadata
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String SNAPSHOT = "SNAPSHOT";
|
||||||
|
|
||||||
|
private final Collection<Artifact> artifacts = new ArrayList<Artifact>();
|
||||||
|
|
||||||
|
private final Map<String, SnapshotVersion> versions = new LinkedHashMap<String, SnapshotVersion>();
|
||||||
|
|
||||||
|
public RemoteSnapshotMetadata( Artifact artifact )
|
||||||
|
{
|
||||||
|
super( createMetadata( artifact ), null );
|
||||||
|
}
|
||||||
|
|
||||||
|
private RemoteSnapshotMetadata( Metadata metadata, File file )
|
||||||
|
{
|
||||||
|
super( metadata, file );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Metadata createMetadata( Artifact artifact )
|
||||||
|
{
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
metadata.setModelVersion( "1.1.0" );
|
||||||
|
metadata.setGroupId( artifact.getGroupId() );
|
||||||
|
metadata.setArtifactId( artifact.getArtifactId() );
|
||||||
|
metadata.setVersion( artifact.getBaseVersion() );
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bind( Artifact artifact )
|
||||||
|
{
|
||||||
|
artifacts.add( artifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MavenMetadata setFile( File file )
|
||||||
|
{
|
||||||
|
return new RemoteSnapshotMetadata( metadata, file );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getKey()
|
||||||
|
{
|
||||||
|
return getGroupId() + ':' + getArtifactId() + ':' + getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getKey( Artifact artifact )
|
||||||
|
{
|
||||||
|
return artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExpandedVersion( Artifact artifact )
|
||||||
|
{
|
||||||
|
return versions.get( artifact.getClassifier() ).getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void merge( Metadata recessive )
|
||||||
|
{
|
||||||
|
Snapshot snapshot;
|
||||||
|
String lastUpdated = "";
|
||||||
|
|
||||||
|
if ( metadata.getVersioning() == null )
|
||||||
|
{
|
||||||
|
DateFormat utcDateFormatter = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
|
||||||
|
utcDateFormatter.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
|
||||||
|
|
||||||
|
snapshot = new Snapshot();
|
||||||
|
snapshot.setBuildNumber( getBuildNumber( recessive ) + 1 );
|
||||||
|
snapshot.setTimestamp( utcDateFormatter.format( new Date() ) );
|
||||||
|
|
||||||
|
Versioning versioning = new Versioning();
|
||||||
|
versioning.setSnapshot( snapshot );
|
||||||
|
versioning.setLastUpdated( snapshot.getTimestamp().replace( ".", "" ) );
|
||||||
|
lastUpdated = versioning.getLastUpdated();
|
||||||
|
|
||||||
|
metadata.setVersioning( versioning );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snapshot = metadata.getVersioning().getSnapshot();
|
||||||
|
lastUpdated = metadata.getVersioning().getLastUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( Artifact artifact : artifacts )
|
||||||
|
{
|
||||||
|
String version = artifact.getVersion();
|
||||||
|
|
||||||
|
if ( version.endsWith( SNAPSHOT ) )
|
||||||
|
{
|
||||||
|
String qualifier = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber();
|
||||||
|
version = version.substring( 0, version.length() - SNAPSHOT.length() ) + qualifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
SnapshotVersion sv = new SnapshotVersion();
|
||||||
|
sv.setClassifier( artifact.getClassifier() );
|
||||||
|
sv.setVersion( version );
|
||||||
|
sv.setUpdated( lastUpdated );
|
||||||
|
versions.put( sv.getClassifier(), sv );
|
||||||
|
}
|
||||||
|
|
||||||
|
artifacts.clear();
|
||||||
|
|
||||||
|
Versioning versioning = recessive.getVersioning();
|
||||||
|
if ( versioning != null )
|
||||||
|
{
|
||||||
|
for ( SnapshotVersion sv : versioning.getSnapshotVersions() )
|
||||||
|
{
|
||||||
|
if ( !versions.containsKey( sv.getClassifier() ) )
|
||||||
|
{
|
||||||
|
versions.put( sv.getClassifier(), sv );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
metadata.getVersioning().setSnapshotVersions( new ArrayList<SnapshotVersion>( versions.values() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getBuildNumber( Metadata metadata )
|
||||||
|
{
|
||||||
|
int number = 0;
|
||||||
|
|
||||||
|
Versioning versioning = metadata.getVersioning();
|
||||||
|
if ( versioning != null )
|
||||||
|
{
|
||||||
|
Snapshot snapshot = versioning.getSnapshot();
|
||||||
|
if ( snapshot != null && snapshot.getBuildNumber() > 0 )
|
||||||
|
{
|
||||||
|
number = snapshot.getBuildNumber();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupId()
|
||||||
|
{
|
||||||
|
return metadata.getGroupId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtifactId()
|
||||||
|
{
|
||||||
|
return metadata.getArtifactId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return metadata.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Nature getNature()
|
||||||
|
{
|
||||||
|
return Nature.SNAPSHOT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.apache.maven.repository.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.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.deployment.DeployRequest;
|
||||||
|
import org.sonatype.aether.impl.MetadataGenerator;
|
||||||
|
import org.sonatype.aether.metadata.Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
class RemoteSnapshotMetadataGenerator
|
||||||
|
implements MetadataGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
private Map<Object, RemoteSnapshotMetadata> snapshots;
|
||||||
|
|
||||||
|
public RemoteSnapshotMetadataGenerator( RepositorySystemSession session, DeployRequest request )
|
||||||
|
{
|
||||||
|
snapshots = new LinkedHashMap<Object, RemoteSnapshotMetadata>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: This should be considered a quirk to support interop with Maven's legacy ArtifactDeployer which
|
||||||
|
* processes one artifact at a time and hence cannot associate the artifacts from the same project to use the
|
||||||
|
* same timestamp+buildno for the snapshot versions. Allowing the caller to pass in metadata from a previous
|
||||||
|
* deployment allows to re-establish the association between the artifacts of the same project.
|
||||||
|
*/
|
||||||
|
for ( Metadata metadata : request.getMetadata() )
|
||||||
|
{
|
||||||
|
if ( metadata instanceof RemoteSnapshotMetadata )
|
||||||
|
{
|
||||||
|
RemoteSnapshotMetadata snapshotMetadata = (RemoteSnapshotMetadata) metadata;
|
||||||
|
snapshots.put( snapshotMetadata.getKey(), snapshotMetadata );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<? extends Metadata> prepare( Collection<? extends Artifact> artifacts )
|
||||||
|
{
|
||||||
|
for ( Artifact artifact : artifacts )
|
||||||
|
{
|
||||||
|
if ( artifact.isSnapshot() )
|
||||||
|
{
|
||||||
|
Object key = RemoteSnapshotMetadata.getKey( artifact );
|
||||||
|
RemoteSnapshotMetadata snapshotMetadata = snapshots.get( key );
|
||||||
|
if ( snapshotMetadata == null )
|
||||||
|
{
|
||||||
|
snapshotMetadata = new RemoteSnapshotMetadata( artifact );
|
||||||
|
snapshots.put( key, snapshotMetadata );
|
||||||
|
}
|
||||||
|
snapshotMetadata.bind( artifact );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return snapshots.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Artifact transformArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
if ( artifact.isSnapshot() && artifact.getVersion().equals( artifact.getBaseVersion() ) )
|
||||||
|
{
|
||||||
|
Object key = RemoteSnapshotMetadata.getKey( artifact );
|
||||||
|
RemoteSnapshotMetadata snapshotMetadata = snapshots.get( key );
|
||||||
|
if ( snapshotMetadata != null )
|
||||||
|
{
|
||||||
|
artifact = artifact.setVersion( snapshotMetadata.getExpandedVersion( artifact ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<? extends Metadata> finish( Collection<? extends Artifact> artifacts )
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package org.apache.maven.repository.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 org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.deployment.DeployRequest;
|
||||||
|
import org.sonatype.aether.impl.MetadataGenerator;
|
||||||
|
import org.sonatype.aether.impl.MetadataGeneratorFactory;
|
||||||
|
import org.sonatype.aether.installation.InstallRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
@Component( role = MetadataGeneratorFactory.class, hint = "snapshot" )
|
||||||
|
public class SnapshotMetadataGeneratorFactory
|
||||||
|
implements MetadataGeneratorFactory
|
||||||
|
{
|
||||||
|
|
||||||
|
public MetadataGenerator newInstance( RepositorySystemSession session, InstallRequest request )
|
||||||
|
{
|
||||||
|
return new LocalSnapshotMetadataGenerator( session, request );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataGenerator newInstance( RepositorySystemSession session, DeployRequest request )
|
||||||
|
{
|
||||||
|
return new RemoteSnapshotMetadataGenerator( session, request );
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPriority()
|
||||||
|
{
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package org.apache.maven.repository.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.io.File;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Metadata;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
final class VersionsMetadata
|
||||||
|
extends MavenMetadata
|
||||||
|
{
|
||||||
|
|
||||||
|
private final Artifact artifact;
|
||||||
|
|
||||||
|
public VersionsMetadata( Artifact artifact )
|
||||||
|
{
|
||||||
|
super( createMetadata( artifact ), null );
|
||||||
|
this.artifact = artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VersionsMetadata( Artifact artifact, File file )
|
||||||
|
{
|
||||||
|
super( createMetadata( artifact ), file );
|
||||||
|
this.artifact = artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Metadata createMetadata( Artifact artifact )
|
||||||
|
{
|
||||||
|
Versioning versioning = new Versioning();
|
||||||
|
versioning.addVersion( artifact.getBaseVersion() );
|
||||||
|
if ( !artifact.isSnapshot() )
|
||||||
|
{
|
||||||
|
versioning.setRelease( artifact.getVersion() );
|
||||||
|
}
|
||||||
|
|
||||||
|
Metadata metadata = new Metadata();
|
||||||
|
metadata.setModelVersion( "1.0.0" );
|
||||||
|
metadata.setVersioning( versioning );
|
||||||
|
metadata.setGroupId( artifact.getGroupId() );
|
||||||
|
metadata.setArtifactId( artifact.getArtifactId() );
|
||||||
|
|
||||||
|
return metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getKey()
|
||||||
|
{
|
||||||
|
return getGroupId() + ':' + getArtifactId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getKey( Artifact artifact )
|
||||||
|
{
|
||||||
|
return artifact.getGroupId() + ':' + artifact.getArtifactId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MavenMetadata setFile( File file )
|
||||||
|
{
|
||||||
|
return new VersionsMetadata( artifact, file );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupId()
|
||||||
|
{
|
||||||
|
return artifact.getGroupId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtifactId()
|
||||||
|
{
|
||||||
|
return artifact.getArtifactId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Nature getNature()
|
||||||
|
{
|
||||||
|
return artifact.isSnapshot() ? Nature.RELEASE_OR_SNAPSHOT : Nature.RELEASE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
package org.apache.maven.repository.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.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.deployment.DeployRequest;
|
||||||
|
import org.sonatype.aether.impl.MetadataGenerator;
|
||||||
|
import org.sonatype.aether.installation.InstallRequest;
|
||||||
|
import org.sonatype.aether.metadata.Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
class VersionsMetadataGenerator
|
||||||
|
implements MetadataGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
private Map<Object, VersionsMetadata> versions;
|
||||||
|
|
||||||
|
public VersionsMetadataGenerator( RepositorySystemSession session, InstallRequest request )
|
||||||
|
{
|
||||||
|
this( session, request.getMetadata() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public VersionsMetadataGenerator( RepositorySystemSession session, DeployRequest request )
|
||||||
|
{
|
||||||
|
this( session, request.getMetadata() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private VersionsMetadataGenerator( RepositorySystemSession session, Collection<? extends Metadata> metadatas )
|
||||||
|
{
|
||||||
|
versions = new LinkedHashMap<Object, VersionsMetadata>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: This should be considered a quirk to support interop with Maven's legacy ArtifactDeployer which
|
||||||
|
* processes one artifact at a time and hence cannot associate the artifacts from the same project to use the
|
||||||
|
* same timestamp+buildno for the snapshot versions. Allowing the caller to pass in metadata from a previous
|
||||||
|
* deployment allows to re-establish the association between the artifacts of the same project.
|
||||||
|
*/
|
||||||
|
for ( Metadata metadata : metadatas )
|
||||||
|
{
|
||||||
|
if ( metadata instanceof VersionsMetadata )
|
||||||
|
{
|
||||||
|
VersionsMetadata versionsMetadata = (VersionsMetadata) metadata;
|
||||||
|
versions.put( versionsMetadata.getKey(), versionsMetadata );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<? extends Metadata> prepare( Collection<? extends Artifact> artifacts )
|
||||||
|
{
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Artifact transformArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
return artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<? extends Metadata> finish( Collection<? extends Artifact> artifacts )
|
||||||
|
{
|
||||||
|
for ( Artifact artifact : artifacts )
|
||||||
|
{
|
||||||
|
Object key = VersionsMetadata.getKey( artifact );
|
||||||
|
VersionsMetadata versionsMetadata = versions.get( key );
|
||||||
|
if ( versionsMetadata == null )
|
||||||
|
{
|
||||||
|
versionsMetadata = new VersionsMetadata( artifact );
|
||||||
|
versions.put( key, versionsMetadata );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return versions.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package org.apache.maven.repository.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 org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.deployment.DeployRequest;
|
||||||
|
import org.sonatype.aether.impl.MetadataGenerator;
|
||||||
|
import org.sonatype.aether.impl.MetadataGeneratorFactory;
|
||||||
|
import org.sonatype.aether.installation.InstallRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
@Component( role = MetadataGeneratorFactory.class, hint = "versions" )
|
||||||
|
public class VersionsMetadataGeneratorFactory
|
||||||
|
implements MetadataGeneratorFactory
|
||||||
|
{
|
||||||
|
|
||||||
|
public MetadataGenerator newInstance( RepositorySystemSession session, InstallRequest request )
|
||||||
|
{
|
||||||
|
return new VersionsMetadataGenerator( session, request );
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataGenerator newInstance( RepositorySystemSession session, DeployRequest request )
|
||||||
|
{
|
||||||
|
return new VersionsMetadataGenerator( session, request );
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPriority()
|
||||||
|
{
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -493,7 +493,6 @@ public class DefaultArtifact
|
||||||
public void setVersionRange( VersionRange versionRange )
|
public void setVersionRange( VersionRange versionRange )
|
||||||
{
|
{
|
||||||
this.versionRange = versionRange;
|
this.versionRange = versionRange;
|
||||||
|
|
||||||
selectVersionFromNewRangeIfAvailable();
|
selectVersionFromNewRangeIfAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,12 @@
|
||||||
<artifactId>wagon-file</artifactId>
|
<artifactId>wagon-file</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sonatype.aether</groupId>
|
||||||
|
<artifactId>aether-connector-wagon</artifactId>
|
||||||
|
<version>${aetherVersion}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>easymock</groupId>
|
<groupId>easymock</groupId>
|
||||||
<artifactId>easymock</artifactId>
|
<artifactId>easymock</artifactId>
|
||||||
|
|
|
@ -20,50 +20,46 @@ package org.apache.maven.artifact.deployer;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.util.Map;
|
||||||
import java.util.Arrays;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
import org.apache.maven.RepositoryUtils;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataDeploymentException;
|
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
|
import org.apache.maven.artifact.repository.metadata.MetadataBridge;
|
||||||
import org.apache.maven.execution.MavenExecutionRequest;
|
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.execution.MavenSession;
|
|
||||||
import org.apache.maven.plugin.LegacySupport;
|
import org.apache.maven.plugin.LegacySupport;
|
||||||
import org.apache.maven.repository.RepositorySystem;
|
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
|
||||||
import org.apache.maven.repository.legacy.TransferListenerAdapter;
|
|
||||||
import org.apache.maven.repository.legacy.WagonManager;
|
|
||||||
import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager;
|
|
||||||
import org.apache.maven.wagon.TransferFailedException;
|
|
||||||
import org.apache.maven.wagon.events.TransferListener;
|
|
||||||
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;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.sonatype.aether.RepositorySystem;
|
||||||
|
import org.sonatype.aether.deployment.DeployRequest;
|
||||||
|
import org.sonatype.aether.deployment.DeployResult;
|
||||||
|
import org.sonatype.aether.deployment.DeploymentException;
|
||||||
|
import org.sonatype.aether.metadata.MergeableMetadata;
|
||||||
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.artifact.SubArtifact;
|
||||||
|
|
||||||
@Component( role = ArtifactDeployer.class )
|
@Component( role = ArtifactDeployer.class, instantiationStrategy = "per-lookup" )
|
||||||
public class DefaultArtifactDeployer
|
public class DefaultArtifactDeployer
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
implements ArtifactDeployer
|
implements ArtifactDeployer
|
||||||
{
|
{
|
||||||
@Requirement
|
|
||||||
private WagonManager wagonManager;
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private ArtifactTransformationManager transformationManager;
|
private RepositorySystem repoSystem;
|
||||||
|
|
||||||
@Requirement
|
|
||||||
private RepositoryMetadataManager repositoryMetadataManager;
|
|
||||||
|
|
||||||
@Requirement
|
|
||||||
private RepositorySystem repositorySystem;
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private LegacySupport legacySupport;
|
private LegacySupport legacySupport;
|
||||||
|
|
||||||
|
private Map<Object, MergeableMetadata> snapshots = new ConcurrentHashMap<Object, MergeableMetadata>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated we want to use the artifact method only, and ensure artifact.file is set
|
* @deprecated we want to use the artifact method only, and ensure artifact.file is set
|
||||||
* correctly.
|
* correctly.
|
||||||
|
@ -82,79 +78,78 @@ public class DefaultArtifactDeployer
|
||||||
ArtifactRepository localRepository )
|
ArtifactRepository localRepository )
|
||||||
throws ArtifactDeploymentException
|
throws ArtifactDeploymentException
|
||||||
{
|
{
|
||||||
deploymentRepository = injectSession( deploymentRepository );
|
DefaultRepositorySystemSession session =
|
||||||
|
new DefaultRepositorySystemSession( legacySupport.getRepositorySession() );
|
||||||
|
LocalRepository localRepo = new LocalRepository( localRepository.getBasedir() );
|
||||||
|
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( localRepo ) );
|
||||||
|
|
||||||
try
|
DeployRequest request = new DeployRequest();
|
||||||
|
|
||||||
|
org.sonatype.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact );
|
||||||
|
mainArtifact = mainArtifact.setFile( source );
|
||||||
|
request.addArtifact( mainArtifact );
|
||||||
|
|
||||||
|
String snapshotKey = null;
|
||||||
|
if ( artifact.isSnapshot() )
|
||||||
{
|
{
|
||||||
transformationManager.transformForDeployment( artifact, deploymentRepository, localRepository );
|
snapshotKey = artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getBaseVersion();
|
||||||
|
request.addMetadata( snapshots.get( snapshotKey ) );
|
||||||
|
}
|
||||||
|
|
||||||
// Copy the original file to the new one if it was transformed
|
for ( ArtifactMetadata metadata : artifact.getMetadataList() )
|
||||||
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
|
{
|
||||||
if ( !artifactFile.equals( source ) )
|
if ( metadata instanceof ProjectArtifactMetadata )
|
||||||
{
|
{
|
||||||
FileUtils.copyFile( source, artifactFile );
|
org.sonatype.aether.artifact.Artifact pomArtifact = new SubArtifact( mainArtifact, "", "pom" );
|
||||||
|
pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() );
|
||||||
|
request.addArtifact( pomArtifact );
|
||||||
}
|
}
|
||||||
|
else if ( metadata instanceof SnapshotArtifactRepositoryMetadata
|
||||||
wagonManager.putArtifact( source, artifact, deploymentRepository, getTransferListener() );
|
|| metadata instanceof ArtifactRepositoryMetadata )
|
||||||
|
|
||||||
// must be after the artifact is installed
|
|
||||||
for ( ArtifactMetadata metadata : artifact.getMetadataList() )
|
|
||||||
{
|
{
|
||||||
repositoryMetadataManager.deploy( metadata, localRepository, deploymentRepository );
|
// eaten, handled by repo system
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request.addMetadata( new MetadataBridge( metadata ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( TransferFailedException e )
|
|
||||||
{
|
|
||||||
throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e );
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e );
|
|
||||||
}
|
|
||||||
catch ( RepositoryMetadataDeploymentException e )
|
|
||||||
{
|
|
||||||
throw new ArtifactDeploymentException( "Error installing artifact's metadata: " + e.getMessage(), e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private TransferListener getTransferListener()
|
RemoteRepository remoteRepo = RepositoryUtils.toRepo( deploymentRepository );
|
||||||
{
|
|
||||||
MavenSession session = legacySupport.getSession();
|
|
||||||
|
|
||||||
if ( session == null )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TransferListenerAdapter.newAdapter( session.getRequest().getTransferListener() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArtifactRepository injectSession( ArtifactRepository repository )
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* NOTE: This provides backward-compat with maven-deploy-plugin:2.4 which bypasses the repository factory when
|
* NOTE: This provides backward-compat with maven-deploy-plugin:2.4 which bypasses the repository factory when
|
||||||
* using an alternative deployment location.
|
* using an alternative deployment location.
|
||||||
*/
|
*/
|
||||||
if ( repository instanceof DefaultArtifactRepository && repository.getAuthentication() == null )
|
if ( deploymentRepository instanceof DefaultArtifactRepository
|
||||||
|
&& deploymentRepository.getAuthentication() == null )
|
||||||
{
|
{
|
||||||
MavenSession session = legacySupport.getSession();
|
remoteRepo.setAuthentication( session.getAuthenticationSelector().getAuthentication( remoteRepo ) );
|
||||||
|
remoteRepo.setProxy( session.getProxySelector().getProxy( remoteRepo ) );
|
||||||
|
}
|
||||||
|
request.setRepository( remoteRepo );
|
||||||
|
|
||||||
if ( session != null )
|
DeployResult result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = repoSystem.deploy( session, request );
|
||||||
|
}
|
||||||
|
catch ( DeploymentException e )
|
||||||
|
{
|
||||||
|
throw new ArtifactDeploymentException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( snapshotKey != null )
|
||||||
|
{
|
||||||
|
for ( Object metadata : result.getMetadata() )
|
||||||
{
|
{
|
||||||
MavenExecutionRequest request = session.getRequest();
|
if ( metadata.getClass().getName().endsWith( ".internal.RemoteSnapshotMetadata" ) )
|
||||||
|
|
||||||
if ( request != null )
|
|
||||||
{
|
{
|
||||||
List<ArtifactRepository> repositories = Arrays.asList( repository );
|
snapshots.put( snapshotKey, (MergeableMetadata) metadata );
|
||||||
|
|
||||||
repositorySystem.injectProxy( repositories, request.getProxies() );
|
|
||||||
|
|
||||||
repositorySystem.injectAuthentication( repositories, request.getServers() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return repository;
|
artifact.setResolvedVersion( result.getArtifacts().iterator().next().getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,21 +20,27 @@ package org.apache.maven.artifact.installer;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
|
import org.apache.maven.RepositoryUtils;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataInstallationException;
|
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
|
import org.apache.maven.artifact.repository.metadata.MetadataBridge;
|
||||||
import org.apache.maven.repository.DefaultLocalRepositoryMaintainerEvent;
|
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
||||||
import org.apache.maven.repository.LocalRepositoryMaintainer;
|
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.repository.LocalRepositoryMaintainerEvent;
|
import org.apache.maven.artifact.repository.metadata.Versioning;
|
||||||
import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager;
|
import org.apache.maven.plugin.LegacySupport;
|
||||||
|
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
|
||||||
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;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.sonatype.aether.RepositorySystem;
|
||||||
|
import org.sonatype.aether.installation.InstallRequest;
|
||||||
|
import org.sonatype.aether.installation.InstallationException;
|
||||||
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.artifact.SubArtifact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
|
@ -44,15 +50,13 @@ public class DefaultArtifactInstaller
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
implements ArtifactInstaller
|
implements ArtifactInstaller
|
||||||
{
|
{
|
||||||
@Requirement
|
|
||||||
private ArtifactTransformationManager transformationManager;
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private RepositoryMetadataManager repositoryMetadataManager;
|
private RepositorySystem repoSystem;
|
||||||
|
|
||||||
@Requirement( optional = true )
|
@Requirement
|
||||||
private LocalRepositoryMaintainer localRepositoryMaintainer;
|
private LegacySupport legacySupport;
|
||||||
|
|
||||||
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
|
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
|
public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
|
||||||
|
@ -67,59 +71,64 @@ public class DefaultArtifactInstaller
|
||||||
public void install( File source, Artifact artifact, ArtifactRepository localRepository )
|
public void install( File source, Artifact artifact, ArtifactRepository localRepository )
|
||||||
throws ArtifactInstallationException
|
throws ArtifactInstallationException
|
||||||
{
|
{
|
||||||
try
|
DefaultRepositorySystemSession session =
|
||||||
|
new DefaultRepositorySystemSession( legacySupport.getRepositorySession() );
|
||||||
|
LocalRepository localRepo = new LocalRepository( localRepository.getBasedir() );
|
||||||
|
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( localRepo ) );
|
||||||
|
|
||||||
|
InstallRequest request = new InstallRequest();
|
||||||
|
|
||||||
|
org.sonatype.aether.artifact.Artifact mainArtifact = RepositoryUtils.toArtifact( artifact );
|
||||||
|
mainArtifact = mainArtifact.setFile( source );
|
||||||
|
request.addArtifact( mainArtifact );
|
||||||
|
|
||||||
|
for ( ArtifactMetadata metadata : artifact.getMetadataList() )
|
||||||
{
|
{
|
||||||
transformationManager.transformForInstall( artifact, localRepository );
|
if ( metadata instanceof ProjectArtifactMetadata )
|
||||||
|
|
||||||
String localPath = localRepository.pathOf( artifact );
|
|
||||||
|
|
||||||
// TODO: use a file: wagon and the wagon manager?
|
|
||||||
File destination = new File( localRepository.getBasedir(), localPath );
|
|
||||||
if ( !destination.getParentFile().exists() )
|
|
||||||
{
|
{
|
||||||
destination.getParentFile().mkdirs();
|
org.sonatype.aether.artifact.Artifact pomArtifact = new SubArtifact( mainArtifact, "", "pom" );
|
||||||
|
pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() );
|
||||||
|
request.addArtifact( pomArtifact );
|
||||||
}
|
}
|
||||||
|
else if ( metadata instanceof SnapshotArtifactRepositoryMetadata
|
||||||
boolean copy =
|
|| metadata instanceof ArtifactRepositoryMetadata )
|
||||||
!destination.exists() || "pom".equals( artifact.getType() )
|
|
||||||
|| source.lastModified() != destination.lastModified() || source.length() != destination.length();
|
|
||||||
|
|
||||||
if ( copy )
|
|
||||||
{
|
{
|
||||||
getLogger().info( "Installing " + source + " to " + destination );
|
// eaten, handled by repo system
|
||||||
|
|
||||||
FileUtils.copyFile( source, destination );
|
|
||||||
destination.setLastModified( source.lastModified() );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
getLogger().info( "Skipped re-installing " + source + " to " + destination + ", seems unchanged" );
|
request.addMetadata( new MetadataBridge( metadata ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// must be after the artifact is installed
|
try
|
||||||
for ( ArtifactMetadata metadata : artifact.getMetadataList() )
|
{
|
||||||
{
|
repoSystem.install( session, request );
|
||||||
repositoryMetadataManager.install( metadata, localRepository );
|
}
|
||||||
}
|
catch ( InstallationException e )
|
||||||
// TODO: would like to flush this, but the plugin metadata is added in advance, not as an install/deploy
|
{
|
||||||
// transformation
|
throw new ArtifactInstallationException( e.getMessage(), e );
|
||||||
// This would avoid the need to merge and clear out the state during deployment
|
}
|
||||||
// artifact.getMetadataList().clear();
|
|
||||||
|
|
||||||
if ( localRepositoryMaintainer != null )
|
/*
|
||||||
{
|
* NOTE: Not used by Maven core, only here to provide backward-compat with plugins like the Install Plugin.
|
||||||
LocalRepositoryMaintainerEvent event =
|
*/
|
||||||
new DefaultLocalRepositoryMaintainerEvent( localRepository, artifact, destination );
|
|
||||||
localRepositoryMaintainer.artifactInstalled( event );
|
if ( artifact.isSnapshot() )
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
{
|
||||||
throw new ArtifactInstallationException( "Error installing artifact: " + e.getMessage(), e );
|
Snapshot snapshot = new Snapshot();
|
||||||
|
snapshot.setLocalCopy( true );
|
||||||
|
artifact.addMetadata( new SnapshotArtifactRepositoryMetadata( artifact, snapshot ) );
|
||||||
}
|
}
|
||||||
catch ( RepositoryMetadataInstallationException e )
|
|
||||||
|
Versioning versioning = new Versioning();
|
||||||
|
versioning.updateTimestamp();
|
||||||
|
versioning.addVersion( artifact.getBaseVersion() );
|
||||||
|
if ( artifact.isRelease() )
|
||||||
{
|
{
|
||||||
throw new ArtifactInstallationException( "Error installing artifact's metadata: " + e.getMessage(), e );
|
versioning.setRelease( artifact.getBaseVersion() );
|
||||||
}
|
}
|
||||||
|
artifact.addMetadata( new ArtifactRepositoryMetadata( artifact, versioning ) );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@ package org.apache.maven.artifact.repository.metadata;
|
||||||
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
|
* 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
|
* "License"); you may not use this file except in compliance with the License. You may obtain a
|
||||||
* copy of the License at
|
* copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
* 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
|
* 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
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
|
@ -22,7 +22,6 @@ import java.io.Reader;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@ import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||||
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
|
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
|
||||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
import org.apache.maven.artifact.repository.RepositoryRequest;
|
||||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
|
||||||
|
@ -49,7 +47,7 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
*/
|
*/
|
||||||
@Component( role = RepositoryMetadataManager.class )
|
@Component(role=RepositoryMetadataManager.class)
|
||||||
public class DefaultRepositoryMetadataManager
|
public class DefaultRepositoryMetadataManager
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
implements RepositoryMetadataManager
|
implements RepositoryMetadataManager
|
||||||
|
@ -60,8 +58,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
@Requirement
|
@Requirement
|
||||||
private UpdateCheckManager updateCheckManager;
|
private UpdateCheckManager updateCheckManager;
|
||||||
|
|
||||||
public void resolve( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories,
|
public void resolve( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
|
||||||
ArtifactRepository localRepository )
|
|
||||||
throws RepositoryMetadataResolutionException
|
throws RepositoryMetadataResolutionException
|
||||||
{
|
{
|
||||||
RepositoryRequest request = new DefaultRepositoryRequest();
|
RepositoryRequest request = new DefaultRepositoryRequest();
|
||||||
|
@ -73,41 +70,6 @@ public class DefaultRepositoryMetadataManager
|
||||||
public void resolve( RepositoryMetadata metadata, RepositoryRequest request )
|
public void resolve( RepositoryMetadata metadata, RepositoryRequest request )
|
||||||
throws RepositoryMetadataResolutionException
|
throws RepositoryMetadataResolutionException
|
||||||
{
|
{
|
||||||
RepositoryCache cache = request.getCache();
|
|
||||||
|
|
||||||
CacheKey cacheKey = null;
|
|
||||||
|
|
||||||
if ( cache != null )
|
|
||||||
{
|
|
||||||
cacheKey = new CacheKey( metadata, request );
|
|
||||||
|
|
||||||
CacheRecord cacheRecord = (CacheRecord) cache.get( request, cacheKey );
|
|
||||||
|
|
||||||
if ( cacheRecord != null )
|
|
||||||
{
|
|
||||||
if ( getLogger().isDebugEnabled() )
|
|
||||||
{
|
|
||||||
getLogger().debug( "Resolved metadata from cache: " + metadata + " @ " + cacheRecord.repository );
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata.setMetadata( MetadataUtils.cloneMetadata( cacheRecord.metadata ) );
|
|
||||||
|
|
||||||
if ( cacheRecord.repository != null )
|
|
||||||
{
|
|
||||||
for ( ArtifactRepository repository : request.getRemoteRepositories() )
|
|
||||||
{
|
|
||||||
if ( cacheRecord.repository.equals( repository.getId() ) )
|
|
||||||
{
|
|
||||||
metadata.setRepository( repository );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ArtifactRepository localRepository = request.getLocalRepository();
|
ArtifactRepository localRepository = request.getLocalRepository();
|
||||||
List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories();
|
List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories();
|
||||||
|
|
||||||
|
@ -209,13 +171,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
catch ( RepositoryMetadataStoreException e )
|
catch ( RepositoryMetadataStoreException e )
|
||||||
{
|
{
|
||||||
throw new RepositoryMetadataResolutionException( "Unable to store local copy of metadata: "
|
throw new RepositoryMetadataResolutionException( "Unable to store local copy of metadata: " + e.getMessage(), e );
|
||||||
+ e.getMessage(), e );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( cache != null )
|
|
||||||
{
|
|
||||||
cache.put( request, cacheKey, new CacheRecord( metadata ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,130 +182,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
return metadataFile.isFile() ? new Date( metadataFile.lastModified() ) : null;
|
return metadataFile.isFile() ? new Date( metadataFile.lastModified() ) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class CacheKey
|
private void mergeMetadata( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
|
||||||
{
|
|
||||||
|
|
||||||
final Object metadataKey;
|
|
||||||
|
|
||||||
final ArtifactRepository localRepository;
|
|
||||||
|
|
||||||
final List<ArtifactRepository> remoteRepositories;
|
|
||||||
|
|
||||||
final int hashCode;
|
|
||||||
|
|
||||||
CacheKey( RepositoryMetadata metadata, RepositoryRequest request )
|
|
||||||
{
|
|
||||||
metadataKey = metadata.getKey();
|
|
||||||
localRepository = request.getLocalRepository();
|
|
||||||
remoteRepositories = request.getRemoteRepositories();
|
|
||||||
|
|
||||||
int hash = 17;
|
|
||||||
hash = hash * 31 + metadata.getKey().hashCode();
|
|
||||||
hash = hash * 31 + repoHashCode( localRepository );
|
|
||||||
for ( ArtifactRepository remoteRepository : remoteRepositories )
|
|
||||||
{
|
|
||||||
hash = hash * 31 + repoHashCode( remoteRepository );
|
|
||||||
}
|
|
||||||
hashCode = hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
int repoHashCode( ArtifactRepository repository )
|
|
||||||
{
|
|
||||||
return ( repository != null && repository.getUrl() != null ) ? repository.getUrl().hashCode() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean repoEquals( ArtifactRepository repo1, ArtifactRepository repo2 )
|
|
||||||
{
|
|
||||||
if ( repo1 == repo2 )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( repo1 == null || repo2 == null )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return equal( repo1.getUrl(), repo2.getUrl() ) && repo1.getClass() == repo2.getClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> boolean equal( T s1, T s2 )
|
|
||||||
{
|
|
||||||
return s1 != null ? s1.equals( s2 ) : s2 == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals( Object obj )
|
|
||||||
{
|
|
||||||
if ( this == obj )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !( obj instanceof CacheKey ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CacheKey that = (CacheKey) obj;
|
|
||||||
|
|
||||||
if ( !this.metadataKey.equals( that.metadataKey ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !repoEquals( this.localRepository, that.localRepository ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Iterator<ArtifactRepository> it1 = this.remoteRepositories.iterator(), it2 =
|
|
||||||
that.remoteRepositories.iterator();; )
|
|
||||||
{
|
|
||||||
if ( !it1.hasNext() || !it2.hasNext() )
|
|
||||||
{
|
|
||||||
if ( it1.hasNext() != it2.hasNext() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ArtifactRepository repo1 = it1.next();
|
|
||||||
ArtifactRepository repo2 = it2.next();
|
|
||||||
if ( !repoEquals( repo1, repo2 ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class CacheRecord
|
|
||||||
{
|
|
||||||
|
|
||||||
final Metadata metadata;
|
|
||||||
|
|
||||||
final String repository;
|
|
||||||
|
|
||||||
CacheRecord( RepositoryMetadata metadata )
|
|
||||||
{
|
|
||||||
this.metadata = MetadataUtils.cloneMetadata( metadata.getMetadata() );
|
|
||||||
this.repository = ( metadata.getRepository() != null ) ? metadata.getRepository().getId() : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergeMetadata( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories,
|
|
||||||
ArtifactRepository localRepository )
|
|
||||||
throws RepositoryMetadataStoreException
|
throws RepositoryMetadataStoreException
|
||||||
{
|
{
|
||||||
// TODO: currently this is first wins, but really we should take the latest by comparing either the
|
// TODO: currently this is first wins, but really we should take the latest by comparing either the
|
||||||
|
@ -378,9 +211,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
updateSnapshotMetadata( metadata, previousMetadata, selected, localRepository );
|
updateSnapshotMetadata( metadata, previousMetadata, selected, localRepository );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSnapshotMetadata( RepositoryMetadata metadata,
|
private void updateSnapshotMetadata( RepositoryMetadata metadata, Map<ArtifactRepository, Metadata> previousMetadata, ArtifactRepository selected, ArtifactRepository localRepository )
|
||||||
Map<ArtifactRepository, Metadata> previousMetadata,
|
|
||||||
ArtifactRepository selected, ArtifactRepository localRepository )
|
|
||||||
throws RepositoryMetadataStoreException
|
throws RepositoryMetadataStoreException
|
||||||
{
|
{
|
||||||
// TODO: this could be a lot nicer... should really be in the snapshot transformation?
|
// TODO: this could be a lot nicer... should really be in the snapshot transformation?
|
||||||
|
@ -405,8 +236,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( ( m.getVersioning() != null ) && ( m.getVersioning().getSnapshot() != null )
|
if ( ( m.getVersioning() != null ) && ( m.getVersioning().getSnapshot() != null ) && m.getVersioning().getSnapshot().isLocalCopy() )
|
||||||
&& m.getVersioning().getSnapshot().isLocalCopy() )
|
|
||||||
{
|
{
|
||||||
m.getVersioning().getSnapshot().setLocalCopy( false );
|
m.getVersioning().getSnapshot().setLocalCopy( false );
|
||||||
metadata.setMetadata( m );
|
metadata.setMetadata( m );
|
||||||
|
@ -419,14 +249,11 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository,
|
private boolean loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository, ArtifactRepository localRepository, Map<ArtifactRepository, Metadata> previousMetadata )
|
||||||
ArtifactRepository localRepository, Map<ArtifactRepository, Metadata> previousMetadata )
|
|
||||||
{
|
{
|
||||||
boolean setRepository = false;
|
boolean setRepository = false;
|
||||||
|
|
||||||
File metadataFile =
|
File metadataFile = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
|
||||||
new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( repoMetadata,
|
|
||||||
remoteRepository ) );
|
|
||||||
|
|
||||||
if ( metadataFile.exists() )
|
if ( metadataFile.exists() )
|
||||||
{
|
{
|
||||||
|
@ -488,13 +315,11 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': "
|
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': " + e.getMessage(), e );
|
||||||
+ e.getMessage(), e );
|
|
||||||
}
|
}
|
||||||
catch ( XmlPullParserException e )
|
catch ( XmlPullParserException e )
|
||||||
{
|
{
|
||||||
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': "
|
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': " + e.getMessage(), e );
|
||||||
+ e.getMessage(), e );
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -505,8 +330,8 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures the last updated timestamp of the specified metadata does not refer to the future and fixes the local
|
* Ensures the last updated timestamp of the specified metadata does not refer to the future and fixes the local metadata if necessary to allow
|
||||||
* metadata if necessary to allow proper merging/updating of metadata during deployment.
|
* proper merging/updating of metadata during deployment.
|
||||||
*/
|
*/
|
||||||
private void fixTimestamp( File metadataFile, Metadata metadata, Metadata reference )
|
private void fixTimestamp( File metadataFile, Metadata metadata, Metadata reference )
|
||||||
{
|
{
|
||||||
|
@ -562,8 +387,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository,
|
public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
|
||||||
ArtifactRepository remoteRepository )
|
|
||||||
throws RepositoryMetadataResolutionException
|
throws RepositoryMetadataResolutionException
|
||||||
{
|
{
|
||||||
File file;
|
File file;
|
||||||
|
@ -573,8 +397,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
catch ( TransferFailedException e )
|
catch ( TransferFailedException e )
|
||||||
{
|
{
|
||||||
throw new RepositoryMetadataResolutionException( metadata + " could not be retrieved from repository: "
|
throw new RepositoryMetadataResolutionException( metadata + " could not be retrieved from repository: " + remoteRepository.getId() + " due to an error: " + e.getMessage(), e );
|
||||||
+ remoteRepository.getId() + " due to an error: " + e.getMessage(), e );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -591,24 +414,18 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metadata,
|
private File getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metadata, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
|
||||||
ArtifactRepository localRepository,
|
|
||||||
ArtifactRepository remoteRepository )
|
|
||||||
throws TransferFailedException
|
throws TransferFailedException
|
||||||
{
|
{
|
||||||
File file =
|
File file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) );
|
||||||
new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata,
|
|
||||||
remoteRepository ) );
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wagonManager.getArtifactMetadataFromDeploymentRepository( metadata, remoteRepository, file,
|
wagonManager.getArtifactMetadataFromDeploymentRepository( metadata, remoteRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
|
||||||
ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
|
|
||||||
}
|
}
|
||||||
catch ( ResourceDoesNotExistException e )
|
catch ( ResourceDoesNotExistException e )
|
||||||
{
|
{
|
||||||
getLogger().info( metadata + " could not be found on repository: " + remoteRepository.getId()
|
getLogger().info( metadata + " could not be found on repository: " + remoteRepository.getId() + ", so will be created" );
|
||||||
+ ", so will be created" );
|
|
||||||
|
|
||||||
// delete the local copy so the old details aren't used.
|
// delete the local copy so the old details aren't used.
|
||||||
if ( file.exists() )
|
if ( file.exists() )
|
||||||
|
@ -626,8 +443,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deploy( ArtifactMetadata metadata, ArtifactRepository localRepository,
|
public void deploy( ArtifactMetadata metadata, ArtifactRepository localRepository, ArtifactRepository deploymentRepository )
|
||||||
ArtifactRepository deploymentRepository )
|
|
||||||
throws RepositoryMetadataDeploymentException
|
throws RepositoryMetadataDeploymentException
|
||||||
{
|
{
|
||||||
File file;
|
File file;
|
||||||
|
@ -640,8 +456,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
}
|
}
|
||||||
catch ( TransferFailedException e )
|
catch ( TransferFailedException e )
|
||||||
{
|
{
|
||||||
throw new RepositoryMetadataDeploymentException( metadata + " could not be retrieved from repository: "
|
throw new RepositoryMetadataDeploymentException( metadata + " could not be retrieved from repository: " + deploymentRepository.getId() + " due to an error: " + e.getMessage(), e );
|
||||||
+ deploymentRepository.getId() + " due to an error: " + e.getMessage(), e );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( file.isFile() )
|
if ( file.isFile() )
|
||||||
|
@ -659,9 +474,7 @@ public class DefaultRepositoryMetadataManager
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// It's a POM - we don't need to retrieve it first
|
// It's a POM - we don't need to retrieve it first
|
||||||
file =
|
file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
|
||||||
new File( localRepository.getBasedir(),
|
|
||||||
localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -0,0 +1,157 @@
|
||||||
|
package org.apache.maven.artifact.repository.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.io.File;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.metadata.ArtifactMetadata;
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
||||||
|
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
||||||
|
import org.codehaus.plexus.util.FileUtils;
|
||||||
|
import org.sonatype.aether.RepositoryException;
|
||||||
|
import org.sonatype.aether.metadata.MergeableMetadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <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
|
||||||
|
*/
|
||||||
|
public final class MetadataBridge
|
||||||
|
implements MergeableMetadata
|
||||||
|
{
|
||||||
|
|
||||||
|
private ArtifactMetadata metadata;
|
||||||
|
|
||||||
|
private boolean merged;
|
||||||
|
|
||||||
|
public MetadataBridge( ArtifactMetadata metadata )
|
||||||
|
{
|
||||||
|
this.metadata = metadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void merge( File current, File result )
|
||||||
|
throws RepositoryException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if ( current.exists() )
|
||||||
|
{
|
||||||
|
FileUtils.copyFile( current, result );
|
||||||
|
}
|
||||||
|
ArtifactRepository localRepo = new MetadataRepository( result );
|
||||||
|
metadata.storeInLocalRepository( localRepo, localRepo );
|
||||||
|
merged = true;
|
||||||
|
}
|
||||||
|
catch ( Exception e )
|
||||||
|
{
|
||||||
|
throw new RepositoryException( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMerged()
|
||||||
|
{
|
||||||
|
return merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGroupId()
|
||||||
|
{
|
||||||
|
return emptify( metadata.getGroupId() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getArtifactId()
|
||||||
|
{
|
||||||
|
return metadata.storedInGroupDirectory() ? "" : emptify( metadata.getArtifactId() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion()
|
||||||
|
{
|
||||||
|
return metadata.storedInArtifactVersionDirectory() ? emptify( metadata.getBaseVersion() ) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType()
|
||||||
|
{
|
||||||
|
return metadata.getRemoteFilename();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String emptify( String string )
|
||||||
|
{
|
||||||
|
return ( string != null ) ? string : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getFile()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataBridge setFile( File file )
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Nature getNature()
|
||||||
|
{
|
||||||
|
if ( metadata instanceof RepositoryMetadata )
|
||||||
|
{
|
||||||
|
switch ( ( (RepositoryMetadata) metadata ).getNature() )
|
||||||
|
{
|
||||||
|
case RepositoryMetadata.RELEASE_OR_SNAPSHOT:
|
||||||
|
return Nature.RELEASE_OR_SNAPSHOT;
|
||||||
|
case RepositoryMetadata.SNAPSHOT:
|
||||||
|
return Nature.SNAPSHOT;
|
||||||
|
default:
|
||||||
|
return Nature.RELEASE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Nature.RELEASE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings( "deprecation" )
|
||||||
|
static class MetadataRepository
|
||||||
|
extends DefaultArtifactRepository
|
||||||
|
{
|
||||||
|
|
||||||
|
private File metadataFile;
|
||||||
|
|
||||||
|
public MetadataRepository( File metadataFile )
|
||||||
|
{
|
||||||
|
super( "local", "", null );
|
||||||
|
this.metadataFile = metadataFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getBasedir()
|
||||||
|
{
|
||||||
|
return metadataFile.getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
|
||||||
|
{
|
||||||
|
return metadataFile.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,26 +1,21 @@
|
||||||
package org.apache.maven.artifact.resolver;
|
package org.apache.maven.artifact.resolver;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* agreements. See the NOTICE file distributed with this work for additional information regarding
|
||||||
* distributed with this work for additional information
|
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* "License"); you may not use this file except in compliance with the License. You may obtain a
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* copy of the License at
|
||||||
* "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
|
||||||
*
|
*
|
||||||
* 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
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* software distributed under the License is distributed on an
|
* the License.
|
||||||
* "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.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
@ -37,57 +32,43 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import org.apache.maven.RepositoryUtils;
|
||||||
import org.apache.maven.artifact.Artifact;
|
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.metadata.ResolutionGroup;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
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.repository.RepositoryRequest;
|
||||||
import org.apache.maven.artifact.repository.metadata.Metadata;
|
|
||||||
import org.apache.maven.artifact.repository.metadata.Snapshot;
|
|
||||||
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
|
|
||||||
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.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.LegacySupport;
|
import org.apache.maven.plugin.LegacySupport;
|
||||||
import org.apache.maven.repository.DefaultLocalRepositoryMaintainerEvent;
|
|
||||||
import org.apache.maven.repository.LocalRepositoryMaintainer;
|
|
||||||
import org.apache.maven.repository.LocalRepositoryMaintainerEvent;
|
|
||||||
import org.apache.maven.repository.legacy.TransferListenerAdapter;
|
|
||||||
import org.apache.maven.repository.legacy.WagonManager;
|
|
||||||
import org.apache.maven.repository.legacy.metadata.ArtifactMetadata;
|
|
||||||
import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest;
|
import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest;
|
||||||
import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest;
|
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.wagon.ResourceDoesNotExistException;
|
|
||||||
import org.apache.maven.wagon.TransferFailedException;
|
|
||||||
import org.apache.maven.wagon.events.TransferListener;
|
import org.apache.maven.wagon.events.TransferListener;
|
||||||
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;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.FileUtils;
|
import org.sonatype.aether.RepositorySystem;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactRequest;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactResult;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
*/
|
*/
|
||||||
@Component( role = ArtifactResolver.class )
|
@Component(role = ArtifactResolver.class)
|
||||||
public class DefaultArtifactResolver
|
public class DefaultArtifactResolver
|
||||||
implements ArtifactResolver
|
implements ArtifactResolver
|
||||||
{
|
{
|
||||||
@Requirement
|
@Requirement
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
@Requirement
|
|
||||||
private WagonManager wagonManager;
|
|
||||||
|
|
||||||
@Requirement
|
|
||||||
private ArtifactTransformationManager transformationManager;
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
protected ArtifactFactory artifactFactory;
|
protected ArtifactFactory artifactFactory;
|
||||||
|
|
||||||
|
@ -99,16 +80,16 @@ public class DefaultArtifactResolver
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private ArtifactMetadataSource source;
|
private ArtifactMetadataSource source;
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private PlexusContainer container;
|
private PlexusContainer container;
|
||||||
|
|
||||||
@Requirement( optional = true )
|
|
||||||
private LocalRepositoryMaintainer localRepositoryMaintainer;
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private LegacySupport legacySupport;
|
private LegacySupport legacySupport;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private RepositorySystem repoSystem;
|
||||||
|
|
||||||
private final Executor executor;
|
private final Executor executor;
|
||||||
|
|
||||||
public DefaultArtifactResolver()
|
public DefaultArtifactResolver()
|
||||||
|
@ -141,13 +122,32 @@ public class DefaultArtifactResolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RepositorySystemSession getSession( ArtifactRepository localRepository )
|
||||||
|
{
|
||||||
|
MavenSession mavenSession = legacySupport.getSession();
|
||||||
|
DefaultRepositorySystemSession session;
|
||||||
|
if ( mavenSession != null )
|
||||||
|
{
|
||||||
|
session = new DefaultRepositorySystemSession( mavenSession.getRepositorySession() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
session = new DefaultRepositorySystemSession();
|
||||||
|
}
|
||||||
|
if ( localRepository != null && localRepository.getBasedir() != null )
|
||||||
|
{
|
||||||
|
LocalRepository localRepo = new LocalRepository( localRepository.getBasedir() );
|
||||||
|
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( localRepo ) );
|
||||||
|
}
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
private void injectSession1( RepositoryRequest request, MavenSession session )
|
private void injectSession1( RepositoryRequest request, MavenSession session )
|
||||||
{
|
{
|
||||||
if ( session != null )
|
if ( session != null )
|
||||||
{
|
{
|
||||||
request.setOffline( session.isOffline() );
|
request.setOffline( session.isOffline() );
|
||||||
request.setForceUpdate( session.getRequest().isUpdateSnapshots() );
|
request.setForceUpdate( session.getRequest().isUpdateSnapshots() );
|
||||||
request.setTransferListener( session.getRequest().getTransferListener() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,297 +163,125 @@ public class DefaultArtifactResolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories,
|
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository, TransferListener resolutionListener )
|
||||||
ArtifactRepository localRepository, TransferListener resolutionListener )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
RepositoryRequest request = new DefaultRepositoryRequest();
|
resolve( artifact, remoteRepositories, getSession( localRepository ) );
|
||||||
injectSession1( request, legacySupport.getSession() );
|
|
||||||
request.setLocalRepository( localRepository );
|
|
||||||
request.setRemoteRepositories( remoteRepositories );
|
|
||||||
resolve( artifact, request, resolutionListener, false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolveAlways( Artifact artifact, List<ArtifactRepository> remoteRepositories,
|
public void resolveAlways( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
|
||||||
ArtifactRepository localRepository )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
RepositoryRequest request = new DefaultRepositoryRequest();
|
resolve( artifact, remoteRepositories, getSession( localRepository ) );
|
||||||
injectSession1( request, legacySupport.getSession() );
|
|
||||||
request.setLocalRepository( localRepository );
|
|
||||||
request.setRemoteRepositories( remoteRepositories );
|
|
||||||
resolve( artifact, request, null, true );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolve( Artifact artifact, RepositoryRequest request, TransferListener downloadMonitor,
|
private void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session )
|
||||||
boolean force )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
if ( artifact == null )
|
if ( artifact == null )
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File destination;
|
|
||||||
|
|
||||||
if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
|
if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
|
||||||
{
|
{
|
||||||
File systemFile = artifact.getFile();
|
File systemFile = artifact.getFile();
|
||||||
|
|
||||||
if ( systemFile == null )
|
if ( systemFile == null )
|
||||||
{
|
{
|
||||||
throw new ArtifactNotFoundException( "System artifact: " + artifact + " has no file attached",
|
throw new ArtifactNotFoundException( "System artifact: " + artifact + " has no file attached", artifact );
|
||||||
artifact );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !systemFile.exists() )
|
if ( !systemFile.exists() )
|
||||||
{
|
{
|
||||||
throw new ArtifactNotFoundException( "System artifact: " + artifact + " not found in path: "
|
throw new ArtifactNotFoundException( "System artifact: " + artifact + " not found in path: " + systemFile, artifact );
|
||||||
+ systemFile, artifact );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !systemFile.isFile() )
|
if ( !systemFile.isFile() )
|
||||||
{
|
{
|
||||||
throw new ArtifactNotFoundException( "System artifact: " + artifact + " is not a file: " + systemFile,
|
throw new ArtifactNotFoundException( "System artifact: " + artifact + " is not a file: " + systemFile, artifact );
|
||||||
artifact );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
artifact.setResolved( true );
|
artifact.setResolved( true );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArtifactRepository localRepository = request.getLocalRepository();
|
|
||||||
|
|
||||||
List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories();
|
|
||||||
|
|
||||||
if ( !artifact.isResolved() )
|
if ( !artifact.isResolved() )
|
||||||
{
|
{
|
||||||
// ----------------------------------------------------------------------
|
ArtifactResult result;
|
||||||
// Check for the existence of the artifact in the specified local
|
|
||||||
// ArtifactRepository. If it is present then simply return as the
|
|
||||||
// request for resolution has been satisfied.
|
|
||||||
// ----------------------------------------------------------------------
|
|
||||||
|
|
||||||
artifact = localRepository.find( artifact );
|
try
|
||||||
|
|
||||||
if ( artifact.isResolved() )
|
|
||||||
{
|
{
|
||||||
return;
|
ArtifactRequest artifactRequest = new ArtifactRequest();
|
||||||
|
artifactRequest.setArtifact( RepositoryUtils.toArtifact( artifact ) );
|
||||||
|
artifactRequest.setRepositories( RepositoryUtils.toRepos( remoteRepositories ) );
|
||||||
|
result = repoSystem.resolveArtifact( session, artifactRequest );
|
||||||
}
|
}
|
||||||
|
catch ( org.sonatype.aether.resolution.ArtifactResolutionException e )
|
||||||
transformationManager.transformForResolve( artifact, request );
|
|
||||||
|
|
||||||
destination = artifact.getFile();
|
|
||||||
|
|
||||||
if ( !request.isOffline() && ( force || !destination.exists() || isMutable( artifact ) ) )
|
|
||||||
{
|
{
|
||||||
try
|
if ( e.getCause() instanceof org.sonatype.aether.transfer.ArtifactNotFoundException )
|
||||||
{
|
|
||||||
if ( artifact.getRepository() != null )
|
|
||||||
{
|
|
||||||
// the transformations discovered the artifact - so use it exclusively
|
|
||||||
wagonManager.getArtifact( artifact, artifact.getRepository(), downloadMonitor,
|
|
||||||
request.isForceUpdate() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wagonManager.getArtifact( artifact, remoteRepositories, downloadMonitor,
|
|
||||||
request.isForceUpdate() );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( localRepositoryMaintainer != null )
|
|
||||||
{
|
|
||||||
LocalRepositoryMaintainerEvent event =
|
|
||||||
new DefaultLocalRepositoryMaintainerEvent( localRepository, artifact, null );
|
|
||||||
localRepositoryMaintainer.artifactDownloaded( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
catch ( ResourceDoesNotExistException e )
|
|
||||||
{
|
{
|
||||||
throw new ArtifactNotFoundException( e.getMessage(), artifact, remoteRepositories, e );
|
throw new ArtifactNotFoundException( e.getMessage(), artifact, remoteRepositories, e );
|
||||||
}
|
}
|
||||||
catch ( TransferFailedException e )
|
else
|
||||||
{
|
{
|
||||||
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( destination.exists() )
|
artifact.selectVersion( result.getArtifact().getVersion() );
|
||||||
{
|
artifact.setFile( result.getArtifact().getFile() );
|
||||||
artifact.setResolved( true );
|
artifact.setResolved( true );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( request.isOffline() )
|
|
||||||
{
|
|
||||||
throw new ArtifactResolutionException( "The repository system is offline"
|
|
||||||
+ " and the requested artifact is not locally available at " + destination, artifact,
|
|
||||||
remoteRepositories );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new ArtifactResolutionException( "Failed to resolve artifact, possibly due to a "
|
|
||||||
+ "repository list that is not appropriately equipped for this artifact's metadata.", artifact,
|
|
||||||
remoteRepositories );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1.0-SNAPSHOT
|
|
||||||
//
|
|
||||||
// 1) pom = 1.0-SNAPSHOT
|
|
||||||
// 2) pom = 1.0-yyyymmdd.hhmmss
|
|
||||||
// 3) baseVersion = 1.0-SNAPSHOT
|
|
||||||
if ( artifact.isSnapshot() && isTimestamped( artifact ) )
|
|
||||||
{
|
|
||||||
String version = artifact.getVersion();
|
|
||||||
|
|
||||||
// 1.0-SNAPSHOT
|
|
||||||
artifact.selectVersion( artifact.getBaseVersion() );
|
|
||||||
|
|
||||||
// Make a file with a 1.0-SNAPSHOT format
|
|
||||||
File copy = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
|
|
||||||
|
|
||||||
// if the timestamped version was resolved or the copy doesn't exist then copy a version
|
|
||||||
// of the file like 1.0-SNAPSHOT. Even if there is a timestamped version the non-timestamped
|
|
||||||
// version will be created.
|
|
||||||
if ( !copy.exists() || copy.lastModified() != destination.lastModified()
|
|
||||||
|| copy.length() != destination.length() )
|
|
||||||
{
|
|
||||||
// recopy file if it was reresolved, or doesn't exist.
|
|
||||||
try
|
|
||||||
{
|
|
||||||
FileUtils.copyFile( destination, copy );
|
|
||||||
|
|
||||||
copy.setLastModified( destination.lastModified() );
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
throw new ArtifactResolutionException( "Unable to copy resolved artifact for local use: "
|
|
||||||
+ e.getMessage(), artifact, remoteRepositories, e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We are only going to use the 1.0-SNAPSHOT version
|
|
||||||
artifact.setFile( copy );
|
|
||||||
|
|
||||||
// Set the version to the 1.0-yyyymmdd.hhmmss version
|
|
||||||
artifact.selectVersion( version );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMutable( Artifact artifact )
|
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
||||||
{
|
|
||||||
return artifact.isSnapshot() && !isTimestamped( artifact ) && !isLocalCopy( artifact );
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isTimestamped( Artifact artifact )
|
|
||||||
{
|
|
||||||
return !artifact.getBaseVersion().equals( artifact.getVersion() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isLocalCopy( Artifact artifact )
|
|
||||||
{
|
|
||||||
boolean localCopy = false;
|
|
||||||
|
|
||||||
for ( ArtifactMetadata m : artifact.getMetadataList() )
|
|
||||||
{
|
|
||||||
if ( m instanceof SnapshotArtifactRepositoryMetadata )
|
|
||||||
{
|
|
||||||
SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata) m;
|
|
||||||
|
|
||||||
Metadata metadata = snapshotMetadata.getMetadata();
|
|
||||||
|
|
||||||
if ( metadata != null )
|
|
||||||
{
|
|
||||||
Versioning versioning = metadata.getVersioning();
|
|
||||||
|
|
||||||
if ( versioning != null )
|
|
||||||
{
|
|
||||||
Snapshot snapshot = versioning.getSnapshot();
|
|
||||||
|
|
||||||
if ( snapshot != null )
|
|
||||||
{
|
|
||||||
// TODO is it possible to have more than one SnapshotArtifactRepositoryMetadata
|
|
||||||
localCopy = snapshot.isLocalCopy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return localCopy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
|
|
||||||
ArtifactRepository localRepository,
|
|
||||||
List<ArtifactRepository> remoteRepositories,
|
|
||||||
ArtifactMetadataSource source, ArtifactFilter filter )
|
ArtifactMetadataSource source, ArtifactFilter filter )
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository,
|
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository, remoteRepositories, source, filter );
|
||||||
remoteRepositories, source, filter );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
|
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
|
||||||
Map managedVersions, ArtifactRepository localRepository,
|
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source )
|
||||||
List<ArtifactRepository> remoteRepositories,
|
|
||||||
ArtifactMetadataSource source )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository,
|
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, null );
|
||||||
remoteRepositories, source, null );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
|
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
|
||||||
Map managedVersions, ArtifactRepository localRepository,
|
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter )
|
||||||
List<ArtifactRepository> remoteRepositories,
|
|
||||||
ArtifactMetadataSource source, ArtifactFilter filter )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository,
|
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, null );
|
||||||
remoteRepositories, source, filter, null );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
|
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository,
|
||||||
List<ArtifactRepository> remoteRepositories,
|
|
||||||
ArtifactRepository localRepository,
|
|
||||||
ArtifactMetadataSource source )
|
ArtifactMetadataSource source )
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
return resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories, source, null );
|
return resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories, source, null );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
|
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository,
|
||||||
List<ArtifactRepository> remoteRepositories,
|
ArtifactMetadataSource source, List<ResolutionListener> listeners )
|
||||||
ArtifactRepository localRepository,
|
|
||||||
ArtifactMetadataSource source,
|
|
||||||
List<ResolutionListener> listeners )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository,
|
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository,
|
||||||
remoteRepositories, source, null, listeners );
|
remoteRepositories, source, null, listeners );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
|
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
|
||||||
Map managedVersions, ArtifactRepository localRepository,
|
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners )
|
||||||
List<ArtifactRepository> remoteRepositories,
|
|
||||||
ArtifactMetadataSource source, ArtifactFilter filter,
|
|
||||||
List<ResolutionListener> listeners )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository,
|
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners, null );
|
||||||
remoteRepositories, source, filter, listeners, null );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
|
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
|
||||||
Map managedVersions, ArtifactRepository localRepository,
|
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners,
|
||||||
List<ArtifactRepository> remoteRepositories,
|
|
||||||
ArtifactMetadataSource source, ArtifactFilter filter,
|
|
||||||
List<ResolutionListener> listeners,
|
|
||||||
List<ConflictResolver> conflictResolvers )
|
List<ConflictResolver> conflictResolvers )
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
|
@ -461,7 +289,7 @@ public class DefaultArtifactResolver
|
||||||
.setArtifact( originatingArtifact )
|
.setArtifact( originatingArtifact )
|
||||||
.setResolveRoot( false )
|
.setResolveRoot( false )
|
||||||
// This is required by the surefire plugin
|
// This is required by the surefire plugin
|
||||||
.setArtifactDependencies( artifacts )
|
.setArtifactDependencies( artifacts )
|
||||||
.setManagedVersionMap( managedVersions )
|
.setManagedVersionMap( managedVersions )
|
||||||
.setLocalRepository( localRepository )
|
.setLocalRepository( localRepository )
|
||||||
.setRemoteRepositories( remoteRepositories )
|
.setRemoteRepositories( remoteRepositories )
|
||||||
|
@ -497,10 +325,10 @@ public class DefaultArtifactResolver
|
||||||
Set<Artifact> artifacts = request.getArtifactDependencies();
|
Set<Artifact> artifacts = request.getArtifactDependencies();
|
||||||
Map managedVersions = request.getManagedVersionMap();
|
Map managedVersions = request.getManagedVersionMap();
|
||||||
List<ResolutionListener> listeners = request.getListeners();
|
List<ResolutionListener> listeners = request.getListeners();
|
||||||
ArtifactFilter collectionFilter = request.getCollectionFilter();
|
ArtifactFilter collectionFilter = request.getCollectionFilter();
|
||||||
ArtifactFilter resolutionFilter = request.getResolutionFilter();
|
ArtifactFilter resolutionFilter = request.getResolutionFilter();
|
||||||
TransferListener transferListener = TransferListenerAdapter.newAdapter( request.getTransferListener() );
|
RepositorySystemSession session = getSession( request.getLocalRepository() );
|
||||||
|
|
||||||
//TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the workspace
|
//TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the workspace
|
||||||
if ( source == null )
|
if ( source == null )
|
||||||
{
|
{
|
||||||
|
@ -532,12 +360,12 @@ public class DefaultArtifactResolver
|
||||||
// This is often an artifact like a POM that is taken from disk and we already have hold of the
|
// This is often an artifact like a POM that is taken from disk and we already have hold of the
|
||||||
// file reference. But this may be a Maven Plugin that we need to resolve from a remote repository
|
// file reference. But this may be a Maven Plugin that we need to resolve from a remote repository
|
||||||
// as well as its dependencies.
|
// as well as its dependencies.
|
||||||
|
|
||||||
if ( request.isResolveRoot() /* && rootArtifact.getFile() == null */ )
|
if ( request.isResolveRoot() /* && rootArtifact.getFile() == null */ )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resolve( rootArtifact, request, transferListener, false );
|
resolve( rootArtifact, request.getRemoteRepositories(), session );
|
||||||
}
|
}
|
||||||
catch ( ArtifactResolutionException e )
|
catch ( ArtifactResolutionException e )
|
||||||
{
|
{
|
||||||
|
@ -609,7 +437,7 @@ public class DefaultArtifactResolver
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( artifacts == null || artifacts.isEmpty() )
|
if ( artifacts == null || artifacts.isEmpty() )
|
||||||
{
|
{
|
||||||
if ( request.isResolveRoot() )
|
if ( request.isResolveRoot() )
|
||||||
|
@ -617,19 +445,18 @@ public class DefaultArtifactResolver
|
||||||
result.addArtifact( rootArtifact );
|
result.addArtifact( rootArtifact );
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// After the collection we will have the artifact object in the result but they will not be resolved yet.
|
// After the collection we will have the artifact object in the result but they will not be resolved yet.
|
||||||
result =
|
result =
|
||||||
artifactCollector.collect( artifacts, rootArtifact, managedVersions, collectionRequest, source,
|
artifactCollector.collect( artifacts, rootArtifact, managedVersions, collectionRequest, source,
|
||||||
collectionFilter, listeners, null );
|
collectionFilter, listeners, null );
|
||||||
|
|
||||||
// We have metadata retrieval problems, or there are cycles that have been detected
|
// We have metadata retrieval problems, or there are cycles that have been detected
|
||||||
// so we give this back to the calling code and let them deal with this information
|
// so we give this back to the calling code and let them deal with this information
|
||||||
// appropriately.
|
// appropriately.
|
||||||
|
|
||||||
if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations()
|
if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions() )
|
||||||
|| result.hasCircularDependencyExceptions() )
|
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -646,11 +473,8 @@ public class DefaultArtifactResolver
|
||||||
|
|
||||||
if ( resolutionFilter == null || resolutionFilter.include( artifact ) )
|
if ( resolutionFilter == null || resolutionFilter.include( artifact ) )
|
||||||
{
|
{
|
||||||
ArtifactResolutionRequest childRequest = new ArtifactResolutionRequest( request );
|
executor.execute( new ResolveTask( classLoader, latch, artifact, session,
|
||||||
childRequest.setRemoteRepositories( node.getRemoteRepositories() );
|
node.getRemoteRepositories(), result ) );
|
||||||
|
|
||||||
executor.execute( new ResolveTask( classLoader, latch, artifact, transferListener, childRequest,
|
|
||||||
result ) );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -671,19 +495,18 @@ public class DefaultArtifactResolver
|
||||||
// We want to send the root artifact back in the result but we need to do this after the other dependencies
|
// We want to send the root artifact back in the result but we need to do this after the other dependencies
|
||||||
// have been resolved.
|
// have been resolved.
|
||||||
if ( request.isResolveRoot() )
|
if ( request.isResolveRoot() )
|
||||||
{
|
{
|
||||||
// Add the root artifact (as the first artifact to retain logical order of class path!)
|
// Add the root artifact (as the first artifact to retain logical order of class path!)
|
||||||
Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();
|
Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();
|
||||||
allArtifacts.add( rootArtifact );
|
allArtifacts.add( rootArtifact );
|
||||||
allArtifacts.addAll( result.getArtifacts() );
|
allArtifacts.addAll( result.getArtifacts() );
|
||||||
result.setArtifacts( allArtifacts );
|
result.setArtifacts( allArtifacts );
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories,
|
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
|
||||||
ArtifactRepository localRepository )
|
|
||||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||||
{
|
{
|
||||||
resolve( artifact, remoteRepositories, localRepository, null );
|
resolve( artifact, remoteRepositories, localRepository, null );
|
||||||
|
@ -719,21 +542,20 @@ public class DefaultArtifactResolver
|
||||||
|
|
||||||
private final Artifact artifact;
|
private final Artifact artifact;
|
||||||
|
|
||||||
private final TransferListener transferListener;
|
private final RepositorySystemSession session;
|
||||||
|
|
||||||
private final ArtifactResolutionRequest request;
|
private final List<ArtifactRepository> remoteRepositories;
|
||||||
|
|
||||||
private final ArtifactResolutionResult result;
|
private final ArtifactResolutionResult result;
|
||||||
|
|
||||||
public ResolveTask( ClassLoader classLoader, CountDownLatch latch, Artifact artifact,
|
public ResolveTask( ClassLoader classLoader, CountDownLatch latch, Artifact artifact, RepositorySystemSession session,
|
||||||
TransferListener transferListener, ArtifactResolutionRequest request,
|
List<ArtifactRepository> remoteRepositories, ArtifactResolutionResult result )
|
||||||
ArtifactResolutionResult result )
|
|
||||||
{
|
{
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
this.latch = latch;
|
this.latch = latch;
|
||||||
this.artifact = artifact;
|
this.artifact = artifact;
|
||||||
this.transferListener = transferListener;
|
this.session = session;
|
||||||
this.request = request;
|
this.remoteRepositories = remoteRepositories;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -742,7 +564,7 @@ public class DefaultArtifactResolver
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Thread.currentThread().setContextClassLoader( classLoader );
|
Thread.currentThread().setContextClassLoader( classLoader );
|
||||||
resolve( artifact, request, transferListener, false );
|
resolve( artifact, remoteRepositories, session );
|
||||||
}
|
}
|
||||||
catch ( ArtifactNotFoundException anfe )
|
catch ( ArtifactNotFoundException anfe )
|
||||||
{
|
{
|
||||||
|
|
|
@ -94,6 +94,7 @@ public class DefaultMavenProjectBuilder
|
||||||
MavenSession session = legacySupport.getSession();
|
MavenSession session = legacySupport.getSession();
|
||||||
if ( session != null )
|
if ( session != null )
|
||||||
{
|
{
|
||||||
|
request.setRepositorySession( session.getRepositorySession() );
|
||||||
request.setOffline( session.isOffline() );
|
request.setOffline( session.isOffline() );
|
||||||
request.setSystemProperties( session.getSystemProperties() );
|
request.setSystemProperties( session.getSystemProperties() );
|
||||||
if ( request.getUserProperties().isEmpty() )
|
if ( request.getUserProperties().isEmpty() )
|
||||||
|
@ -108,7 +109,6 @@ public class DefaultMavenProjectBuilder
|
||||||
request.setMirrors( req.getMirrors() );
|
request.setMirrors( req.getMirrors() );
|
||||||
request.setProxies( req.getProxies() );
|
request.setProxies( req.getProxies() );
|
||||||
request.setRemoteRepositories( req.getRemoteRepositories() );
|
request.setRemoteRepositories( req.getRemoteRepositories() );
|
||||||
request.setTransferListener( req.getTransferListener() );
|
|
||||||
request.setForceUpdate( req.isUpdateSnapshots() );
|
request.setForceUpdate( req.isUpdateSnapshots() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,6 @@ public class DefaultLegacyArtifactCollector
|
||||||
request.setServers( session.getRequest().getServers() );
|
request.setServers( session.getRequest().getServers() );
|
||||||
request.setMirrors( session.getRequest().getMirrors() );
|
request.setMirrors( session.getRequest().getMirrors() );
|
||||||
request.setProxies( session.getRequest().getProxies() );
|
request.setProxies( session.getRequest().getProxies() );
|
||||||
request.setTransferListener( session.getRequest().getTransferListener() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,33 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
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.plugin.LegacySupport;
|
||||||
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
|
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||||
|
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||||
|
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.collection.DependencyGraphTransformer;
|
||||||
|
import org.sonatype.aether.collection.DependencyManager;
|
||||||
|
import org.sonatype.aether.collection.DependencySelector;
|
||||||
|
import org.sonatype.aether.collection.DependencyTraverser;
|
||||||
|
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
|
||||||
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.graph.manager.ClassicDependencyManager;
|
||||||
|
import org.sonatype.aether.util.graph.selector.AndDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.ExclusionDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.OptionalDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.ScopeDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.NearestVersionConflictResolver;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.ConflictMarker;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator;
|
||||||
|
import org.sonatype.aether.util.graph.traverser.FatArtifactTraverser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||||
|
@ -53,6 +75,14 @@ public abstract class AbstractArtifactComponentTestCase
|
||||||
super.setUp();
|
super.setUp();
|
||||||
artifactFactory = lookup( ArtifactFactory.class);
|
artifactFactory = lookup( ArtifactFactory.class);
|
||||||
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
|
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
|
||||||
|
|
||||||
|
RepositorySystemSession repoSession = initRepoSession();
|
||||||
|
MavenSession session =
|
||||||
|
new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(),
|
||||||
|
new DefaultMavenExecutionResult() );
|
||||||
|
|
||||||
|
LegacySupport legacySupport = lookup(LegacySupport.class);
|
||||||
|
legacySupport.setSession( session );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -297,4 +327,33 @@ public abstract class AbstractArtifactComponentTestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected RepositorySystemSession initRepoSession()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
|
||||||
|
session.setIgnoreMissingArtifactDescriptor( true );
|
||||||
|
session.setIgnoreInvalidArtifactDescriptor( true );
|
||||||
|
DependencyTraverser depTraverser = new FatArtifactTraverser();
|
||||||
|
session.setDependencyTraverser( depTraverser );
|
||||||
|
|
||||||
|
DependencyManager depManager = new ClassicDependencyManager();
|
||||||
|
session.setDependencyManager( depManager );
|
||||||
|
|
||||||
|
DependencySelector depFilter =
|
||||||
|
new AndDependencySelector( new ScopeDependencySelector( "test", "provided" ),
|
||||||
|
new OptionalDependencySelector(), new ExclusionDependencySelector() );
|
||||||
|
session.setDependencySelector( depFilter );
|
||||||
|
|
||||||
|
DependencyGraphTransformer transformer =
|
||||||
|
new ChainedDependencyGraphTransformer( new ConflictMarker(), new JavaEffectiveScopeCalculator(),
|
||||||
|
new NearestVersionConflictResolver(),
|
||||||
|
new JavaDependencyContextRefiner() );
|
||||||
|
session.setDependencyGraphTransformer( transformer );
|
||||||
|
|
||||||
|
session.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepository().getBasedir() ) );
|
||||||
|
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||||
import org.apache.maven.model.building.ModelBuildingException;
|
import org.apache.maven.model.building.ModelBuildingException;
|
||||||
import org.apache.maven.model.building.ModelProblem;
|
import org.apache.maven.model.building.ModelProblem;
|
||||||
import org.apache.maven.repository.RepositorySystem;
|
import org.apache.maven.repository.RepositorySystem;
|
||||||
|
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,6 +130,7 @@ public abstract class AbstractMavenProjectTestCase
|
||||||
configuration.setRemoteRepositories( Arrays.asList( new ArtifactRepository[] {} ) );
|
configuration.setRemoteRepositories( Arrays.asList( new ArtifactRepository[] {} ) );
|
||||||
configuration.setProcessPlugins( false );
|
configuration.setProcessPlugins( false );
|
||||||
configuration.setResolveDependencies( true );
|
configuration.setResolveDependencies( true );
|
||||||
|
initRepoSession( configuration );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -157,8 +159,17 @@ public abstract class AbstractMavenProjectTestCase
|
||||||
{
|
{
|
||||||
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
|
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
|
||||||
configuration.setLocalRepository( getLocalRepository() );
|
configuration.setLocalRepository( getLocalRepository() );
|
||||||
|
initRepoSession( configuration );
|
||||||
|
|
||||||
return projectBuilder.build( pom, configuration ).getProject();
|
return projectBuilder.build( pom, configuration ).getProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void initRepoSession( ProjectBuildingRequest request )
|
||||||
|
{
|
||||||
|
File localRepo = new File( request.getLocalRepository().getBasedir() );
|
||||||
|
MavenRepositorySystemSession session = new MavenRepositorySystemSession();
|
||||||
|
session.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) );
|
||||||
|
request.setRepositorySession( session );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
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 java.io.FileNotFoundException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.impl.ArtifactResolver;
|
||||||
|
import org.sonatype.aether.impl.internal.DefaultArtifactResolver;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactRequest;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactResolutionException;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactResult;
|
||||||
|
import org.sonatype.aether.transfer.ArtifactNotFoundException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
@Component( role = ArtifactResolver.class, hint = "classpath" )
|
||||||
|
public class ClasspathArtifactResolver
|
||||||
|
extends DefaultArtifactResolver
|
||||||
|
{
|
||||||
|
|
||||||
|
public List<ArtifactResult> resolveArtifacts( RepositorySystemSession session,
|
||||||
|
Collection<? extends ArtifactRequest> requests )
|
||||||
|
throws ArtifactResolutionException
|
||||||
|
{
|
||||||
|
List<ArtifactResult> results = new ArrayList<ArtifactResult>();
|
||||||
|
|
||||||
|
for ( ArtifactRequest request : requests )
|
||||||
|
{
|
||||||
|
ArtifactResult result = new ArtifactResult( request );
|
||||||
|
results.add( result );
|
||||||
|
|
||||||
|
Artifact artifact = request.getArtifact();
|
||||||
|
if ( "maven-test".equals( artifact.getGroupId() ) )
|
||||||
|
{
|
||||||
|
String scope = artifact.getArtifactId().substring( "scope-".length() );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
artifact = artifact.setFile( ProjectClasspathTest.getFileForClasspathResource( ProjectClasspathTest.dir
|
||||||
|
+ "transitive-" + scope + "-dep.xml" ) );
|
||||||
|
result.setArtifact( artifact );
|
||||||
|
}
|
||||||
|
catch ( FileNotFoundException e )
|
||||||
|
{
|
||||||
|
throw new IllegalStateException( "Missing test POM for " + artifact );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.addException( new ArtifactNotFoundException( artifact, null ) );
|
||||||
|
throw new ArtifactResolutionException( results );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,17 +26,9 @@ import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.lifecycle.*;
|
import org.apache.maven.lifecycle.*;
|
||||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.model.PluginExecution;
|
import org.apache.maven.model.PluginExecution;
|
||||||
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
|
||||||
import org.apache.maven.plugin.MojoExecution;
|
import org.apache.maven.plugin.MojoExecution;
|
||||||
import org.apache.maven.plugin.MojoNotFoundException;
|
|
||||||
import org.apache.maven.plugin.PluginDescriptorParsingException;
|
|
||||||
import org.apache.maven.plugin.PluginNotFoundException;
|
|
||||||
import org.apache.maven.plugin.PluginResolutionException;
|
|
||||||
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
|
|
||||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A stub implementation that assumes an empty lifecycle to bypass interaction with the plugin manager and to avoid
|
* A stub implementation that assumes an empty lifecycle to bypass interaction with the plugin manager and to avoid
|
||||||
|
@ -49,8 +41,6 @@ public class EmptyLifecycleExecutor
|
||||||
{
|
{
|
||||||
|
|
||||||
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
|
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
|
||||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
|
||||||
MojoNotFoundException
|
|
||||||
{
|
{
|
||||||
return new MavenExecutionPlan(null, null, null, new DefaultLifecycles() );
|
return new MavenExecutionPlan(null, null, null, new DefaultLifecycles() );
|
||||||
}
|
}
|
||||||
|
@ -102,14 +92,10 @@ public class EmptyLifecycleExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
|
public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
|
||||||
throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
|
|
||||||
PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
|
|
||||||
LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
|
public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
|
||||||
throws LifecycleExecutionException
|
|
||||||
{
|
{
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
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 java.util.Collections;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
|
||||||
|
import org.apache.maven.model.Plugin;
|
||||||
|
import org.apache.maven.model.PluginExecution;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public class EmptyLifecyclePluginAnalyzer
|
||||||
|
implements LifeCyclePluginAnalyzer
|
||||||
|
{
|
||||||
|
public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
|
||||||
|
{
|
||||||
|
Set<Plugin> plugins;
|
||||||
|
|
||||||
|
// NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests
|
||||||
|
if ( "JAR".equals( packaging ) )
|
||||||
|
{
|
||||||
|
plugins = new LinkedHashSet<Plugin>();
|
||||||
|
|
||||||
|
plugins.add( newPlugin( "maven-compiler-plugin", "compile", "testCompile" ) );
|
||||||
|
plugins.add( newPlugin( "maven-resources-plugin", "resources", "testResources" ) );
|
||||||
|
plugins.add( newPlugin( "maven-surefire-plugin", "test" ) );
|
||||||
|
plugins.add( newPlugin( "maven-jar-plugin", "jar" ) );
|
||||||
|
plugins.add( newPlugin( "maven-install-plugin", "install" ) );
|
||||||
|
plugins.add( newPlugin( "maven-deploy-plugin", "deploy" ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugins = Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Plugin newPlugin( String artifactId, String... goals )
|
||||||
|
{
|
||||||
|
Plugin plugin = new Plugin();
|
||||||
|
|
||||||
|
plugin.setGroupId( "org.apache.maven.plugins" );
|
||||||
|
plugin.setArtifactId( artifactId );
|
||||||
|
|
||||||
|
for ( String goal : goals )
|
||||||
|
{
|
||||||
|
PluginExecution pluginExecution = new PluginExecution();
|
||||||
|
pluginExecution.setId( "default-" + goal );
|
||||||
|
pluginExecution.addGoal( goal );
|
||||||
|
plugin.addExecution( pluginExecution );
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
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 java.io.File;
|
||||||
|
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
public class LegacyLocalRepositoryManager
|
||||||
|
extends SimpleLocalRepositoryManager
|
||||||
|
{
|
||||||
|
|
||||||
|
public LegacyLocalRepositoryManager( File basedir )
|
||||||
|
{
|
||||||
|
super( basedir );
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPathForLocalArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
StringBuilder path = new StringBuilder( 128 );
|
||||||
|
|
||||||
|
path.append( artifact.getGroupId() ).append( '/' );
|
||||||
|
|
||||||
|
path.append( artifact.getExtension() ).append( 's' ).append( '/' );
|
||||||
|
|
||||||
|
path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );
|
||||||
|
|
||||||
|
if ( artifact.getClassifier().length() > 0 )
|
||||||
|
{
|
||||||
|
path.append( '-' ).append( artifact.getClassifier() );
|
||||||
|
}
|
||||||
|
|
||||||
|
path.append( '.' ).append( artifact.getExtension() );
|
||||||
|
|
||||||
|
return path.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,6 +24,9 @@ import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.repository.RepositorySystem;
|
import org.apache.maven.repository.RepositorySystem;
|
||||||
|
import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader;
|
||||||
|
import org.sonatype.aether.impl.ArtifactDescriptorReader;
|
||||||
|
import org.sonatype.aether.impl.ArtifactResolver;
|
||||||
|
|
||||||
public class ProjectClasspathTest
|
public class ProjectClasspathTest
|
||||||
extends AbstractMavenProjectTestCase
|
extends AbstractMavenProjectTestCase
|
||||||
|
@ -33,11 +36,15 @@ public class ProjectClasspathTest
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" );
|
||||||
|
DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class);
|
||||||
|
pomReader.setArtifactResolver( resolver );
|
||||||
|
|
||||||
projectBuilder = lookup( ProjectBuilder.class, "classpath" );
|
projectBuilder = lookup( ProjectBuilder.class, "classpath" );
|
||||||
|
|
||||||
// the metadata source looks up the default impl, so we have to trick it
|
// the metadata source looks up the default impl, so we have to trick it
|
||||||
getContainer().addComponent( projectBuilder, ProjectBuilder.class, "default" );
|
getContainer().addComponent( projectBuilder, ProjectBuilder.class, "default" );
|
||||||
|
|
||||||
repositorySystem = lookup( RepositorySystem.class );
|
repositorySystem = lookup( RepositorySystem.class );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,17 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
||||||
|
import org.apache.maven.execution.DefaultMavenExecutionRequest;
|
||||||
|
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.model.Repository;
|
import org.apache.maven.model.Repository;
|
||||||
import org.apache.maven.model.RepositoryPolicy;
|
import org.apache.maven.model.RepositoryPolicy;
|
||||||
|
import org.apache.maven.plugin.LegacySupport;
|
||||||
import org.apache.maven.repository.RepositorySystem;
|
import org.apache.maven.repository.RepositorySystem;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link LegacyRepositorySystem}.
|
* Tests {@link LegacyRepositorySystem}.
|
||||||
|
@ -107,6 +113,12 @@ public class LegacyRepositorySystemTest
|
||||||
.setRemoteRepositories( getRemoteRepositories() )
|
.setRemoteRepositories( getRemoteRepositories() )
|
||||||
.setLocalRepository( getLocalRepository() );
|
.setLocalRepository( getLocalRepository() );
|
||||||
|
|
||||||
|
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
|
||||||
|
session.setLocalRepositoryManager( new SimpleLocalRepositoryManager( request.getLocalRepository().getBasedir() ) );
|
||||||
|
LegacySupport legacySupport = lookup( LegacySupport.class );
|
||||||
|
legacySupport.setSession( new MavenSession( getContainer(), session, new DefaultMavenExecutionRequest(),
|
||||||
|
new DefaultMavenExecutionResult() ) );
|
||||||
|
|
||||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||||
resolutionErrorHandler.throwErrors( request, result );
|
resolutionErrorHandler.throwErrors( request, result );
|
||||||
assertEquals( 2, result.getArtifacts().size() );
|
assertEquals( 2, result.getArtifacts().size() );
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
package org.apache.maven.repository.ideworkspace;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
|
||||||
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
|
|
||||||
import org.apache.maven.repository.RepositorySystem;
|
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
|
||||||
|
|
||||||
public class IdeWorkspaceRepositoryTest
|
|
||||||
extends PlexusTestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
private RepositorySystem repositorySystem;
|
|
||||||
private ArtifactRepository localRepository;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
repositorySystem = lookup( RepositorySystem.class );
|
|
||||||
localRepository = repositorySystem.createLocalRepository( new File( "target/IdeWorkspaceRepositoryTest" ).getCanonicalFile() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void tearDown()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
repositorySystem = null;
|
|
||||||
localRepository = null;
|
|
||||||
|
|
||||||
super.tearDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testResolveFromWorkspace()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
Artifact artifact =
|
|
||||||
repositorySystem.createArtifact( TestIdeWorkspaceRepository.GROUP_ID, TestIdeWorkspaceRepository.ARTIFACT_ID,
|
|
||||||
TestIdeWorkspaceRepository.VERSION, "jar" );
|
|
||||||
|
|
||||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
|
|
||||||
request.setArtifact( artifact );
|
|
||||||
request.setLocalRepository( localRepository );
|
|
||||||
request.setRemoteRepositories( new ArrayList<ArtifactRepository>() );
|
|
||||||
|
|
||||||
repositorySystem.resolve( request );
|
|
||||||
|
|
||||||
assertTrue( artifact.isResolved() );
|
|
||||||
assertEquals( TestIdeWorkspaceRepository.ARTIFACT_FILE, artifact.getFile() );
|
|
||||||
assertSame( localRepository, request.getLocalRepository() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDelegatingLocalRepo()
|
|
||||||
throws Exception
|
|
||||||
{
|
|
||||||
Artifact artifact =
|
|
||||||
repositorySystem.createArtifact( TestIdeWorkspaceRepository.GROUP_ID, TestIdeWorkspaceRepository.ARTIFACT_ID,
|
|
||||||
TestIdeWorkspaceRepository.VERSION, "jar" );
|
|
||||||
|
|
||||||
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository = new DelegatingLocalArtifactRepository( localRepository );
|
|
||||||
|
|
||||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
|
|
||||||
request.setArtifact( artifact );
|
|
||||||
request.setLocalRepository( delegatingLocalArtifactRepository );
|
|
||||||
request.setRemoteRepositories( new ArrayList<ArtifactRepository>() );
|
|
||||||
|
|
||||||
repositorySystem.resolve( request );
|
|
||||||
|
|
||||||
assertTrue( artifact.isResolved() );
|
|
||||||
assertEquals( TestIdeWorkspaceRepository.ARTIFACT_FILE, artifact.getFile() );
|
|
||||||
|
|
||||||
// make sure we restore original repository
|
|
||||||
assertSame( delegatingLocalArtifactRepository, request.getLocalRepository() );
|
|
||||||
assertNull( delegatingLocalArtifactRepository.getIdeWorspace() );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
package org.apache.maven.repository.ideworkspace;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.repository.LocalArtifactRepository;
|
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
|
||||||
|
|
||||||
@Component( role = LocalArtifactRepository.class, hint = LocalArtifactRepository.IDE_WORKSPACE )
|
|
||||||
public class TestIdeWorkspaceRepository
|
|
||||||
extends LocalArtifactRepository
|
|
||||||
{
|
|
||||||
|
|
||||||
public static final String GROUP_ID = "test";
|
|
||||||
|
|
||||||
public static final String ARTIFACT_ID = "test";
|
|
||||||
|
|
||||||
public static final String VERSION = "1.0.0-SNAPSHOT";
|
|
||||||
|
|
||||||
public static final File ARTIFACT_FILE = new File( "/a/b/c/d" );
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Artifact find( Artifact artifact )
|
|
||||||
{
|
|
||||||
if ( GROUP_ID.equals( artifact.getGroupId() ) && ARTIFACT_ID.equals( artifact.getArtifactId() )
|
|
||||||
&& VERSION.equals( artifact.getVersion() ) )
|
|
||||||
{
|
|
||||||
artifact.setFile( ARTIFACT_FILE );
|
|
||||||
artifact.setResolved( true );
|
|
||||||
}
|
|
||||||
return artifact;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasLocalMetadata()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -30,16 +30,6 @@ under the License.
|
||||||
<role-hint>default</role-hint>
|
<role-hint>default</role-hint>
|
||||||
<field-name>logger</field-name>
|
<field-name>logger</field-name>
|
||||||
</requirement>
|
</requirement>
|
||||||
<requirement>
|
|
||||||
<role>org.apache.maven.repository.legacy.WagonManager</role>
|
|
||||||
<role-hint>default</role-hint>
|
|
||||||
<field-name>wagonManager</field-name>
|
|
||||||
</requirement>
|
|
||||||
<requirement>
|
|
||||||
<role>org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager</role>
|
|
||||||
<role-hint>default</role-hint>
|
|
||||||
<field-name>transformationManager</field-name>
|
|
||||||
</requirement>
|
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||||
<role-hint>default</role-hint>
|
<role-hint>default</role-hint>
|
||||||
|
@ -65,17 +55,16 @@ under the License.
|
||||||
<role-hint>default</role-hint>
|
<role-hint>default</role-hint>
|
||||||
<field-name>container</field-name>
|
<field-name>container</field-name>
|
||||||
</requirement>
|
</requirement>
|
||||||
<requirement>
|
|
||||||
<role>org.apache.maven.repository.LocalRepositoryMaintainer</role>
|
|
||||||
<role-hint>default</role-hint>
|
|
||||||
<field-name>localRepositoryMaintainer</field-name>
|
|
||||||
<optional>true</optional>
|
|
||||||
</requirement>
|
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.plugin.LegacySupport</role>
|
<role>org.apache.maven.plugin.LegacySupport</role>
|
||||||
<role-hint>default</role-hint>
|
<role-hint>default</role-hint>
|
||||||
<field-name>legacySupport</field-name>
|
<field-name>legacySupport</field-name>
|
||||||
</requirement>
|
</requirement>
|
||||||
|
<requirement>
|
||||||
|
<role>org.sonatype.aether.RepositorySystem</role>
|
||||||
|
<role-hint>default</role-hint>
|
||||||
|
<field-name>repoSystem</field-name>
|
||||||
|
</requirement>
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
</components>
|
</components>
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
<plexus>
|
<plexus>
|
||||||
<components>
|
<components>
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
|
<role>org.apache.maven.lifecycle.LifeCyclePluginAnalyzer</role>
|
||||||
<implementation>org.apache.maven.project.EmptyLifecycleExecutor</implementation>
|
<implementation>org.apache.maven.project.EmptyLifecyclePluginAnalyzer</implementation>
|
||||||
</component>
|
</component>
|
||||||
</components>
|
</components>
|
||||||
</plexus>
|
</plexus>
|
||||||
|
|
|
@ -53,6 +53,15 @@
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-model-builder</artifactId>
|
<artifactId>maven-model-builder</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-aether-provider</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.sonatype.aether</groupId>
|
||||||
|
<artifactId>aether-impl</artifactId>
|
||||||
|
<version>${aetherVersion}</version>
|
||||||
|
</dependency>
|
||||||
<!-- Plexus -->
|
<!-- Plexus -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.sonatype.spice</groupId>
|
<groupId>org.sonatype.spice</groupId>
|
||||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.maven;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
|
|
||||||
public interface ArtifactFilterManager
|
public interface ArtifactFilterManager
|
||||||
|
@ -39,4 +41,7 @@ public interface ArtifactFilterManager
|
||||||
* @param artifactId
|
* @param artifactId
|
||||||
*/
|
*/
|
||||||
void excludeArtifact( String artifactId );
|
void excludeArtifact( String artifactId );
|
||||||
}
|
|
||||||
|
Set<String> getCoreArtifactExcludes();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ public class DefaultArtifactFilterManager
|
||||||
artifacts.add( "plexus:plexus-container-default" );
|
artifacts.add( "plexus:plexus-container-default" );
|
||||||
artifacts.add( "org.sonatype.spice:spice-inject-plexus" );
|
artifacts.add( "org.sonatype.spice:spice-inject-plexus" );
|
||||||
artifacts.add( "org.apache.maven:maven-artifact" );
|
artifacts.add( "org.apache.maven:maven-artifact" );
|
||||||
|
artifacts.add( "org.apache.maven:maven-aether-provider" );
|
||||||
artifacts.add( "org.apache.maven:maven-artifact-manager" );
|
artifacts.add( "org.apache.maven:maven-artifact-manager" );
|
||||||
artifacts.add( "org.apache.maven:maven-compat" );
|
artifacts.add( "org.apache.maven:maven-compat" );
|
||||||
artifacts.add( "org.apache.maven:maven-core" );
|
artifacts.add( "org.apache.maven:maven-core" );
|
||||||
|
@ -78,6 +79,8 @@ public class DefaultArtifactFilterManager
|
||||||
artifacts.add( "org.apache.maven:maven-settings-builder" );
|
artifacts.add( "org.apache.maven:maven-settings-builder" );
|
||||||
artifacts.add( "org.apache.maven:maven-toolchain" );
|
artifacts.add( "org.apache.maven:maven-toolchain" );
|
||||||
artifacts.add( "org.apache.maven.wagon:wagon-provider-api" );
|
artifacts.add( "org.apache.maven.wagon:wagon-provider-api" );
|
||||||
|
artifacts.add( "org.sonatype.aether:aether-api" );
|
||||||
|
artifacts.add( "org.sonatype.aether:aether-spi" );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: Don't exclude the wagons or any of their dependencies (apart from the wagon API). This would otherwise
|
* NOTE: Don't exclude the wagons or any of their dependencies (apart from the wagon API). This would otherwise
|
||||||
|
@ -120,18 +123,11 @@ public class DefaultArtifactFilterManager
|
||||||
/**
|
/**
|
||||||
* Returns the artifact filter for the standard core artifacts.
|
* Returns the artifact filter for the standard core artifacts.
|
||||||
*
|
*
|
||||||
* @see org.apache.maven.ArtifactFilterManager#getExtensionArtifactFilter()
|
* @see org.apache.maven.ArtifactFilterManager#getExtensionDependencyFilter()
|
||||||
*/
|
*/
|
||||||
public ArtifactFilter getCoreArtifactFilter()
|
public ArtifactFilter getCoreArtifactFilter()
|
||||||
{
|
{
|
||||||
Set<String> excludes = new LinkedHashSet<String>( DEFAULT_EXCLUSIONS );
|
return new ExclusionSetFilter( getCoreArtifactExcludes() );
|
||||||
|
|
||||||
for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
|
|
||||||
{
|
|
||||||
delegate.addCoreExcludes( excludes );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ExclusionSetFilter( excludes );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ArtifactFilterManagerDelegate> getDelegates()
|
private List<ArtifactFilterManagerDelegate> getDelegates()
|
||||||
|
@ -154,4 +150,16 @@ public class DefaultArtifactFilterManager
|
||||||
excludedArtifacts.add( artifactId );
|
excludedArtifacts.add( artifactId );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getCoreArtifactExcludes()
|
||||||
|
{
|
||||||
|
Set<String> excludes = new LinkedHashSet<String>( DEFAULT_EXCLUSIONS );
|
||||||
|
|
||||||
|
for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
|
||||||
|
{
|
||||||
|
delegate.addCoreExcludes( excludes );
|
||||||
|
}
|
||||||
|
|
||||||
|
return excludes;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
package org.apache.maven;
|
package org.apache.maven;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* agreements. See the NOTICE file distributed with this work for additional information regarding
|
||||||
* distributed with this work for additional information
|
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* "License"); you may not use this file except in compliance with the License. You may obtain a
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* copy of the License at
|
||||||
* "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
|
||||||
*
|
*
|
||||||
* 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
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* software distributed under the License is distributed on an
|
* the License.
|
||||||
* "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.io.File;
|
import java.io.File;
|
||||||
|
@ -33,6 +29,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
|
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||||
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
import org.apache.maven.execution.DefaultMavenExecutionResult;
|
||||||
import org.apache.maven.execution.ExecutionEvent;
|
import org.apache.maven.execution.ExecutionEvent;
|
||||||
import org.apache.maven.execution.MavenExecutionRequest;
|
import org.apache.maven.execution.MavenExecutionRequest;
|
||||||
|
@ -47,6 +44,7 @@ import org.apache.maven.model.building.ModelProblem;
|
||||||
import org.apache.maven.model.building.ModelProblemUtils;
|
import org.apache.maven.model.building.ModelProblemUtils;
|
||||||
import org.apache.maven.model.building.ModelSource;
|
import org.apache.maven.model.building.ModelSource;
|
||||||
import org.apache.maven.model.building.UrlModelSource;
|
import org.apache.maven.model.building.UrlModelSource;
|
||||||
|
import org.apache.maven.plugin.LegacySupport;
|
||||||
import org.apache.maven.project.DuplicateProjectException;
|
import org.apache.maven.project.DuplicateProjectException;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.ProjectBuilder;
|
import org.apache.maven.project.ProjectBuilder;
|
||||||
|
@ -56,6 +54,13 @@ import org.apache.maven.project.ProjectBuildingResult;
|
||||||
import org.apache.maven.project.ProjectSorter;
|
import org.apache.maven.project.ProjectSorter;
|
||||||
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
|
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
|
||||||
import org.apache.maven.repository.LocalRepositoryNotAccessibleException;
|
import org.apache.maven.repository.LocalRepositoryNotAccessibleException;
|
||||||
|
import org.apache.maven.settings.Mirror;
|
||||||
|
import org.apache.maven.settings.Proxy;
|
||||||
|
import org.apache.maven.settings.Server;
|
||||||
|
import org.apache.maven.settings.building.SettingsProblem;
|
||||||
|
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
|
||||||
|
import org.apache.maven.settings.crypto.SettingsDecrypter;
|
||||||
|
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
|
||||||
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;
|
||||||
|
@ -63,11 +68,39 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||||
|
import org.sonatype.aether.RepositoryEvent;
|
||||||
|
import org.sonatype.aether.RepositorySystem;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.collection.DependencyGraphTransformer;
|
||||||
|
import org.sonatype.aether.collection.DependencyManager;
|
||||||
|
import org.sonatype.aether.collection.DependencySelector;
|
||||||
|
import org.sonatype.aether.collection.DependencyTraverser;
|
||||||
|
import org.sonatype.aether.repository.Authentication;
|
||||||
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.repository.RepositoryPolicy;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceReader;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.graph.manager.ClassicDependencyManager;
|
||||||
|
import org.sonatype.aether.util.graph.selector.AndDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.ExclusionDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.OptionalDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.selector.ScopeDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.NearestVersionConflictResolver;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.ConflictMarker;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator;
|
||||||
|
import org.sonatype.aether.util.graph.traverser.FatArtifactTraverser;
|
||||||
|
import org.sonatype.aether.util.listener.AbstractRepositoryListener;
|
||||||
|
import org.sonatype.aether.util.repository.ChainedWorkspaceReader;
|
||||||
|
import org.sonatype.aether.util.repository.DefaultAuthenticationSelector;
|
||||||
|
import org.sonatype.aether.util.repository.DefaultMirrorSelector;
|
||||||
|
import org.sonatype.aether.util.repository.DefaultProxySelector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
*/
|
*/
|
||||||
@Component( role = Maven.class )
|
@Component(role = Maven.class)
|
||||||
public class DefaultMaven
|
public class DefaultMaven
|
||||||
implements Maven
|
implements Maven
|
||||||
{
|
{
|
||||||
|
@ -78,7 +111,6 @@ public class DefaultMaven
|
||||||
@Requirement
|
@Requirement
|
||||||
protected ProjectBuilder projectBuilder;
|
protected ProjectBuilder projectBuilder;
|
||||||
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private LifecycleStarter lifecycleStarter;
|
private LifecycleStarter lifecycleStarter;
|
||||||
|
|
||||||
|
@ -91,6 +123,21 @@ public class DefaultMaven
|
||||||
@Requirement
|
@Requirement
|
||||||
private ExecutionEventCatapult eventCatapult;
|
private ExecutionEventCatapult eventCatapult;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private ArtifactHandlerManager artifactHandlerManager;
|
||||||
|
|
||||||
|
@Requirement( optional = true, hint = "ide" )
|
||||||
|
private WorkspaceReader workspaceRepository;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private RepositorySystem repoSystem;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private SettingsDecrypter settingsDecrypter;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
private LegacySupport legacySupport;
|
||||||
|
|
||||||
public MavenExecutionResult execute( MavenExecutionRequest request )
|
public MavenExecutionResult execute( MavenExecutionRequest request )
|
||||||
{
|
{
|
||||||
MavenExecutionResult result;
|
MavenExecutionResult result;
|
||||||
|
@ -113,22 +160,25 @@ public class DefaultMaven
|
||||||
processResult( new DefaultMavenExecutionResult(),
|
processResult( new DefaultMavenExecutionResult(),
|
||||||
new InternalErrorException( "Internal error: " + e, e ) );
|
new InternalErrorException( "Internal error: " + e, e ) );
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
legacySupport.setSession( null );
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( { "ThrowableInstanceNeverThrown", "ThrowableResultOfMethodCallIgnored" } )
|
@SuppressWarnings({"ThrowableInstanceNeverThrown", "ThrowableResultOfMethodCallIgnored"})
|
||||||
private MavenExecutionResult doExecute( MavenExecutionRequest request )
|
private MavenExecutionResult doExecute( MavenExecutionRequest request )
|
||||||
{
|
{
|
||||||
//TODO: Need a general way to inject standard properties
|
//TODO: Need a general way to inject standard properties
|
||||||
if ( request.getStartTime() != null )
|
if ( request.getStartTime() != null )
|
||||||
{
|
{
|
||||||
request.getSystemProperties().put( "${build.timestamp}",
|
request.getSystemProperties().put( "${build.timestamp}", new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) );
|
||||||
new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
request.setStartTime( new Date() );
|
request.setStartTime( new Date() );
|
||||||
|
|
||||||
MavenExecutionResult result = new DefaultMavenExecutionResult();
|
MavenExecutionResult result = new DefaultMavenExecutionResult();
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -142,10 +192,13 @@ public class DefaultMaven
|
||||||
|
|
||||||
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository =
|
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository =
|
||||||
new DelegatingLocalArtifactRepository( request.getLocalRepository() );
|
new DelegatingLocalArtifactRepository( request.getLocalRepository() );
|
||||||
|
|
||||||
|
request.setLocalRepository( delegatingLocalArtifactRepository );
|
||||||
|
|
||||||
request.setLocalRepository( delegatingLocalArtifactRepository );
|
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) newRepositorySession( request );
|
||||||
|
|
||||||
MavenSession session = new MavenSession( container, request, result );
|
MavenSession session = new MavenSession( container, repoSession, request, result );
|
||||||
|
legacySupport.setSession( session );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -161,12 +214,14 @@ public class DefaultMaven
|
||||||
|
|
||||||
eventCatapult.fire( ExecutionEvent.Type.ProjectDiscoveryStarted, session, null );
|
eventCatapult.fire( ExecutionEvent.Type.ProjectDiscoveryStarted, session, null );
|
||||||
|
|
||||||
//TODO: optimize for the single project or no project
|
request.getProjectBuildingRequest().setRepositorySession( session.getRepositorySession() );
|
||||||
|
|
||||||
|
//TODO: optimize for the single project or no project
|
||||||
|
|
||||||
List<MavenProject> projects;
|
List<MavenProject> projects;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
projects = getProjectsForMavenReactor( request );
|
projects = getProjectsForMavenReactor( request );
|
||||||
}
|
}
|
||||||
catch ( ProjectBuildingException e )
|
catch ( ProjectBuildingException e )
|
||||||
{
|
{
|
||||||
|
@ -176,20 +231,23 @@ public class DefaultMaven
|
||||||
session.setProjects( projects );
|
session.setProjects( projects );
|
||||||
|
|
||||||
result.setTopologicallySortedProjects( session.getProjects() );
|
result.setTopologicallySortedProjects( session.getProjects() );
|
||||||
|
|
||||||
result.setProject( session.getTopLevelProject() );
|
result.setProject( session.getTopLevelProject() );
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Map<String, MavenProject> projectMap;
|
Map<String, MavenProject> projectMap;
|
||||||
projectMap = getProjectMap( session.getProjects() );
|
projectMap = getProjectMap( session.getProjects() );
|
||||||
|
|
||||||
// Desired order of precedence for local artifact repositories
|
// Desired order of precedence for local artifact repositories
|
||||||
//
|
//
|
||||||
// Reactor
|
// Reactor
|
||||||
// Workspace
|
// Workspace
|
||||||
// User Local Repository
|
// User Local Repository
|
||||||
delegatingLocalArtifactRepository.setBuildReactor( new ReactorArtifactRepository( projectMap ) );
|
ReactorReader reactorRepository = new ReactorReader( projectMap );
|
||||||
|
|
||||||
|
repoSession.setWorkspaceReader( ChainedWorkspaceReader.newInstance( reactorRepository,
|
||||||
|
repoSession.getWorkspaceReader() ) );
|
||||||
}
|
}
|
||||||
catch ( org.apache.maven.DuplicateProjectException e )
|
catch ( org.apache.maven.DuplicateProjectException e )
|
||||||
{
|
{
|
||||||
|
@ -226,7 +284,7 @@ public class DefaultMaven
|
||||||
session.setProjectDependencyGraph( projectDependencyGraph );
|
session.setProjectDependencyGraph( projectDependencyGraph );
|
||||||
}
|
}
|
||||||
catch ( CycleDetectedException e )
|
catch ( CycleDetectedException e )
|
||||||
{
|
{
|
||||||
String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();
|
String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();
|
||||||
|
|
||||||
ProjectCycleException error = new ProjectCycleException( message, e );
|
ProjectCycleException error = new ProjectCycleException( message, e );
|
||||||
|
@ -261,7 +319,133 @@ public class DefaultMaven
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( { "ResultOfMethodCallIgnored" } )
|
public RepositorySystemSession newRepositorySession( MavenExecutionRequest request )
|
||||||
|
{
|
||||||
|
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
|
||||||
|
|
||||||
|
session.setCache( request.getRepositoryCache() );
|
||||||
|
|
||||||
|
session.setIgnoreInvalidArtifactDescriptor( true ).setIgnoreMissingArtifactDescriptor( true );
|
||||||
|
|
||||||
|
session.setUserProps( request.getUserProperties() );
|
||||||
|
session.setSystemProps( request.getSystemProperties() );
|
||||||
|
session.setConfigProps( request.getSystemProperties() );
|
||||||
|
|
||||||
|
session.setOffline( request.isOffline() );
|
||||||
|
session.setChecksumPolicy( request.getGlobalChecksumPolicy() );
|
||||||
|
session.setUpdatePolicy( request.isUpdateSnapshots() ? RepositoryPolicy.UPDATE_POLICY_ALWAYS : null );
|
||||||
|
|
||||||
|
session.setNotFoundCachingEnabled( !request.isUpdateSnapshots() );
|
||||||
|
session.setTransferErrorCachingEnabled( !request.isUpdateSnapshots() );
|
||||||
|
|
||||||
|
session.setArtifactTypeRegistry( RepositoryUtils.newArtifactTypeRegistry( artifactHandlerManager ) );
|
||||||
|
|
||||||
|
LocalRepository localRepo = new LocalRepository( request.getLocalRepository().getBasedir() );
|
||||||
|
session.setLocalRepositoryManager( repoSystem.newLocalRepositoryManager( localRepo ) );
|
||||||
|
|
||||||
|
session.setWorkspaceReader( workspaceRepository );
|
||||||
|
|
||||||
|
DefaultSettingsDecryptionRequest decrypt = new DefaultSettingsDecryptionRequest();
|
||||||
|
decrypt.setProxies( request.getProxies() );
|
||||||
|
decrypt.setServers( request.getServers() );
|
||||||
|
SettingsDecryptionResult decrypted = settingsDecrypter.decrypt( decrypt );
|
||||||
|
|
||||||
|
if ( logger.isDebugEnabled() )
|
||||||
|
{
|
||||||
|
for ( SettingsProblem problem : decrypted.getProblems() )
|
||||||
|
{
|
||||||
|
logger.debug( problem.getMessage(), problem.getException() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
|
||||||
|
for ( Mirror mirror : request.getMirrors() )
|
||||||
|
{
|
||||||
|
mirrorSelector.add( mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(),
|
||||||
|
mirror.getMirrorOfLayouts() );
|
||||||
|
}
|
||||||
|
session.setMirrorSelector( mirrorSelector );
|
||||||
|
|
||||||
|
DefaultProxySelector proxySelector = new DefaultProxySelector();
|
||||||
|
for ( Proxy proxy : decrypted.getProxies() )
|
||||||
|
{
|
||||||
|
Authentication proxyAuth = new Authentication( proxy.getUsername(), proxy.getPassword() );
|
||||||
|
proxySelector.add( new org.sonatype.aether.repository.Proxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(),
|
||||||
|
proxyAuth ), proxy.getNonProxyHosts() );
|
||||||
|
}
|
||||||
|
session.setProxySelector( proxySelector );
|
||||||
|
|
||||||
|
DefaultAuthenticationSelector authSelector = new DefaultAuthenticationSelector();
|
||||||
|
for ( Server server : decrypted.getServers() )
|
||||||
|
{
|
||||||
|
Authentication auth =
|
||||||
|
new Authentication( server.getUsername(), server.getPassword(), server.getPrivateKey(),
|
||||||
|
server.getPassphrase() );
|
||||||
|
authSelector.add( server.getId(), auth );
|
||||||
|
}
|
||||||
|
session.setAuthenticationSelector( authSelector );
|
||||||
|
|
||||||
|
DependencyTraverser depTraverser = new FatArtifactTraverser();
|
||||||
|
session.setDependencyTraverser( depTraverser );
|
||||||
|
|
||||||
|
DependencyManager depManager = new ClassicDependencyManager();
|
||||||
|
session.setDependencyManager( depManager );
|
||||||
|
|
||||||
|
DependencySelector depFilter =
|
||||||
|
new AndDependencySelector( new ScopeDependencySelector( "test", "provided" ), new OptionalDependencySelector(),
|
||||||
|
new ExclusionDependencySelector() );
|
||||||
|
session.setDependencySelector( depFilter );
|
||||||
|
|
||||||
|
DependencyGraphTransformer transformer =
|
||||||
|
new ChainedDependencyGraphTransformer( new ConflictMarker(), new JavaEffectiveScopeCalculator(),
|
||||||
|
new NearestVersionConflictResolver(),
|
||||||
|
new JavaDependencyContextRefiner() );
|
||||||
|
session.setDependencyGraphTransformer( transformer );
|
||||||
|
|
||||||
|
session.setTransferListener( request.getTransferListener() );
|
||||||
|
|
||||||
|
session.setRepositoryListener( new AbstractRepositoryListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void artifactInstalling( RepositoryEvent event )
|
||||||
|
{
|
||||||
|
logger.info( "Installing " + event.getArtifact().getFile() + " to " + event.getFile() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void metadataInstalling( RepositoryEvent event )
|
||||||
|
{
|
||||||
|
logger.debug( "Installing " + event.getMetadata() + " to " + event.getFile() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void artifactDescriptorInvalid( RepositoryEvent event )
|
||||||
|
{
|
||||||
|
if ( logger.isDebugEnabled() )
|
||||||
|
{
|
||||||
|
logger.warn( "The POM for " + event.getArtifact() + " is invalid"
|
||||||
|
+ ", transitive dependencies (if any) will not be available: "
|
||||||
|
+ event.getException().getMessage() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.warn( "The POM for " + event.getArtifact() + " is invalid"
|
||||||
|
+ ", transitive dependencies (if any) will not be available"
|
||||||
|
+ ", enable debug logging for more details" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void artifactDescriptorMissing( RepositoryEvent event )
|
||||||
|
{
|
||||||
|
logger.warn( "The POM for " + event.getArtifact() + " is missing, no dependency information available" );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"ResultOfMethodCallIgnored"})
|
||||||
private void validateLocalRepository( MavenExecutionRequest request )
|
private void validateLocalRepository( MavenExecutionRequest request )
|
||||||
throws LocalRepositoryNotAccessibleException
|
throws LocalRepositoryNotAccessibleException
|
||||||
{
|
{
|
||||||
|
@ -334,7 +518,7 @@ public class DefaultMaven
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MavenProject> getProjectsForMavenReactor( MavenExecutionRequest request )
|
private List<MavenProject> getProjectsForMavenReactor( MavenExecutionRequest request )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
|
@ -352,8 +536,8 @@ public class DefaultMaven
|
||||||
request.setProjectPresent( false );
|
request.setProjectPresent( false );
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
|
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
|
||||||
collectProjects( projects, files, request );
|
collectProjects( projects, files, request );
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
@ -405,8 +589,7 @@ public class DefaultMaven
|
||||||
{
|
{
|
||||||
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
|
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
|
||||||
|
|
||||||
List<ProjectBuildingResult> results =
|
List<ProjectBuildingResult> results = projectBuilder.build( files, request.isRecursive(), projectBuildingRequest );
|
||||||
projectBuilder.build( files, request.isRecursive(), projectBuildingRequest );
|
|
||||||
|
|
||||||
boolean problems = false;
|
boolean problems = false;
|
||||||
|
|
||||||
|
@ -423,8 +606,7 @@ public class DefaultMaven
|
||||||
for ( ModelProblem problem : result.getProblems() )
|
for ( ModelProblem problem : result.getProblems() )
|
||||||
{
|
{
|
||||||
String location = ModelProblemUtils.formatLocation( problem, result.getProjectId() );
|
String location = ModelProblemUtils.formatLocation( problem, result.getProjectId() );
|
||||||
logger.warn( problem.getMessage()
|
logger.warn( problem.getMessage() + ( StringUtils.isNotEmpty( location ) ? " @ " + location : "" ) );
|
||||||
+ ( StringUtils.isNotEmpty( location ) ? " @ " + location : "" ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
problems = true;
|
problems = true;
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.apache.maven.repository.RepositorySystem;
|
||||||
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;
|
||||||
|
|
||||||
@Component( role = ProjectDependenciesResolver.class )
|
@Component(role = ProjectDependenciesResolver.class)
|
||||||
public class DefaultProjectDependenciesResolver
|
public class DefaultProjectDependenciesResolver
|
||||||
implements ProjectDependenciesResolver
|
implements ProjectDependenciesResolver
|
||||||
{
|
{
|
||||||
|
@ -97,15 +97,15 @@ public class DefaultProjectDependenciesResolver
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( scopesToCollect == null || scopesToCollect.isEmpty() )
|
if ( ( scopesToCollect == null || scopesToCollect.isEmpty() ) &&
|
||||||
&& ( scopesToResolve == null || scopesToResolve.isEmpty() ) )
|
( scopesToResolve == null || scopesToResolve.isEmpty() ) )
|
||||||
{
|
{
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Logic for transitive global exclusions
|
Logic for transitve global exclusions
|
||||||
|
|
||||||
List<String> exclusions = new ArrayList<String>();
|
List<String> exclusions = new ArrayList<String>();
|
||||||
|
|
||||||
|
@ -126,8 +126,7 @@ public class DefaultProjectDependenciesResolver
|
||||||
|
|
||||||
if ( ! exclusions.isEmpty() )
|
if ( ! exclusions.isEmpty() )
|
||||||
{
|
{
|
||||||
filter = new AndArtifactFilter( Arrays.asList( new ArtifactFilter[]{ new ExcludesArtifactFilter( exclusions ),
|
filter = new AndArtifactFilter( Arrays.asList( new ArtifactFilter[]{ new ExcludesArtifactFilter( exclusions ), scopeFilter } ) );
|
||||||
scopeFilter } ) );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -141,11 +140,10 @@ public class DefaultProjectDependenciesResolver
|
||||||
collectionScopeFilter = new CumulativeScopeArtifactFilter( collectionScopeFilter, resolutionScopeFilter );
|
collectionScopeFilter = new CumulativeScopeArtifactFilter( collectionScopeFilter, resolutionScopeFilter );
|
||||||
|
|
||||||
ArtifactResolutionRequest request =
|
ArtifactResolutionRequest request =
|
||||||
new ArtifactResolutionRequest().setResolveRoot( false ).setResolveTransitively( true )
|
new ArtifactResolutionRequest().setResolveRoot( false ).setResolveTransitively( true ).setCollectionFilter(
|
||||||
.setCollectionFilter( collectionScopeFilter ).setResolutionFilter( resolutionScopeFilter )
|
collectionScopeFilter ).setResolutionFilter( resolutionScopeFilter ).setLocalRepository(
|
||||||
.setLocalRepository( session.getLocalRepository() ).setOffline( session.isOffline() )
|
session.getLocalRepository() ).setOffline( session.isOffline() ).setForceUpdate(
|
||||||
.setForceUpdate( session.getRequest().isUpdateSnapshots() ).setCache( session.getRepositoryCache() );
|
session.getRequest().isUpdateSnapshots() );
|
||||||
request.setTransferListener( session.getRequest().getTransferListener() );
|
|
||||||
request.setServers( session.getRequest().getServers() );
|
request.setServers( session.getRequest().getServers() );
|
||||||
request.setMirrors( session.getRequest().getMirrors() );
|
request.setMirrors( session.getRequest().getMirrors() );
|
||||||
request.setProxies( session.getRequest().getProxies() );
|
request.setProxies( session.getRequest().getProxies() );
|
||||||
|
|
|
@ -19,39 +19,40 @@ package org.apache.maven;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.repository.LocalArtifactRepository;
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceReader;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An implementation of a repository that knows how to search the Maven reactor for artifacts.
|
* An implementation of a workspace reader that knows how to search the Maven reactor for artifacts.
|
||||||
*
|
*
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
*/
|
*/
|
||||||
public class ReactorArtifactRepository
|
class ReactorReader
|
||||||
extends LocalArtifactRepository
|
implements WorkspaceReader
|
||||||
{
|
{
|
||||||
|
|
||||||
private Map<String, MavenProject> projectsByGAV;
|
private Map<String, MavenProject> projectsByGAV;
|
||||||
|
|
||||||
private Map<String, List<MavenProject>> projectsByGA;
|
private Map<String, List<MavenProject>> projectsByGA;
|
||||||
|
|
||||||
private final int hashCode;
|
private WorkspaceRepository repository;
|
||||||
|
|
||||||
@SuppressWarnings( { "ConstantConditions" } )
|
@SuppressWarnings( { "ConstantConditions" } )
|
||||||
public ReactorArtifactRepository( Map<String, MavenProject> reactorProjects )
|
public ReactorReader( Map<String, MavenProject> reactorProjects )
|
||||||
{
|
{
|
||||||
projectsByGAV = reactorProjects;
|
projectsByGAV = reactorProjects;
|
||||||
hashCode = ( reactorProjects != null ) ? reactorProjects.keySet().hashCode() : 0;
|
|
||||||
|
|
||||||
projectsByGA = new HashMap<String, List<MavenProject>>( reactorProjects.size() * 2 );
|
projectsByGA = new HashMap<String, List<MavenProject>>( reactorProjects.size() * 2 );
|
||||||
for ( MavenProject project : reactorProjects.values() )
|
for ( MavenProject project : reactorProjects.values() )
|
||||||
|
@ -68,35 +69,18 @@ public class ReactorArtifactRepository
|
||||||
|
|
||||||
projects.add( project );
|
projects.add( project );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
repository = new WorkspaceRepository( "reactor", new HashSet<String>( projectsByGAV.keySet() ) );
|
||||||
public Artifact find( Artifact artifact )
|
|
||||||
{
|
|
||||||
String projectKey = ArtifactUtils.key( artifact );
|
|
||||||
|
|
||||||
MavenProject project = projectsByGAV.get( projectKey );
|
|
||||||
|
|
||||||
if ( project != null )
|
|
||||||
{
|
|
||||||
File file = find( project, artifact );
|
|
||||||
if ( file != null )
|
|
||||||
{
|
|
||||||
resolve( artifact, file );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return artifact;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File find( MavenProject project, Artifact artifact )
|
private File find( MavenProject project, Artifact artifact )
|
||||||
{
|
{
|
||||||
if ( "pom".equals( artifact.getType() ) )
|
if ( "pom".equals( artifact.getExtension() ) )
|
||||||
{
|
{
|
||||||
return project.getFile();
|
return project.getFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
Artifact projectArtifact = findMatchingArtifact( project, artifact );
|
org.apache.maven.artifact.Artifact projectArtifact = findMatchingArtifact( project, artifact );
|
||||||
|
|
||||||
if ( hasArtifactFileFromPackagePhase( projectArtifact ) )
|
if ( hasArtifactFileFromPackagePhase( projectArtifact ) )
|
||||||
{
|
{
|
||||||
|
@ -125,24 +109,120 @@ public class ReactorArtifactRepository
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasArtifactFileFromPackagePhase( Artifact projectArtifact )
|
private boolean hasArtifactFileFromPackagePhase( org.apache.maven.artifact.Artifact projectArtifact )
|
||||||
{
|
{
|
||||||
return projectArtifact != null && projectArtifact.getFile() != null && projectArtifact.getFile().exists();
|
return projectArtifact != null && projectArtifact.getFile() != null && projectArtifact.getFile().exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolve( Artifact artifact, File file )
|
/**
|
||||||
|
* Tries to resolve the specified artifact from the artifacts of the given project.
|
||||||
|
*
|
||||||
|
* @param project The project to try to resolve the artifact from, must not be <code>null</code>.
|
||||||
|
* @param requestedArtifact The artifact to resolve, must not be <code>null</code>.
|
||||||
|
* @return The matching artifact from the project or <code>null</code> if not found.
|
||||||
|
*/
|
||||||
|
private org.apache.maven.artifact.Artifact findMatchingArtifact( MavenProject project, Artifact requestedArtifact )
|
||||||
{
|
{
|
||||||
artifact.setFile( file );
|
String requestedRepositoryConflictId = getConflictId( requestedArtifact );
|
||||||
|
|
||||||
artifact.setResolved( true );
|
org.apache.maven.artifact.Artifact mainArtifact = project.getArtifact();
|
||||||
|
if ( requestedRepositoryConflictId.equals( getConflictId( mainArtifact ) ) )
|
||||||
|
{
|
||||||
|
return mainArtifact;
|
||||||
|
}
|
||||||
|
|
||||||
artifact.setRepository( this );
|
Collection<org.apache.maven.artifact.Artifact> attachedArtifacts = project.getAttachedArtifacts();
|
||||||
|
if ( attachedArtifacts != null && !attachedArtifacts.isEmpty() )
|
||||||
|
{
|
||||||
|
for ( org.apache.maven.artifact.Artifact attachedArtifact : attachedArtifacts )
|
||||||
|
{
|
||||||
|
if ( requestedRepositoryConflictId.equals( getConflictId( attachedArtifact ) ) )
|
||||||
|
{
|
||||||
|
return attachedArtifact;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the repository conflict id of the specified artifact. Unlike the dependency conflict id, the repository
|
||||||
|
* conflict id uses the artifact file extension instead of the artifact type. Hence, the repository conflict id more
|
||||||
|
* closely reflects the identity of artifacts as perceived by a repository.
|
||||||
|
*
|
||||||
|
* @param artifact The artifact, must not be <code>null</code>.
|
||||||
|
* @return The repository conflict id, never <code>null</code>.
|
||||||
|
*/
|
||||||
|
private String getConflictId( org.apache.maven.artifact.Artifact artifact )
|
||||||
|
{
|
||||||
|
StringBuilder buffer = new StringBuilder( 128 );
|
||||||
|
buffer.append( artifact.getGroupId() );
|
||||||
|
buffer.append( ':' ).append( artifact.getArtifactId() );
|
||||||
|
if ( artifact.getArtifactHandler() != null )
|
||||||
|
{
|
||||||
|
buffer.append( ':' ).append( artifact.getArtifactHandler().getExtension() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
buffer.append( ':' ).append( artifact.getType() );
|
||||||
|
}
|
||||||
|
if ( artifact.hasClassifier() )
|
||||||
|
{
|
||||||
|
buffer.append( ':' ).append( artifact.getClassifier() );
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getConflictId( Artifact artifact )
|
||||||
|
{
|
||||||
|
StringBuilder buffer = new StringBuilder( 128 );
|
||||||
|
buffer.append( artifact.getGroupId() );
|
||||||
|
buffer.append( ':' ).append( artifact.getArtifactId() );
|
||||||
|
buffer.append( ':' ).append( artifact.getExtension() );
|
||||||
|
if ( artifact.getClassifier().length() > 0 )
|
||||||
|
{
|
||||||
|
buffer.append( ':' ).append( artifact.getClassifier() );
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the specified artifact refers to test classes.
|
||||||
|
*
|
||||||
|
* @param artifact The artifact to check, must not be {@code null}.
|
||||||
|
* @return {@code true} if the artifact refers to test classes, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
private static boolean isTestArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
if ( "test-jar".equals( artifact.getProperty( "type", "" ) ) )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if ( "jar".equals( artifact.getExtension() ) && "tests".equals( artifact.getClassifier() ) )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File findArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
String projectKey = artifact.getGroupId() + ':' + artifact.getArtifactId() + ':' + artifact.getVersion();
|
||||||
|
|
||||||
|
MavenProject project = projectsByGAV.get( projectKey );
|
||||||
|
|
||||||
|
if ( project != null )
|
||||||
|
{
|
||||||
|
return find( project, artifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> findVersions( Artifact artifact )
|
public List<String> findVersions( Artifact artifact )
|
||||||
{
|
{
|
||||||
String key = ArtifactUtils.versionlessKey( artifact );
|
String key = artifact.getGroupId() + ':' + artifact.getArtifactId();
|
||||||
|
|
||||||
List<MavenProject> projects = projectsByGA.get( key );
|
List<MavenProject> projects = projectsByGA.get( key );
|
||||||
if ( projects == null || projects.isEmpty() )
|
if ( projects == null || projects.isEmpty() )
|
||||||
|
@ -163,148 +243,9 @@ public class ReactorArtifactRepository
|
||||||
return Collections.unmodifiableList( versions );
|
return Collections.unmodifiableList( versions );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public WorkspaceRepository getRepository()
|
||||||
public String getId()
|
|
||||||
{
|
{
|
||||||
return "reactor";
|
return repository;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasLocalMetadata()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tries to resolve the specified artifact from the artifacts of the given project.
|
|
||||||
*
|
|
||||||
* @param project The project to try to resolve the artifact from, must not be <code>null</code>.
|
|
||||||
* @param requestedArtifact The artifact to resolve, must not be <code>null</code>.
|
|
||||||
* @return The matching artifact from the project or <code>null</code> if not found.
|
|
||||||
*/
|
|
||||||
private Artifact findMatchingArtifact( MavenProject project, Artifact requestedArtifact )
|
|
||||||
{
|
|
||||||
String requestedDependencyConflictId = requestedArtifact.getDependencyConflictId();
|
|
||||||
|
|
||||||
// check for match with project's main artifact by dependency conflict id
|
|
||||||
Artifact mainArtifact = project.getArtifact();
|
|
||||||
if ( requestedDependencyConflictId.equals( mainArtifact.getDependencyConflictId() ) )
|
|
||||||
{
|
|
||||||
return mainArtifact;
|
|
||||||
}
|
|
||||||
|
|
||||||
String requestedRepositoryConflictId = getRepositoryConflictId( requestedArtifact );
|
|
||||||
|
|
||||||
// check for match with project's main artifact by repository conflict id
|
|
||||||
if ( requestedRepositoryConflictId.equals( getRepositoryConflictId( mainArtifact ) ) )
|
|
||||||
{
|
|
||||||
return mainArtifact;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for match with one of the attached artifacts
|
|
||||||
Collection<Artifact> attachedArtifacts = project.getAttachedArtifacts();
|
|
||||||
if ( attachedArtifacts != null && !attachedArtifacts.isEmpty() )
|
|
||||||
{
|
|
||||||
// first try matching by dependency conflict id
|
|
||||||
for ( Artifact attachedArtifact : attachedArtifacts )
|
|
||||||
{
|
|
||||||
if ( requestedDependencyConflictId.equals( attachedArtifact.getDependencyConflictId() ) )
|
|
||||||
{
|
|
||||||
return attachedArtifact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// next try matching by repository conflict id
|
|
||||||
for ( Artifact attachedArtifact : attachedArtifacts )
|
|
||||||
{
|
|
||||||
if ( requestedRepositoryConflictId.equals( getRepositoryConflictId( attachedArtifact ) ) )
|
|
||||||
{
|
|
||||||
return attachedArtifact;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the repository conflict id of the specified artifact. Unlike the dependency conflict id, the repository
|
|
||||||
* conflict id uses the artifact file extension instead of the artifact type. Hence, the repository conflict id more
|
|
||||||
* closely reflects the identity of artifacts as perceived by a repository.
|
|
||||||
*
|
|
||||||
* @param artifact The artifact, must not be <code>null</code>.
|
|
||||||
* @return The repository conflict id, never <code>null</code>.
|
|
||||||
*/
|
|
||||||
private String getRepositoryConflictId( Artifact artifact )
|
|
||||||
{
|
|
||||||
StringBuilder buffer = new StringBuilder( 128 );
|
|
||||||
buffer.append( artifact.getGroupId() );
|
|
||||||
buffer.append( ':' ).append( artifact.getArtifactId() );
|
|
||||||
if ( artifact.getArtifactHandler() != null )
|
|
||||||
{
|
|
||||||
buffer.append( ':' ).append( artifact.getArtifactHandler().getExtension() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buffer.append( ':' ).append( artifact.getType() );
|
|
||||||
}
|
|
||||||
if ( artifact.hasClassifier() )
|
|
||||||
{
|
|
||||||
buffer.append( ':' ).append( artifact.getClassifier() );
|
|
||||||
}
|
|
||||||
return buffer.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the specified artifact refers to test classes.
|
|
||||||
*
|
|
||||||
* @param artifact The artifact to check, must not be {@code null}.
|
|
||||||
* @return {@code true} if the artifact refers to test classes, {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
private static boolean isTestArtifact( Artifact artifact )
|
|
||||||
{
|
|
||||||
if ( "test-jar".equals( artifact.getType() ) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if ( "jar".equals( artifact.getType() ) && "tests".equals( artifact.getClassifier() ) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
return hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals( Object obj )
|
|
||||||
{
|
|
||||||
if ( this == obj )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if ( obj == null )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ( getClass() != obj.getClass() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReactorArtifactRepository other = (ReactorArtifactRepository) obj;
|
|
||||||
|
|
||||||
return eq( projectsByGAV.keySet(), other.projectsByGAV.keySet() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isProjectAware()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,325 @@
|
||||||
|
package org.apache.maven;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.handler.ArtifactHandler;
|
||||||
|
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
|
||||||
|
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.artifact.ArtifactType;
|
||||||
|
import org.sonatype.aether.artifact.ArtifactTypeRegistry;
|
||||||
|
import org.sonatype.aether.graph.Dependency;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.graph.DependencyNode;
|
||||||
|
import org.sonatype.aether.graph.Exclusion;
|
||||||
|
import org.sonatype.aether.repository.Authentication;
|
||||||
|
import org.sonatype.aether.repository.Proxy;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.RepositoryPolicy;
|
||||||
|
import org.sonatype.aether.util.artifact.ArtifactProperties;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifactType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <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
|
||||||
|
*/
|
||||||
|
public class RepositoryUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
private static String nullify( String string )
|
||||||
|
{
|
||||||
|
return ( string == null || string.length() <= 0 ) ? null : string;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static org.apache.maven.artifact.Artifact toArtifact( Dependency dependency )
|
||||||
|
{
|
||||||
|
if ( dependency == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
org.apache.maven.artifact.Artifact result = toArtifact( dependency.getArtifact() );
|
||||||
|
result.setScope( dependency.getScope() );
|
||||||
|
result.setOptional( dependency.isOptional() );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.apache.maven.artifact.Artifact toArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
if ( artifact == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArtifactHandler handler = newHandler( artifact );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: From Artifact.hasClassifier(), an empty string and a null both denote "no classifier". However, some
|
||||||
|
* plugins only check for null, so be sure to nullify an empty classifier.
|
||||||
|
*/
|
||||||
|
org.apache.maven.artifact.Artifact result =
|
||||||
|
new org.apache.maven.artifact.DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
||||||
|
artifact.getVersion(), null,
|
||||||
|
artifact.getProperty( ArtifactProperties.TYPE,
|
||||||
|
artifact.getExtension() ),
|
||||||
|
nullify( artifact.getClassifier() ), handler );
|
||||||
|
|
||||||
|
result.setFile( artifact.getFile() );
|
||||||
|
result.setResolved( artifact.getFile() != null );
|
||||||
|
|
||||||
|
List<String> trail = new ArrayList<String>( 1 );
|
||||||
|
trail.add( result.getId() );
|
||||||
|
result.setDependencyTrail( trail );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void toArtifacts( Collection<org.apache.maven.artifact.Artifact> artifacts,
|
||||||
|
Collection<? extends DependencyNode> nodes, List<String> trail,
|
||||||
|
DependencyFilter filter )
|
||||||
|
{
|
||||||
|
for ( DependencyNode node : nodes )
|
||||||
|
{
|
||||||
|
org.apache.maven.artifact.Artifact artifact = toArtifact( node.getDependency() );
|
||||||
|
|
||||||
|
List<String> nodeTrail = new ArrayList<String>( trail.size() + 1 );
|
||||||
|
nodeTrail.addAll( trail );
|
||||||
|
nodeTrail.add( artifact.getId() );
|
||||||
|
|
||||||
|
if ( filter == null || filter.accept( node, Collections.<DependencyNode> emptyList() ) )
|
||||||
|
{
|
||||||
|
artifact.setDependencyTrail( nodeTrail );
|
||||||
|
artifacts.add( artifact );
|
||||||
|
}
|
||||||
|
|
||||||
|
toArtifacts( artifacts, node.getChildren(), nodeTrail, filter );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Artifact toArtifact( org.apache.maven.artifact.Artifact artifact )
|
||||||
|
{
|
||||||
|
if ( artifact == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String version = artifact.getVersion();
|
||||||
|
if ( version == null && artifact.getVersionRange() != null )
|
||||||
|
{
|
||||||
|
version = artifact.getVersionRange().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> props = null;
|
||||||
|
if ( org.apache.maven.artifact.Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
|
||||||
|
{
|
||||||
|
props = Collections.singletonMap( ArtifactProperties.LACKS_DESCRIPTOR, Boolean.TRUE.toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
Artifact result =
|
||||||
|
new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(),
|
||||||
|
artifact.getArtifactHandler().getExtension(), version, props,
|
||||||
|
newArtifactType( artifact.getType(), artifact.getArtifactHandler() ) );
|
||||||
|
result = result.setFile( artifact.getFile() );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dependency toDependency( org.apache.maven.artifact.Artifact artifact,
|
||||||
|
Collection<org.apache.maven.model.Exclusion> exclusions )
|
||||||
|
{
|
||||||
|
if ( artifact == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Artifact result = toArtifact( artifact );
|
||||||
|
|
||||||
|
List<Exclusion> excl = null;
|
||||||
|
if ( exclusions != null )
|
||||||
|
{
|
||||||
|
excl = new ArrayList<Exclusion>( exclusions.size() );
|
||||||
|
for ( org.apache.maven.model.Exclusion exclusion : exclusions )
|
||||||
|
{
|
||||||
|
excl.add( toExclusion( exclusion ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Dependency( result, artifact.getScope(), artifact.isOptional(), excl );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<RemoteRepository> toRepos( List<ArtifactRepository> repos )
|
||||||
|
{
|
||||||
|
if ( repos == null )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<RemoteRepository> results = new ArrayList<RemoteRepository>( repos.size() );
|
||||||
|
for ( ArtifactRepository repo : repos )
|
||||||
|
{
|
||||||
|
results.add( toRepo( repo ) );
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RemoteRepository toRepo( ArtifactRepository repo )
|
||||||
|
{
|
||||||
|
RemoteRepository result = null;
|
||||||
|
if ( repo != null )
|
||||||
|
{
|
||||||
|
result = new RemoteRepository( repo.getId(), repo.getLayout().getId(), repo.getUrl() );
|
||||||
|
result.setPolicy( true, toPolicy( repo.getSnapshots() ) );
|
||||||
|
result.setPolicy( false, toPolicy( repo.getReleases() ) );
|
||||||
|
result.setAuthentication( toAuthentication( repo.getAuthentication() ) );
|
||||||
|
result.setProxy( toProxy( repo.getProxy() ) );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RepositoryPolicy toPolicy( ArtifactRepositoryPolicy policy )
|
||||||
|
{
|
||||||
|
RepositoryPolicy result = null;
|
||||||
|
if ( policy != null )
|
||||||
|
{
|
||||||
|
result = new RepositoryPolicy( policy.isEnabled(), policy.getUpdatePolicy(), policy.getChecksumPolicy() );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Authentication toAuthentication( org.apache.maven.artifact.repository.Authentication auth )
|
||||||
|
{
|
||||||
|
Authentication result = null;
|
||||||
|
if ( auth != null )
|
||||||
|
{
|
||||||
|
result = new Authentication( auth.getUsername(), auth.getPassword() );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Proxy toProxy( org.apache.maven.repository.Proxy proxy )
|
||||||
|
{
|
||||||
|
Proxy result = null;
|
||||||
|
if ( proxy != null )
|
||||||
|
{
|
||||||
|
Authentication auth = new Authentication( proxy.getUserName(), proxy.getPassword() );
|
||||||
|
result = new Proxy( proxy.getProtocol(), proxy.getHost(), proxy.getPort(), auth );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArtifactHandler newHandler( Artifact artifact )
|
||||||
|
{
|
||||||
|
String type = artifact.getProperty( ArtifactProperties.TYPE, artifact.getExtension() );
|
||||||
|
DefaultArtifactHandler handler = new DefaultArtifactHandler( type );
|
||||||
|
handler.setExtension( artifact.getExtension() );
|
||||||
|
handler.setLanguage( artifact.getProperty( ArtifactProperties.LANGUAGE, null ) );
|
||||||
|
handler.setAddedToClasspath( Boolean.parseBoolean( artifact.getProperty( ArtifactProperties.CONSTITUTES_BUILD_PATH,
|
||||||
|
"" ) ) );
|
||||||
|
handler.setIncludesDependencies( Boolean.parseBoolean( artifact.getProperty( ArtifactProperties.INCLUDES_DEPENDENCIES,
|
||||||
|
"" ) ) );
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArtifactType newArtifactType( String id, ArtifactHandler handler )
|
||||||
|
{
|
||||||
|
return new DefaultArtifactType( id, handler.getExtension(), handler.getClassifier(), handler.getLanguage(),
|
||||||
|
handler.isAddedToClasspath(), handler.isIncludesDependencies() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Dependency toDependency( org.apache.maven.model.Dependency dependency,
|
||||||
|
ArtifactTypeRegistry stereotypes )
|
||||||
|
{
|
||||||
|
ArtifactType stereotype = stereotypes.get( dependency.getType() );
|
||||||
|
if ( stereotype == null )
|
||||||
|
{
|
||||||
|
stereotype = new DefaultArtifactType( dependency.getType() );
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean system = dependency.getSystemPath() != null && dependency.getSystemPath().length() > 0;
|
||||||
|
|
||||||
|
Map<String, String> props = null;
|
||||||
|
if ( system )
|
||||||
|
{
|
||||||
|
props = Collections.singletonMap( ArtifactProperties.LACKS_DESCRIPTOR, Boolean.TRUE.toString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
Artifact artifact =
|
||||||
|
new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null,
|
||||||
|
dependency.getVersion(), props, stereotype );
|
||||||
|
|
||||||
|
if ( system )
|
||||||
|
{
|
||||||
|
artifact = artifact.setFile( new File( dependency.getSystemPath() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Exclusion> exclusions = new ArrayList<Exclusion>( dependency.getExclusions().size() );
|
||||||
|
for ( org.apache.maven.model.Exclusion exclusion : dependency.getExclusions() )
|
||||||
|
{
|
||||||
|
exclusions.add( toExclusion( exclusion ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
Dependency result = new Dependency( artifact, dependency.getScope(), dependency.isOptional(), exclusions );
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Exclusion toExclusion( org.apache.maven.model.Exclusion exclusion )
|
||||||
|
{
|
||||||
|
return new Exclusion( exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArtifactTypeRegistry newArtifactTypeRegistry( ArtifactHandlerManager handlerManager )
|
||||||
|
{
|
||||||
|
return new MavenArtifactTypeRegistry( handlerManager );
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MavenArtifactTypeRegistry
|
||||||
|
implements ArtifactTypeRegistry
|
||||||
|
{
|
||||||
|
|
||||||
|
private final ArtifactHandlerManager handlerManager;
|
||||||
|
|
||||||
|
public MavenArtifactTypeRegistry( ArtifactHandlerManager handlerManager )
|
||||||
|
{
|
||||||
|
this.handlerManager = handlerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtifactType get( String stereotypeId )
|
||||||
|
{
|
||||||
|
ArtifactHandler handler = handlerManager.getArtifactHandler( stereotypeId );
|
||||||
|
return newArtifactType( stereotypeId, handler );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -64,6 +64,11 @@ public class DefaultArtifactHandler
|
||||||
return extension;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setExtension( String extension )
|
||||||
|
{
|
||||||
|
this.extension = extension;
|
||||||
|
}
|
||||||
|
|
||||||
public String getType()
|
public String getType()
|
||||||
{
|
{
|
||||||
return type;
|
return type;
|
||||||
|
@ -97,6 +102,11 @@ public class DefaultArtifactHandler
|
||||||
return includesDependencies;
|
return includesDependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIncludesDependencies( boolean includesDependencies )
|
||||||
|
{
|
||||||
|
this.includesDependencies = includesDependencies;
|
||||||
|
}
|
||||||
|
|
||||||
public String getLanguage()
|
public String getLanguage()
|
||||||
{
|
{
|
||||||
if ( language == null )
|
if ( language == null )
|
||||||
|
@ -107,8 +117,19 @@ public class DefaultArtifactHandler
|
||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLanguage( String language )
|
||||||
|
{
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAddedToClasspath()
|
public boolean isAddedToClasspath()
|
||||||
{
|
{
|
||||||
return addedToClasspath;
|
return addedToClasspath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAddedToClasspath( boolean addedToClasspath )
|
||||||
|
{
|
||||||
|
this.addedToClasspath = addedToClasspath;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,10 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects basic settings to access the repository system.
|
* Collects basic settings to access the repository system.
|
||||||
*
|
*
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
public class DefaultRepositoryRequest
|
public class DefaultRepositoryRequest
|
||||||
|
@ -43,10 +42,6 @@ public class DefaultRepositoryRequest
|
||||||
|
|
||||||
private List<ArtifactRepository> remoteRepositories;
|
private List<ArtifactRepository> remoteRepositories;
|
||||||
|
|
||||||
private RepositoryCache cache;
|
|
||||||
|
|
||||||
private ArtifactTransferListener transferListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty repository request.
|
* Creates an empty repository request.
|
||||||
*/
|
*/
|
||||||
|
@ -57,7 +52,7 @@ public class DefaultRepositoryRequest
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a shallow copy of the specified repository request.
|
* Creates a shallow copy of the specified repository request.
|
||||||
*
|
*
|
||||||
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
|
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
|
||||||
*/
|
*/
|
||||||
public DefaultRepositoryRequest( RepositoryRequest repositoryRequest )
|
public DefaultRepositoryRequest( RepositoryRequest repositoryRequest )
|
||||||
|
@ -65,16 +60,13 @@ public class DefaultRepositoryRequest
|
||||||
setLocalRepository( repositoryRequest.getLocalRepository() );
|
setLocalRepository( repositoryRequest.getLocalRepository() );
|
||||||
setRemoteRepositories( repositoryRequest.getRemoteRepositories() );
|
setRemoteRepositories( repositoryRequest.getRemoteRepositories() );
|
||||||
setOffline( repositoryRequest.isOffline() );
|
setOffline( repositoryRequest.isOffline() );
|
||||||
setCache( repositoryRequest.getCache() );
|
|
||||||
setForceUpdate( repositoryRequest.isForceUpdate() );
|
setForceUpdate( repositoryRequest.isForceUpdate() );
|
||||||
setTransferListener( repositoryRequest.getTransferListener() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RepositoryRequest getRepositoryRequest( MavenSession session, MavenProject project )
|
public static RepositoryRequest getRepositoryRequest( MavenSession session, MavenProject project )
|
||||||
{
|
{
|
||||||
RepositoryRequest request = new DefaultRepositoryRequest();
|
RepositoryRequest request = new DefaultRepositoryRequest();
|
||||||
|
|
||||||
request.setCache( session.getRepositoryCache() );
|
|
||||||
request.setLocalRepository( session.getLocalRepository() );
|
request.setLocalRepository( session.getLocalRepository() );
|
||||||
if ( project != null )
|
if ( project != null )
|
||||||
{
|
{
|
||||||
|
@ -82,7 +74,6 @@ public class DefaultRepositoryRequest
|
||||||
}
|
}
|
||||||
request.setOffline( session.isOffline() );
|
request.setOffline( session.isOffline() );
|
||||||
request.setForceUpdate( session.getRequest().isUpdateSnapshots() );
|
request.setForceUpdate( session.getRequest().isUpdateSnapshots() );
|
||||||
request.setTransferListener( session.getRequest().getTransferListener() );
|
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
@ -140,28 +131,4 @@ public class DefaultRepositoryRequest
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepositoryCache getCache()
|
|
||||||
{
|
|
||||||
return cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultRepositoryRequest setCache( RepositoryCache cache )
|
|
||||||
{
|
|
||||||
this.cache = cache;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArtifactTransferListener getTransferListener()
|
|
||||||
{
|
|
||||||
return transferListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultRepositoryRequest setTransferListener( ArtifactTransferListener transferListener )
|
|
||||||
{
|
|
||||||
this.transferListener = transferListener;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ package org.apache.maven.artifact.repository;
|
||||||
*
|
*
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface RepositoryCache
|
public interface RepositoryCache
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.apache.maven.artifact.repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects basic settings to access the repository system.
|
* Collects basic settings to access the repository system.
|
||||||
*
|
*
|
||||||
|
@ -94,34 +92,4 @@ public interface RepositoryRequest
|
||||||
*/
|
*/
|
||||||
RepositoryRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
|
RepositoryRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the repository cache to use.
|
|
||||||
*
|
|
||||||
* @return The repository cache to use or {@code null} if none.
|
|
||||||
*/
|
|
||||||
RepositoryCache getCache();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the repository cache to use.
|
|
||||||
*
|
|
||||||
* @param cache The repository cache to use, may be {@code null}.
|
|
||||||
* @return This request, never {@code null}.
|
|
||||||
*/
|
|
||||||
RepositoryRequest setCache( RepositoryCache cache );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the listener to notify of transfer events.
|
|
||||||
*
|
|
||||||
* @return The transfer listener or {@code null} if none.
|
|
||||||
*/
|
|
||||||
ArtifactTransferListener getTransferListener();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the listener to notify of transfer events.
|
|
||||||
*
|
|
||||||
* @param transferListener The transfer listener to notify, may be {@code null}.
|
|
||||||
* @return This request, never {@code null}.
|
|
||||||
*/
|
|
||||||
RepositoryRequest setTransferListener( ArtifactTransferListener transferListener );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
import org.apache.maven.artifact.repository.RepositoryCache;
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
import org.apache.maven.artifact.repository.RepositoryRequest;
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
|
||||||
import org.apache.maven.settings.Mirror;
|
import org.apache.maven.settings.Mirror;
|
||||||
import org.apache.maven.settings.Proxy;
|
import org.apache.maven.settings.Proxy;
|
||||||
import org.apache.maven.settings.Server;
|
import org.apache.maven.settings.Server;
|
||||||
|
@ -55,8 +54,6 @@ public class ArtifactResolutionRequest
|
||||||
|
|
||||||
private List<ArtifactRepository> remoteRepositories;
|
private List<ArtifactRepository> remoteRepositories;
|
||||||
|
|
||||||
private RepositoryCache cache;
|
|
||||||
|
|
||||||
private ArtifactFilter collectionFilter;
|
private ArtifactFilter collectionFilter;
|
||||||
|
|
||||||
private ArtifactFilter resolutionFilter;
|
private ArtifactFilter resolutionFilter;
|
||||||
|
@ -66,8 +63,6 @@ public class ArtifactResolutionRequest
|
||||||
|
|
||||||
// This is like a filter but overrides all transitive versions
|
// This is like a filter but overrides all transitive versions
|
||||||
private Map managedVersionMap;
|
private Map managedVersionMap;
|
||||||
|
|
||||||
private ArtifactTransferListener transferListener;
|
|
||||||
|
|
||||||
private boolean resolveRoot = true;
|
private boolean resolveRoot = true;
|
||||||
|
|
||||||
|
@ -92,10 +87,8 @@ public class ArtifactResolutionRequest
|
||||||
{
|
{
|
||||||
setLocalRepository( request.getLocalRepository() );
|
setLocalRepository( request.getLocalRepository() );
|
||||||
setRemoteRepositories( request.getRemoteRepositories() );
|
setRemoteRepositories( request.getRemoteRepositories() );
|
||||||
setCache( request.getCache() );
|
|
||||||
setOffline( request.isOffline() );
|
setOffline( request.isOffline() );
|
||||||
setForceUpdate( request.isForceUpdate() );
|
setForceUpdate( request.isForceUpdate() );
|
||||||
setTransferListener( request.getTransferListener() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Artifact getArtifact()
|
public Artifact getArtifact()
|
||||||
|
@ -237,17 +230,6 @@ public class ArtifactResolutionRequest
|
||||||
{
|
{
|
||||||
return resolveTransitively;
|
return resolveTransitively;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactTransferListener getTransferListener()
|
|
||||||
{
|
|
||||||
return transferListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArtifactResolutionRequest setTransferListener( ArtifactTransferListener transferListener )
|
|
||||||
{
|
|
||||||
this.transferListener = transferListener;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
@ -263,13 +245,11 @@ public class ArtifactResolutionRequest
|
||||||
|
|
||||||
public RepositoryCache getCache()
|
public RepositoryCache getCache()
|
||||||
{
|
{
|
||||||
return cache;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionRequest setCache( RepositoryCache cache )
|
public ArtifactResolutionRequest setCache( RepositoryCache cache )
|
||||||
{
|
{
|
||||||
this.cache = cache;
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.maven.classrealm;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
|
@ -49,12 +49,12 @@ class ArtifactClassRealmConstituent
|
||||||
|
|
||||||
public String getType()
|
public String getType()
|
||||||
{
|
{
|
||||||
return artifact.getType();
|
return artifact.getExtension();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClassifier()
|
public String getClassifier()
|
||||||
{
|
{
|
||||||
return artifact.hasClassifier() ? artifact.getClassifier() : "";
|
return artifact.getClassifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion()
|
public String getVersion()
|
||||||
|
@ -70,7 +70,7 @@ class ArtifactClassRealmConstituent
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return artifact.getId();
|
return artifact.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ package org.apache.maven.classrealm;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the class realms used by Maven. <strong>Warning:</strong> This is an internal utility interface that is only
|
* Manages the class realms used by Maven. <strong>Warning:</strong> This is an internal utility interface that is only
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.classrealm.ClassRealmRequest.RealmType;
|
import org.apache.maven.classrealm.ClassRealmRequest.RealmType;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
|
@ -43,11 +42,12 @@ import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the class realms used by Maven. <strong>Warning:</strong> This is an internal utility class that is only
|
* Manages the class realms used by Maven. <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 interface can be changed or
|
* public for technical reasons, it is not part of the public API. In particular, this class can be changed or deleted
|
||||||
* deleted without prior notice.
|
* without prior notice.
|
||||||
*
|
*
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
|
@ -133,7 +133,7 @@ public class DefaultClassRealmManager
|
||||||
{
|
{
|
||||||
for ( Artifact artifact : artifacts )
|
for ( Artifact artifact : artifacts )
|
||||||
{
|
{
|
||||||
artifactIds.add( artifact.getId() );
|
artifactIds.add( getId( artifact ) );
|
||||||
if ( artifact.getFile() != null )
|
if ( artifact.getFile() != null )
|
||||||
{
|
{
|
||||||
constituents.add( new ArtifactClassRealmConstituent( artifact ) );
|
constituents.add( new ArtifactClassRealmConstituent( artifact ) );
|
||||||
|
@ -260,6 +260,9 @@ public class DefaultClassRealmManager
|
||||||
// maven-*
|
// maven-*
|
||||||
importingRealm.importFrom( coreRealm, "org.apache.maven" );
|
importingRealm.importFrom( coreRealm, "org.apache.maven" );
|
||||||
|
|
||||||
|
// aether
|
||||||
|
importingRealm.importFrom( coreRealm, "org.sonatype.aether" );
|
||||||
|
|
||||||
// plexus-classworlds
|
// plexus-classworlds
|
||||||
importingRealm.importFrom( coreRealm, "org.codehaus.plexus.classworlds" );
|
importingRealm.importFrom( coreRealm, "org.codehaus.plexus.classworlds" );
|
||||||
|
|
||||||
|
@ -334,11 +337,21 @@ public class DefaultClassRealmManager
|
||||||
+ version;
|
+ version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getId( Artifact artifact )
|
||||||
|
{
|
||||||
|
return getId( artifact.getGroupId(), artifact.getArtifactId(), artifact.getExtension(), artifact.getClassifier(),
|
||||||
|
artifact.getBaseVersion() );
|
||||||
|
}
|
||||||
|
|
||||||
private static String getId( ClassRealmConstituent constituent )
|
private static String getId( ClassRealmConstituent constituent )
|
||||||
{
|
{
|
||||||
return constituent.getGroupId() + ':' + constituent.getArtifactId() + ':' + constituent.getType()
|
return getId( constituent.getGroupId(), constituent.getArtifactId(), constituent.getType(),
|
||||||
+ ( StringUtils.isNotEmpty( constituent.getClassifier() ) ? ':' + constituent.getClassifier() : "" ) + ':'
|
constituent.getClassifier(), constituent.getVersion() );
|
||||||
+ constituent.getVersion();
|
}
|
||||||
|
|
||||||
|
private static String getId( String gid, String aid, String type, String cls, String ver )
|
||||||
|
{
|
||||||
|
return gid + ':' + aid + ':' + type + ( StringUtils.isNotEmpty( cls ) ? ':' + cls : "" ) + ':' + ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ClassRealmManagerDelegate> getDelegates()
|
private List<ClassRealmManagerDelegate> getDelegates()
|
||||||
|
|
|
@ -26,14 +26,15 @@ import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.project.DefaultProjectBuildingRequest;
|
import org.apache.maven.project.DefaultProjectBuildingRequest;
|
||||||
import org.apache.maven.project.ProjectBuildingRequest;
|
import org.apache.maven.project.ProjectBuildingRequest;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
|
||||||
import org.apache.maven.settings.Mirror;
|
import org.apache.maven.settings.Mirror;
|
||||||
import org.apache.maven.settings.Proxy;
|
import org.apache.maven.settings.Proxy;
|
||||||
import org.apache.maven.settings.Server;
|
import org.apache.maven.settings.Server;
|
||||||
|
import org.sonatype.aether.RepositoryCache;
|
||||||
|
import org.sonatype.aether.transfer.TransferListener;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositoryCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
|
@ -42,7 +43,7 @@ public class DefaultMavenExecutionRequest
|
||||||
implements MavenExecutionRequest
|
implements MavenExecutionRequest
|
||||||
{
|
{
|
||||||
|
|
||||||
private RepositoryCache repositoryCache = new SessionRepositoryCache();
|
private RepositoryCache repositoryCache = new DefaultRepositoryCache();
|
||||||
|
|
||||||
private ArtifactRepository localRepository;
|
private ArtifactRepository localRepository;
|
||||||
|
|
||||||
|
@ -110,7 +111,7 @@ public class DefaultMavenExecutionRequest
|
||||||
|
|
||||||
private List<String> inactiveProfiles;
|
private List<String> inactiveProfiles;
|
||||||
|
|
||||||
private ArtifactTransferListener transferListener;
|
private TransferListener transferListener;
|
||||||
|
|
||||||
private int loggingLevel = LOGGING_LEVEL_INFO;
|
private int loggingLevel = LOGGING_LEVEL_INFO;
|
||||||
|
|
||||||
|
@ -350,7 +351,7 @@ public class DefaultMavenExecutionRequest
|
||||||
return inactiveProfiles;
|
return inactiveProfiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactTransferListener getTransferListener()
|
public TransferListener getTransferListener()
|
||||||
{
|
{
|
||||||
return transferListener;
|
return transferListener;
|
||||||
}
|
}
|
||||||
|
@ -592,7 +593,7 @@ public class DefaultMavenExecutionRequest
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenExecutionRequest setTransferListener( ArtifactTransferListener transferListener )
|
public MavenExecutionRequest setTransferListener( TransferListener transferListener )
|
||||||
{
|
{
|
||||||
this.transferListener = transferListener;
|
this.transferListener = transferListener;
|
||||||
|
|
||||||
|
@ -953,7 +954,6 @@ public class DefaultMavenExecutionRequest
|
||||||
projectBuildingRequest.setUserProperties( getUserProperties() );
|
projectBuildingRequest.setUserProperties( getUserProperties() );
|
||||||
projectBuildingRequest.setRemoteRepositories( getRemoteRepositories() );
|
projectBuildingRequest.setRemoteRepositories( getRemoteRepositories() );
|
||||||
projectBuildingRequest.setPluginArtifactRepositories( getPluginArtifactRepositories() );
|
projectBuildingRequest.setPluginArtifactRepositories( getPluginArtifactRepositories() );
|
||||||
projectBuildingRequest.setRepositoryCache( getRepositoryCache() );
|
|
||||||
projectBuildingRequest.setOffline( isOffline() );
|
projectBuildingRequest.setOffline( isOffline() );
|
||||||
projectBuildingRequest.setForceUpdate( isUpdateSnapshots() );
|
projectBuildingRequest.setForceUpdate( isUpdateSnapshots() );
|
||||||
projectBuildingRequest.setServers( getServers() );
|
projectBuildingRequest.setServers( getServers() );
|
||||||
|
@ -964,7 +964,6 @@ public class DefaultMavenExecutionRequest
|
||||||
projectBuildingRequest.setProfiles( getProfiles() );
|
projectBuildingRequest.setProfiles( getProfiles() );
|
||||||
projectBuildingRequest.setProcessPlugins( true );
|
projectBuildingRequest.setProcessPlugins( true );
|
||||||
projectBuildingRequest.setBuildStartTime( getStartTime() );
|
projectBuildingRequest.setBuildStartTime( getStartTime() );
|
||||||
projectBuildingRequest.setTransferListener( getTransferListener() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectBuildingRequest;
|
return projectBuildingRequest;
|
||||||
|
|
|
@ -25,7 +25,7 @@ import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.project.DependencyResolutionResult;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
/** @author Jason van Zyl */
|
/** @author Jason van Zyl */
|
||||||
|
@ -36,7 +36,7 @@ public class DefaultMavenExecutionResult
|
||||||
|
|
||||||
private List<MavenProject> topologicallySortedProjects;
|
private List<MavenProject> topologicallySortedProjects;
|
||||||
|
|
||||||
private ArtifactResolutionResult artifactResolutionResult;
|
private DependencyResolutionResult dependencyResolutionResult;
|
||||||
|
|
||||||
private List<Throwable> exceptions;
|
private List<Throwable> exceptions;
|
||||||
|
|
||||||
|
@ -66,14 +66,14 @@ public class DefaultMavenExecutionResult
|
||||||
return topologicallySortedProjects;
|
return topologicallySortedProjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult getArtifactResolutionResult()
|
public DependencyResolutionResult getDependencyResolutionResult()
|
||||||
{
|
{
|
||||||
return artifactResolutionResult;
|
return dependencyResolutionResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenExecutionResult setArtifactResolutionResult( ArtifactResolutionResult artifactResolutionResult )
|
public MavenExecutionResult setDependencyResolutionResult( DependencyResolutionResult dependencyResolutionResult )
|
||||||
{
|
{
|
||||||
this.artifactResolutionResult = artifactResolutionResult;
|
this.dependencyResolutionResult = dependencyResolutionResult;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,14 @@ import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
|
||||||
import org.apache.maven.model.Profile;
|
import org.apache.maven.model.Profile;
|
||||||
import org.apache.maven.project.ProjectBuildingRequest;
|
import org.apache.maven.project.ProjectBuildingRequest;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
|
||||||
import org.apache.maven.settings.Mirror;
|
import org.apache.maven.settings.Mirror;
|
||||||
import org.apache.maven.settings.Proxy;
|
import org.apache.maven.settings.Proxy;
|
||||||
import org.apache.maven.settings.Server;
|
import org.apache.maven.settings.Server;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
import org.sonatype.aether.RepositoryCache;
|
||||||
|
import org.sonatype.aether.transfer.TransferListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
|
@ -170,8 +170,8 @@ public interface MavenExecutionRequest
|
||||||
boolean isShowErrors();
|
boolean isShowErrors();
|
||||||
|
|
||||||
// Transfer listeners
|
// Transfer listeners
|
||||||
MavenExecutionRequest setTransferListener( ArtifactTransferListener transferListener );
|
MavenExecutionRequest setTransferListener( TransferListener transferListener );
|
||||||
ArtifactTransferListener getTransferListener();
|
TransferListener getTransferListener();
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
MavenExecutionRequest setLoggingLevel( int loggingLevel );
|
MavenExecutionRequest setLoggingLevel( int loggingLevel );
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.maven.execution;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
import org.apache.maven.project.DependencyResolutionResult;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,8 +35,8 @@ public interface MavenExecutionResult
|
||||||
MavenExecutionResult setTopologicallySortedProjects( List<MavenProject> projects );
|
MavenExecutionResult setTopologicallySortedProjects( List<MavenProject> projects );
|
||||||
List<MavenProject> getTopologicallySortedProjects();
|
List<MavenProject> getTopologicallySortedProjects();
|
||||||
|
|
||||||
MavenExecutionResult setArtifactResolutionResult( ArtifactResolutionResult result );
|
MavenExecutionResult setDependencyResolutionResult( DependencyResolutionResult result );
|
||||||
ArtifactResolutionResult getArtifactResolutionResult();
|
DependencyResolutionResult getDependencyResolutionResult();
|
||||||
|
|
||||||
// for each exception
|
// for each exception
|
||||||
// - knowing what artifacts are missing
|
// - knowing what artifacts are missing
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.apache.maven.project.ProjectBuildingRequest;
|
||||||
import org.apache.maven.settings.Settings;
|
import org.apache.maven.settings.Settings;
|
||||||
import org.codehaus.plexus.PlexusContainer;
|
import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
|
@ -50,6 +51,8 @@ public class MavenSession
|
||||||
|
|
||||||
private MavenExecutionResult result;
|
private MavenExecutionResult result;
|
||||||
|
|
||||||
|
private RepositorySystemSession repositorySession;
|
||||||
|
|
||||||
private final Settings settings;
|
private final Settings settings;
|
||||||
|
|
||||||
private Properties executionProperties;
|
private Properties executionProperties;
|
||||||
|
@ -115,12 +118,14 @@ public class MavenSession
|
||||||
setProjects( projects );
|
setProjects( projects );
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenExecutionResult result )
|
public MavenSession( PlexusContainer container, RepositorySystemSession repositorySession, MavenExecutionRequest request,
|
||||||
|
MavenExecutionResult result )
|
||||||
{
|
{
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.request = request;
|
this.request = request;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
this.settings = new SettingsAdapter( request );
|
this.settings = new SettingsAdapter( request );
|
||||||
|
this.repositorySession = repositorySession;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProjects( List<MavenProject> projects )
|
public void setProjects( List<MavenProject> projects )
|
||||||
|
@ -180,9 +185,10 @@ public class MavenSession
|
||||||
return container.lookupMap( role );
|
return container.lookupMap( role );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public RepositoryCache getRepositoryCache()
|
public RepositoryCache getRepositoryCache()
|
||||||
{
|
{
|
||||||
return request.getRepositoryCache();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactRepository getLocalRepository()
|
public ArtifactRepository getLocalRepository()
|
||||||
|
@ -277,7 +283,7 @@ public class MavenSession
|
||||||
|
|
||||||
public ProjectBuildingRequest getProjectBuildingRequest()
|
public ProjectBuildingRequest getProjectBuildingRequest()
|
||||||
{
|
{
|
||||||
return request.getProjectBuildingRequest();
|
return request.getProjectBuildingRequest().setRepositorySession( getRepositorySession() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPluginGroups()
|
public List<String> getPluginGroups()
|
||||||
|
@ -382,4 +388,10 @@ public class MavenSession
|
||||||
{
|
{
|
||||||
this.parallel = parallel;
|
this.parallel = parallel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RepositorySystemSession getRepositorySession()
|
||||||
|
{
|
||||||
|
return repositorySession;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,7 @@ package org.apache.maven.lifecycle;
|
||||||
|
|
||||||
import org.apache.maven.lifecycle.internal.BuilderCommon;
|
import org.apache.maven.lifecycle.internal.BuilderCommon;
|
||||||
import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
|
import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
|
||||||
import org.apache.maven.plugin.InvalidPluginDescriptorException;
|
|
||||||
import org.apache.maven.plugin.MojoExecution;
|
import org.apache.maven.plugin.MojoExecution;
|
||||||
import org.apache.maven.plugin.MojoNotFoundException;
|
|
||||||
import org.apache.maven.plugin.PluginDescriptorParsingException;
|
|
||||||
import org.apache.maven.plugin.PluginNotFoundException;
|
|
||||||
import org.apache.maven.plugin.PluginResolutionException;
|
|
||||||
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
|
|
||||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -55,9 +48,6 @@ public class DefaultSchedules
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ExecutionPlanItem> createExecutionPlanItem( MavenProject mavenProject, List<MojoExecution> executions )
|
public List<ExecutionPlanItem> createExecutionPlanItem( MavenProject mavenProject, List<MojoExecution> executions )
|
||||||
throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
|
|
||||||
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
|
|
||||||
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
|
|
||||||
{
|
{
|
||||||
BuilderCommon.attachToThread( mavenProject );
|
BuilderCommon.attachToThread( mavenProject );
|
||||||
|
|
||||||
|
|
|
@ -1,25 +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.
|
||||||
|
*/
|
||||||
package org.apache.maven.lifecycle.internal;
|
package org.apache.maven.lifecycle.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 org.apache.maven.artifact.repository.DefaultRepositoryRequest;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.lifecycle.DefaultLifecycles;
|
import org.apache.maven.lifecycle.DefaultLifecycles;
|
||||||
import org.apache.maven.lifecycle.DefaultSchedules;
|
import org.apache.maven.lifecycle.DefaultSchedules;
|
||||||
|
@ -147,9 +141,10 @@ public class DefaultLifecycleExecutionPlanCalculator
|
||||||
|
|
||||||
if ( mojoDescriptor == null )
|
if ( mojoDescriptor == null )
|
||||||
{
|
{
|
||||||
mojoDescriptor = pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(),
|
mojoDescriptor =
|
||||||
DefaultRepositoryRequest.getRepositoryRequest(
|
pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(),
|
||||||
session, project ) );
|
project.getRemotePluginRepositories(),
|
||||||
|
session.getRepositorySession() );
|
||||||
|
|
||||||
mojoExecution.setMojoDescriptor( mojoDescriptor );
|
mojoExecution.setMojoDescriptor( mojoDescriptor );
|
||||||
}
|
}
|
||||||
|
@ -251,10 +246,11 @@ public class DefaultLifecycleExecutionPlanCalculator
|
||||||
|
|
||||||
if ( lifecycle == null )
|
if ( lifecycle == null )
|
||||||
{
|
{
|
||||||
throw new LifecyclePhaseNotFoundException( "Unknown lifecycle phase \"" + lifecyclePhase
|
throw new LifecyclePhaseNotFoundException(
|
||||||
+ "\". You must specify a valid lifecycle phase" + " or a goal in the format <plugin-prefix>:<goal> or"
|
"Unknown lifecycle phase \"" + lifecyclePhase + "\". You must specify a valid lifecycle phase" +
|
||||||
+ " <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: "
|
" or a goal in the format <plugin-prefix>:<goal> or" +
|
||||||
+ defaultLifeCycles.getLifecyclePhaseList() + ".", lifecyclePhase );
|
" <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: " +
|
||||||
|
defaultLifeCycles.getLifecyclePhaseList() + ".", lifecyclePhase );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -309,9 +305,8 @@ public class DefaultLifecycleExecutionPlanCalculator
|
||||||
for ( String goal : execution.getGoals() )
|
for ( String goal : execution.getGoals() )
|
||||||
{
|
{
|
||||||
MojoDescriptor mojoDescriptor =
|
MojoDescriptor mojoDescriptor =
|
||||||
pluginManager.getMojoDescriptor( plugin, goal,
|
pluginManager.getMojoDescriptor( plugin, goal, project.getRemotePluginRepositories(),
|
||||||
DefaultRepositoryRequest.getRepositoryRequest( session,
|
session.getRepositorySession() );
|
||||||
project ) );
|
|
||||||
|
|
||||||
Map<Integer, List<MojoExecution>> phaseBindings = mappings.get( mojoDescriptor.getPhase() );
|
Map<Integer, List<MojoExecution>> phaseBindings = mappings.get( mojoDescriptor.getPhase() );
|
||||||
if ( phaseBindings != null )
|
if ( phaseBindings != null )
|
||||||
|
@ -464,8 +459,8 @@ public class DefaultLifecycleExecutionPlanCalculator
|
||||||
{
|
{
|
||||||
parameterConfiguration = new Xpp3Dom( parameterConfiguration, parameter.getName() );
|
parameterConfiguration = new Xpp3Dom( parameterConfiguration, parameter.getName() );
|
||||||
|
|
||||||
if ( StringUtils.isEmpty( parameterConfiguration.getAttribute( "implementation" ) )
|
if ( StringUtils.isEmpty( parameterConfiguration.getAttribute( "implementation" ) ) &&
|
||||||
&& StringUtils.isNotEmpty( parameter.getImplementation() ) )
|
StringUtils.isNotEmpty( parameter.getImplementation() ) )
|
||||||
{
|
{
|
||||||
parameterConfiguration.setAttribute( "implementation", parameter.getImplementation() );
|
parameterConfiguration.setAttribute( "implementation", parameter.getImplementation() );
|
||||||
}
|
}
|
||||||
|
@ -488,7 +483,8 @@ public class DefaultLifecycleExecutionPlanCalculator
|
||||||
PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
|
PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
|
||||||
LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
|
LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
|
||||||
{
|
{
|
||||||
calculateForkedExecutions( mojoExecution, session, session.getCurrentProject(), new HashSet<MojoDescriptor>() );
|
calculateForkedExecutions( mojoExecution, session, session.getCurrentProject(), new HashSet<MojoDescriptor>() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -556,8 +552,8 @@ public class DefaultLifecycleExecutionPlanCalculator
|
||||||
{
|
{
|
||||||
MojoDescriptor forkedMojoDescriptor =
|
MojoDescriptor forkedMojoDescriptor =
|
||||||
pluginManager.getMojoDescriptor( forkedExecution.getPlugin(), forkedExecution.getGoal(),
|
pluginManager.getMojoDescriptor( forkedExecution.getPlugin(), forkedExecution.getGoal(),
|
||||||
DefaultRepositoryRequest.getRepositoryRequest( session,
|
project.getRemotePluginRepositories(),
|
||||||
project ) );
|
session.getRepositorySession() );
|
||||||
|
|
||||||
forkedExecution.setMojoDescriptor( forkedMojoDescriptor );
|
forkedExecution.setMojoDescriptor( forkedMojoDescriptor );
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,41 @@
|
||||||
package org.apache.maven.lifecycle.internal;
|
package org.apache.maven.lifecycle.internal;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* agreements. See the NOTICE file distributed with this work for additional information regarding
|
||||||
* distributed with this work for additional information
|
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* "License"); you may not use this file except in compliance with the License. You may obtain a
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* copy of the License at
|
||||||
* "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
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
* software distributed under the License is distributed on an
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* KIND, either express or implied. See the License for the
|
* the License.
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.ProjectDependenciesResolver;
|
import org.apache.maven.RepositoryUtils;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|
||||||
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||||
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
import org.apache.maven.lifecycle.MavenExecutionPlan;
|
||||||
|
import org.apache.maven.project.DefaultDependencyResolutionRequest;
|
||||||
|
import org.apache.maven.project.DependencyResolutionException;
|
||||||
|
import org.apache.maven.project.DependencyResolutionResult;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.project.ProjectDependenciesResolver;
|
||||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||||
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;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
import org.sonatype.aether.graph.Dependency;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.graph.DependencyNode;
|
||||||
|
import org.sonatype.aether.util.filter.AndDependencyFilter;
|
||||||
|
import org.sonatype.aether.util.filter.ScopeDependencyFilter;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -47,11 +49,12 @@ import java.util.*;
|
||||||
* <p/>
|
* <p/>
|
||||||
* NOTE: This class is not part of any public api and can be changed or deleted without prior notice.
|
* NOTE: This class is not part of any public api and can be changed or deleted without prior notice.
|
||||||
*/
|
*/
|
||||||
@Component( role = LifecycleDependencyResolver.class )
|
@Component(role = LifecycleDependencyResolver.class)
|
||||||
public class LifecycleDependencyResolver
|
public class LifecycleDependencyResolver
|
||||||
{
|
{
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private ProjectDependenciesResolver projectDependenciesResolver;
|
private ProjectDependenciesResolver dependenciesResolver;
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
@ -59,14 +62,14 @@ public class LifecycleDependencyResolver
|
||||||
@Requirement
|
@Requirement
|
||||||
private ArtifactFactory artifactFactory;
|
private ArtifactFactory artifactFactory;
|
||||||
|
|
||||||
@SuppressWarnings( { "UnusedDeclaration" } )
|
@SuppressWarnings({"UnusedDeclaration"})
|
||||||
public LifecycleDependencyResolver()
|
public LifecycleDependencyResolver()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public LifecycleDependencyResolver( ProjectDependenciesResolver projectDependenciesResolver, Logger logger )
|
public LifecycleDependencyResolver( ProjectDependenciesResolver projectDependenciesResolver, Logger logger )
|
||||||
{
|
{
|
||||||
this.projectDependenciesResolver = projectDependenciesResolver;
|
this.dependenciesResolver = projectDependenciesResolver;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,87 +139,112 @@ public class LifecycleDependencyResolver
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Artifact> artifacts =
|
Set<Artifact> artifacts =
|
||||||
getProjectDependencies( project, scopesToCollect, scopesToResolve, session, aggregating,
|
getDependencies( project, scopesToCollect, scopesToResolve, session, aggregating, projectArtifacts );
|
||||||
projectArtifacts );
|
|
||||||
|
|
||||||
project.setResolvedArtifacts( artifacts );
|
project.setResolvedArtifacts( artifacts );
|
||||||
|
|
||||||
|
Map<String, Artifact> map = new HashMap<String, Artifact>();
|
||||||
|
for ( Artifact artifact : artifacts )
|
||||||
|
{
|
||||||
|
map.put( artifact.getId(), artifact );
|
||||||
|
}
|
||||||
|
for ( Artifact artifact : project.getDependencyArtifacts() )
|
||||||
|
{
|
||||||
|
if ( artifact.getFile() == null )
|
||||||
|
{
|
||||||
|
Artifact resolved = map.get( artifact.getId() );
|
||||||
|
if ( resolved != null )
|
||||||
|
{
|
||||||
|
artifact.setFile( resolved.getFile() );
|
||||||
|
artifact.setDependencyTrail( resolved.getDependencyTrail() );
|
||||||
|
artifact.setResolvedVersion( resolved.getVersion() );
|
||||||
|
artifact.setResolved( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Artifact> getProjectDependencies( MavenProject project, Collection<String> scopesToCollect,
|
private Set<Artifact> getDependencies( MavenProject project, Collection<String> scopesToCollect,
|
||||||
Collection<String> scopesToResolve, MavenSession session,
|
Collection<String> scopesToResolve, MavenSession session,
|
||||||
boolean aggregating, Set<Artifact> projectArtifacts )
|
boolean aggregating, Set<Artifact> projectArtifacts )
|
||||||
throws LifecycleExecutionException
|
throws LifecycleExecutionException
|
||||||
{
|
{
|
||||||
Set<Artifact> artifacts;
|
if ( scopesToCollect == null )
|
||||||
|
{
|
||||||
|
scopesToCollect = Collections.emptySet();
|
||||||
|
}
|
||||||
|
if ( scopesToResolve == null )
|
||||||
|
{
|
||||||
|
scopesToResolve = Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( scopesToCollect.isEmpty() && scopesToResolve.isEmpty() )
|
||||||
|
{
|
||||||
|
return new LinkedHashSet<Artifact>();
|
||||||
|
}
|
||||||
|
|
||||||
|
scopesToCollect = new HashSet<String>( scopesToCollect );
|
||||||
|
scopesToCollect.addAll( scopesToResolve );
|
||||||
|
|
||||||
|
DependencyFilter collectionFilter = new ScopeDependencyFilter( null, negate( scopesToCollect ) );
|
||||||
|
DependencyFilter resolutionFilter = new ScopeDependencyFilter( null, negate( scopesToResolve ) );
|
||||||
|
resolutionFilter = AndDependencyFilter.newInstance( collectionFilter, resolutionFilter );
|
||||||
|
resolutionFilter =
|
||||||
|
AndDependencyFilter.newInstance( resolutionFilter, new ReactorDependencyFilter( projectArtifacts ) );
|
||||||
|
|
||||||
|
DependencyResolutionResult result;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
try
|
DefaultDependencyResolutionRequest request =
|
||||||
|
new DefaultDependencyResolutionRequest( project, session.getRepositorySession() );
|
||||||
|
request.setResolutionFilter( resolutionFilter );
|
||||||
|
|
||||||
|
result = dependenciesResolver.resolve( request );
|
||||||
|
}
|
||||||
|
catch ( DependencyResolutionException e )
|
||||||
|
{
|
||||||
|
result = e.getResult();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MNG-2277, the check below compensates for our bad plugin support where we ended up with aggregator
|
||||||
|
* plugins that require dependency resolution although they usually run in phases of the build where project
|
||||||
|
* artifacts haven't been assembled yet. The prime example of this is "mvn release:prepare".
|
||||||
|
*/
|
||||||
|
if ( aggregating && areAllDependenciesInReactor( session.getProjects(), result.getUnresolvedDependencies() ) )
|
||||||
{
|
{
|
||||||
artifacts = projectDependenciesResolver.resolve( project , scopesToCollect,
|
logger.warn( "The following dependencies could not be resolved at this point of the build"
|
||||||
scopesToResolve, session, projectArtifacts );
|
+ " but seem to be part of the reactor:" );
|
||||||
|
|
||||||
|
for ( Dependency dependency : result.getUnresolvedDependencies() )
|
||||||
|
{
|
||||||
|
logger.warn( "o " + dependency );
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.warn( "Try running the build up to the lifecycle phase \"package\"" );
|
||||||
}
|
}
|
||||||
catch ( MultipleArtifactsNotFoundException e )
|
else
|
||||||
{
|
{
|
||||||
/*
|
throw new LifecycleExecutionException( null, project, e );
|
||||||
* MNG-2277, the check below compensates for our bad plugin support where we ended up with aggregator
|
|
||||||
* plugins that require dependency resolution although they usually run in phases of the build where
|
|
||||||
* project artifacts haven't been assembled yet. The prime example of this is "mvn release:prepare".
|
|
||||||
*/
|
|
||||||
artifacts = handleException( session, aggregating, e );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return artifacts;
|
|
||||||
}
|
|
||||||
catch ( ArtifactResolutionException e )
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( null, project, e );
|
|
||||||
}
|
|
||||||
catch ( ArtifactNotFoundException e )
|
|
||||||
{
|
|
||||||
throw new LifecycleExecutionException( null, project, e );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
|
||||||
|
if ( result.getDependencyGraph() != null && !result.getDependencyGraph().getChildren().isEmpty() )
|
||||||
|
|
||||||
private Set<Artifact> handleException( MavenSession session, boolean aggregating,
|
|
||||||
MultipleArtifactsNotFoundException e )
|
|
||||||
throws MultipleArtifactsNotFoundException
|
|
||||||
{
|
|
||||||
Set<Artifact> artifacts;
|
|
||||||
/*
|
|
||||||
* MNG-2277, the check below compensates for our bad plugin support where we ended up with aggregator
|
|
||||||
* plugins that require dependency resolution although they usually run in phases of the build where project
|
|
||||||
* artifacts haven't been assembled yet. The prime example of this is "mvn release:prepare".
|
|
||||||
*/
|
|
||||||
if ( aggregating && areAllArtifactsInReactor( session.getProjects(), e.getMissingArtifacts() ) )
|
|
||||||
{
|
{
|
||||||
logger.warn( "The following artifacts could not be resolved at this point of the build"
|
RepositoryUtils.toArtifacts( artifacts, result.getDependencyGraph().getChildren(),
|
||||||
+ " but seem to be part of the reactor:" );
|
Collections.singletonList( project.getArtifact().getId() ), collectionFilter );
|
||||||
|
|
||||||
for ( Artifact artifact : e.getMissingArtifacts() )
|
|
||||||
{
|
|
||||||
logger.warn( "o " + artifact.getId() );
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.warn( "Try running the build up to the lifecycle phase \"package\"" );
|
|
||||||
|
|
||||||
artifacts = new LinkedHashSet<Artifact>( e.getResolvedArtifacts() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
return artifacts;
|
return artifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean areAllArtifactsInReactor( Collection<MavenProject> projects, Collection<Artifact> artifacts )
|
private boolean areAllDependenciesInReactor( Collection<MavenProject> projects, Collection<Dependency> dependencies )
|
||||||
{
|
{
|
||||||
Set<String> projectKeys = getReactorProjectKeys( projects );
|
Set<String> projectKeys = getReactorProjectKeys( projects );
|
||||||
|
|
||||||
for ( Artifact artifact : artifacts )
|
for ( Dependency dependency : dependencies )
|
||||||
{
|
{
|
||||||
String key = ArtifactUtils.key( artifact );
|
org.sonatype.aether.artifact.Artifact a = dependency.getArtifact();
|
||||||
|
String key = ArtifactUtils.key( a.getGroupId(), a.getArtifactId(), a.getVersion() );
|
||||||
if ( !projectKeys.contains( key ) )
|
if ( !projectKeys.contains( key ) )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -237,4 +265,73 @@ public class LifecycleDependencyResolver
|
||||||
return projectKeys;
|
return projectKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<String> negate( Collection<String> scopes )
|
||||||
|
{
|
||||||
|
Collection<String> result = new HashSet<String>();
|
||||||
|
Collections.addAll( result, "system", "compile", "provided", "runtime", "test" );
|
||||||
|
|
||||||
|
for ( String scope : scopes )
|
||||||
|
{
|
||||||
|
if ( "compile".equals( scope ) )
|
||||||
|
{
|
||||||
|
result.remove( "compile" );
|
||||||
|
result.remove( "system" );
|
||||||
|
result.remove( "provided" );
|
||||||
|
}
|
||||||
|
else if ( "runtime".equals( scope ) )
|
||||||
|
{
|
||||||
|
result.remove( "compile" );
|
||||||
|
result.remove( "runtime" );
|
||||||
|
}
|
||||||
|
else if ( "compile+runtime".equals( scope ) )
|
||||||
|
{
|
||||||
|
result.remove( "compile" );
|
||||||
|
result.remove( "system" );
|
||||||
|
result.remove( "provided" );
|
||||||
|
result.remove( "runtime" );
|
||||||
|
}
|
||||||
|
else if ( "runtime+system".equals( scope ) )
|
||||||
|
{
|
||||||
|
result.remove( "compile" );
|
||||||
|
result.remove( "system" );
|
||||||
|
result.remove( "runtime" );
|
||||||
|
}
|
||||||
|
else if ( "test".equals( scope ) )
|
||||||
|
{
|
||||||
|
result.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ReactorDependencyFilter
|
||||||
|
implements DependencyFilter
|
||||||
|
{
|
||||||
|
|
||||||
|
private Set<String> keys = new HashSet<String>();
|
||||||
|
|
||||||
|
public ReactorDependencyFilter( Collection<Artifact> artifacts )
|
||||||
|
{
|
||||||
|
for ( Artifact artifact : artifacts )
|
||||||
|
{
|
||||||
|
String key = ArtifactUtils.key( artifact );
|
||||||
|
keys.add( key );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean accept( DependencyNode node, List<DependencyNode> parents )
|
||||||
|
{
|
||||||
|
Dependency dependency = node.getDependency();
|
||||||
|
if ( dependency != null )
|
||||||
|
{
|
||||||
|
org.sonatype.aether.artifact.Artifact a = dependency.getArtifact();
|
||||||
|
String key = ArtifactUtils.key( a.getGroupId(), a.getArtifactId(), a.getVersion() );
|
||||||
|
return !keys.contains( key );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,9 @@ public class LifecyclePluginResolver
|
||||||
{
|
{
|
||||||
if ( plugin.getVersion() == null )
|
if ( plugin.getVersion() == null )
|
||||||
{
|
{
|
||||||
PluginVersionRequest request = new DefaultPluginVersionRequest( plugin, session );
|
PluginVersionRequest request =
|
||||||
|
new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
|
||||||
|
project.getRemotePluginRepositories() );
|
||||||
plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
|
plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
|
||||||
}
|
}
|
||||||
versions.put( plugin.getKey(), plugin.getVersion() );
|
versions.put( plugin.getKey(), plugin.getVersion() );
|
||||||
|
@ -82,7 +84,9 @@ public class LifecyclePluginResolver
|
||||||
plugin.setVersion( versions.get( plugin.getKey() ) );
|
plugin.setVersion( versions.get( plugin.getKey() ) );
|
||||||
if ( plugin.getVersion() == null )
|
if ( plugin.getVersion() == null )
|
||||||
{
|
{
|
||||||
PluginVersionRequest request = new DefaultPluginVersionRequest( plugin, session );
|
PluginVersionRequest request =
|
||||||
|
new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
|
||||||
|
project.getRemotePluginRepositories() );
|
||||||
plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
|
plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.maven.lifecycle.internal;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Dependency;
|
import org.apache.maven.model.Dependency;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
@ -202,17 +200,16 @@ public class MojoDescriptorCreator
|
||||||
|
|
||||||
injectPluginDeclarationFromProject( plugin, project );
|
injectPluginDeclarationFromProject( plugin, project );
|
||||||
|
|
||||||
RepositoryRequest repositoryRequest = DefaultRepositoryRequest.getRepositoryRequest( session, project );
|
|
||||||
|
|
||||||
// If there is no version to be found then we need to look in the repository metadata for
|
// If there is no version to be found then we need to look in the repository metadata for
|
||||||
// this plugin and see what's specified as the latest release.
|
// this plugin and see what's specified as the latest release.
|
||||||
//
|
//
|
||||||
if ( plugin.getVersion() == null )
|
if ( plugin.getVersion() == null )
|
||||||
{
|
{
|
||||||
resolvePluginVersion( plugin, repositoryRequest );
|
resolvePluginVersion( plugin, session, project );
|
||||||
}
|
}
|
||||||
|
|
||||||
return pluginManager.getMojoDescriptor( plugin, goal, repositoryRequest );
|
return pluginManager.getMojoDescriptor( plugin, goal, project.getRemotePluginRepositories(),
|
||||||
|
session.getRepositorySession() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: take repo mans into account as one may be aggregating prefixes of many
|
// TODO: take repo mans into account as one may be aggregating prefixes of many
|
||||||
|
@ -234,10 +231,12 @@ public class MojoDescriptorCreator
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolvePluginVersion( Plugin plugin, RepositoryRequest repositoryRequest )
|
private void resolvePluginVersion( Plugin plugin, MavenSession session, MavenProject project )
|
||||||
throws PluginVersionResolutionException
|
throws PluginVersionResolutionException
|
||||||
{
|
{
|
||||||
PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, repositoryRequest );
|
PluginVersionRequest versionRequest =
|
||||||
|
new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
|
||||||
|
project.getRemotePluginRepositories() );
|
||||||
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
|
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.lifecycle.LifecycleExecutor;
|
import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
@ -54,7 +54,7 @@ public class DefaultLifecycleBindingsInjector
|
||||||
private LifecycleBindingsMerger merger = new LifecycleBindingsMerger();
|
private LifecycleBindingsMerger merger = new LifecycleBindingsMerger();
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private LifecycleExecutor lifecycle;
|
private LifeCyclePluginAnalyzer lifecycle;
|
||||||
|
|
||||||
public void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
|
public void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,30 +1,29 @@
|
||||||
package org.apache.maven.plugin;
|
package org.apache.maven.plugin;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* agreements. See the NOTICE file distributed with this work for additional information regarding
|
||||||
* distributed with this work for additional information
|
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* "License"); you may not use this file except in compliance with the License. You may obtain a
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* copy of the License at
|
||||||
* "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
|
||||||
*
|
*
|
||||||
* 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
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* software distributed under the License is distributed on an
|
* the License.
|
||||||
* "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.apache.maven.artifact.repository.RepositoryRequest;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
|
@ -32,12 +31,13 @@ import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
public interface BuildPluginManager
|
public interface BuildPluginManager
|
||||||
{
|
{
|
||||||
// igorf: Way too many declared exceptions!
|
// igorf: Way too many declared exceptions!
|
||||||
PluginDescriptor loadPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
|
PluginDescriptor loadPlugin( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
||||||
InvalidPluginDescriptorException;
|
InvalidPluginDescriptorException;
|
||||||
|
|
||||||
// igorf: Way too many declared exceptions!
|
// igorf: Way too many declared exceptions!
|
||||||
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
|
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories,
|
||||||
|
RepositorySystemSession session )
|
||||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
||||||
MojoNotFoundException, InvalidPluginDescriptorException;
|
MojoNotFoundException, InvalidPluginDescriptorException;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,211 @@
|
||||||
|
package org.apache.maven.plugin;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.maven.model.Dependency;
|
||||||
|
import org.apache.maven.model.Exclusion;
|
||||||
|
import org.apache.maven.model.Plugin;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.RepositoryPolicy;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceReader;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
class CacheUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
public static <T> boolean eq( T s1, T s2 )
|
||||||
|
{
|
||||||
|
return s1 != null ? s1.equals( s2 ) : s2 == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int hash( Object obj )
|
||||||
|
{
|
||||||
|
return obj != null ? obj.hashCode() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int repositoriesHashCode( List<RemoteRepository> repositories )
|
||||||
|
{
|
||||||
|
int result = 17;
|
||||||
|
for ( RemoteRepository repository : repositories )
|
||||||
|
{
|
||||||
|
result = 31 * result + repositoryHashCode( repository );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int repositoryHashCode( RemoteRepository repository )
|
||||||
|
{
|
||||||
|
int result = 17;
|
||||||
|
result = 31 * result + hash( repository.getUrl() );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean repositoryEquals( RemoteRepository r1, RemoteRepository r2 )
|
||||||
|
{
|
||||||
|
if ( r1 == r2 )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return eq( r1.getId(), r2.getId() ) && eq( r1.getUrl(), r2.getUrl() )
|
||||||
|
&& policyEquals( r1.getPolicy( false ), r2.getPolicy( false ) )
|
||||||
|
&& policyEquals( r1.getPolicy( true ), r2.getPolicy( true ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean policyEquals( RepositoryPolicy p1, RepositoryPolicy p2 )
|
||||||
|
{
|
||||||
|
if ( p1 == p2 )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// update policy doesn't affect contents
|
||||||
|
return p1.isEnabled() == p2.isEnabled() && eq( p1.getChecksumPolicy(), p2.getChecksumPolicy() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean repositoriesEquals( List<RemoteRepository> r1, List<RemoteRepository> r2 )
|
||||||
|
{
|
||||||
|
if ( r1.size() != r2.size() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( Iterator<RemoteRepository> it1 = r1.iterator(), it2 = r2.iterator(); it1.hasNext(); )
|
||||||
|
{
|
||||||
|
if ( !repositoryEquals( it1.next(), it2.next() ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int pluginHashCode( Plugin plugin )
|
||||||
|
{
|
||||||
|
int hash = 17;
|
||||||
|
|
||||||
|
hash = hash * 31 + hash( plugin.getGroupId() );
|
||||||
|
hash = hash * 31 + hash( plugin.getArtifactId() );
|
||||||
|
hash = hash * 31 + hash( plugin.getVersion() );
|
||||||
|
|
||||||
|
hash = hash * 31 + ( plugin.isExtensions() ? 1 : 0 );
|
||||||
|
|
||||||
|
for ( Dependency dependency : plugin.getDependencies() )
|
||||||
|
{
|
||||||
|
hash = hash * 31 + hash( dependency.getGroupId() );
|
||||||
|
hash = hash * 31 + hash( dependency.getArtifactId() );
|
||||||
|
hash = hash * 31 + hash( dependency.getVersion() );
|
||||||
|
hash = hash * 31 + hash( dependency.getType() );
|
||||||
|
hash = hash * 31 + hash( dependency.getClassifier() );
|
||||||
|
hash = hash * 31 + hash( dependency.getScope() );
|
||||||
|
|
||||||
|
for ( Exclusion exclusion : dependency.getExclusions() )
|
||||||
|
{
|
||||||
|
hash = hash * 31 + hash( exclusion.getGroupId() );
|
||||||
|
hash = hash * 31 + hash( exclusion.getArtifactId() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean pluginEquals( Plugin a, Plugin b )
|
||||||
|
{
|
||||||
|
return eq( a.getArtifactId(), b.getArtifactId() ) //
|
||||||
|
&& eq( a.getGroupId(), b.getGroupId() ) //
|
||||||
|
&& eq( a.getVersion(), b.getVersion() ) //
|
||||||
|
&& a.isExtensions() == b.isExtensions() //
|
||||||
|
&& dependenciesEquals( a.getDependencies(), b.getDependencies() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean dependenciesEquals( List<Dependency> a, List<Dependency> b )
|
||||||
|
{
|
||||||
|
if ( a.size() != b.size() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<Dependency> aI = a.iterator();
|
||||||
|
Iterator<Dependency> bI = b.iterator();
|
||||||
|
|
||||||
|
while ( aI.hasNext() )
|
||||||
|
{
|
||||||
|
Dependency aD = aI.next();
|
||||||
|
Dependency bD = bI.next();
|
||||||
|
|
||||||
|
boolean r = eq( aD.getGroupId(), bD.getGroupId() ) //
|
||||||
|
&& eq( aD.getArtifactId(), bD.getArtifactId() ) //
|
||||||
|
&& eq( aD.getVersion(), bD.getVersion() ) //
|
||||||
|
&& eq( aD.getType(), bD.getType() ) //
|
||||||
|
&& eq( aD.getClassifier(), bD.getClassifier() ) //
|
||||||
|
&& eq( aD.getScope(), bD.getScope() );
|
||||||
|
|
||||||
|
r &= exclusionsEquals( aD.getExclusions(), bD.getExclusions() );
|
||||||
|
|
||||||
|
if ( !r )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean exclusionsEquals( List<Exclusion> a, List<Exclusion> b )
|
||||||
|
{
|
||||||
|
if ( a.size() != b.size() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterator<Exclusion> aI = a.iterator();
|
||||||
|
Iterator<Exclusion> bI = b.iterator();
|
||||||
|
|
||||||
|
while ( aI.hasNext() )
|
||||||
|
{
|
||||||
|
Exclusion aD = aI.next();
|
||||||
|
Exclusion bD = bI.next();
|
||||||
|
|
||||||
|
boolean r = eq( aD.getGroupId(), bD.getGroupId() ) //
|
||||||
|
&& eq( aD.getArtifactId(), bD.getArtifactId() );
|
||||||
|
|
||||||
|
if ( !r )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WorkspaceRepository getWorkspace( RepositorySystemSession session )
|
||||||
|
{
|
||||||
|
WorkspaceReader reader = session.getWorkspaceReader();
|
||||||
|
return ( reader != null ) ? reader.getRepository() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,28 +1,24 @@
|
||||||
package org.apache.maven.plugin;
|
package org.apache.maven.plugin;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* agreements. See the NOTICE file distributed with this work for additional information regarding
|
||||||
* distributed with this work for additional information
|
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
* "License"); you may not use this file except in compliance with the License. You may obtain a
|
||||||
* to you under the Apache License, Version 2.0 (the
|
* copy of the License at
|
||||||
* "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
|
||||||
*
|
*
|
||||||
* 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
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* or implied. See the License for the specific language governing permissions and limitations under
|
||||||
* software distributed under the License is distributed on an
|
* the License.
|
||||||
* "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.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
|
@ -32,11 +28,13 @@ import org.codehaus.plexus.PlexusContainer;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
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;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
// TODO: the antrun plugin has its own configurator, the only plugin that does. might need to think about how that works
|
// TODO: the antrun plugin has its own configurator, the only plugin that does. might need to think about how that works
|
||||||
// TODO: remove the coreArtifactFilterManager
|
// TODO: remove the coreArtifactFilterManager
|
||||||
|
|
||||||
@Component( role = BuildPluginManager.class )
|
@Component(role = BuildPluginManager.class)
|
||||||
public class DefaultBuildPluginManager
|
public class DefaultBuildPluginManager
|
||||||
implements BuildPluginManager
|
implements BuildPluginManager
|
||||||
{
|
{
|
||||||
|
@ -51,19 +49,18 @@ public class DefaultBuildPluginManager
|
||||||
private LegacySupport legacySupport;
|
private LegacySupport legacySupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param plugin
|
* @param plugin
|
||||||
* @param repositoryRequest
|
* @param repositoryRequest
|
||||||
* @return PluginDescriptor The component descriptor for the Maven plugin.
|
* @return PluginDescriptor The component descriptor for the Maven plugin.
|
||||||
* @throws PluginNotFoundException The plugin could not be found in any repositories.
|
* @throws PluginNotFoundException The plugin could not be found in any repositories.
|
||||||
* @throws PluginResolutionException The plugin could be found but could not be resolved.
|
* @throws PluginResolutionException The plugin could be found but could not be resolved.
|
||||||
* @throws InvalidPluginDescriptorException
|
* @throws InvalidPluginDescriptorException
|
||||||
*/
|
*/
|
||||||
public PluginDescriptor loadPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
|
public PluginDescriptor loadPlugin( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException
|
||||||
InvalidPluginDescriptorException
|
|
||||||
{
|
{
|
||||||
return mavenPluginManager.getPluginDescriptor( plugin, repositoryRequest );
|
return mavenPluginManager.getPluginDescriptor( plugin, repositories, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
@ -175,9 +172,9 @@ public class DefaultBuildPluginManager
|
||||||
/**
|
/**
|
||||||
* TODO pluginDescriptor classRealm and artifacts are set as a side effect of this
|
* TODO pluginDescriptor classRealm and artifacts are set as a side effect of this
|
||||||
* call, which is not nice.
|
* call, which is not nice.
|
||||||
* @throws PluginResolutionException
|
* @throws PluginResolutionException
|
||||||
*/
|
*/
|
||||||
public ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor )
|
public ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor )
|
||||||
throws PluginResolutionException, PluginManagerException
|
throws PluginResolutionException, PluginManagerException
|
||||||
{
|
{
|
||||||
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
|
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
|
||||||
|
@ -192,11 +189,12 @@ public class DefaultBuildPluginManager
|
||||||
return pluginDescriptor.getClassRealm();
|
return pluginDescriptor.getClassRealm();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
|
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories,
|
||||||
|
RepositorySystemSession session )
|
||||||
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
||||||
MojoNotFoundException, InvalidPluginDescriptorException
|
MojoNotFoundException, InvalidPluginDescriptorException
|
||||||
{
|
{
|
||||||
return mavenPluginManager.getMojoDescriptor( plugin, goal, repositoryRequest );
|
return mavenPluginManager.getMojoDescriptor( plugin, goal, repositories, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,11 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.project.ExtensionDescriptor;
|
import org.apache.maven.project.ExtensionDescriptor;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default extension realm cache implementation. Assumes cached data does not change.
|
* Default extension realm cache implementation. Assumes cached data does not change.
|
||||||
|
|
|
@ -22,19 +22,18 @@ package org.apache.maven.plugin;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
|
||||||
import org.apache.maven.model.Dependency;
|
|
||||||
import org.apache.maven.model.Exclusion;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Igor Fedorenko
|
* @author Igor Fedorenko
|
||||||
|
@ -46,36 +45,67 @@ public class DefaultPluginArtifactsCache
|
||||||
{
|
{
|
||||||
|
|
||||||
private static class CacheKey
|
private static class CacheKey
|
||||||
|
implements Key
|
||||||
{
|
{
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
private final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
|
private final WorkspaceRepository workspace;
|
||||||
|
|
||||||
private final ArtifactFilter extensionArtifactFilter;
|
private final LocalRepository localRepo;
|
||||||
|
|
||||||
|
private final List<RemoteRepository> repositories;
|
||||||
|
|
||||||
|
private final DependencyFilter filter;
|
||||||
|
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
public CacheKey( Plugin plugin, RepositoryRequest repositoryRequest, ArtifactFilter extensionArtifactFilter )
|
public CacheKey( Plugin plugin, DependencyFilter extensionFilter, List<RemoteRepository> repositories,
|
||||||
|
RepositorySystemSession session )
|
||||||
{
|
{
|
||||||
this.plugin = plugin.clone();
|
this.plugin = plugin.clone();
|
||||||
this.repositories.add( repositoryRequest.getLocalRepository() );
|
workspace = CacheUtils.getWorkspace( session );
|
||||||
this.repositories.addAll( repositoryRequest.getRemoteRepositories() );
|
this.localRepo = session.getLocalRepository();
|
||||||
this.extensionArtifactFilter = extensionArtifactFilter;
|
this.repositories = new ArrayList<RemoteRepository>( repositories.size() );
|
||||||
|
for ( RemoteRepository repository : repositories )
|
||||||
|
{
|
||||||
|
if ( repository.isRepositoryManager() )
|
||||||
|
{
|
||||||
|
this.repositories.addAll( repository.getMirroredRepositories() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.repositories.add( repository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.filter = extensionFilter;
|
||||||
|
|
||||||
int hash = 17;
|
int hash = 17;
|
||||||
hash = hash * 31 + pluginHashCode( plugin );
|
hash = hash * 31 + CacheUtils.pluginHashCode( plugin );
|
||||||
hash = hash * 31 + repositories.hashCode();
|
hash = hash * 31 + hash( workspace );
|
||||||
hash = hash * 31 + ( extensionArtifactFilter != null ? extensionArtifactFilter.hashCode() : 0 );
|
hash = hash * 31 + hash( localRepo );
|
||||||
|
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
|
||||||
|
hash = hash * 31 + hash( extensionFilter );
|
||||||
this.hashCode = hash;
|
this.hashCode = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return plugin.getId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int hash( Object obj )
|
||||||
|
{
|
||||||
|
return obj != null ? obj.hashCode() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals( Object o )
|
public boolean equals( Object o )
|
||||||
{
|
{
|
||||||
|
@ -89,34 +119,43 @@ public class DefaultPluginArtifactsCache
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheKey other = (CacheKey) o;
|
CacheKey that = (CacheKey) o;
|
||||||
|
|
||||||
return pluginEquals( plugin, other.plugin ) && eq( repositories, other.repositories )
|
return CacheUtils.pluginEquals( plugin, that.plugin ) && eq( workspace, that.workspace )
|
||||||
&& eq( extensionArtifactFilter, other.extensionArtifactFilter );
|
&& eq( localRepo, that.localRepo ) && CacheUtils.repositoriesEquals( repositories, that.repositories )
|
||||||
|
&& eq( filter, that.filter );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> boolean eq( T s1, T s2 )
|
||||||
|
{
|
||||||
|
return s1 != null ? s1.equals( s2 ) : s2 == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Map<CacheKey, CacheRecord> cache = new HashMap<CacheKey, CacheRecord>();
|
protected final Map<Key, CacheRecord> cache = new HashMap<Key, CacheRecord>();
|
||||||
|
|
||||||
public CacheRecord get( Plugin plugin, RepositoryRequest repositoryRequest, ArtifactFilter extensionArtifactFilter )
|
public Key createKey( Plugin plugin, DependencyFilter extensionFilter, List<RemoteRepository> repositories,
|
||||||
|
RepositorySystemSession session )
|
||||||
{
|
{
|
||||||
return cache.get( new CacheKey( plugin, repositoryRequest, extensionArtifactFilter ) );
|
return new CacheKey( plugin, extensionFilter, repositories, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheRecord put( Plugin plugin, RepositoryRequest repositoryRequest, ArtifactFilter extensionArtifactFilter,
|
public CacheRecord get( Key key )
|
||||||
List<Artifact> pluginArtifacts )
|
{
|
||||||
|
return cache.get( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheRecord put( Key key, List<Artifact> pluginArtifacts )
|
||||||
{
|
{
|
||||||
if ( pluginArtifacts == null )
|
if ( pluginArtifacts == null )
|
||||||
{
|
{
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheKey key = new CacheKey( plugin, repositoryRequest, extensionArtifactFilter );
|
|
||||||
|
|
||||||
if ( cache.containsKey( key ) )
|
if ( cache.containsKey( key ) )
|
||||||
{
|
{
|
||||||
throw new IllegalStateException( "Duplicate artifact resolution result for plugin " + plugin.getId() );
|
throw new IllegalStateException( "Duplicate artifact resolution result for plugin " + key );
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheRecord record =
|
CacheRecord record =
|
||||||
|
@ -134,102 +173,12 @@ public class DefaultPluginArtifactsCache
|
||||||
|
|
||||||
protected static int pluginHashCode( Plugin plugin )
|
protected static int pluginHashCode( Plugin plugin )
|
||||||
{
|
{
|
||||||
int hash = 17;
|
return CacheUtils.pluginHashCode( plugin );
|
||||||
|
|
||||||
hash = hash * 31 + plugin.getGroupId().hashCode();
|
|
||||||
hash = hash * 31 + plugin.getArtifactId().hashCode();
|
|
||||||
hash = hash * 31 + plugin.getVersion().hashCode();
|
|
||||||
|
|
||||||
for ( Dependency dependency : plugin.getDependencies() )
|
|
||||||
{
|
|
||||||
hash = hash * 31 + dependency.getGroupId().hashCode();
|
|
||||||
hash = hash * 31 + dependency.getArtifactId().hashCode();
|
|
||||||
hash = hash * 31 + dependency.getVersion().hashCode();
|
|
||||||
hash = hash * 31 + dependency.getType().hashCode();
|
|
||||||
hash = hash * 31 + ( dependency.getClassifier() != null ? dependency.getClassifier().hashCode() : 0 );
|
|
||||||
hash = hash * 31 + ( dependency.getScope() != null ? dependency.getScope().hashCode() : 0 );
|
|
||||||
|
|
||||||
for ( Exclusion exclusion : dependency.getExclusions() )
|
|
||||||
{
|
|
||||||
hash = hash * 31 + exclusion.getGroupId().hashCode();
|
|
||||||
hash = hash * 31 + exclusion.getArtifactId().hashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean pluginEquals( Plugin a, Plugin b )
|
protected static boolean pluginEquals( Plugin a, Plugin b )
|
||||||
{
|
{
|
||||||
return eq( a.getGroupId(), b.getGroupId() ) //
|
return CacheUtils.pluginEquals( a, b );
|
||||||
&& eq( a.getArtifactId(), b.getArtifactId() ) //
|
|
||||||
&& eq( a.getVersion(), b.getVersion() ) //
|
|
||||||
&& dependenciesEquals( a.getDependencies(), b.getDependencies() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean dependenciesEquals( List<Dependency> a, List<Dependency> b )
|
|
||||||
{
|
|
||||||
if ( a.size() != b.size() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<Dependency> aI = a.iterator();
|
|
||||||
Iterator<Dependency> bI = b.iterator();
|
|
||||||
|
|
||||||
while ( aI.hasNext() )
|
|
||||||
{
|
|
||||||
Dependency aD = aI.next();
|
|
||||||
Dependency bD = bI.next();
|
|
||||||
|
|
||||||
boolean r = eq( aD.getGroupId(), bD.getGroupId() ) //
|
|
||||||
&& eq( aD.getArtifactId(), bD.getArtifactId() ) //
|
|
||||||
&& eq( aD.getVersion(), bD.getVersion() ) //
|
|
||||||
&& eq( aD.getType(), bD.getType() ) //
|
|
||||||
&& eq( aD.getClassifier(), bD.getClassifier() ) //
|
|
||||||
&& eq( aD.getScope(), bD.getScope() );
|
|
||||||
|
|
||||||
r &= exclusionsEquals( aD.getExclusions(), bD.getExclusions() );
|
|
||||||
|
|
||||||
if ( !r )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean exclusionsEquals( List<Exclusion> a, List<Exclusion> b )
|
|
||||||
{
|
|
||||||
if ( a.size() != b.size() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<Exclusion> aI = a.iterator();
|
|
||||||
Iterator<Exclusion> bI = b.iterator();
|
|
||||||
|
|
||||||
while ( aI.hasNext() )
|
|
||||||
{
|
|
||||||
Exclusion aD = aI.next();
|
|
||||||
Exclusion bD = bI.next();
|
|
||||||
|
|
||||||
boolean r = eq( aD.getGroupId(), bD.getGroupId() ) //
|
|
||||||
&& eq( aD.getArtifactId(), bD.getArtifactId() );
|
|
||||||
|
|
||||||
if ( !r )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> boolean eq( T s1, T s2 )
|
|
||||||
{
|
|
||||||
return s1 != null ? s1.equals( s2 ) : s2 == null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register( MavenProject project, CacheRecord record )
|
public void register( MavenProject project, CacheRecord record )
|
||||||
|
|
|
@ -21,19 +21,19 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
import org.apache.maven.artifact.ArtifactUtils;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.component.repository.ComponentDescriptor;
|
import org.codehaus.plexus.component.repository.ComponentDescriptor;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches raw plugin descriptors. A raw plugin descriptor is a descriptor that has just been extracted from the plugin
|
* Caches raw plugin descriptors. A raw plugin descriptor is a descriptor that has just been extracted from the plugin
|
||||||
|
@ -57,14 +57,9 @@ public class DefaultPluginDescriptorCache
|
||||||
descriptors.clear();
|
descriptors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Key createKey( Plugin plugin, RepositoryRequest repositoryRequest )
|
public Key createKey( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
{
|
{
|
||||||
return new CacheKey( plugin, repositoryRequest );
|
return new CacheKey( plugin, repositories, session );
|
||||||
}
|
|
||||||
|
|
||||||
public void put( Key cacheKey, PluginDescriptor pluginDescriptor )
|
|
||||||
{
|
|
||||||
descriptors.put( cacheKey, clone( pluginDescriptor ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PluginDescriptor get( Key cacheKey )
|
public PluginDescriptor get( Key cacheKey )
|
||||||
|
@ -72,6 +67,11 @@ public class DefaultPluginDescriptorCache
|
||||||
return clone( descriptors.get( cacheKey ) );
|
return clone( descriptors.get( cacheKey ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void put( Key cacheKey, PluginDescriptor pluginDescriptor )
|
||||||
|
{
|
||||||
|
descriptors.put( cacheKey, clone( pluginDescriptor ) );
|
||||||
|
}
|
||||||
|
|
||||||
private static PluginDescriptor clone( PluginDescriptor original )
|
private static PluginDescriptor clone( PluginDescriptor original )
|
||||||
{
|
{
|
||||||
PluginDescriptor clone = null;
|
PluginDescriptor clone = null;
|
||||||
|
@ -129,25 +129,42 @@ public class DefaultPluginDescriptorCache
|
||||||
|
|
||||||
private final String version;
|
private final String version;
|
||||||
|
|
||||||
private final List<ArtifactRepository> repositories;
|
private final WorkspaceRepository workspace;
|
||||||
|
|
||||||
|
private final LocalRepository localRepo;
|
||||||
|
|
||||||
|
private final List<RemoteRepository> repositories;
|
||||||
|
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
public CacheKey( Plugin plugin, RepositoryRequest repositoryRequest )
|
public CacheKey( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
{
|
{
|
||||||
groupId = plugin.getGroupId();
|
groupId = plugin.getGroupId();
|
||||||
artifactId = plugin.getArtifactId();
|
artifactId = plugin.getArtifactId();
|
||||||
version = plugin.getVersion();
|
version = plugin.getVersion();
|
||||||
|
|
||||||
repositories = new ArrayList<ArtifactRepository>( repositoryRequest.getRemoteRepositories().size() + 1 );
|
workspace = CacheUtils.getWorkspace( session );
|
||||||
repositories.add( repositoryRequest.getLocalRepository() );
|
localRepo = session.getLocalRepository();
|
||||||
repositories.addAll( repositoryRequest.getRemoteRepositories() );
|
this.repositories = new ArrayList<RemoteRepository>( repositories.size() );
|
||||||
|
for ( RemoteRepository repository : repositories )
|
||||||
|
{
|
||||||
|
if ( repository.isRepositoryManager() )
|
||||||
|
{
|
||||||
|
this.repositories.addAll( repository.getMirroredRepositories() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.repositories.add( repository );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int hash = 17;
|
int hash = 17;
|
||||||
hash = hash * 31 + groupId.hashCode();
|
hash = hash * 31 + groupId.hashCode();
|
||||||
hash = hash * 31 + artifactId.hashCode();
|
hash = hash * 31 + artifactId.hashCode();
|
||||||
hash = hash * 31 + version.hashCode();
|
hash = hash * 31 + version.hashCode();
|
||||||
hash = hash * 31 + repositoriesHashCode( repositories );
|
hash = hash * 31 + hash( workspace );
|
||||||
|
hash = hash * 31 + localRepo.hashCode();
|
||||||
|
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
|
||||||
this.hashCode = hash;
|
this.hashCode = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,8 +189,10 @@ public class DefaultPluginDescriptorCache
|
||||||
|
|
||||||
CacheKey that = (CacheKey) obj;
|
CacheKey that = (CacheKey) obj;
|
||||||
|
|
||||||
return this.artifactId.equals( that.artifactId ) && this.groupId.equals( that.groupId )
|
return eq( this.artifactId, that.artifactId ) && eq( this.groupId, that.groupId )
|
||||||
&& this.version.equals( that.version ) && repositoriesEquals( this.repositories, that.repositories );
|
&& eq( this.version, that.version ) && eq( this.localRepo, that.localRepo )
|
||||||
|
&& eq( this.workspace, that.workspace )
|
||||||
|
&& CacheUtils.repositoriesEquals( this.repositories, that.repositories );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -182,61 +201,9 @@ public class DefaultPluginDescriptorCache
|
||||||
return groupId + ':' + artifactId + ':' + version;
|
return groupId + ':' + artifactId + ':' + version;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int repositoryHashCode( ArtifactRepository repository )
|
private static int hash( Object obj )
|
||||||
{
|
{
|
||||||
int result = 17;
|
return obj != null ? obj.hashCode() : 0;
|
||||||
result = 31 * result + ( repository.getId() != null ? repository.getId().hashCode() : 0 );
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int repositoriesHashCode( List<ArtifactRepository> repositories )
|
|
||||||
{
|
|
||||||
int result = 17;
|
|
||||||
for ( ArtifactRepository repository : repositories )
|
|
||||||
{
|
|
||||||
result = 31 * result + repositoryHashCode( repository );
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean repositoryEquals( ArtifactRepository r1, ArtifactRepository r2 )
|
|
||||||
{
|
|
||||||
if ( r1 == r2 )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return eq( r1.getId(), r2.getId() ) && eq( r1.getUrl(), r2.getUrl() )
|
|
||||||
&& repositoryPolicyEquals( r1.getReleases(), r2.getReleases() )
|
|
||||||
&& repositoryPolicyEquals( r1.getSnapshots(), r2.getSnapshots() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean repositoryPolicyEquals( ArtifactRepositoryPolicy p1, ArtifactRepositoryPolicy p2 )
|
|
||||||
{
|
|
||||||
if ( p1 == p2 )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return p1.isEnabled() == p2.isEnabled() && eq( p1.getUpdatePolicy(), p2.getUpdatePolicy() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean repositoriesEquals( List<ArtifactRepository> r1, List<ArtifactRepository> r2 )
|
|
||||||
{
|
|
||||||
if ( r1.size() != r2.size() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( Iterator<ArtifactRepository> it1 = r1.iterator(), it2 = r2.iterator(); it1.hasNext(); )
|
|
||||||
{
|
|
||||||
if ( !repositoryEquals( it1.next(), it2.next() ) )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> boolean eq( T s1, T s2 )
|
private static <T> boolean eq( T s1, T s2 )
|
||||||
|
|
|
@ -21,20 +21,20 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
|
||||||
import org.apache.maven.model.Dependency;
|
|
||||||
import org.apache.maven.model.Exclusion;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.WorkspaceRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default PluginCache implementation. Assumes cached data does not change.
|
* Default PluginCache implementation. Assumes cached data does not change.
|
||||||
|
@ -45,45 +45,76 @@ public class DefaultPluginRealmCache
|
||||||
{
|
{
|
||||||
|
|
||||||
protected static class CacheKey
|
protected static class CacheKey
|
||||||
|
implements Key
|
||||||
{
|
{
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
private final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
|
private final WorkspaceRepository workspace;
|
||||||
|
|
||||||
|
private final LocalRepository localRepo;
|
||||||
|
|
||||||
|
private final List<RemoteRepository> repositories;
|
||||||
|
|
||||||
private final ClassLoader parentRealm;
|
private final ClassLoader parentRealm;
|
||||||
|
|
||||||
private final List<String> parentImports;
|
private final List<String> parentImports;
|
||||||
|
|
||||||
private final ArtifactFilter filter;
|
private final DependencyFilter filter;
|
||||||
|
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
public CacheKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
public CacheKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
||||||
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
|
DependencyFilter dependencyFilter, List<RemoteRepository> repositories,
|
||||||
List<ArtifactRepository> remoteRepositories )
|
RepositorySystemSession session )
|
||||||
{
|
{
|
||||||
this.plugin = plugin.clone();
|
this.plugin = plugin.clone();
|
||||||
this.repositories.add( localRepository );
|
this.workspace = CacheUtils.getWorkspace( session );
|
||||||
this.repositories.addAll( remoteRepositories );
|
this.localRepo = session.getLocalRepository();
|
||||||
|
this.repositories = new ArrayList<RemoteRepository>( repositories.size() );
|
||||||
|
for ( RemoteRepository repository : repositories )
|
||||||
|
{
|
||||||
|
if ( repository.isRepositoryManager() )
|
||||||
|
{
|
||||||
|
this.repositories.addAll( repository.getMirroredRepositories() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.repositories.add( repository );
|
||||||
|
}
|
||||||
|
}
|
||||||
this.parentRealm = parentRealm;
|
this.parentRealm = parentRealm;
|
||||||
this.parentImports = ( parentImports != null ) ? parentImports : Collections.<String> emptyList();
|
this.parentImports = ( parentImports != null ) ? parentImports : Collections.<String> emptyList();
|
||||||
this.filter = dependencyFilter;
|
this.filter = dependencyFilter;
|
||||||
|
|
||||||
int hash = 17;
|
int hash = 17;
|
||||||
hash = hash * 31 + pluginHashCode( plugin );
|
hash = hash * 31 + CacheUtils.pluginHashCode( plugin );
|
||||||
hash = hash * 31 + repositories.hashCode();
|
hash = hash * 31 + hash( workspace );
|
||||||
hash = hash * 31 + ( parentRealm != null ? parentRealm.hashCode() : 0 );
|
hash = hash * 31 + hash( localRepo );
|
||||||
|
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
|
||||||
|
hash = hash * 31 + hash( parentRealm );
|
||||||
hash = hash * 31 + this.parentImports.hashCode();
|
hash = hash * 31 + this.parentImports.hashCode();
|
||||||
hash = hash * 31 + ( dependencyFilter != null ? dependencyFilter.hashCode() : 0 );
|
hash = hash * 31 + hash( dependencyFilter );
|
||||||
this.hashCode = hash;
|
this.hashCode = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return plugin.getId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
return hashCode;
|
return hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int hash( Object obj )
|
||||||
|
{
|
||||||
|
return obj != null ? obj.hashCode() : 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals( Object o )
|
public boolean equals( Object o )
|
||||||
{
|
{
|
||||||
|
@ -97,40 +128,45 @@ public class DefaultPluginRealmCache
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheKey other = (CacheKey) o;
|
CacheKey that = (CacheKey) o;
|
||||||
|
|
||||||
return parentRealm == other.parentRealm && pluginEquals( plugin, other.plugin )
|
return parentRealm == that.parentRealm && CacheUtils.pluginEquals( plugin, that.plugin )
|
||||||
&& eq( repositories, other.repositories ) && eq( filter, other.filter )
|
&& eq( workspace, that.workspace ) && eq( localRepo, that.localRepo )
|
||||||
&& eq( parentImports, other.parentImports );
|
&& CacheUtils.repositoriesEquals( this.repositories, that.repositories ) && eq( filter, that.filter )
|
||||||
|
&& eq( parentImports, that.parentImports );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> boolean eq( T s1, T s2 )
|
||||||
|
{
|
||||||
|
return s1 != null ? s1.equals( s2 ) : s2 == null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final Map<CacheKey, CacheRecord> cache = new ConcurrentHashMap<CacheKey, CacheRecord>();
|
protected final Map<Key, CacheRecord> cache = new ConcurrentHashMap<Key, CacheRecord>();
|
||||||
|
|
||||||
public CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
public Key createKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
||||||
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
|
DependencyFilter dependencyFilter, List<RemoteRepository> repositories,
|
||||||
List<ArtifactRepository> remoteRepositories )
|
RepositorySystemSession session )
|
||||||
{
|
{
|
||||||
return cache.get( new CacheKey( plugin, parentRealm, parentImports, dependencyFilter, localRepository,
|
return new CacheKey( plugin, parentRealm, parentImports, dependencyFilter, repositories, session );
|
||||||
remoteRepositories ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
public CacheRecord get( Key key )
|
||||||
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
|
{
|
||||||
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm,
|
return cache.get( key );
|
||||||
List<Artifact> pluginArtifacts )
|
}
|
||||||
|
|
||||||
|
public CacheRecord put( Key key, ClassRealm pluginRealm, List<Artifact> pluginArtifacts )
|
||||||
{
|
{
|
||||||
if ( pluginRealm == null || pluginArtifacts == null )
|
if ( pluginRealm == null || pluginArtifacts == null )
|
||||||
{
|
{
|
||||||
throw new NullPointerException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheKey key =
|
|
||||||
new CacheKey( plugin, parentRealm, parentImports, dependencyFilter, localRepository, remoteRepositories );
|
|
||||||
|
|
||||||
if ( cache.containsKey( key ) )
|
if ( cache.containsKey( key ) )
|
||||||
{
|
{
|
||||||
throw new IllegalStateException( "Duplicate plugin realm for plugin " + plugin.getId() );
|
throw new IllegalStateException( "Duplicate plugin realm for plugin " + key );
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheRecord record = new CacheRecord( pluginRealm, pluginArtifacts );
|
CacheRecord record = new CacheRecord( pluginRealm, pluginArtifacts );
|
||||||
|
@ -147,105 +183,12 @@ public class DefaultPluginRealmCache
|
||||||
|
|
||||||
protected static int pluginHashCode( Plugin plugin )
|
protected static int pluginHashCode( Plugin plugin )
|
||||||
{
|
{
|
||||||
int hash = 17;
|
return CacheUtils.pluginHashCode( plugin );
|
||||||
|
|
||||||
hash = hash * 31 + plugin.getGroupId().hashCode();
|
|
||||||
hash = hash * 31 + plugin.getArtifactId().hashCode();
|
|
||||||
hash = hash * 31 + plugin.getVersion().hashCode();
|
|
||||||
|
|
||||||
hash = hash * 31 + ( plugin.isExtensions() ? 1 : 0 );
|
|
||||||
|
|
||||||
for ( Dependency dependency : plugin.getDependencies() )
|
|
||||||
{
|
|
||||||
hash = hash * 31 + dependency.getGroupId().hashCode();
|
|
||||||
hash = hash * 31 + dependency.getArtifactId().hashCode();
|
|
||||||
hash = hash * 31 + dependency.getVersion().hashCode();
|
|
||||||
hash = hash * 31 + dependency.getType().hashCode();
|
|
||||||
hash = hash * 31 + ( dependency.getClassifier() != null ? dependency.getClassifier().hashCode() : 0 );
|
|
||||||
hash = hash * 31 + ( dependency.getScope() != null ? dependency.getScope().hashCode() : 0 );
|
|
||||||
|
|
||||||
for ( Exclusion exclusion : dependency.getExclusions() )
|
|
||||||
{
|
|
||||||
hash = hash * 31 + exclusion.getGroupId().hashCode();
|
|
||||||
hash = hash * 31 + exclusion.getArtifactId().hashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean pluginEquals( Plugin a, Plugin b )
|
protected static boolean pluginEquals( Plugin a, Plugin b )
|
||||||
{
|
{
|
||||||
return eq( a.getGroupId(), b.getGroupId() ) //
|
return CacheUtils.pluginEquals( a, b );
|
||||||
&& eq( a.getArtifactId(), b.getArtifactId() ) //
|
|
||||||
&& eq( a.getVersion(), b.getVersion() ) //
|
|
||||||
&& a.isExtensions() == b.isExtensions() //
|
|
||||||
&& dependenciesEquals( a.getDependencies(), b.getDependencies() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean dependenciesEquals( List<Dependency> a, List<Dependency> b )
|
|
||||||
{
|
|
||||||
if ( a.size() != b.size() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<Dependency> aI = a.iterator();
|
|
||||||
Iterator<Dependency> bI = b.iterator();
|
|
||||||
|
|
||||||
while ( aI.hasNext() )
|
|
||||||
{
|
|
||||||
Dependency aD = aI.next();
|
|
||||||
Dependency bD = bI.next();
|
|
||||||
|
|
||||||
boolean r = eq( aD.getGroupId(), bD.getGroupId() ) //
|
|
||||||
&& eq( aD.getArtifactId(), bD.getArtifactId() ) //
|
|
||||||
&& eq( aD.getVersion(), bD.getVersion() ) //
|
|
||||||
&& eq( aD.getType(), bD.getType() ) //
|
|
||||||
&& eq( aD.getClassifier(), bD.getClassifier() ) //
|
|
||||||
&& eq( aD.getScope(), bD.getScope() );
|
|
||||||
|
|
||||||
r &= exclusionsEquals( aD.getExclusions(), bD.getExclusions() );
|
|
||||||
|
|
||||||
if ( !r )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean exclusionsEquals( List<Exclusion> a, List<Exclusion> b )
|
|
||||||
{
|
|
||||||
if ( a.size() != b.size() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<Exclusion> aI = a.iterator();
|
|
||||||
Iterator<Exclusion> bI = b.iterator();
|
|
||||||
|
|
||||||
while ( aI.hasNext() )
|
|
||||||
{
|
|
||||||
Exclusion aD = aI.next();
|
|
||||||
Exclusion bD = bI.next();
|
|
||||||
|
|
||||||
boolean r = eq( aD.getGroupId(), bD.getGroupId() ) //
|
|
||||||
&& eq( aD.getArtifactId(), bD.getArtifactId() );
|
|
||||||
|
|
||||||
if ( !r )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> boolean eq( T s1, T s2 )
|
|
||||||
{
|
|
||||||
return s1 != null ? s1.equals( s2 ) : s2 == null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register( MavenProject project, CacheRecord record )
|
public void register( MavenProject project, CacheRecord record )
|
||||||
|
|
|
@ -21,10 +21,10 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.project.ExtensionDescriptor;
|
import org.apache.maven.project.ExtensionDescriptor;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches extension class realms. <strong>Warning:</strong> This is an internal utility interface that is only public
|
* Caches extension class realms. <strong>Warning:</strong> This is an internal utility interface that is only public
|
||||||
|
|
|
@ -24,12 +24,10 @@ import java.util.List;
|
||||||
public class InvalidPluginDescriptorException
|
public class InvalidPluginDescriptorException
|
||||||
extends Exception
|
extends Exception
|
||||||
{
|
{
|
||||||
private List<String> errors;
|
|
||||||
|
|
||||||
public InvalidPluginDescriptorException( String message, List<String> errors )
|
public InvalidPluginDescriptorException( String message, List<String> errors )
|
||||||
{
|
{
|
||||||
super( toMessage( message, errors ) );
|
super( toMessage( message, errors ) );
|
||||||
this.errors = errors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toMessage( String message, List<String> errors )
|
private static String toMessage( String message, List<String> errors )
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.maven.plugin;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps to provide backward-compatibility with plugins that use legacy components. <strong>Warning:</strong> This is an
|
* Helps to provide backward-compatibility with plugins that use legacy components. <strong>Warning:</strong> This is an
|
||||||
|
@ -48,4 +49,11 @@ public interface LegacySupport
|
||||||
*/
|
*/
|
||||||
MavenSession getSession();
|
MavenSession getSession();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the currently active repository session.
|
||||||
|
*
|
||||||
|
* @return The currently active repository session or {@code null} if none.
|
||||||
|
*/
|
||||||
|
RepositorySystemSession getRepositorySession();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,13 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such
|
* Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such
|
||||||
|
@ -43,11 +44,12 @@ public interface MavenPluginManager
|
||||||
* Retrieves the descriptor for the specified plugin from its main artifact.
|
* Retrieves the descriptor for the specified plugin from its main artifact.
|
||||||
*
|
*
|
||||||
* @param plugin The plugin whose descriptor should be retrieved, must not be {@code null}.
|
* @param plugin The plugin whose descriptor should be retrieved, must not be {@code null}.
|
||||||
* @param repositoryRequest The repository request to use for resolving the plugin's main artifact, must not be
|
* @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
|
||||||
* {@code null}.
|
* null}.
|
||||||
|
* @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
|
||||||
* @return The plugin descriptor, never {@code null}.
|
* @return The plugin descriptor, never {@code null}.
|
||||||
*/
|
*/
|
||||||
PluginDescriptor getPluginDescriptor( Plugin plugin, RepositoryRequest repositoryRequest )
|
PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException;
|
throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,11 +57,13 @@ public interface MavenPluginManager
|
||||||
*
|
*
|
||||||
* @param plugin The plugin whose mojo descriptor should be retrieved, must not be {@code null}.
|
* @param plugin The plugin whose mojo descriptor should be retrieved, must not be {@code null}.
|
||||||
* @param goal The simple name of the mojo whose descriptor should be retrieved, must not be {@code null}.
|
* @param goal The simple name of the mojo whose descriptor should be retrieved, must not be {@code null}.
|
||||||
* @param repositoryRequest The repository request to use for resolving the plugin's main artifact, must not be
|
* @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
|
||||||
* {@code null}.
|
* null}.
|
||||||
|
* @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
|
||||||
* @return The mojo descriptor, never {@code null}.
|
* @return The mojo descriptor, never {@code null}.
|
||||||
*/
|
*/
|
||||||
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
|
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories,
|
||||||
|
RepositorySystemSession session )
|
||||||
throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
||||||
InvalidPluginDescriptorException;
|
InvalidPluginDescriptorException;
|
||||||
|
|
||||||
|
@ -76,7 +80,7 @@ public interface MavenPluginManager
|
||||||
* @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
|
* @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
|
||||||
*/
|
*/
|
||||||
void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
|
void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
|
||||||
List<String> imports, ArtifactFilter filter )
|
List<String> imports, DependencyFilter filter )
|
||||||
throws PluginResolutionException, PluginContainerException;
|
throws PluginResolutionException, PluginContainerException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,11 +21,12 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches plugin artifacts. <strong>Warning:</strong> This is an internal utility interface that is only public for
|
* Caches plugin artifacts. <strong>Warning:</strong> This is an internal utility interface that is only public for
|
||||||
|
@ -38,6 +39,14 @@ import org.apache.maven.project.MavenProject;
|
||||||
public interface PluginArtifactsCache
|
public interface PluginArtifactsCache
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A cache key.
|
||||||
|
*/
|
||||||
|
interface Key
|
||||||
|
{
|
||||||
|
// marker interface for cache keys
|
||||||
|
}
|
||||||
|
|
||||||
public static class CacheRecord
|
public static class CacheRecord
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -50,10 +59,12 @@ public interface PluginArtifactsCache
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheRecord get( Plugin plugin, RepositoryRequest repositoryRequest, ArtifactFilter extensionArtifactFilter );
|
Key createKey( Plugin plugin, DependencyFilter extensionFilter, List<RemoteRepository> repositories,
|
||||||
|
RepositorySystemSession session );
|
||||||
|
|
||||||
CacheRecord put( Plugin plugin, RepositoryRequest repositoryRequest, ArtifactFilter extensionArtifactFilter,
|
CacheRecord get( Key key );
|
||||||
List<Artifact> pluginArtifacts );
|
|
||||||
|
CacheRecord put( Key key, List<Artifact> pluginArtifacts );
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,12 @@ package org.apache.maven.plugin;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches raw plugin descriptors. A raw plugin descriptor is a descriptor that has just been extracted from the plugin
|
* Caches raw plugin descriptors. A raw plugin descriptor is a descriptor that has just been extracted from the plugin
|
||||||
|
@ -44,11 +47,11 @@ public interface PluginDescriptorCache
|
||||||
// marker interface for cache keys
|
// marker interface for cache keys
|
||||||
}
|
}
|
||||||
|
|
||||||
Key createKey( Plugin plugin, RepositoryRequest repositoryRequest );
|
Key createKey( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session );
|
||||||
|
|
||||||
void put( Key cacheKey, PluginDescriptor pluginDescriptor );
|
void put( Key key, PluginDescriptor pluginDescriptor );
|
||||||
|
|
||||||
PluginDescriptor get( Key cacheKey );
|
PluginDescriptor get( Key key );
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,9 @@ public class PluginDescriptorParsingException
|
||||||
extends Exception
|
extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
private Plugin plugin;
|
|
||||||
|
|
||||||
public PluginDescriptorParsingException( Plugin plugin, String descriptorLocation, Throwable e )
|
public PluginDescriptorParsingException( Plugin plugin, String descriptorLocation, Throwable e )
|
||||||
{
|
{
|
||||||
super( createMessage( plugin, descriptorLocation, e ), e );
|
super( createMessage( plugin, descriptorLocation, e ), e );
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String createMessage( Plugin plugin, String descriptorLocation, Throwable e )
|
private static String createMessage( Plugin plugin, String descriptorLocation, Throwable e )
|
||||||
|
|
|
@ -229,6 +229,10 @@ public class PluginParameterExpressionEvaluator
|
||||||
e );
|
e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if ( expression.equals( "repositorySystemSession" ) )
|
||||||
|
{
|
||||||
|
value = session.getRepositorySession();
|
||||||
|
}
|
||||||
else if ( expression.equals( "mojo" ) )
|
else if ( expression.equals( "mojo" ) )
|
||||||
{
|
{
|
||||||
value = mojoExecution;
|
value = mojoExecution;
|
||||||
|
|
|
@ -22,17 +22,18 @@ package org.apache.maven.plugin;
|
||||||
import java.util.List;
|
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.resolver.filter.ArtifactFilter;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches plugin class realms. <strong>Warning:</strong> This is an internal utility interface that is only public for
|
* Caches plugin class realms. <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
|
* technical reasons, it is not part of the public API. In particular, this interface can be changed or deleted without
|
||||||
* prior notice.
|
* prior notice.
|
||||||
*
|
*
|
||||||
* @author Igor Fedorenko
|
* @author Igor Fedorenko
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +43,7 @@ public interface PluginRealmCache
|
||||||
public static class CacheRecord
|
public static class CacheRecord
|
||||||
{
|
{
|
||||||
public final ClassRealm realm;
|
public final ClassRealm realm;
|
||||||
|
|
||||||
public final List<Artifact> artifacts;
|
public final List<Artifact> artifacts;
|
||||||
|
|
||||||
public CacheRecord( ClassRealm realm, List<Artifact> artifacts )
|
public CacheRecord( ClassRealm realm, List<Artifact> artifacts )
|
||||||
|
@ -51,14 +53,20 @@ public interface PluginRealmCache
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
/**
|
||||||
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
|
* A cache key.
|
||||||
List<ArtifactRepository> remoteRepositories );
|
*/
|
||||||
|
interface Key
|
||||||
|
{
|
||||||
|
// marker interface for cache keys
|
||||||
|
}
|
||||||
|
|
||||||
CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
Key createKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
|
||||||
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
|
DependencyFilter dependencyFilter, List<RemoteRepository> repositories, RepositorySystemSession session );
|
||||||
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm,
|
|
||||||
List<Artifact> pluginArtifacts );
|
CacheRecord get( Key key );
|
||||||
|
|
||||||
|
CacheRecord put( Key key, ClassRealm pluginRealm, List<Artifact> pluginArtifacts );
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
|
@ -66,7 +74,7 @@ public interface PluginRealmCache
|
||||||
* Registers the specified cache record for usage with the given project. Integrators can use the information
|
* Registers the specified cache record for usage with the given project. Integrators can use the information
|
||||||
* collected from this method in combination with a custom cache implementation to dispose unused records from the
|
* collected from this method in combination with a custom cache implementation to dispose unused records from the
|
||||||
* cache.
|
* cache.
|
||||||
*
|
*
|
||||||
* @param project The project that employs the plugin realm, must not be {@code null}.
|
* @param project The project that employs the plugin realm, must not be {@code null}.
|
||||||
* @param record The cache record being used for the project, must not be {@code null}.
|
* @param record The cache record being used for the project, must not be {@code null}.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,8 +19,6 @@ package org.apache.maven.plugin;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,15 +28,15 @@ import org.apache.maven.model.Plugin;
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class PluginResolutionException
|
public class PluginResolutionException
|
||||||
extends AbstractArtifactResolutionException
|
extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
private final Plugin plugin;
|
private final Plugin plugin;
|
||||||
|
|
||||||
public PluginResolutionException( Plugin plugin, ArtifactResolutionException e )
|
public PluginResolutionException( Plugin plugin, Throwable cause )
|
||||||
{
|
{
|
||||||
super( "Plugin " + plugin.getId() + " or one of its dependencies could not be resolved: " + e.getMessage(),
|
super( "Plugin " + plugin.getId() + " or one of its dependencies could not be resolved: " + cause.getMessage(),
|
||||||
e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getType(), null, e.getRemoteRepositories(), null,
|
cause );
|
||||||
e );
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,4 +44,5 @@ public class PluginResolutionException
|
||||||
{
|
{
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.maven.plugin.internal;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.LegacySupport;
|
import org.apache.maven.plugin.LegacySupport;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helps to provide backward-compatibility with plugins that use legacy components. <strong>Warning:</strong> This is an
|
* Helps to provide backward-compatibility with plugins that use legacy components. <strong>Warning:</strong> This is an
|
||||||
|
@ -55,4 +56,10 @@ public class DefaultLegacySupport
|
||||||
return session.get();
|
return session.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RepositorySystemSession getRepositorySession()
|
||||||
|
{
|
||||||
|
MavenSession session = getSession();
|
||||||
|
return ( session != null ) ? session.getRepositorySession() : null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,18 +28,16 @@ import java.io.InputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
|
import org.apache.maven.RepositoryUtils;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
|
||||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
|
||||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
|
||||||
import org.apache.maven.classrealm.ClassRealmManager;
|
import org.apache.maven.classrealm.ClassRealmManager;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
|
@ -86,6 +84,12 @@ import org.codehaus.plexus.util.IOUtil;
|
||||||
import org.codehaus.plexus.util.ReaderFactory;
|
import org.codehaus.plexus.util.ReaderFactory;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.graph.DependencyNode;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.util.filter.AndDependencyFilter;
|
||||||
|
import org.sonatype.aether.util.graph.PreorderNodeListGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such
|
* Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such
|
||||||
|
@ -120,17 +124,17 @@ public class DefaultMavenPluginManager
|
||||||
|
|
||||||
private PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
|
private PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
|
||||||
|
|
||||||
public synchronized PluginDescriptor getPluginDescriptor( Plugin plugin, RepositoryRequest repositoryRequest )
|
public synchronized PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException
|
throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException
|
||||||
{
|
{
|
||||||
PluginDescriptorCache.Key cacheKey = pluginDescriptorCache.createKey( plugin, repositoryRequest );
|
PluginDescriptorCache.Key cacheKey = pluginDescriptorCache.createKey( plugin, repositories, session );
|
||||||
|
|
||||||
PluginDescriptor pluginDescriptor = pluginDescriptorCache.get( cacheKey );
|
PluginDescriptor pluginDescriptor = pluginDescriptorCache.get( cacheKey );
|
||||||
|
|
||||||
if ( pluginDescriptor == null )
|
if ( pluginDescriptor == null )
|
||||||
{
|
{
|
||||||
Artifact pluginArtifact =
|
Artifact pluginArtifact =
|
||||||
pluginDependenciesResolver.resolve( plugin, new ArtifactResolutionRequest( repositoryRequest ) );
|
RepositoryUtils.toArtifact( pluginDependenciesResolver.resolve( plugin, repositories, session ) );
|
||||||
|
|
||||||
pluginDescriptor = extractPluginDescriptor( pluginArtifact, plugin );
|
pluginDescriptor = extractPluginDescriptor( pluginArtifact, plugin );
|
||||||
|
|
||||||
|
@ -239,11 +243,12 @@ public class DefaultMavenPluginManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
|
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories,
|
||||||
|
RepositorySystemSession session )
|
||||||
throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
|
||||||
InvalidPluginDescriptorException
|
InvalidPluginDescriptorException
|
||||||
{
|
{
|
||||||
PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin, repositoryRequest );
|
PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin, repositories, session );
|
||||||
|
|
||||||
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
|
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
|
||||||
|
|
||||||
|
@ -256,16 +261,18 @@ public class DefaultMavenPluginManager
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session,
|
public synchronized void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session,
|
||||||
ClassLoader parent, List<String> imports, ArtifactFilter filter )
|
ClassLoader parent, List<String> imports, DependencyFilter filter )
|
||||||
throws PluginResolutionException, PluginContainerException
|
throws PluginResolutionException, PluginContainerException
|
||||||
{
|
{
|
||||||
Plugin plugin = pluginDescriptor.getPlugin();
|
Plugin plugin = pluginDescriptor.getPlugin();
|
||||||
|
|
||||||
MavenProject project = session.getCurrentProject();
|
MavenProject project = session.getCurrentProject();
|
||||||
|
|
||||||
PluginRealmCache.CacheRecord cacheRecord =
|
PluginRealmCache.Key cacheKey =
|
||||||
pluginRealmCache.get( plugin, parent, imports, filter, session.getLocalRepository(),
|
pluginRealmCache.createKey( plugin, parent, imports, filter, project.getRemotePluginRepositories(),
|
||||||
project.getPluginArtifactRepositories() );
|
session.getRepositorySession() );
|
||||||
|
|
||||||
|
PluginRealmCache.CacheRecord cacheRecord = pluginRealmCache.get( cacheKey );
|
||||||
|
|
||||||
if ( cacheRecord != null )
|
if ( cacheRecord != null )
|
||||||
{
|
{
|
||||||
|
@ -277,16 +284,14 @@ public class DefaultMavenPluginManager
|
||||||
createPluginRealm( pluginDescriptor, session, parent, imports, filter );
|
createPluginRealm( pluginDescriptor, session, parent, imports, filter );
|
||||||
|
|
||||||
cacheRecord =
|
cacheRecord =
|
||||||
pluginRealmCache.put( plugin, parent, imports, filter, session.getLocalRepository(),
|
pluginRealmCache.put( cacheKey, pluginDescriptor.getClassRealm(), pluginDescriptor.getArtifacts() );
|
||||||
project.getPluginArtifactRepositories(), pluginDescriptor.getClassRealm(),
|
|
||||||
pluginDescriptor.getArtifacts() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginRealmCache.register( project, cacheRecord );
|
pluginRealmCache.register( project, cacheRecord );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
|
private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
|
||||||
List<String> imports, ArtifactFilter filter )
|
List<String> imports, DependencyFilter filter )
|
||||||
throws PluginResolutionException, PluginContainerException
|
throws PluginResolutionException, PluginContainerException
|
||||||
{
|
{
|
||||||
Plugin plugin = pluginDescriptor.getPlugin();
|
Plugin plugin = pluginDescriptor.getPlugin();
|
||||||
|
@ -305,42 +310,32 @@ public class DefaultMavenPluginManager
|
||||||
|
|
||||||
MavenProject project = session.getCurrentProject();
|
MavenProject project = session.getCurrentProject();
|
||||||
|
|
||||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
|
DependencyFilter dependencyFilter = project.getExtensionDependencyFilter();
|
||||||
request.setLocalRepository( session.getLocalRepository() );
|
dependencyFilter = AndDependencyFilter.newInstance( dependencyFilter, filter );
|
||||||
request.setRemoteRepositories( project.getPluginArtifactRepositories() );
|
|
||||||
request.setCache( session.getRepositoryCache() );
|
|
||||||
request.setOffline( session.isOffline() );
|
|
||||||
request.setForceUpdate( session.getRequest().isUpdateSnapshots() );
|
|
||||||
request.setServers( session.getRequest().getServers() );
|
|
||||||
request.setMirrors( session.getRequest().getMirrors() );
|
|
||||||
request.setProxies( session.getRequest().getProxies() );
|
|
||||||
request.setTransferListener( session.getRequest().getTransferListener() );
|
|
||||||
|
|
||||||
ArtifactFilter dependencyFilter = project.getExtensionArtifactFilter();
|
DependencyNode root =
|
||||||
if ( dependencyFilter == null )
|
pluginDependenciesResolver.resolve( plugin, RepositoryUtils.toArtifact( pluginArtifact ), dependencyFilter,
|
||||||
|
project.getRemotePluginRepositories(), session.getRepositorySession() );
|
||||||
|
|
||||||
|
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
|
||||||
|
root.accept( nlg );
|
||||||
|
|
||||||
|
List<Artifact> exposedPluginArtifacts = new ArrayList<Artifact>( nlg.getNodes().size() );
|
||||||
|
RepositoryUtils.toArtifacts( exposedPluginArtifacts, Collections.singleton( root ),
|
||||||
|
Collections.<String> emptyList(), null );
|
||||||
|
for ( Iterator<Artifact> it = exposedPluginArtifacts.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
dependencyFilter = filter;
|
Artifact artifact = it.next();
|
||||||
}
|
if ( artifact.getFile() == null )
|
||||||
else if ( filter != null )
|
|
||||||
{
|
|
||||||
dependencyFilter = new AndArtifactFilter( Arrays.asList( dependencyFilter, filter ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Artifact> pluginArtifacts =
|
|
||||||
pluginDependenciesResolver.resolve( plugin, pluginArtifact, request, dependencyFilter );
|
|
||||||
|
|
||||||
ClassRealm pluginRealm = classRealmManager.createPluginRealm( plugin, parent, imports, pluginArtifacts );
|
|
||||||
|
|
||||||
List<Artifact> exposedPluginArtifacts = new ArrayList<Artifact>();
|
|
||||||
|
|
||||||
for ( Artifact artifact : pluginArtifacts )
|
|
||||||
{
|
|
||||||
if ( artifact.getFile() != null )
|
|
||||||
{
|
{
|
||||||
exposedPluginArtifacts.add( artifact );
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<org.sonatype.aether.artifact.Artifact> pluginArtifacts = nlg.getArtifacts( true );
|
||||||
|
|
||||||
|
ClassRealm pluginRealm = classRealmManager.createPluginRealm( plugin, parent, imports, pluginArtifacts );
|
||||||
|
|
||||||
pluginDescriptor.setClassRealm( pluginRealm );
|
pluginDescriptor.setClassRealm( pluginRealm );
|
||||||
pluginDescriptor.setArtifacts( exposedPluginArtifacts );
|
pluginDescriptor.setArtifacts( exposedPluginArtifacts );
|
||||||
|
|
||||||
|
|
|
@ -19,28 +19,37 @@ package org.apache.maven.plugin.internal;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.maven.ArtifactFilterManager;
|
import org.apache.maven.ArtifactFilterManager;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.RepositoryUtils;
|
||||||
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.Dependency;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.PluginResolutionException;
|
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.Component;
|
||||||
import org.codehaus.plexus.component.annotations.Requirement;
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
import org.sonatype.aether.RepositorySystem;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.collection.CollectRequest;
|
||||||
|
import org.sonatype.aether.collection.DependencyCollectionException;
|
||||||
|
import org.sonatype.aether.collection.DependencyGraphTransformer;
|
||||||
|
import org.sonatype.aether.collection.DependencySelector;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.graph.DependencyNode;
|
||||||
|
import org.sonatype.aether.graph.DependencyVisitor;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactRequest;
|
||||||
|
import org.sonatype.aether.resolution.ArtifactResolutionException;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
||||||
|
import org.sonatype.aether.util.artifact.JavaScopes;
|
||||||
|
import org.sonatype.aether.util.filter.AndDependencyFilter;
|
||||||
|
import org.sonatype.aether.util.filter.ExclusionsDependencyFilter;
|
||||||
|
import org.sonatype.aether.util.filter.ScopeDependencyFilter;
|
||||||
|
import org.sonatype.aether.util.graph.selector.AndDependencySelector;
|
||||||
|
import org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility class that
|
* Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility class that
|
||||||
|
@ -55,29 +64,32 @@ public class DefaultPluginDependenciesResolver
|
||||||
implements PluginDependenciesResolver
|
implements PluginDependenciesResolver
|
||||||
{
|
{
|
||||||
|
|
||||||
@Requirement
|
private static final String REPOSITORY_CONTEXT = "plugin";
|
||||||
protected RepositorySystem repositorySystem;
|
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private ResolutionErrorHandler resolutionErrorHandler;
|
private Logger logger;
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private ArtifactFilterManager artifactFilterManager;
|
private ArtifactFilterManager artifactFilterManager;
|
||||||
|
|
||||||
public Artifact resolve( Plugin plugin, ArtifactResolutionRequest request )
|
@Requirement
|
||||||
|
private RepositorySystem repoSystem;
|
||||||
|
|
||||||
|
private Artifact toArtifact( Plugin plugin, RepositorySystemSession session )
|
||||||
|
{
|
||||||
|
return new DefaultArtifact( plugin.getGroupId(), plugin.getArtifactId(), null, "jar", plugin.getVersion(),
|
||||||
|
session.getArtifactTypeRegistry().get( "maven-plugin" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public Artifact resolve( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
throws PluginResolutionException
|
throws PluginResolutionException
|
||||||
{
|
{
|
||||||
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin );
|
Artifact pluginArtifact = toArtifact( plugin, session );
|
||||||
|
|
||||||
request.setArtifact( pluginArtifact );
|
|
||||||
request.setResolveRoot( true );
|
|
||||||
request.setResolveTransitively( false );
|
|
||||||
|
|
||||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
resolutionErrorHandler.throwErrors( request, result );
|
ArtifactRequest request = new ArtifactRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT );
|
||||||
|
pluginArtifact = repoSystem.resolveArtifact( session, request ).getArtifact();
|
||||||
}
|
}
|
||||||
catch ( ArtifactResolutionException e )
|
catch ( ArtifactResolutionException e )
|
||||||
{
|
{
|
||||||
|
@ -87,96 +99,113 @@ public class DefaultPluginDependenciesResolver
|
||||||
return pluginArtifact;
|
return pluginArtifact;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
|
public DependencyNode resolve( Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter,
|
||||||
ArtifactFilter dependencyFilter )
|
List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
throws PluginResolutionException
|
throws PluginResolutionException
|
||||||
{
|
{
|
||||||
if ( pluginArtifact == null )
|
if ( pluginArtifact == null )
|
||||||
{
|
{
|
||||||
pluginArtifact = repositorySystem.createPluginArtifact( plugin );
|
pluginArtifact = toArtifact( plugin, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Artifact> overrideArtifacts = new LinkedHashSet<Artifact>();
|
DependencyFilter collectionFilter = new ScopeDependencyFilter( "provided", "test" );
|
||||||
for ( Dependency dependency : plugin.getDependencies() )
|
|
||||||
{
|
|
||||||
if ( !Artifact.SCOPE_SYSTEM.equals( dependency.getScope() ) )
|
|
||||||
{
|
|
||||||
dependency.setScope( Artifact.SCOPE_RUNTIME );
|
|
||||||
}
|
|
||||||
overrideArtifacts.add( repositorySystem.createDependencyArtifact( dependency ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
ArtifactFilter collectionFilter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME_PLUS_SYSTEM );
|
DependencyFilter resolutionFilter =
|
||||||
|
new ExclusionsDependencyFilter( artifactFilterManager.getCoreArtifactExcludes() );
|
||||||
|
resolutionFilter = AndDependencyFilter.newInstance( resolutionFilter, dependencyFilter );
|
||||||
|
resolutionFilter = new AndDependencyFilter( collectionFilter, resolutionFilter );
|
||||||
|
|
||||||
ArtifactFilter resolutionFilter = artifactFilterManager.getCoreArtifactFilter();
|
DependencyNode node;
|
||||||
|
|
||||||
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
|
try
|
||||||
{
|
{
|
||||||
resolutionErrorHandler.throwErrors( request, result );
|
DependencySelector selector =
|
||||||
|
AndDependencySelector.newInstance( session.getDependencySelector(), new WagonExcluder() );
|
||||||
|
|
||||||
|
DependencyGraphTransformer transformer =
|
||||||
|
ChainedDependencyGraphTransformer.newInstance( session.getDependencyGraphTransformer(),
|
||||||
|
new PlexusUtilsInjector() );
|
||||||
|
|
||||||
|
DefaultRepositorySystemSession pluginSession = new DefaultRepositorySystemSession( session );
|
||||||
|
pluginSession.setDependencySelector( selector );
|
||||||
|
pluginSession.setDependencyGraphTransformer( transformer );
|
||||||
|
|
||||||
|
CollectRequest request = new CollectRequest();
|
||||||
|
request.setRequestContext( REPOSITORY_CONTEXT );
|
||||||
|
request.setRepositories( repositories );
|
||||||
|
request.setRoot( new org.sonatype.aether.graph.Dependency( pluginArtifact, null ) );
|
||||||
|
for ( Dependency dependency : plugin.getDependencies() )
|
||||||
|
{
|
||||||
|
org.sonatype.aether.graph.Dependency pluginDep =
|
||||||
|
RepositoryUtils.toDependency( dependency, session.getArtifactTypeRegistry() );
|
||||||
|
if ( !JavaScopes.SYSTEM.equals( pluginDep.getScope() ) )
|
||||||
|
{
|
||||||
|
pluginDep = pluginDep.setScope( JavaScopes.RUNTIME );
|
||||||
|
}
|
||||||
|
request.addDependency( pluginDep );
|
||||||
|
}
|
||||||
|
|
||||||
|
node = repoSystem.collectDependencies( pluginSession, request ).getRoot();
|
||||||
|
|
||||||
|
if ( logger.isDebugEnabled() )
|
||||||
|
{
|
||||||
|
node.accept( new GraphLogger() );
|
||||||
|
}
|
||||||
|
|
||||||
|
repoSystem.resolveDependencies( session, node, resolutionFilter );
|
||||||
|
}
|
||||||
|
catch ( DependencyCollectionException e )
|
||||||
|
{
|
||||||
|
throw new PluginResolutionException( plugin, e );
|
||||||
}
|
}
|
||||||
catch ( ArtifactResolutionException e )
|
catch ( ArtifactResolutionException e )
|
||||||
{
|
{
|
||||||
throw new PluginResolutionException( plugin, e );
|
throw new PluginResolutionException( plugin, e );
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Artifact> pluginArtifacts = new ArrayList<Artifact>( result.getArtifacts() );
|
return node;
|
||||||
|
|
||||||
listener.removeBannedDependencies( pluginArtifacts );
|
|
||||||
|
|
||||||
addPlexusUtils( pluginArtifacts, plugin, request );
|
|
||||||
|
|
||||||
return pluginArtifacts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// backward-compatibility with Maven 2.x
|
class GraphLogger
|
||||||
private void addPlexusUtils( List<Artifact> pluginArtifacts, Plugin plugin, RepositoryRequest repositoryRequest )
|
implements DependencyVisitor
|
||||||
throws PluginResolutionException
|
|
||||||
{
|
{
|
||||||
for ( Artifact artifact : pluginArtifacts )
|
|
||||||
|
private String indent = "";
|
||||||
|
|
||||||
|
public boolean visitEnter( DependencyNode node )
|
||||||
{
|
{
|
||||||
if ( "org.codehaus.plexus:plexus-utils:jar".equals( artifact.getDependencyConflictId() ) )
|
StringBuilder buffer = new StringBuilder( 128 );
|
||||||
|
buffer.append( indent );
|
||||||
|
org.sonatype.aether.graph.Dependency dep = node.getDependency();
|
||||||
|
if ( dep != null )
|
||||||
{
|
{
|
||||||
return;
|
org.sonatype.aether.artifact.Artifact art = dep.getArtifact();
|
||||||
|
|
||||||
|
buffer.append( art );
|
||||||
|
buffer.append( ':' ).append( dep.getScope() );
|
||||||
|
|
||||||
|
if ( node.getPremanagedScope() != null && !node.getPremanagedScope().equals( dep.getScope() ) )
|
||||||
|
{
|
||||||
|
buffer.append( " (scope managed from " ).append( node.getPremanagedScope() ).append( ")" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( node.getPremanagedVersion() != null && !node.getPremanagedVersion().equals( art.getVersion() ) )
|
||||||
|
{
|
||||||
|
buffer.append( " (version managed from " ).append( node.getPremanagedVersion() ).append( ")" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug( buffer.toString() );
|
||||||
|
indent += " ";
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Artifact plexusUtils =
|
public boolean visitLeave( DependencyNode node )
|
||||||
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 );
|
indent = indent.substring( 0, indent.length() - 3 );
|
||||||
}
|
return true;
|
||||||
catch ( ArtifactResolutionException e )
|
|
||||||
{
|
|
||||||
throw new PluginResolutionException( plugin, e );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginArtifacts.add( plexusUtils );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,6 @@ package org.apache.maven.plugin.internal;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
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.ArtifactNotFoundException;
|
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
||||||
|
@ -100,10 +98,9 @@ public class DefaultPluginManager
|
||||||
PluginDescriptor pluginDescriptor;
|
PluginDescriptor pluginDescriptor;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RepositoryRequest repositoryRequest =
|
pluginDescriptor =
|
||||||
DefaultRepositoryRequest.getRepositoryRequest( session, session.getCurrentProject() );
|
pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(),
|
||||||
|
session.getRepositorySession() );
|
||||||
pluginDescriptor = pluginManager.getPluginDescriptor( plugin, repositoryRequest );
|
|
||||||
|
|
||||||
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
|
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
|
||||||
}
|
}
|
||||||
|
@ -133,10 +130,9 @@ public class DefaultPluginManager
|
||||||
PluginDescriptor pluginDescriptor;
|
PluginDescriptor pluginDescriptor;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RepositoryRequest repositoryRequest =
|
pluginDescriptor =
|
||||||
DefaultRepositoryRequest.getRepositoryRequest( session, session.getCurrentProject() );
|
pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(),
|
||||||
|
session.getRepositorySession() );
|
||||||
pluginDescriptor = pluginManager.getPluginDescriptor( plugin, repositoryRequest );
|
|
||||||
|
|
||||||
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
|
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
|
||||||
}
|
}
|
||||||
|
@ -234,24 +230,24 @@ public class DefaultPluginManager
|
||||||
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
|
||||||
PluginVersionNotFoundException
|
PluginVersionNotFoundException
|
||||||
{
|
{
|
||||||
RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
|
MavenSession session = legacySupport.getSession();
|
||||||
repositoryRequest.setLocalRepository( localRepository );
|
|
||||||
repositoryRequest.setRemoteRepositories( project.getPluginArtifactRepositories() );
|
|
||||||
repositoryRequest.setOffline( settings.isOffline() );
|
|
||||||
|
|
||||||
if ( plugin.getVersion() == null )
|
if ( plugin.getVersion() == null )
|
||||||
{
|
{
|
||||||
PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, repositoryRequest );
|
PluginVersionRequest versionRequest =
|
||||||
|
new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
|
||||||
|
project.getRemotePluginRepositories() );
|
||||||
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
|
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return pluginManager.getPluginDescriptor( plugin, repositoryRequest );
|
return pluginManager.getPluginDescriptor( plugin, project.getRemotePluginRepositories(),
|
||||||
|
session.getRepositorySession() );
|
||||||
}
|
}
|
||||||
catch ( PluginResolutionException e )
|
catch ( PluginResolutionException e )
|
||||||
{
|
{
|
||||||
throw new PluginNotFoundException( plugin, repositoryRequest.getRemoteRepositories() );
|
throw new PluginNotFoundException( plugin, project.getPluginArtifactRepositories() );
|
||||||
}
|
}
|
||||||
catch ( PluginDescriptorParsingException e )
|
catch ( PluginDescriptorParsingException e )
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
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 org.sonatype.aether.RepositoryException;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.collection.DependencyGraphTransformationContext;
|
||||||
|
import org.sonatype.aether.collection.DependencyGraphTransformer;
|
||||||
|
import org.sonatype.aether.graph.Dependency;
|
||||||
|
import org.sonatype.aether.graph.DependencyNode;
|
||||||
|
import org.sonatype.aether.util.artifact.DefaultArtifact;
|
||||||
|
import org.sonatype.aether.util.artifact.JavaScopes;
|
||||||
|
import org.sonatype.aether.util.graph.DefaultDependencyNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects plexus-utils:1.1 into a plugin's class path if it doesn't already declare a dependency on plexus-utils. This
|
||||||
|
* is another legacy bit to provide backward-compat with Maven 2.x.
|
||||||
|
*
|
||||||
|
* @author Benjamin Bentmann
|
||||||
|
*/
|
||||||
|
class PlexusUtilsInjector
|
||||||
|
implements DependencyGraphTransformer
|
||||||
|
{
|
||||||
|
|
||||||
|
private static final String GID = "org.codehaus.plexus";
|
||||||
|
|
||||||
|
private static final String AID = "plexus-utils";
|
||||||
|
|
||||||
|
private static final String VER = "1.1";
|
||||||
|
|
||||||
|
private static final String EXT = "jar";
|
||||||
|
|
||||||
|
public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context )
|
||||||
|
throws RepositoryException
|
||||||
|
{
|
||||||
|
if ( findPlexusUtils( node ) == null )
|
||||||
|
{
|
||||||
|
Artifact pu = new DefaultArtifact( GID, AID, null, EXT, VER );
|
||||||
|
DefaultDependencyNode child = new DefaultDependencyNode( new Dependency( pu, JavaScopes.RUNTIME ) );
|
||||||
|
child.setRepositories( node.getRepositories() );
|
||||||
|
child.setRequestContext( node.getRequestContext() );
|
||||||
|
node.getChildren().add( child );
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DependencyNode findPlexusUtils( DependencyNode node )
|
||||||
|
{
|
||||||
|
Artifact artifact = node.getDependency().getArtifact();
|
||||||
|
|
||||||
|
if ( AID.equals( artifact.getArtifactId() ) && GID.equals( artifact.getGroupId() )
|
||||||
|
&& EXT.equals( artifact.getExtension() ) && "".equals( artifact.getClassifier() ) )
|
||||||
|
{
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( DependencyNode child : node.getChildren() )
|
||||||
|
{
|
||||||
|
DependencyNode result = findPlexusUtils( child );
|
||||||
|
if ( result != null )
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,11 +21,13 @@ package org.apache.maven.plugin.internal;
|
||||||
|
|
||||||
import java.util.List;
|
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.model.Plugin;
|
||||||
import org.apache.maven.plugin.PluginResolutionException;
|
import org.apache.maven.plugin.PluginResolutionException;
|
||||||
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.graph.DependencyFilter;
|
||||||
|
import org.sonatype.aether.graph.DependencyNode;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility interface
|
* Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility interface
|
||||||
|
@ -40,29 +42,30 @@ public interface PluginDependenciesResolver
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the main artifact of the specified plugin.
|
* Resolves the main artifact of the specified plugin.
|
||||||
*
|
*
|
||||||
* @param plugin The plugin for which to resolve the main artifact, must not be {@code null}.
|
* @param plugin The plugin for which to resolve the main artifact, must not be {@code null}.
|
||||||
* @param request A prepopulated resolution request that will be completed and used for the resolution, must not be
|
* @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
|
||||||
* {@code null}.
|
* null}.
|
||||||
|
* @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
|
||||||
* @return The resolved plugin artifact, never {@code null}.
|
* @return The resolved plugin artifact, never {@code null}.
|
||||||
* @throws PluginResolutionException If the plugin artifact could not be resolved.
|
* @throws PluginResolutionException If the plugin artifact could not be resolved.
|
||||||
*/
|
*/
|
||||||
Artifact resolve( Plugin plugin, ArtifactResolutionRequest request )
|
public Artifact resolve( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
throws PluginResolutionException;
|
throws PluginResolutionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves the runtime dependencies of the specified plugin.
|
* Resolves the runtime dependencies of the specified plugin.
|
||||||
*
|
*
|
||||||
* @param plugin The plugin for which to resolve the dependencies, must not be {@code null}.
|
* @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 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
|
* @param dependencyFilter A filter to exclude artifacts from resolution (but not collection), may be {@code null}.
|
||||||
* {@code null}.
|
* @param repositories The plugin repositories to use for resolving the plugin artifacts, must not be {@code null}.
|
||||||
* @param dependencyFilter A filter to exclude artifacts from resolution, may be {@code null}.
|
* @param session The repository session to use for resolving the plugin artifacts, must not be {@code null}.
|
||||||
* @return The list of artifacts denoting the resolved plugin class path, never {@code null}.
|
* @return The dependency tree denoting the resolved plugin class path, never {@code null}.
|
||||||
* @throws PluginResolutionException If any dependency could not be resolved.
|
* @throws PluginResolutionException If any dependency could not be resolved.
|
||||||
*/
|
*/
|
||||||
List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
|
DependencyNode resolve( Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter,
|
||||||
ArtifactFilter dependencyFilter )
|
List<RemoteRepository> repositories, RepositorySystemSession session )
|
||||||
throws PluginResolutionException;
|
throws PluginResolutionException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
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 org.sonatype.aether.artifact.Artifact;
|
||||||
|
import org.sonatype.aether.collection.DependencyCollectionContext;
|
||||||
|
import org.sonatype.aether.collection.DependencySelector;
|
||||||
|
import org.sonatype.aether.graph.Dependency;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 WagonExcluder
|
||||||
|
implements DependencySelector
|
||||||
|
{
|
||||||
|
|
||||||
|
private final boolean coreArtifact;
|
||||||
|
|
||||||
|
public WagonExcluder()
|
||||||
|
{
|
||||||
|
this( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
private WagonExcluder( boolean coreArtifact )
|
||||||
|
{
|
||||||
|
this.coreArtifact = coreArtifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean selectDependency( Dependency dependency )
|
||||||
|
{
|
||||||
|
return !coreArtifact || !isWagonProvider( dependency.getArtifact() );
|
||||||
|
}
|
||||||
|
|
||||||
|
public DependencySelector deriveChildSelector( DependencyCollectionContext context )
|
||||||
|
{
|
||||||
|
if ( coreArtifact || !isLegacyCoreArtifact( context.getDependency().getArtifact() ) )
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new WagonExcluder( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isLegacyCoreArtifact( Artifact artifact )
|
||||||
|
{
|
||||||
|
String version = artifact.getVersion();
|
||||||
|
return version != null && version.startsWith( "2." ) && artifact.getArtifactId().startsWith( "maven-" )
|
||||||
|
&& artifact.getGroupId().equals( "org.apache.maven" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isWagonProvider( Artifact artifact )
|
||||||
|
{
|
||||||
|
if ( "org.apache.maven.wagon".equals( artifact.getGroupId() ) )
|
||||||
|
{
|
||||||
|
return artifact.getArtifactId().startsWith( "wagon-" );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object obj )
|
||||||
|
{
|
||||||
|
if ( obj == this )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if ( obj == null || !getClass().equals( obj.getClass() ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
WagonExcluder that = (WagonExcluder) obj;
|
||||||
|
return coreArtifact == that.coreArtifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int hash = getClass().hashCode();
|
||||||
|
hash = hash * 31 + ( coreArtifact ? 1 : 0 );
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,17 +19,14 @@ package org.apache.maven.plugin.prefix;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects settings required to resolve a plugin prefix.
|
* Collects settings required to resolve a plugin prefix.
|
||||||
|
@ -43,34 +40,25 @@ public class DefaultPluginPrefixRequest
|
||||||
|
|
||||||
private String prefix;
|
private String prefix;
|
||||||
|
|
||||||
private List<String> pluginGroups;
|
private List<String> pluginGroups = Collections.emptyList();
|
||||||
|
|
||||||
private Model pom;
|
private Model pom;
|
||||||
|
|
||||||
private RepositoryRequest repositoryRequest;
|
private List<RemoteRepository> repositories = Collections.emptyList();
|
||||||
|
|
||||||
|
private RepositorySystemSession session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty request.
|
* Creates an empty request.
|
||||||
*/
|
*/
|
||||||
public DefaultPluginPrefixRequest()
|
public DefaultPluginPrefixRequest()
|
||||||
{
|
{
|
||||||
repositoryRequest = new DefaultRepositoryRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a request by copying settings from the specified repository request.
|
|
||||||
*
|
|
||||||
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
|
|
||||||
*/
|
|
||||||
public DefaultPluginPrefixRequest( RepositoryRequest repositoryRequest )
|
|
||||||
{
|
|
||||||
this.repositoryRequest = new DefaultRepositoryRequest( repositoryRequest );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a request for the specified plugin prefix and build session. The provided build session will be used to
|
* Creates a request for the specified plugin prefix and build session. The provided build session will be used to
|
||||||
* configure repository settings. If the session has a current project, its plugin artifact repositories and model
|
* configure repository settings. If the session has a current project, its plugin repositories and model will be
|
||||||
* will be used as well.
|
* used as well.
|
||||||
*
|
*
|
||||||
* @param prefix The plugin prefix to resolve, must not be {@code null}.
|
* @param prefix The plugin prefix to resolve, must not be {@code null}.
|
||||||
* @param session The build session from which to derive further settings, must not be {@code null}.
|
* @param session The build session from which to derive further settings, must not be {@code null}.
|
||||||
|
@ -79,18 +67,12 @@ public class DefaultPluginPrefixRequest
|
||||||
{
|
{
|
||||||
setPrefix( prefix );
|
setPrefix( prefix );
|
||||||
|
|
||||||
this.repositoryRequest = new DefaultRepositoryRequest();
|
setRepositorySession( session.getRepositorySession() );
|
||||||
|
|
||||||
setCache( session.getRepositoryCache() );
|
|
||||||
setLocalRepository( session.getLocalRepository() );
|
|
||||||
setOffline( session.isOffline() );
|
|
||||||
setForceUpdate( session.getRequest().isUpdateSnapshots() );
|
|
||||||
setTransferListener( session.getRequest().getTransferListener() );
|
|
||||||
|
|
||||||
MavenProject project = session.getCurrentProject();
|
MavenProject project = session.getCurrentProject();
|
||||||
if ( project != null )
|
if ( project != null )
|
||||||
{
|
{
|
||||||
setRemoteRepositories( project.getPluginArtifactRepositories() );
|
setRepositories( project.getRemotePluginRepositories() );
|
||||||
setPom( project.getModel() );
|
setPom( project.getModel() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,17 +93,19 @@ public class DefaultPluginPrefixRequest
|
||||||
|
|
||||||
public List<String> getPluginGroups()
|
public List<String> getPluginGroups()
|
||||||
{
|
{
|
||||||
if ( pluginGroups == null )
|
|
||||||
{
|
|
||||||
pluginGroups = new ArrayList<String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return pluginGroups;
|
return pluginGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultPluginPrefixRequest setPluginGroups( List<String> pluginGroups )
|
public DefaultPluginPrefixRequest setPluginGroups( List<String> pluginGroups )
|
||||||
{
|
{
|
||||||
this.pluginGroups = pluginGroups;
|
if ( pluginGroups != null )
|
||||||
|
{
|
||||||
|
this.pluginGroups = pluginGroups;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.pluginGroups = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -138,74 +122,33 @@ public class DefaultPluginPrefixRequest
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepositoryCache getCache()
|
public List<RemoteRepository> getRepositories()
|
||||||
{
|
{
|
||||||
return repositoryRequest.getCache();
|
return repositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultPluginPrefixRequest setCache( RepositoryCache cache )
|
public DefaultPluginPrefixRequest setRepositories( List<RemoteRepository> repositories )
|
||||||
{
|
{
|
||||||
repositoryRequest.setCache( cache );
|
if ( repositories != null )
|
||||||
|
{
|
||||||
|
this.repositories = repositories;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.repositories = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactRepository getLocalRepository()
|
public RepositorySystemSession getRepositorySession()
|
||||||
{
|
{
|
||||||
return repositoryRequest.getLocalRepository();
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultPluginPrefixRequest setLocalRepository( ArtifactRepository localRepository )
|
public DefaultPluginPrefixRequest setRepositorySession( RepositorySystemSession session )
|
||||||
{
|
{
|
||||||
repositoryRequest.setLocalRepository( localRepository );
|
this.session = session;
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ArtifactRepository> getRemoteRepositories()
|
|
||||||
{
|
|
||||||
return repositoryRequest.getRemoteRepositories();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultPluginPrefixRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
|
|
||||||
{
|
|
||||||
repositoryRequest.setRemoteRepositories( remoteRepositories );
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOffline()
|
|
||||||
{
|
|
||||||
return repositoryRequest.isOffline();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultPluginPrefixRequest setOffline( boolean offline )
|
|
||||||
{
|
|
||||||
repositoryRequest.setOffline( offline );
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isForceUpdate()
|
|
||||||
{
|
|
||||||
return repositoryRequest.isForceUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultPluginPrefixRequest setForceUpdate( boolean forceUpdate )
|
|
||||||
{
|
|
||||||
repositoryRequest.setForceUpdate( forceUpdate );
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArtifactTransferListener getTransferListener()
|
|
||||||
{
|
|
||||||
return repositoryRequest.getTransferListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultPluginPrefixRequest setTransferListener( ArtifactTransferListener transferListener )
|
|
||||||
{
|
|
||||||
repositoryRequest.setTransferListener( transferListener );
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,29 +21,21 @@ package org.apache.maven.plugin.prefix;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.sonatype.aether.repository.LocalRepository;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
public class NoPluginFoundForPrefixException
|
public class NoPluginFoundForPrefixException
|
||||||
extends Exception
|
extends Exception
|
||||||
{
|
{
|
||||||
private String prefix;
|
|
||||||
|
public NoPluginFoundForPrefixException( String prefix, List<String> pluginGroups, LocalRepository localRepository,
|
||||||
private ArtifactRepository localRepository;
|
List<RemoteRepository> remoteRepositories )
|
||||||
|
|
||||||
private List<ArtifactRepository> remoteRepositories;
|
|
||||||
|
|
||||||
public NoPluginFoundForPrefixException( String prefix, List<String> pluginGroups,
|
|
||||||
ArtifactRepository localRepository,
|
|
||||||
List<ArtifactRepository> remoteRepositories )
|
|
||||||
{
|
{
|
||||||
super( "No plugin found for prefix '" + prefix + "' in the current project and in the plugin groups "
|
super( "No plugin found for prefix '" + prefix + "' in the current project and in the plugin groups "
|
||||||
+ pluginGroups + " available from the repositories " + format( localRepository, remoteRepositories ) );
|
+ pluginGroups + " available from the repositories " + format( localRepository, remoteRepositories ) );
|
||||||
this.prefix = prefix;
|
|
||||||
this.localRepository = localRepository;
|
|
||||||
this.remoteRepositories = remoteRepositories;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String format( ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
private static String format( LocalRepository localRepository, List<RemoteRepository> remoteRepositories )
|
||||||
{
|
{
|
||||||
String repos = "[";
|
String repos = "[";
|
||||||
|
|
||||||
|
@ -54,7 +46,7 @@ public class NoPluginFoundForPrefixException
|
||||||
|
|
||||||
if ( remoteRepositories != null && !remoteRepositories.isEmpty() )
|
if ( remoteRepositories != null && !remoteRepositories.isEmpty() )
|
||||||
{
|
{
|
||||||
for ( ArtifactRepository repository : remoteRepositories )
|
for ( RemoteRepository repository : remoteRepositories )
|
||||||
{
|
{
|
||||||
repos += ", ";
|
repos += ", ";
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,9 @@ package org.apache.maven.plugin.prefix;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects settings required to resolve a plugin prefix.
|
* Collects settings required to resolve a plugin prefix.
|
||||||
|
@ -34,7 +32,6 @@ import org.apache.maven.repository.ArtifactTransferListener;
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
public interface PluginPrefixRequest
|
public interface PluginPrefixRequest
|
||||||
extends RepositoryRequest
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,80 +81,35 @@ public interface PluginPrefixRequest
|
||||||
*/
|
*/
|
||||||
PluginPrefixRequest setPom( Model pom );
|
PluginPrefixRequest setPom( Model pom );
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether network access to remote repositories has been disabled.
|
|
||||||
*
|
|
||||||
* @return {@code true} if remote access has been disabled, {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
boolean isOffline();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables/disables network access to remote repositories.
|
|
||||||
*
|
|
||||||
* @param offline {@code true} to disable remote access, {@code false} to allow network access.
|
|
||||||
* @return This request, never {@code null}.
|
|
||||||
*/
|
|
||||||
PluginPrefixRequest setOffline( boolean offline );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the local repository to use.
|
|
||||||
*
|
|
||||||
* @return The local repository to use or {@code null} if not set.
|
|
||||||
*/
|
|
||||||
ArtifactRepository getLocalRepository();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the local repository to use.
|
|
||||||
*
|
|
||||||
* @param localRepository The local repository to use.
|
|
||||||
* @return This request, never {@code null}.
|
|
||||||
*/
|
|
||||||
PluginPrefixRequest setLocalRepository( ArtifactRepository localRepository );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the remote repositories to use.
|
* Gets the remote repositories to use.
|
||||||
*
|
*
|
||||||
* @return The remote repositories to use, never {@code null}.
|
* @return The remote repositories to use, never {@code null}.
|
||||||
*/
|
*/
|
||||||
List<ArtifactRepository> getRemoteRepositories();
|
List<RemoteRepository> getRepositories();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the remote repositories to use. <em>Note:</em> When creating a request from a project, be sure to use the
|
* Sets the remote repositories to use. <em>Note:</em> When creating a request from a project, be sure to use the
|
||||||
* plugin artifact repositories and not the regular artifact repositories.
|
* plugin repositories and not the regular project repositories.
|
||||||
*
|
*
|
||||||
* @param remoteRepositories The remote repositories to use.
|
* @param repositories The remote repositories to use.
|
||||||
* @return This request, never {@code null}.
|
* @return This request, never {@code null}.
|
||||||
*/
|
*/
|
||||||
PluginPrefixRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
|
PluginPrefixRequest setRepositories( List<RemoteRepository> repositories );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the repository cache to use.
|
* Gets the session to use for repository access.
|
||||||
*
|
*
|
||||||
* @return The repository cache to use or {@code null} if none.
|
* @return The repository session or {@code null} if not set.
|
||||||
*/
|
*/
|
||||||
RepositoryCache getCache();
|
RepositorySystemSession getRepositorySession();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the repository cache to use.
|
* Sets the session to use for repository access.
|
||||||
*
|
*
|
||||||
* @param cache The repository cache to use, may be {@code null}.
|
* @param repositorySession The repository session to use.
|
||||||
* @return This request, never {@code null}.
|
* @return This request, never {@code null}.
|
||||||
*/
|
*/
|
||||||
PluginPrefixRequest setCache( RepositoryCache cache );
|
PluginPrefixRequest setRepositorySession( RepositorySystemSession repositorySession );
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the listener to notify of transfer events.
|
|
||||||
*
|
|
||||||
* @return The transfer listener or {@code null} if none.
|
|
||||||
*/
|
|
||||||
ArtifactTransferListener getTransferListener();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the listener to notify of transfer events.
|
|
||||||
*
|
|
||||||
* @param transferListener The transfer listener to notify, may be {@code null}.
|
|
||||||
* @return This request, never {@code null}.
|
|
||||||
*/
|
|
||||||
PluginPrefixRequest setTransferListener( ArtifactTransferListener transferListener );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.apache.maven.plugin.prefix;
|
package org.apache.maven.plugin.prefix;
|
||||||
|
|
||||||
|
import org.sonatype.aether.repository.ArtifactRepository;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
@ -19,8 +21,6 @@ package org.apache.maven.plugin.prefix;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the result of a plugin prefix resolution request.
|
* Describes the result of a plugin prefix resolution request.
|
||||||
*
|
*
|
||||||
|
|
|
@ -23,11 +23,9 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
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.io.MetadataReader;
|
import org.apache.maven.artifact.repository.metadata.io.MetadataReader;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
|
@ -38,12 +36,18 @@ import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
|
||||||
import org.apache.maven.plugin.prefix.PluginPrefixRequest;
|
import org.apache.maven.plugin.prefix.PluginPrefixRequest;
|
||||||
import org.apache.maven.plugin.prefix.PluginPrefixResolver;
|
import org.apache.maven.plugin.prefix.PluginPrefixResolver;
|
||||||
import org.apache.maven.plugin.prefix.PluginPrefixResult;
|
import org.apache.maven.plugin.prefix.PluginPrefixResult;
|
||||||
import org.apache.maven.repository.RepositorySystem;
|
|
||||||
import org.apache.maven.repository.ArtifactDoesNotExistException;
|
|
||||||
import org.apache.maven.repository.ArtifactTransferFailedException;
|
|
||||||
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;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
|
import org.sonatype.aether.RepositorySystem;
|
||||||
|
import org.sonatype.aether.repository.ArtifactRepository;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
import org.sonatype.aether.repository.RepositoryPolicy;
|
||||||
|
import org.sonatype.aether.resolution.MetadataRequest;
|
||||||
|
import org.sonatype.aether.resolution.MetadataResult;
|
||||||
|
import org.sonatype.aether.transfer.MetadataNotFoundException;
|
||||||
|
import org.sonatype.aether.util.DefaultRepositorySystemSession;
|
||||||
|
import org.sonatype.aether.util.metadata.DefaultMetadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolves a plugin prefix.
|
* Resolves a plugin prefix.
|
||||||
|
@ -56,6 +60,8 @@ public class DefaultPluginPrefixResolver
|
||||||
implements PluginPrefixResolver
|
implements PluginPrefixResolver
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final String REPOSITORY_CONTEXT = "plugin";
|
||||||
|
|
||||||
@Requirement
|
@Requirement
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
|
|
||||||
|
@ -82,8 +88,8 @@ public class DefaultPluginPrefixResolver
|
||||||
if ( result == null )
|
if ( result == null )
|
||||||
{
|
{
|
||||||
throw new NoPluginFoundForPrefixException( request.getPrefix(), request.getPluginGroups(),
|
throw new NoPluginFoundForPrefixException( request.getPrefix(), request.getPluginGroups(),
|
||||||
request.getLocalRepository(),
|
request.getRepositorySession().getLocalRepository(),
|
||||||
request.getRemoteRepositories() );
|
request.getRepositories() );
|
||||||
}
|
}
|
||||||
else if ( logger.isDebugEnabled() )
|
else if ( logger.isDebugEnabled() )
|
||||||
{
|
{
|
||||||
|
@ -126,7 +132,8 @@ public class DefaultPluginPrefixResolver
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PluginDescriptor pluginDescriptor = pluginManager.loadPlugin( plugin, request );
|
PluginDescriptor pluginDescriptor =
|
||||||
|
pluginManager.loadPlugin( plugin, request.getRepositories(), request.getRepositorySession() );
|
||||||
|
|
||||||
if ( request.getPrefix().equals( pluginDescriptor.getGoalPrefix() ) )
|
if ( request.getPrefix().equals( pluginDescriptor.getGoalPrefix() ) )
|
||||||
{
|
{
|
||||||
|
@ -152,155 +159,105 @@ public class DefaultPluginPrefixResolver
|
||||||
|
|
||||||
private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request )
|
private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request )
|
||||||
{
|
{
|
||||||
ArtifactRepository localRepository = request.getLocalRepository();
|
List<MetadataRequest> requests = new ArrayList<MetadataRequest>();
|
||||||
|
|
||||||
// Process all plugin groups in the local repository first to see if we get a hit. A developer may have been
|
|
||||||
// developing a plugin locally and installing.
|
|
||||||
//
|
|
||||||
for ( String pluginGroup : request.getPluginGroups() )
|
for ( String pluginGroup : request.getPluginGroups() )
|
||||||
{
|
{
|
||||||
String localPath = getLocalMetadataPath( pluginGroup, localRepository );
|
org.sonatype.aether.metadata.Metadata metadata =
|
||||||
|
new DefaultMetadata( pluginGroup, "maven-metadata.xml", DefaultMetadata.Nature.RELEASE_OR_SNAPSHOT );
|
||||||
|
|
||||||
File groupMetadataFile = new File( localRepository.getBasedir(), localPath );
|
requests.add( new MetadataRequest( metadata, null, REPOSITORY_CONTEXT ) );
|
||||||
|
|
||||||
PluginPrefixResult result =
|
for ( RemoteRepository repository : request.getRepositories() )
|
||||||
resolveFromRepository( request, pluginGroup, groupMetadataFile, localRepository );
|
|
||||||
|
|
||||||
if ( result != null )
|
|
||||||
{
|
{
|
||||||
return result;
|
requests.add( new MetadataRequest( metadata, repository, REPOSITORY_CONTEXT ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, List<ArtifactRepository>> recheck = new HashMap<String, List<ArtifactRepository>>();
|
// initial try, use locally cached metadata
|
||||||
|
|
||||||
// Process all the remote repositories.
|
List<MetadataResult> results = repositorySystem.resolveMetadata( request.getRepositorySession(), requests );
|
||||||
//
|
requests.clear();
|
||||||
for ( String pluginGroup : request.getPluginGroups() )
|
|
||||||
|
PluginPrefixResult result = processResults( request, results, requests );
|
||||||
|
|
||||||
|
if ( result != null )
|
||||||
{
|
{
|
||||||
for ( ArtifactRepository repository : request.getRemoteRepositories() )
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// second try, refetch all (possibly outdated) metadata that wasn't updated in the first attempt
|
||||||
|
|
||||||
|
if ( !request.getRepositorySession().isOffline() && !requests.isEmpty() )
|
||||||
|
{
|
||||||
|
DefaultRepositorySystemSession session =
|
||||||
|
new DefaultRepositorySystemSession( request.getRepositorySession() );
|
||||||
|
session.setUpdatePolicy( RepositoryPolicy.UPDATE_POLICY_ALWAYS );
|
||||||
|
|
||||||
|
results = repositorySystem.resolveMetadata( session, requests );
|
||||||
|
|
||||||
|
return processResults( request, results, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PluginPrefixResult processResults( PluginPrefixRequest request, List<MetadataResult> results,
|
||||||
|
List<MetadataRequest> requests )
|
||||||
|
{
|
||||||
|
for ( MetadataResult res : results )
|
||||||
|
{
|
||||||
|
if ( res.getException() != null )
|
||||||
{
|
{
|
||||||
if ( !isEnabled( repository ) )
|
if ( res.getException() instanceof MetadataNotFoundException )
|
||||||
{
|
{
|
||||||
logger.debug( "Skipped plugin prefix lookup from disabled repository " + repository.getId() );
|
logger.debug( "Could not find " + res.getRequest().getMetadata() + " in "
|
||||||
continue;
|
+ res.getRequest().getRepository() );
|
||||||
|
}
|
||||||
|
else if ( logger.isDebugEnabled() )
|
||||||
|
{
|
||||||
|
logger.warn( "Could not retrieve " + res.getRequest().getMetadata() + " from "
|
||||||
|
+ res.getRequest().getRepository() + ": " + res.getException().getMessage(), res.getException() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logger.warn( "Could not retrieve " + res.getRequest().getMetadata() + " from "
|
||||||
|
+ res.getRequest().getRepository() + ": " + res.getException().getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
org.sonatype.aether.metadata.Metadata metadata = res.getMetadata();
|
||||||
|
|
||||||
|
if ( metadata != null )
|
||||||
|
{
|
||||||
|
ArtifactRepository repository = res.getRequest().getRepository();
|
||||||
|
if ( repository == null )
|
||||||
|
{
|
||||||
|
repository = request.getRepositorySession().getLocalRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
String localPath = getLocalMetadataPath( pluginGroup, repository );
|
PluginPrefixResult result =
|
||||||
|
resolveFromRepository( request, metadata.getGroupId(), metadata.getFile(), repository );
|
||||||
File groupMetadataFile = new File( localRepository.getBasedir(), localPath );
|
|
||||||
|
|
||||||
if ( !request.isOffline() && ( !groupMetadataFile.exists() || request.isForceUpdate() ) )
|
|
||||||
{
|
|
||||||
String remotePath = getRemoteMetadataPath( pluginGroup, repository );
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
repositorySystem.retrieve( repository, groupMetadataFile, remotePath,
|
|
||||||
request.getTransferListener() );
|
|
||||||
}
|
|
||||||
catch ( ArtifactTransferFailedException e )
|
|
||||||
{
|
|
||||||
if ( logger.isDebugEnabled() )
|
|
||||||
{
|
|
||||||
logger.warn( "Failed to retrieve " + remotePath + " from " + repository.getId() + ": "
|
|
||||||
+ e.getMessage(), e );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn( "Failed to retrieve " + remotePath + " from " + repository.getId() + ": "
|
|
||||||
+ e.getMessage() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( ArtifactDoesNotExistException e )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( !request.isOffline() && !request.isForceUpdate() )
|
|
||||||
{
|
|
||||||
List<ArtifactRepository> repos = recheck.get( pluginGroup );
|
|
||||||
if ( repos == null )
|
|
||||||
{
|
|
||||||
repos = new ArrayList<ArtifactRepository>();
|
|
||||||
recheck.put( pluginGroup, repos );
|
|
||||||
}
|
|
||||||
repos.add( repository );
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginPrefixResult result = resolveFromRepository( request, pluginGroup, groupMetadataFile,
|
|
||||||
repository );
|
|
||||||
|
|
||||||
if ( result != null )
|
if ( result != null )
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Retry the remote repositories for which we previously only consulted the possibly outdated local cache.
|
if ( requests != null && !res.isUpdated() )
|
||||||
//
|
|
||||||
for ( String pluginGroup : request.getPluginGroups() )
|
|
||||||
{
|
|
||||||
List<ArtifactRepository> repos = recheck.get( pluginGroup );
|
|
||||||
if ( repos == null )
|
|
||||||
{
|
{
|
||||||
continue;
|
requests.add( res.getRequest() );
|
||||||
}
|
|
||||||
|
|
||||||
for ( ArtifactRepository repository : repos )
|
|
||||||
{
|
|
||||||
String localPath = getLocalMetadataPath( pluginGroup, repository );
|
|
||||||
|
|
||||||
File groupMetadataFile = new File( localRepository.getBasedir(), localPath );
|
|
||||||
|
|
||||||
String remotePath = getRemoteMetadataPath( pluginGroup, repository );
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
repositorySystem.retrieve( repository, groupMetadataFile, remotePath,
|
|
||||||
request.getTransferListener() );
|
|
||||||
}
|
|
||||||
catch ( ArtifactTransferFailedException e )
|
|
||||||
{
|
|
||||||
if ( logger.isDebugEnabled() )
|
|
||||||
{
|
|
||||||
logger.warn( "Failed to retrieve " + remotePath + " from " + repository.getId() + ": "
|
|
||||||
+ e.getMessage(), e );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.warn( "Failed to retrieve " + remotePath + " from " + repository.getId() + ": "
|
|
||||||
+ e.getMessage() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( ArtifactDoesNotExistException e )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginPrefixResult result = resolveFromRepository( request, pluginGroup, groupMetadataFile,
|
|
||||||
repository );
|
|
||||||
|
|
||||||
if ( result != null )
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEnabled( ArtifactRepository repository )
|
|
||||||
{
|
|
||||||
return repository.getReleases().isEnabled() || repository.getSnapshots().isEnabled();
|
|
||||||
}
|
|
||||||
|
|
||||||
private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request, String pluginGroup,
|
private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request, String pluginGroup,
|
||||||
File metadataFile, ArtifactRepository repository )
|
File metadataFile, ArtifactRepository repository )
|
||||||
{
|
{
|
||||||
if ( metadataFile.isFile() )
|
if ( metadataFile != null && metadataFile.isFile() )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -337,14 +294,4 @@ public class DefaultPluginPrefixResolver
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLocalMetadataPath( String groupId, ArtifactRepository repository )
|
|
||||||
{
|
|
||||||
return groupId.replace( '.', '/' ) + "/" + "maven-metadata-" + repository.getId() + ".xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRemoteMetadataPath( String groupId, ArtifactRepository repository )
|
|
||||||
{
|
|
||||||
return groupId.replace( '.', '/' ) + "/" + "maven-metadata.xml";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,9 @@ package org.apache.maven.plugin.prefix.internal;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.plugin.prefix.PluginPrefixResult;
|
import org.apache.maven.plugin.prefix.PluginPrefixResult;
|
||||||
|
import org.sonatype.aether.repository.ArtifactRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the result of a plugin prefix resolution request.
|
* Describes the result of a plugin prefix resolution request.
|
||||||
|
|
|
@ -19,17 +19,15 @@ package org.apache.maven.plugin.version;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Plugin;
|
import org.apache.maven.model.Plugin;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects settings required to resolve the version for a plugin.
|
* Collects settings required to resolve the version for a plugin.
|
||||||
|
@ -47,65 +45,55 @@ public class DefaultPluginVersionRequest
|
||||||
|
|
||||||
private Model pom;
|
private Model pom;
|
||||||
|
|
||||||
private RepositoryRequest repositoryRequest;
|
private List<RemoteRepository> repositories = Collections.emptyList();
|
||||||
|
|
||||||
|
private RepositorySystemSession session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty request.
|
* Creates an empty request.
|
||||||
*/
|
*/
|
||||||
public DefaultPluginVersionRequest()
|
public DefaultPluginVersionRequest()
|
||||||
{
|
{
|
||||||
repositoryRequest = new DefaultRepositoryRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a request by copying settings from the specified repository request.
|
|
||||||
*
|
|
||||||
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
|
|
||||||
*/
|
|
||||||
public DefaultPluginVersionRequest( RepositoryRequest repositoryRequest )
|
|
||||||
{
|
|
||||||
this.repositoryRequest = new DefaultRepositoryRequest( repositoryRequest );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a request for the specified plugin by copying settings from the specified repository request.
|
|
||||||
*
|
|
||||||
* @param The plugin for which to resolve a version, must not be {@code null}.
|
|
||||||
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
|
|
||||||
*/
|
|
||||||
public DefaultPluginVersionRequest( Plugin plugin, RepositoryRequest repositoryRequest )
|
|
||||||
{
|
|
||||||
this.groupId = plugin.getGroupId();
|
|
||||||
this.artifactId = plugin.getArtifactId();
|
|
||||||
this.repositoryRequest = new DefaultRepositoryRequest( repositoryRequest );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a request for the specified plugin by copying settings from the specified build session. If the session
|
* Creates a request for the specified plugin by copying settings from the specified build session. If the session
|
||||||
* has a current project, its plugin artifact repositories will be used as well.
|
* has a current project, its plugin repositories will be used as well.
|
||||||
*
|
*
|
||||||
* @param The plugin for which to resolve a version, must not be {@code null}.
|
* @param plugin The plugin for which to resolve a version, must not be {@code null}.
|
||||||
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
|
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
|
||||||
*/
|
*/
|
||||||
public DefaultPluginVersionRequest( Plugin plugin, MavenSession session )
|
public DefaultPluginVersionRequest( Plugin plugin, MavenSession session )
|
||||||
{
|
{
|
||||||
this.groupId = plugin.getGroupId();
|
setGroupId( plugin.getGroupId() );
|
||||||
this.artifactId = plugin.getArtifactId();
|
setArtifactId( plugin.getArtifactId() );
|
||||||
this.repositoryRequest = new DefaultRepositoryRequest();
|
|
||||||
|
|
||||||
setCache( session.getRepositoryCache() );
|
setRepositorySession( session.getRepositorySession() );
|
||||||
setLocalRepository( session.getLocalRepository() );
|
|
||||||
setOffline( session.isOffline() );
|
|
||||||
setForceUpdate( session.getRequest().isUpdateSnapshots() );
|
|
||||||
setTransferListener( session.getRequest().getTransferListener() );
|
|
||||||
|
|
||||||
MavenProject project = session.getCurrentProject();
|
MavenProject project = session.getCurrentProject();
|
||||||
if ( project != null )
|
if ( project != null )
|
||||||
{
|
{
|
||||||
setRemoteRepositories( project.getPluginArtifactRepositories() );
|
setRepositories( project.getRemotePluginRepositories() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a request for the specified plugin using the given repository session and plugin repositories.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin for which to resolve a version, must not be {@code null}.
|
||||||
|
* @param session The repository session to use, must not be {@code null}.
|
||||||
|
* @param repositories The plugin repositories to query, may be {@code null}.
|
||||||
|
*/
|
||||||
|
public DefaultPluginVersionRequest( Plugin plugin, RepositorySystemSession session, List<RemoteRepository> repositories )
|
||||||
|
{
|
||||||
|
setGroupId( plugin.getGroupId() );
|
||||||
|
setArtifactId( plugin.getArtifactId() );
|
||||||
|
|
||||||
|
setRepositorySession( session );
|
||||||
|
|
||||||
|
setRepositories( repositories );
|
||||||
|
}
|
||||||
|
|
||||||
public String getGroupId()
|
public String getGroupId()
|
||||||
{
|
{
|
||||||
return groupId;
|
return groupId;
|
||||||
|
@ -142,74 +130,33 @@ public class DefaultPluginVersionRequest
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepositoryCache getCache()
|
public List<RemoteRepository> getRepositories()
|
||||||
{
|
{
|
||||||
return repositoryRequest.getCache();
|
return repositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultPluginVersionRequest setCache( RepositoryCache cache )
|
public DefaultPluginVersionRequest setRepositories( List<RemoteRepository> repositories )
|
||||||
{
|
{
|
||||||
repositoryRequest.setCache( cache );
|
if ( repositories != null )
|
||||||
|
{
|
||||||
|
this.repositories = repositories;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.repositories = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactRepository getLocalRepository()
|
public RepositorySystemSession getRepositorySession()
|
||||||
{
|
{
|
||||||
return repositoryRequest.getLocalRepository();
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DefaultPluginVersionRequest setLocalRepository( ArtifactRepository localRepository )
|
public DefaultPluginVersionRequest setRepositorySession( RepositorySystemSession session )
|
||||||
{
|
{
|
||||||
repositoryRequest.setLocalRepository( localRepository );
|
this.session = session;
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ArtifactRepository> getRemoteRepositories()
|
|
||||||
{
|
|
||||||
return repositoryRequest.getRemoteRepositories();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultPluginVersionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
|
|
||||||
{
|
|
||||||
repositoryRequest.setRemoteRepositories( remoteRepositories );
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isOffline()
|
|
||||||
{
|
|
||||||
return repositoryRequest.isOffline();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultPluginVersionRequest setOffline( boolean offline )
|
|
||||||
{
|
|
||||||
repositoryRequest.setOffline( offline );
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isForceUpdate()
|
|
||||||
{
|
|
||||||
return repositoryRequest.isForceUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultPluginVersionRequest setForceUpdate( boolean forceUpdate )
|
|
||||||
{
|
|
||||||
repositoryRequest.setForceUpdate( forceUpdate );
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArtifactTransferListener getTransferListener()
|
|
||||||
{
|
|
||||||
return repositoryRequest.getTransferListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultPluginVersionRequest setTransferListener( ArtifactTransferListener transferListener )
|
|
||||||
{
|
|
||||||
repositoryRequest.setTransferListener( transferListener );
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,9 @@ package org.apache.maven.plugin.version;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryCache;
|
|
||||||
import org.apache.maven.artifact.repository.RepositoryRequest;
|
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.repository.ArtifactTransferListener;
|
import org.sonatype.aether.RepositorySystemSession;
|
||||||
|
import org.sonatype.aether.repository.RemoteRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collects settings required to resolve the version for a plugin.
|
* Collects settings required to resolve the version for a plugin.
|
||||||
|
@ -34,7 +32,6 @@ import org.apache.maven.repository.ArtifactTransferListener;
|
||||||
* @author Benjamin Bentmann
|
* @author Benjamin Bentmann
|
||||||
*/
|
*/
|
||||||
public interface PluginVersionRequest
|
public interface PluginVersionRequest
|
||||||
extends RepositoryRequest
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,80 +81,35 @@ public interface PluginVersionRequest
|
||||||
*/
|
*/
|
||||||
PluginVersionRequest setPom( Model pom );
|
PluginVersionRequest setPom( Model pom );
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicates whether network access to remote repositories has been disabled.
|
|
||||||
*
|
|
||||||
* @return {@code true} if remote access has been disabled, {@code false} otherwise.
|
|
||||||
*/
|
|
||||||
boolean isOffline();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables/disables network access to remote repositories.
|
|
||||||
*
|
|
||||||
* @param offline {@code true} to disable remote access, {@code false} to allow network access.
|
|
||||||
* @return This request, never {@code null}.
|
|
||||||
*/
|
|
||||||
PluginVersionRequest setOffline( boolean offline );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the local repository to use.
|
|
||||||
*
|
|
||||||
* @return The local repository to use or {@code null} if not set.
|
|
||||||
*/
|
|
||||||
ArtifactRepository getLocalRepository();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the local repository to use.
|
|
||||||
*
|
|
||||||
* @param localRepository The local repository to use.
|
|
||||||
* @return This request, never {@code null}.
|
|
||||||
*/
|
|
||||||
PluginVersionRequest setLocalRepository( ArtifactRepository localRepository );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the remote repositories to use.
|
* Gets the remote repositories to use.
|
||||||
*
|
*
|
||||||
* @return The remote repositories to use, never {@code null}.
|
* @return The remote repositories to use, never {@code null}.
|
||||||
*/
|
*/
|
||||||
List<ArtifactRepository> getRemoteRepositories();
|
List<RemoteRepository> getRepositories();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the remote repositories to use. <em>Note:</em> When creating a request from a project, be sure to use the
|
* Sets the remote repositories to use. <em>Note:</em> When creating a request from a project, be sure to use the
|
||||||
* plugin artifact repositories and not the regular artifact repositories.
|
* plugin repositories and not the regular project repositories.
|
||||||
*
|
*
|
||||||
* @param remoteRepositories The remote repositories to use.
|
* @param repositories The remote repositories to use.
|
||||||
* @return This request, never {@code null}.
|
* @return This request, never {@code null}.
|
||||||
*/
|
*/
|
||||||
PluginVersionRequest setRemoteRepositories( List<ArtifactRepository> remoteRepositories );
|
PluginVersionRequest setRepositories( List<RemoteRepository> repositories );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the repository cache to use.
|
* Gets the session to use for repository access.
|
||||||
*
|
*
|
||||||
* @return The repository cache to use or {@code null} if none.
|
* @return The repository session or {@code null} if not set.
|
||||||
*/
|
*/
|
||||||
RepositoryCache getCache();
|
RepositorySystemSession getRepositorySession();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the repository cache to use.
|
* Sets the session to use for repository access.
|
||||||
*
|
*
|
||||||
* @param cache The repository cache to use, may be {@code null}.
|
* @param repositorySession The repository session to use.
|
||||||
* @return This request, never {@code null}.
|
* @return This request, never {@code null}.
|
||||||
*/
|
*/
|
||||||
PluginVersionRequest setCache( RepositoryCache cache );
|
PluginVersionRequest setRepositorySession( RepositorySystemSession repositorySession );
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the listener to notify of transfer events.
|
|
||||||
*
|
|
||||||
* @return The transfer listener or {@code null} if none.
|
|
||||||
*/
|
|
||||||
ArtifactTransferListener getTransferListener();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the listener to notify of transfer events.
|
|
||||||
*
|
|
||||||
* @param transferListener The transfer listener to notify, may be {@code null}.
|
|
||||||
* @return This request, never {@code null}.
|
|
||||||
*/
|
|
||||||
PluginVersionRequest setTransferListener( ArtifactTransferListener transferListener );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue