Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#485 make reading manifest optional in AnalysisScopeReader #486

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,34 @@ public static AnalysisScope makePrimordialScope(File exclusionsFile) throws IOEx
/**
* @param classPath class path to analyze, delimited by {@link File#pathSeparator}
* @param exclusionsFile file holding class hierarchy exclusions. may be null
* @param readManifest read manifest to retrieve Class-Path entries
* @throws IllegalStateException if there are problems reading wala properties
*/
public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, File exclusionsFile)
throws IOException {
public static AnalysisScope makeJavaBinaryAnalysisScope(
String classPath, File exclusionsFile, boolean readManifest) throws IOException {
if (classPath == null) {
throw new IllegalArgumentException("classPath null");
}
AnalysisScope scope = makePrimordialScope(exclusionsFile);
ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);

addClassPathToScope(classPath, scope, loader);
addClassPathToScope(classPath, scope, loader, readManifest);

return scope;
}

/**
* @param classPath class path to analyze, delimited by {@link File#pathSeparator}
* @param exclusionsFile file holding class hierarchy exclusions. may be null
* @throws IllegalStateException if there are problems reading wala properties
*/
public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, File exclusionsFile)
throws IOException {
return makeJavaBinaryAnalysisScope(classPath, exclusionsFile, true);
}

public static void addClassPathToScope(
String classPath, AnalysisScope scope, ClassLoaderReference loader) {
String classPath, AnalysisScope scope, ClassLoaderReference loader, boolean readManifest) {
if (classPath == null) {
throw new IllegalArgumentException("null classPath");
}
Expand All @@ -240,18 +251,20 @@ public static void addClassPathToScope(
if (path.endsWith(".jar")) {
JarFile jar = new JarFile(path, false);
scope.addToScope(loader, jar);
try {
if (jar.getManifest() != null) {
String cp = jar.getManifest().getMainAttributes().getValue("Class-Path");
if (cp != null) {
for (String cpEntry : cp.split(" ")) {
addClassPathToScope(
new File(path).getParent() + File.separator + cpEntry, scope, loader);
if (readManifest) {
try {
if (jar.getManifest() != null) {
String cp = jar.getManifest().getMainAttributes().getValue("Class-Path");
if (cp != null) {
for (String cpEntry : cp.split(" ")) {
addClassPathToScope(
new File(path).getParent() + File.separator + cpEntry, scope, loader);
}
}
}
} catch (RuntimeException e) {
System.err.println("warning: trouble processing class path of " + path);
}
} catch (RuntimeException e) {
System.err.println("warning: trouble processing class path of " + path);
}
} else {
File f = new File(path);
Expand All @@ -266,4 +279,9 @@ public static void addClassPathToScope(
Assertions.UNREACHABLE(e.toString());
}
}

public static void addClassPathToScope(
String classPath, AnalysisScope scope, ClassLoaderReference loader) {
addClassPathToScope(classPath, scope, loader, true);
}
}