[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:
Benjamin Bentmann 2010-08-24 22:46:07 +00:00
parent c85a6a4ec2
commit 6c37a89744
156 changed files with 7429 additions and 3180 deletions

View File

@ -13,7 +13,7 @@ The Apache Software Foundation (http://www.apache.org/).
This product includes software (Plexus and Classworlds) developed by
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/).
This product includes software (NekoHTML) developed by

View File

@ -59,6 +59,10 @@
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-file</artifactId>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -195,7 +195,7 @@ Do you want to continue?</input>
<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-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/paramdoc.mdo" />
</target>

View File

@ -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>

View File

@ -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 );
}
}
}

View File

@ -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;
}
}
}

View File

@ -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 );
}
}

View File

@ -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 );
}
}

View File

@ -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 );
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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() );
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -493,7 +493,6 @@ public VersionRange getVersionRange()
public void setVersionRange( VersionRange versionRange )
{
this.versionRange = versionRange;
selectVersionFromNewRangeIfAvailable();
}

View File

@ -69,6 +69,12 @@
<artifactId>wagon-file</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>${aetherVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>easymock</groupId>
<artifactId>easymock</artifactId>

View File

@ -20,50 +20,46 @@
*/
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
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.RepositoryMetadataDeploymentException;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.MetadataBridge;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.RepositorySystem;
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.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
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
extends AbstractLogEnabled
implements ArtifactDeployer
{
@Requirement
private WagonManager wagonManager;
@Requirement
private ArtifactTransformationManager transformationManager;
@Requirement
private RepositoryMetadataManager repositoryMetadataManager;
@Requirement
private RepositorySystem repositorySystem;
private RepositorySystem repoSystem;
@Requirement
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
* correctly.
@ -82,79 +78,78 @@ public void deploy( File source, Artifact artifact, ArtifactRepository deploymen
ArtifactRepository localRepository )
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
File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
if ( !artifactFile.equals( source ) )
for ( ArtifactMetadata metadata : artifact.getMetadataList() )
{
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 );
}
wagonManager.putArtifact( source, artifact, deploymentRepository, getTransferListener() );
// must be after the artifact is installed
for ( ArtifactMetadata metadata : artifact.getMetadataList() )
else if ( metadata instanceof SnapshotArtifactRepositoryMetadata
|| metadata instanceof ArtifactRepositoryMetadata )
{
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()
{
MavenSession session = legacySupport.getSession();
if ( session == null )
{
return null;
}
return TransferListenerAdapter.newAdapter( session.getRequest().getTransferListener() );
}
private ArtifactRepository injectSession( ArtifactRepository repository )
{
RemoteRepository remoteRepo = RepositoryUtils.toRepo( deploymentRepository );
/*
* NOTE: This provides backward-compat with maven-deploy-plugin:2.4 which bypasses the repository factory when
* 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 ( request != null )
if ( metadata.getClass().getName().endsWith( ".internal.RemoteSnapshotMetadata" ) )
{
List<ArtifactRepository> repositories = Arrays.asList( repository );
repositorySystem.injectProxy( repositories, request.getProxies() );
repositorySystem.injectAuthentication( repositories, request.getServers() );
snapshots.put( snapshotKey, (MergeableMetadata) metadata );
}
}
}
return repository;
artifact.setResolvedVersion( result.getArtifacts().iterator().next().getVersion() );
}
}

View File

@ -20,21 +20,27 @@
*/
import java.io.File;
import java.io.IOException;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataInstallationException;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.repository.DefaultLocalRepositoryMaintainerEvent;
import org.apache.maven.repository.LocalRepositoryMaintainer;
import org.apache.maven.repository.LocalRepositoryMaintainerEvent;
import org.apache.maven.repository.legacy.resolver.transform.ArtifactTransformationManager;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.MetadataBridge;
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.plugin.LegacySupport;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
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
@ -44,15 +50,13 @@ public class DefaultArtifactInstaller
extends AbstractLogEnabled
implements ArtifactInstaller
{
@Requirement
private ArtifactTransformationManager transformationManager;
@Requirement
private RepositoryMetadataManager repositoryMetadataManager;
@Requirement( optional = true )
private LocalRepositoryMaintainer localRepositoryMaintainer;
private RepositorySystem repoSystem;
@Requirement
private LegacySupport legacySupport;
/** @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly. */
@Deprecated
public void install( String basedir, String finalName, Artifact artifact, ArtifactRepository localRepository )
@ -67,59 +71,64 @@ public void install( String basedir, String finalName, Artifact artifact, Artifa
public void install( File source, Artifact artifact, ArtifactRepository localRepository )
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 );
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() )
if ( metadata instanceof ProjectArtifactMetadata )
{
destination.getParentFile().mkdirs();
org.sonatype.aether.artifact.Artifact pomArtifact = new SubArtifact( mainArtifact, "", "pom" );
pomArtifact = pomArtifact.setFile( ( (ProjectArtifactMetadata) metadata ).getFile() );
request.addArtifact( pomArtifact );
}
boolean copy =
!destination.exists() || "pom".equals( artifact.getType() )
|| source.lastModified() != destination.lastModified() || source.length() != destination.length();
if ( copy )
else if ( metadata instanceof SnapshotArtifactRepositoryMetadata
|| metadata instanceof ArtifactRepositoryMetadata )
{
getLogger().info( "Installing " + source + " to " + destination );
FileUtils.copyFile( source, destination );
destination.setLastModified( source.lastModified() );
// eaten, handled by repo system
}
else
{
getLogger().info( "Skipped re-installing " + source + " to " + destination + ", seems unchanged" );
request.addMetadata( new MetadataBridge( metadata ) );
}
}
// must be after the artifact is installed
for ( ArtifactMetadata metadata : artifact.getMetadataList() )
{
repositoryMetadataManager.install( metadata, localRepository );
}
// TODO: would like to flush this, but the plugin metadata is added in advance, not as an install/deploy
// transformation
// This would avoid the need to merge and clear out the state during deployment
// artifact.getMetadataList().clear();
try
{
repoSystem.install( session, request );
}
catch ( InstallationException e )
{
throw new ArtifactInstallationException( e.getMessage(), e );
}
if ( localRepositoryMaintainer != null )
{
LocalRepositoryMaintainerEvent event =
new DefaultLocalRepositoryMaintainerEvent( localRepository, artifact, destination );
localRepositoryMaintainer.artifactInstalled( event );
}
}
catch ( IOException e )
/*
* NOTE: Not used by Maven core, only here to provide backward-compat with plugins like the Install Plugin.
*/
if ( artifact.isSnapshot() )
{
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 ) );
}
}
}

View File

@ -6,9 +6,9 @@
* 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
@ -22,7 +22,6 @@
import java.io.Writer;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -30,7 +29,6 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
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.metadata.io.xpp3.MetadataXpp3Reader;
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
@ -49,7 +47,7 @@
/**
* @author Jason van Zyl
*/
@Component( role = RepositoryMetadataManager.class )
@Component(role=RepositoryMetadataManager.class)
public class DefaultRepositoryMetadataManager
extends AbstractLogEnabled
implements RepositoryMetadataManager
@ -60,8 +58,7 @@ public class DefaultRepositoryMetadataManager
@Requirement
private UpdateCheckManager updateCheckManager;
public void resolve( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository )
public void resolve( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
throws RepositoryMetadataResolutionException
{
RepositoryRequest request = new DefaultRepositoryRequest();
@ -73,41 +70,6 @@ public void resolve( RepositoryMetadata metadata, List<ArtifactRepository> remot
public void resolve( RepositoryMetadata metadata, RepositoryRequest request )
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();
List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories();
@ -209,13 +171,7 @@ else if ( updateCheckManager.isUpdateRequired( metadata, repository, file ) )
}
catch ( RepositoryMetadataStoreException e )
{
throw new RepositoryMetadataResolutionException( "Unable to store local copy of metadata: "
+ e.getMessage(), e );
}
if ( cache != null )
{
cache.put( request, cacheKey, new CacheRecord( metadata ) );
throw new RepositoryMetadataResolutionException( "Unable to store local copy of metadata: " + e.getMessage(), e );
}
}
@ -226,130 +182,7 @@ private Date getLocalCopyLastModified( ArtifactRepository localRepository, Repos
return metadataFile.isFile() ? new Date( metadataFile.lastModified() ) : null;
}
private static final class CacheKey
{
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 )
private void mergeMetadata( RepositoryMetadata metadata, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
throws RepositoryMetadataStoreException
{
// TODO: currently this is first wins, but really we should take the latest by comparing either the
@ -378,9 +211,7 @@ private void mergeMetadata( RepositoryMetadata metadata, List<ArtifactRepository
updateSnapshotMetadata( metadata, previousMetadata, selected, localRepository );
}
private void updateSnapshotMetadata( RepositoryMetadata metadata,
Map<ArtifactRepository, Metadata> previousMetadata,
ArtifactRepository selected, ArtifactRepository localRepository )
private void updateSnapshotMetadata( RepositoryMetadata metadata, Map<ArtifactRepository, Metadata> previousMetadata, ArtifactRepository selected, ArtifactRepository localRepository )
throws RepositoryMetadataStoreException
{
// TODO: this could be a lot nicer... should really be in the snapshot transformation?
@ -405,8 +236,7 @@ private void updateSnapshotMetadata( RepositoryMetadata metadata,
}
else
{
if ( ( m.getVersioning() != null ) && ( m.getVersioning().getSnapshot() != null )
&& m.getVersioning().getSnapshot().isLocalCopy() )
if ( ( m.getVersioning() != null ) && ( m.getVersioning().getSnapshot() != null ) && m.getVersioning().getSnapshot().isLocalCopy() )
{
m.getVersioning().getSnapshot().setLocalCopy( false );
metadata.setMetadata( m );
@ -419,14 +249,11 @@ private void updateSnapshotMetadata( RepositoryMetadata metadata,
}
}
private boolean loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository,
ArtifactRepository localRepository, Map<ArtifactRepository, Metadata> previousMetadata )
private boolean loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository, ArtifactRepository localRepository, Map<ArtifactRepository, Metadata> previousMetadata )
{
boolean setRepository = false;
File metadataFile =
new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( repoMetadata,
remoteRepository ) );
File metadataFile = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) );
if ( metadataFile.exists() )
{
@ -488,13 +315,11 @@ protected Metadata readMetadata( File mappingFile )
}
catch ( IOException e )
{
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': "
+ e.getMessage(), e );
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': " + e.getMessage(), e );
}
catch ( XmlPullParserException e )
{
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': "
+ e.getMessage(), e );
throw new RepositoryMetadataReadException( "Cannot read metadata from '" + mappingFile + "': " + e.getMessage(), e );
}
finally
{
@ -505,8 +330,8 @@ protected Metadata readMetadata( File mappingFile )
}
/**
* Ensures the last updated timestamp of the specified metadata does not refer to the future and fixes the local
* metadata if necessary to allow proper merging/updating of metadata during deployment.
* Ensures the last updated timestamp of the specified metadata does not refer to the future and fixes the local metadata if necessary to allow
* proper merging/updating of metadata during deployment.
*/
private void fixTimestamp( File metadataFile, Metadata metadata, Metadata reference )
{
@ -562,8 +387,7 @@ private void fixTimestamp( File metadataFile, Metadata metadata, Metadata refere
}
}
public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws RepositoryMetadataResolutionException
{
File file;
@ -573,8 +397,7 @@ public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository local
}
catch ( TransferFailedException e )
{
throw new RepositoryMetadataResolutionException( metadata + " could not be retrieved from repository: "
+ remoteRepository.getId() + " due to an error: " + e.getMessage(), e );
throw new RepositoryMetadataResolutionException( metadata + " could not be retrieved from repository: " + remoteRepository.getId() + " due to an error: " + e.getMessage(), e );
}
try
@ -591,24 +414,18 @@ public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository local
}
}
private File getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metadata,
ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
private File getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metadata, ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws TransferFailedException
{
File file =
new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata,
remoteRepository ) );
File file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) );
try
{
wagonManager.getArtifactMetadataFromDeploymentRepository( metadata, remoteRepository, file,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
wagonManager.getArtifactMetadataFromDeploymentRepository( metadata, remoteRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
}
catch ( ResourceDoesNotExistException e )
{
getLogger().info( metadata + " could not be found on repository: " + remoteRepository.getId()
+ ", so will be created" );
getLogger().info( metadata + " could not be found on repository: " + remoteRepository.getId() + ", so will be created" );
// delete the local copy so the old details aren't used.
if ( file.exists() )
@ -626,8 +443,7 @@ private File getArtifactMetadataFromDeploymentRepository( ArtifactMetadata metad
return file;
}
public void deploy( ArtifactMetadata metadata, ArtifactRepository localRepository,
ArtifactRepository deploymentRepository )
public void deploy( ArtifactMetadata metadata, ArtifactRepository localRepository, ArtifactRepository deploymentRepository )
throws RepositoryMetadataDeploymentException
{
File file;
@ -640,8 +456,7 @@ public void deploy( ArtifactMetadata metadata, ArtifactRepository localRepositor
}
catch ( TransferFailedException e )
{
throw new RepositoryMetadataDeploymentException( metadata + " could not be retrieved from repository: "
+ deploymentRepository.getId() + " due to an error: " + e.getMessage(), e );
throw new RepositoryMetadataDeploymentException( metadata + " could not be retrieved from repository: " + deploymentRepository.getId() + " due to an error: " + e.getMessage(), e );
}
if ( file.isFile() )
@ -659,9 +474,7 @@ public void deploy( ArtifactMetadata metadata, ArtifactRepository localRepositor
else
{
// It's a POM - we don't need to retrieve it first
file =
new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
}
try

View File

@ -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();
}
}
}

View File

@ -1,26 +1,21 @@
package org.apache.maven.artifact.resolver;
/*
* 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.
* 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.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
@ -37,57 +32,43 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.metadata.ResolutionGroup;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
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.execution.MavenSession;
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.MetadataResolutionRequest;
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.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
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
*/
@Component( role = ArtifactResolver.class )
@Component(role = ArtifactResolver.class)
public class DefaultArtifactResolver
implements ArtifactResolver
{
@Requirement
@Requirement
private Logger logger;
@Requirement
private WagonManager wagonManager;
@Requirement
private ArtifactTransformationManager transformationManager;
@Requirement
protected ArtifactFactory artifactFactory;
@ -99,16 +80,16 @@ public class DefaultArtifactResolver
@Requirement
private ArtifactMetadataSource source;
@Requirement
private PlexusContainer container;
@Requirement( optional = true )
private LocalRepositoryMaintainer localRepositoryMaintainer;
@Requirement
private LegacySupport legacySupport;
@Requirement
private RepositorySystem repoSystem;
private final Executor executor;
public DefaultArtifactResolver()
@ -141,13 +122,32 @@ protected void finalize()
}
}
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 )
{
if ( session != null )
{
request.setOffline( session.isOffline() );
request.setForceUpdate( session.getRequest().isUpdateSnapshots() );
request.setTransferListener( session.getRequest().getTransferListener() );
}
}
@ -163,297 +163,125 @@ private void injectSession2( ArtifactResolutionRequest request, MavenSession ses
}
}
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository, TransferListener resolutionListener )
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository, TransferListener resolutionListener )
throws ArtifactResolutionException, ArtifactNotFoundException
{
RepositoryRequest request = new DefaultRepositoryRequest();
injectSession1( request, legacySupport.getSession() );
request.setLocalRepository( localRepository );
request.setRemoteRepositories( remoteRepositories );
resolve( artifact, request, resolutionListener, false );
resolve( artifact, remoteRepositories, getSession( localRepository ) );
}
public void resolveAlways( Artifact artifact, List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository )
public void resolveAlways( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException
{
RepositoryRequest request = new DefaultRepositoryRequest();
injectSession1( request, legacySupport.getSession() );
request.setLocalRepository( localRepository );
request.setRemoteRepositories( remoteRepositories );
resolve( artifact, request, null, true );
resolve( artifact, remoteRepositories, getSession( localRepository ) );
}
private void resolve( Artifact artifact, RepositoryRequest request, TransferListener downloadMonitor,
boolean force )
private void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session )
throws ArtifactResolutionException, ArtifactNotFoundException
{
if ( artifact == null )
{
return;
}
File destination;
if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
{
File systemFile = artifact.getFile();
if ( systemFile == null )
{
throw new ArtifactNotFoundException( "System artifact: " + artifact + " has no file attached",
artifact );
throw new ArtifactNotFoundException( "System artifact: " + artifact + " has no file attached", artifact );
}
if ( !systemFile.exists() )
{
throw new ArtifactNotFoundException( "System artifact: " + artifact + " not found in path: "
+ systemFile, artifact );
throw new ArtifactNotFoundException( "System artifact: " + artifact + " not found in path: " + systemFile, artifact );
}
if ( !systemFile.isFile() )
{
throw new ArtifactNotFoundException( "System artifact: " + artifact + " is not a file: " + systemFile,
artifact );
throw new ArtifactNotFoundException( "System artifact: " + artifact + " is not a file: " + systemFile, artifact );
}
artifact.setResolved( true );
return;
}
ArtifactRepository localRepository = request.getLocalRepository();
List<ArtifactRepository> remoteRepositories = request.getRemoteRepositories();
if ( !artifact.isResolved() )
{
// ----------------------------------------------------------------------
// 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.
// ----------------------------------------------------------------------
ArtifactResult result;
artifact = localRepository.find( artifact );
if ( artifact.isResolved() )
try
{
return;
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact( RepositoryUtils.toArtifact( artifact ) );
artifactRequest.setRepositories( RepositoryUtils.toRepos( remoteRepositories ) );
result = repoSystem.resolveArtifact( session, artifactRequest );
}
transformationManager.transformForResolve( artifact, request );
destination = artifact.getFile();
if ( !request.isOffline() && ( force || !destination.exists() || isMutable( artifact ) ) )
catch ( org.sonatype.aether.resolution.ArtifactResolutionException e )
{
try
{
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 )
if ( e.getCause() instanceof org.sonatype.aether.transfer.ArtifactNotFoundException )
{
throw new ArtifactNotFoundException( e.getMessage(), artifact, remoteRepositories, e );
}
catch ( TransferFailedException e )
else
{
throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories, e );
}
}
if ( destination.exists() )
{
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 );
}
artifact.selectVersion( result.getArtifact().getVersion() );
artifact.setFile( result.getArtifact().getFile() );
artifact.setResolved( true );
}
}
private boolean isMutable( Artifact artifact )
{
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,
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository,
remoteRepositories, source, filter );
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository, remoteRepositories, source, filter );
}
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source )
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository,
remoteRepositories, source, null );
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, null );
}
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter )
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository,
remoteRepositories, source, filter, null );
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, null );
}
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository,
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories, source, null );
}
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository,
ArtifactMetadataSource source,
List<ResolutionListener> listeners )
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository,
ArtifactMetadataSource source, List<ResolutionListener> listeners )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, Collections.EMPTY_MAP, localRepository,
remoteRepositories, source, null, listeners );
}
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter,
List<ResolutionListener> listeners )
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners )
throws ArtifactResolutionException, ArtifactNotFoundException
{
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository,
remoteRepositories, source, filter, listeners, null );
return resolveTransitively( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners, null );
}
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact,
Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories,
ArtifactMetadataSource source, ArtifactFilter filter,
List<ResolutionListener> listeners,
public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
throws ArtifactResolutionException, ArtifactNotFoundException
{
@ -461,7 +289,7 @@ public ArtifactResolutionResult resolveTransitively( Set<Artifact> artifacts, Ar
.setArtifact( originatingArtifact )
.setResolveRoot( false )
// This is required by the surefire plugin
.setArtifactDependencies( artifacts )
.setArtifactDependencies( artifacts )
.setManagedVersionMap( managedVersions )
.setLocalRepository( localRepository )
.setRemoteRepositories( remoteRepositories )
@ -497,10 +325,10 @@ public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
Set<Artifact> artifacts = request.getArtifactDependencies();
Map managedVersions = request.getManagedVersionMap();
List<ResolutionListener> listeners = request.getListeners();
ArtifactFilter collectionFilter = request.getCollectionFilter();
ArtifactFilter collectionFilter = request.getCollectionFilter();
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
if ( source == null )
{
@ -532,12 +360,12 @@ public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
// 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
// as well as its dependencies.
if ( request.isResolveRoot() /* && rootArtifact.getFile() == null */ )
{
{
try
{
resolve( rootArtifact, request, transferListener, false );
resolve( rootArtifact, request.getRemoteRepositories(), session );
}
catch ( ArtifactResolutionException e )
{
@ -609,7 +437,7 @@ public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
return result;
}
}
if ( artifacts == null || artifacts.isEmpty() )
{
if ( request.isResolveRoot() )
@ -617,19 +445,18 @@ public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
result.addArtifact( rootArtifact );
}
return result;
}
}
// After the collection we will have the artifact object in the result but they will not be resolved yet.
result =
artifactCollector.collect( artifacts, rootArtifact, managedVersions, collectionRequest, source,
collectionFilter, listeners, null );
// 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
// appropriately.
if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations()
|| result.hasCircularDependencyExceptions() )
if ( result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions() )
{
return result;
}
@ -646,11 +473,8 @@ public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
if ( resolutionFilter == null || resolutionFilter.include( artifact ) )
{
ArtifactResolutionRequest childRequest = new ArtifactResolutionRequest( request );
childRequest.setRemoteRepositories( node.getRemoteRepositories() );
executor.execute( new ResolveTask( classLoader, latch, artifact, transferListener, childRequest,
result ) );
executor.execute( new ResolveTask( classLoader, latch, artifact, session,
node.getRemoteRepositories(), result ) );
}
else
{
@ -671,19 +495,18 @@ public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
// We want to send the root artifact back in the result but we need to do this after the other dependencies
// have been resolved.
if ( request.isResolveRoot() )
{
{
// Add the root artifact (as the first artifact to retain logical order of class path!)
Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();
allArtifacts.add( rootArtifact );
allArtifacts.addAll( result.getArtifacts() );
result.setArtifacts( allArtifacts );
}
}
return result;
}
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories,
ArtifactRepository localRepository )
public void resolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException, ArtifactNotFoundException
{
resolve( artifact, remoteRepositories, localRepository, null );
@ -719,21 +542,20 @@ private class ResolveTask
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;
public ResolveTask( ClassLoader classLoader, CountDownLatch latch, Artifact artifact,
TransferListener transferListener, ArtifactResolutionRequest request,
ArtifactResolutionResult result )
public ResolveTask( ClassLoader classLoader, CountDownLatch latch, Artifact artifact, RepositorySystemSession session,
List<ArtifactRepository> remoteRepositories, ArtifactResolutionResult result )
{
this.classLoader = classLoader;
this.latch = latch;
this.artifact = artifact;
this.transferListener = transferListener;
this.request = request;
this.session = session;
this.remoteRepositories = remoteRepositories;
this.result = result;
}
@ -742,7 +564,7 @@ public void run()
try
{
Thread.currentThread().setContextClassLoader( classLoader );
resolve( artifact, request, transferListener, false );
resolve( artifact, remoteRepositories, session );
}
catch ( ArtifactNotFoundException anfe )
{

View File

@ -94,6 +94,7 @@ private ProjectBuildingRequest injectSession( ProjectBuildingRequest request )
MavenSession session = legacySupport.getSession();
if ( session != null )
{
request.setRepositorySession( session.getRepositorySession() );
request.setOffline( session.isOffline() );
request.setSystemProperties( session.getSystemProperties() );
if ( request.getUserProperties().isEmpty() )
@ -108,7 +109,6 @@ private ProjectBuildingRequest injectSession( ProjectBuildingRequest request )
request.setMirrors( req.getMirrors() );
request.setProxies( req.getProxies() );
request.setRemoteRepositories( req.getRemoteRepositories() );
request.setTransferListener( req.getTransferListener() );
request.setForceUpdate( req.isUpdateSnapshots() );
}
}

View File

@ -83,7 +83,6 @@ private void injectSession( ArtifactResolutionRequest request )
request.setServers( session.getRequest().getServers() );
request.setMirrors( session.getRequest().getMirrors() );
request.setProxies( session.getRequest().getProxies() );
request.setTransferListener( session.getRequest().getTransferListener() );
}
}

View File

@ -29,11 +29,33 @@
import org.apache.maven.artifact.factory.ArtifactFactory;
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.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
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.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>
@ -53,6 +75,14 @@ protected void setUp()
super.setUp();
artifactFactory = lookup( ArtifactFactory.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
@ -297,4 +327,33 @@ protected void deleteArtifact( Artifact artifact, ArtifactRepository repository
}
}
}
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;
}
}

View File

@ -27,6 +27,7 @@
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.codehaus.plexus.PlexusTestCase;
/**
@ -129,6 +130,7 @@ protected MavenProject getProjectWithDependencies( File pom )
configuration.setRemoteRepositories( Arrays.asList( new ArtifactRepository[] {} ) );
configuration.setProcessPlugins( false );
configuration.setResolveDependencies( true );
initRepoSession( configuration );
try
{
@ -157,8 +159,17 @@ protected MavenProject getProject( File pom )
{
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
configuration.setLocalRepository( getLocalRepository() );
initRepoSession( configuration );
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 );
}
}

View File

@ -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;
}
}

View File

@ -26,17 +26,9 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.*;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
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
@ -49,8 +41,6 @@ public class EmptyLifecycleExecutor
{
public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException
{
return new MavenExecutionPlan(null, null, null, new DefaultLifecycles() );
}
@ -102,14 +92,10 @@ private Plugin newPlugin( String artifactId, String... goals )
}
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 )
throws LifecycleExecutionException
{
return Collections.emptyList();
}

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -24,6 +24,9 @@
import org.apache.maven.artifact.Artifact;
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
extends AbstractMavenProjectTestCase
@ -33,11 +36,15 @@ public class ProjectClasspathTest
public void setUp()
throws Exception
{
ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" );
DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class);
pomReader.setArtifactResolver( resolver );
projectBuilder = lookup( ProjectBuilder.class, "classpath" );
// the metadata source looks up the default impl, so we have to trick it
getContainer().addComponent( projectBuilder, ProjectBuilder.class, "default" );
repositorySystem = lookup( RepositorySystem.class );
}

View File

@ -24,11 +24,17 @@
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.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.Repository;
import org.apache.maven.model.RepositoryPolicy;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.PlexusTestCase;
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
/**
* Tests {@link LegacyRepositorySystem}.
@ -107,6 +113,12 @@ public void testThatASystemScopedDependencyIsNotResolvedFromRepositories()
.setRemoteRepositories( getRemoteRepositories() )
.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 );
resolutionErrorHandler.throwErrors( request, result );
assertEquals( 2, result.getArtifacts().size() );

View File

@ -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() );
}
}

View File

@ -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;
}
}

View File

@ -30,16 +30,6 @@ under the License.
<role-hint>default</role-hint>
<field-name>logger</field-name>
</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>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<role-hint>default</role-hint>
@ -65,17 +55,16 @@ under the License.
<role-hint>default</role-hint>
<field-name>container</field-name>
</requirement>
<requirement>
<role>org.apache.maven.repository.LocalRepositoryMaintainer</role>
<role-hint>default</role-hint>
<field-name>localRepositoryMaintainer</field-name>
<optional>true</optional>
</requirement>
<requirement>
<role>org.apache.maven.plugin.LegacySupport</role>
<role-hint>default</role-hint>
<field-name>legacySupport</field-name>
</requirement>
<requirement>
<role>org.sonatype.aether.RepositorySystem</role>
<role-hint>default</role-hint>
<field-name>repoSystem</field-name>
</requirement>
</requirements>
</component>
</components>

View File

@ -2,8 +2,8 @@
<plexus>
<components>
<component>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
<implementation>org.apache.maven.project.EmptyLifecycleExecutor</implementation>
<role>org.apache.maven.lifecycle.LifeCyclePluginAnalyzer</role>
<implementation>org.apache.maven.project.EmptyLifecyclePluginAnalyzer</implementation>
</component>
</components>
</plexus>

View File

@ -53,6 +53,15 @@
<groupId>org.apache.maven</groupId>
<artifactId>maven-model-builder</artifactId>
</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 -->
<dependency>
<groupId>org.sonatype.spice</groupId>

View File

@ -19,6 +19,8 @@
* under the License.
*/
import java.util.Set;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
public interface ArtifactFilterManager
@ -39,4 +41,7 @@ public interface ArtifactFilterManager
* @param artifactId
*/
void excludeArtifact( String artifactId );
}
Set<String> getCoreArtifactExcludes();
}

View File

@ -59,6 +59,7 @@ public class DefaultArtifactFilterManager
artifacts.add( "plexus:plexus-container-default" );
artifacts.add( "org.sonatype.spice:spice-inject-plexus" );
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-compat" );
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-toolchain" );
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
@ -120,18 +123,11 @@ public ArtifactFilter getArtifactFilter()
/**
* Returns the artifact filter for the standard core artifacts.
*
* @see org.apache.maven.ArtifactFilterManager#getExtensionArtifactFilter()
* @see org.apache.maven.ArtifactFilterManager#getExtensionDependencyFilter()
*/
public ArtifactFilter getCoreArtifactFilter()
{
Set<String> excludes = new LinkedHashSet<String>( DEFAULT_EXCLUSIONS );
for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
{
delegate.addCoreExcludes( excludes );
}
return new ExclusionSetFilter( excludes );
return new ExclusionSetFilter( getCoreArtifactExcludes() );
}
private List<ArtifactFilterManagerDelegate> getDelegates()
@ -154,4 +150,16 @@ public void excludeArtifact( String 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;
}
}

View File

@ -1,22 +1,18 @@
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.
* 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;
@ -33,6 +29,7 @@
import java.util.Map;
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.ExecutionEvent;
import org.apache.maven.execution.MavenExecutionRequest;
@ -47,6 +44,7 @@
import org.apache.maven.model.building.ModelProblemUtils;
import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.building.UrlModelSource;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.DuplicateProjectException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
@ -56,6 +54,13 @@
import org.apache.maven.project.ProjectSorter;
import org.apache.maven.repository.DelegatingLocalArtifactRepository;
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.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@ -63,11 +68,39 @@
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
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
*/
@Component( role = Maven.class )
@Component(role = Maven.class)
public class DefaultMaven
implements Maven
{
@ -78,7 +111,6 @@ public class DefaultMaven
@Requirement
protected ProjectBuilder projectBuilder;
@Requirement
private LifecycleStarter lifecycleStarter;
@ -91,6 +123,21 @@ public class DefaultMaven
@Requirement
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 )
{
MavenExecutionResult result;
@ -113,22 +160,25 @@ public MavenExecutionResult execute( MavenExecutionRequest request )
processResult( new DefaultMavenExecutionResult(),
new InternalErrorException( "Internal error: " + e, e ) );
}
finally
{
legacySupport.setSession( null );
}
return result;
}
@SuppressWarnings( { "ThrowableInstanceNeverThrown", "ThrowableResultOfMethodCallIgnored" } )
@SuppressWarnings({"ThrowableInstanceNeverThrown", "ThrowableResultOfMethodCallIgnored"})
private MavenExecutionResult doExecute( MavenExecutionRequest request )
{
//TODO: Need a general way to inject standard properties
if ( request.getStartTime() != null )
{
request.getSystemProperties().put( "${build.timestamp}",
new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) );
}
request.getSystemProperties().put( "${build.timestamp}", new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) );
}
request.setStartTime( new Date() );
MavenExecutionResult result = new DefaultMavenExecutionResult();
try
@ -142,10 +192,13 @@ private MavenExecutionResult doExecute( MavenExecutionRequest request )
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository =
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
{
@ -161,12 +214,14 @@ private MavenExecutionResult doExecute( MavenExecutionRequest request )
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;
try
{
projects = getProjectsForMavenReactor( request );
projects = getProjectsForMavenReactor( request );
}
catch ( ProjectBuildingException e )
{
@ -176,20 +231,23 @@ private MavenExecutionResult doExecute( MavenExecutionRequest request )
session.setProjects( projects );
result.setTopologicallySortedProjects( session.getProjects() );
result.setProject( session.getTopLevelProject() );
try
{
Map<String, MavenProject> projectMap;
projectMap = getProjectMap( session.getProjects() );
// Desired order of precedence for local artifact repositories
//
// Reactor
// Workspace
// 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 )
{
@ -226,7 +284,7 @@ private MavenExecutionResult doExecute( MavenExecutionRequest request )
session.setProjectDependencyGraph( projectDependencyGraph );
}
catch ( CycleDetectedException e )
{
{
String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();
ProjectCycleException error = new ProjectCycleException( message, e );
@ -261,7 +319,133 @@ private MavenExecutionResult doExecute( MavenExecutionRequest request )
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 )
throws LocalRepositoryNotAccessibleException
{
@ -334,7 +518,7 @@ private MavenExecutionResult processResult( MavenExecutionResult result, Throwab
return result;
}
private List<MavenProject> getProjectsForMavenReactor( MavenExecutionRequest request )
throws ProjectBuildingException
{
@ -352,8 +536,8 @@ private List<MavenProject> getProjectsForMavenReactor( MavenExecutionRequest req
request.setProjectPresent( false );
return projects;
}
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
collectProjects( projects, files, request );
return projects;
}
@ -405,8 +589,7 @@ private void collectProjects( List<MavenProject> projects, List<File> files, Mav
{
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
List<ProjectBuildingResult> results =
projectBuilder.build( files, request.isRecursive(), projectBuildingRequest );
List<ProjectBuildingResult> results = projectBuilder.build( files, request.isRecursive(), projectBuildingRequest );
boolean problems = false;
@ -423,8 +606,7 @@ private void collectProjects( List<MavenProject> projects, List<File> files, Mav
for ( ModelProblem problem : result.getProblems() )
{
String location = ModelProblemUtils.formatLocation( problem, result.getProjectId() );
logger.warn( problem.getMessage()
+ ( StringUtils.isNotEmpty( location ) ? " @ " + location : "" ) );
logger.warn( problem.getMessage() + ( StringUtils.isNotEmpty( location ) ? " @ " + location : "" ) );
}
problems = true;

View File

@ -42,7 +42,7 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
@Component( role = ProjectDependenciesResolver.class )
@Component(role = ProjectDependenciesResolver.class)
public class DefaultProjectDependenciesResolver
implements ProjectDependenciesResolver
{
@ -97,15 +97,15 @@ private Set<Artifact> resolveImpl( Collection<? extends MavenProject> projects,
return resolved;
}
if ( ( scopesToCollect == null || scopesToCollect.isEmpty() )
&& ( scopesToResolve == null || scopesToResolve.isEmpty() ) )
if ( ( scopesToCollect == null || scopesToCollect.isEmpty() ) &&
( scopesToResolve == null || scopesToResolve.isEmpty() ) )
{
return resolved;
}
/*
Logic for transitive global exclusions
Logic for transitve global exclusions
List<String> exclusions = new ArrayList<String>();
@ -126,8 +126,7 @@ private Set<Artifact> resolveImpl( Collection<? extends MavenProject> projects,
if ( ! exclusions.isEmpty() )
{
filter = new AndArtifactFilter( Arrays.asList( new ArtifactFilter[]{ new ExcludesArtifactFilter( exclusions ),
scopeFilter } ) );
filter = new AndArtifactFilter( Arrays.asList( new ArtifactFilter[]{ new ExcludesArtifactFilter( exclusions ), scopeFilter } ) );
}
else
{
@ -141,11 +140,10 @@ private Set<Artifact> resolveImpl( Collection<? extends MavenProject> projects,
collectionScopeFilter = new CumulativeScopeArtifactFilter( collectionScopeFilter, resolutionScopeFilter );
ArtifactResolutionRequest request =
new ArtifactResolutionRequest().setResolveRoot( false ).setResolveTransitively( true )
.setCollectionFilter( collectionScopeFilter ).setResolutionFilter( resolutionScopeFilter )
.setLocalRepository( session.getLocalRepository() ).setOffline( session.isOffline() )
.setForceUpdate( session.getRequest().isUpdateSnapshots() ).setCache( session.getRepositoryCache() );
request.setTransferListener( session.getRequest().getTransferListener() );
new ArtifactResolutionRequest().setResolveRoot( false ).setResolveTransitively( true ).setCollectionFilter(
collectionScopeFilter ).setResolutionFilter( resolutionScopeFilter ).setLocalRepository(
session.getLocalRepository() ).setOffline( session.isOffline() ).setForceUpdate(
session.getRequest().isUpdateSnapshots() );
request.setServers( session.getRequest().getServers() );
request.setMirrors( session.getRequest().getMirrors() );
request.setProxies( session.getRequest().getProxies() );

View File

@ -19,39 +19,40 @@
* under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
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.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
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
*/
public class ReactorArtifactRepository
extends LocalArtifactRepository
class ReactorReader
implements WorkspaceReader
{
private Map<String, MavenProject> projectsByGAV;
private Map<String, List<MavenProject>> projectsByGA;
private final int hashCode;
private WorkspaceRepository repository;
@SuppressWarnings( { "ConstantConditions" } )
public ReactorArtifactRepository( Map<String, MavenProject> reactorProjects )
public ReactorReader( Map<String, MavenProject> reactorProjects )
{
projectsByGAV = reactorProjects;
hashCode = ( reactorProjects != null ) ? reactorProjects.keySet().hashCode() : 0;
projectsByGA = new HashMap<String, List<MavenProject>>( reactorProjects.size() * 2 );
for ( MavenProject project : reactorProjects.values() )
@ -68,35 +69,18 @@ public ReactorArtifactRepository( Map<String, MavenProject> reactorProjects )
projects.add( project );
}
}
@Override
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;
repository = new WorkspaceRepository( "reactor", new HashSet<String>( projectsByGAV.keySet() ) );
}
private File find( MavenProject project, Artifact artifact )
{
if ( "pom".equals( artifact.getType() ) )
if ( "pom".equals( artifact.getExtension() ) )
{
return project.getFile();
}
Artifact projectArtifact = findMatchingArtifact( project, artifact );
org.apache.maven.artifact.Artifact projectArtifact = findMatchingArtifact( project, artifact );
if ( hasArtifactFileFromPackagePhase( projectArtifact ) )
{
@ -125,24 +109,120 @@ else if ( !project.hasCompletedPhase( "package" ) )
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();
}
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 )
{
String key = ArtifactUtils.versionlessKey( artifact );
String key = artifact.getGroupId() + ':' + artifact.getArtifactId();
List<MavenProject> projects = projectsByGA.get( key );
if ( projects == null || projects.isEmpty() )
@ -163,148 +243,9 @@ public List<String> findVersions( Artifact artifact )
return Collections.unmodifiableList( versions );
}
@Override
public String getId()
public WorkspaceRepository getRepository()
{
return "reactor";
}
@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;
return repository;
}
}

View File

@ -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 );
}
}
}

View File

@ -64,6 +64,11 @@ public String getExtension()
return extension;
}
public void setExtension( String extension )
{
this.extension = extension;
}
public String getType()
{
return type;
@ -97,6 +102,11 @@ public boolean isIncludesDependencies()
return includesDependencies;
}
public void setIncludesDependencies( boolean includesDependencies )
{
this.includesDependencies = includesDependencies;
}
public String getLanguage()
{
if ( language == null )
@ -107,8 +117,19 @@ public String getLanguage()
return language;
}
public void setLanguage( String language )
{
this.language = language;
}
public boolean isAddedToClasspath()
{
return addedToClasspath;
}
public void setAddedToClasspath( boolean addedToClasspath )
{
this.addedToClasspath = addedToClasspath;
}
}

View File

@ -24,11 +24,10 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.ArtifactTransferListener;
/**
* Collects basic settings to access the repository system.
*
*
* @author Benjamin Bentmann
*/
public class DefaultRepositoryRequest
@ -43,10 +42,6 @@ public class DefaultRepositoryRequest
private List<ArtifactRepository> remoteRepositories;
private RepositoryCache cache;
private ArtifactTransferListener transferListener;
/**
* Creates an empty repository request.
*/
@ -57,7 +52,7 @@ public DefaultRepositoryRequest()
/**
* Creates a shallow copy of the specified repository request.
*
*
* @param repositoryRequest The repository request to copy from, must not be {@code null}.
*/
public DefaultRepositoryRequest( RepositoryRequest repositoryRequest )
@ -65,16 +60,13 @@ public DefaultRepositoryRequest( RepositoryRequest repositoryRequest )
setLocalRepository( repositoryRequest.getLocalRepository() );
setRemoteRepositories( repositoryRequest.getRemoteRepositories() );
setOffline( repositoryRequest.isOffline() );
setCache( repositoryRequest.getCache() );
setForceUpdate( repositoryRequest.isForceUpdate() );
setTransferListener( repositoryRequest.getTransferListener() );
}
public static RepositoryRequest getRepositoryRequest( MavenSession session, MavenProject project )
{
RepositoryRequest request = new DefaultRepositoryRequest();
request.setCache( session.getRepositoryCache() );
request.setLocalRepository( session.getLocalRepository() );
if ( project != null )
{
@ -82,7 +74,6 @@ public static RepositoryRequest getRepositoryRequest( MavenSession session, Mave
}
request.setOffline( session.isOffline() );
request.setForceUpdate( session.getRequest().isUpdateSnapshots() );
request.setTransferListener( session.getRequest().getTransferListener() );
return request;
}
@ -140,28 +131,4 @@ public DefaultRepositoryRequest setRemoteRepositories( List<ArtifactRepository>
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;
}
}

View File

@ -25,6 +25,7 @@
*
* @author Benjamin Bentmann
*/
@Deprecated
public interface RepositoryCache
{

View File

@ -21,8 +21,6 @@
import java.util.List;
import org.apache.maven.repository.ArtifactTransferListener;
/**
* Collects basic settings to access the repository system.
*
@ -94,34 +92,4 @@ public interface RepositoryRequest
*/
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 );
}

View File

@ -29,7 +29,6 @@
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.artifact.repository.RepositoryRequest;
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.Proxy;
import org.apache.maven.settings.Server;
@ -55,8 +54,6 @@ public class ArtifactResolutionRequest
private List<ArtifactRepository> remoteRepositories;
private RepositoryCache cache;
private ArtifactFilter collectionFilter;
private ArtifactFilter resolutionFilter;
@ -66,8 +63,6 @@ public class ArtifactResolutionRequest
// This is like a filter but overrides all transitive versions
private Map managedVersionMap;
private ArtifactTransferListener transferListener;
private boolean resolveRoot = true;
@ -92,10 +87,8 @@ public ArtifactResolutionRequest( RepositoryRequest request )
{
setLocalRepository( request.getLocalRepository() );
setRemoteRepositories( request.getRemoteRepositories() );
setCache( request.getCache() );
setOffline( request.isOffline() );
setForceUpdate( request.isForceUpdate() );
setTransferListener( request.getTransferListener() );
}
public Artifact getArtifact()
@ -237,17 +230,6 @@ public boolean isResolveTransitively()
{
return resolveTransitively;
}
public ArtifactTransferListener getTransferListener()
{
return transferListener;
}
public ArtifactResolutionRequest setTransferListener( ArtifactTransferListener transferListener )
{
this.transferListener = transferListener;
return this;
}
public String toString()
{
@ -263,13 +245,11 @@ public String toString()
public RepositoryCache getCache()
{
return cache;
return null;
}
public ArtifactResolutionRequest setCache( RepositoryCache cache )
{
this.cache = cache;
return this;
}

View File

@ -21,7 +21,7 @@
import java.io.File;
import org.apache.maven.artifact.Artifact;
import org.sonatype.aether.artifact.Artifact;
/**
* @author Benjamin Bentmann
@ -49,12 +49,12 @@ public String getArtifactId()
public String getType()
{
return artifact.getType();
return artifact.getExtension();
}
public String getClassifier()
{
return artifact.hasClassifier() ? artifact.getClassifier() : "";
return artifact.getClassifier();
}
public String getVersion()
@ -70,7 +70,7 @@ public File getFile()
@Override
public String toString()
{
return artifact.getId();
return artifact.toString();
}
}

View File

@ -21,10 +21,10 @@
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
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

View File

@ -28,7 +28,6 @@
import java.util.Random;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.classrealm.ClassRealmRequest.RealmType;
import org.apache.maven.model.Model;
@ -43,11 +42,12 @@
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.logging.Logger;
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
* public for technical reasons, it is not part of the public API. In particular, this interface can be changed or
* deleted without prior notice.
* 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
*/
@ -133,7 +133,7 @@ private ClassRealm createRealm( String baseRealmId, RealmType type, ClassLoader
{
for ( Artifact artifact : artifacts )
{
artifactIds.add( artifact.getId() );
artifactIds.add( getId( artifact ) );
if ( artifact.getFile() != null )
{
constituents.add( new ArtifactClassRealmConstituent( artifact ) );
@ -260,6 +260,9 @@ private void importMavenApi( ClassRealm importingRealm )
// maven-*
importingRealm.importFrom( coreRealm, "org.apache.maven" );
// aether
importingRealm.importFrom( coreRealm, "org.sonatype.aether" );
// plexus-classworlds
importingRealm.importFrom( coreRealm, "org.codehaus.plexus.classworlds" );
@ -334,11 +337,21 @@ private static String getKey( Plugin plugin, boolean extension )
+ 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 )
{
return constituent.getGroupId() + ':' + constituent.getArtifactId() + ':' + constituent.getType()
+ ( StringUtils.isNotEmpty( constituent.getClassifier() ) ? ':' + constituent.getClassifier() : "" ) + ':'
+ constituent.getVersion();
return getId( constituent.getGroupId(), constituent.getArtifactId(), constituent.getType(),
constituent.getClassifier(), 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()

View File

@ -26,14 +26,15 @@
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.model.Profile;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
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
@ -42,7 +43,7 @@ public class DefaultMavenExecutionRequest
implements MavenExecutionRequest
{
private RepositoryCache repositoryCache = new SessionRepositoryCache();
private RepositoryCache repositoryCache = new DefaultRepositoryCache();
private ArtifactRepository localRepository;
@ -110,7 +111,7 @@ public class DefaultMavenExecutionRequest
private List<String> inactiveProfiles;
private ArtifactTransferListener transferListener;
private TransferListener transferListener;
private int loggingLevel = LOGGING_LEVEL_INFO;
@ -350,7 +351,7 @@ public List<String> getInactiveProfiles()
return inactiveProfiles;
}
public ArtifactTransferListener getTransferListener()
public TransferListener getTransferListener()
{
return transferListener;
}
@ -592,7 +593,7 @@ public MavenExecutionRequest setInteractiveMode( boolean interactive )
return this;
}
public MavenExecutionRequest setTransferListener( ArtifactTransferListener transferListener )
public MavenExecutionRequest setTransferListener( TransferListener transferListener )
{
this.transferListener = transferListener;
@ -953,7 +954,6 @@ public ProjectBuildingRequest getProjectBuildingRequest()
projectBuildingRequest.setUserProperties( getUserProperties() );
projectBuildingRequest.setRemoteRepositories( getRemoteRepositories() );
projectBuildingRequest.setPluginArtifactRepositories( getPluginArtifactRepositories() );
projectBuildingRequest.setRepositoryCache( getRepositoryCache() );
projectBuildingRequest.setOffline( isOffline() );
projectBuildingRequest.setForceUpdate( isUpdateSnapshots() );
projectBuildingRequest.setServers( getServers() );
@ -964,7 +964,6 @@ public ProjectBuildingRequest getProjectBuildingRequest()
projectBuildingRequest.setProfiles( getProfiles() );
projectBuildingRequest.setProcessPlugins( true );
projectBuildingRequest.setBuildStartTime( getStartTime() );
projectBuildingRequest.setTransferListener( getTransferListener() );
}
return projectBuildingRequest;

View File

@ -25,7 +25,7 @@
import java.util.List;
import java.util.Map;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.project.MavenProject;
/** @author Jason van Zyl */
@ -36,7 +36,7 @@ public class DefaultMavenExecutionResult
private List<MavenProject> topologicallySortedProjects;
private ArtifactResolutionResult artifactResolutionResult;
private DependencyResolutionResult dependencyResolutionResult;
private List<Throwable> exceptions;
@ -66,14 +66,14 @@ public List<MavenProject> getTopologicallySortedProjects()
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;
}

View File

@ -26,14 +26,14 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.model.Profile;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.ArtifactTransferListener;
import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Server;
import org.codehaus.plexus.logging.Logger;
import org.sonatype.aether.RepositoryCache;
import org.sonatype.aether.transfer.TransferListener;
/**
* @author Jason van Zyl
@ -170,8 +170,8 @@ public interface MavenExecutionRequest
boolean isShowErrors();
// Transfer listeners
MavenExecutionRequest setTransferListener( ArtifactTransferListener transferListener );
ArtifactTransferListener getTransferListener();
MavenExecutionRequest setTransferListener( TransferListener transferListener );
TransferListener getTransferListener();
// Logging
MavenExecutionRequest setLoggingLevel( int loggingLevel );

View File

@ -21,7 +21,7 @@
import java.util.List;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.project.MavenProject;
/**
@ -35,8 +35,8 @@ public interface MavenExecutionResult
MavenExecutionResult setTopologicallySortedProjects( List<MavenProject> projects );
List<MavenProject> getTopologicallySortedProjects();
MavenExecutionResult setArtifactResolutionResult( ArtifactResolutionResult result );
ArtifactResolutionResult getArtifactResolutionResult();
MavenExecutionResult setDependencyResolutionResult( DependencyResolutionResult result );
DependencyResolutionResult getDependencyResolutionResult();
// for each exception
// - knowing what artifacts are missing

View File

@ -36,6 +36,7 @@
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.sonatype.aether.RepositorySystemSession;
/**
* @author Jason van Zyl
@ -50,6 +51,8 @@ public class MavenSession
private MavenExecutionResult result;
private RepositorySystemSession repositorySession;
private final Settings settings;
private Properties executionProperties;
@ -115,12 +118,14 @@ public MavenSession( PlexusContainer container, MavenExecutionRequest request, M
setProjects( projects );
}
public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenExecutionResult result )
public MavenSession( PlexusContainer container, RepositorySystemSession repositorySession, MavenExecutionRequest request,
MavenExecutionResult result )
{
this.container = container;
this.request = request;
this.result = result;
this.settings = new SettingsAdapter( request );
this.repositorySession = repositorySession;
}
public void setProjects( List<MavenProject> projects )
@ -180,9 +185,10 @@ public Map<String, Object> lookupMap( String role )
return container.lookupMap( role );
}
@Deprecated
public RepositoryCache getRepositoryCache()
{
return request.getRepositoryCache();
return null;
}
public ArtifactRepository getLocalRepository()
@ -277,7 +283,7 @@ public MavenProject getCurrentProject()
public ProjectBuildingRequest getProjectBuildingRequest()
{
return request.getProjectBuildingRequest();
return request.getProjectBuildingRequest().setRepositorySession( getRepositorySession() );
}
public List<String> getPluginGroups()
@ -382,4 +388,10 @@ public void setParallel( boolean parallel )
{
this.parallel = parallel;
}
public RepositorySystemSession getRepositorySession()
{
return repositorySession;
}
}

View File

@ -21,14 +21,7 @@
import org.apache.maven.lifecycle.internal.BuilderCommon;
import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
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 java.util.ArrayList;
@ -55,9 +48,6 @@ public DefaultSchedules( List<Scheduling> schedules )
}
public List<ExecutionPlanItem> createExecutionPlanItem( MavenProject mavenProject, List<MojoExecution> executions )
throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
{
BuilderCommon.attachToThread( mavenProject );

View File

@ -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;
/*
* 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.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.DefaultSchedules;
@ -147,9 +141,10 @@ private void setupMojoExections( MavenSession session, MavenProject project,
if ( mojoDescriptor == null )
{
mojoDescriptor = pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(),
DefaultRepositoryRequest.getRepositoryRequest(
session, project ) );
mojoDescriptor =
pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(),
project.getRemotePluginRepositories(),
session.getRepositorySession() );
mojoExecution.setMojoDescriptor( mojoDescriptor );
}
@ -251,10 +246,11 @@ private Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSessio
if ( lifecycle == null )
{
throw new LifecyclePhaseNotFoundException( "Unknown lifecycle phase \"" + lifecyclePhase
+ "\". You must specify a valid lifecycle phase" + " or a goal in the format <plugin-prefix>:<goal> or"
+ " <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: "
+ defaultLifeCycles.getLifecyclePhaseList() + ".", lifecyclePhase );
throw new LifecyclePhaseNotFoundException(
"Unknown lifecycle phase \"" + lifecyclePhase + "\". You must specify a valid lifecycle phase" +
" or a goal in the format <plugin-prefix>:<goal> or" +
" <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: " +
defaultLifeCycles.getLifecyclePhaseList() + ".", lifecyclePhase );
}
/*
@ -309,9 +305,8 @@ private Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSessio
for ( String goal : execution.getGoals() )
{
MojoDescriptor mojoDescriptor =
pluginManager.getMojoDescriptor( plugin, goal,
DefaultRepositoryRequest.getRepositoryRequest( session,
project ) );
pluginManager.getMojoDescriptor( plugin, goal, project.getRemotePluginRepositories(),
session.getRepositorySession() );
Map<Integer, List<MojoExecution>> phaseBindings = mappings.get( mojoDescriptor.getPhase() );
if ( phaseBindings != null )
@ -464,8 +459,8 @@ private void finalizeMojoConfiguration( MojoExecution mojoExecution )
{
parameterConfiguration = new Xpp3Dom( parameterConfiguration, parameter.getName() );
if ( StringUtils.isEmpty( parameterConfiguration.getAttribute( "implementation" ) )
&& StringUtils.isNotEmpty( parameter.getImplementation() ) )
if ( StringUtils.isEmpty( parameterConfiguration.getAttribute( "implementation" ) ) &&
StringUtils.isNotEmpty( parameter.getImplementation() ) )
{
parameterConfiguration.setAttribute( "implementation", parameter.getImplementation() );
}
@ -488,7 +483,8 @@ public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession
PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
{
calculateForkedExecutions( mojoExecution, session, session.getCurrentProject(), new HashSet<MojoDescriptor>() );
calculateForkedExecutions( mojoExecution, session, session.getCurrentProject(), new HashSet<MojoDescriptor>() );
}
@ -556,8 +552,8 @@ private List<MojoExecution> calculateForkedLifecycle( MojoExecution mojoExecutio
{
MojoDescriptor forkedMojoDescriptor =
pluginManager.getMojoDescriptor( forkedExecution.getPlugin(), forkedExecution.getGoal(),
DefaultRepositoryRequest.getRepositoryRequest( session,
project ) );
project.getRemotePluginRepositories(),
session.getRepositorySession() );
forkedExecution.setMojoDescriptor( forkedMojoDescriptor );
}

View File

@ -1,39 +1,41 @@
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
* 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
* 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.
* 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.ProjectDependenciesResolver;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
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.lifecycle.LifecycleExecutionException;
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.ProjectDependenciesResolver;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
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.*;
@ -47,11 +49,12 @@
* <p/>
* 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
{
@Requirement
private ProjectDependenciesResolver projectDependenciesResolver;
private ProjectDependenciesResolver dependenciesResolver;
@Requirement
private Logger logger;
@ -59,14 +62,14 @@ public class LifecycleDependencyResolver
@Requirement
private ArtifactFactory artifactFactory;
@SuppressWarnings( { "UnusedDeclaration" } )
@SuppressWarnings({"UnusedDeclaration"})
public LifecycleDependencyResolver()
{
}
public LifecycleDependencyResolver( ProjectDependenciesResolver projectDependenciesResolver, Logger logger )
{
this.projectDependenciesResolver = projectDependenciesResolver;
this.dependenciesResolver = projectDependenciesResolver;
this.logger = logger;
}
@ -136,87 +139,112 @@ private void resolveProjectDependencies( MavenProject project, Collection<String
}
Set<Artifact> artifacts =
getProjectDependencies( project, scopesToCollect, scopesToResolve, session, aggregating,
projectArtifacts );
getDependencies( project, scopesToCollect, scopesToResolve, session, aggregating, projectArtifacts );
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,
Collection<String> scopesToResolve, MavenSession session,
boolean aggregating, Set<Artifact> projectArtifacts )
private Set<Artifact> getDependencies( MavenProject project, Collection<String> scopesToCollect,
Collection<String> scopesToResolve, MavenSession session,
boolean aggregating, Set<Artifact> projectArtifacts )
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
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,
scopesToResolve, session, projectArtifacts );
logger.warn( "The following dependencies could not be resolved at this point of the build"
+ " 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
{
/*
* 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 );
throw new LifecycleExecutionException( null, project, e );
}
return artifacts;
}
catch ( ArtifactResolutionException e )
{
throw new LifecycleExecutionException( null, project, e );
}
catch ( ArtifactNotFoundException e )
{
throw new LifecycleExecutionException( null, project, e );
}
}
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() ) )
Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
if ( result.getDependencyGraph() != null && !result.getDependencyGraph().getChildren().isEmpty() )
{
logger.warn( "The following artifacts could not be resolved at this point of the build"
+ " but seem to be part of the reactor:" );
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;
RepositoryUtils.toArtifacts( artifacts, result.getDependencyGraph().getChildren(),
Collections.singletonList( project.getArtifact().getId() ), collectionFilter );
}
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 );
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 ) )
{
return false;
@ -237,4 +265,73 @@ private Set<String> getReactorProjectKeys( Collection<MavenProject> projects )
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;
}
}
}

View File

@ -66,7 +66,9 @@ public void resolveMissingPluginVersions( MavenProject project, MavenSession ses
{
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() );
}
versions.put( plugin.getKey(), plugin.getVersion() );
@ -82,7 +84,9 @@ public void resolveMissingPluginVersions( MavenProject project, MavenSession ses
plugin.setVersion( versions.get( plugin.getKey() ) );
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() );
}
}

View File

@ -19,8 +19,6 @@
* 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.model.Dependency;
import org.apache.maven.model.Plugin;
@ -202,17 +200,16 @@ else if ( numTokens == 2 )
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
// this plugin and see what's specified as the latest release.
//
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
@ -234,10 +231,12 @@ public Plugin findPluginForPrefix( String prefix, MavenSession session )
return plugin;
}
private void resolvePluginVersion( Plugin plugin, RepositoryRequest repositoryRequest )
private void resolvePluginVersion( Plugin plugin, MavenSession session, MavenProject project )
throws PluginVersionResolutionException
{
PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, repositoryRequest );
PluginVersionRequest versionRequest =
new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
project.getRemotePluginRepositories() );
plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() );
}

View File

@ -27,7 +27,7 @@
import java.util.List;
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.Model;
import org.apache.maven.model.Plugin;
@ -54,7 +54,7 @@ public class DefaultLifecycleBindingsInjector
private LifecycleBindingsMerger merger = new LifecycleBindingsMerger();
@Requirement
private LifecycleExecutor lifecycle;
private LifeCyclePluginAnalyzer lifecycle;
public void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector problems )
{

View File

@ -1,30 +1,29 @@
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.
* 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.RepositoryRequest;
import java.util.List;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.repository.RemoteRepository;
/**
* @author Jason van Zyl
@ -32,12 +31,13 @@
public interface BuildPluginManager
{
// 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,
InvalidPluginDescriptorException;
// 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,
MojoNotFoundException, InvalidPluginDescriptorException;

View File

@ -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;
}
}

View File

@ -1,28 +1,24 @@
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.
* 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.ByteArrayOutputStream;
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.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -32,11 +28,13 @@
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.annotations.Component;
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: remove the coreArtifactFilterManager
@Component( role = BuildPluginManager.class )
@Component(role = BuildPluginManager.class)
public class DefaultBuildPluginManager
implements BuildPluginManager
{
@ -51,19 +49,18 @@ public class DefaultBuildPluginManager
private LegacySupport legacySupport;
/**
*
*
* @param plugin
* @param repositoryRequest
* @return PluginDescriptor The component descriptor for the Maven plugin.
* @throws PluginNotFoundException The plugin could not be found in any repositories.
* @throws PluginResolutionException The plugin could be found but could not be resolved.
* @throws InvalidPluginDescriptorException
* @throws InvalidPluginDescriptorException
*/
public PluginDescriptor loadPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
InvalidPluginDescriptorException
public PluginDescriptor loadPlugin( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException
{
return mavenPluginManager.getPluginDescriptor( plugin, repositoryRequest );
return mavenPluginManager.getPluginDescriptor( plugin, repositories, session );
}
// ----------------------------------------------------------------------
@ -175,9 +172,9 @@ public void executeMojo( MavenSession session, MojoExecution mojoExecution )
/**
* TODO pluginDescriptor classRealm and artifacts are set as a side effect of this
* 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
{
ClassRealm pluginRealm = pluginDescriptor.getClassRealm();
@ -192,11 +189,12 @@ public ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginD
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,
MojoNotFoundException, InvalidPluginDescriptorException
{
return mavenPluginManager.getMojoDescriptor( plugin, goal, repositoryRequest );
return mavenPluginManager.getMojoDescriptor( plugin, goal, repositories, session );
}
}

View File

@ -25,11 +25,11 @@
import java.util.List;
import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.ExtensionDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.annotations.Component;
import org.sonatype.aether.artifact.Artifact;
/**
* Default extension realm cache implementation. Assumes cached data does not change.

View File

@ -22,19 +22,18 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
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.project.MavenProject;
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
@ -46,36 +45,67 @@ public class DefaultPluginArtifactsCache
{
private static class CacheKey
implements Key
{
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;
public CacheKey( Plugin plugin, RepositoryRequest repositoryRequest, ArtifactFilter extensionArtifactFilter )
public CacheKey( Plugin plugin, DependencyFilter extensionFilter, List<RemoteRepository> repositories,
RepositorySystemSession session )
{
this.plugin = plugin.clone();
this.repositories.add( repositoryRequest.getLocalRepository() );
this.repositories.addAll( repositoryRequest.getRemoteRepositories() );
this.extensionArtifactFilter = extensionArtifactFilter;
workspace = CacheUtils.getWorkspace( session );
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.filter = extensionFilter;
int hash = 17;
hash = hash * 31 + pluginHashCode( plugin );
hash = hash * 31 + repositories.hashCode();
hash = hash * 31 + ( extensionArtifactFilter != null ? extensionArtifactFilter.hashCode() : 0 );
hash = hash * 31 + CacheUtils.pluginHashCode( plugin );
hash = hash * 31 + hash( workspace );
hash = hash * 31 + hash( localRepo );
hash = hash * 31 + CacheUtils.repositoriesHashCode( repositories );
hash = hash * 31 + hash( extensionFilter );
this.hashCode = hash;
}
@Override
public String toString()
{
return plugin.getId();
}
@Override
public int hashCode()
{
return hashCode;
}
private static int hash( Object obj )
{
return obj != null ? obj.hashCode() : 0;
}
@Override
public boolean equals( Object o )
{
@ -89,34 +119,43 @@ public boolean equals( Object o )
return false;
}
CacheKey other = (CacheKey) o;
CacheKey that = (CacheKey) o;
return pluginEquals( plugin, other.plugin ) && eq( repositories, other.repositories )
&& eq( extensionArtifactFilter, other.extensionArtifactFilter );
return CacheUtils.pluginEquals( plugin, that.plugin ) && eq( workspace, that.workspace )
&& 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,
List<Artifact> pluginArtifacts )
public CacheRecord get( Key key )
{
return cache.get( key );
}
public CacheRecord put( Key key, List<Artifact> pluginArtifacts )
{
if ( pluginArtifacts == null )
{
throw new NullPointerException();
}
CacheKey key = new CacheKey( plugin, repositoryRequest, extensionArtifactFilter );
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 =
@ -134,102 +173,12 @@ public void flush()
protected static int pluginHashCode( Plugin plugin )
{
int hash = 17;
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;
return CacheUtils.pluginHashCode( plugin );
}
protected static boolean pluginEquals( Plugin a, Plugin b )
{
return eq( a.getGroupId(), b.getGroupId() ) //
&& 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;
return CacheUtils.pluginEquals( a, b );
}
public void register( MavenProject project, CacheRecord record )

View File

@ -21,19 +21,19 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
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.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.annotations.Component;
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
@ -57,14 +57,9 @@ public void flush()
descriptors.clear();
}
public Key createKey( Plugin plugin, RepositoryRequest repositoryRequest )
public Key createKey( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
{
return new CacheKey( plugin, repositoryRequest );
}
public void put( Key cacheKey, PluginDescriptor pluginDescriptor )
{
descriptors.put( cacheKey, clone( pluginDescriptor ) );
return new CacheKey( plugin, repositories, session );
}
public PluginDescriptor get( Key cacheKey )
@ -72,6 +67,11 @@ public PluginDescriptor get( Key cacheKey )
return clone( descriptors.get( cacheKey ) );
}
public void put( Key cacheKey, PluginDescriptor pluginDescriptor )
{
descriptors.put( cacheKey, clone( pluginDescriptor ) );
}
private static PluginDescriptor clone( PluginDescriptor original )
{
PluginDescriptor clone = null;
@ -129,25 +129,42 @@ private static final class CacheKey
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;
public CacheKey( Plugin plugin, RepositoryRequest repositoryRequest )
public CacheKey( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
{
groupId = plugin.getGroupId();
artifactId = plugin.getArtifactId();
version = plugin.getVersion();
repositories = new ArrayList<ArtifactRepository>( repositoryRequest.getRemoteRepositories().size() + 1 );
repositories.add( repositoryRequest.getLocalRepository() );
repositories.addAll( repositoryRequest.getRemoteRepositories() );
workspace = CacheUtils.getWorkspace( session );
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 );
}
}
int hash = 17;
hash = hash * 31 + groupId.hashCode();
hash = hash * 31 + artifactId.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;
}
@ -172,8 +189,10 @@ public boolean equals( Object obj )
CacheKey that = (CacheKey) obj;
return this.artifactId.equals( that.artifactId ) && this.groupId.equals( that.groupId )
&& this.version.equals( that.version ) && repositoriesEquals( this.repositories, that.repositories );
return eq( this.artifactId, that.artifactId ) && eq( this.groupId, that.groupId )
&& eq( this.version, that.version ) && eq( this.localRepo, that.localRepo )
&& eq( this.workspace, that.workspace )
&& CacheUtils.repositoriesEquals( this.repositories, that.repositories );
}
@Override
@ -182,61 +201,9 @@ public String toString()
return groupId + ':' + artifactId + ':' + version;
}
private static int repositoryHashCode( ArtifactRepository repository )
private static int hash( Object obj )
{
int result = 17;
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;
return obj != null ? obj.hashCode() : 0;
}
private static <T> boolean eq( T s1, T s2 )

View File

@ -21,20 +21,20 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
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.project.MavenProject;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
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.
@ -45,45 +45,76 @@ public class DefaultPluginRealmCache
{
protected static class CacheKey
implements Key
{
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 List<String> parentImports;
private final ArtifactFilter filter;
private final DependencyFilter filter;
private final int hashCode;
public CacheKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
DependencyFilter dependencyFilter, List<RemoteRepository> repositories,
RepositorySystemSession session )
{
this.plugin = plugin.clone();
this.repositories.add( localRepository );
this.repositories.addAll( remoteRepositories );
this.workspace = CacheUtils.getWorkspace( session );
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.parentImports = ( parentImports != null ) ? parentImports : Collections.<String> emptyList();
this.filter = dependencyFilter;
int hash = 17;
hash = hash * 31 + pluginHashCode( plugin );
hash = hash * 31 + repositories.hashCode();
hash = hash * 31 + ( parentRealm != null ? parentRealm.hashCode() : 0 );
hash = hash * 31 + CacheUtils.pluginHashCode( plugin );
hash = hash * 31 + hash( workspace );
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 + ( dependencyFilter != null ? dependencyFilter.hashCode() : 0 );
hash = hash * 31 + hash( dependencyFilter );
this.hashCode = hash;
}
@Override
public String toString()
{
return plugin.getId();
}
@Override
public int hashCode()
{
return hashCode;
}
private static int hash( Object obj )
{
return obj != null ? obj.hashCode() : 0;
}
@Override
public boolean equals( Object o )
{
@ -97,40 +128,45 @@ public boolean equals( Object o )
return false;
}
CacheKey other = (CacheKey) o;
CacheKey that = (CacheKey) o;
return parentRealm == other.parentRealm && pluginEquals( plugin, other.plugin )
&& eq( repositories, other.repositories ) && eq( filter, other.filter )
&& eq( parentImports, other.parentImports );
return parentRealm == that.parentRealm && CacheUtils.pluginEquals( plugin, that.plugin )
&& eq( workspace, that.workspace ) && eq( localRepo, that.localRepo )
&& 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,
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
public Key createKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
DependencyFilter dependencyFilter, List<RemoteRepository> repositories,
RepositorySystemSession session )
{
return cache.get( new CacheKey( plugin, parentRealm, parentImports, dependencyFilter, localRepository,
remoteRepositories ) );
return new CacheKey( plugin, parentRealm, parentImports, dependencyFilter, repositories, session );
}
public CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm,
List<Artifact> pluginArtifacts )
public CacheRecord get( Key key )
{
return cache.get( key );
}
public CacheRecord put( Key key, ClassRealm pluginRealm, List<Artifact> pluginArtifacts )
{
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 ) )
{
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 );
@ -147,105 +183,12 @@ public void flush()
protected static int pluginHashCode( Plugin plugin )
{
int hash = 17;
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;
return CacheUtils.pluginHashCode( plugin );
}
protected static boolean pluginEquals( Plugin a, Plugin b )
{
return eq( a.getGroupId(), b.getGroupId() ) //
&& 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;
return CacheUtils.pluginEquals( a, b );
}
public void register( MavenProject project, CacheRecord record )

View File

@ -21,10 +21,10 @@
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.project.ExtensionDescriptor;
import org.apache.maven.project.MavenProject;
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

View File

@ -24,12 +24,10 @@
public class InvalidPluginDescriptorException
extends Exception
{
private List<String> errors;
public InvalidPluginDescriptorException( String message, List<String> errors )
{
super( toMessage( message, errors ) );
this.errors = errors;
}
private static String toMessage( String message, List<String> errors )

View File

@ -20,6 +20,7 @@
*/
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
@ -48,4 +49,11 @@ public interface LegacySupport
*/
MavenSession getSession();
/**
* Gets the currently active repository session.
*
* @return The currently active repository session or {@code null} if none.
*/
RepositorySystemSession getRepositorySession();
}

View File

@ -21,12 +21,13 @@
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.model.Plugin;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
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
@ -43,11 +44,12 @@ public interface MavenPluginManager
* 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 repositoryRequest The repository request to use for resolving the plugin's main artifact, must not be
* {@code null}.
* @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
* 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}.
*/
PluginDescriptor getPluginDescriptor( Plugin plugin, RepositoryRequest repositoryRequest )
PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException;
/**
@ -55,11 +57,13 @@ PluginDescriptor getPluginDescriptor( Plugin plugin, RepositoryRequest repositor
*
* @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 repositoryRequest The repository request to use for resolving the plugin's main artifact, must not be
* {@code null}.
* @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
* 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}.
*/
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories,
RepositorySystemSession session )
throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
InvalidPluginDescriptorException;
@ -76,7 +80,7 @@ MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest
* @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
*/
void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
List<String> imports, ArtifactFilter filter )
List<String> imports, DependencyFilter filter )
throws PluginResolutionException, PluginContainerException;
/**

View File

@ -21,11 +21,12 @@
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.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
@ -38,6 +39,14 @@
public interface PluginArtifactsCache
{
/**
* A cache key.
*/
interface Key
{
// marker interface for cache keys
}
public static class CacheRecord
{
@ -50,10 +59,12 @@ public CacheRecord( List<Artifact> artifacts )
}
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,
List<Artifact> pluginArtifacts );
CacheRecord get( Key key );
CacheRecord put( Key key, List<Artifact> pluginArtifacts );
void flush();

View File

@ -19,9 +19,12 @@
* under the License.
*/
import org.apache.maven.artifact.repository.RepositoryRequest;
import java.util.List;
import org.apache.maven.model.Plugin;
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
@ -44,11 +47,11 @@ interface Key
// 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();

View File

@ -28,12 +28,9 @@ public class PluginDescriptorParsingException
extends Exception
{
private Plugin plugin;
public PluginDescriptorParsingException( Plugin plugin, String descriptorLocation, Throwable e )
{
super( createMessage( plugin, descriptorLocation, e ), e );
this.plugin = plugin;
}
private static String createMessage( Plugin plugin, String descriptorLocation, Throwable e )

View File

@ -229,6 +229,10 @@ else if ( expression.startsWith( "project" ) || expression.startsWith( "pom" ) )
e );
}
}
else if ( expression.equals( "repositorySystemSession" ) )
{
value = session.getRepositorySession();
}
else if ( expression.equals( "mojo" ) )
{
value = mojoExecution;

View File

@ -22,17 +22,18 @@
import java.util.List;
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.project.MavenProject;
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
* technical reasons, it is not part of the public API. In particular, this interface can be changed or deleted without
* prior notice.
*
*
* @author Igor Fedorenko
* @author Benjamin Bentmann
*/
@ -42,6 +43,7 @@ public interface PluginRealmCache
public static class CacheRecord
{
public final ClassRealm realm;
public final List<Artifact> artifacts;
public CacheRecord( ClassRealm realm, List<Artifact> artifacts )
@ -51,14 +53,20 @@ public CacheRecord( ClassRealm realm, List<Artifact> artifacts )
}
}
CacheRecord get( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories );
/**
* A cache key.
*/
interface Key
{
// marker interface for cache keys
}
CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
ArtifactFilter dependencyFilter, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories, ClassRealm pluginRealm,
List<Artifact> pluginArtifacts );
Key createKey( Plugin plugin, ClassLoader parentRealm, List<String> parentImports,
DependencyFilter dependencyFilter, List<RemoteRepository> repositories, RepositorySystemSession session );
CacheRecord get( Key key );
CacheRecord put( Key key, ClassRealm pluginRealm, List<Artifact> pluginArtifacts );
void flush();
@ -66,7 +74,7 @@ CacheRecord put( Plugin plugin, ClassLoader parentRealm, List<String> parentImpo
* 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
* cache.
*
*
* @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}.
*/

View File

@ -19,8 +19,6 @@
* under the License.
*/
import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.model.Plugin;
/**
@ -30,15 +28,15 @@
* @version $Id$
*/
public class PluginResolutionException
extends AbstractArtifactResolutionException
extends Exception
{
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(),
e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getType(), null, e.getRemoteRepositories(), null,
e );
super( "Plugin " + plugin.getId() + " or one of its dependencies could not be resolved: " + cause.getMessage(),
cause );
this.plugin = plugin;
}
@ -46,4 +44,5 @@ public Plugin getPlugin()
{
return plugin;
}
}

View File

@ -22,6 +22,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
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
@ -55,4 +56,10 @@ public MavenSession getSession()
return session.get();
}
public RepositorySystemSession getRepositorySession()
{
MavenSession session = getSession();
return ( session != null ) ? session.getRepositorySession() : null;
}
}

View File

@ -28,18 +28,16 @@
import java.io.PrintStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import org.apache.maven.RepositoryUtils;
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.execution.MavenSession;
import org.apache.maven.model.Plugin;
@ -86,6 +84,12 @@
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
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
@ -120,17 +124,17 @@ public class DefaultMavenPluginManager
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
{
PluginDescriptorCache.Key cacheKey = pluginDescriptorCache.createKey( plugin, repositoryRequest );
PluginDescriptorCache.Key cacheKey = pluginDescriptorCache.createKey( plugin, repositories, session );
PluginDescriptor pluginDescriptor = pluginDescriptorCache.get( cacheKey );
if ( pluginDescriptor == null )
{
Artifact pluginArtifact =
pluginDependenciesResolver.resolve( plugin, new ArtifactResolutionRequest( repositoryRequest ) );
RepositoryUtils.toArtifact( pluginDependenciesResolver.resolve( plugin, repositories, session ) );
pluginDescriptor = extractPluginDescriptor( pluginArtifact, plugin );
@ -239,11 +243,12 @@ private PluginDescriptor parsePluginDescriptor( InputStream is, Plugin plugin, S
}
}
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,
InvalidPluginDescriptorException
{
PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin, repositoryRequest );
PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin, repositories, session );
MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal );
@ -256,16 +261,18 @@ public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryR
}
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
{
Plugin plugin = pluginDescriptor.getPlugin();
MavenProject project = session.getCurrentProject();
PluginRealmCache.CacheRecord cacheRecord =
pluginRealmCache.get( plugin, parent, imports, filter, session.getLocalRepository(),
project.getPluginArtifactRepositories() );
PluginRealmCache.Key cacheKey =
pluginRealmCache.createKey( plugin, parent, imports, filter, project.getRemotePluginRepositories(),
session.getRepositorySession() );
PluginRealmCache.CacheRecord cacheRecord = pluginRealmCache.get( cacheKey );
if ( cacheRecord != null )
{
@ -277,16 +284,14 @@ public synchronized void setupPluginRealm( PluginDescriptor pluginDescriptor, Ma
createPluginRealm( pluginDescriptor, session, parent, imports, filter );
cacheRecord =
pluginRealmCache.put( plugin, parent, imports, filter, session.getLocalRepository(),
project.getPluginArtifactRepositories(), pluginDescriptor.getClassRealm(),
pluginDescriptor.getArtifacts() );
pluginRealmCache.put( cacheKey, pluginDescriptor.getClassRealm(), pluginDescriptor.getArtifacts() );
}
pluginRealmCache.register( project, cacheRecord );
}
private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
List<String> imports, ArtifactFilter filter )
List<String> imports, DependencyFilter filter )
throws PluginResolutionException, PluginContainerException
{
Plugin plugin = pluginDescriptor.getPlugin();
@ -305,42 +310,32 @@ private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession
MavenProject project = session.getCurrentProject();
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setLocalRepository( session.getLocalRepository() );
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() );
DependencyFilter dependencyFilter = project.getExtensionDependencyFilter();
dependencyFilter = AndDependencyFilter.newInstance( dependencyFilter, filter );
ArtifactFilter dependencyFilter = project.getExtensionArtifactFilter();
if ( dependencyFilter == null )
DependencyNode root =
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;
}
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 )
Artifact artifact = it.next();
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.setArtifacts( exposedPluginArtifacts );

View File

@ -19,28 +19,37 @@
* under the License.
*/
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.ArtifactFilterManager;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.RepositoryRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
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
@ -55,29 +64,32 @@ public class DefaultPluginDependenciesResolver
implements PluginDependenciesResolver
{
@Requirement
protected RepositorySystem repositorySystem;
private static final String REPOSITORY_CONTEXT = "plugin";
@Requirement
private ResolutionErrorHandler resolutionErrorHandler;
private Logger logger;
@Requirement
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
{
Artifact pluginArtifact = repositorySystem.createPluginArtifact( plugin );
request.setArtifact( pluginArtifact );
request.setResolveRoot( true );
request.setResolveTransitively( false );
ArtifactResolutionResult result = repositorySystem.resolve( request );
Artifact pluginArtifact = toArtifact( plugin, session );
try
{
resolutionErrorHandler.throwErrors( request, result );
ArtifactRequest request = new ArtifactRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT );
pluginArtifact = repoSystem.resolveArtifact( session, request ).getArtifact();
}
catch ( ArtifactResolutionException e )
{
@ -87,96 +99,113 @@ public Artifact resolve( Plugin plugin, ArtifactResolutionRequest request )
return pluginArtifact;
}
public List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
ArtifactFilter dependencyFilter )
public DependencyNode resolve( Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter,
List<RemoteRepository> repositories, RepositorySystemSession session )
throws PluginResolutionException
{
if ( pluginArtifact == null )
{
pluginArtifact = repositorySystem.createPluginArtifact( plugin );
pluginArtifact = toArtifact( plugin, session );
}
Set<Artifact> overrideArtifacts = new LinkedHashSet<Artifact>();
for ( Dependency dependency : plugin.getDependencies() )
{
if ( !Artifact.SCOPE_SYSTEM.equals( dependency.getScope() ) )
{
dependency.setScope( Artifact.SCOPE_RUNTIME );
}
overrideArtifacts.add( repositorySystem.createDependencyArtifact( dependency ) );
}
DependencyFilter collectionFilter = new ScopeDependencyFilter( "provided", "test" );
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();
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 );
DependencyNode node;
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 )
{
throw new PluginResolutionException( plugin, e );
}
List<Artifact> pluginArtifacts = new ArrayList<Artifact>( result.getArtifacts() );
listener.removeBannedDependencies( pluginArtifacts );
addPlexusUtils( pluginArtifacts, plugin, request );
return pluginArtifacts;
return node;
}
// backward-compatibility with Maven 2.x
private void addPlexusUtils( List<Artifact> pluginArtifacts, Plugin plugin, RepositoryRequest repositoryRequest )
throws PluginResolutionException
class GraphLogger
implements DependencyVisitor
{
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 =
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
public boolean visitLeave( DependencyNode node )
{
resolutionErrorHandler.throwErrors( request, result );
}
catch ( ArtifactResolutionException e )
{
throw new PluginResolutionException( plugin, e );
indent = indent.substring( 0, indent.length() - 3 );
return true;
}
pluginArtifacts.add( plexusUtils );
}
}

View File

@ -22,8 +22,6 @@
import java.util.Map;
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.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
@ -100,10 +98,9 @@ public Object getPluginComponent( Plugin plugin, String role, String roleHint )
PluginDescriptor pluginDescriptor;
try
{
RepositoryRequest repositoryRequest =
DefaultRepositoryRequest.getRepositoryRequest( session, session.getCurrentProject() );
pluginDescriptor = pluginManager.getPluginDescriptor( plugin, repositoryRequest );
pluginDescriptor =
pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(),
session.getRepositorySession() );
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
}
@ -133,10 +130,9 @@ public Map getPluginComponents( Plugin plugin, String role )
PluginDescriptor pluginDescriptor;
try
{
RepositoryRequest repositoryRequest =
DefaultRepositoryRequest.getRepositoryRequest( session, session.getCurrentProject() );
pluginDescriptor = pluginManager.getPluginDescriptor( plugin, repositoryRequest );
pluginDescriptor =
pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(),
session.getRepositorySession() );
pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null );
}
@ -234,24 +230,24 @@ public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Setti
InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException,
PluginVersionNotFoundException
{
RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
repositoryRequest.setLocalRepository( localRepository );
repositoryRequest.setRemoteRepositories( project.getPluginArtifactRepositories() );
repositoryRequest.setOffline( settings.isOffline() );
MavenSession session = legacySupport.getSession();
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() );
}
try
{
return pluginManager.getPluginDescriptor( plugin, repositoryRequest );
return pluginManager.getPluginDescriptor( plugin, project.getRemotePluginRepositories(),
session.getRepositorySession() );
}
catch ( PluginResolutionException e )
{
throw new PluginNotFoundException( plugin, repositoryRequest.getRemoteRepositories() );
throw new PluginNotFoundException( plugin, project.getPluginArtifactRepositories() );
}
catch ( PluginDescriptorParsingException e )
{

View File

@ -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;
}
}

View File

@ -21,11 +21,13 @@
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.PluginResolutionException;
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
@ -40,29 +42,30 @@ public interface PluginDependenciesResolver
/**
* 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 request A prepopulated resolution request that will be completed and used for the resolution, must not be
* {@code null}.
* @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
* 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}.
* @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;
/**
* Resolves the runtime dependencies of the specified plugin.
*
*
* @param plugin The plugin for which to resolve the dependencies, must not be {@code null}.
* @param pluginArtifact The plugin's main artifact, may be {@code null}.
* @param request A prepopulated resolution request that will be completed and used for the resolution, must not be
* {@code null}.
* @param dependencyFilter A filter to exclude artifacts from resolution, may be {@code null}.
* @return The list of artifacts denoting the resolved plugin class path, never {@code null}.
* @param dependencyFilter A filter to exclude artifacts from resolution (but not collection), may be {@code null}.
* @param repositories The plugin repositories to use for resolving the plugin artifacts, must not be {@code null}.
* @param session The repository session to use for resolving the plugin artifacts, must not be {@code null}.
* @return The dependency tree denoting the resolved plugin class path, never {@code null}.
* @throws PluginResolutionException If any dependency could not be resolved.
*/
List<Artifact> resolve( Plugin plugin, Artifact pluginArtifact, ArtifactResolutionRequest request,
ArtifactFilter dependencyFilter )
DependencyNode resolve( Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter,
List<RemoteRepository> repositories, RepositorySystemSession session )
throws PluginResolutionException;
}

View File

@ -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;
}
}

View File

@ -19,17 +19,14 @@
* under the License.
*/
import java.util.ArrayList;
import java.util.Collections;
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.model.Model;
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.
@ -43,34 +40,25 @@ public class DefaultPluginPrefixRequest
private String prefix;
private List<String> pluginGroups;
private List<String> pluginGroups = Collections.emptyList();
private Model pom;
private RepositoryRequest repositoryRequest;
private List<RemoteRepository> repositories = Collections.emptyList();
private RepositorySystemSession session;
/**
* Creates an empty request.
*/
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
* configure repository settings. If the session has a current project, its plugin artifact repositories and model
* will be used as well.
* configure repository settings. If the session has a current project, its plugin repositories and model will be
* used as well.
*
* @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}.
@ -79,18 +67,12 @@ public DefaultPluginPrefixRequest( String prefix, MavenSession session )
{
setPrefix( prefix );
this.repositoryRequest = new DefaultRepositoryRequest();
setCache( session.getRepositoryCache() );
setLocalRepository( session.getLocalRepository() );
setOffline( session.isOffline() );
setForceUpdate( session.getRequest().isUpdateSnapshots() );
setTransferListener( session.getRequest().getTransferListener() );
setRepositorySession( session.getRepositorySession() );
MavenProject project = session.getCurrentProject();
if ( project != null )
{
setRemoteRepositories( project.getPluginArtifactRepositories() );
setRepositories( project.getRemotePluginRepositories() );
setPom( project.getModel() );
}
@ -111,17 +93,19 @@ public DefaultPluginPrefixRequest setPrefix( String prefix )
public List<String> getPluginGroups()
{
if ( pluginGroups == null )
{
pluginGroups = new ArrayList<String>();
}
return pluginGroups;
}
public DefaultPluginPrefixRequest setPluginGroups( List<String> pluginGroups )
{
this.pluginGroups = pluginGroups;
if ( pluginGroups != null )
{
this.pluginGroups = pluginGroups;
}
else
{
this.pluginGroups = Collections.emptyList();
}
return this;
}
@ -138,74 +122,33 @@ public DefaultPluginPrefixRequest setPom( Model pom )
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;
}
public ArtifactRepository getLocalRepository()
public RepositorySystemSession getRepositorySession()
{
return repositoryRequest.getLocalRepository();
return session;
}
public DefaultPluginPrefixRequest setLocalRepository( ArtifactRepository localRepository )
public DefaultPluginPrefixRequest setRepositorySession( RepositorySystemSession session )
{
repositoryRequest.setLocalRepository( localRepository );
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 );
this.session = session;
return this;
}

View File

@ -21,29 +21,21 @@
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
extends Exception
{
private String prefix;
private ArtifactRepository localRepository;
private List<ArtifactRepository> remoteRepositories;
public NoPluginFoundForPrefixException( String prefix, List<String> pluginGroups,
ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepositories )
public NoPluginFoundForPrefixException( String prefix, List<String> pluginGroups, LocalRepository localRepository,
List<RemoteRepository> remoteRepositories )
{
super( "No plugin found for prefix '" + prefix + "' in the current project and in the plugin groups "
+ 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 = "[";
@ -54,7 +46,7 @@ private static String format( ArtifactRepository localRepository, List<ArtifactR
if ( remoteRepositories != null && !remoteRepositories.isEmpty() )
{
for ( ArtifactRepository repository : remoteRepositories )
for ( RemoteRepository repository : remoteRepositories )
{
repos += ", ";

View File

@ -21,11 +21,9 @@
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.repository.ArtifactTransferListener;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.repository.RemoteRepository;
/**
* Collects settings required to resolve a plugin prefix.
@ -34,7 +32,6 @@
* @author Benjamin Bentmann
*/
public interface PluginPrefixRequest
extends RepositoryRequest
{
/**
@ -84,80 +81,35 @@ public interface PluginPrefixRequest
*/
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.
*
* @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
* 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}.
*/
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}.
*/
PluginPrefixRequest 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}.
*/
PluginPrefixRequest setTransferListener( ArtifactTransferListener transferListener );
PluginPrefixRequest setRepositorySession( RepositorySystemSession repositorySession );
}

View File

@ -1,5 +1,7 @@
package org.apache.maven.plugin.prefix;
import org.sonatype.aether.repository.ArtifactRepository;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -19,8 +21,6 @@
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* Describes the result of a plugin prefix resolution request.
*

View File

@ -23,11 +23,9 @@
import java.io.IOException;
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.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.io.MetadataReader;
import org.apache.maven.model.Build;
@ -38,12 +36,18 @@
import org.apache.maven.plugin.prefix.PluginPrefixRequest;
import org.apache.maven.plugin.prefix.PluginPrefixResolver;
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.Requirement;
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.
@ -56,6 +60,8 @@ public class DefaultPluginPrefixResolver
implements PluginPrefixResolver
{
private static final String REPOSITORY_CONTEXT = "plugin";
@Requirement
private Logger logger;
@ -82,8 +88,8 @@ public PluginPrefixResult resolve( PluginPrefixRequest request )
if ( result == null )
{
throw new NoPluginFoundForPrefixException( request.getPrefix(), request.getPluginGroups(),
request.getLocalRepository(),
request.getRemoteRepositories() );
request.getRepositorySession().getLocalRepository(),
request.getRepositories() );
}
else if ( logger.isDebugEnabled() )
{
@ -126,7 +132,8 @@ private PluginPrefixResult resolveFromProject( PluginPrefixRequest request, List
{
try
{
PluginDescriptor pluginDescriptor = pluginManager.loadPlugin( plugin, request );
PluginDescriptor pluginDescriptor =
pluginManager.loadPlugin( plugin, request.getRepositories(), request.getRepositorySession() );
if ( request.getPrefix().equals( pluginDescriptor.getGoalPrefix() ) )
{
@ -152,155 +159,105 @@ private PluginPrefixResult resolveFromProject( PluginPrefixRequest request, List
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() )
{
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 =
resolveFromRepository( request, pluginGroup, groupMetadataFile, localRepository );
if ( result != null )
for ( RemoteRepository repository : request.getRepositories() )
{
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.
//
for ( String pluginGroup : request.getPluginGroups() )
List<MetadataResult> results = repositorySystem.resolveMetadata( request.getRepositorySession(), requests );
requests.clear();
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() );
continue;
logger.debug( "Could not find " + res.getRequest().getMetadata() + " in "
+ 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 );
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 );
PluginPrefixResult result =
resolveFromRepository( request, metadata.getGroupId(), metadata.getFile(), repository );
if ( result != null )
{
return result;
}
}
}
// Retry the remote repositories for which we previously only consulted the possibly outdated local cache.
//
for ( String pluginGroup : request.getPluginGroups() )
{
List<ArtifactRepository> repos = recheck.get( pluginGroup );
if ( repos == null )
if ( requests != null && !res.isUpdated() )
{
continue;
}
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;
}
requests.add( res.getRequest() );
}
}
return null;
}
private boolean isEnabled( ArtifactRepository repository )
{
return repository.getReleases().isEnabled() || repository.getSnapshots().isEnabled();
}
private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request, String pluginGroup,
File metadataFile, ArtifactRepository repository )
{
if ( metadataFile.isFile() )
if ( metadataFile != null && metadataFile.isFile() )
{
try
{
@ -337,14 +294,4 @@ private PluginPrefixResult resolveFromRepository( PluginPrefixRequest request, S
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";
}
}

View File

@ -19,9 +19,9 @@
* under the License.
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.prefix.PluginPrefixResult;
import org.sonatype.aether.repository.ArtifactRepository;
/**
* Describes the result of a plugin prefix resolution request.

View File

@ -19,17 +19,15 @@
* under the License.
*/
import java.util.Collections;
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.model.Model;
import org.apache.maven.model.Plugin;
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.
@ -47,65 +45,55 @@ public class DefaultPluginVersionRequest
private Model pom;
private RepositoryRequest repositoryRequest;
private List<RemoteRepository> repositories = Collections.emptyList();
private RepositorySystemSession session;
/**
* Creates an empty request.
*/
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
* 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}.
*/
public DefaultPluginVersionRequest( Plugin plugin, MavenSession session )
{
this.groupId = plugin.getGroupId();
this.artifactId = plugin.getArtifactId();
this.repositoryRequest = new DefaultRepositoryRequest();
setGroupId( plugin.getGroupId() );
setArtifactId( plugin.getArtifactId() );
setCache( session.getRepositoryCache() );
setLocalRepository( session.getLocalRepository() );
setOffline( session.isOffline() );
setForceUpdate( session.getRequest().isUpdateSnapshots() );
setTransferListener( session.getRequest().getTransferListener() );
setRepositorySession( session.getRepositorySession() );
MavenProject project = session.getCurrentProject();
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()
{
return groupId;
@ -142,74 +130,33 @@ public DefaultPluginVersionRequest setPom( Model pom )
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;
}
public ArtifactRepository getLocalRepository()
public RepositorySystemSession getRepositorySession()
{
return repositoryRequest.getLocalRepository();
return session;
}
public DefaultPluginVersionRequest setLocalRepository( ArtifactRepository localRepository )
public DefaultPluginVersionRequest setRepositorySession( RepositorySystemSession session )
{
repositoryRequest.setLocalRepository( localRepository );
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 );
this.session = session;
return this;
}

View File

@ -21,11 +21,9 @@
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.repository.ArtifactTransferListener;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.repository.RemoteRepository;
/**
* Collects settings required to resolve the version for a plugin.
@ -34,7 +32,6 @@
* @author Benjamin Bentmann
*/
public interface PluginVersionRequest
extends RepositoryRequest
{
/**
@ -84,80 +81,35 @@ public interface PluginVersionRequest
*/
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.
*
* @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
* 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}.
*/
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}.
*/
PluginVersionRequest 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}.
*/
PluginVersionRequest setTransferListener( ArtifactTransferListener transferListener );
PluginVersionRequest setRepositorySession( RepositorySystemSession repositorySession );
}

Some files were not shown because too many files have changed in this diff Show More