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 | 12 | { |
37 | 12 | this.prefix = formatPrefix( prefix ); |
38 | 12 | } |
39 | |
|
40 | |
private String formatPrefix( String prefix ) |
41 | |
{ |
42 | 12 | if ( prefix.startsWith( "/" ) ) |
43 | |
{ |
44 | 10 | prefix = prefix.substring( 1 ); |
45 | |
} |
46 | |
|
47 | 12 | if ( prefix.length() > 0 && !prefix.endsWith( "/" ) ) |
48 | |
{ |
49 | 2 | prefix += "/"; |
50 | |
} |
51 | |
|
52 | 12 | return prefix; |
53 | |
} |
54 | |
|
55 | |
public Location resolve( String locationSpecification, MessageHolder messageHolder ) |
56 | |
{ |
57 | 4 | String spec = formatLocation( locationSpecification ); |
58 | |
|
59 | 4 | return super.resolve( spec, messageHolder ); |
60 | |
} |
61 | |
|
62 | |
private String formatLocation( String location ) |
63 | |
{ |
64 | 4 | if ( location.startsWith( "/" ) ) |
65 | |
{ |
66 | 0 | location = location.substring( 1 ); |
67 | |
} |
68 | |
|
69 | 4 | return prefix + location; |
70 | |
} |
71 | |
|
72 | |
} |