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.repository.ArtifactRepository;
24 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
25 import org.apache.maven.artifact.repository.metadata.Versioning;
26 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
27 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
28
29 import java.util.List;
30
31 public class LatestArtifactTransformation
32 extends AbstractVersionTransformation
33 {
34 public void transformForResolve( Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository )
35 throws ArtifactResolutionException, ArtifactNotFoundException
36 {
37 if ( Artifact.LATEST_VERSION.equals( artifact.getVersion() ) )
38 {
39 try
40 {
41 String version = resolveVersion( artifact, localRepository, remoteRepositories );
42 if ( Artifact.LATEST_VERSION.equals( version ) )
43 {
44 throw new ArtifactNotFoundException( "Unable to determine the latest version", artifact );
45 }
46
47 artifact.setBaseVersion( version );
48 artifact.updateVersion( version, localRepository );
49 }
50 catch ( RepositoryMetadataResolutionException e )
51 {
52 throw new ArtifactResolutionException( e.getMessage(), artifact, e );
53 }
54 }
55 }
56
57 public void transformForInstall( Artifact artifact, ArtifactRepository localRepository )
58 {
59
60 }
61
62 public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository,
63 ArtifactRepository localRepository )
64 {
65
66 }
67
68 protected String constructVersion( Versioning versioning, String baseVersion )
69 {
70 return versioning.getLatest();
71 }
72 }