misc bug fixes and cleanups for new AnalysisScopes
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2171 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
eb7599b7ac
commit
378427225c
|
@ -1,7 +1,6 @@
|
||||||
bin.includes = lib/primordial.jar.model,\
|
bin.includes = lib/primordial.jar.model,\
|
||||||
plugin.properties,\
|
plugin.properties,\
|
||||||
dat/J2SEClassHierarchyExclusions.xml,\
|
dat/J2SEClassHierarchyExclusions.xml,\
|
||||||
dat/SyntheticJ2SEModel.xml,\
|
|
||||||
dat/natives.xml,\
|
dat/natives.xml,\
|
||||||
META-INF/,\
|
META-INF/,\
|
||||||
.
|
.
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Primordial,Java,jarFile,primordial_jar_model
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<com.ibm.wala.java.scope:EJavaAnalysisScope xmlns:com.ibm.wala.java.scope="http:///com/ibm/wala/wala.ecore.java.scope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
||||||
<loaders loaderName="Primordial">
|
|
||||||
<modules xsi:type="com.ibm.wala.java.scope:EBuiltInModule" id="primordial_jar_model"/>
|
|
||||||
</loaders>
|
|
||||||
</com.ibm.wala.java.scope:EJavaAnalysisScope>
|
|
|
@ -97,14 +97,10 @@ public class AnalysisScope {
|
||||||
protected AnalysisScope(Collection<Language> languages) {
|
protected AnalysisScope(Collection<Language> languages) {
|
||||||
super();
|
super();
|
||||||
this.languages = languages;
|
this.languages = languages;
|
||||||
ClassLoaderReference primordial =
|
ClassLoaderReference primordial = new ClassLoaderReference(PRIMORDIAL, ClassLoaderReference.Java);
|
||||||
new ClassLoaderReference(PRIMORDIAL, ClassLoaderReference.Java);
|
ClassLoaderReference extension = new ClassLoaderReference(EXTENSION, ClassLoaderReference.Java);
|
||||||
ClassLoaderReference extension =
|
ClassLoaderReference application = new ClassLoaderReference(APPLICATION, ClassLoaderReference.Java);
|
||||||
new ClassLoaderReference(EXTENSION, ClassLoaderReference.Java);
|
ClassLoaderReference synthetic = new ClassLoaderReference(SYNTHETIC, ClassLoaderReference.Java);
|
||||||
ClassLoaderReference application =
|
|
||||||
new ClassLoaderReference(APPLICATION, ClassLoaderReference.Java);
|
|
||||||
ClassLoaderReference synthetic =
|
|
||||||
new ClassLoaderReference(SYNTHETIC, ClassLoaderReference.Java);
|
|
||||||
extension.setParent(primordial);
|
extension.setParent(primordial);
|
||||||
application.setParent(extension);
|
application.setParent(extension);
|
||||||
synthetic.setParent(application);
|
synthetic.setParent(application);
|
||||||
|
@ -162,10 +158,11 @@ public class AnalysisScope {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the set of "base languages," each of which defines a family of
|
* @return the set of "base languages," each of which defines a family of
|
||||||
* compatible languages, and therefore induces a distinct ClassHierarchy
|
* compatible languages, and therefore induces a distinct
|
||||||
|
* ClassHierarchy
|
||||||
*/
|
*/
|
||||||
public Set<Language> getBaseLanguages() {
|
public Set<Language> getBaseLanguages() {
|
||||||
Set<Language> result= new HashSet<Language>();
|
Set<Language> result = new HashSet<Language>();
|
||||||
for (Language language : languages) {
|
for (Language language : languages) {
|
||||||
if (language.getBaseLanguage() == null) {
|
if (language.getBaseLanguage() == null) {
|
||||||
result.add(language);
|
result.add(language);
|
||||||
|
@ -180,7 +177,7 @@ public class AnalysisScope {
|
||||||
* @param loader
|
* @param loader
|
||||||
* @param file
|
* @param file
|
||||||
*/
|
*/
|
||||||
public void addSourceFileToScope(ClassLoaderReference loader, File file, String fileName) throws IllegalArgumentException {
|
public void addSourceFileToScope(ClassLoaderReference loader, File file, String fileName) throws IllegalArgumentException {
|
||||||
Set<Module> s = MapUtil.findOrCreateSet(moduleMap, loader);
|
Set<Module> s = MapUtil.findOrCreateSet(moduleMap, loader);
|
||||||
s.add(new SourceFileModule(file, fileName));
|
s.add(new SourceFileModule(file, fileName));
|
||||||
}
|
}
|
||||||
|
@ -229,9 +226,10 @@ public class AnalysisScope {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the ClassLoaderReference specified by <code>name</code>.
|
* @return the ClassLoaderReference specified by <code>name</code>.
|
||||||
* @throws IllegalArgumentException if name is null
|
* @throws IllegalArgumentException
|
||||||
|
* if name is null
|
||||||
*/
|
*/
|
||||||
public ClassLoaderReference getLoader(Atom name) throws IllegalArgumentException {
|
public ClassLoaderReference getLoader(Atom name) throws IllegalArgumentException {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
throw new IllegalArgumentException("name is null");
|
throw new IllegalArgumentException("name is null");
|
||||||
}
|
}
|
||||||
|
@ -366,7 +364,7 @@ public class AnalysisScope {
|
||||||
public boolean isJava16Libraries() throws IllegalStateException {
|
public boolean isJava16Libraries() throws IllegalStateException {
|
||||||
return getJavaLibraryVersion().startsWith("1.6");
|
return getJavaLibraryVersion().startsWith("1.6");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isJava15Libraries() throws IllegalStateException {
|
public boolean isJava15Libraries() throws IllegalStateException {
|
||||||
return getJavaLibraryVersion().startsWith("1.5");
|
return getJavaLibraryVersion().startsWith("1.5");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,36 @@
|
||||||
package com.ibm.wala.util.config;
|
package com.ibm.wala.util.config;
|
||||||
|
|
||||||
import com.ibm.wala.classLoader.*;
|
import java.io.BufferedReader;
|
||||||
import com.ibm.wala.ipa.callgraph.*;
|
import java.io.File;
|
||||||
import com.ibm.wala.properties.*;
|
import java.io.FileReader;
|
||||||
import com.ibm.wala.types.*;
|
import java.io.IOException;
|
||||||
import com.ibm.wala.util.Atom;
|
import java.util.Collections;
|
||||||
import com.ibm.wala.util.debug.*;
|
import java.util.StringTokenizer;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import java.io.*;
|
import com.ibm.wala.classLoader.BinaryDirectoryTreeModule;
|
||||||
import java.util.*;
|
import com.ibm.wala.classLoader.Language;
|
||||||
import java.util.jar.*;
|
import com.ibm.wala.classLoader.Module;
|
||||||
|
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
|
||||||
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
|
import com.ibm.wala.properties.WalaProperties;
|
||||||
|
import com.ibm.wala.types.ClassLoaderReference;
|
||||||
|
import com.ibm.wala.util.Atom;
|
||||||
|
import com.ibm.wala.util.debug.Assertions;
|
||||||
|
|
||||||
public class AnalysisScopeReader {
|
public class AnalysisScopeReader {
|
||||||
|
|
||||||
private static final ClassLoader MY_CLASSLOADER =
|
private static final ClassLoader MY_CLASSLOADER = AnalysisScopeReader.class.getClassLoader();
|
||||||
AnalysisScopeReader.class.getClassLoader();
|
|
||||||
|
|
||||||
private static final String BASIC_FILE =
|
private static final String BASIC_FILE = "primordial.txt";
|
||||||
"J2SESyntheticModel.txt";
|
|
||||||
|
|
||||||
public static AnalysisScope
|
public static AnalysisScope read(String scopeFileName, String exclusionsFile, ClassLoader javaLoader) {
|
||||||
read(String scopeFileName, String exclusionsFile, ClassLoader javaLoader)
|
AnalysisScope scope = AnalysisScope.createAnalysisScope(Collections.singleton(Language.JAVA));
|
||||||
{
|
|
||||||
AnalysisScope scope =
|
|
||||||
AnalysisScope.createAnalysisScope(Collections.singleton(Language.JAVA));
|
|
||||||
|
|
||||||
return read(scope, scopeFileName, exclusionsFile, javaLoader);
|
return read(scope, scopeFileName, exclusionsFile, javaLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnalysisScope
|
public static AnalysisScope read(AnalysisScope scope, String scopeFileName, String exclusionsFile, ClassLoader javaLoader) {
|
||||||
read(AnalysisScope scope,
|
|
||||||
String scopeFileName,
|
|
||||||
String exclusionsFile,
|
|
||||||
ClassLoader javaLoader)
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
File scopeFile = FileProvider.getFile(scopeFileName, javaLoader);
|
File scopeFile = FileProvider.getFile(scopeFileName, javaLoader);
|
||||||
assert scopeFile.exists();
|
assert scopeFile.exists();
|
||||||
|
@ -41,50 +38,49 @@ public class AnalysisScopeReader {
|
||||||
String line;
|
String line;
|
||||||
BufferedReader r = new BufferedReader(new FileReader(scopeFile));
|
BufferedReader r = new BufferedReader(new FileReader(scopeFile));
|
||||||
while ((line = r.readLine()) != null) {
|
while ((line = r.readLine()) != null) {
|
||||||
StringTokenizer toks = new StringTokenizer(line, "\n,");
|
StringTokenizer toks = new StringTokenizer(line, "\n,");
|
||||||
|
|
||||||
Atom loaderName = Atom.findOrCreateUnicodeAtom(toks.nextToken());
|
Atom loaderName = Atom.findOrCreateUnicodeAtom(toks.nextToken());
|
||||||
Atom languageName = Atom.findOrCreateUnicodeAtom(toks.nextToken());
|
Atom languageName = Atom.findOrCreateUnicodeAtom(toks.nextToken());
|
||||||
ClassLoaderReference walaLoader =
|
ClassLoaderReference walaLoader = new ClassLoaderReference(loaderName, languageName);
|
||||||
new ClassLoaderReference(loaderName, languageName);
|
|
||||||
|
|
||||||
String entryType = toks.nextToken();
|
String entryType = toks.nextToken();
|
||||||
String entryPathname = toks.nextToken();
|
String entryPathname = toks.nextToken();
|
||||||
if ("classFile".equals(entryType)) {
|
if ("classFile".equals(entryType)) {
|
||||||
File cf = FileProvider.getFile(entryPathname, javaLoader);
|
File cf = FileProvider.getFile(entryPathname, javaLoader);
|
||||||
scope.addClassFileToScope(walaLoader, cf);
|
scope.addClassFileToScope(walaLoader, cf);
|
||||||
} else if ("sourceFile".equals(entryType)) {
|
} else if ("sourceFile".equals(entryType)) {
|
||||||
File sf = FileProvider.getFile(entryPathname, javaLoader);
|
File sf = FileProvider.getFile(entryPathname, javaLoader);
|
||||||
scope.addSourceFileToScope(walaLoader, sf, entryPathname);
|
scope.addSourceFileToScope(walaLoader, sf, entryPathname);
|
||||||
} else if ("binaryDir".equals(entryType)) {
|
} else if ("binaryDir".equals(entryType)) {
|
||||||
File bd = FileProvider.getFile(entryPathname, javaLoader);
|
File bd = FileProvider.getFile(entryPathname, javaLoader);
|
||||||
assert bd.isDirectory();
|
assert bd.isDirectory();
|
||||||
scope.addToScope(walaLoader, new BinaryDirectoryTreeModule(bd));
|
scope.addToScope(walaLoader, new BinaryDirectoryTreeModule(bd));
|
||||||
} else if ("sourceDir".equals(entryType)) {
|
} else if ("sourceDir".equals(entryType)) {
|
||||||
File sd = FileProvider.getFile(entryPathname, javaLoader);
|
File sd = FileProvider.getFile(entryPathname, javaLoader);
|
||||||
assert sd.isDirectory();
|
assert sd.isDirectory();
|
||||||
scope.addToScope(walaLoader, new SourceDirectoryTreeModule(sd));
|
scope.addToScope(walaLoader, new SourceDirectoryTreeModule(sd));
|
||||||
} else if ("jarFile".equals(entryType)) {
|
} else if ("jarFile".equals(entryType)) {
|
||||||
Module M = FileProvider.getJarFileModule(entryPathname, javaLoader);
|
Module M = FileProvider.getJarFileModule(entryPathname, javaLoader);
|
||||||
scope.addToScope(walaLoader, M);
|
scope.addToScope(walaLoader, M);
|
||||||
} else if ("loaderImpl".equals(entryType)) {
|
} else if ("loaderImpl".equals(entryType)) {
|
||||||
scope.setLoaderImpl(walaLoader, entryPathname);
|
scope.setLoaderImpl(walaLoader, entryPathname);
|
||||||
} else if ("stdlib".equals(entryType)) {
|
} else if ("stdlib".equals(entryType)) {
|
||||||
String[] stdlibs = WalaProperties.getJ2SEJarFiles();
|
String[] stdlibs = WalaProperties.getJ2SEJarFiles();
|
||||||
for(int i = 0; i < stdlibs.length; i++) {
|
for (int i = 0; i < stdlibs.length; i++) {
|
||||||
scope.addToScope(walaLoader, new JarFile(stdlibs[i]));
|
scope.addToScope(walaLoader, new JarFile(stdlibs[i]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Assertions.UNREACHABLE();
|
Assertions.UNREACHABLE();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exclusionsFile != null) {
|
if (exclusionsFile != null) {
|
||||||
scope.setExclusions(new FileOfClasses(exclusionsFile, javaLoader));
|
scope.setExclusions(new FileOfClasses(exclusionsFile, javaLoader));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Assertions.UNREACHABLE(e.toString());
|
Assertions.UNREACHABLE(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return scope;
|
return scope;
|
||||||
|
@ -94,27 +90,24 @@ public class AnalysisScopeReader {
|
||||||
return read(BASIC_FILE, exclusionsFile, MY_CLASSLOADER);
|
return read(BASIC_FILE, exclusionsFile, MY_CLASSLOADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AnalysisScope
|
public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, String exclusionsFile) {
|
||||||
makeJavaBinaryAnalysisScope(String classPath, String exclusionsFile)
|
|
||||||
{
|
|
||||||
AnalysisScope scope = makePrimordialScope(exclusionsFile);
|
AnalysisScope scope = makePrimordialScope(exclusionsFile);
|
||||||
ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
|
ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
StringTokenizer paths =
|
StringTokenizer paths = new StringTokenizer(classPath, File.pathSeparator);
|
||||||
new StringTokenizer(classPath, File.pathSeparator);
|
|
||||||
while (paths.hasMoreTokens()) {
|
while (paths.hasMoreTokens()) {
|
||||||
String path = paths.nextToken();
|
String path = paths.nextToken();
|
||||||
if (path.endsWith(".jar")) {
|
if (path.endsWith(".jar")) {
|
||||||
scope.addToScope(loader, new JarFile(path));
|
scope.addToScope(loader, new JarFile(path));
|
||||||
} else {
|
} else {
|
||||||
File f = new File(path);
|
File f = new File(path);
|
||||||
if (f.isDirectory()) {
|
if (f.isDirectory()) {
|
||||||
scope.addToScope(loader, new BinaryDirectoryTreeModule(f));
|
scope.addToScope(loader, new BinaryDirectoryTreeModule(f));
|
||||||
} else {
|
} else {
|
||||||
scope.addClassFileToScope(loader, f);
|
scope.addClassFileToScope(loader, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Assertions.UNREACHABLE(e.toString());
|
Assertions.UNREACHABLE(e.toString());
|
||||||
|
|
|
@ -10,14 +10,17 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.ibm.wala.util.config;
|
package com.ibm.wala.util.config;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.ibm.wala.classLoader.IClass;
|
import com.ibm.wala.classLoader.IClass;
|
||||||
import com.ibm.wala.ipa.callgraph.impl.SetOfClasses;
|
import com.ibm.wala.ipa.callgraph.impl.SetOfClasses;
|
||||||
import com.ibm.wala.types.TypeReference;
|
import com.ibm.wala.types.TypeReference;
|
||||||
import com.ibm.wala.util.debug.Assertions;
|
import com.ibm.wala.util.debug.Assertions;
|
||||||
import com.ibm.wala.util.warnings.WalaException;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.regex.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue