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  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.module.launcher;
 8  
 
 9  
 import org.mule.module.reboot.MuleContainerBootstrapUtils;
 10  
 import org.mule.util.FileUtils;
 11  
 import org.mule.util.SystemUtils;
 12  
 
 13  
 import java.io.File;
 14  
 import java.net.URL;
 15  
 import java.util.Collection;
 16  
 
 17  
 import org.apache.commons.logging.Log;
 18  
 import org.apache.commons.logging.LogFactory;
 19  
 
 20  
 /**
 21  
  *  Load $MULE_HOME/lib/shared/<domain> libraries.
 22  
  */
 23  
 public class MuleSharedDomainClassLoader extends GoodCitizenClassLoader
 24  
 {
 25  
 
 26  0
     protected transient Log logger = LogFactory.getLog(getClass());
 27  
 
 28  0
     private final String domain = "undefined";
 29  
 
 30  
     @SuppressWarnings("unchecked")
 31  
     public MuleSharedDomainClassLoader(String domain, ClassLoader parent)
 32  
     {
 33  0
         super(new URL[0], parent);
 34  
         try
 35  
         {
 36  0
             File domainDir = new File(MuleContainerBootstrapUtils.getMuleHome(), "lib/shared/" + domain);
 37  0
             if (!domainDir.exists())
 38  
             {
 39  0
                 throw new IllegalArgumentException(
 40  
                         String.format("Shared ClassLoader Domain '%s' doesn't exist", domain));
 41  
             }
 42  
 
 43  0
             if (!domainDir.canRead())
 44  
             {
 45  0
                 throw new IllegalArgumentException(
 46  
                         String.format("Shared ClassLoader Domain '%s' is not accessible", domain));
 47  
             }
 48  
 
 49  0
             Collection<File> jars = FileUtils.listFiles(domainDir, new String[] {"jar"}, false);
 50  
 
 51  0
             if (logger.isDebugEnabled())
 52  
             {
 53  
                 {
 54  0
                     StringBuilder sb = new StringBuilder();
 55  0
                     sb.append("Loading Shared ClassLoader Domain: ").append(domain).append(SystemUtils.LINE_SEPARATOR);
 56  0
                     sb.append("=============================").append(SystemUtils.LINE_SEPARATOR);
 57  
 
 58  0
                     for (File jar : jars)
 59  
                     {
 60  0
                         sb.append(jar.toURI().toURL()).append(SystemUtils.LINE_SEPARATOR);
 61  
                     }
 62  
 
 63  0
                     sb.append("=============================").append(SystemUtils.LINE_SEPARATOR);
 64  
 
 65  0
                     logger.debug(sb.toString());
 66  
                 }
 67  
             }
 68  
 
 69  0
             for (File jar : jars)
 70  
             {
 71  0
                 addURL(jar.toURI().toURL());
 72  
             }
 73  
         }
 74  0
         catch (Throwable t)
 75  
         {
 76  0
             throw new RuntimeException(t);
 77  0
         }
 78  0
     }
 79  
 
 80  
     public String getDomain()
 81  
     {
 82  0
         return domain;
 83  
     }
 84  
 
 85  
     @Override
 86  
     public String toString()
 87  
     {
 88  0
         return String.format("%s[%s]@%s", getClass().getName(),
 89  
                              domain,
 90  
                              Integer.toHexString(System.identityHashCode(this)));
 91  
     }
 92  
 
 93  
 }