rewrite getURLForFile to use FileProvider

This commit is contained in:
Manu Sridharan 2013-11-30 10:02:32 -08:00
parent 9ee9206ff2
commit 3d2350dde6
1 changed files with 13 additions and 7 deletions

View File

@ -11,12 +11,13 @@
package com.ibm.wala.cast.js.test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.Set;
import junit.framework.Assert;
import org.junit.Assert;
import com.ibm.wala.cast.ir.ssa.AstIRFactory;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
@ -47,6 +48,7 @@ import com.ibm.wala.ssa.IRFactory;
import com.ibm.wala.util.CancelException;
import com.ibm.wala.util.WalaException;
import com.ibm.wala.util.collections.HashSetFactory;
import com.ibm.wala.util.io.FileProvider;
/**
* TODO this class is a mess. rewrite.
@ -96,13 +98,17 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
return makeCG(loaders, scope, builderType, AstIRFactory.makeDefaultFactory());
}
public static URL getURLforFile(String dir, String name) {
URL script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + File.separator + name);
if (script == null) {
script = JSCallGraphBuilderUtil.class.getClassLoader().getResource(dir + "/" + name);
public static URL getURLforFile(String dir, String name) throws IOException {
File f = null;
FileProvider provider = new FileProvider();
try {
f = provider.getFile(dir + File.separator + name, JSCallGraphBuilderUtil.class.getClassLoader());
} catch (FileNotFoundException e) {
// I guess we need to do this on Windows sometimes? --MS
// if this fails, we won't catch the exception
f = provider.getFile(dir + "/" + name, JSCallGraphBuilderUtil.class.getClassLoader());
}
assert script != null : "cannot find " + dir + " and " + name;
return script;
return f.toURI().toURL();
}
static AnalysisScope makeScriptScope(String dir, String name, JavaScriptLoaderFactory loaders) throws IOException {