1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.boot; |
12 | |
|
13 | |
import java.io.File; |
14 | |
import java.io.FileFilter; |
15 | |
import java.io.IOException; |
16 | |
import java.net.MalformedURLException; |
17 | |
import java.net.URL; |
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Arrays; |
20 | |
import java.util.Collections; |
21 | |
import java.util.Iterator; |
22 | |
import java.util.List; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class DefaultMuleClassPathConfig |
28 | |
{ |
29 | |
protected static final String MULE_DIR = "/lib/mule"; |
30 | |
protected static final String USER_DIR = "/lib/user"; |
31 | |
protected static final String OPT_DIR = "/lib/opt"; |
32 | |
|
33 | 2 | private List urls = new ArrayList(); |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public DefaultMuleClassPathConfig(File muleHome, File muleBase) |
41 | 2 | { |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
try |
47 | |
{ |
48 | 2 | if (!muleHome.getCanonicalFile().equals(muleBase.getCanonicalFile())) |
49 | |
{ |
50 | 2 | File userOverrideDir = new File(muleBase, USER_DIR); |
51 | 2 | this.addFile(userOverrideDir); |
52 | 2 | this.addFiles(this.listJars(userOverrideDir)); |
53 | |
} |
54 | |
} |
55 | 0 | catch (IOException ioe) |
56 | |
{ |
57 | 0 | System.out.println("Unable to check to see if there are local jars to load: " + ioe.toString()); |
58 | 2 | } |
59 | |
|
60 | 2 | File userDir = new File(muleHome, USER_DIR); |
61 | 2 | this.addFile(userDir); |
62 | 2 | this.addFiles(this.listJars(userDir)); |
63 | |
|
64 | 2 | File muleDir = new File(muleHome, MULE_DIR); |
65 | 2 | this.addFile(muleDir); |
66 | 2 | this.addFiles(this.listJars(muleDir)); |
67 | |
|
68 | 2 | File optDir = new File(muleHome, OPT_DIR); |
69 | 2 | this.addFile(optDir); |
70 | 2 | this.addFiles(this.listJars(optDir)); |
71 | 2 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public List getURLs() |
79 | |
{ |
80 | 2 | return new ArrayList(this.urls); |
81 | |
} |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void addURLs(List urls) |
89 | |
{ |
90 | 0 | if (urls != null && !urls.isEmpty()) |
91 | |
{ |
92 | 0 | this.urls.addAll(urls); |
93 | |
} |
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public void addURL(URL url) |
102 | |
{ |
103 | 8 | this.urls.add(url); |
104 | 8 | } |
105 | |
|
106 | |
public void addFiles(List files) |
107 | |
{ |
108 | 8 | for (Iterator i = files.iterator(); i.hasNext();) |
109 | |
{ |
110 | 0 | this.addFile((File)i.next()); |
111 | |
} |
112 | 8 | } |
113 | |
|
114 | |
public void addFile(File jar) |
115 | |
{ |
116 | |
try |
117 | |
{ |
118 | 8 | this.addURL(jar.getAbsoluteFile().toURI().toURL()); |
119 | |
} |
120 | 0 | catch (MalformedURLException mux) |
121 | |
{ |
122 | 0 | throw new RuntimeException("Failed to construct a classpath URL", mux); |
123 | 8 | } |
124 | 8 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
protected List listJars(File path) |
132 | |
{ |
133 | 8 | File[] jars = path.listFiles(new FileFilter() |
134 | |
{ |
135 | 8 | public boolean accept(File pathname) |
136 | |
{ |
137 | |
try |
138 | |
{ |
139 | 0 | return pathname.getCanonicalPath().endsWith(".jar"); |
140 | |
} |
141 | 0 | catch (IOException e) |
142 | |
{ |
143 | 0 | throw new RuntimeException(e.getMessage()); |
144 | |
} |
145 | |
} |
146 | |
}); |
147 | |
|
148 | 8 | return jars == null ? Collections.EMPTY_LIST : Arrays.asList(jars); |
149 | |
} |
150 | |
|
151 | |
} |