1 | |
package org.apache.maven.shared.io.location; |
2 | |
|
3 | |
import java.net.URL; |
4 | |
|
5 | |
import org.apache.maven.shared.io.logging.MessageHolder; |
6 | |
|
7 | |
public class ClasspathResourceLocatorStrategy |
8 | |
implements LocatorStrategy |
9 | |
{ |
10 | |
|
11 | 4 | private String tempFilePrefix = "location."; |
12 | |
|
13 | 4 | private String tempFileSuffix = ".cpurl"; |
14 | |
|
15 | 4 | private boolean tempFileDeleteOnExit = true; |
16 | |
|
17 | 3 | public ClasspathResourceLocatorStrategy() |
18 | |
{ |
19 | 3 | } |
20 | |
|
21 | 1 | public ClasspathResourceLocatorStrategy( String tempFilePrefix, String tempFileSuffix, boolean tempFileDeleteOnExit ) |
22 | |
{ |
23 | 1 | this.tempFilePrefix = tempFilePrefix; |
24 | 1 | this.tempFileSuffix = tempFileSuffix; |
25 | 1 | this.tempFileDeleteOnExit = tempFileDeleteOnExit; |
26 | 1 | } |
27 | |
|
28 | |
public Location resolve( String locationSpecification, MessageHolder messageHolder ) |
29 | |
{ |
30 | 2 | ClassLoader cloader = Thread.currentThread().getContextClassLoader(); |
31 | |
|
32 | 2 | URL resource = cloader.getResource( locationSpecification ); |
33 | |
|
34 | 2 | Location location = null; |
35 | |
|
36 | 2 | if ( resource != null ) |
37 | |
{ |
38 | 2 | location = new URLLocation( resource, locationSpecification, tempFilePrefix, tempFileSuffix, |
39 | 1 | tempFileDeleteOnExit ); |
40 | |
} |
41 | |
else |
42 | |
{ |
43 | 2 | messageHolder.addMessage( "Failed to resolve classpath resource: " + locationSpecification |
44 | 1 | + " from classloader: " + cloader ); |
45 | |
} |
46 | |
|
47 | 2 | return location; |
48 | |
} |
49 | |
|
50 | |
} |