1 | |
package org.apache.maven.archiva.repository.content; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.apache.maven.archiva.model.ArchivaArtifact; |
24 | |
import org.apache.maven.archiva.model.ArtifactReference; |
25 | |
import org.apache.maven.archiva.repository.layout.LayoutException; |
26 | |
|
27 | |
import java.util.HashMap; |
28 | |
import java.util.Map; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | 0 | public abstract class AbstractLegacyRepositoryContent |
36 | |
{ |
37 | |
private static final String PATH_SEPARATOR = "/"; |
38 | |
|
39 | |
private static final Map<String, String> typeToDirectoryMap; |
40 | |
|
41 | |
static |
42 | |
{ |
43 | 0 | typeToDirectoryMap = new HashMap<String, String>(); |
44 | 0 | typeToDirectoryMap.put( "ejb-client", "ejb" ); |
45 | 0 | typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_PLUGIN, "maven-plugin" ); |
46 | 0 | typeToDirectoryMap.put( ArtifactExtensionMapping.MAVEN_ONE_PLUGIN, "plugin" ); |
47 | 0 | typeToDirectoryMap.put( "distribution-tgz", "distribution" ); |
48 | 0 | typeToDirectoryMap.put( "distribution-zip", "distribution" ); |
49 | 0 | typeToDirectoryMap.put( "javadoc", "javadoc.jar" ); |
50 | 0 | } |
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
private PathParser legacyPathParser; |
56 | |
|
57 | |
public ArtifactReference toArtifactReference( String path ) |
58 | |
throws LayoutException |
59 | |
{ |
60 | 0 | return legacyPathParser.toArtifactReference( path ); |
61 | |
} |
62 | |
|
63 | |
public String toPath( ArchivaArtifact reference ) |
64 | |
{ |
65 | 0 | if ( reference == null ) |
66 | |
{ |
67 | 0 | throw new IllegalArgumentException( "Artifact reference cannot be null" ); |
68 | |
} |
69 | |
|
70 | 0 | return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference |
71 | |
.getClassifier(), reference.getType() ); |
72 | |
} |
73 | |
|
74 | |
public String toPath( ArtifactReference reference ) |
75 | |
{ |
76 | 0 | if ( reference == null ) |
77 | |
{ |
78 | 0 | throw new IllegalArgumentException( "Artifact reference cannot be null" ); |
79 | |
} |
80 | |
|
81 | 0 | return toPath( reference.getGroupId(), reference.getArtifactId(), reference.getVersion(), reference |
82 | |
.getClassifier(), reference.getType() ); |
83 | |
} |
84 | |
|
85 | |
private String toPath( String groupId, String artifactId, String version, String classifier, String type ) |
86 | |
{ |
87 | 0 | StringBuffer path = new StringBuffer(); |
88 | |
|
89 | 0 | path.append( groupId ).append( PATH_SEPARATOR ); |
90 | 0 | path.append( getDirectory( classifier, type ) ).append( PATH_SEPARATOR ); |
91 | |
|
92 | 0 | if ( version != null ) |
93 | |
{ |
94 | 0 | path.append( artifactId ).append( '-' ).append( version ); |
95 | |
|
96 | 0 | if ( StringUtils.isNotBlank( classifier ) ) |
97 | |
{ |
98 | 0 | path.append( '-' ).append( classifier ); |
99 | |
} |
100 | |
|
101 | 0 | path.append( '.' ).append( ArtifactExtensionMapping.getExtension( type ) ); |
102 | |
} |
103 | |
|
104 | 0 | return path.toString(); |
105 | |
} |
106 | |
|
107 | |
private String getDirectory( String classifier, String type ) |
108 | |
{ |
109 | 0 | String dirname = (String) typeToDirectoryMap.get( type ); |
110 | |
|
111 | 0 | if ( dirname != null ) |
112 | |
{ |
113 | 0 | return dirname + "s"; |
114 | |
} |
115 | |
|
116 | |
|
117 | 0 | return type + "s"; |
118 | |
} |
119 | |
|
120 | |
public void setLegacyPathParser( PathParser parser ) |
121 | |
{ |
122 | 0 | this.legacyPathParser = parser; |
123 | 0 | } |
124 | |
} |