1 package org.eclipse.aether.internal.impl.synccontext.named;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.eclipse.aether.RepositorySystemSession;
23 import org.eclipse.aether.artifact.Artifact;
24 import org.eclipse.aether.metadata.Metadata;
25
26 import javax.inject.Named;
27 import javax.inject.Singleton;
28 import java.util.Collection;
29 import java.util.TreeSet;
30
31
32
33
34
35 @Singleton
36 @Named( GAVNameMapper.NAME )
37 public class GAVNameMapper implements NameMapper
38 {
39 public static final String NAME = "gav";
40
41 @Override
42 public Collection<String> nameLocks( final RepositorySystemSession session,
43 final Collection<? extends Artifact> artifacts,
44 final Collection<? extends Metadata> metadatas )
45 {
46
47
48 Collection<String> keys = new TreeSet<>();
49 if ( artifacts != null )
50 {
51 for ( Artifact artifact : artifacts )
52 {
53 String key = "artifact:" + artifact.getGroupId()
54 + ":" + artifact.getArtifactId()
55 + ":" + artifact.getBaseVersion();
56 keys.add( key );
57 }
58 }
59
60 if ( metadatas != null )
61 {
62 for ( Metadata metadata : metadatas )
63 {
64 StringBuilder key = new StringBuilder( "metadata:" );
65 if ( !metadata.getGroupId().isEmpty() )
66 {
67 key.append( metadata.getGroupId() );
68 if ( !metadata.getArtifactId().isEmpty() )
69 {
70 key.append( ':' ).append( metadata.getArtifactId() );
71 if ( !metadata.getVersion().isEmpty() )
72 {
73 key.append( ':' ).append( metadata.getVersion() );
74 }
75 }
76 }
77 keys.add( key.toString() );
78 }
79 }
80 return keys;
81 }
82 }