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