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