jjg@106: jjg@106: package com.sun.tools.javac.file; jjg@106: jjg@106: import java.io.File; jjg@106: import java.io.IOException; jjg@106: import java.util.ArrayList; jjg@106: import java.util.Collections; jjg@106: import java.util.List; jjg@106: import java.util.StringTokenizer; jjg@106: import java.util.jar.Attributes; jjg@106: import java.util.jar.JarFile; jjg@106: import java.util.jar.Manifest; jjg@106: jjg@106: import com.sun.tools.javac.util.Context; jjg@106: jjg@106: /** jjg@106: * Get meta-info about files. Default direct (non-caching) implementation. jjg@106: * @see CacheFSInfo jjg@333: * jjg@581: *

This is NOT part of any supported API. jjg@333: * If you write code that depends on this, you do so at your own risk. jjg@333: * This code and its internal interfaces are subject to change or jjg@333: * deletion without notice. jjg@106: */ jjg@106: public class FSInfo { jjg@106: jjg@106: /** Get the FSInfo instance for this context. jjg@106: * @param context the context jjg@106: * @return the Paths instance for this context jjg@106: */ jjg@106: public static FSInfo instance(Context context) { jjg@106: FSInfo instance = context.get(FSInfo.class); jjg@106: if (instance == null) jjg@106: instance = new FSInfo(); jjg@106: return instance; jjg@106: } jjg@106: jjg@106: protected FSInfo() { jjg@106: } jjg@106: jjg@106: protected FSInfo(Context context) { jjg@106: context.put(FSInfo.class, this); jjg@106: } jjg@106: jjg@106: public File getCanonicalFile(File file) { jjg@106: try { jjg@106: return file.getCanonicalFile(); jjg@106: } catch (IOException e) { jjg@106: return file.getAbsoluteFile(); jjg@106: } jjg@106: } jjg@106: jjg@106: public boolean exists(File file) { jjg@106: return file.exists(); jjg@106: } jjg@106: jjg@106: public boolean isDirectory(File file) { jjg@106: return file.isDirectory(); jjg@106: } jjg@106: jjg@106: public boolean isFile(File file) { jjg@106: return file.isFile(); jjg@106: } jjg@106: jjg@106: public List getJarClassPath(File file) throws IOException { jjg@106: String parent = file.getParent(); jjg@106: JarFile jarFile = new JarFile(file); jjg@106: try { jjg@106: Manifest man = jarFile.getManifest(); jjg@106: if (man == null) jjg@106: return Collections.emptyList(); jjg@106: jjg@106: Attributes attr = man.getMainAttributes(); jjg@106: if (attr == null) jjg@106: return Collections.emptyList(); jjg@106: jjg@106: String path = attr.getValue(Attributes.Name.CLASS_PATH); jjg@106: if (path == null) jjg@106: return Collections.emptyList(); jjg@106: jjg@106: List list = new ArrayList(); jjg@106: jjg@106: for (StringTokenizer st = new StringTokenizer(path); st.hasMoreTokens(); ) { jjg@106: String elt = st.nextToken(); jjg@106: File f = (parent == null ? new File(elt) : new File(parent, elt)); jjg@106: list.add(f); jjg@106: } jjg@106: jjg@106: return list; jjg@106: } finally { jjg@106: jarFile.close(); jjg@106: } jjg@106: } jjg@106: }