1 package org.apache.maven.shared.io.location;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.net.URL;
23
24 import org.apache.maven.shared.io.logging.MessageHolder;
25
26
27
28
29
30 public class ClasspathResourceLocatorStrategy
31 implements LocatorStrategy
32 {
33
34 private String tempFilePrefix = "location.";
35
36 private String tempFileSuffix = ".cpurl";
37
38 private boolean tempFileDeleteOnExit = true;
39
40
41
42
43 public ClasspathResourceLocatorStrategy()
44 {
45 }
46
47
48
49
50
51
52 public ClasspathResourceLocatorStrategy( String tempFilePrefix, String tempFileSuffix,
53 boolean tempFileDeleteOnExit )
54 {
55 this.tempFilePrefix = tempFilePrefix;
56 this.tempFileSuffix = tempFileSuffix;
57 this.tempFileDeleteOnExit = tempFileDeleteOnExit;
58 }
59
60
61 public Location resolve( String locationSpecification, MessageHolder messageHolder )
62 {
63 ClassLoader cloader = Thread.currentThread().getContextClassLoader();
64
65 URL resource = cloader.getResource( locationSpecification );
66
67 Location location = null;
68
69 if ( resource != null )
70 {
71 location = new URLLocation( resource, locationSpecification, tempFilePrefix, tempFileSuffix,
72 tempFileDeleteOnExit );
73 }
74 else
75 {
76 messageHolder.addMessage( "Failed to resolve classpath resource: " + locationSpecification
77 + " from classloader: " + cloader );
78 }
79
80 return location;
81 }
82
83 }