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