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