Coverage Report - org.mule.module.launcher.MuleApplicationClassLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleApplicationClassLoader
0%
0/31
0%
0/16
0
 
 1  
 /*
 2  
  * $Id: MuleApplicationClassLoader.java 20088 2010-11-05 16:51:41Z aperepel $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.module.launcher;
 12  
 
 13  
 import org.mule.api.config.MuleProperties;
 14  
 import org.mule.util.FileUtils;
 15  
 import org.mule.util.SystemUtils;
 16  
 
 17  
 import org.apache.commons.logging.Log;
 18  
 import org.apache.commons.logging.LogFactory;
 19  
 
 20  
 import java.io.File;
 21  
 import java.io.IOException;
 22  
 import java.net.URL;
 23  
 import java.util.Collection;
 24  
 
 25  
 public class MuleApplicationClassLoader extends GoodCitizenClassLoader
 26  
 {
 27  
 
 28  
     /**
 29  
      * Library directory in Mule application.
 30  
      */
 31  
     public static final String PATH_LIBRARY = "lib";
 32  
 
 33  
     /**
 34  
      * Classes and resources directory in Mule application.
 35  
      */
 36  
     public static final String PATH_CLASSES = "classes";
 37  
 
 38  0
     protected static final URL[] CLASSPATH_EMPTY = new URL[0];
 39  0
     protected final transient Log logger = LogFactory.getLog(getClass());
 40  
     private String appName;
 41  
 
 42  
     public MuleApplicationClassLoader(String appName, ClassLoader parentCl)
 43  
     {
 44  0
         super(CLASSPATH_EMPTY, parentCl);
 45  0
         this.appName = appName;
 46  
         try
 47  
         {
 48  
             // get lib dir
 49  0
             final String muleHome = System.getProperty(MuleProperties.MULE_HOME_DIRECTORY_PROPERTY);
 50  0
             String configPath = String.format("%s/apps/%s", muleHome, appName);
 51  0
             File parentFile = new File(configPath); 
 52  0
             File classesDir = new File(parentFile, PATH_CLASSES);
 53  0
             addURL(classesDir.toURI().toURL());
 54  
 
 55  0
             File libDir = new File(parentFile, PATH_LIBRARY);
 56  
 
 57  0
             if (logger.isInfoEnabled())
 58  
             {
 59  0
                 logger.info(String.format("[%s] Library directory: %s", appName, libDir));
 60  
             }
 61  
 
 62  0
             if (libDir.exists() && libDir.canRead())
 63  
             {
 64  
                 @SuppressWarnings("unchecked")
 65  0
                 Collection<File> jars = FileUtils.listFiles(libDir, new String[] {"jar"}, false);
 66  
 
 67  0
                 if (!jars.isEmpty() && logger.isInfoEnabled())
 68  
                 {
 69  0
                     StringBuilder sb = new StringBuilder();
 70  0
                     sb.append(String.format("[%s] Loading the following jars:%n", appName));
 71  0
                     sb.append("=============================").append(SystemUtils.LINE_SEPARATOR);
 72  
 
 73  0
                     for (File jar : jars)
 74  
                     {
 75  0
                         sb.append(jar.toURI().toURL()).append(SystemUtils.LINE_SEPARATOR);
 76  
                     }
 77  
 
 78  0
                     sb.append("=============================").append(SystemUtils.LINE_SEPARATOR);
 79  
 
 80  0
                     logger.info(sb.toString());
 81  
                 }
 82  
 
 83  0
                 for (File jar : jars)
 84  
                 {
 85  0
                     addURL(jar.toURI().toURL());
 86  
                 }
 87  
             }
 88  
 
 89  
         }
 90  0
         catch (IOException e)
 91  
         {
 92  0
             if (logger.isDebugEnabled())
 93  
             {
 94  0
                 logger.debug(String.format("[%s]", appName), e);
 95  
             }
 96  0
         }
 97  0
     }
 98  
 
 99  
     public String getAppName()
 100  
     {
 101  0
         return appName;
 102  
     }
 103  
 
 104  
     @Override
 105  
     public String toString()
 106  
     {
 107  0
         return String.format("%s[%s]@%s", getClass().getName(),
 108  
                              appName,
 109  
                              Integer.toHexString(System.identityHashCode(this)));
 110  
     }
 111  
 
 112  
 }