fix some problems with getting files from Plugins

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1103 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-05-14 16:46:40 +00:00
parent 66c94ec42d
commit 88b11f3596
2 changed files with 24 additions and 9 deletions

View File

@ -27,6 +27,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin;
import com.ibm.wala.classLoader.JarFileModule;
import com.ibm.wala.classLoader.Module;
@ -88,7 +89,7 @@ public class FileProvider {
}
// otherwise load from plugin
return getFromPlugin(fileName);
return getFromPlugin(CorePlugin.getDefault(), fileName);
}
}
@ -96,7 +97,7 @@ public class FileProvider {
/**
*/
public static File getFile(String fileName) throws IOException {
return (CorePlugin.getDefault() == null) ? getFileFromClassLoader(fileName) : getFileFromPlugin(fileName);
return (CorePlugin.getDefault() == null) ? getFileFromClassLoader(fileName) : getFileFromPlugin(CorePlugin.getDefault(), fileName);
}
/**
@ -104,9 +105,9 @@ public class FileProvider {
* @return the jar file packaged with this plug-in of the given name, or null
* if not found.
*/
private static File getFileFromPlugin(String fileName) throws IOException {
public static File getFileFromPlugin(Plugin p, String fileName) throws IOException {
URL url = getFileURLFromPlugin(fileName);
URL url = getFileURLFromPlugin(p, fileName);
if (url == null) {
throw new FileNotFoundException(fileName);
}
@ -118,8 +119,8 @@ public class FileProvider {
* @return the jar file packaged with this plug-in of the given name, or null
* if not found.
*/
private static JarFileModule getFromPlugin(String fileName) throws IOException {
URL url = getFileURLFromPlugin(fileName);
private static JarFileModule getFromPlugin(Plugin p, String fileName) throws IOException {
URL url = getFileURLFromPlugin(p, fileName);
return (url == null) ? null : new JarFileModule(new JarFile(filePathFromURL(url)));
}
@ -131,12 +132,12 @@ public class FileProvider {
* @return the URL, or <code>null</code> if the file is not found
* @throws IOException
*/
private static URL getFileURLFromPlugin(String fileName) throws IOException {
URL url = FileLocator.find(CorePlugin.getDefault().getBundle(), new Path(fileName), null);
private static URL getFileURLFromPlugin(Plugin p, String fileName) throws IOException {
URL url = FileLocator.find(p.getBundle(), new Path(fileName), null);
if (url == null) {
// try lib/fileName
fileName = "lib/" + fileName;
url = FileLocator.find(CorePlugin.getDefault().getBundle(), new Path(fileName), null);
url = FileLocator.find(p.getBundle(), new Path(fileName), null);
if (url == null) {
// give up
return null;

View File

@ -20,6 +20,8 @@ import java.io.LineNumberReader;
import java.util.Properties;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.Plugin;
import com.ibm.wala.util.StringStuff;
import com.ibm.wala.util.config.FileProvider;
import com.ibm.wala.util.debug.Assertions;
@ -84,6 +86,18 @@ public class Table implements Cloneable {
File f = FileProvider.getFile(fileName);
return readFromTextFile(f);
}
/**
* read from a text file obtained as a resource
* @param fileName
* @return
* @throws IOException
* @throws WalaException
*/
public static Table readFromTextFile(Plugin p, String fileName) throws IOException, WalaException {
File f = FileProvider.getFileFromPlugin(p, fileName);
return readFromTextFile(f);
}
/**
* @param f