1 package org.apache.maven.repository.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.LinkedHashSet;
26
27 import org.apache.maven.artifact.repository.metadata.Metadata;
28 import org.apache.maven.artifact.repository.metadata.Versioning;
29 import org.eclipse.aether.artifact.Artifact;
30 import org.eclipse.aether.artifact.ArtifactProperties;
31
32
33
34
35 final class VersionsMetadata
36 extends MavenMetadata
37 {
38
39 private final Artifact artifact;
40
41 public VersionsMetadata( Artifact artifact )
42 {
43 super( createRepositoryMetadata( artifact ), null );
44 this.artifact = artifact;
45 }
46
47 public VersionsMetadata( Artifact artifact, File file )
48 {
49 super( createRepositoryMetadata( artifact ), file );
50 this.artifact = artifact;
51 }
52
53 private static Metadata createRepositoryMetadata( Artifact artifact )
54 {
55 Metadata metadata = new Metadata();
56 metadata.setGroupId( artifact.getGroupId() );
57 metadata.setArtifactId( artifact.getArtifactId() );
58
59 Versioning versioning = new Versioning();
60 versioning.addVersion( artifact.getBaseVersion() );
61 if ( !artifact.isSnapshot() )
62 {
63 versioning.setRelease( artifact.getBaseVersion() );
64 }
65 if ( "maven-plugin".equals( artifact.getProperty( ArtifactProperties.TYPE, "" ) ) )
66 {
67 versioning.setLatest( artifact.getBaseVersion() );
68 }
69
70 metadata.setVersioning( versioning );
71
72 return metadata;
73 }
74
75 @Override
76 protected void merge( Metadata recessive )
77 {
78 Versioning versioning = metadata.getVersioning();
79 versioning.updateTimestamp();
80
81 if ( recessive.getVersioning() != null )
82 {
83 if ( versioning.getLatest() == null )
84 {
85 versioning.setLatest( recessive.getVersioning().getLatest() );
86 }
87 if ( versioning.getRelease() == null )
88 {
89 versioning.setRelease( recessive.getVersioning().getRelease() );
90 }
91
92 Collection<String> versions = new LinkedHashSet<>( recessive.getVersioning().getVersions() );
93 versions.addAll( versioning.getVersions() );
94 versioning.setVersions( new ArrayList<>( versions ) );
95 }
96 }
97
98 public Object getKey()
99 {
100 return getGroupId() + ':' + getArtifactId();
101 }
102
103 public static Object getKey( Artifact artifact )
104 {
105 return artifact.getGroupId() + ':' + artifact.getArtifactId();
106 }
107
108 public MavenMetadata setFile( File file )
109 {
110 return new VersionsMetadata( artifact, file );
111 }
112
113 public String getGroupId()
114 {
115 return artifact.getGroupId();
116 }
117
118 public String getArtifactId()
119 {
120 return artifact.getArtifactId();
121 }
122
123 public String getVersion()
124 {
125 return "";
126 }
127
128 public Nature getNature()
129 {
130 return artifact.isSnapshot() ? Nature.RELEASE_OR_SNAPSHOT : Nature.RELEASE;
131 }
132
133 }