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 javax.inject.Inject;
22
23 import java.util.List;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.artifact.repository.ArtifactRepository;
27 import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
28 import org.apache.maven.artifact.repository.RepositoryRequest;
29 import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
30 import org.apache.maven.artifact.repository.metadata.Metadata;
31 import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
32 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
33 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
34 import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
35 import org.apache.maven.artifact.repository.metadata.Versioning;
36 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
37 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
38 import org.apache.maven.repository.legacy.WagonManager;
39 import org.codehaus.plexus.logging.AbstractLogEnabled;
40
41
42
43
44
45
46 @Deprecated
47 public abstract class AbstractVersionTransformation extends AbstractLogEnabled implements ArtifactTransformation {
48 @Inject
49 protected RepositoryMetadataManager repositoryMetadataManager;
50
51 @Inject
52 protected WagonManager wagonManager;
53
54 public void transformForResolve(
55 Artifact artifact, List<ArtifactRepository> remoteRepositories, ArtifactRepository localRepository)
56 throws ArtifactResolutionException, ArtifactNotFoundException {
57 RepositoryRequest request = new DefaultRepositoryRequest();
58 request.setLocalRepository(localRepository);
59 request.setRemoteRepositories(remoteRepositories);
60 transformForResolve(artifact, request);
61 }
62
63 protected String resolveVersion(
64 Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories)
65 throws RepositoryMetadataResolutionException {
66 RepositoryRequest request = new DefaultRepositoryRequest();
67 request.setLocalRepository(localRepository);
68 request.setRemoteRepositories(remoteRepositories);
69 return resolveVersion(artifact, request);
70 }
71
72 protected String resolveVersion(Artifact artifact, RepositoryRequest request)
73 throws RepositoryMetadataResolutionException {
74 RepositoryMetadata metadata;
75
76 if (!artifact.isSnapshot() || Artifact.LATEST_VERSION.equals(artifact.getBaseVersion())) {
77 metadata = new ArtifactRepositoryMetadata(artifact);
78 } else {
79 metadata = new SnapshotArtifactRepositoryMetadata(artifact);
80 }
81
82 repositoryMetadataManager.resolve(metadata, request);
83
84 artifact.addMetadata(metadata);
85
86 Metadata repoMetadata = metadata.getMetadata();
87 String version = null;
88 if (repoMetadata != null && repoMetadata.getVersioning() != null) {
89 version = constructVersion(repoMetadata.getVersioning(), artifact.getBaseVersion());
90 }
91
92 if (version == null) {
93
94 version = artifact.getBaseVersion();
95 }
96
97
98
99 if (getLogger().isDebugEnabled()) {
100 if (!version.equals(artifact.getBaseVersion())) {
101 String message = artifact.getArtifactId() + ": resolved to version " + version;
102 if (artifact.getRepository() != null) {
103 message += " from repository " + artifact.getRepository().getId();
104 } else {
105 message += " from local repository";
106 }
107 getLogger().debug(message);
108 } else {
109
110 getLogger().debug(artifact.getArtifactId() + ": using locally installed snapshot");
111 }
112 }
113 return version;
114 }
115
116 protected abstract String constructVersion(Versioning versioning, String baseVersion);
117 }