1 package org.apache.maven.plugin.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 public 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 public Location resolve( String locationSpecification, MessageHolder messageHolder )
56 {
57 String spec = formatLocation( locationSpecification );
58
59 return super.resolve( spec, messageHolder );
60 }
61
62 private String formatLocation( String location )
63 {
64 if ( location.startsWith( "/" ) )
65 {
66 location = location.substring( 1 );
67 }
68
69 return prefix + location;
70 }
71
72 }