Author: gboue Date: Sun Oct 30 15:00:30 2016 New Revision: 1767164 URL: http://svn.apache.org/viewvc?rev=1767164&view=rev Log: [MSHARED-596] Support for getting local metadata for RepositoryManager
Adding method "getPathForLocalMetadata" in RepositoryManager delegating to Sonatype or Eclipse Aether depending on the Maven version. Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/RepositoryManager.java maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/DefaultRepositoryManager.java maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven30RepositoryManager.java maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven31RepositoryManager.java Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/RepositoryManager.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/RepositoryManager.java?rev=1767164&r1=1767163&r2=1767164&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/RepositoryManager.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/RepositoryManager.java Sun Oct 30 15:00:30 2016 @@ -22,6 +22,7 @@ package org.apache.maven.shared.reposito import java.io.File; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.shared.artifact.ArtifactCoordinate; @@ -44,6 +45,13 @@ public interface RepositoryManager * @return the path for the local artifact. */ String getPathForLocalArtifact( ProjectBuildingRequest buildingRequest, ArtifactCoordinate coordinate ); + + /** + * @param buildingRequest {@link ProjectBuildingRequest} + * @param metadata {@link ArtifactMetadata} + * @return the path of the local metadata. + */ + String getPathForLocalMetadata( ProjectBuildingRequest buildingRequest, ArtifactMetadata metadata ); /** * Create a new {@code ProjectBuildingRequest} with an adjusted repository session. Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/DefaultRepositoryManager.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/DefaultRepositoryManager.java?rev=1767164&r1=1767163&r2=1767164&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/DefaultRepositoryManager.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/DefaultRepositoryManager.java Sun Oct 30 15:00:30 2016 @@ -22,8 +22,11 @@ package org.apache.maven.shared.reposito import java.io.File; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.project.artifact.ProjectArtifactMetadata; import org.apache.maven.shared.artifact.ArtifactCoordinate; +import org.apache.maven.shared.artifact.DefaultArtifactCoordinate; import org.apache.maven.shared.repository.RepositoryManager; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; @@ -72,6 +75,34 @@ public class DefaultRepositoryManager } catch ( ComponentLookupException e ) { + throw new IllegalStateException( e.getMessage(), e ); + } + } + + @Override + public String getPathForLocalMetadata( ProjectBuildingRequest buildingRequest, ArtifactMetadata metadata ) + { + if ( metadata instanceof ProjectArtifactMetadata ) + { + DefaultArtifactCoordinate pomCoordinate = new DefaultArtifactCoordinate(); + pomCoordinate.setGroupId( metadata.getGroupId() ); + pomCoordinate.setArtifactId( metadata.getArtifactId() ); + pomCoordinate.setVersion( metadata.getBaseVersion() ); + pomCoordinate.setExtension( "pom" ); + return getPathForLocalArtifact( buildingRequest, pomCoordinate ); + } + + try + { + + String hint = isMaven31() ? "maven31" : "maven3"; + + RepositoryManager effectiveRepositoryManager = container.lookup( RepositoryManager.class, hint ); + + return effectiveRepositoryManager.getPathForLocalMetadata( buildingRequest, metadata ); + } + catch ( ComponentLookupException e ) + { throw new IllegalStateException( e.getMessage(), e ); } } Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven30RepositoryManager.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven30RepositoryManager.java?rev=1767164&r1=1767163&r2=1767164&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven30RepositoryManager.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven30RepositoryManager.java Sun Oct 30 15:00:30 2016 @@ -23,6 +23,7 @@ import java.io.File; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.shared.artifact.ArtifactCoordinate; @@ -33,11 +34,14 @@ import org.codehaus.plexus.component.ann import org.sonatype.aether.RepositorySystem; import org.sonatype.aether.RepositorySystemSession; import org.sonatype.aether.artifact.Artifact; +import org.sonatype.aether.metadata.Metadata; +import org.sonatype.aether.metadata.Metadata.Nature; import org.sonatype.aether.repository.LocalRepository; import org.sonatype.aether.repository.LocalRepositoryManager; import org.sonatype.aether.util.DefaultRepositoryCache; import org.sonatype.aether.util.DefaultRepositorySystemSession; import org.sonatype.aether.util.artifact.DefaultArtifact; +import org.sonatype.aether.util.metadata.DefaultMetadata; /** * @@ -100,6 +104,27 @@ public class Maven30RepositoryManager } @Override + public String getPathForLocalMetadata( ProjectBuildingRequest buildingRequest, ArtifactMetadata metadata ) + { + Metadata aetherMetadata = + new DefaultMetadata( metadata.getGroupId(), + metadata.storedInGroupDirectory() ? null : metadata.getArtifactId(), + metadata.storedInArtifactVersionDirectory() ? metadata.getBaseVersion() : null, + "maven-metadata.xml", Nature.RELEASE_OR_SNAPSHOT ); + + RepositorySystemSession session; + try + { + session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + return session.getLocalRepositoryManager().getPathForLocalMetadata( aetherMetadata ); + } + + @Override public ProjectBuildingRequest setLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest, File basedir ) { ProjectBuildingRequest newRequest = new DefaultProjectBuildingRequest( buildingRequest ); Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven31RepositoryManager.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven31RepositoryManager.java?rev=1767164&r1=1767163&r2=1767164&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven31RepositoryManager.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/repository/internal/Maven31RepositoryManager.java Sun Oct 30 15:00:30 2016 @@ -23,6 +23,7 @@ import java.io.File; import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; +import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.project.DefaultProjectBuildingRequest; import org.apache.maven.project.ProjectBuildingRequest; import org.apache.maven.shared.artifact.ArtifactCoordinate; @@ -36,6 +37,9 @@ import org.eclipse.aether.RepositorySyst import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.metadata.DefaultMetadata; +import org.eclipse.aether.metadata.Metadata; +import org.eclipse.aether.metadata.Metadata.Nature; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; @@ -96,6 +100,27 @@ public class Maven31RepositoryManager return session.getLocalRepositoryManager().getPathForLocalArtifact( aetherArtifact ); } + + @Override + public String getPathForLocalMetadata( ProjectBuildingRequest buildingRequest, ArtifactMetadata metadata ) + { + Metadata aetherMetadata = + new DefaultMetadata( metadata.getGroupId(), + metadata.storedInGroupDirectory() ? null : metadata.getArtifactId(), + metadata.storedInArtifactVersionDirectory() ? metadata.getBaseVersion() : null, + "maven-metadata.xml", Nature.RELEASE_OR_SNAPSHOT ); + + RepositorySystemSession session; + try + { + session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + return session.getLocalRepositoryManager().getPathForLocalMetadata( aetherMetadata ); + } @Override public ProjectBuildingRequest setLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest, File basedir )