1 package org.apache.maven.artifact.transform; 2 3 18 19 import org.apache.maven.artifact.Artifact; 20 import org.apache.maven.artifact.metadata.ArtifactMetadata; 21 import org.apache.maven.artifact.repository.ArtifactRepository; 22 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; 23 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException; 24 import org.apache.maven.artifact.repository.metadata.Versioning; 25 import org.apache.maven.artifact.resolver.ArtifactNotFoundException; 26 import org.apache.maven.artifact.resolver.ArtifactResolutionException; 27 28 import java.util.List ; 29 30 36 public class ReleaseArtifactTransformation 37 extends AbstractVersionTransformation 38 { 39 public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) 40 throws ArtifactResolutionException, ArtifactNotFoundException 41 { 42 if ( Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) ) 43 { 44 try 45 { 46 String version = resolveVersion( artifact, localRepository, remoteRepositories ); 47 48 if ( Artifact.RELEASE_VERSION.equals( version ) ) 49 { 50 throw new ArtifactNotFoundException( "Unable to determine the release version", artifact ); 51 } 52 53 artifact.setBaseVersion( version ); 54 artifact.updateVersion( version, localRepository ); 55 } 56 catch ( RepositoryMetadataResolutionException e ) 57 { 58 throw new ArtifactResolutionException( e.getMessage(), artifact, e ); 59 } 60 } 61 } 62 63 public void transformForInstall( Artifact artifact, ArtifactRepository localRepository ) 64 { 65 ArtifactMetadata metadata = createMetadata( artifact ); 66 67 artifact.addMetadata( metadata ); 68 } 69 70 public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository, 71 ArtifactRepository localRepository ) 72 { 73 ArtifactMetadata metadata = createMetadata( artifact ); 74 75 artifact.addMetadata( metadata ); 76 } 77 78 private ArtifactMetadata createMetadata( Artifact artifact ) 79 { 80 Versioning versioning = new Versioning(); 81 versioning.updateTimestamp(); 82 versioning.addVersion( artifact.getVersion() ); 83 84 if ( artifact.isRelease() ) 85 { 86 versioning.setRelease( artifact.getVersion() ); 87 } 88 89 return new ArtifactRepositoryMetadata( artifact, versioning ); 90 } 91 92 protected String constructVersion( Versioning versioning, String baseVersion ) 93 { 94 return versioning.getRelease(); 95 } 96 } 97 | Popular Tags |