|
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 |
| package edu.rice.cs.drjava.model.repl.newjvm; |
|
38 |
| |
|
39 |
| import java.io.File; |
|
40 |
| import java.util.LinkedList; |
|
41 |
| import java.lang.ClassLoader; |
|
42 |
| import edu.rice.cs.plt.io.IOUtil; |
|
43 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
44 |
| import edu.rice.cs.plt.lambda.Lambda; |
|
45 |
| import edu.rice.cs.plt.reflect.PathClassLoader; |
|
46 |
| |
|
47 |
| import static edu.rice.cs.plt.debug.DebugUtil.error; |
|
48 |
| import static edu.rice.cs.plt.debug.DebugUtil.debug; |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| public class ClassPathManager implements Lambda<ClassLoader, ClassLoader> { |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| private final LinkedList<File> _projectCP; |
|
60 |
| private final LinkedList<File> _buildCP; |
|
61 |
| private final LinkedList<File> _projectFilesCP; |
|
62 |
| private final LinkedList<File> _externalFilesCP; |
|
63 |
| private final LinkedList<File> _extraCP; |
|
64 |
| |
|
65 |
| |
|
66 |
| private final Iterable<File> _fullPath; |
|
67 |
| |
|
68 |
206
| public ClassPathManager(Iterable<File> builtInCP) {
|
|
69 |
206
| _projectCP = new LinkedList<File>();
|
|
70 |
206
| _buildCP = new LinkedList<File>();
|
|
71 |
206
| _projectFilesCP = new LinkedList<File>();
|
|
72 |
206
| _externalFilesCP = new LinkedList<File>();
|
|
73 |
206
| _extraCP = new LinkedList<File>();
|
|
74 |
| |
|
75 |
206
| Iterable<Iterable<File>> allPaths =
|
|
76 |
| IterUtil.<Iterable<File>>make(IterUtil.asSizedIterable(_projectCP), |
|
77 |
| IterUtil.asSizedIterable(_buildCP), |
|
78 |
| IterUtil.asSizedIterable(_projectFilesCP), |
|
79 |
| IterUtil.asSizedIterable(_externalFilesCP), |
|
80 |
| IterUtil.asSizedIterable(_extraCP), |
|
81 |
| IterUtil.snapshot(builtInCP)); |
|
82 |
| |
|
83 |
| |
|
84 |
206
| _fullPath = IterUtil.collapse(IterUtil.map(allPaths, _makeSafeSnapshot));
|
|
85 |
206
| updateProperty();
|
|
86 |
| } |
|
87 |
| |
|
88 |
| public static final String INTERACTIONS_CLASS_PATH_PROPERTY = "edu.rice.cs.drjava.interactions.class.path"; |
|
89 |
| |
|
90 |
869
| protected void updateProperty() {
|
|
91 |
869
| System.setProperty(INTERACTIONS_CLASS_PATH_PROPERTY,IOUtil.pathToString(_fullPath));
|
|
92 |
| } |
|
93 |
| |
|
94 |
| private final Lambda<Iterable<File>, Iterable<File>> _makeSafeSnapshot = |
|
95 |
| new Lambda<Iterable<File>, Iterable<File>>() { |
|
96 |
14124
| public Iterable<File> value(Iterable<File> arg) {
|
|
97 |
14124
| synchronized(ClassPathManager.this) { return IterUtil.snapshot(arg); }
|
|
98 |
| } |
|
99 |
| }; |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
0
| public synchronized void addProjectCP(File f) { _projectCP.addFirst(f); updateProperty(); }
|
|
105 |
| |
|
106 |
0
| public synchronized Iterable<File> getProjectCP() { return IterUtil.snapshot(_projectCP); }
|
|
107 |
| |
|
108 |
| |
|
109 |
30
| public synchronized void addBuildDirectoryCP(File f) {
|
|
110 |
30
| _buildCP.remove(f);
|
|
111 |
30
| _buildCP.addFirst(f);
|
|
112 |
30
| updateProperty();
|
|
113 |
| } |
|
114 |
| |
|
115 |
0
| public synchronized Iterable<File> getBuildDirectoryCP() { return IterUtil.snapshot(_buildCP); }
|
|
116 |
| |
|
117 |
| |
|
118 |
182
| public synchronized void addProjectFilesCP(File f) {
|
|
119 |
182
| _projectFilesCP.remove(f);
|
|
120 |
182
| _projectFilesCP.addFirst(f);
|
|
121 |
182
| updateProperty();
|
|
122 |
| } |
|
123 |
| |
|
124 |
0
| public synchronized Iterable<File> getProjectFilesCP() { return IterUtil.snapshot(_projectFilesCP); }
|
|
125 |
| |
|
126 |
| |
|
127 |
225
| public synchronized void addExternalFilesCP(File f) {
|
|
128 |
225
| _externalFilesCP.remove(f);
|
|
129 |
225
| _externalFilesCP.addFirst(f);
|
|
130 |
225
| updateProperty();
|
|
131 |
| } |
|
132 |
| |
|
133 |
0
| public synchronized Iterable<File> getExternalFilesCP() { return IterUtil.snapshot(_externalFilesCP); }
|
|
134 |
| |
|
135 |
| |
|
136 |
2
| public synchronized void addExtraCP(File f) {
|
|
137 |
2
| _extraCP.remove(f);
|
|
138 |
2
| _extraCP.addFirst(f);
|
|
139 |
2
| updateProperty();
|
|
140 |
| } |
|
141 |
| |
|
142 |
0
| public Iterable<File> getExtraCP() { return IterUtil.snapshot(_extraCP); }
|
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
224
| public synchronized ClassLoader makeClassLoader(ClassLoader parent) {
|
|
152 |
224
| updateProperty();
|
|
153 |
224
| return new PathClassLoader(parent, _fullPath);
|
|
154 |
| } |
|
155 |
| |
|
156 |
| |
|
157 |
18
| public ClassLoader value(ClassLoader parent) { return makeClassLoader(parent); }
|
|
158 |
| |
|
159 |
| |
|
160 |
0
| public synchronized Iterable<File> getClassPath() { updateProperty(); return _fullPath; }
|
|
161 |
| } |