remove dependence from cast.java.test to eclipse.tests

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@2850 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
dolby-oss 2008-05-27 13:29:35 +00:00
parent 78ea9c621f
commit ed8a7159e6
3 changed files with 155 additions and 3 deletions

View File

@ -10,7 +10,6 @@ Require-Bundle: com.ibm.wala.core.tests,
com.ibm.wala.cast,
com.ibm.wala.core,
org.eclipse.core.runtime,
org.junit4,
com.ibm.wala.eclipse.tests
org.junit4
Eclipse-LazyStart: true
Export-Package: com.ibm.wala.cast.java.test

View File

@ -47,7 +47,7 @@ import com.ibm.wala.classLoader.JarFileModule;
import com.ibm.wala.classLoader.SourceDirectoryTreeModule;
import com.ibm.wala.classLoader.SourceFileModule;
import com.ibm.wala.core.tests.util.WalaTestCase;
import com.ibm.wala.eclipse.tests.EclipseTestUtil;
import com.ibm.wala.core.tests.util.EclipseTestUtil;
import com.ibm.wala.eclipse.util.EclipseProjectPath;
import com.ibm.wala.ipa.callgraph.CGNode;
import com.ibm.wala.ipa.callgraph.CallGraph;

View File

@ -0,0 +1,153 @@
/*******************************************************************************
* 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.core.tests.util;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.List;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jdt.core.IJavaModel;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
import org.osgi.framework.Bundle;
public class EclipseTestUtil {
public static void importZippedProject(Plugin plugin, String zipFileName) {
ZipFile zipFile = getZipFile(plugin, zipFileName);
ZipFileStructureProvider zp = new ZipFileStructureProvider(zipFile);
List children = zp.getChildren(zp.getRoot());
Object element = children.get(0);
String projectName = zp.getLabel(element);
createOpenProject(projectName);
importZipfile(zipFile,zp);
}
public static void createOpenProject(String projectName) {
IWorkspaceRoot root = getWorkspace();
IProject project = root.getProject(projectName);
try {
project.create(null);
project.open(null);
} catch (CoreException e) {
e.printStackTrace();
}
}
public static void destroyProject(String projectName) {
IWorkspaceRoot root = getWorkspace();
IProject project = root.getProject(projectName);
try {
project.delete(true, null);
} catch (CoreException e) {
e.printStackTrace();
}
}
protected static void importZipfile(ZipFile sourceZip, ZipFileStructureProvider provider) {
IPath containerPath = getWorkspacePath();
ImportOperation importOp = new ImportOperation(containerPath,provider.getRoot(), provider,
new IOverwriteQuery() {
public String queryOverwrite(String pathString) {
return IOverwriteQuery.ALL;
}
}
);
importOp.setCreateContainerStructure(true);
importOp.setOverwriteResources(true);
try {
importOp.run(new NullProgressMonitor());
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
sourceZip.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static File getTestDataFile(Plugin plugin, String filename) {
Bundle bundle = plugin.getBundle();
IPath path = new Path("testdata").append(filename);
URL url = FileLocator.find(bundle, path, null);
assert url != null;
try {
URL fileURL = FileLocator.toFileURL(url);
File file = new File(fileURL.getPath());
return file;
} catch (IOException e) {
reportException(e);
}
return null;
}
public static ZipFile getZipFile(Plugin plugin, String testArchive) {
File file = getTestDataFile(plugin, testArchive);
if(file != null) {
try {
return new ZipFile(file);
} catch (ZipException e) {
reportException(e);
} catch (IOException e) {
reportException(e);
}
}
return null;
}
public static IWorkspaceRoot getWorkspace() {
return ResourcesPlugin.getWorkspace().getRoot();
}
private static IPath getWorkspacePath() {
return ResourcesPlugin.getWorkspace().getRoot().getFullPath();
}
private static void reportException(Exception e) {
// TODO: add to appropriate error log? Report differently ??
e.printStackTrace();
}
public static IJavaProject getNamedProject(String projectName) {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IJavaModel javaModel = JavaCore.create(workspaceRoot);
IJavaProject helloWorldProject = javaModel.getJavaProject(projectName);
return helloWorldProject;
}
}