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