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