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