got code to compile again, and wala.core regression tests pass
This commit is contained in:
parent
e0d3df8ea7
commit
c116f16823
|
@ -24,11 +24,11 @@ import com.ibm.wala.cast.java.test.ide.IDEIRTestUtil;
|
||||||
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
|
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
|
||||||
import com.ibm.wala.core.tests.plugin.CoreTestsPlugin;
|
import com.ibm.wala.core.tests.plugin.CoreTestsPlugin;
|
||||||
import com.ibm.wala.ide.tests.util.EclipseTestUtil;
|
import com.ibm.wala.ide.tests.util.EclipseTestUtil;
|
||||||
|
import com.ibm.wala.ide.util.EclipseFileProvider;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
||||||
import com.ibm.wala.ipa.callgraph.impl.Util;
|
import com.ibm.wala.ipa.callgraph.impl.Util;
|
||||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||||
import com.ibm.wala.util.io.FileProvider;
|
|
||||||
|
|
||||||
public class JDTJava15IRTests extends IRTests {
|
public class JDTJava15IRTests extends IRTests {
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class JDTJava15IRTests extends IRTests {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
engine.setExclusionsFile((new FileProvider())
|
engine.setExclusionsFile((new EclipseFileProvider())
|
||||||
.getFileFromPlugin(CoreTestsPlugin.getDefault(), CallGraphTestUtil.REGRESSION_EXCLUSIONS).getAbsolutePath());
|
.getFileFromPlugin(CoreTestsPlugin.getDefault(), CallGraphTestUtil.REGRESSION_EXCLUSIONS).getAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Assert.assertFalse("Cannot find exclusions file", true);
|
Assert.assertFalse("Cannot find exclusions file", true);
|
||||||
|
|
|
@ -54,11 +54,11 @@ import com.ibm.wala.cast.java.test.ide.IDEIRTestUtil;
|
||||||
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
|
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
|
||||||
import com.ibm.wala.core.tests.plugin.CoreTestsPlugin;
|
import com.ibm.wala.core.tests.plugin.CoreTestsPlugin;
|
||||||
import com.ibm.wala.ide.tests.util.EclipseTestUtil;
|
import com.ibm.wala.ide.tests.util.EclipseTestUtil;
|
||||||
|
import com.ibm.wala.ide.util.EclipseFileProvider;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
import com.ibm.wala.ipa.callgraph.Entrypoint;
|
||||||
import com.ibm.wala.ipa.callgraph.impl.Util;
|
import com.ibm.wala.ipa.callgraph.impl.Util;
|
||||||
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
import com.ibm.wala.ipa.cha.IClassHierarchy;
|
||||||
import com.ibm.wala.util.io.FileProvider;
|
|
||||||
|
|
||||||
public class JDTJavaIRTests extends JavaIRTests {
|
public class JDTJavaIRTests extends JavaIRTests {
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class JDTJavaIRTests extends JavaIRTests {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
engine.setExclusionsFile((new FileProvider())
|
engine.setExclusionsFile((new EclipseFileProvider())
|
||||||
.getFileFromPlugin(CoreTestsPlugin.getDefault(), CallGraphTestUtil.REGRESSION_EXCLUSIONS).getAbsolutePath());
|
.getFileFromPlugin(CoreTestsPlugin.getDefault(), CallGraphTestUtil.REGRESSION_EXCLUSIONS).getAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Assert.assertFalse("Cannot find exclusions file", true);
|
Assert.assertFalse("Cannot find exclusions file", true);
|
||||||
|
|
|
@ -25,7 +25,8 @@ import com.ibm.wala.classLoader.BinaryDirectoryTreeModule;
|
||||||
import com.ibm.wala.classLoader.ClassLoaderFactory;
|
import com.ibm.wala.classLoader.ClassLoaderFactory;
|
||||||
import com.ibm.wala.classLoader.Module;
|
import com.ibm.wala.classLoader.Module;
|
||||||
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
|
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
|
||||||
import com.ibm.wala.core.plugin.CorePlugin;
|
import com.ibm.wala.ide.plugin.CorePlugin;
|
||||||
|
import com.ibm.wala.ide.util.EclipseFileProvider;
|
||||||
import com.ibm.wala.ide.util.EclipseProjectPath;
|
import com.ibm.wala.ide.util.EclipseProjectPath;
|
||||||
import com.ibm.wala.ide.util.EclipseProjectPath.Loader;
|
import com.ibm.wala.ide.util.EclipseProjectPath.Loader;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
||||||
|
@ -64,7 +65,7 @@ public class EclipseProjectSourceAnalysisEngine extends EclipseProjectAnalysisEn
|
||||||
super(project);
|
super(project);
|
||||||
this.fileExt = fileExt;
|
this.fileExt = fileExt;
|
||||||
try {
|
try {
|
||||||
setExclusionsFile((new FileProvider()).getFileFromPlugin(CorePlugin.getDefault(), "J2SEClassHierarchyExclusions.txt")
|
setExclusionsFile((new EclipseFileProvider()).getFileFromPlugin(CorePlugin.getDefault(), "J2SEClassHierarchyExclusions.txt")
|
||||||
.getAbsolutePath());
|
.getAbsolutePath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Assertions.UNREACHABLE("Cannot find exclusions file");
|
Assertions.UNREACHABLE("Cannot find exclusions file");
|
||||||
|
|
|
@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.core.runtime,
|
||||||
com.ibm.wala.cast.js.test;bundle-version="1.0.0",
|
com.ibm.wala.cast.js.test;bundle-version="1.0.0",
|
||||||
com.ibm.wala.cast.test;bundle-version="1.0.0",
|
com.ibm.wala.cast.test;bundle-version="1.0.0",
|
||||||
com.ibm.wala.core.tests;bundle-version="1.1.3",
|
com.ibm.wala.core.tests;bundle-version="1.1.3",
|
||||||
org.junit4;bundle-version="4.3.1"
|
org.junit4;bundle-version="4.3.1",
|
||||||
|
com.ibm.wala.ide;bundle-version="1.1.3"
|
||||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||||
Bundle-ActivationPolicy: lazy
|
Bundle-ActivationPolicy: lazy
|
||||||
Export-Package: com.ibm.wala.cast.js.test
|
Export-Package: com.ibm.wala.cast.js.test
|
||||||
|
|
|
@ -20,13 +20,13 @@ import com.ibm.wala.cast.js.ipa.callgraph.correlations.extraction.CorrelatedPair
|
||||||
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil;
|
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil;
|
||||||
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil.CGBuilderType;
|
import com.ibm.wala.cast.js.test.JSCallGraphBuilderUtil.CGBuilderType;
|
||||||
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
import com.ibm.wala.cast.js.translator.CAstRhinoTranslatorFactory;
|
||||||
|
import com.ibm.wala.ide.util.ProgressMaster;
|
||||||
|
import com.ibm.wala.ide.util.ProgressMonitorDelegate;
|
||||||
import com.ibm.wala.ipa.callgraph.CGNode;
|
import com.ibm.wala.ipa.callgraph.CGNode;
|
||||||
import com.ibm.wala.ipa.callgraph.CallGraph;
|
import com.ibm.wala.ipa.callgraph.CallGraph;
|
||||||
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
|
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
|
||||||
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
|
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
|
||||||
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
import com.ibm.wala.ipa.cha.ClassHierarchyException;
|
||||||
import com.ibm.wala.util.ProgressMaster;
|
|
||||||
import com.ibm.wala.util.ProgressMonitorDelegate;
|
|
||||||
import com.ibm.wala.util.io.CommandLine;
|
import com.ibm.wala.util.io.CommandLine;
|
||||||
import com.ibm.wala.util.io.FileProvider;
|
import com.ibm.wala.util.io.FileProvider;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ Bundle-Activator: com.ibm.wala.cast.plugin.AstPlugin
|
||||||
Bundle-Vendor: IBM
|
Bundle-Vendor: IBM
|
||||||
Require-Bundle: com.ibm.wala.core,
|
Require-Bundle: com.ibm.wala.core,
|
||||||
com.ibm.wala.shrike,
|
com.ibm.wala.shrike,
|
||||||
org.eclipse.core.runtime
|
org.eclipse.core.runtime,
|
||||||
|
com.ibm.wala.ide;bundle-version="1.1.3"
|
||||||
Bundle-ActivationPolicy: lazy
|
Bundle-ActivationPolicy: lazy
|
||||||
Export-Package: com.ibm.wala.cast.analysis.typeInference,
|
Export-Package: com.ibm.wala.cast.analysis.typeInference,
|
||||||
com.ibm.wala.cast.ipa.callgraph,
|
com.ibm.wala.cast.ipa.callgraph,
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
package com.ibm.wala.cast.ir.translator;
|
package com.ibm.wala.cast.ir.translator;
|
||||||
|
|
||||||
import com.ibm.wala.cast.tree.CAst;
|
import com.ibm.wala.cast.tree.CAst;
|
||||||
import com.ibm.wala.core.plugin.CorePlugin;
|
import com.ibm.wala.ide.plugin.CorePlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* superclass for CAst parsers / translators making use of native code. performs
|
* superclass for CAst parsers / translators making use of native code. performs
|
||||||
|
|
|
@ -7,7 +7,8 @@ Bundle-Vendor: %providerName
|
||||||
Require-Bundle: com.ibm.wala.shrike,
|
Require-Bundle: com.ibm.wala.shrike,
|
||||||
com.ibm.wala.core,
|
com.ibm.wala.core,
|
||||||
org.eclipse.core.runtime,
|
org.eclipse.core.runtime,
|
||||||
org.junit4;bundle-version="4.3.1"
|
org.junit4;bundle-version="4.3.1",
|
||||||
|
com.ibm.wala.ide;bundle-version="1.1.3"
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Export-Package: com.ibm.wala.core.tests.basic,
|
Export-Package: com.ibm.wala.core.tests.basic,
|
||||||
com.ibm.wala.core.tests.callGraph,
|
com.ibm.wala.core.tests.callGraph,
|
||||||
|
|
|
@ -52,6 +52,8 @@ import com.ibm.wala.demandpa.alg.statemachine.StateMachineFactory;
|
||||||
import com.ibm.wala.demandpa.flowgraph.IFlowLabel;
|
import com.ibm.wala.demandpa.flowgraph.IFlowLabel;
|
||||||
import com.ibm.wala.demandpa.util.MemoryAccessMap;
|
import com.ibm.wala.demandpa.util.MemoryAccessMap;
|
||||||
import com.ibm.wala.demandpa.util.SimpleMemoryAccessMap;
|
import com.ibm.wala.demandpa.util.SimpleMemoryAccessMap;
|
||||||
|
import com.ibm.wala.ide.util.ProgressMaster;
|
||||||
|
import com.ibm.wala.ide.util.ProgressMonitorDelegate;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
import com.ibm.wala.ipa.callgraph.AnalysisCache;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
|
@ -77,8 +79,6 @@ import com.ibm.wala.types.ClassLoaderReference;
|
||||||
import com.ibm.wala.types.TypeReference;
|
import com.ibm.wala.types.TypeReference;
|
||||||
import com.ibm.wala.util.CancelException;
|
import com.ibm.wala.util.CancelException;
|
||||||
import com.ibm.wala.util.Predicate;
|
import com.ibm.wala.util.Predicate;
|
||||||
import com.ibm.wala.util.ProgressMaster;
|
|
||||||
import com.ibm.wala.util.ProgressMonitorDelegate;
|
|
||||||
import com.ibm.wala.util.WalaException;
|
import com.ibm.wala.util.WalaException;
|
||||||
import com.ibm.wala.util.collections.Pair;
|
import com.ibm.wala.util.collections.Pair;
|
||||||
import com.ibm.wala.util.debug.Assertions;
|
import com.ibm.wala.util.debug.Assertions;
|
||||||
|
|
|
@ -4,7 +4,7 @@ Eclipse-LazyStart: true
|
||||||
Bundle-Name: %pluginName
|
Bundle-Name: %pluginName
|
||||||
Bundle-SymbolicName: com.ibm.wala.core
|
Bundle-SymbolicName: com.ibm.wala.core
|
||||||
Bundle-Version: 1.1.3.qualifier
|
Bundle-Version: 1.1.3.qualifier
|
||||||
Bundle-Activator: com.ibm.wala.core.plugin.CorePlugin
|
Bundle-Activator: com.ibm.wala.ide.plugin.CorePlugin
|
||||||
Bundle-Vendor: %providerName
|
Bundle-Vendor: %providerName
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Require-Bundle: com.ibm.wala.shrike,
|
Require-Bundle: com.ibm.wala.shrike,
|
||||||
|
|
|
@ -1,42 +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.classLoader;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A module which is a wrapper around a .java file
|
|
||||||
*/
|
|
||||||
public class EclipseSourceFileModule extends SourceFileModule {
|
|
||||||
|
|
||||||
private IFile f;
|
|
||||||
|
|
||||||
public static EclipseSourceFileModule createEclipseSourceFileModule(IFile f) {
|
|
||||||
if (f == null) {
|
|
||||||
throw new IllegalArgumentException("null f");
|
|
||||||
}
|
|
||||||
return new EclipseSourceFileModule(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
private EclipseSourceFileModule(IFile f) {
|
|
||||||
super(new File(f.getLocation().toOSString()),f.getLocation().lastSegment());
|
|
||||||
this.f = f;
|
|
||||||
}
|
|
||||||
public IFile getIFile() {
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "EclipseSourceFileModule:" + getFile().toString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,10 +17,6 @@ import java.net.URL;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
|
||||||
import org.osgi.framework.Bundle;
|
|
||||||
|
|
||||||
import com.ibm.wala.core.plugin.CorePlugin;
|
|
||||||
import com.ibm.wala.util.WalaException;
|
import com.ibm.wala.util.WalaException;
|
||||||
import com.ibm.wala.util.debug.Assertions;
|
import com.ibm.wala.util.debug.Assertions;
|
||||||
import com.ibm.wala.util.io.FileProvider;
|
import com.ibm.wala.util.io.FileProvider;
|
||||||
|
@ -147,24 +143,4 @@ public final class WalaProperties {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This is fragile. Use with care.
|
|
||||||
* @return a String representing the path to the wala.core plugin installation
|
|
||||||
*/
|
|
||||||
public static String getWalaCorePluginHome() {
|
|
||||||
if (CorePlugin.getDefault() == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String install = Platform.getInstallLocation().getURL().getPath();
|
|
||||||
Bundle b = Platform.getBundle("com.ibm.wala.core");
|
|
||||||
String l = b.getLocation();
|
|
||||||
if (l.startsWith("update@")) {
|
|
||||||
l = l.replace("update@", "");
|
|
||||||
}
|
|
||||||
if (l.startsWith("reference:file:")) {
|
|
||||||
return l.replace("reference:file:","");
|
|
||||||
} else {
|
|
||||||
return install + File.separator + l;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,9 @@ import java.io.InputStreamReader;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Plugin;
|
|
||||||
|
|
||||||
import com.ibm.wala.classLoader.BinaryDirectoryTreeModule;
|
import com.ibm.wala.classLoader.BinaryDirectoryTreeModule;
|
||||||
import com.ibm.wala.classLoader.Module;
|
import com.ibm.wala.classLoader.Module;
|
||||||
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
|
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
|
||||||
import com.ibm.wala.core.plugin.CorePlugin;
|
|
||||||
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
import com.ibm.wala.properties.WalaProperties;
|
import com.ibm.wala.properties.WalaProperties;
|
||||||
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
import com.ibm.wala.shrikeCT.InvalidClassFileException;
|
||||||
|
@ -39,7 +36,7 @@ public class AnalysisScopeReader {
|
||||||
|
|
||||||
private static final ClassLoader MY_CLASSLOADER = AnalysisScopeReader.class.getClassLoader();
|
private static final ClassLoader MY_CLASSLOADER = AnalysisScopeReader.class.getClassLoader();
|
||||||
|
|
||||||
private static final String BASIC_FILE = "primordial.txt";
|
protected static final String BASIC_FILE = "primordial.txt";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read in an analysis scope for a Java application from a text file
|
* read in an analysis scope for a Java application from a text file
|
||||||
|
@ -51,20 +48,15 @@ public class AnalysisScopeReader {
|
||||||
*/
|
*/
|
||||||
public static AnalysisScope readJavaScope(String scopeFileName, File exclusionsFile, ClassLoader javaLoader) throws IOException {
|
public static AnalysisScope readJavaScope(String scopeFileName, File exclusionsFile, ClassLoader javaLoader) throws IOException {
|
||||||
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
|
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
|
||||||
return read(scope, scopeFileName, exclusionsFile, javaLoader, CorePlugin.getDefault());
|
return read(scope, scopeFileName, exclusionsFile, javaLoader, new FileProvider());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AnalysisScope readJavaScope(String scopeFileName, File exclusionsFile, ClassLoader javaLoader, Plugin plugIn) throws IOException {
|
|
||||||
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
|
|
||||||
return read(scope, scopeFileName, exclusionsFile, javaLoader, plugIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AnalysisScope read(AnalysisScope scope, String scopeFileName, File exclusionsFile, ClassLoader javaLoader,
|
protected static AnalysisScope read(AnalysisScope scope, String scopeFileName, File exclusionsFile, ClassLoader javaLoader,
|
||||||
Plugin plugIn) throws IOException {
|
FileProvider fp) throws IOException {
|
||||||
BufferedReader r = null;
|
BufferedReader r = null;
|
||||||
try {
|
try {
|
||||||
File scopeFile = (plugIn == null) ? (new FileProvider()).getFile(scopeFileName, javaLoader) : (new FileProvider()).getFileFromPlugin(plugIn,
|
File scopeFile = fp.getFile(scopeFileName, javaLoader);
|
||||||
scopeFileName);
|
|
||||||
assert scopeFile.exists();
|
assert scopeFile.exists();
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
|
@ -147,12 +139,10 @@ public class AnalysisScopeReader {
|
||||||
* @throws IllegalStateException if there are problmes reading wala properties
|
* @throws IllegalStateException if there are problmes reading wala properties
|
||||||
*/
|
*/
|
||||||
public static AnalysisScope makePrimordialScope(File exclusionsFile) throws IOException {
|
public static AnalysisScope makePrimordialScope(File exclusionsFile) throws IOException {
|
||||||
return readJavaScope(BASIC_FILE, exclusionsFile, MY_CLASSLOADER, CorePlugin.getDefault());
|
return readJavaScope(BASIC_FILE, exclusionsFile, MY_CLASSLOADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AnalysisScope makePrimordialScope(File exclusionsFile, Plugin plugIn) throws IOException {
|
|
||||||
return readJavaScope(BASIC_FILE, exclusionsFile, MY_CLASSLOADER, plugIn);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param classPath class path to analyze, delimited by File.pathSeparator
|
* @param classPath class path to analyze, delimited by File.pathSeparator
|
||||||
|
@ -161,20 +151,10 @@ public class AnalysisScopeReader {
|
||||||
* @throws IllegalStateException if there are problems reading wala properties
|
* @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) throws IOException {
|
||||||
return makeJavaBinaryAnalysisScope(classPath, exclusionsFile, CorePlugin.getDefault());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param classPath class path to analyze, delimited by File.pathSeparator
|
|
||||||
* @param exclusionsFile file holding class hierarchy exclusions. may be null
|
|
||||||
* @throws IOException
|
|
||||||
* @throws IllegalStateException if there are problems reading wala properties
|
|
||||||
*/
|
|
||||||
public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, File exclusionsFile, Plugin plugIn) throws IOException {
|
|
||||||
if (classPath == null) {
|
if (classPath == null) {
|
||||||
throw new IllegalArgumentException("classPath null");
|
throw new IllegalArgumentException("classPath null");
|
||||||
}
|
}
|
||||||
AnalysisScope scope = makePrimordialScope(exclusionsFile, plugIn);
|
AnalysisScope scope = makePrimordialScope(exclusionsFile);
|
||||||
ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
|
ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
|
||||||
|
|
||||||
addClassPathToScope(classPath, scope, loader);
|
addClassPathToScope(classPath, scope, loader);
|
||||||
|
|
|
@ -14,68 +14,22 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.JarURLConnection;
|
import java.net.JarURLConnection;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.zip.ZipException;
|
import java.util.zip.ZipException;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.FileLocator;
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
|
||||||
import org.eclipse.core.runtime.Plugin;
|
|
||||||
|
|
||||||
import com.ibm.wala.classLoader.JarFileModule;
|
import com.ibm.wala.classLoader.JarFileModule;
|
||||||
import com.ibm.wala.classLoader.Module;
|
import com.ibm.wala.classLoader.Module;
|
||||||
import com.ibm.wala.classLoader.NestedJarFileModule;
|
import com.ibm.wala.classLoader.NestedJarFileModule;
|
||||||
import com.ibm.wala.core.plugin.CorePlugin;
|
|
||||||
import com.ibm.wala.util.debug.Assertions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides files that are packaged with this plug-in
|
* This class provides files that are packaged with this plug-in
|
||||||
*/
|
*/
|
||||||
public class FileProvider {
|
public class FileProvider {
|
||||||
|
|
||||||
/**
|
|
||||||
* This class uses reflection to access classes and methods that are only
|
|
||||||
* available when Eclipse is running as an IDE environment. The choice to use
|
|
||||||
* reflection is related to builds: with this design the build doesn't need to
|
|
||||||
* provide IDE bundles during compilation and hence can spot invalid uses of
|
|
||||||
* such classes through this bundle.
|
|
||||||
*
|
|
||||||
* Because of this class, this bundle must OPTIONALY require
|
|
||||||
* 'org.eclipse.core.resources'.
|
|
||||||
*/
|
|
||||||
private static final class EclipseUtil {
|
|
||||||
private static Object workspaceRoot = null;
|
|
||||||
private static Method workspaceRoot_getFile = null;
|
|
||||||
|
|
||||||
public static Module getJarFileModule(String fileName, ClassLoader loader) {
|
|
||||||
// Using reflection to enable this code to be built without the
|
|
||||||
// org.eclipse.core.resources bundle
|
|
||||||
//
|
|
||||||
try {
|
|
||||||
if (workspaceRoot_getFile == null) {
|
|
||||||
Class<?> cls = Class.forName("org.eclipse.core.resources.ResourcesPlugin");
|
|
||||||
Method getWorkspaceMethod = cls.getDeclaredMethod("getWorkspace");
|
|
||||||
Object workspace = getWorkspaceMethod.invoke(null);
|
|
||||||
Method getRoot = workspace.getClass().getDeclaredMethod("getRoot");
|
|
||||||
workspaceRoot = getRoot.invoke(workspace);
|
|
||||||
workspaceRoot_getFile = workspaceRoot.getClass().getMethod("getFile", IPath.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
IPath path = new Path(fileName);
|
|
||||||
if (workspaceRoot_getFile.invoke(workspaceRoot, path) != null) {
|
|
||||||
return new JarFileModule(new JarFile(fileName, false));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final static int DEBUG_LEVEL = 0;
|
private final static int DEBUG_LEVEL = 0;
|
||||||
|
|
||||||
|
@ -89,15 +43,7 @@ public class FileProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Module getJarFileModule(String fileName, ClassLoader loader) throws IOException {
|
public Module getJarFileModule(String fileName, ClassLoader loader) throws IOException {
|
||||||
if (CorePlugin.getDefault() == null) {
|
return getJarFileFromClassLoader(fileName, loader);
|
||||||
return getJarFileFromClassLoader(fileName, loader);
|
|
||||||
} else if (CorePlugin.IS_RESOURCES_BUNDLE_AVAILABLE) {
|
|
||||||
Module module = EclipseUtil.getJarFileModule(fileName, loader);
|
|
||||||
if (module != null) {
|
|
||||||
return module;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getFromPlugin(CorePlugin.getDefault(), fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getResource(String fileName) throws IOException {
|
public URL getResource(String fileName) throws IOException {
|
||||||
|
@ -111,11 +57,10 @@ public class FileProvider {
|
||||||
if (fileName == null) {
|
if (fileName == null) {
|
||||||
throw new IllegalArgumentException("null fileName");
|
throw new IllegalArgumentException("null fileName");
|
||||||
}
|
}
|
||||||
if (CorePlugin.getDefault() == null && loader == null) {
|
if (loader == null) {
|
||||||
throw new IllegalArgumentException("null loader");
|
throw new IllegalArgumentException("null loader");
|
||||||
}
|
}
|
||||||
return (CorePlugin.getDefault() == null) ? loader.getResource(fileName) : FileLocator.find(CorePlugin.getDefault().getBundle(),
|
return loader.getResource(fileName);
|
||||||
new Path(fileName), null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile(String fileName) throws IOException {
|
public File getFile(String fileName) throws IOException {
|
||||||
|
@ -126,111 +71,7 @@ public class FileProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFile(String fileName, ClassLoader loader) throws IOException {
|
public File getFile(String fileName, ClassLoader loader) throws IOException {
|
||||||
return (CorePlugin.getDefault() == null) ? getFileFromClassLoader(fileName, loader) : getFileFromPlugin(
|
return getFileFromClassLoader(fileName, loader);
|
||||||
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
|
|
||||||
*/
|
|
||||||
public File getFileFromPlugin(Plugin p, String fileName) throws IOException {
|
|
||||||
|
|
||||||
if (p == null) {
|
|
||||||
throw new IllegalArgumentException("p is null");
|
|
||||||
}
|
|
||||||
if (fileName == null) {
|
|
||||||
throw new IllegalArgumentException("null fileName");
|
|
||||||
}
|
|
||||||
URL url = getFileURLFromPlugin(p, fileName);
|
|
||||||
if (url == null) {
|
|
||||||
throw new FileNotFoundException(fileName);
|
|
||||||
}
|
|
||||||
return new File(filePathFromURL(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param fileName
|
|
||||||
* @return the jar file packaged with this plug-in of the given name, or null
|
|
||||||
* if not found.
|
|
||||||
*/
|
|
||||||
private JarFileModule getFromPlugin(Plugin p, String fileName) throws IOException {
|
|
||||||
URL url = getFileURLFromPlugin(p, fileName);
|
|
||||||
return (url == null) ? null : new JarFileModule(new JarFile(filePathFromURL(url)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a file URL for a file from a plugin
|
|
||||||
*
|
|
||||||
* @param fileName
|
|
||||||
* the file name
|
|
||||||
* @return the URL, or <code>null</code> if the file is not found
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
private URL getFileURLFromPlugin(Plugin p, String fileName) throws IOException {
|
|
||||||
try {
|
|
||||||
URL url = FileLocator.find(p.getBundle(), new Path(fileName), null);
|
|
||||||
if (url == null) {
|
|
||||||
// try lib/fileName
|
|
||||||
String libFileName = "lib/" + fileName;
|
|
||||||
url = FileLocator.find(p.getBundle(), new Path(libFileName), null);
|
|
||||||
if (url == null) {
|
|
||||||
// try bin/fileName
|
|
||||||
String binFileName = "bin/" + fileName;
|
|
||||||
url = FileLocator.find(p.getBundle(), new Path(binFileName), null);
|
|
||||||
if (url == null) {
|
|
||||||
// try it as an absolute path?
|
|
||||||
File f = new File(fileName);
|
|
||||||
if (!f.exists()) {
|
|
||||||
// give up
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
url = f.toURI().toURL();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
url = FileLocator.toFileURL(url);
|
|
||||||
url = fixupFileURLSpaces(url);
|
|
||||||
return url;
|
|
||||||
} catch (ExceptionInInitializerError e) {
|
|
||||||
throw new IOException("failure to get file URL for " + fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* escape spaces in a URL, primarily to work around a bug in
|
|
||||||
* {@link File#toURL()}
|
|
||||||
*
|
|
||||||
* @param url
|
|
||||||
* @return an escaped version of the URL
|
|
||||||
*/
|
|
||||||
private URL fixupFileURLSpaces(URL url) {
|
|
||||||
String urlString = url.toExternalForm();
|
|
||||||
StringBuffer fixedUpUrl = new StringBuffer();
|
|
||||||
int lastIndex = 0;
|
|
||||||
while (true) {
|
|
||||||
int spaceIndex = urlString.indexOf(' ', lastIndex);
|
|
||||||
|
|
||||||
if (spaceIndex < 0) {
|
|
||||||
fixedUpUrl.append(urlString.substring(lastIndex));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fixedUpUrl.append(urlString.substring(lastIndex, spaceIndex));
|
|
||||||
fixedUpUrl.append("%20");
|
|
||||||
lastIndex = spaceIndex + 1;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return new URL(fixedUpUrl.toString());
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Assertions.UNREACHABLE();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,5 +18,6 @@ Bundle-ActivationPolicy: lazy
|
||||||
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
Bundle-RequiredExecutionEnvironment: J2SE-1.5
|
||||||
Export-Package: com.ibm.wala.ide,
|
Export-Package: com.ibm.wala.ide,
|
||||||
com.ibm.wala.ide.classloader,
|
com.ibm.wala.ide.classloader,
|
||||||
|
com.ibm.wala.ide.plugin,
|
||||||
com.ibm.wala.ide.ui,
|
com.ibm.wala.ide.ui,
|
||||||
com.ibm.wala.ide.util
|
com.ibm.wala.ide.util
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.ibm.wala.core.plugin;
|
package com.ibm.wala.ide.plugin;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.core.runtime.Plugin;
|
import org.eclipse.core.runtime.Plugin;
|
|
@ -0,0 +1,67 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008 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.ide.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.Plugin;
|
||||||
|
|
||||||
|
import com.ibm.wala.ide.plugin.CorePlugin;
|
||||||
|
import com.ibm.wala.ipa.callgraph.AnalysisScope;
|
||||||
|
import com.ibm.wala.types.ClassLoaderReference;
|
||||||
|
import com.ibm.wala.util.config.AnalysisScopeReader;
|
||||||
|
|
||||||
|
public class EclipseAnalysisScopeReader extends AnalysisScopeReader {
|
||||||
|
|
||||||
|
public static AnalysisScope readJavaScopeFromPlugin(String scopeFileName, File exclusionsFile, ClassLoader javaLoader) throws IOException {
|
||||||
|
return readJavaScopeFromPlugin(scopeFileName, exclusionsFile, javaLoader, CorePlugin.getDefault());
|
||||||
|
}
|
||||||
|
public static AnalysisScope readJavaScopeFromPlugin(String scopeFileName, File exclusionsFile, ClassLoader javaLoader, Plugin plugIn) throws IOException {
|
||||||
|
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
|
||||||
|
return read(scope, scopeFileName, exclusionsFile, javaLoader, new EclipseFileProvider(plugIn));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AnalysisScope makePrimordialScopeFromPlugin(File exclusionsFile) throws IOException {
|
||||||
|
return makePrimordialScopeFromPlugin(exclusionsFile, CorePlugin.getDefault());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param exclusionsFile file holding class hierarchy exclusions. may be null
|
||||||
|
* @throws IOException
|
||||||
|
* @throws IllegalStateException if there are problmes reading wala properties
|
||||||
|
*/
|
||||||
|
public static AnalysisScope makePrimordialScopeFromPlugin(File exclusionsFile, Plugin plugIn) throws IOException {
|
||||||
|
return read(AnalysisScope.createJavaAnalysisScope(), BASIC_FILE, exclusionsFile,
|
||||||
|
EclipseAnalysisScopeReader.class.getClassLoader(), new EclipseFileProvider(plugIn));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AnalysisScope makeJavaBinaryAnalysisScopeFromPlugin(String classPath, File exclusionsFile) throws IOException {
|
||||||
|
return makeJavaBinaryAnalysisScopeFromPlugin(classPath, exclusionsFile, CorePlugin.getDefault());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param classPath class path to analyze, delimited by File.pathSeparator
|
||||||
|
* @param exclusionsFile file holding class hierarchy exclusions. may be null
|
||||||
|
* @throws IOException
|
||||||
|
* @throws IllegalStateException if there are problems reading wala properties
|
||||||
|
*/
|
||||||
|
public static AnalysisScope makeJavaBinaryAnalysisScopeFromPlugin(String classPath, File exclusionsFile, Plugin plugIn) throws IOException {
|
||||||
|
if (classPath == null) {
|
||||||
|
throw new IllegalArgumentException("classPath null");
|
||||||
|
}
|
||||||
|
AnalysisScope scope = makePrimordialScopeFromPlugin(exclusionsFile, plugIn);
|
||||||
|
ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION);
|
||||||
|
|
||||||
|
addClassPathToScope(classPath, scope, loader);
|
||||||
|
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,245 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2008 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.ide.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.FileLocator;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.Plugin;
|
||||||
|
import org.osgi.framework.Bundle;
|
||||||
|
|
||||||
|
import com.ibm.wala.classLoader.JarFileModule;
|
||||||
|
import com.ibm.wala.classLoader.Module;
|
||||||
|
import com.ibm.wala.ide.plugin.CorePlugin;
|
||||||
|
import com.ibm.wala.util.debug.Assertions;
|
||||||
|
import com.ibm.wala.util.io.FileProvider;
|
||||||
|
|
||||||
|
public class EclipseFileProvider extends FileProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the plug-in to use. If <code>null</code>, {@link CorePlugin#getDefault()} is used.
|
||||||
|
*/
|
||||||
|
private final Plugin plugIn;
|
||||||
|
|
||||||
|
public EclipseFileProvider() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EclipseFileProvider(Plugin plugIn) {
|
||||||
|
this.plugIn = plugIn;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* This class uses reflection to access classes and methods that are only
|
||||||
|
* available when Eclipse is running as an IDE environment. The choice to use
|
||||||
|
* reflection is related to builds: with this design the build doesn't need to
|
||||||
|
* provide IDE bundles during compilation and hence can spot invalid uses of
|
||||||
|
* such classes through this bundle.
|
||||||
|
*
|
||||||
|
* Because of this class, this bundle must OPTIONALY require
|
||||||
|
* 'org.eclipse.core.resources'.
|
||||||
|
*/
|
||||||
|
private static final class EclipseUtil {
|
||||||
|
private static Object workspaceRoot = null;
|
||||||
|
private static Method workspaceRoot_getFile = null;
|
||||||
|
|
||||||
|
public static Module getJarFileModule(String fileName) {
|
||||||
|
// Using reflection to enable this code to be built without the
|
||||||
|
// org.eclipse.core.resources bundle
|
||||||
|
//
|
||||||
|
try {
|
||||||
|
if (workspaceRoot_getFile == null) {
|
||||||
|
Class<?> cls = Class.forName("org.eclipse.core.resources.ResourcesPlugin");
|
||||||
|
Method getWorkspaceMethod = cls.getDeclaredMethod("getWorkspace");
|
||||||
|
Object workspace = getWorkspaceMethod.invoke(null);
|
||||||
|
Method getRoot = workspace.getClass().getDeclaredMethod("getRoot");
|
||||||
|
workspaceRoot = getRoot.invoke(workspace);
|
||||||
|
workspaceRoot_getFile = workspaceRoot.getClass().getMethod("getFile", IPath.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
IPath path = new Path(fileName);
|
||||||
|
if (workspaceRoot_getFile.invoke(workspaceRoot, path) != null) {
|
||||||
|
return new JarFileModule(new JarFile(fileName, false));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Module getJarFileModule(String fileName, ClassLoader loader) throws IOException {
|
||||||
|
if (CorePlugin.getDefault() == null) {
|
||||||
|
return getJarFileFromClassLoader(fileName, loader);
|
||||||
|
} else if (plugIn != null) {
|
||||||
|
return getFromPlugin(plugIn, fileName);
|
||||||
|
} else if (CorePlugin.IS_RESOURCES_BUNDLE_AVAILABLE) {
|
||||||
|
Module module = EclipseUtil.getJarFileModule(fileName);
|
||||||
|
if (module != null) {
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getFromPlugin(CorePlugin.getDefault(), fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fileName
|
||||||
|
* @return the jar file packaged with this plug-in of the given name, or null
|
||||||
|
* if not found.
|
||||||
|
*/
|
||||||
|
private JarFileModule getFromPlugin(Plugin p, String fileName) throws IOException {
|
||||||
|
URL url = getFileURLFromPlugin(p, fileName);
|
||||||
|
return (url == null) ? null : new JarFileModule(new JarFile(filePathFromURL(url)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a file URL for a file from a plugin
|
||||||
|
*
|
||||||
|
* @param fileName
|
||||||
|
* the file name
|
||||||
|
* @return the URL, or <code>null</code> if the file is not found
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private URL getFileURLFromPlugin(Plugin p, String fileName) throws IOException {
|
||||||
|
try {
|
||||||
|
URL url = FileLocator.find(p.getBundle(), new Path(fileName), null);
|
||||||
|
if (url == null) {
|
||||||
|
// try lib/fileName
|
||||||
|
String libFileName = "lib/" + fileName;
|
||||||
|
url = FileLocator.find(p.getBundle(), new Path(libFileName), null);
|
||||||
|
if (url == null) {
|
||||||
|
// try bin/fileName
|
||||||
|
String binFileName = "bin/" + fileName;
|
||||||
|
url = FileLocator.find(p.getBundle(), new Path(binFileName), null);
|
||||||
|
if (url == null) {
|
||||||
|
// try it as an absolute path?
|
||||||
|
File f = new File(fileName);
|
||||||
|
if (!f.exists()) {
|
||||||
|
// give up
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
url = f.toURI().toURL();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
url = FileLocator.toFileURL(url);
|
||||||
|
url = fixupFileURLSpaces(url);
|
||||||
|
return url;
|
||||||
|
} catch (ExceptionInInitializerError e) {
|
||||||
|
throw new IOException("failure to get file URL for " + fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* escape spaces in a URL, primarily to work around a bug in
|
||||||
|
* {@link File#toURL()}
|
||||||
|
*
|
||||||
|
* @param url
|
||||||
|
* @return an escaped version of the URL
|
||||||
|
*/
|
||||||
|
private URL fixupFileURLSpaces(URL url) {
|
||||||
|
String urlString = url.toExternalForm();
|
||||||
|
StringBuffer fixedUpUrl = new StringBuffer();
|
||||||
|
int lastIndex = 0;
|
||||||
|
while (true) {
|
||||||
|
int spaceIndex = urlString.indexOf(' ', lastIndex);
|
||||||
|
|
||||||
|
if (spaceIndex < 0) {
|
||||||
|
fixedUpUrl.append(urlString.substring(lastIndex));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fixedUpUrl.append(urlString.substring(lastIndex, spaceIndex));
|
||||||
|
fixedUpUrl.append("%20");
|
||||||
|
lastIndex = spaceIndex + 1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new URL(fixedUpUrl.toString());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Assertions.UNREACHABLE();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL getResource(String fileName, ClassLoader loader) throws IOException {
|
||||||
|
if (fileName == null) {
|
||||||
|
throw new IllegalArgumentException("null fileName");
|
||||||
|
}
|
||||||
|
Plugin p = plugIn == null ? CorePlugin.getDefault() : plugIn;
|
||||||
|
if (p == null && loader == null) {
|
||||||
|
throw new IllegalArgumentException("null loader");
|
||||||
|
}
|
||||||
|
return (p == null) ? loader.getResource(fileName) : FileLocator.find(p.getBundle(),
|
||||||
|
new Path(fileName), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getFile(String fileName, ClassLoader loader) throws IOException {
|
||||||
|
Plugin p = plugIn == null ? CorePlugin.getDefault() : plugIn;
|
||||||
|
return (p == null) ? getFileFromClassLoader(fileName, loader) : getFileFromPlugin(
|
||||||
|
p, 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
|
||||||
|
*/
|
||||||
|
public File getFileFromPlugin(Plugin p, String fileName) throws IOException {
|
||||||
|
|
||||||
|
if (p == null) {
|
||||||
|
throw new IllegalArgumentException("p is null");
|
||||||
|
}
|
||||||
|
if (fileName == null) {
|
||||||
|
throw new IllegalArgumentException("null fileName");
|
||||||
|
}
|
||||||
|
URL url = getFileURLFromPlugin(p, fileName);
|
||||||
|
if (url == null) {
|
||||||
|
throw new FileNotFoundException(fileName);
|
||||||
|
}
|
||||||
|
return new File(filePathFromURL(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is fragile. Use with care.
|
||||||
|
* @return a String representing the path to the wala.core plugin installation
|
||||||
|
*/
|
||||||
|
public static String getWalaCorePluginHome() {
|
||||||
|
if (CorePlugin.getDefault() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String install = Platform.getInstallLocation().getURL().getPath();
|
||||||
|
Bundle b = Platform.getBundle("com.ibm.wala.core");
|
||||||
|
String l = b.getLocation();
|
||||||
|
if (l.startsWith("update@")) {
|
||||||
|
l = l.replace("update@", "");
|
||||||
|
}
|
||||||
|
if (l.startsWith("reference:file:")) {
|
||||||
|
return l.replace("reference:file:","");
|
||||||
|
} else {
|
||||||
|
return install + File.separator + l;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,7 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.ibm.wala.util;
|
package com.ibm.wala.ide.util;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package com.ibm.wala.util;
|
package com.ibm.wala.ide.util;
|
||||||
|
|
||||||
|
import com.ibm.wala.util.MonitorUtil;
|
||||||
import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
|
import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
Loading…
Reference in New Issue