1 package org.eclipse.aether.internal.impl;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import org.eclipse.aether.artifact.Artifact;
26 import org.eclipse.aether.metadata.Metadata;
27
28 import static java.util.Objects.requireNonNull;
29
30
31
32
33
34
35 @Singleton
36 @Named
37 public final class DefaultLocalPathComposer implements LocalPathComposer
38 {
39 @Override
40 public String getPathForArtifact( Artifact artifact, boolean local )
41 {
42 requireNonNull( artifact );
43
44 StringBuilder path = new StringBuilder( 128 );
45
46 path.append( artifact.getGroupId().replace( '.', '/' ) ).append( '/' );
47
48 path.append( artifact.getArtifactId() ).append( '/' );
49
50 path.append( artifact.getBaseVersion() ).append( '/' );
51
52 path.append( artifact.getArtifactId() ).append( '-' );
53 if ( local )
54 {
55 path.append( artifact.getBaseVersion() );
56 }
57 else
58 {
59 path.append( artifact.getVersion() );
60 }
61
62 if ( artifact.getClassifier().length() > 0 )
63 {
64 path.append( '-' ).append( artifact.getClassifier() );
65 }
66
67 if ( artifact.getExtension().length() > 0 )
68 {
69 path.append( '.' ).append( artifact.getExtension() );
70 }
71
72 return path.toString();
73 }
74
75 @Override
76 public String getPathForMetadata( Metadata metadata, String repositoryKey )
77 {
78 requireNonNull( metadata );
79 requireNonNull( repositoryKey );
80
81 StringBuilder path = new StringBuilder( 128 );
82
83 if ( metadata.getGroupId().length() > 0 )
84 {
85 path.append( metadata.getGroupId().replace( '.', '/' ) ).append( '/' );
86
87 if ( metadata.getArtifactId().length() > 0 )
88 {
89 path.append( metadata.getArtifactId() ).append( '/' );
90
91 if ( metadata.getVersion().length() > 0 )
92 {
93 path.append( metadata.getVersion() ).append( '/' );
94 }
95 }
96 }
97
98 path.append( insertRepositoryKey( metadata.getType(), repositoryKey ) );
99
100 return path.toString();
101 }
102
103 private String insertRepositoryKey( String metadataType, String repositoryKey )
104 {
105 String result;
106 int idx = metadataType.indexOf( '.' );
107 if ( idx < 0 )
108 {
109 result = metadataType + '-' + repositoryKey;
110 }
111 else
112 {
113 result = metadataType.substring( 0, idx ) + '-' + repositoryKey + metadataType.substring( idx );
114 }
115 return result;
116 }
117 }