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