1
2
3
4
5
6
7
8
9
10
11 package org.mule.modules.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
26
27 public class DefaultMuleClassPathConfig
28 {
29 protected static final String MULE_DIR = "/lib/mule";
30 protected static final String USER_DIR = "/lib/user";
31 protected static final String OPT_DIR = "/lib/opt";
32
33 private List urls = new ArrayList();
34
35
36
37
38
39
40 public DefaultMuleClassPathConfig(File muleHome, File muleBase)
41 {
42
43
44
45
46 try
47 {
48 if (!muleHome.getCanonicalFile().equals(muleBase.getCanonicalFile()))
49 {
50 File userOverrideDir = new File(muleBase, USER_DIR);
51 this.addFile(userOverrideDir);
52 this.addFiles(this.listJars(userOverrideDir));
53 }
54 }
55 catch (IOException ioe)
56 {
57 System.out.println("Unable to check to see if there are local jars to load: " + ioe.toString());
58 }
59
60 File userDir = new File(muleHome, USER_DIR);
61 this.addFile(userDir);
62 this.addFiles(this.listJars(userDir));
63
64 File muleDir = new File(muleHome, MULE_DIR);
65 this.addFile(muleDir);
66 this.addFiles(this.listJars(muleDir));
67
68 File optDir = new File(muleHome, OPT_DIR);
69 this.addFile(optDir);
70 this.addFiles(this.listJars(optDir));
71 }
72
73
74
75
76
77
78 public List getURLs()
79 {
80 return new ArrayList(this.urls);
81 }
82
83
84
85
86
87
88 public void addURLs(List urls)
89 {
90 if (urls != null && !urls.isEmpty())
91 {
92 this.urls.addAll(urls);
93 }
94 }
95
96
97
98
99
100
101 public void addURL(URL url)
102 {
103 this.urls.add(url);
104 }
105
106 public void addFiles(List files)
107 {
108 for (Iterator i = files.iterator(); i.hasNext();)
109 {
110 this.addFile((File)i.next());
111 }
112 }
113
114 public void addFile(File jar)
115 {
116 try
117 {
118 this.addURL(jar.getAbsoluteFile().toURI().toURL());
119 }
120 catch (MalformedURLException mux)
121 {
122 throw new RuntimeException("Failed to construct a classpath URL", mux);
123 }
124 }
125
126
127
128
129
130
131 protected List listJars(File path)
132 {
133 File[] jars = path.listFiles(new FileFilter()
134 {
135 public boolean accept(File pathname)
136 {
137 try
138 {
139 return pathname.getCanonicalPath().endsWith(".jar");
140 }
141 catch (IOException e)
142 {
143 throw new RuntimeException(e.getMessage());
144 }
145 }
146 });
147
148 return jars == null ? Collections.EMPTY_LIST : Arrays.asList(jars);
149 }
150
151 }