1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.modules.boot; |
12 | |
|
13 | |
import org.mule.util.ClassUtils; |
14 | |
|
15 | |
import java.io.File; |
16 | |
import java.lang.reflect.InvocationTargetException; |
17 | |
import java.lang.reflect.Method; |
18 | |
import java.net.URL; |
19 | |
import java.net.URLClassLoader; |
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
|
23 | 0 | public class GuiInstallerLibraryDownloader |
24 | |
{ |
25 | 0 | private static String proxyHost = null; |
26 | 0 | private static String proxyPort = null; |
27 | 0 | private static String proxyUsername = null; |
28 | 0 | private static String proxyPassword = null; |
29 | |
|
30 | |
public static void main(String args[]) throws Exception |
31 | |
{ |
32 | 0 | File muleHome = new File(args[0]); |
33 | |
|
34 | |
|
35 | |
|
36 | 0 | DefaultMuleClassPathConfig classPath = new DefaultMuleClassPathConfig(muleHome, muleHome); |
37 | 0 | addLibrariesToClasspath(classPath.getURLs()); |
38 | |
|
39 | |
|
40 | |
|
41 | 0 | if (!ClassUtils.isClassOnPath("javax.activation.DataSource", GuiInstallerLibraryDownloader.class)) |
42 | |
{ |
43 | 0 | if (args.length > 1){ |
44 | 0 | proxyHost = args[1]; |
45 | |
} |
46 | 0 | if (args.length > 2){ |
47 | 0 | proxyPort = args[2]; |
48 | |
} |
49 | 0 | if (args.length > 3){ |
50 | 0 | proxyUsername = args[3]; |
51 | |
} |
52 | 0 | if (args.length > 4){ |
53 | 0 | proxyPassword = args[4]; |
54 | |
} |
55 | 0 | LibraryDownloader downloader = new LibraryDownloader(muleHome, proxyHost, proxyPort, proxyUsername, proxyPassword); |
56 | 0 | addLibrariesToClasspath(downloader.downloadLibraries()); |
57 | |
} |
58 | 0 | } |
59 | |
|
60 | |
private static void addLibrariesToClasspath(List urls) |
61 | |
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException |
62 | |
{ |
63 | 0 | ClassLoader sys = ClassLoader.getSystemClassLoader(); |
64 | 0 | if (!(sys instanceof URLClassLoader)) |
65 | |
{ |
66 | 0 | throw new IllegalArgumentException( |
67 | |
"PANIC: Mule has been started with an unsupported classloader: " + sys.getClass().getName() |
68 | |
+ ". " + "Please report this error to user<at>mule<dot>codehaus<dot>org"); |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | 0 | URLClassLoader sysCl = (URLClassLoader)sys; |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | 0 | Class refClass = URLClassLoader.class; |
79 | 0 | Method methodAddUrl = refClass.getDeclaredMethod("addURL", new Class[]{URL.class}); |
80 | 0 | methodAddUrl.setAccessible(true); |
81 | 0 | for (Iterator it = urls.iterator(); it.hasNext();) |
82 | |
{ |
83 | 0 | URL url = (URL)it.next(); |
84 | 0 | methodAddUrl.invoke(sysCl, new Object[]{url}); |
85 | |
} |
86 | 0 | } |
87 | |
} |