1 package org.apache.maven.plugins.assembly.io;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.shared.io.location.ClasspathResourceLocatorStrategy;
23 import org.apache.maven.shared.io.location.Location;
24 import org.apache.maven.shared.io.logging.MessageHolder;
25
26
27
28
29 class PrefixedClasspathLocatorStrategy
30 extends ClasspathResourceLocatorStrategy
31 {
32
33 private final String prefix;
34
35 public PrefixedClasspathLocatorStrategy( String prefix )
36 {
37 this.prefix = formatPrefix( prefix );
38 }
39
40 private String formatPrefix( String prefix )
41 {
42 if ( prefix.startsWith( "/" ) )
43 {
44 prefix = prefix.substring( 1 );
45 }
46
47 if ( prefix.length() > 0 && !prefix.endsWith( "/" ) )
48 {
49 prefix += "/";
50 }
51
52 return prefix;
53 }
54
55 @Override
56 public Location resolve( String locationSpecification, MessageHolder messageHolder )
57 {
58 String spec = formatLocation( locationSpecification );
59
60 return super.resolve( spec, messageHolder );
61 }
62
63 private String formatLocation( String location )
64 {
65 if ( location.startsWith( "/" ) )
66 {
67 location = location.substring( 1 );
68 }
69
70 return prefix + location;
71 }
72
73 }