1 /* 2 * $Id: GuiInstallerLibraryDownloader.java 7976 2007-08-21 14:26:13Z dirk.olmes $ 3 * -------------------------------------------------------------------------------------- 4 * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com 5 * 6 * The software in this package is published under the terms of the CPAL v1.0 7 * license, a copy of which has been included with this distribution in the 8 * LICENSE.txt file. 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 public class GuiInstallerLibraryDownloader 24 { 25 private static String proxyHost = null; 26 private static String proxyPort = null; 27 private static String proxyUsername = null; 28 private static String proxyPassword = null; 29 30 public static void main(String args[]) throws Exception 31 { 32 File muleHome = new File(args[0]); 33 34 // Build up a list of libraries from $MULE_HOME/lib/* and add them to the 35 // classpath. 36 DefaultMuleClassPathConfig classPath = new DefaultMuleClassPathConfig(muleHome, muleHome); 37 addLibrariesToClasspath(classPath.getURLs()); 38 39 // One-time download to get libraries not included in the Mule distribution 40 // and store them in MULE_HOME/lib/user. 41 if (!ClassUtils.isClassOnPath("javax.activation.DataSource", GuiInstallerLibraryDownloader.class)) 42 { 43 if (args.length > 1){ 44 proxyHost = args[1]; 45 } 46 if (args.length > 2){ 47 proxyPort = args[2]; 48 } 49 if (args.length > 3){ 50 proxyUsername = args[3]; 51 } 52 if (args.length > 4){ 53 proxyPassword = args[4]; 54 } 55 LibraryDownloader downloader = new LibraryDownloader(muleHome, proxyHost, proxyPort, proxyUsername, proxyPassword); 56 addLibrariesToClasspath(downloader.downloadLibraries()); 57 } 58 } 59 60 private static void addLibrariesToClasspath(List urls) 61 throws NoSuchMethodException, IllegalAccessException, InvocationTargetException 62 { 63 ClassLoader sys = ClassLoader.getSystemClassLoader(); 64 if (!(sys instanceof URLClassLoader)) 65 { 66 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 // system classloader is in this case the one that launched the application, 72 // which is usually something like a JDK-vendor proprietary AppClassLoader 73 URLClassLoader sysCl = (URLClassLoader)sys; 74 75 // get a Method ref from the normal class, but invoke on a proprietary parent 76 // object, 77 // as this method is usually protected in those classloaders 78 Class refClass = URLClassLoader.class; 79 Method methodAddUrl = refClass.getDeclaredMethod("addURL", new Class[]{URL.class}); 80 methodAddUrl.setAccessible(true); 81 for (Iterator it = urls.iterator(); it.hasNext();) 82 { 83 URL url = (URL)it.next(); 84 methodAddUrl.invoke(sysCl, new Object[]{url}); 85 } 86 } 87 }