remove EMF
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2161 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
421ea35de8
commit
17a8b62204
|
@ -6,8 +6,7 @@ Bundle-Version: 1.0.0
|
|||
Bundle-Activator: com.ibm.wala.core.plugin.CorePlugin
|
||||
Bundle-Vendor: IBM
|
||||
Bundle-Localization: plugin
|
||||
Require-Bundle: com.ibm.wala.emf;visibility:=reexport,
|
||||
com.ibm.wala.shrike;visibility:=reexport,
|
||||
Require-Bundle: com.ibm.wala.shrike;visibility:=reexport,
|
||||
org.eclipse.core.resources;visibility:=reexport,
|
||||
org.eclipse.jface,
|
||||
org.eclipse.jdt.core;visibility:=reexport,
|
||||
|
@ -36,7 +35,6 @@ Export-Package: .,
|
|||
com.ibm.wala.dynamic,
|
||||
com.ibm.wala.eclipse,
|
||||
com.ibm.wala.eclipse.util,
|
||||
com.ibm.wala.emf.wrappers,
|
||||
com.ibm.wala.escape,
|
||||
com.ibm.wala.fixedpoint.impl,
|
||||
com.ibm.wala.fixpoint,
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Primordial,Java,jarFile,primordial_jar_model
|
|
@ -23,7 +23,6 @@ import com.ibm.wala.classLoader.Module;
|
|||
import com.ibm.wala.client.AnalysisEngine;
|
||||
import com.ibm.wala.client.CallGraphBuilderFactory;
|
||||
import com.ibm.wala.eclipse.util.CancelException;
|
||||
import com.ibm.wala.emf.wrappers.EMFScopeWrapper;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
|
@ -39,6 +38,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.debug.Assertions;
|
||||
|
||||
/**
|
||||
|
@ -177,7 +177,7 @@ public abstract class AbstractAnalysisEngine implements AnalysisEngine {
|
|||
Assertions.UNREACHABLE("no j2selibs specified. You probably did not call AppAnalysisEngine.setJ2SELibrary.");
|
||||
}
|
||||
|
||||
scope = new EMFScopeWrapper(BASIC_FILE, getExclusionsFile(), getClass().getClassLoader());
|
||||
scope = AnalysisScopeReader.read(BASIC_FILE, getExclusionsFile(), getClass().getClassLoader());
|
||||
|
||||
// add standard libraries
|
||||
for (int i = 0; i < j2seLibs.length; i++) {
|
||||
|
|
|
@ -36,13 +36,13 @@ import com.ibm.wala.classLoader.JarFileModule;
|
|||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
|
||||
import com.ibm.wala.client.impl.AbstractAnalysisEngine;
|
||||
import com.ibm.wala.emf.wrappers.EMFScopeWrapper;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.util.Atom;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.collections.HashSetFactory;
|
||||
import com.ibm.wala.util.collections.MapUtil;
|
||||
import com.ibm.wala.util.config.*;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
|
||||
/**
|
||||
|
@ -220,7 +220,7 @@ public class EclipseProjectPath {
|
|||
Set<Module> s = MapUtil.findOrCreateSet(binaryModules, Loader.APPLICATION);
|
||||
s.add(new BinaryDirectoryTreeModule(makeAbsolute(project.getOutputLocation()).toFile()));
|
||||
|
||||
AnalysisScope scope = new EMFScopeWrapper(AbstractAnalysisEngine.BASIC_FILE, exclusionsFile, classLoader);
|
||||
AnalysisScope scope = AnalysisScopeReader.read(AbstractAnalysisEngine.BASIC_FILE, exclusionsFile, classLoader);
|
||||
|
||||
for (Loader loader : Loader.values()) {
|
||||
for (Module m : binaryModules.get(loader)) {
|
||||
|
|
|
@ -1,515 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 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.emf.wrappers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipException;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.emf.ecore.xmi.XMLResource.XMLMap;
|
||||
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
|
||||
|
||||
import com.ibm.wala.classLoader.Language;
|
||||
import com.ibm.wala.classLoader.Module;
|
||||
import com.ibm.wala.ecore.j2ee.scope.impl.J2EEScopePackageImpl;
|
||||
import com.ibm.wala.ecore.java.scope.EBuiltInModule;
|
||||
import com.ibm.wala.ecore.java.scope.EBuiltInResource;
|
||||
import com.ibm.wala.ecore.java.scope.EClassFile;
|
||||
import com.ibm.wala.ecore.java.scope.EClassLoader;
|
||||
import com.ibm.wala.ecore.java.scope.EJarFile;
|
||||
import com.ibm.wala.ecore.java.scope.EJavaAnalysisScope;
|
||||
import com.ibm.wala.ecore.java.scope.EModule;
|
||||
import com.ibm.wala.ecore.java.scope.ESourceFile;
|
||||
import com.ibm.wala.ecore.java.scope.EStandardClassLoader;
|
||||
import com.ibm.wala.ecore.java.scope.JavaScopeFactory;
|
||||
import com.ibm.wala.ecore.java.scope.impl.JavaScopePackageImpl;
|
||||
import com.ibm.wala.ecore.java.scope.util.JavaScopeSwitch;
|
||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||
import com.ibm.wala.properties.WalaProperties;
|
||||
import com.ibm.wala.types.ClassLoaderReference;
|
||||
import com.ibm.wala.util.collections.HashMapFactory;
|
||||
import com.ibm.wala.util.config.FileProvider;
|
||||
import com.ibm.wala.util.config.XMLSetOfClasses;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.debug.Trace;
|
||||
import com.ibm.wala.util.warnings.WalaException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Goal of this class is to generate a scope-wrapper around a given Jar or Class
|
||||
* file. The generated scope-wrapper currently provides the an additional
|
||||
* Primordial class loader with the primoirdial_jar_model built-in module. In
|
||||
* the future, additional information may be included in the generated
|
||||
* scope-wrapper.
|
||||
*
|
||||
* The generator emulates internal structure created by scope files such as the
|
||||
* following example:
|
||||
*
|
||||
* <verbatim> <loaders loaderName="Primordial"> <modules
|
||||
* xsi:type="com.ibm.wala.java.scope:BuiltInModule"/> <modules
|
||||
* xsi:type="com.ibm.wala.java.scope:BuiltInModule" id="primordial_jar_model"/>
|
||||
* </loaders> <loaders loaderName="Application"> <modules
|
||||
* url="$TESTDATA/Example.jar" xsi:type="com.ibm.wala.java.scope:JarFile"/>
|
||||
* </loaders> </verbatim>
|
||||
*
|
||||
* @author Eran Yahav (yahave)
|
||||
* @author Stephen Fink
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EMFScopeWrapper extends AnalysisScope {
|
||||
|
||||
private final static int DEBUG_LEVEL = 0;
|
||||
|
||||
private final String exclusionsFile;
|
||||
|
||||
private final String scopeFile;
|
||||
|
||||
private final ClassLoader classloader;
|
||||
|
||||
private static final Object SUCCESS = new Object();
|
||||
|
||||
static {
|
||||
JavaScopePackageImpl.init();
|
||||
J2EEScopePackageImpl.init();
|
||||
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor enabling automated construction of the ScopeWrapper (with no
|
||||
* files provided)
|
||||
*/
|
||||
protected EMFScopeWrapper(final ClassLoader loader) {
|
||||
super(Collections.singleton(Language.JAVA));
|
||||
this.classloader = loader;
|
||||
this.scopeFile = null;
|
||||
this.exclusionsFile = null;
|
||||
}
|
||||
|
||||
public EMFScopeWrapper(String scopeFile, String exclusionsFile, ClassLoader loader, boolean scopeAsFile) {
|
||||
super(Collections.singleton(Language.JAVA));
|
||||
this.scopeFile = scopeFile;
|
||||
this.classloader = loader;
|
||||
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println(getClass() + " ctor " + scopeFile);
|
||||
}
|
||||
this.exclusionsFile = exclusionsFile;
|
||||
EJavaAnalysisScope escope = null;
|
||||
try {
|
||||
if (scopeAsFile) {
|
||||
escope = readScopeAsFile();
|
||||
} else {
|
||||
escope = readScope();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
populate(escope);
|
||||
addDefaultBypassLoader();
|
||||
|
||||
if (exclusionsFile != null) {
|
||||
setExclusions(new XMLSetOfClasses(exclusionsFile, loader));
|
||||
}
|
||||
}
|
||||
|
||||
public EMFScopeWrapper(String scopeFile, String exclusionsFile, ClassLoader loader) {
|
||||
this(scopeFile, exclusionsFile, loader, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* add the default logic for synthetic bypass.
|
||||
*/
|
||||
protected void addDefaultBypassLoader() {
|
||||
ClassLoaderReference synthLoader = classLoaderName2Ref(EStandardClassLoader.SYNTHETIC_LITERAL.getName());
|
||||
setLoaderImpl(synthLoader, com.ibm.wala.ipa.summaries.BypassSyntheticClassLoader.class.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up internal data structures
|
||||
*
|
||||
* @param escope
|
||||
*/
|
||||
protected void populate(EJavaAnalysisScope escope) {
|
||||
for (Iterator<EClassLoader> it = escope.getLoaders().iterator(); it.hasNext();) {
|
||||
EClassLoader loader = it.next();
|
||||
ClassLoaderReference loaderRef = classLoaderName2Ref(loader.getLoaderName());
|
||||
for (Iterator<EModule> it2 = loader.getModules().iterator(); it2.hasNext();) {
|
||||
EModule m = it2.next();
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("populate: " + m);
|
||||
}
|
||||
processModule(m, loaderRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void processModule(EModule m, final ClassLoaderReference loader) {
|
||||
JavaScopeSwitch sw = new JavaScopeSwitch() {
|
||||
|
||||
@Override
|
||||
public Object defaultCase(EObject object) {
|
||||
Assertions.UNREACHABLE(object.getClass().toString());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object caseEBuiltInModule(EBuiltInModule object) {
|
||||
processBuiltInModule(object, loader);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object caseEJarFile(EJarFile object) {
|
||||
processJarFile(object, loader);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object caseEClassFile(EClassFile object) {
|
||||
try {
|
||||
processClassFile(object, loader);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE(e.toString());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object caseESourceFile(ESourceFile object) {
|
||||
try {
|
||||
processSourceFile(object, loader);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE(e.toString());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
};
|
||||
sw.doSwitch(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param m
|
||||
* @param loader
|
||||
*/
|
||||
private void processSourceFile(ESourceFile m, ClassLoaderReference loader) throws IOException {
|
||||
String fileName = m.getUrl();
|
||||
Assertions.productionAssertion(fileName != null, "null file name specified");
|
||||
File file = FileProvider.getFile(fileName);
|
||||
addSourceFileToScope(loader, file, fileName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param m
|
||||
* @param loader
|
||||
* @throws IOException
|
||||
*/
|
||||
private void processClassFile(EClassFile m, ClassLoaderReference loader) throws IOException {
|
||||
String fileName = m.getUrl();
|
||||
Assertions.productionAssertion(fileName != null, "null file name specified");
|
||||
File file = FileProvider.getFile(fileName);
|
||||
addClassFileToScope(loader, file);
|
||||
}
|
||||
|
||||
|
||||
private void processJarFile(EJarFile m, ClassLoaderReference loader) throws IllegalArgumentException {
|
||||
String fileName = m.getUrl();
|
||||
Assertions.productionAssertion(fileName != null, "null jar file name specified");
|
||||
Module mod = null;
|
||||
try {
|
||||
mod = FileProvider.getJarFileModule(fileName);
|
||||
if (mod == null) {
|
||||
throw new IllegalArgumentException("failed to find jar file module " + fileName);
|
||||
}
|
||||
} catch (ZipException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE("Error opening jar file: " + fileName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE("Error opening jar file: " + fileName);
|
||||
}
|
||||
addToScope(loader, mod);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param m
|
||||
*/
|
||||
private void processBuiltInModule(EBuiltInModule m, ClassLoaderReference loader) {
|
||||
EBuiltInResource r = m.getId();
|
||||
switch (r.getValue()) {
|
||||
case EBuiltInResource.DEFAULT_J2SE_LIBS:
|
||||
String[] libNames = WalaProperties.getJ2SEJarFiles();
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("DEFAULT_J2SE_LIBS:");
|
||||
for (int i = 0; i < libNames.length; i++) {
|
||||
Trace.println(" " + libNames[i]);
|
||||
}
|
||||
}
|
||||
addLibsToLoader(libNames, loader);
|
||||
break;
|
||||
case EBuiltInResource.DEFAULT_J2EE_LIBS:
|
||||
String[] jlibNames = WalaProperties.getJ2EEJarFiles();
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("DEFAULT_J2EE_LIBS:");
|
||||
for (int i = 0; i < jlibNames.length; i++) {
|
||||
Trace.println(" " + jlibNames[i]);
|
||||
}
|
||||
}
|
||||
addLibsToLoader(jlibNames, loader);
|
||||
break;
|
||||
case EBuiltInResource.PRIMORDIAL_JAR_MODEL:
|
||||
addDefaultJarFileToScope(r.getName().replace('_', '.'), loader);
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("PRIMORDIAL_JAR_MODEL: " + r.getName());
|
||||
}
|
||||
break;
|
||||
case EBuiltInResource.EXTENSION_JAR_MODEL:
|
||||
addDefaultJarFileToScope(r.getName().replace('_', '.'), loader);
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("EXTENSION_JAR_MODEL: " + r.getName());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Assertions.UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This method loads the default jar file of this name from the
|
||||
* JarFileProvider
|
||||
*
|
||||
* @param ch @param start @param length
|
||||
*/
|
||||
private void addDefaultJarFileToScope(String fileName, ClassLoaderReference loader) {
|
||||
Module m = null;
|
||||
Assertions.productionAssertion(fileName.length() > 0, "null fileName");
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("Load default jar file: " + fileName);
|
||||
}
|
||||
try {
|
||||
m = FileProvider.getJarFileModule(fileName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.productionAssertion(m != null, "could not open " + fileName);
|
||||
}
|
||||
Assertions.productionAssertion(m != null, "could not open " + fileName);
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("Add to scope: " + m);
|
||||
}
|
||||
addToScope(loader, m);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param libNames
|
||||
* @param loader
|
||||
*/
|
||||
private void addLibsToLoader(String[] libNames, ClassLoaderReference loader) {
|
||||
for (int i = 0; i < libNames.length; i++) {
|
||||
Module m = null;
|
||||
String fileName = libNames[i];
|
||||
Assertions.productionAssertion(fileName.length() > 0, "null fileName");
|
||||
try {
|
||||
m = FileProvider.getJarFileModule(fileName);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.productionAssertion(m != null, "could not open " + fileName);
|
||||
}
|
||||
Assertions.productionAssertion(m != null, "could not open " + fileName);
|
||||
if (DEBUG_LEVEL > 0) {
|
||||
Trace.println("EMFScopeWrapper add file to loader " + fileName);
|
||||
}
|
||||
addToScope(loader, m);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an EMF scope object
|
||||
*/
|
||||
private EJavaAnalysisScope readScope() {
|
||||
InputStream s = classloader.getResourceAsStream(scopeFile);
|
||||
if (s == null) {
|
||||
Assertions.UNREACHABLE("failed to open scope file: " + scopeFile);
|
||||
}
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
Resource r = resSet.createResource(URI.createURI(getClass() + "junk"));
|
||||
Assertions.productionAssertion(r != null);
|
||||
Map<String, XMLMap> options = HashMapFactory.make();
|
||||
try {
|
||||
r.load(s, options);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE("unable to parse " + scopeFile);
|
||||
}
|
||||
return (EJavaAnalysisScope) r.getContents().get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an EMF scope object
|
||||
*/
|
||||
private EJavaAnalysisScope readScopeAsFile() {
|
||||
EJavaAnalysisScope result = null;
|
||||
try {
|
||||
File theScopeFile = new File(scopeFile);
|
||||
InputStream s = new FileInputStream(theScopeFile);
|
||||
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
Resource r = resSet.createResource(URI.createURI(getClass().toString())); // +
|
||||
// "junk2"));
|
||||
Assertions.productionAssertion(r != null);
|
||||
Map<String, XMLMap> options = HashMapFactory.make();
|
||||
try {
|
||||
r.load(s, options);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE("unable to parse " + scopeFile);
|
||||
}
|
||||
result = (EJavaAnalysisScope) r.getContents().get(0);
|
||||
} catch (IOException e) {
|
||||
Assertions.UNREACHABLE("scopeAsFile: failed to open scope file: " + scopeFile);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getExclusionString() {
|
||||
return "Exclusions defined in file " + exclusionsFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a EMFScopeWrapper for a given jar file
|
||||
*
|
||||
* @param cl -
|
||||
* application class loader
|
||||
* @param jarUrl -
|
||||
* URL to the Jar file to be wrapped
|
||||
* @param exclusionsFile -
|
||||
* exclusions file
|
||||
* @return a new EMFScopeWrapper wrapping the jar file
|
||||
* @throws WalaException
|
||||
*/
|
||||
public static EMFScopeWrapper generateJarScope(ClassLoader cl, String jarUrl, String exclusionsFile) throws WalaException {
|
||||
EClassLoader primordial = JavaScopeUtil.createPrimordialLoader();
|
||||
EClassLoader application = JavaScopeUtil.createJarApplicationLoader(jarUrl);
|
||||
|
||||
Collection<EClassLoader> loaders = new ArrayList<EClassLoader>();
|
||||
loaders.add(primordial);
|
||||
loaders.add(application);
|
||||
|
||||
try {
|
||||
return generateScope(cl, loaders, exclusionsFile);
|
||||
} catch (Throwable e) {
|
||||
throw new WalaException("problem generating scope", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a EMFScopeWrapper for a given class file
|
||||
*
|
||||
* @param cl -
|
||||
* application class loader
|
||||
* @param classUrl -
|
||||
* URL to the class file to be wrapped
|
||||
* @param exclusionsFile -
|
||||
* exclusions file
|
||||
* @return a new EMFScopeWrapper wrapping the class file
|
||||
* @throws WalaException
|
||||
*/
|
||||
public static EMFScopeWrapper generateClassScope(ClassLoader cl, String classUrl, String exclusionsFile) throws WalaException {
|
||||
EClassLoader primordial = JavaScopeUtil.createPrimordialLoader();
|
||||
EClassLoader application = JavaScopeUtil.createClassApplicationLoader(classUrl);
|
||||
|
||||
Collection<EClassLoader> loaders = new ArrayList<EClassLoader>();
|
||||
loaders.add(primordial);
|
||||
loaders.add(application);
|
||||
|
||||
try {
|
||||
return generateScope(cl, loaders, exclusionsFile);
|
||||
} catch (Throwable e) {
|
||||
throw new WalaException("problem generating scope", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* generates a EMFScopeWrapper from a collection of loaders
|
||||
*
|
||||
* @param cl -
|
||||
* application class loader
|
||||
* @param loaders -
|
||||
* collection of class loaders
|
||||
* @param exclusionsFile -
|
||||
* exclusion file
|
||||
* @return a new EMFScopeWrapper comprising of the given loaders, and taking
|
||||
* the provided exclusion file into account
|
||||
*/
|
||||
static EMFScopeWrapper generateScope(ClassLoader cl, Collection<EClassLoader> loaders, String exclusionsFile)
|
||||
throws WalaException {
|
||||
EMFScopeWrapper csw = new EMFScopeWrapper(cl);
|
||||
|
||||
EJavaAnalysisScope jas = JavaScopeFactory.eINSTANCE.createEJavaAnalysisScope();
|
||||
jas.getLoaders().clear();
|
||||
jas.getLoaders().addAll(loaders);
|
||||
|
||||
csw.populate(jas);
|
||||
|
||||
csw.addDefaultBypassLoader();
|
||||
|
||||
if (exclusionsFile != null) {
|
||||
csw.setExclusions(new XMLSetOfClasses(exclusionsFile, cl));
|
||||
}
|
||||
|
||||
return csw;
|
||||
}
|
||||
|
||||
/**
|
||||
* generates a EMFScopeWrapper from am EJavaAnalysisScope
|
||||
*
|
||||
* @param escope
|
||||
* @return a new EMFScopeWrapper comprising the given scope
|
||||
* @throws WalaException
|
||||
* @throws IllegalArgumentException
|
||||
* if escope is null
|
||||
*/
|
||||
public static EMFScopeWrapper generateScope(EJavaAnalysisScope escope) throws WalaException {
|
||||
if (escope == null) {
|
||||
throw new IllegalArgumentException("escope is null");
|
||||
}
|
||||
return generateScope(escope, new EMFScopeWrapper(EMFScopeWrapper.class.getClassLoader()));
|
||||
}
|
||||
|
||||
private static EMFScopeWrapper generateScope(final EJavaAnalysisScope escope, final EMFScopeWrapper csw) {
|
||||
csw.populate(escope);
|
||||
csw.addDefaultBypassLoader();
|
||||
String exclusionsFile = escope.getExclusionFileName();
|
||||
if (exclusionsFile != null) {
|
||||
csw.setExclusions(new XMLSetOfClasses(exclusionsFile, EMFScopeWrapper.class.getClassLoader()));
|
||||
}
|
||||
|
||||
return csw;
|
||||
}
|
||||
}
|
|
@ -1,147 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 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.emf.wrappers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.resource.URIConverter;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.emf.ecore.resource.impl.URIConverterImpl;
|
||||
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
|
||||
|
||||
import com.ibm.wala.ecore.regex.impl.RegexPackageImpl;
|
||||
import com.ibm.wala.util.warnings.WalaException;
|
||||
|
||||
/**
|
||||
*
|
||||
* miscellaneous utilities for manipulating EMF objects
|
||||
*
|
||||
* @author sfink
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class EUtil {
|
||||
|
||||
private static final String CORE_ECORE = "wala.ecore";
|
||||
|
||||
|
||||
static {
|
||||
RegexPackageImpl.init();
|
||||
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a URIConverter set up to find ecore models used by WALA
|
||||
*/
|
||||
public static URIConverter getURIConverter() {
|
||||
|
||||
ClassLoader loader = EUtil.class.getClassLoader();
|
||||
if (loader == null) {
|
||||
// a hack for when we're sticking stuff in the bootstrap classpath
|
||||
loader = ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
URL url = loader.getResource(CORE_ECORE);
|
||||
String s = url.toString();
|
||||
int index = s.indexOf(CORE_ECORE);
|
||||
s = s.substring(0, index);
|
||||
|
||||
// URI uri1 = URI.createURI(CORE_CONTROLLER_URI);
|
||||
// URI uri2 = URI.createURI(s);
|
||||
URIConverter converter = new URIConverterImpl();
|
||||
// converter.getURIMap().put(uri1, uri2);
|
||||
|
||||
return converter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param xmlFile
|
||||
* an xml file
|
||||
* @return List<EObject> serialized in said file.
|
||||
* @throws IllegalArgumentException if loader is null
|
||||
*/
|
||||
public static List<EObject> readEObjects(String xmlFile, ClassLoader loader) throws WalaException {
|
||||
|
||||
if (loader == null) {
|
||||
throw new IllegalArgumentException("loader is null");
|
||||
}
|
||||
URL url = loader.getResource(xmlFile);
|
||||
URI fileURI = null;
|
||||
if (url != null) {
|
||||
fileURI = URI.createURI(url.toString());
|
||||
} else {
|
||||
fileURI = URI.createFileURI(xmlFile);
|
||||
}
|
||||
|
||||
URIConverter converter = getURIConverter();
|
||||
ResourceSet resourceSet = new ResourceSetImpl();
|
||||
resourceSet.setURIConverter(converter);
|
||||
|
||||
Resource resource = resourceSet.createResource(fileURI);
|
||||
|
||||
try {
|
||||
resource.load(null);
|
||||
} catch (IOException e) {
|
||||
throw new WalaException("failure to load " + xmlFile + ".", e);
|
||||
}
|
||||
|
||||
return resource.getContents();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param R
|
||||
// * @param key
|
||||
// * @return the subset r \in R s.t. r.X.equals(key)
|
||||
// * @throws IllegalArgumentException if R is null
|
||||
// */
|
||||
// public static ERelation pruneRelationForKey(ERelation R, EObject key) {
|
||||
// if (R == null) {
|
||||
// throw new IllegalArgumentException("R is null");
|
||||
// }
|
||||
// Map m = createMap(R);
|
||||
// Set s = (Set) m.get(key);
|
||||
// m = new HashMap(1);
|
||||
// if (s != null) {
|
||||
// m.put(key,s);
|
||||
// }
|
||||
// ERelation result = CommonFactory.eINSTANCE.createERelation();
|
||||
// result.setName(R.getName());
|
||||
// populateRelation(result,m);
|
||||
// return result;
|
||||
// }
|
||||
// /**
|
||||
// * @param R
|
||||
// * @param f
|
||||
// * @return the subset r \in R s.t. r.X.equals(some y s.t. f.accepts(y))
|
||||
// * @throws IllegalArgumentException if R is null
|
||||
// */
|
||||
// public static ERelation pruneRelationForKey(ERelation R, Filter f) {
|
||||
// if (R == null) {
|
||||
// throw new IllegalArgumentException("R is null");
|
||||
// }
|
||||
// Map m = createMap(R);
|
||||
// Map newM = new HashMap();
|
||||
// for (FilterIterator it = new FilterIterator(m.keySet().iterator(),f); it.hasNext(); ) {
|
||||
// Object key = it.next();
|
||||
// newM.put(key,m.get(key));
|
||||
// }
|
||||
//
|
||||
// ERelation result = CommonFactory.eINSTANCE.createERelation();
|
||||
// result.setName(R.getName());
|
||||
// populateRelation(result,newM);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
}
|
|
@ -1,221 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 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.emf.wrappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import com.ibm.wala.ecore.java.scope.EBuiltInModule;
|
||||
import com.ibm.wala.ecore.java.scope.EBuiltInResource;
|
||||
import com.ibm.wala.ecore.java.scope.EClassFile;
|
||||
import com.ibm.wala.ecore.java.scope.EClassLoader;
|
||||
import com.ibm.wala.ecore.java.scope.EJarFile;
|
||||
import com.ibm.wala.ecore.java.scope.EJavaAnalysisScope;
|
||||
import com.ibm.wala.ecore.java.scope.JavaScopeFactory;
|
||||
import com.ibm.wala.util.io.FileSuffixes;
|
||||
import com.ibm.wala.util.warnings.WalaException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Utilities to help manipulate EMF objects representing Java analysis scopes.
|
||||
*
|
||||
*
|
||||
* @author Eran Yahav (yahave)
|
||||
*/
|
||||
public class JavaScopeUtil {
|
||||
// codes used to classify classpath entries
|
||||
private final static byte JAR_FILE = 0;
|
||||
|
||||
/**
|
||||
* name of the Primordial class loader
|
||||
*/
|
||||
private static final String PRIMORDIAL_LOADER_NAME = "Primordial";
|
||||
|
||||
/**
|
||||
* name of the application class loader
|
||||
*/
|
||||
private static final String APPLICATION_LOADER_NAME = "Application";
|
||||
|
||||
/**
|
||||
* name of the jar file providing the primordial model
|
||||
*/
|
||||
private static final String PRIMORDIAL_JAR_FILE = "primordial_jar_model";
|
||||
|
||||
/**
|
||||
* Creates a new EClassLoader representing the application class loader
|
||||
*
|
||||
* @return a new EClassLoader
|
||||
*/
|
||||
public static EClassLoader createApplicationLoader() {
|
||||
EClassLoader application = JavaScopeFactory.eINSTANCE.createEClassLoader();
|
||||
application.setLoaderName(APPLICATION_LOADER_NAME);
|
||||
return application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EClassLoader representing the application class loader, and
|
||||
* containing the given Jar file as a module.
|
||||
*
|
||||
* @param jarUrl -
|
||||
* URL to the jar file to be included as module\
|
||||
* @return a new ClassLoader containing the provided Jar file as a module
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static EClassLoader createJarApplicationLoader(String jarUrl) {
|
||||
EClassLoader application = createApplicationLoader();
|
||||
EJarFile jf = createJarModule(jarUrl);
|
||||
application.getModules().clear();
|
||||
application.getModules().add(jf);
|
||||
return application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EClassLoader representing the application class loader, and
|
||||
* containing the given class file as a module.
|
||||
*
|
||||
* @param classUrl -
|
||||
* URL to the class file to be included as module
|
||||
* @return a new ClassLoader containing the provided class file as a module
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static EClassLoader createClassApplicationLoader(String classUrl) {
|
||||
EClassLoader application = JavaScopeFactory.eINSTANCE.createEClassLoader();
|
||||
application.setLoaderName(APPLICATION_LOADER_NAME);
|
||||
EClassFile cf = createClassModule(classUrl);
|
||||
application.getModules().clear();
|
||||
application.getModules().add(cf);
|
||||
return application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Primordial class loader
|
||||
*
|
||||
* @return a new EClassLoader representing the Primordial class loader, and
|
||||
* containing the primordial_jar_model as a module.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static EClassLoader createPrimordialLoader() {
|
||||
EClassLoader primordialLoader = JavaScopeFactory.eINSTANCE.createEClassLoader();
|
||||
primordialLoader.setLoaderName(PRIMORDIAL_LOADER_NAME);
|
||||
EBuiltInModule bim1 = JavaScopeFactory.eINSTANCE.createEBuiltInModule();
|
||||
EBuiltInModule bim2 = JavaScopeFactory.eINSTANCE.createEBuiltInModule();
|
||||
EBuiltInResource bir = EBuiltInResource.get(PRIMORDIAL_JAR_FILE);
|
||||
bim2.setId(bir);
|
||||
Collection<EBuiltInModule> modules = new ArrayList<EBuiltInModule>();
|
||||
modules.add(bim1);
|
||||
modules.add(bim2);
|
||||
|
||||
primordialLoader.getModules().clear();
|
||||
primordialLoader.getModules().addAll(modules);
|
||||
return primordialLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a JarFile from a given url
|
||||
*
|
||||
* @param urlString -
|
||||
* url to the jar file
|
||||
* @return a JarFile from the url
|
||||
*/
|
||||
public static EJarFile createJarModule(String urlString) {
|
||||
EJarFile aJarFile = JavaScopeFactory.eINSTANCE.createEJarFile();
|
||||
aJarFile.setUrl(urlString);
|
||||
return aJarFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a ClassFile from a given url
|
||||
*
|
||||
* @param urlString -
|
||||
* url to the class file
|
||||
* @return a ClassFile from the url
|
||||
*/
|
||||
public static EClassFile createClassModule(String urlString) {
|
||||
EClassFile aClassFile = JavaScopeFactory.eINSTANCE.createEClassFile();
|
||||
aClassFile.setUrl(urlString);
|
||||
return aClassFile;
|
||||
}
|
||||
|
||||
public static EJavaAnalysisScope makeAnalysisScope(String classpath, String exclusions) throws WalaException {
|
||||
|
||||
if (classpath == null) {
|
||||
throw new IllegalArgumentException("classpath is null");
|
||||
}
|
||||
// create an EJavaAnalysisScope and deposit it into the output PAS
|
||||
EJavaAnalysisScope scope = JavaScopeFactory.eINSTANCE.createEJavaAnalysisScope();
|
||||
scope.setExclusionFileName(exclusions);
|
||||
|
||||
// populate the analysis scope according to the contents of the classpath
|
||||
populateScope(scope, classpath);
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
public static EJavaAnalysisScope makePrimordialScope(String exclusions) throws WalaException {
|
||||
return makeAnalysisScope("", exclusions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate an analysis scope object according to the contents of a String
|
||||
* which represents the classpath
|
||||
*
|
||||
* @param scope
|
||||
* a scope object to populate
|
||||
* @param string
|
||||
* a ';'-delimited classpath string
|
||||
* @throws WalaException
|
||||
* if there's a problem
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void populateScope(EJavaAnalysisScope scope, String string) throws WalaException {
|
||||
// This component assumes that the analysis scope describes the application
|
||||
// loader. Create an object to represent the application loader.
|
||||
EClassLoader appLoader = createApplicationLoader();
|
||||
scope.getLoaders().add(appLoader);
|
||||
|
||||
// Parse the String which represents the classpath
|
||||
StringTokenizer tokenizer = new StringTokenizer(string, ";");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String token = tokenizer.nextToken();
|
||||
byte kind = classifyToken(token);
|
||||
switch (kind) {
|
||||
case JAR_FILE:
|
||||
// Add a jar-file module to the analysis scope
|
||||
EJarFile j = createJarModule(token);
|
||||
appLoader.getModules().add(j);
|
||||
break;
|
||||
default:
|
||||
// TODO: implement more cases
|
||||
throw new WalaException("unexpected kind: " + kind);
|
||||
}
|
||||
}
|
||||
|
||||
// add the primordial class loader to the analysis scope
|
||||
scope.getLoaders().add(createPrimordialLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param token
|
||||
* an entry in a classpath
|
||||
* @return JAR_FILE if it's a jar file name
|
||||
* @throws WalaException
|
||||
* if we cannot deduce the kind of the token
|
||||
*/
|
||||
public static byte classifyToken(String token) throws WalaException {
|
||||
if (FileSuffixes.isJarFile(token)) {
|
||||
return JAR_FILE;
|
||||
} else {
|
||||
throw new WalaException("could not parse classpath token: " + token);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -109,6 +109,8 @@ public class AnalysisScope {
|
|||
application.setParent(extension);
|
||||
synthetic.setParent(application);
|
||||
|
||||
setLoaderImpl(synthetic, "com.ibm.wala.ipa.summaries.BypassSyntheticClassLoader");
|
||||
|
||||
loadersByName.put(PRIMORDIAL, primordial);
|
||||
loadersByName.put(EXTENSION, extension);
|
||||
loadersByName.put(APPLICATION, application);
|
||||
|
@ -254,8 +256,7 @@ public class AnalysisScope {
|
|||
return loaderImplByRef.get(ref);
|
||||
}
|
||||
|
||||
// todo: nuke this?
|
||||
protected void setLoaderImpl(ClassLoaderReference ref, String implClass) {
|
||||
public void setLoaderImpl(ClassLoaderReference ref, String implClass) {
|
||||
loaderImplByRef.put(ref, implClass);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002 - 2006 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;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.ibm.wala.ecore.common.EContainer;
|
||||
import com.ibm.wala.ecore.regex.EPattern;
|
||||
|
||||
/**
|
||||
* @author sfink
|
||||
*
|
||||
*/
|
||||
public class PatternSetUtil {
|
||||
|
||||
/**
|
||||
* @param c a Container of EPattern
|
||||
* @return a regular expression that is the OR of a set of regular expressions
|
||||
* contained the EContainer
|
||||
* @throws IllegalArgumentException if c is null
|
||||
*/
|
||||
public static String composeRegularExpression(EContainer c) {
|
||||
if (c == null) {
|
||||
throw new IllegalArgumentException("c is null");
|
||||
}
|
||||
StringBuffer result = new StringBuffer();
|
||||
for (Iterator it = c.getContents().iterator(); it.hasNext(); ) {
|
||||
EPattern pattern = (EPattern)it.next();
|
||||
String s = pattern.getPattern();
|
||||
result.append(s);
|
||||
if (it.hasNext()) {
|
||||
result.append('|');
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
package com.ibm.wala.util.config;
|
||||
|
||||
import com.ibm.wala.classLoader.*;
|
||||
import com.ibm.wala.ipa.callgraph.*;
|
||||
import com.ibm.wala.properties.*;
|
||||
import com.ibm.wala.types.*;
|
||||
import com.ibm.wala.util.Atom;
|
||||
import com.ibm.wala.util.debug.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.jar.*;
|
||||
|
||||
public class AnalysisScopeReader {
|
||||
|
||||
private static final ClassLoader MY_CLASSLOADER =
|
||||
AnalysisScopeReader.class.getClassLoader();
|
||||
|
||||
private static final String BASIC_FILE =
|
||||
"J2SESyntheticModel.txt";
|
||||
|
||||
public static AnalysisScope
|
||||
read(String scopeFileName, String 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)
|
||||
{
|
||||
try {
|
||||
File scopeFile = FileProvider.getFile(scopeFileName, javaLoader);
|
||||
assert scopeFile.exists();
|
||||
|
||||
String line;
|
||||
BufferedReader r = new BufferedReader(new FileReader(scopeFile));
|
||||
while ((line = r.readLine()) != null) {
|
||||
StringTokenizer toks = new StringTokenizer(line, "\n,");
|
||||
|
||||
Atom loaderName = Atom.findOrCreateUnicodeAtom(toks.nextToken());
|
||||
Atom languageName = Atom.findOrCreateUnicodeAtom(toks.nextToken());
|
||||
ClassLoaderReference walaLoader =
|
||||
new ClassLoaderReference(loaderName, languageName);
|
||||
|
||||
String entryType = toks.nextToken();
|
||||
String entryPathname = toks.nextToken();
|
||||
if ("classFile".equals(entryType)) {
|
||||
File cf = FileProvider.getFile(entryPathname, javaLoader);
|
||||
scope.addClassFileToScope(walaLoader, cf);
|
||||
} else if ("sourceFile".equals(entryType)) {
|
||||
File sf = FileProvider.getFile(entryPathname, javaLoader);
|
||||
scope.addSourceFileToScope(walaLoader, sf, entryPathname);
|
||||
} else if ("binaryDir".equals(entryType)) {
|
||||
File bd = FileProvider.getFile(entryPathname, javaLoader);
|
||||
assert bd.isDirectory();
|
||||
scope.addToScope(walaLoader, new BinaryDirectoryTreeModule(bd));
|
||||
} else if ("sourceDir".equals(entryType)) {
|
||||
File sd = FileProvider.getFile(entryPathname, javaLoader);
|
||||
assert sd.isDirectory();
|
||||
scope.addToScope(walaLoader, new SourceDirectoryTreeModule(sd));
|
||||
} else if ("jarFile".equals(entryType)) {
|
||||
Module M = FileProvider.getJarFileModule(entryPathname, javaLoader);
|
||||
scope.addToScope(walaLoader, M);
|
||||
} else if ("loaderImpl".equals(entryType)) {
|
||||
scope.setLoaderImpl(walaLoader, entryPathname);
|
||||
} else if ("stdlib".equals(entryType)) {
|
||||
String[] stdlibs = WalaProperties.getJ2SEJarFiles();
|
||||
for(int i = 0; i < stdlibs.length; i++) {
|
||||
scope.addToScope(walaLoader, new JarFile(stdlibs[i]));
|
||||
}
|
||||
} else {
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
if (exclusionsFile != null) {
|
||||
scope.setExclusions(new FileOfClasses(exclusionsFile, javaLoader));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
Assertions.UNREACHABLE(e.toString());
|
||||
}
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
public static AnalysisScope makePrimordialScope(String exclusionsFile) {
|
||||
return read(BASIC_FILE, exclusionsFile, MY_CLASSLOADER);
|
||||
}
|
||||
|
||||
public static AnalysisScope
|
||||
makeJavaBinaryAnalysisScope(String classPath, String exclusionsFile)
|
||||
{
|
||||
AnalysisScope scope = makePrimordialScope(exclusionsFile);
|
||||
ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
|
||||
|
||||
try {
|
||||
StringTokenizer paths =
|
||||
new StringTokenizer(classPath, File.pathSeparator);
|
||||
while (paths.hasMoreTokens()) {
|
||||
String path = paths.nextToken();
|
||||
if (path.endsWith(".jar")) {
|
||||
scope.addToScope(loader, new JarFile(path));
|
||||
} else {
|
||||
File f = new File(path);
|
||||
if (f.isDirectory()) {
|
||||
scope.addToScope(loader, new BinaryDirectoryTreeModule(f));
|
||||
} else {
|
||||
scope.addClassFileToScope(loader, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Assertions.UNREACHABLE(e.toString());
|
||||
}
|
||||
|
||||
return scope;
|
||||
}
|
||||
}
|
|
@ -10,25 +10,22 @@
|
|||
*******************************************************************************/
|
||||
package com.ibm.wala.util.config;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.ibm.wala.classLoader.IClass;
|
||||
import com.ibm.wala.ecore.common.EContainer;
|
||||
import com.ibm.wala.emf.wrappers.EUtil;
|
||||
import com.ibm.wala.ipa.callgraph.impl.SetOfClasses;
|
||||
import com.ibm.wala.types.TypeReference;
|
||||
import com.ibm.wala.util.PatternSetUtil;
|
||||
import com.ibm.wala.util.debug.Assertions;
|
||||
import com.ibm.wala.util.warnings.WalaException;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* An object which represents a set of classes read from an XML file.
|
||||
*
|
||||
* @author sfink
|
||||
*/
|
||||
public class XMLSetOfClasses extends SetOfClasses {
|
||||
public class FileOfClasses extends SetOfClasses {
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
|
@ -38,19 +35,27 @@ public class XMLSetOfClasses extends SetOfClasses {
|
|||
|
||||
private boolean needsCompile = true;
|
||||
|
||||
public XMLSetOfClasses(String xmlFile, ClassLoader loader) {
|
||||
super();
|
||||
|
||||
EContainer c = null;
|
||||
public FileOfClasses(String textFileName, ClassLoader loader) {
|
||||
try {
|
||||
c = (EContainer) EUtil.readEObjects(xmlFile, loader).get(0);
|
||||
} catch (WalaException e) {
|
||||
File textFile = FileProvider.getFile(textFileName, loader);
|
||||
BufferedReader is = new BufferedReader(new FileReader(textFile));
|
||||
|
||||
StringBuffer regex = null;
|
||||
String line;
|
||||
while ((line = is.readLine()) != null) {
|
||||
if (regex == null) {
|
||||
regex = new StringBuffer("(" + line + ")");
|
||||
} else {
|
||||
regex.append("|(" + line + ")");
|
||||
}
|
||||
}
|
||||
|
||||
this.regex = regex.toString();
|
||||
needsCompile = true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Assertions.UNREACHABLE();
|
||||
}
|
||||
|
||||
regex = PatternSetUtil.composeRegularExpression(c);
|
||||
needsCompile = true;
|
||||
}
|
||||
|
||||
private void compile() {
|
||||
|
@ -96,4 +101,4 @@ public class XMLSetOfClasses extends SetOfClasses {
|
|||
regex = regex + '|' + klass.getReference().getName().toString();
|
||||
needsCompile = true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -67,16 +67,14 @@ public class FileProvider {
|
|||
* if not found.
|
||||
*/
|
||||
public static Module getJarFileModule(String fileName) throws IOException {
|
||||
// try {
|
||||
// return (CorePlugin.getDefault() == null) ?
|
||||
// getJarFileFromClassLoader(fileName) : getFromPlugin(fileName);
|
||||
// } catch (IOException e) {
|
||||
// System.err.println("Problem with file " + fileName);
|
||||
// throw e;
|
||||
// }
|
||||
return getJarFileModule(fileName, FileProvider.class.getClassLoader());
|
||||
}
|
||||
|
||||
public static Module getJarFileModule(String fileName, ClassLoader loader)
|
||||
throws IOException
|
||||
{
|
||||
if (CorePlugin.getDefault() == null) {
|
||||
return getJarFileFromClassLoader(fileName);
|
||||
return getJarFileFromClassLoader(fileName, loader);
|
||||
} else {
|
||||
// try to load the path as a full path
|
||||
try {
|
||||
|
@ -97,7 +95,16 @@ public class FileProvider {
|
|||
/**
|
||||
*/
|
||||
public static File getFile(String fileName) throws IOException {
|
||||
return (CorePlugin.getDefault() == null) ? getFileFromClassLoader(fileName) : getFileFromPlugin(CorePlugin.getDefault(), fileName);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,8 +194,10 @@ public class FileProvider {
|
|||
/**
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public static File getFileFromClassLoader(String fileName) throws FileNotFoundException {
|
||||
URL url = FileProvider.class.getClassLoader().getResource(fileName);
|
||||
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);
|
||||
}
|
||||
|
@ -211,8 +220,11 @@ public class FileProvider {
|
|||
* if not found: wrapped as a JarFileModule or a NestedJarFileModule
|
||||
* @throws IOException
|
||||
*/
|
||||
public static Module getJarFileFromClassLoader(String fileName) throws IOException {
|
||||
URL url = FileProvider.class.getClassLoader().getResource(fileName);
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue