本文整理匯總了Java中org.eclipse.core.runtime.FileLocator.toFileURL方法的典型用法代碼示例。如果您正苦於以下問題:Java FileLocator.toFileURL方法的具體用法?Java FileLocator.toFileURL怎麽用?Java FileLocator.toFileURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.core.runtime.FileLocator
的用法示例。
在下文中一共展示了FileLocator.toFileURL方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateClassPath
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
private String [] updateClassPath (ILaunchConfiguration configuration) throws CoreException {
URL resource = this.getClass().getResource(GW4ELaunchConfigurationDelegate.class.getSimpleName() + ".class");
String jarpath = GW4ELaunchConfigurationDelegate.class.getProtectionDomain().getCodeSource().getLocation().getPath ();
try {
resource = FileLocator.toFileURL(resource);
} catch (IOException e) {
ResourceManager.logException(e);
}
String root = resource.toString();
if (root.startsWith("jar:")) {
String vals[] = root.split("/");
for (String val: vals) {
if (val.contains("!")) {
root = val.substring(0, val.length() - 1);
}
}
} else {
int pos = root.indexOf((GW4ELaunchConfigurationDelegate.class.getName() ).replaceAll("\\.", "/"));
root = root.substring(0,pos);
}
String[] defaultCp = getClasspath(configuration);
String[] extendedCp = new String[defaultCp.length+2];
System.arraycopy(defaultCp, 0, extendedCp, 0, defaultCp.length);
extendedCp[extendedCp.length-1] = normalizePath(root);
extendedCp[extendedCp.length-2] = normalizePath(jarpath);
return extendedCp;
}
示例2: extractProject
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
/**
* <p>
* Unzip the project archive to the specified folder
* </p>
*
* @param projectFolderFile The folder where to unzip the project archive
* @param monitor Monitor to display progress and/or cancel operation
*
* @throws IOException
*
* @throws InterruptedException
*
* @throws FileNotFoundException
*/
private void extractProject(File projectFolderFile, URL url, IProgressMonitor monitor) throws FileNotFoundException, IOException, InterruptedException {
// Get project archive
URL urlZipLocal = FileLocator.toFileURL(url);
// Walk each element and unzip
ZipFile zipFile = new ZipFile(urlZipLocal.getPath());
try {
// Allow for a hundred work units
monitor.beginTask("Extracting Project", zipFile.size());
unzip(zipFile, projectFolderFile, monitor);
} finally {
zipFile.close();
monitor.done();
}
}
示例3: loadProperties
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
/**
* Load properties.
*/
private static void loadProperties() {
URL pluginUrl = null;
String absolutePath;
String completePath;
BufferedInputStream stream;
try {
pluginUrl = FileLocator.toFileURL(Activator.getInstallURL());
absolutePath = new File(pluginUrl.getPath()).getAbsolutePath();
completePath = absolutePath + SEPARATOR + FILE_NAME;
stream = new BufferedInputStream(new FileInputStream(completePath));
PROPERTIES.load(stream);
stream.close();
} catch (IOException e) {
throw new WrappedException("Error during loading properties", e);
}
}
示例4: loadFromClasspath
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
/**
* Tries to load the given {@code path} from the classpath. Throws an exception
* containing the given {@code description} if this fails.
*
* @param path The path to retrieve.
* @param description Description of what is expected to be found at {@code path}.
* @return The retrieved path.
* @throws IOException If retrieving the {@code path} is not possible.
*/
private Path loadFromClasspath(final String path, final String description) throws IOException {
final URL classpathUrl = MeasurementFileManager.class.getResource(path);
if (classpathUrl == null) {
throw new FileNotFoundException(String.format("Cannot find the %s!", description));
}
final URL fileUrl = FileLocator.toFileURL(classpathUrl);
try {
// The URL to Path conversion has to be done like this, to make it work with
// Linux and Windows style paths.
final URI urii = new URI(fileUrl.getProtocol(), fileUrl.getPath(), null);
final Path returnValue = Paths.get(urii).toAbsolutePath();
return returnValue;
} catch (final URISyntaxException uriSyntaxException) {
throw new FileNotFoundException(uriSyntaxException.getMessage());
}
}
示例5: getScriptsHome
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
public static String getScriptsHome() throws IOException, URISyntaxException {
File scriptsHome;
try {
URL url = new URL("platform:/plugin/" + PLUGIN_ID + "/scripts");
URL fileURL = FileLocator.toFileURL(url);
scriptsHome = new File(URIUtil.toURI(fileURL));
} catch (MalformedURLException e) {
// Running without OSGi, make a guess the scripts are relative to the local directory
scriptsHome = new File("scripts/");
}
if (!scriptsHome.exists()) {
throw new IOException("Failed to find " + PLUGIN_ID + "/scripts, expected it here: " + scriptsHome);
}
return scriptsHome.toString();
}
示例6: getSciSoftPyHome
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
public static String getSciSoftPyHome() throws IOException, URISyntaxException {
File scriptsHome;
try {
URL url = new URL("platform:/plugin/org.eclipse.triquetrum.python.service/scripts");
URL fileURL = FileLocator.toFileURL(url);
scriptsHome = new File(URIUtil.toURI(fileURL));
} catch (MalformedURLException e) {
// Running without OSGi, make a guess the scripts are relative to the local directory
scriptsHome = new File("../org.eclipse.triquetrum.python.service/scripts/");
}
if (!scriptsHome.exists()) {
throw new IOException("Failed to find org.eclipse.triquetrum.python.service/scripts, expected it here: " + scriptsHome);
}
return scriptsHome.toString();
}
示例7: execute
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
@Execute
public void execute() {
Bundle b = Platform.getBundle("org.bbaw.bts.core.commons.corpus.help");
URL url = b.getEntry("resources/BTS.pdf");
File file = null;
try {
URL resolvedURL = FileLocator.toFileURL(url);
URI resolvedURI = new URI(resolvedURL.getProtocol(),
resolvedURL.getPath(), null);
file = new File(resolvedURI);
OpenExternalBrowser.openURL(file.getAbsolutePath());
} catch (URISyntaxException | IOException e) {
e.printStackTrace();
String errMsg = "Could not open document. "+(file != null ? file.getAbsolutePath() : "");
MessageDialog md = new MessageDialog(null, "Error", null, errMsg + "\n" + e.toString(),
MessageDialog.ERROR, new String[]{"OK"}, 0);
md.open();
}
}
示例8: addProjectAnnotationsLibrary
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
private static File addProjectAnnotationsLibrary(IJavaProject jProject) throws IOException, URISyntaxException, MalformedURLException {
// see http://stackoverflow.com/q/23825933/475329 for logic of getting bundle resource
URL fileURL = Activator.getDefault().getBundle().getEntry(ANNOTATIONS_JAR_PATH);
URL resolvedFileURL = FileLocator.toFileURL(fileURL);
// need to use the 3-arg constructor of URI in order to properly escape file system chars
URI resolvedURI = new URI(resolvedFileURL.getProtocol(), resolvedFileURL.getPath(), null);
InputStream annotationsJarInputStream = resolvedURI.toURL().openConnection().getInputStream();
if(annotationsJarInputStream == null){
throw new RuntimeException("Could not locate: " + ANNOTATIONS_JAR_PATH);
}
File annotationsLibDirectory = new File(jProject.getProject().getLocation().toFile().getCanonicalPath() + File.separatorChar + JREF_PROJECT_RESOURCE_DIRECTORY);
annotationsLibDirectory.mkdirs();
File annotationsJar = new File(annotationsLibDirectory.getCanonicalPath() + File.separatorChar + JRE_FRAMEWORKER_ANNOTATIONS_JAR);
Files.copy(annotationsJarInputStream, annotationsJar.toPath());
return annotationsJar;
}
示例9: start
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
@Override
public int start(final List<String> args) throws IOException {
HeadlessSimulationLoader.preloadGAMA();
final int[] count = { 0 };
final int[] code = { 0 };
final Multimap<Bundle, String> plugins = GamaBundleLoader.getPluginsWithModels();
for (final Bundle bundle : plugins.keySet()) {
for (final String entry : plugins.get(bundle)) {
final Enumeration<URL> urls = bundle.findEntries(entry, "*", true);
if (urls != null)
while (urls.hasMoreElements()) {
final URL url = urls.nextElement();
if (isModel(url)) {
final URL resolvedFileURL = FileLocator.toFileURL(url);
validate(count, code, resolvedFileURL);
}
}
}
}
log("" + count[0] + " GAMA models compiled in built-in library and plugins. " + code[0]
+ " compilation errors found");
return code[0];
}
示例10: getCurrentGamaStampString
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
public static String getCurrentGamaStampString() {
String gamaStamp = null;
try {
final URL tmpURL = new URL("platform:/plugin/msi.gama.models/models/");
final URL resolvedFileURL = FileLocator.toFileURL(tmpURL);
// We need to use the 3-arg constructor of URI in order to properly escape file system chars
final URI resolvedURI = new URI(resolvedFileURL.getProtocol(), resolvedFileURL.getPath(), null).normalize();
final File modelsRep = new File(resolvedURI);
// loading file from URL Path is not a good idea. There are some bugs
// File modelsRep = new File(urlRep.getPath());
final long time = modelsRep.lastModified();
gamaStamp = ".built_in_models_" + time;
System.out.println(">GAMA version " + BUILTIN_VERSION + " loading...");
System.out.println(">GAMA models library version: " + gamaStamp);
} catch (final IOException | URISyntaxException e) {
e.printStackTrace();
}
return gamaStamp;
}
示例11: estimateLocation
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
protected Location estimateLocation(final IPath location) {
try {
final URL old_url = new URL("platform:/plugin/" + GamaBundleLoader.CORE_MODELS.getSymbolicName() + "/");
final URL new_url = FileLocator.toFileURL(old_url);
// windows URL formating
final URI resolvedURI = new URI(new_url.getProtocol(), new_url.getPath(), null).normalize();
final URL urlRep = resolvedURI.toURL();
final String osString = location.toOSString();
final boolean isTest = osString.contains(GamaBundleLoader.REGULAR_TESTS_LAYOUT);
if (!isTest && osString.startsWith(urlRep.getPath())) { return Location.CoreModels; }
if (osString
.startsWith(urlRep.getPath().replace(GamaBundleLoader.CORE_MODELS.getSymbolicName() + "/", ""))) {
if (isTest)
return Location.Tests;
return Location.Plugins;
}
return Location.Other;
} catch (final IOException | URISyntaxException e) {
e.printStackTrace();
return Location.Unknown;
}
}
示例12: load
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
/**
* Loads a resource from the classpath.
*
* @param path The classpath relative path to the resource.
* @return The requested resource.
*/
private static File load(final String path) {
final URL classpathUrl = PalladioFileShareSystemTest.class.getResource(path);
if (classpathUrl == null) {
throw new RuntimeException(path + " cannot be found!");
}
try {
// we already have a file URL, so we can directly return the file
if ("file".equals(classpathUrl.getProtocol())) {
return new File(classpathUrl.toURI());
}
// we have a bundle URL and need to resolve it into an file url
final URL fileUrl = FileLocator.toFileURL(classpathUrl);
// The URL to Path conversion has to be done like this, to make it work with
// Linux and Windows style paths.
final URI urii = new URI(fileUrl.getProtocol(), fileUrl.getPath(), null);
return Paths.get(urii).toAbsolutePath().toFile();
} catch (final URISyntaxException | IOException loadError) {
throw new RuntimeException(loadError);
}
}
示例13: getFallbackCompilerPath
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
protected String getFallbackCompilerPath() {
Bundle bundle = Platform.getBundle(SolidityCompilerActivator.PLUGIN_ID);
URL url = FileLocator.find(bundle, getPath(), null);
try {
URL fileURL = FileLocator.toFileURL(url);
return fileURL.getFile();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例14: resolveFile
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
private static File resolveFile(String pluginName, String path) {
Bundle bundle = Platform.getBundle(pluginName);
URL fileURL = bundle.getEntry(path);
try {
URL resolvedFileURL = FileLocator.toFileURL(fileURL);
URI resolvedURI = new URI(resolvedFileURL.getProtocol(), resolvedFileURL.getPath(), null);
return new File(resolvedURI);
} catch (URISyntaxException | IOException e) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
}
return null;
}
示例15: resolveImage
import org.eclipse.core.runtime.FileLocator; //導入方法依賴的package包/類
private static Image resolveImage(String pluginName, String path) {
Bundle bundle = Platform.getBundle(pluginName);
URL fileURL = bundle.getEntry(path);
try {
URL resolvedFileURL = FileLocator.toFileURL(fileURL);
return ImageDescriptor.createFromURL(resolvedFileURL).createImage();
} catch (IOException e) {
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
}
return null;
}