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.lang.reflect.InvocationTargetException; |
15 | |
import java.lang.reflect.Method; |
16 | |
import java.net.URL; |
17 | |
import java.net.URLClassLoader; |
18 | |
import java.util.Iterator; |
19 | |
import java.util.List; |
20 | |
|
21 | |
public final class MuleBootstrapUtils |
22 | |
{ |
23 | 0 | private static final String MULE_LIB_FILENAME = "lib" + File.separator + "mule"; |
24 | 0 | private static final String MULE_HOME = System.getProperty("mule.home"); |
25 | |
|
26 | |
public static final String MULE_LOCAL_JAR_FILENAME = "mule-local-install.jar"; |
27 | |
|
28 | |
private MuleBootstrapUtils() |
29 | 0 | { |
30 | |
|
31 | 0 | } |
32 | |
|
33 | |
public static File getMuleHomeFile() |
34 | |
{ |
35 | 0 | return new File(MULE_HOME); |
36 | |
} |
37 | |
|
38 | |
public static File getMuleLibDir() |
39 | |
{ |
40 | 0 | return new File(MULE_HOME + File.separator + MULE_LIB_FILENAME); |
41 | |
} |
42 | |
|
43 | |
public static File getMuleLocalJarFile() |
44 | |
{ |
45 | 0 | return new File(getMuleLibDir(), MULE_LOCAL_JAR_FILENAME); |
46 | |
} |
47 | |
|
48 | |
public static void addLocalJarFilesToClasspath(File muleHome, File muleBase) throws Exception |
49 | |
{ |
50 | 0 | DefaultMuleClassPathConfig classPath = new DefaultMuleClassPathConfig(muleHome, muleBase); |
51 | 0 | addLibrariesToClasspath(classPath.getURLs()); |
52 | 0 | } |
53 | |
|
54 | |
public static void addLibrariesToClasspath(List urls) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException |
55 | |
{ |
56 | 0 | ClassLoader sys = ClassLoader.getSystemClassLoader(); |
57 | 0 | if (!(sys instanceof URLClassLoader)) |
58 | |
{ |
59 | 0 | throw new IllegalArgumentException( |
60 | |
"PANIC: Mule has been started with an unsupported classloader: " + sys.getClass().getName() |
61 | |
+ ". " + "Please report this error to user<at>mule<dot>codehaus<dot>org"); |
62 | |
} |
63 | |
|
64 | |
|
65 | |
|
66 | 0 | URLClassLoader sysCl = (URLClassLoader) sys; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | 0 | Class refClass = URLClassLoader.class; |
87 | 0 | Method methodAddUrl = refClass.getDeclaredMethod("addURL", new Class[]{URL.class}); |
88 | 0 | methodAddUrl.setAccessible(true); |
89 | 0 | for (Iterator it = urls.iterator(); it.hasNext();) |
90 | |
{ |
91 | 0 | URL url = (URL) it.next(); |
92 | 0 | methodAddUrl.invoke(sysCl, new Object[]{url}); |
93 | 0 | } |
94 | 0 | } |
95 | |
|
96 | |
public static class ProxyInfo |
97 | |
{ |
98 | |
String host; |
99 | |
String port; |
100 | |
String username; |
101 | |
String password; |
102 | |
|
103 | |
public ProxyInfo(String host, String port) |
104 | |
{ |
105 | 0 | this(host, port, null, null); |
106 | 0 | } |
107 | |
|
108 | |
public ProxyInfo(String host, String port, String username, String password) |
109 | 0 | { |
110 | 0 | this.host = host; |
111 | 0 | this.port = port; |
112 | 0 | this.username = username; |
113 | 0 | this.password = password; |
114 | 0 | } |
115 | |
} |
116 | |
} |