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