diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/config/FileProvider.java b/com.ibm.wala.core/src/com/ibm/wala/util/config/FileProvider.java index 459956223..dd5381225 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/config/FileProvider.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/config/FileProvider.java @@ -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 null 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; diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/tables/Table.java b/com.ibm.wala.core/src/com/ibm/wala/util/tables/Table.java index 5ba289b43..bc22d29ee 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/tables/Table.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/tables/Table.java @@ -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