blob: c352d7e5b04e2d21fbca59ee7c1040c5341c9c51 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* 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 org.eclipse.jdt.ui.tests.refactoring.infra;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IPluginDescriptor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.ResourcesPlugin;
public class RefactoringTestPlugin extends Plugin {
private static RefactoringTestPlugin fgDefault;
public RefactoringTestPlugin(IPluginDescriptor descriptor) {
super(descriptor);
fgDefault= this;
}
public static RefactoringTestPlugin getDefault() {
return fgDefault;
}
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
public static void enableAutobuild(boolean enable) throws CoreException {
// disable auto build
IWorkspace workspace= getWorkspace();
IWorkspaceDescription desc= workspace.getDescription();
desc.setAutoBuilding(enable);
workspace.setDescription(desc);
}
public InputStream getTestResourceStream(String fileName) throws IOException {
IPath path= new Path("resources").append(fileName);
URL url= new URL(getDescriptor().getInstallURL(), path.toString());
return url.openStream();
}
public File getFileInPlugin(IPath path) {
try {
URL installURL= new URL(getDescriptor().getInstallURL(), path.toString());
URL localURL= Platform.asLocalURL(installURL);
return new File(localURL.getFile());
} catch (IOException e) {
return null;
}
}
}