Lines 168-181
Link Here
|
168 |
|
168 |
|
169 |
private static final ErrorManager ERR = ErrorManager.getDefault().getInstance(ClassPath.class.getName()); |
169 |
private static final ErrorManager ERR = ErrorManager.getDefault().getInstance(ClassPath.class.getName()); |
170 |
|
170 |
|
171 |
private static final Lookup.Result/*<ClassPathProvider>*/ implementations = |
171 |
private static final Lookup.Result<? extends ClassPathProvider> implementations = |
172 |
Lookup.getDefault().lookup(new Lookup.Template(ClassPathProvider.class)); |
172 |
Lookup.getDefault().lookupResult(ClassPathProvider.class); |
173 |
|
173 |
|
174 |
private ClassPathImplementation impl; |
174 |
private ClassPathImplementation impl; |
175 |
private FileObject[] rootsCache; |
175 |
private FileObject[] rootsCache; |
176 |
private PropertyChangeListener pListener; |
176 |
private PropertyChangeListener pListener; |
177 |
private RootsListener rootsListener; |
177 |
private RootsListener rootsListener; |
178 |
private List entriesCache; |
178 |
private List<ClassPath.Entry> entriesCache; |
179 |
|
179 |
|
180 |
/** |
180 |
/** |
181 |
* Retrieves valid roots of ClassPath, in the proper order. |
181 |
* Retrieves valid roots of ClassPath, in the proper order. |
Lines 187-196
Link Here
|
187 |
*/ |
187 |
*/ |
188 |
public synchronized FileObject[] getRoots() { |
188 |
public synchronized FileObject[] getRoots() { |
189 |
if (rootsCache == null || rootsListener == null) { |
189 |
if (rootsCache == null || rootsListener == null) { |
190 |
List entries = this.entries(); |
190 |
List<ClassPath.Entry> entries = this.entries(); |
191 |
List l = new ArrayList (); |
191 |
List<FileObject> l = new ArrayList<FileObject> (); |
192 |
for (Iterator it = entries.iterator(); it.hasNext();) { |
192 |
for (Entry entry : entries) { |
193 |
Entry entry = (Entry) it.next(); |
|
|
194 |
RootsListener rootsListener = this.getRootsListener(); |
193 |
RootsListener rootsListener = this.getRootsListener(); |
195 |
if (rootsListener != null) { |
194 |
if (rootsListener != null) { |
196 |
rootsListener.addRoot (entry.getURL()); |
195 |
rootsListener.addRoot (entry.getURL()); |
Lines 199-205
Link Here
|
199 |
if (fo != null) |
198 |
if (fo != null) |
200 |
l.add (fo); |
199 |
l.add (fo); |
201 |
} |
200 |
} |
202 |
this.rootsCache = (FileObject[]) l.toArray (new FileObject[l.size()]); |
201 |
this.rootsCache = l.toArray (new FileObject[l.size()]); |
203 |
} |
202 |
} |
204 |
return this.rootsCache; |
203 |
return this.rootsCache; |
205 |
} |
204 |
} |
Lines 211-234
Link Here
|
211 |
* instance. Clients must assume that the returned value is immutable. |
210 |
* instance. Clients must assume that the returned value is immutable. |
212 |
* @return list of definition entries (Entry instances) |
211 |
* @return list of definition entries (Entry instances) |
213 |
*/ |
212 |
*/ |
214 |
public List entries() { |
213 |
public List<ClassPath.Entry> entries() { |
215 |
synchronized (this) { |
214 |
synchronized (this) { |
216 |
if (this.entriesCache != null) { |
215 |
if (this.entriesCache != null) { |
217 |
return this.entriesCache; |
216 |
return this.entriesCache; |
218 |
} |
217 |
} |
219 |
} |
218 |
} |
220 |
List resources = impl.getResources(); |
219 |
List<? extends PathResourceImplementation> resources = impl.getResources(); |
221 |
synchronized (this) { |
220 |
synchronized (this) { |
222 |
if (this.entriesCache == null) { |
221 |
if (this.entriesCache == null) { |
223 |
//The ClassPathImplementation.getResources () should never return |
222 |
//The ClassPathImplementation.getResources () should never return |
224 |
// null but it was not explicitly stated in the javadoc |
223 |
// null but it was not explicitly stated in the javadoc |
225 |
if (resources == null) { |
224 |
if (resources == null) { |
226 |
this.entriesCache = Collections.EMPTY_LIST; |
225 |
this.entriesCache = Collections.<ClassPath.Entry>emptyList(); |
227 |
} |
226 |
} |
228 |
else { |
227 |
else { |
229 |
List cache = new ArrayList (); |
228 |
List<ClassPath.Entry> cache = new ArrayList<ClassPath.Entry> (); |
230 |
for (Iterator it = resources.iterator(); it.hasNext();) { |
229 |
for (PathResourceImplementation pr : resources) { |
231 |
PathResourceImplementation pr = (PathResourceImplementation)it.next(); |
|
|
232 |
URL[] roots = pr.getRoots(); |
230 |
URL[] roots = pr.getRoots(); |
233 |
for (int i=0; i <roots.length; i++) { |
231 |
for (int i=0; i <roots.length; i++) { |
234 |
Entry e = new Entry (roots[i]); |
232 |
Entry e = new Entry (roots[i]); |
Lines 277-285
Link Here
|
277 |
* @param resourceName resource name |
275 |
* @param resourceName resource name |
278 |
* @return list of resources identified by the given name. |
276 |
* @return list of resources identified by the given name. |
279 |
*/ |
277 |
*/ |
280 |
public final List findAllResources(String resourceName) { |
278 |
public final List<? extends FileObject> findAllResources(String resourceName) { |
281 |
FileObject[] roots = getRoots(); |
279 |
FileObject[] roots = getRoots(); |
282 |
List l = new ArrayList(roots.length); |
280 |
List<FileObject> l = new ArrayList<FileObject>(roots.length); |
283 |
int[] idx = new int[] { 0 }; |
281 |
int[] idx = new int[] { 0 }; |
284 |
String[] namec = parseResourceName(resourceName); |
282 |
String[] namec = parseResourceName(resourceName); |
285 |
while (idx[0] < roots.length) { |
283 |
while (idx[0] < roots.length) { |
Lines 347-353
Link Here
|
347 |
*/ |
345 |
*/ |
348 |
public final FileObject findOwnerRoot(FileObject resource) { |
346 |
public final FileObject findOwnerRoot(FileObject resource) { |
349 |
FileObject[] roots = getRoots(); |
347 |
FileObject[] roots = getRoots(); |
350 |
Set/*<FileObject>*/ rootsSet = new HashSet(Arrays.asList(roots)); |
348 |
Set<FileObject> rootsSet = new HashSet<FileObject>(Arrays.asList(roots)); |
351 |
for (FileObject f = resource; f != null; f = f.getParent()) { |
349 |
for (FileObject f = resource; f != null; f = f.getParent()) { |
352 |
if (rootsSet.contains(f)) { |
350 |
if (rootsSet.contains(f)) { |
353 |
return f; |
351 |
return f; |
Lines 439-447
Link Here
|
439 |
} |
437 |
} |
440 |
boolean log = ERR.isLoggable(ErrorManager.INFORMATIONAL); |
438 |
boolean log = ERR.isLoggable(ErrorManager.INFORMATIONAL); |
441 |
if (log) ERR.log("CP.getClassPath: " + f + " of type " + id); |
439 |
if (log) ERR.log("CP.getClassPath: " + f + " of type " + id); |
442 |
Iterator it = implementations.allInstances().iterator(); |
440 |
for (ClassPathProvider impl : implementations.allInstances()) { |
443 |
while (it.hasNext()) { |
|
|
444 |
ClassPathProvider impl = (ClassPathProvider)it.next(); |
445 |
ClassPath cp = impl.findClassPath(f, id); |
441 |
ClassPath cp = impl.findClassPath(f, id); |
446 |
if (cp != null) { |
442 |
if (cp != null) { |
447 |
if (log) ERR.log(" got result " + cp + " from " + impl); |
443 |
if (log) ERR.log(" got result " + cp + " from " + impl); |
Lines 566-572
Link Here
|
566 |
* name, the next one is either the extension or null. |
562 |
* name, the next one is either the extension or null. |
567 |
*/ |
563 |
*/ |
568 |
private static String[] parseResourceName(String name) { |
564 |
private static String[] parseResourceName(String name) { |
569 |
Collection parsed = new ArrayList(name.length() / 4); |
565 |
Collection<String> parsed = new ArrayList<String>(name.length() / 4); |
570 |
char[] chars = name.toCharArray(); |
566 |
char[] chars = name.toCharArray(); |
571 |
char ch; |
567 |
char ch; |
572 |
int pos = 0; |
568 |
int pos = 0; |
Lines 609-615
Link Here
|
609 |
System.err.println("parsed size is not even!!"); |
605 |
System.err.println("parsed size is not even!!"); |
610 |
System.err.println("input = " + name); |
606 |
System.err.println("input = " + name); |
611 |
} |
607 |
} |
612 |
return (String[])parsed.toArray(new String[parsed.size()]); |
608 |
return parsed.toArray(new String[parsed.size()]); |
613 |
} |
609 |
} |
614 |
|
610 |
|
615 |
/** |
611 |
/** |
Lines 641-649
Link Here
|
641 |
return f; |
637 |
return f; |
642 |
} |
638 |
} |
643 |
|
639 |
|
644 |
private static final Reference EMPTY_REF = new SoftReference(null); |
640 |
private static final Reference<ClassLoader> EMPTY_REF = new SoftReference<ClassLoader>(null); |
645 |
|
641 |
|
646 |
private Reference refClassLoader = EMPTY_REF; |
642 |
private Reference<ClassLoader> refClassLoader = EMPTY_REF; |
647 |
|
643 |
|
648 |
/* package private */synchronized void resetClassLoader(ClassLoader cl) { |
644 |
/* package private */synchronized void resetClassLoader(ClassLoader cl) { |
649 |
if (refClassLoader.get() == cl) |
645 |
if (refClassLoader.get() == cl) |
Lines 663-674
Link Here
|
663 |
*/ |
659 |
*/ |
664 |
public final synchronized ClassLoader getClassLoader(boolean cache) { |
660 |
public final synchronized ClassLoader getClassLoader(boolean cache) { |
665 |
// XXX consider adding ClassLoader and/or InputOutput and/or PermissionCollection params |
661 |
// XXX consider adding ClassLoader and/or InputOutput and/or PermissionCollection params |
666 |
Object o = refClassLoader.get(); |
662 |
ClassLoader o = refClassLoader.get(); |
667 |
if (!cache || o == null) { |
663 |
if (!cache || o == null) { |
668 |
o = ClassLoaderSupport.create(this); |
664 |
o = ClassLoaderSupport.create(this); |
669 |
refClassLoader = new SoftReference(o); |
665 |
refClassLoader = new SoftReference<ClassLoader>(o); |
670 |
} |
666 |
} |
671 |
return (ClassLoader)o; |
667 |
return o; |
672 |
} |
668 |
} |
673 |
|
669 |
|
674 |
|
670 |
|
Lines 695-708
Link Here
|
695 |
} |
691 |
} |
696 |
|
692 |
|
697 |
|
693 |
|
698 |
private static class RootsListener extends WeakReference implements FileChangeListener, Runnable { |
694 |
private static class RootsListener extends WeakReference<ClassPath> implements FileChangeListener, Runnable { |
699 |
|
695 |
|
700 |
private boolean initialized; |
696 |
private boolean initialized; |
701 |
private Set roots; |
697 |
private Set<String> roots; |
702 |
|
698 |
|
703 |
private RootsListener (ClassPath owner) { |
699 |
private RootsListener (ClassPath owner) { |
704 |
super (owner, Utilities.activeReferenceQueue()); |
700 |
super (owner, Utilities.activeReferenceQueue()); |
705 |
roots = new HashSet (); |
701 |
roots = new HashSet<String> (); |
706 |
} |
702 |
} |
707 |
|
703 |
|
708 |
public void addRoot (URL url) { |
704 |
public void addRoot (URL url) { |
Lines 867-873
Link Here
|
867 |
return fileSystems; |
863 |
return fileSystems; |
868 |
} |
864 |
} |
869 |
File[] roots = File.listRoots(); |
865 |
File[] roots = File.listRoots(); |
870 |
Set allRoots = new LinkedHashSet(); |
866 |
Set<FileSystem> allRoots = new LinkedHashSet<FileSystem>(); |
871 |
assert roots != null && roots.length > 0 : "Could not list file roots"; // NOI18N |
867 |
assert roots != null && roots.length > 0 : "Could not list file roots"; // NOI18N |
872 |
|
868 |
|
873 |
for (int i = 0; i < roots.length; i++) { |
869 |
for (int i = 0; i < roots.length; i++) { |