avoid using files since the automated tests get things out of jars

This commit is contained in:
Julian Dolby 2013-08-07 16:44:21 -04:00
parent 512b3bbf48
commit a9331dca6f
2 changed files with 13 additions and 6 deletions

View File

@ -68,7 +68,7 @@ public class CGUtil {
if (url.getFile().endsWith(".js")) { if (url.getFile().endsWith(".js")) {
scripts = new SourceModule[]{ scripts = new SourceModule[]{
new SourceURLModule(url), new SourceURLModule(url),
new SourceFileModule(new File(JSCallGraphBuilderUtil.class.getClassLoader().getResource("prologue.js").getFile()), "prologue.js", null) JSCallGraphBuilderUtil.getPrologueFile("prologue.js")
}; };
} else { } else {
scripts = JSCallGraphBuilderUtil.makeHtmlScope(url, loaders); scripts = JSCallGraphBuilderUtil.makeHtmlScope(url, loaders);

View File

@ -20,7 +20,6 @@ import junit.framework.Assert;
import com.ibm.wala.cast.ir.ssa.AstIRFactory; import com.ibm.wala.cast.ir.ssa.AstIRFactory;
import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error; import com.ibm.wala.cast.ir.translator.TranslatorToCAst.Error;
import com.ibm.wala.cast.js.html.MappedSourceModule;
import com.ibm.wala.cast.js.html.WebPageLoaderFactory; import com.ibm.wala.cast.js.html.WebPageLoaderFactory;
import com.ibm.wala.cast.js.html.WebUtil; import com.ibm.wala.cast.js.html.WebUtil;
import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions; import com.ibm.wala.cast.js.ipa.callgraph.JSAnalysisOptions;
@ -34,7 +33,6 @@ import com.ibm.wala.cast.js.loader.JavaScriptLoaderFactory;
import com.ibm.wala.cast.loader.CAstAbstractLoader; import com.ibm.wala.cast.loader.CAstAbstractLoader;
import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory; import com.ibm.wala.cast.tree.rewrite.CAstRewriterFactory;
import com.ibm.wala.classLoader.IMethod; import com.ibm.wala.classLoader.IMethod;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.classLoader.SourceModule; import com.ibm.wala.classLoader.SourceModule;
import com.ibm.wala.classLoader.SourceURLModule; import com.ibm.wala.classLoader.SourceURLModule;
import com.ibm.wala.ipa.callgraph.AnalysisCache; import com.ibm.wala.ipa.callgraph.AnalysisCache;
@ -111,11 +109,20 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
return makeScriptScope(getURLforFile(dir, name), dir, name, loaders); return makeScriptScope(getURLforFile(dir, name), dir, name, loaders);
} }
public static SourceModule getPrologueFile(final String name) {
return new SourceURLModule(JSCallGraphBuilderUtil.class.getClassLoader().getResource(name)) {
@Override
public String getName() {
return name;
}
};
}
static AnalysisScope makeScriptScope(URL script, String dir, String name, JavaScriptLoaderFactory loaders) throws IOException { static AnalysisScope makeScriptScope(URL script, String dir, String name, JavaScriptLoaderFactory loaders) throws IOException {
return makeScope( return makeScope(
new SourceModule[] { new SourceModule[] {
(script.openConnection() instanceof JarURLConnection)? new SourceURLModule(script): makeSourceModule(script, dir, name), (script.openConnection() instanceof JarURLConnection)? new SourceURLModule(script): makeSourceModule(script, dir, name),
new SourceFileModule(new File(JSCallGraphBuilderUtil.class.getClassLoader().getResource("prologue.js").getFile()), "prologue.js", null) getPrologueFile("prologue.js")
}, loaders, JavaScriptLoader.JS); }, loaders, JavaScriptLoader.JS);
} }
@ -166,8 +173,8 @@ public class JSCallGraphBuilderUtil extends com.ibm.wala.cast.js.ipa.callgraph.J
Set<SourceModule> scripts = HashSetFactory.make(); Set<SourceModule> scripts = HashSetFactory.make();
JavaScriptLoader.addBootstrapFile(WebUtil.preamble); JavaScriptLoader.addBootstrapFile(WebUtil.preamble);
scripts.add(new SourceFileModule(new File(JSCallGraphBuilderUtil.class.getClassLoader().getResource("prologue.js").getFile()), "prologue.js", null)); scripts.add(getPrologueFile("prologue.js"));
scripts.add(new SourceFileModule(new File(JSCallGraphBuilderUtil.class.getClassLoader().getResource("preamble.js").getFile()), "preamble.js", null)); scripts.add(getPrologueFile("preamble.js"));
try { try {
scripts.addAll(WebUtil.extractScriptFromHTML(url).fst); scripts.addAll(WebUtil.extractScriptFromHTML(url).fst);