-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArecaClassLoader.java
More file actions
132 lines (111 loc) · 4.01 KB
/
Copy pathArecaClassLoader.java
File metadata and controls
132 lines (111 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package com.application.areca.impl.tools;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import com.myJava.util.log.Logger;
/**
* A classloader implementation that points to the jars and zip files contained in the "libext" subdirectory of Areca
* <BR>(ie at the same level of the "lib" directory)
* <BR>
* @author Olivier PETRUCCI
* <BR>
*
*/
/*
Copyright 2005-2015, Olivier PETRUCCI.
This file is part of Areca.
Areca is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Areca is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Areca; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
public class ArecaClassLoader extends URLClassLoader {
private static URL[] URLS = new URL[0];
private static String PREFIX = "areca-";
static {
try {
File jarDir = getArecaJarPath();
if (jarDir == null) {
Logger.defaultLogger().warn("No additional jar files will be loaded");
} else {
//Logger.defaultLogger().fine("Looking for additional jar files in " + jarDir + " ...");
String loadedList = "";
// List jars that have already been loaded by Areca
String prefix = jarDir.getAbsolutePath();
Set alreadyLoaded = new HashSet();
StringTokenizer stt = new StringTokenizer(System.getProperty("java.class.path"), System.getProperty("path.separator"));
while (stt.hasMoreTokens()) {
String item = stt.nextToken();
if (item.startsWith(prefix)) {
String name = new File(item).getName();
alreadyLoaded.add(name);
loadedList += ", " + name;
}
}
//Logger.defaultLogger().fine("Already loaded : " + loadedList.substring(2));
// List jars to be dynamically loaded, and build the URL list
File[] jars = jarDir.listFiles();
if (jars != null) {
ArrayList list = new ArrayList();
String dynamicList = "";
for (int i=0; i<jars.length; i++) {
String jarName = jars[i].getName();
if (
(jarName.toLowerCase().endsWith(".jar") || jarName.toLowerCase().endsWith(".zip"))
&& jarName.startsWith(PREFIX)
&& (! alreadyLoaded.contains(jars[i].getName()))
) {
list.add(jars[i].toURI().toURL());
dynamicList += ", " + jars[i].getName();
}
}
URLS = (URL[])list.toArray(new URL[list.size()]);
/*
if (dynamicList.length() < 2) {
Logger.defaultLogger().fine("No additional jar files detected in " + jarDir);
} else {
Logger.defaultLogger().fine("Additional jar files : " + dynamicList.substring(2));
}
*/
}
}
} catch (Throwable e) {
Logger.defaultLogger().error("Unable to instanciate dynamic classloader", e);
}
}
private static File getArecaJarPath() {
StringTokenizer stt = new StringTokenizer(System.getProperty("java.class.path"), System.getProperty("path.separator"));
String arecajar = null;
while (stt.hasMoreTokens()) {
String item = stt.nextToken();
if (item.endsWith("\\areca.jar") || item.endsWith("/areca.jar")) {
arecajar = item;
break;
}
}
if (arecajar == null) {
Logger.defaultLogger().warn("Unable to locate areca jar file");
return null;
} else {
File jarDir = new File(arecajar).getParentFile();
return jarDir;
}
}
public ArecaClassLoader() {
super(URLS);
}
public ArecaClassLoader(ClassLoader parent) {
super(URLS, parent);
}
}