1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.legacy.resolver.transform;
20
21 import org.apache.maven.artifact.Artifact;
22 import org.apache.maven.artifact.repository.ArtifactRepository;
23 import org.apache.maven.artifact.repository.RepositoryRequest;
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 import org.codehaus.plexus.component.annotations.Component;
29
30
31
32
33 @Component(role = ArtifactTransformation.class, hint = "latest")
34 public class LatestArtifactTransformation extends AbstractVersionTransformation {
35
36 public void transformForResolve(Artifact artifact, RepositoryRequest request)
37 throws ArtifactResolutionException, ArtifactNotFoundException {
38 if (Artifact.LATEST_VERSION.equals(artifact.getVersion())) {
39 try {
40 String version = resolveVersion(artifact, request);
41 if (Artifact.LATEST_VERSION.equals(version)) {
42 throw new ArtifactNotFoundException("Unable to determine the latest version", artifact);
43 }
44
45 artifact.setBaseVersion(version);
46 artifact.updateVersion(version, request.getLocalRepository());
47 } catch (RepositoryMetadataResolutionException e) {
48 throw new ArtifactResolutionException(e.getMessage(), artifact, e);
49 }
50 }
51 }
52
53 public void transformForInstall(Artifact artifact, ArtifactRepository localRepository) {
54
55 }
56
57 public void transformForDeployment(
58 Artifact artifact, ArtifactRepository remoteRepository, ArtifactRepository localRepository) {
59
60 }
61
62 protected String constructVersion(Versioning versioning, String baseVersion) {
63 return versioning.getLatest();
64 }
65 }