1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.apache.commons.classscan.builtin; |
15 | |
|
16 | |
import java.io.File; |
17 | |
import java.io.IOException; |
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collections; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
import java.util.regex.Pattern; |
23 | |
|
24 | |
import org.apache.commons.classscan.ClassPathElement; |
25 | |
import org.apache.commons.classscan.ResourceFile; |
26 | |
import org.apache.commons.classscan.spi.model.SpiClassPath; |
27 | |
import org.apache.commons.classscan.spi.model.SpiClassPathElement; |
28 | |
import org.apache.commons.classscan.spi.model.SpiMetaClassLoader; |
29 | |
import org.apache.commons.classscan.spi.model.SpiMetaRegistry; |
30 | |
import org.slf4j.Logger; |
31 | |
import org.slf4j.LoggerFactory; |
32 | |
|
33 | |
public class BootstrapClassPath implements SpiClassPath { |
34 | |
|
35 | 0 | private static final Logger logger = LoggerFactory.getLogger(BootstrapClassPath.class); |
36 | |
|
37 | 0 | static Pattern PATH_SPLITTER = Pattern.compile(File.pathSeparator); |
38 | |
|
39 | |
private final SpiMetaRegistry registry; |
40 | |
|
41 | 0 | public BootstrapClassPath(SpiMetaRegistry registry) { |
42 | 0 | this.registry = registry; |
43 | 0 | } |
44 | |
|
45 | |
@Override |
46 | |
public List<? extends ClassPathElement> getClassPathElements() { |
47 | 0 | return getBootstrapLocations(); |
48 | |
} |
49 | |
|
50 | |
private List<SpiClassPathElement> getBootstrapLocations() { |
51 | 0 | List<SpiClassPathElement> locations= new ArrayList<SpiClassPathElement>(); |
52 | 0 | for(String element : parseBootstrapClassPathValues()) { |
53 | |
try { |
54 | 0 | SpiClassPathElement location = checkLocation(element); |
55 | 0 | if(location!=null) { |
56 | 0 | locations.add(location); |
57 | |
} |
58 | 0 | } catch (IOException e) { |
59 | 0 | logger.info("Bootstrap Classpath element "+element+" ignored", e); |
60 | 0 | } |
61 | |
} |
62 | 0 | return locations; |
63 | |
} |
64 | |
|
65 | |
String[] parseBootstrapClassPathValues() { |
66 | 0 | return PATH_SPLITTER.split(System.getProperty("sun.boot.class.path")); |
67 | |
} |
68 | |
|
69 | |
private SpiClassPathElement checkLocation(String element) throws IOException { |
70 | 0 | File location = new File(element); |
71 | 0 | return registry.createClassPathElement(location.toURI().toURL()); |
72 | |
} |
73 | |
|
74 | |
@Override |
75 | |
public SpiMetaClassLoader createMetaClassLoader(SpiMetaRegistry registry, ClassLoader classLoader) { |
76 | 0 | if(classLoader!=null) { |
77 | 0 | throw new IllegalArgumentException("BootStrap ClassLoader should be null"); |
78 | |
} |
79 | |
|
80 | 0 | return new BootstrapMetaClassLoader(registry); |
81 | |
} |
82 | |
|
83 | |
@Override |
84 | |
public Map<ClassPathElement, ResourceFile> getResources(String fileName) { |
85 | 0 | return Collections.emptyMap(); |
86 | |
} |
87 | |
} |