1 package org.apache.maven.repository.legacy.resolver.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.RepositoryRequest;
26 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
27 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
28 import org.apache.maven.artifact.repository.metadata.Versioning;
29 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
30 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
31 import org.codehaus.plexus.component.annotations.Component;
32
33
34
35
36
37
38
39 @Component( role = ArtifactTransformation.class, hint = "release" )
40 public class ReleaseArtifactTransformation
41 extends AbstractVersionTransformation
42 {
43
44 public void transformForResolve( Artifact artifact, RepositoryRequest request )
45 throws ArtifactResolutionException, ArtifactNotFoundException
46 {
47 if ( Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) )
48 {
49 try
50 {
51 String version = resolveVersion( artifact, request );
52
53 if ( Artifact.RELEASE_VERSION.equals( version ) )
54 {
55 throw new ArtifactNotFoundException( "Unable to determine the release version", artifact );
56 }
57
58 artifact.setBaseVersion( version );
59 artifact.updateVersion( version, request.getLocalRepository() );
60 }
61 catch ( RepositoryMetadataResolutionException e )
62 {
63 throw new ArtifactResolutionException( e.getMessage(), artifact, e );
64 }
65 }
66 }
67
68 public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
69 {
70 ArtifactMetadata metadata = createMetadata( artifact );
71
72 artifact.addMetadata( metadata );
73 }
74
75 public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
76 ArtifactRepository localRepository )
77 {
78 ArtifactMetadata metadata = createMetadata( artifact );
79
80 artifact.addMetadata( metadata );
81 }
82
83 private ArtifactMetadata createMetadata( Artifact artifact )
84 {
85 Versioning versioning = new Versioning();
86 versioning.updateTimestamp();
87 versioning.addVersion( artifact.getVersion() );
88
89 if ( artifact.isRelease() )
90 {
91 versioning.setRelease( artifact.getVersion() );
92 }
93
94 return new ArtifactRepositoryMetadata( artifact, versioning );
95 }
96
97 protected String constructVersion( Versioning versioning, String baseVersion )
98 {
99 return versioning.getRelease();
100 }
101 }