You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2010/08/25 00:46:12 UTC
svn commit: r988749 [2/9] - in /maven/maven-3/trunk: ./ apache-maven/
maven-aether-provider/ maven-aether-provider/src/
maven-aether-provider/src/main/ maven-aether-provider/src/main/java/
maven-aether-provider/src/main/java/org/ maven-aether-provider/...
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java Tue Aug 24 22:46:07 2010
@@ -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;
+ }
+ }
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java Tue Aug 24 22:46:07 2010
@@ -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;
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadata.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java Tue Aug 24 22:46:07 2010
@@ -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();
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/LocalSnapshotMetadataGenerator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java Tue Aug 24 22:46:07 2010
@@ -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();
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenMetadata.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSession.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSession.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSession.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSession.java Tue Aug 24 22:46:07 2010
@@ -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() );
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSession.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/MavenRepositorySystemSession.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java Tue Aug 24 22:46:07 2010
@@ -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();
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RelocatedArtifact.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java Tue Aug 24 22:46:07 2010
@@ -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;
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadata.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java Tue Aug 24 22:46:07 2010
@@ -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();
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/RemoteSnapshotMetadataGenerator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/SnapshotMetadataGeneratorFactory.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/SnapshotMetadataGeneratorFactory.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/SnapshotMetadataGeneratorFactory.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/SnapshotMetadataGeneratorFactory.java Tue Aug 24 22:46:07 2010
@@ -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;
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/SnapshotMetadataGeneratorFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/SnapshotMetadataGeneratorFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java Tue Aug 24 22:46:07 2010
@@ -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;
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadata.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java Tue Aug 24 22:46:07 2010
@@ -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();
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGenerator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGeneratorFactory.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGeneratorFactory.java?rev=988749&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGeneratorFactory.java (added)
+++ maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGeneratorFactory.java Tue Aug 24 22:46:07 2010
@@ -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;
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGeneratorFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/maven-3/trunk/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/VersionsMetadataGeneratorFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/maven-3/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java?rev=988749&r1=988748&r2=988749&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java (original)
+++ maven/maven-3/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java Tue Aug 24 22:46:07 2010
@@ -493,7 +493,6 @@ public class DefaultArtifact
public void setVersionRange( VersionRange versionRange )
{
this.versionRange = versionRange;
-
selectVersionFromNewRangeIfAvailable();
}
Modified: maven/maven-3/trunk/maven-compat/pom.xml
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-compat/pom.xml?rev=988749&r1=988748&r2=988749&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-compat/pom.xml (original)
+++ maven/maven-3/trunk/maven-compat/pom.xml Tue Aug 24 22:46:07 2010
@@ -70,6 +70,12 @@
<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>
<version>1.2_Java1.3</version>
Modified: maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java?rev=988749&r1=988748&r2=988749&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java (original)
+++ maven/maven-3/trunk/maven-compat/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java Tue Aug 24 22:46:07 2010
@@ -20,50 +20,46 @@ package org.apache.maven.artifact.deploy
*/
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 class DefaultArtifactDeployer
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 )
+
+ 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 ( deploymentRepository instanceof DefaultArtifactRepository
+ && deploymentRepository.getAuthentication() == null )
{
- throw new ArtifactDeploymentException( "Error deploying artifact: " + e.getMessage(), e );
+ remoteRepo.setAuthentication( session.getAuthenticationSelector().getAuthentication( remoteRepo ) );
+ remoteRepo.setProxy( session.getProxySelector().getProxy( remoteRepo ) );
}
- catch ( RepositoryMetadataDeploymentException e )
+ request.setRepository( remoteRepo );
+
+ DeployResult result;
+ try
{
- throw new ArtifactDeploymentException( "Error installing artifact's metadata: " + e.getMessage(), e );
+ result = repoSystem.deploy( session, request );
}
- }
-
- private TransferListener getTransferListener()
- {
- MavenSession session = legacySupport.getSession();
-
- if ( session == null )
+ catch ( DeploymentException e )
{
- return null;
+ throw new ArtifactDeploymentException( e.getMessage(), e );
}
- return TransferListenerAdapter.newAdapter( session.getRequest().getTransferListener() );
- }
-
- private ArtifactRepository injectSession( ArtifactRepository repository )
- {
- /*
- * NOTE: This provides backward-compat with maven-deploy-plugin:2.4 which bypasses the repository factory when
- * using an alternative deployment location.
- */
- if ( repository instanceof DefaultArtifactRepository && repository.getAuthentication() == null )
+ if ( snapshotKey != null )
{
- MavenSession session = legacySupport.getSession();
-
- if ( session != 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() );
}
}