Coverage Report - org.mule.module.launcher.MuleSharedDomainClassLoader
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleSharedDomainClassLoader
0%
0/25
0%
0/10
0
 
 1  
 /*
 2  
  * $Id: MuleSharedDomainClassLoader.java 19191 2010-08-25 21:05:23Z tcarlson $
 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.module.reboot.MuleContainerBootstrapUtils;
 14  
 import org.mule.util.FileUtils;
 15  
 import org.mule.util.SystemUtils;
 16  
 
 17  
 import java.io.File;
 18  
 import java.net.URL;
 19  
 import java.util.Collection;
 20  
 
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 
 24  
 /**
 25  
  *  Load $MULE_HOME/lib/shared/<domain> libraries.
 26  
  */
 27  
 public class MuleSharedDomainClassLoader extends GoodCitizenClassLoader
 28  
 {
 29  
 
 30  0
     protected transient Log logger = LogFactory.getLog(getClass());
 31  
 
 32  0
     private final String domain = "undefined";
 33  
 
 34  
     @SuppressWarnings("unchecked")
 35  
     public MuleSharedDomainClassLoader(String domain, ClassLoader parent)
 36  
     {
 37  0
         super(new URL[0], parent);
 38  
         try
 39  
         {
 40  0
             File domainDir = new File(MuleContainerBootstrapUtils.getMuleHome(), "lib/shared/" + domain);
 41  0
             if (!domainDir.exists())
 42  
             {
 43  0
                 throw new IllegalArgumentException(
 44  
                         String.format("Shared ClassLoader Domain '%s' doesn't exist", domain));
 45  
             }
 46  
 
 47  0
             if (!domainDir.canRead())
 48  
             {
 49  0
                 throw new IllegalArgumentException(
 50  
                         String.format("Shared ClassLoader Domain '%s' is not accessible", domain));
 51  
             }
 52  
 
 53  0
             Collection<File> jars = FileUtils.listFiles(domainDir, new String[] {"jar"}, false);
 54  
 
 55  0
             if (logger.isDebugEnabled())
 56  
             {
 57  
                 {
 58  0
                     StringBuilder sb = new StringBuilder();
 59  0
                     sb.append("Loading Shared ClassLoader Domain: ").append(domain).append(SystemUtils.LINE_SEPARATOR);
 60  0
                     sb.append("=============================").append(SystemUtils.LINE_SEPARATOR);
 61  
 
 62  0
                     for (File jar : jars)
 63  
                     {
 64  0
                         sb.append(jar.toURI().toURL()).append(SystemUtils.LINE_SEPARATOR);
 65  
                     }
 66  
 
 67  0
                     sb.append("=============================").append(SystemUtils.LINE_SEPARATOR);
 68  
 
 69  0
                     logger.debug(sb.toString());
 70  
                 }
 71  
             }
 72  
 
 73  0
             for (File jar : jars)
 74  
             {
 75  0
                 addURL(jar.toURI().toURL());
 76  
             }
 77  
         }
 78  0
         catch (Throwable t)
 79  
         {
 80  0
             throw new RuntimeException(t);
 81  0
         }
 82  0
     }
 83  
 
 84  
     public String getDomain()
 85  
     {
 86  0
         return domain;
 87  
     }
 88  
 
 89  
     @Override
 90  
     public String toString()
 91  
     {
 92  0
         return String.format("%s[%s]@%s", getClass().getName(),
 93  
                              domain,
 94  
                              Integer.toHexString(System.identityHashCode(this)));
 95  
     }
 96  
 
 97  
 }