Skip to content

Commit

Permalink
Issue#485 make reading manifest optional in AnalysisScopeReader
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-chenzhi committed May 10, 2019
1 parent c6bd0c0 commit a7db476
Showing 1 changed file with 31 additions and 13 deletions.
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);
}
}

0 comments on commit a7db476

Please sign in to comment.