1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jadira.scanner.file.locator;
17
18 import java.io.File;
19 import java.net.MalformedURLException;
20 import java.net.URL;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.StringTokenizer;
24
25 import org.jadira.scanner.core.api.Locator;
26 import org.jadira.scanner.core.exception.ClasspathAccessException;
27
28
29
30
31
32 public class JavaClasspathUrlLocator implements Locator<URL> {
33
34 @Override
35 public List<URL> locate() {
36
37 List<URL> list = new ArrayList<URL>();
38 String classpath = System.getProperty("java.class.path");
39 StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator);
40
41 while (tokenizer.hasMoreTokens()) {
42
43 String path = tokenizer.nextToken();
44
45 File fp = new File(path);
46 if (!fp.exists()) {
47 throw new ClasspathAccessException("File in java.class.path does not exist: " + fp);
48 }
49
50 try {
51 list.add(fp.toURI().toURL());
52 } catch (MalformedURLException e) {
53 throw new ClasspathAccessException("URL was invalid: " + fp.toURI().toString(), e);
54 }
55 }
56 return list;
57 }
58 }
59