Coverage Report - org.mule.modules.boot.GuiInstallerLibraryDownloader
 
Classes in this File Line Coverage Branch Coverage Complexity
GuiInstallerLibraryDownloader
0%
0/31
0%
0/9
5
 
 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  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  
         // Build up a list of libraries from $MULE_HOME/lib/* and add them to the
 35  
         // classpath.
 36  0
         DefaultMuleClassPathConfig classPath = new DefaultMuleClassPathConfig(muleHome, muleHome);
 37  0
         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  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  
         // system classloader is in this case the one that launched the application,
 72  
         // which is usually something like a JDK-vendor proprietary AppClassLoader
 73  0
         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  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  
 }