From 3a4b91b3108aa8f0972f59cfc6d38d775c6d2688 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 12 Sep 2005 01:23:23 +0000 Subject: [PATCH] PR: MNG-613 push shared code into metadata manager git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280232 13f79535-47bb-0310-9956-ffa450edef68 --- .../metadata/SnapshotArtifactMetadata.java | 4 + .../metadata/AbstractRepositoryMetadata.java | 9 +- .../metadata/ArtifactRepositoryMetadata.java | 5 + .../DefaultRepositoryMetadataManager.java | 117 ++++++++++++--- .../metadata/GroupRepositoryMetadata.java | 6 + .../metadata/RepositoryMetadata.java | 52 +++++++ .../metadata/RepositoryMetadataManager.java | 4 +- .../SnapshotArtifactRepositoryMetadata.java | 6 + .../AbstractVersionTransformation.java | 142 ++---------------- .../ReleaseArtifactTransformation.java | 2 +- .../transform/SnapshotTransformation.java | 30 ++-- .../resources/META-INF/plexus/components.xml | 16 ++ .../artifact/metadata/ArtifactMetadata.java | 21 +-- .../resources/META-INF/plexus/components.xml | 16 -- .../plugin/DefaultPluginMappingManager.java | 69 +-------- .../project/artifact/MavenMetadataSource.java | 49 ++---- .../src/main/mdo/metadata.mdo | 16 +- 17 files changed, 269 insertions(+), 295 deletions(-) create mode 100644 maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java rename {maven-artifact => maven-artifact-manager}/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java (90%) diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java index f39e559ebc..ef6fb0330a 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java @@ -175,4 +175,8 @@ public class SnapshotArtifactMetadata return artifact.getBaseVersion(); } + public void setRepository( ArtifactRepository remoteRepository ) + { + artifact.setRepository( remoteRepository ); + } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java index 71ff42b62d..ef93a33c37 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/AbstractRepositoryMetadata.java @@ -39,7 +39,7 @@ import java.io.Writer; * @version $Id$ */ public abstract class AbstractRepositoryMetadata - implements ArtifactMetadata + implements RepositoryMetadata { private Metadata metadata; @@ -162,7 +162,12 @@ public abstract class AbstractRepositoryMetadata return versioning; } - protected Metadata getMetadata() + public void setMetadata( Metadata metadata ) + { + this.metadata = metadata; + } + + public Metadata getMetadata() { return metadata; } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java index ac14ef380d..9b6f12516f 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/ArtifactRepositoryMetadata.java @@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository.metadata; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; /** * Metadata for the artifact directory of the repository. @@ -78,4 +79,8 @@ public class ArtifactRepositoryMetadata return false; } + public void setRepository( ArtifactRepository remoteRepository ) + { + artifact.setRepository( remoteRepository ); + } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java index 142f4008ec..7d4fad300e 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java @@ -21,11 +21,18 @@ import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.codehaus.plexus.logging.AbstractLogEnabled; +import org.codehaus.plexus.util.IOUtil; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -44,24 +51,28 @@ public class DefaultRepositoryMetadataManager */ private Set cachedMetadata = new HashSet(); - public void resolve( ArtifactMetadata metadata, List remoteRepositories, ArtifactRepository localRepository ) + public void resolve( RepositoryMetadata metadata, List remoteRepositories, ArtifactRepository localRepository ) throws ArtifactMetadataRetrievalException { - boolean alreadyResolved = alreadyResolved( metadata ); - if ( !alreadyResolved ) + // TODO: currently this is first wins, but really we should take the latest by comparing either the + // snapshot timestamp, or some other timestamp later encoded into the metadata. + loadMetadata( metadata, localRepository, localRepository ); + + for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) { - for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) + ArtifactRepository repository = (ArtifactRepository) i.next(); + + ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots() + : repository.getReleases(); + + if ( !policy.isEnabled() ) { - ArtifactRepository repository = (ArtifactRepository) i.next(); - - ArtifactRepositoryPolicy policy = metadata.isSnapshot() ? repository.getSnapshots() - : repository.getReleases(); - - if ( !policy.isEnabled() ) - { - getLogger().debug( "Skipping disabled repository " + repository.getId() ); - } - else + getLogger().debug( "Skipping disabled repository " + repository.getId() ); + } + else + { + boolean alreadyResolved = alreadyResolved( metadata ); + if ( !alreadyResolved ) { File file = new File( localRepository.getBasedir(), localRepository.pathOfLocalRepositoryMetadata( metadata, repository ) ); @@ -84,14 +95,70 @@ public class DefaultRepositoryMetadataManager { metadata.storeInLocalRepository( localRepository, repository ); } + cachedMetadata.add( metadata.getKey() ); } + loadMetadata( metadata, repository, localRepository ); } - - cachedMetadata.add( metadata.getKey() ); } } - public void resolveAlways( ArtifactMetadata metadata, ArtifactRepository localRepository, + private void loadMetadata( RepositoryMetadata repoMetadata, ArtifactRepository remoteRepository, + ArtifactRepository localRepository ) + throws ArtifactMetadataRetrievalException + { + File metadataFile = new File( localRepository.getBasedir(), + localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) ); + + if ( metadataFile.exists() ) + { + Metadata metadata = readMetadata( metadataFile ); + repoMetadata.setRepository( remoteRepository ); + + if ( repoMetadata.getMetadata() != null ) + { + metadata.merge( repoMetadata.getMetadata() ); + } + repoMetadata.setMetadata( metadata ); + } + } + + /** + * @todo share with DefaultPluginMappingManager. + */ + protected static Metadata readMetadata( File mappingFile ) + throws ArtifactMetadataRetrievalException + { + Metadata result; + + Reader fileReader = null; + try + { + fileReader = new FileReader( mappingFile ); + + MetadataXpp3Reader mappingReader = new MetadataXpp3Reader(); + + result = mappingReader.read( fileReader ); + } + catch ( FileNotFoundException e ) + { + throw new ArtifactMetadataRetrievalException( "Cannot read version information from: " + mappingFile, e ); + } + catch ( IOException e ) + { + throw new ArtifactMetadataRetrievalException( "Cannot read version information from: " + mappingFile, e ); + } + catch ( XmlPullParserException e ) + { + throw new ArtifactMetadataRetrievalException( "Cannot parse version information from: " + mappingFile, e ); + } + finally + { + IOUtil.close( fileReader ); + } + return result; + } + + public void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository, ArtifactRepository remoteRepository ) throws ArtifactMetadataRetrievalException { @@ -99,6 +166,12 @@ public class DefaultRepositoryMetadataManager localRepository.pathOfLocalRepositoryMetadata( metadata, remoteRepository ) ); resolveAlways( metadata, remoteRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); + + if ( file.exists() ) + { + Metadata prevMetadata = readMetadata( file ); + metadata.setMetadata( prevMetadata ); + } } private void resolveAlways( ArtifactMetadata metadata, ArtifactRepository repository, File file, @@ -135,15 +208,17 @@ public class DefaultRepositoryMetadataManager throws ArtifactMetadataRetrievalException { getLogger().info( "Retrieving previous metadata from " + deploymentRepository.getId() ); - resolveAlways( metadata, localRepository, deploymentRepository ); + + File file = new File( localRepository.getBasedir(), + localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) ); + + resolveAlways( metadata, deploymentRepository, file, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); metadata.storeInLocalRepository( localRepository, deploymentRepository ); try { - File f = new File( localRepository.getBasedir(), - localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) ); - wagonManager.putArtifactMetadata( f, metadata, deploymentRepository ); + wagonManager.putArtifactMetadata( file, metadata, deploymentRepository ); } catch ( TransferFailedException e ) { diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java index 098cc8ca6e..828d2c720a 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/GroupRepositoryMetadata.java @@ -16,6 +16,8 @@ package org.apache.maven.artifact.repository.metadata; * limitations under the License. */ +import org.apache.maven.artifact.repository.ArtifactRepository; + import java.util.Iterator; import java.util.List; @@ -93,4 +95,8 @@ public class GroupRepositoryMetadata return false; } + public void setRepository( ArtifactRepository remoteRepository ) + { + // intentionally blank + } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java new file mode 100644 index 0000000000..8a84c21805 --- /dev/null +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadata.java @@ -0,0 +1,52 @@ +package org.apache.maven.artifact.repository.metadata; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * Describes repository directory metadata. + * + * @author Brett Porter + * @version $Id$ + * @todo not happy about the store method - they use "this" + */ +public interface RepositoryMetadata + extends ArtifactMetadata +{ + /** + * Set the repository the metadata was located in. + * + * @param remoteRepository the repository + */ + void setRepository( ArtifactRepository remoteRepository ); + + /** + * Get the repository metadata associated with this marker. + * + * @return the metadata, or null if none loaded + */ + Metadata getMetadata(); + + /** + * Set the metadata contents. + * + * @param metadata the metadata + */ + void setMetadata( Metadata metadata ); +} diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java similarity index 90% rename from maven-artifact/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java rename to maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java index 5f95b072af..601d4f2f8f 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/RepositoryMetadataManager.java @@ -24,10 +24,10 @@ import java.util.List; public interface RepositoryMetadataManager { - void resolve( ArtifactMetadata repositoryMetadata, List repositories, ArtifactRepository localRepository ) + void resolve( RepositoryMetadata repositoryMetadata, List repositories, ArtifactRepository localRepository ) throws ArtifactMetadataRetrievalException; - void resolveAlways( ArtifactMetadata metadata, ArtifactRepository localRepository, + void resolveAlways( RepositoryMetadata metadata, ArtifactRepository localRepository, ArtifactRepository remoteRepository ) throws ArtifactMetadataRetrievalException; diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/SnapshotArtifactRepositoryMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/SnapshotArtifactRepositoryMetadata.java index b9dbec0cde..f1703fa3a4 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/SnapshotArtifactRepositoryMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/metadata/SnapshotArtifactRepositoryMetadata.java @@ -17,6 +17,7 @@ package org.apache.maven.artifact.repository.metadata; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; /** * Metadata for the artifact version directory of the repository. @@ -75,4 +76,9 @@ public class SnapshotArtifactRepositoryMetadata { return artifact.isSnapshot(); } + + public void setRepository( ArtifactRepository remoteRepository ) + { + artifact.setRepository( remoteRepository ); + } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java index 9b4eeb64de..22ac98a688 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java @@ -18,27 +18,21 @@ package org.apache.maven.artifact.transform; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; -import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.LegacyArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.Versioning; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.codehaus.plexus.logging.AbstractLogEnabled; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; -import java.io.Reader; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -68,7 +62,7 @@ public abstract class AbstractVersionTransformation throws ArtifactMetadataRetrievalException { // TODO: can we improve on this? - ArtifactMetadata metadata; + RepositoryMetadata metadata; if ( !artifact.isSnapshot() || Artifact.LATEST_VERSION.equals( artifact.getBaseVersion() ) ) { metadata = new ArtifactRepositoryMetadata( artifact ); @@ -80,49 +74,11 @@ public abstract class AbstractVersionTransformation repositoryMetadataManager.resolve( metadata, remoteRepositories, localRepository ); -/* - // TODO: can this go directly into the manager? At least share with DefaultPluginMappingManager - // TODO: use this, cache the output, select from that list instead of the next set - Versioning versioning = new Versioning(); - for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) - { - ArtifactRepository repository = (ArtifactRepository) i.next(); - - mergeVersioning( versioning, loadVersioningInformation( metadata, repository, localRepository ) ); - } - mergeVersioning( versioning, loadVersioningInformation( metadata, localRepository, localRepository ) ); - - String version = selectVersion( versioning, artifact.getVersion() ); -*/ - Versioning versioning = null; - for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) - { - ArtifactRepository repository = (ArtifactRepository) i.next(); - - versioning = loadVersioningInformation( metadata, repository, localRepository, artifact ); - if ( versioning != null ) - { - artifact.setRepository( repository ); - // TODO: merge instead (see above) - break; - } - } - Versioning v = loadVersioningInformation( metadata, localRepository, localRepository, artifact ); - if ( v != null ) - { - versioning = v; - // TODO: figure out way to avoid duplicated message - if ( getLogger().isDebugEnabled() /*&& !alreadyResolved*/ ) - { - // Locally installed file is newer, don't use the resolved version - getLogger().debug( artifact.getArtifactId() + ": using locally installed snapshot" ); - } - } - + Metadata repoMetadata = metadata.getMetadata(); String version = null; - if ( versioning != null ) + if ( repoMetadata != null && repoMetadata.getVersioning() != null ) { - version = constructVersion( versioning, artifact.getBaseVersion() ); + version = constructVersion( repoMetadata.getVersioning(), artifact.getBaseVersion() ); } if ( version == null ) @@ -135,9 +91,10 @@ public abstract class AbstractVersionTransformation } // TODO: also do this logging for other metadata? + // TODO: figure out way to avoid duplicated message if ( getLogger().isDebugEnabled() ) { - if ( version != null && !version.equals( artifact.getBaseVersion() ) ) + if ( !version.equals( artifact.getBaseVersion() ) ) { String message = artifact.getArtifactId() + ": resolved to version " + version; if ( artifact.getRepository() != null ) @@ -150,40 +107,17 @@ public abstract class AbstractVersionTransformation } getLogger().debug( message ); } + else + { + // Locally installed file is newer, don't use the resolved version + getLogger().debug( artifact.getArtifactId() + ": using locally installed snapshot" ); + } } return version; } protected abstract String constructVersion( Versioning versioning, String baseVersion ); -/* TODO - private void mergeVersioning( Versioning dest, Versioning source ) - { - // TODO: currently, it is first wins. We should probably compare the versions, or check timestamping? - // This could also let us choose the newer of the locally installed version and the remotely built version - if ( dest.getLatest() == null ) - { - dest.setLatest( source.getLatest() ); - } - if ( dest.getRelease() == null ) - { - dest.setRelease( source.getRelease() ); - } - if ( dest.getSnapshot() == null ) - { - dest.setSnapshot( source.getSnapshot() ); - } - for ( Iterator i = source.getVersions().iterator(); i.hasNext(); ) - { - String version = (String) i.next(); - if ( !dest.getVersions().contains( version ) ) - { - dest.getVersions().add( version ); - } - } - } -*/ - /** * @todo remove in beta-2 - used for legacy handling */ @@ -312,56 +246,4 @@ public abstract class AbstractVersionTransformation // No type - one per POM return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getBaseVersion(); } - - protected Versioning loadVersioningInformation( ArtifactMetadata repoMetadata, ArtifactRepository remoteRepository, - ArtifactRepository localRepository, Artifact artifact ) - throws ArtifactMetadataRetrievalException - { - File metadataFile = new File( localRepository.getBasedir(), - localRepository.pathOfLocalRepositoryMetadata( repoMetadata, remoteRepository ) ); - - Versioning versioning = null; - if ( metadataFile.exists() ) - { - Metadata metadata = readMetadata( metadataFile ); - versioning = metadata.getVersioning(); - } - return versioning; - } - - /** - * @todo share with DefaultPluginMappingManager. - */ - private static Metadata readMetadata( File mappingFile ) - throws ArtifactMetadataRetrievalException - { - Metadata result; - - Reader fileReader = null; - try - { - fileReader = new FileReader( mappingFile ); - - MetadataXpp3Reader mappingReader = new MetadataXpp3Reader(); - - result = mappingReader.read( fileReader ); - } - catch ( FileNotFoundException e ) - { - throw new ArtifactMetadataRetrievalException( "Cannot read version information from: " + mappingFile, e ); - } - catch ( IOException e ) - { - throw new ArtifactMetadataRetrievalException( "Cannot read version information from: " + mappingFile, e ); - } - catch ( XmlPullParserException e ) - { - throw new ArtifactMetadataRetrievalException( "Cannot parse version information from: " + mappingFile, e ); - } - finally - { - IOUtil.close( fileReader ); - } - return result; - } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/ReleaseArtifactTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/ReleaseArtifactTransformation.java index 11c8f23ca5..e5876a8f3d 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/ReleaseArtifactTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/ReleaseArtifactTransformation.java @@ -88,7 +88,7 @@ public class ReleaseArtifactTransformation return new ReleaseArtifactMetadata( artifact ); } - protected String constructVersion( Versioning versioning, String bS ) + protected String constructVersion( Versioning versioning, String baseVersion ) { return versioning.getRelease(); } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index c59a40b9c8..cf816f76a7 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -23,6 +23,8 @@ import org.apache.maven.artifact.metadata.LegacyArtifactMetadata; import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.repository.metadata.Metadata; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.Snapshot; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.Versioning; @@ -58,10 +60,9 @@ public class SnapshotTransformation { if ( artifact.isSnapshot() ) { - // TODO: Better way to create this - should have to construct Versioning - ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + metadata.getMetadata().getVersioning().getSnapshot().setLocalCopy( true ); - // TODO: should merge with other repository metadata sitting on the same level? artifact.addMetadata( metadata ); } } @@ -109,7 +110,11 @@ public class SnapshotTransformation Snapshot snapshot = versioning.getSnapshot(); if ( snapshot != null ) { - if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 ) + if ( snapshot.isLocalCopy() ) + { + version = baseVersion; + } + else if ( snapshot.getTimestamp() != null && snapshot.getBuildNumber() > 0 ) { String newVersion = snapshot.getTimestamp() + "-" + snapshot.getBuildNumber(); version = StringUtils.replace( baseVersion, "SNAPSHOT", newVersion ); @@ -123,14 +128,21 @@ public class SnapshotTransformation throws ArtifactMetadataRetrievalException { // TODO: can we improve on this? - ArtifactMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); getLogger().info( "Retrieving previous build number from " + remoteRepository.getId() ); repositoryMetadataManager.resolveAlways( metadata, localRepository, remoteRepository ); - Versioning versioning = loadVersioningInformation( metadata, remoteRepository, localRepository, artifact ); int buildNumber = 0; - if ( versioning == null ) + Metadata repoMetadata = metadata.getMetadata(); + if ( repoMetadata != null ) + { + if ( repoMetadata.getVersioning() != null && repoMetadata.getVersioning().getSnapshot() != null ) + { + buildNumber = repoMetadata.getVersioning().getSnapshot().getBuildNumber(); + } + } + else { try { @@ -147,10 +159,6 @@ public class SnapshotTransformation getLogger().debug( "Unable to find legacy metadata - ignoring" ); } } - else if ( versioning.getSnapshot() != null ) - { - buildNumber = versioning.getSnapshot().getBuildNumber(); - } return buildNumber; } diff --git a/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml b/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml index d5e402d92c..ebb4dc6b6f 100644 --- a/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml +++ b/maven-artifact-manager/src/main/resources/META-INF/plexus/components.xml @@ -10,6 +10,16 @@ org.apache.maven.artifact.manager.DefaultWagonManager + + org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager + org.apache.maven.artifact.repository.metadata.DefaultRepositoryMetadataManager + + + org.apache.maven.artifact.manager.WagonManager + + + +