blob: 3798ccb924118b19bab41b9dab5e4a2380be1a6e [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 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.jst.jsp.tests.encoding;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
/**
* The main plugin class to be used in the desktop.
*/
public class JSPEncodingTestsPlugin extends Plugin {
// The shared instance.
private static JSPEncodingTestsPlugin plugin;
public static List getAllTestFiles(String topDirName) {
List result = null;
URL installURL = getInstallLocation();
// String scheme = installURL.getProtocol();
String path = installURL.getPath();
String location = path + topDirName;
File topDir = new File(location);
if (!topDir.isDirectory()) {
throw new IllegalArgumentException(topDirName + " is not a directory");
}
else {
result = getFilesInDir(topDir);
}
return result;
}
/**
* Returns the shared instance.
*/
public static JSPEncodingTestsPlugin getDefault() {
return plugin;
}
private static List getFilesInDir(File topDir) {
List files = new ArrayList();
File[] topFiles = topDir.listFiles();
for (int i = 0; i < topFiles.length; i++) {
File file = topFiles[i];
if (file.isFile()) {
files.add(file);
}
else if (file.isDirectory() && !file.getName().endsWith("CVS")) {
List innerFiles = getFilesInDir(file);
files.addAll(innerFiles);
}
}
return files;
}
public static URL getInstallLocation() {
URL installLocation = Platform.getBundle("org.eclipse.jst.jsp.tests.encoding").getEntry("/");
URL resolvedLocation = null;
try {
resolvedLocation = Platform.resolve(installLocation);
}
catch (IOException e) {
// impossible
throw new Error(e);
}
return resolvedLocation;
}
/**
* Returns the string from the plugin's resource bundle, or 'key' if not
* found.
*/
public static String getResourceString(String key) {
ResourceBundle bundle = JSPEncodingTestsPlugin.getDefault().getResourceBundle();
try {
return (bundle != null ? bundle.getString(key) : key);
}
catch (MissingResourceException e) {
return key;
}
}
public static File getTestFile(String filepath) {
URL installURL = getInstallLocation();
// String scheme = installURL.getProtocol();
String path = installURL.getPath();
String location = path + filepath;
File result = new File(location);
return result;
}
public static Reader getTestReader(String filepath) throws FileNotFoundException {
URL installURL = getInstallLocation();
// String scheme = installURL.getProtocol();
String path = installURL.getPath();
String location = path + filepath;
Reader result = new FileReader(location);
return result;
}
/**
* Returns the workspace instance.
*/
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
/**
* The constructor.
*/
public JSPEncodingTestsPlugin() {
super();
plugin = this;
}
/**
* Returns the plugin's resource bundle,
*/
public ResourceBundle getResourceBundle() {
return null;
}
}