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