author | pgovereau |
Mon, 21 Apr 2014 17:57:47 -0400 | |
changeset 24222 | 244127f8dd79 |
parent 22163 | 3651128c74eb |
permissions | -rw-r--r-- |
1208 | 1 |
|
2 |
package com.sun.tools.javac.file; |
|
3 |
||
4 |
import java.io.File; |
|
5 |
import java.io.IOException; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.Collections; |
|
8 |
import java.util.List; |
|
9 |
import java.util.StringTokenizer; |
|
10 |
import java.util.jar.Attributes; |
|
11 |
import java.util.jar.JarFile; |
|
12 |
import java.util.jar.Manifest; |
|
13 |
||
14 |
import com.sun.tools.javac.util.Context; |
|
15 |
||
16 |
/** |
|
17 |
* Get meta-info about files. Default direct (non-caching) implementation. |
|
18 |
* @see CacheFSInfo |
|
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
19 |
* |
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
3380
diff
changeset
|
20 |
* <p><b>This is NOT part of any supported API. |
3380
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
21 |
* If you write code that depends on this, you do so at your own risk. |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
22 |
* This code and its internal interfaces are subject to change or |
a6c2bcab0fec
6865399: some javac files are missing Sun internal API comment
jjg
parents:
1208
diff
changeset
|
23 |
* deletion without notice.</b> |
1208 | 24 |
*/ |
25 |
public class FSInfo { |
|
26 |
||
27 |
/** Get the FSInfo instance for this context. |
|
28 |
* @param context the context |
|
29 |
* @return the Paths instance for this context |
|
30 |
*/ |
|
31 |
public static FSInfo instance(Context context) { |
|
32 |
FSInfo instance = context.get(FSInfo.class); |
|
33 |
if (instance == null) |
|
34 |
instance = new FSInfo(); |
|
35 |
return instance; |
|
36 |
} |
|
37 |
||
38 |
protected FSInfo() { |
|
39 |
} |
|
40 |
||
41 |
protected FSInfo(Context context) { |
|
42 |
context.put(FSInfo.class, this); |
|
43 |
} |
|
44 |
||
45 |
public File getCanonicalFile(File file) { |
|
46 |
try { |
|
47 |
return file.getCanonicalFile(); |
|
48 |
} catch (IOException e) { |
|
49 |
return file.getAbsoluteFile(); |
|
50 |
} |
|
51 |
} |
|
52 |
||
53 |
public boolean exists(File file) { |
|
54 |
return file.exists(); |
|
55 |
} |
|
56 |
||
57 |
public boolean isDirectory(File file) { |
|
58 |
return file.isDirectory(); |
|
59 |
} |
|
60 |
||
61 |
public boolean isFile(File file) { |
|
62 |
return file.isFile(); |
|
63 |
} |
|
64 |
||
65 |
public List<File> getJarClassPath(File file) throws IOException { |
|
66 |
String parent = file.getParent(); |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
5847
diff
changeset
|
67 |
try (JarFile jarFile = new JarFile(file)) { |
1208 | 68 |
Manifest man = jarFile.getManifest(); |
69 |
if (man == null) |
|
70 |
return Collections.emptyList(); |
|
71 |
||
72 |
Attributes attr = man.getMainAttributes(); |
|
73 |
if (attr == null) |
|
74 |
return Collections.emptyList(); |
|
75 |
||
76 |
String path = attr.getValue(Attributes.Name.CLASS_PATH); |
|
77 |
if (path == null) |
|
78 |
return Collections.emptyList(); |
|
79 |
||
22163 | 80 |
List<File> list = new ArrayList<>(); |
1208 | 81 |
|
22159
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
5847
diff
changeset
|
82 |
for (StringTokenizer st = new StringTokenizer(path); |
682da512ec17
8030253: Update langtools to use strings-in-switch
briangoetz
parents:
5847
diff
changeset
|
83 |
st.hasMoreTokens(); ) { |
1208 | 84 |
String elt = st.nextToken(); |
24222
244127f8dd79
8030046: javac incorrectly handles absolute paths in manifest classpath
pgovereau
parents:
22163
diff
changeset
|
85 |
try { |
244127f8dd79
8030046: javac incorrectly handles absolute paths in manifest classpath
pgovereau
parents:
22163
diff
changeset
|
86 |
File f = parent == null ? new File(elt): new File(file.toURI().resolve(elt)); |
244127f8dd79
8030046: javac incorrectly handles absolute paths in manifest classpath
pgovereau
parents:
22163
diff
changeset
|
87 |
list.add(f); |
244127f8dd79
8030046: javac incorrectly handles absolute paths in manifest classpath
pgovereau
parents:
22163
diff
changeset
|
88 |
} catch (IllegalArgumentException ex) {} |
1208 | 89 |
} |
90 |
||
91 |
return list; |
|
92 |
} |
|
93 |
} |
|
94 |
} |