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