clean up and refactor some APIs surrounding file I/O and exclusions files. Needed in order to allow clients to use some APIs with application-specific exclusions.
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2247 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
2ca10de94a
commit
fc6442bf04
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.client.impl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.jar.JarFile;
|
||||
|
@ -38,7 +40,7 @@ import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
|||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||
import com.ibm.wala.ssa.DefaultIRFactory;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.util.config.*;
|
||||
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
/**
|
||||
|
@ -171,13 +173,14 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
|
|||
|
||||
/**
|
||||
* Set up the AnalysisScope object
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void buildAnalysisScope() {
|
||||
protected void buildAnalysisScope() throws IOException {
|
||||
if (j2seLibs == null) {
|
||||
Assertions.UNREACHABLE("no j2selibs specified. You probably did not call AppAnalysisEngine.setJ2SELibrary.");
|
||||
}
|
||||
|
||||
scope = AnalysisScopeReader.read(SYNTHETIC_J2SE_MODEL, getExclusionsFile(), getClass().getClassLoader());
|
||||
scope = AnalysisScopeReader.read(SYNTHETIC_J2SE_MODEL, new File(getExclusionsFile()), getClass().getClassLoader());
|
||||
|
||||
// add standard libraries
|
||||
for (int i = 0; i < j2seLibs.length; i++) {
|
||||
|
@ -323,8 +326,9 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
|
|||
* given entry points.
|
||||
* @throws CancelException
|
||||
* @throws IllegalArgumentException
|
||||
* @throws IOException
|
||||
*/
|
||||
public CallGraphBuilder defaultCallGraphBuilder() throws IllegalArgumentException, CancelException {
|
||||
public CallGraphBuilder defaultCallGraphBuilder() throws IllegalArgumentException, CancelException, IOException {
|
||||
buildAnalysisScope();
|
||||
IClassHierarchy cha = buildClassHierarchy();
|
||||
setClassHierarchy(cha);
|
||||
|
@ -334,7 +338,7 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
|
|||
return buildCallGraph(cha, options, true);
|
||||
}
|
||||
|
||||
public CallGraph buildDefaultCallGraph() throws IllegalArgumentException, CancelException {
|
||||
public CallGraph buildDefaultCallGraph() throws IllegalArgumentException, CancelException, IOException {
|
||||
return defaultCallGraphBuilder().makeCallGraph(options);
|
||||
}
|
||||
|
||||
|
|
|
@ -215,7 +215,7 @@ public class EclipseProjectPath {
|
|||
/**
|
||||
* Convert this path to a WALA analysis scope
|
||||
*/
|
||||
public AnalysisScope toAnalysisScope(final ClassLoader classLoader, final String exclusionsFile) {
|
||||
public AnalysisScope toAnalysisScope(ClassLoader classLoader, File exclusionsFile) {
|
||||
try {
|
||||
Set<Module> s = MapUtil.findOrCreateSet(binaryModules, Loader.APPLICATION);
|
||||
s.add(new BinaryDirectoryTreeModule(makeAbsolute(project.getOutputLocation()).toFile()));
|
||||
|
@ -238,7 +238,7 @@ public class EclipseProjectPath {
|
|||
}
|
||||
}
|
||||
|
||||
public AnalysisScope toAnalysisScope(final String exclusionsFile) {
|
||||
public AnalysisScope toAnalysisScope(final File exclusionsFile) {
|
||||
return toAnalysisScope(getClass().getClassLoader(), exclusionsFile);
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ public class Slicer {
|
|||
FULL("full", false, false, false, false),
|
||||
NO_BASE_PTRS("no_base_ptrs", true, false, false, false),
|
||||
NO_BASE_NO_HEAP("no_base_no_heap", true, true, false, false),
|
||||
NO_BASE_NO_EXCEPTIONS("no_base_no_exceptions", true, false, false, true),
|
||||
NO_BASE_NO_HEAP_NO_EXCEPTIONS("no_base_no_heap_no_exceptions", true, true, false, true),
|
||||
NO_HEAP("no_heap", false, true, false, false),
|
||||
NONE("none", true, true, true, true),
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.util.config;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -18,19 +28,23 @@ import com.ibm.wala.types.ClassLoaderReference;
|
|||
import com.ibm.wala.util.Atom;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
/**
|
||||
* Reads {@link AnalysisScope} from a text file.
|
||||
*
|
||||
*/
|
||||
public class AnalysisScopeReader {
|
||||
|
||||
private static final ClassLoader MY_CLASSLOADER = AnalysisScopeReader.class.getClassLoader();
|
||||
|
||||
private static final String BASIC_FILE = "primordial.txt";
|
||||
|
||||
public static AnalysisScope read(String scopeFileName, String exclusionsFile, ClassLoader javaLoader) {
|
||||
public static AnalysisScope read(String scopeFileName, File exclusionsFile, ClassLoader javaLoader) {
|
||||
AnalysisScope scope = AnalysisScope.createAnalysisScope(Collections.singleton(Language.JAVA));
|
||||
|
||||
return read(scope, scopeFileName, exclusionsFile, javaLoader);
|
||||
}
|
||||
|
||||
public static AnalysisScope read(AnalysisScope scope, String scopeFileName, String exclusionsFile, ClassLoader javaLoader) {
|
||||
public static AnalysisScope read(AnalysisScope scope, String scopeFileName, File exclusionsFile, ClassLoader javaLoader) {
|
||||
try {
|
||||
File scopeFile = FileProvider.getFile(scopeFileName, javaLoader);
|
||||
assert scopeFile.exists();
|
||||
|
@ -76,7 +90,7 @@ public class AnalysisScopeReader {
|
|||
}
|
||||
|
||||
if (exclusionsFile != null) {
|
||||
scope.setExclusions(new FileOfClasses(exclusionsFile, javaLoader));
|
||||
scope.setExclusions(new FileOfClasses(exclusionsFile));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
|
@ -86,11 +100,11 @@ public class AnalysisScopeReader {
|
|||
return scope;
|
||||
}
|
||||
|
||||
public static AnalysisScope makePrimordialScope(String exclusionsFile) {
|
||||
public static AnalysisScope makePrimordialScope(File exclusionsFile) {
|
||||
return read(BASIC_FILE, exclusionsFile, MY_CLASSLOADER);
|
||||
}
|
||||
|
||||
public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, String exclusionsFile) {
|
||||
public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, File exclusionsFile) {
|
||||
AnalysisScope scope = makePrimordialScope(exclusionsFile);
|
||||
ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
|
||||
|
||||
|
|
|
@ -10,19 +10,21 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.util.config;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.ipa.callgraph.impl.SetOfClasses;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
/**
|
||||
*
|
||||
* An object which represents a set of classes read from an XML file.
|
||||
* An object which represents a set of classes read from a text file.
|
||||
*
|
||||
* @author sfink
|
||||
*/
|
||||
|
@ -36,34 +38,26 @@ public class FileOfClasses extends SetOfClasses {
|
|||
|
||||
private boolean needsCompile = false;
|
||||
|
||||
public FileOfClasses(String textFileName, ClassLoader loader) {
|
||||
try {
|
||||
URL textFile = FileProvider.getResource(textFileName, loader);
|
||||
BufferedReader is =
|
||||
new BufferedReader(
|
||||
new InputStreamReader(
|
||||
textFile.openConnection().getInputStream()));
|
||||
|
||||
StringBuffer regex = null;
|
||||
String line;
|
||||
while ((line = is.readLine()) != null) {
|
||||
if (regex == null) {
|
||||
regex = new StringBuffer("(" + line + ")");
|
||||
} else {
|
||||
regex.append("|(" + line + ")");
|
||||
}
|
||||
public FileOfClasses(File textFile) throws IOException {
|
||||
|
||||
BufferedReader is = new BufferedReader(new InputStreamReader(new FileInputStream(textFile)));
|
||||
|
||||
StringBuffer regex = null;
|
||||
String line;
|
||||
while ((line = is.readLine()) != null) {
|
||||
if (regex == null) {
|
||||
regex = new StringBuffer("(" + line + ")");
|
||||
} else {
|
||||
regex.append("|(" + line + ")");
|
||||
}
|
||||
|
||||
if (regex != null) {
|
||||
this.regex = regex.toString();
|
||||
needsCompile = true;
|
||||
}
|
||||
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
if (regex != null) {
|
||||
this.regex = regex.toString();
|
||||
needsCompile = true;
|
||||
}
|
||||
|
||||
is.close();
|
||||
}
|
||||
|
||||
private void compile() {
|
||||
|
|
|
@ -38,7 +38,7 @@ import com.ibm.wala.util.debug.Trace;
|
|||
|
||||
/**
|
||||
*
|
||||
* This class provides Jar files that are packaged with this plug-in
|
||||
* This class provides files that are packaged with this plug-in
|
||||
*
|
||||
* @author sfink
|
||||
*/
|
||||
|
@ -70,9 +70,7 @@ public class FileProvider {
|
|||
return getJarFileModule(fileName, FileProvider.class.getClassLoader());
|
||||
}
|
||||
|
||||
public static Module getJarFileModule(String fileName, ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
public static Module getJarFileModule(String fileName, ClassLoader loader) throws IOException {
|
||||
if (CorePlugin.getDefault() == null) {
|
||||
return getJarFileFromClassLoader(fileName, loader);
|
||||
} else {
|
||||
|
@ -95,38 +93,29 @@ public class FileProvider {
|
|||
public static URL getResource(String fileName) throws IOException {
|
||||
return getResource(fileName, FileProvider.class.getClassLoader());
|
||||
}
|
||||
|
||||
public static URL getResource(String fileName, ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
return
|
||||
(CorePlugin.getDefault() == null) ?
|
||||
loader.getResource(fileName):
|
||||
FileLocator.find(
|
||||
CorePlugin.getDefault().getBundle(),
|
||||
new Path(fileName), null);
|
||||
|
||||
public static URL getResource(String fileName, ClassLoader loader) throws IOException {
|
||||
return (CorePlugin.getDefault() == null) ? loader.getResource(fileName) : FileLocator.find(CorePlugin.getDefault().getBundle(),
|
||||
new Path(fileName), null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public static File getFile(String fileName) throws IOException {
|
||||
return getFile(fileName, FileProvider.class.getClassLoader());
|
||||
}
|
||||
|
||||
public static File getFile(String fileName, ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
return
|
||||
(CorePlugin.getDefault() == null) ?
|
||||
getFileFromClassLoader(fileName, loader) :
|
||||
getFileFromPlugin(CorePlugin.getDefault(), fileName);
|
||||
|
||||
public static File getFile(String fileName, ClassLoader loader) throws IOException {
|
||||
return (CorePlugin.getDefault() == null) ? getFileFromClassLoader(fileName, loader) : getFileFromPlugin(
|
||||
CorePlugin.getDefault(), fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fileName
|
||||
* @return the jar file packaged with this plug-in of the given name, or null
|
||||
* if not found.
|
||||
* @throws IllegalArgumentException if p is null
|
||||
* @throws IllegalArgumentException
|
||||
* if p is null
|
||||
*/
|
||||
public static File getFileFromPlugin(Plugin p, String fileName) throws IOException {
|
||||
|
||||
|
@ -154,7 +143,7 @@ public class FileProvider {
|
|||
* get a file URL for a file from a plugin
|
||||
*
|
||||
* @param fileName
|
||||
* the file name
|
||||
* the file name
|
||||
* @return the URL, or <code>null</code> if the file is not found
|
||||
* @throws IOException
|
||||
*/
|
||||
|
@ -214,9 +203,7 @@ public class FileProvider {
|
|||
/**
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public static File getFileFromClassLoader(String fileName, ClassLoader loader)
|
||||
throws FileNotFoundException
|
||||
{
|
||||
public static File getFileFromClassLoader(String fileName, ClassLoader loader) throws FileNotFoundException {
|
||||
URL url = loader.getResource(fileName);
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("FileProvider got url: " + url + " for " + fileName);
|
||||
|
@ -226,7 +213,7 @@ public class FileProvider {
|
|||
// system classloader
|
||||
File f = new File(fileName);
|
||||
if (f.exists()) {
|
||||
return f;
|
||||
return f;
|
||||
}
|
||||
throw new FileNotFoundException(fileName);
|
||||
} else {
|
||||
|
@ -240,10 +227,7 @@ public class FileProvider {
|
|||
* if not found: wrapped as a JarFileModule or a NestedJarFileModule
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Module
|
||||
getJarFileFromClassLoader(String fileName, ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
public static Module getJarFileFromClassLoader(String fileName, ClassLoader loader) throws IOException {
|
||||
URL url = loader.getResource(fileName);
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("FileProvider got url: " + url + " for " + fileName);
|
||||
|
@ -274,7 +258,8 @@ public class FileProvider {
|
|||
*
|
||||
* @param url
|
||||
* @return the path name for the url
|
||||
* @throws IllegalArgumentException if url is null
|
||||
* @throws IllegalArgumentException
|
||||
* if url is null
|
||||
*/
|
||||
public static String filePathFromURL(URL url) {
|
||||
if (url == null) {
|
||||
|
|
Loading…
Reference in New Issue