Coverage Report - org.mule.module.boot.DefaultMuleClassPathConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultMuleClassPathConfig
0%
0/35
0%
0/10
2.125
DefaultMuleClassPathConfig$1
0%
0/4
N/A
2.125
 
 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.boot;
 8  
 
 9  
 import java.io.File;
 10  
 import java.io.FileFilter;
 11  
 import java.io.IOException;
 12  
 import java.net.MalformedURLException;
 13  
 import java.net.URL;
 14  
 import java.util.ArrayList;
 15  
 import java.util.Arrays;
 16  
 import java.util.Collections;
 17  
 import java.util.Iterator;
 18  
 import java.util.List;
 19  
 
 20  
 /**
 21  
  * Constructs a default set of JAR Urls located under Mule home folder.
 22  
  */
 23  
 // TODO this duplicates DefaultMuleClassPathConfig in the reboot module. See if this class can be moved to mule-core
 24  
 public class DefaultMuleClassPathConfig
 25  
 {
 26  
     protected static final String MULE_DIR = "/lib/mule";
 27  
     protected static final String USER_DIR = "/lib/user";
 28  
     protected static final String OPT_DIR = "/lib/opt";
 29  
 
 30  0
     private List urls = new ArrayList();
 31  
 
 32  
     /**
 33  
      * Constructs a new DefaultMuleClassPathConfig.
 34  
      * @param muleHome Mule home directory
 35  
      * @param muleBase Mule base directory
 36  
      */
 37  
     public DefaultMuleClassPathConfig(File muleHome, File muleBase)
 38  0
     {
 39  
         /**
 40  
          * Pick up any local jars, if there are any. Doing this here insures that any
 41  
          * local class that override the global classes will in fact do so.
 42  
          */
 43  
         try
 44  
         {
 45  0
             if (!muleHome.getCanonicalFile().equals(muleBase.getCanonicalFile()))
 46  
             {
 47  0
                 File userOverrideDir = new File(muleBase, USER_DIR);
 48  0
                 this.addFile(userOverrideDir);
 49  0
                 this.addFiles(this.listJars(userOverrideDir));
 50  
             }
 51  
         }
 52  0
         catch (IOException ioe)
 53  
         {
 54  0
             System.out.println("Unable to check to see if there are local jars to load: " + ioe.toString());
 55  0
         }
 56  
 
 57  0
         File userDir = new File(muleHome, USER_DIR);
 58  0
         this.addFile(userDir);
 59  0
         this.addFiles(this.listJars(userDir));
 60  
 
 61  0
         File muleDir = new File(muleHome, MULE_DIR);
 62  0
         this.addFile(muleDir);
 63  0
         this.addFiles(this.listJars(muleDir));
 64  
 
 65  0
         File optDir = new File(muleHome, OPT_DIR);
 66  0
         this.addFile(optDir);
 67  0
         this.addFiles(this.listJars(optDir));
 68  0
     }
 69  
 
 70  
     /**
 71  
      * Getter for property 'urls'.
 72  
      *
 73  
      * @return A copy of 'urls'. Items are java.net.URL
 74  
      */
 75  
     public List getURLs()
 76  
     {
 77  0
         return new ArrayList(this.urls);
 78  
     }
 79  
 
 80  
     /**
 81  
      * Setter for property 'urls'.
 82  
      *
 83  
      * @param urls Value to set for property 'urls'.
 84  
      */
 85  
     public void addURLs(List urls)
 86  
     {
 87  0
         if (urls != null && !urls.isEmpty())
 88  
         {
 89  0
             this.urls.addAll(urls);
 90  
         }
 91  0
     }
 92  
 
 93  
     /**
 94  
      * Add a URL to Mule's classpath.
 95  
      *
 96  
      * @param url folder (should end with a slash) or jar path
 97  
      */
 98  
     public void addURL(URL url)
 99  
     {
 100  0
         this.urls.add(url);
 101  0
     }
 102  
 
 103  
     public void addFiles(List files)
 104  
     {
 105  0
         for (Iterator i = files.iterator(); i.hasNext();)
 106  
         {
 107  0
             this.addFile((File)i.next());
 108  
         }
 109  0
     }
 110  
 
 111  
     public void addFile(File jar)
 112  
     {
 113  
         try
 114  
         {
 115  0
             this.addURL(jar.getAbsoluteFile().toURI().toURL());
 116  
         }
 117  0
         catch (MalformedURLException mux)
 118  
         {
 119  0
             throw new RuntimeException("Failed to construct a classpath URL", mux);
 120  0
         }
 121  0
     }
 122  
 
 123  
     /**
 124  
      * Find and if necessary filter the jars for classpath.
 125  
      *
 126  
      * @return a list of {@link File}s
 127  
      */
 128  
     protected List listJars(File path)
 129  
     {
 130  0
         File[] jars = path.listFiles(new FileFilter()
 131  0
         {
 132  
             public boolean accept(File pathname)
 133  
             {
 134  
                 try
 135  
                 {
 136  0
                     return pathname.getCanonicalPath().endsWith(".jar");
 137  
                 }
 138  0
                 catch (IOException e)
 139  
                 {
 140  0
                     throw new RuntimeException(e.getMessage());
 141  
                 }
 142  
             }
 143  
         });
 144  
 
 145  0
         return jars == null ? Collections.EMPTY_LIST : Arrays.asList(jars);
 146  
     }
 147  
 
 148  
 }