Java Code Examples for org.eclipse.core.runtime.FileLocator#getBundleFile()

The following examples show how to use org.eclipse.core.runtime.FileLocator#getBundleFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XdsResourcesUpdater.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param installedUpdatesRegistry 
 * @param dirWithUpdatesPath directory where updates are
 * @param updateDirSubdirWithResource relative path where update is
 * @param newResourceName update resource name
 * @throws IOException
 * @throws FileNotFoundException
 * @return true if the resource was updated
 */
private boolean updateResource(InstalledUpdatesRegistry installedUpdatesRegistry, Bundle resourcesBundle, String dirWithUpdatesPath, Update update) {
	String newResourceRelativePath = update.newResourceLocation;
	String existingResourceRelativePath = update.existingResourceLocation;
	String xmlSchemaRelativePath = update.xmlSchemaLocation;
	Version version = update.version;
	File resourceFolderFile = null;
	try {
		resourceFolderFile = FileLocator.getBundleFile(resourcesBundle);
	} catch (IOException e) {
		LogHelper.logError(e);
		return false;
	}
	
	return updateResource(installedUpdatesRegistry, dirWithUpdatesPath,
			newResourceRelativePath, resourceFolderFile,
			existingResourceRelativePath, xmlSchemaRelativePath, version, true);
}
 
Example 2
Source File: RascalManager.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private void collectClassPathForBundle(Bundle bundle, List<URL> classPath,
		List<String> compilerClassPath) {
	try {
		File file = FileLocator.getBundleFile(bundle);
		URL url = file.toURI().toURL();

		if (classPath.contains(url)) {
			return; // kill infinite loop
		}
		classPath.add(0, url);
		compilerClassPath.add(0, file.getAbsolutePath());
		
		BundleWiring wiring = bundle.adapt(BundleWiring.class);
		for (BundleWire dep : wiring.getRequiredWires(null)) {
			collectClassPathForBundle(dep.getProviderWiring().getBundle(),
					classPath, compilerClassPath);
		}

		List<String> requiredLibs = new RascalBundleManifest().getRequiredLibraries(bundle);
		if (requiredLibs != null) {
			for (String lib : requiredLibs) {
				classPath.add(bundle.getResource(lib));
			}
		}

	} 
	catch (IOException e) {
		Rasctivator.logException("error while tracing dependencies", e);
	} 
}
 
Example 3
Source File: BundleUtils.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param bundleName
 * @return file this can return null if bundle is not found
 * @throws IOException
 */
public static File getBundleLocation(final String bundleName) throws IOException {
	final Bundle bundle = Platform.getBundle(bundleName);
	if (bundle == null) {
		return null;
	}
	return FileLocator.getBundleFile(bundle);
}
 
Example 4
Source File: BundleUtils.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param bundleName
 * @return file this can return null if bundle is not found
 * @throws IOException
 */
public static File getBundleLocation(final String bundleName) throws IOException {
	final Bundle bundle = Platform.getBundle(bundleName);
	if (bundle == null) {
		return null;
	}
	return FileLocator.getBundleFile(bundle);
}
 
Example 5
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static File getXdsPluginsDirectory() throws IOException {
	File bundleFile = FileLocator.getBundleFile(getXdsResourcesPluginBundle());
	return bundleFile.getParentFile();
}
 
Example 6
Source File: TargetDefinitionSetup.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * If necessary, creates and loads a new target platform. Waits until the new platform has been loaded.
 *
 * @throws IOException
 *           if locating bundle file fails
 */
public static void initializeTargetPlatform() throws IOException {
  // The work-around is creating a new target platform adding the parent folders of the bundles
  try {
    final ITargetPlatformService targetPlatformService = TargetPlatformService.getDefault();
    final ITargetHandle workspaceTargetHandle = targetPlatformService.getWorkspaceTargetHandle();
    if (workspaceTargetHandle == null || !TARGET_PLATFORM_NAME.equals(workspaceTargetHandle.getTargetDefinition().getName())) {
      final ITargetDefinition targetDefinition = targetPlatformService.newTarget();
      targetDefinition.setName(TARGET_PLATFORM_NAME);
      final List<ITargetLocation> bundleContainers = new ArrayList<ITargetLocation>();
      final Set<String> dirs = new HashSet<String>();
      for (final Bundle bundle : Platform.getBundle("org.eclipse.core.runtime").getBundleContext().getBundles()) { //$NON-NLS-1$
        final File file = FileLocator.getBundleFile(bundle);
        final File folder = file.getParentFile();
        final String path = folder.getAbsolutePath();
        if (dirs.add(path)) {
          ITargetLocation newDirectoryLocation = targetPlatformService.newDirectoryLocation(path);
          bundleContainers.add(newDirectoryLocation);
        }
      }
      targetDefinition.setTargetLocations(bundleContainers.toArray(new ITargetLocation[bundleContainers.size()]));
      targetDefinition.setArch(Platform.getOSArch());
      targetDefinition.setOS(Platform.getOS());
      targetDefinition.setWS(Platform.getWS());
      targetDefinition.setNL(Platform.getNL());
      targetPlatformService.saveTargetDefinition(targetDefinition);

      final CountDownLatch platformLoaded = new CountDownLatch(1);
      LoadTargetDefinitionJob.load(targetDefinition, new JobChangeAdapter() {
        @Override
        public void done(final IJobChangeEvent event) {
          platformLoaded.countDown();
        }
      });

      platformLoaded.await();

    }
  } catch (final CoreException coreException) {
    // Nothing
  } catch (InterruptedException e) {
    // Restore interrupted status
    Thread.currentThread().interrupt();
  }
}
 
Example 7
Source File: ScriptingEngine.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * createScriptingContainer
 * 
 * @param scope
 * @return
 */
private ScriptingContainer createScriptingContainer(LocalContextScope scope)
{
	// ScriptingContainer result = new ScriptingContainer(scope, LocalVariableBehavior.PERSISTENT);
	ScriptingContainer result = new ScriptingContainer(scope, LocalVariableBehavior.TRANSIENT);

	try
	{
		File jrubyHome = null;
		Bundle jruby = Platform.getBundle("org.jruby"); //$NON-NLS-1$
		// try just exploding the jruby lib dir
		URL url = FileLocator.find(jruby, new Path("lib"), null); //$NON-NLS-1$

		if (url != null)
		{
			File lib = ResourceUtil.resourcePathToFile(url);
			// Ok, now use the parent of exploded lib dir as JRuby Home
			jrubyHome = lib.getParentFile();
		}
		else
		{
			// Ok, just assume the plugin is unpacked and pass the root of the plugin as JRuby Home
			jrubyHome = FileLocator.getBundleFile(jruby);
		}

		result.setHomeDirectory(jrubyHome.getAbsolutePath());

		// TODO Generate two containers? A global one for loading bundles, a threadsafe one for executing
		// commands/snippets/etc?
		// Pre-load 'ruble' framework files!
		List<String> loadPaths = result.getLoadPaths();
		loadPaths.addAll(0, getContributedLoadPaths());
		result.setLoadPaths(loadPaths);
	}
	catch (IOException e)
	{
		String message = MessageFormat.format(Messages.ScriptingEngine_Error_Setting_JRuby_Home,
				new Object[] { e.getMessage() });

		IdeLog.logError(ScriptingActivator.getDefault(), message, e);
		ScriptLogger.logError(message);
	}

	return result;
}
 
Example 8
Source File: BundleUtils.java    From dawnsci with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Get the java.io.File location of a bundle.
 * @param bundleName
 * @return
 * @throws Exception 
 */
public static File getBundleLocation(final Bundle bundle) throws IOException {
	return FileLocator.getBundleFile(bundle);
}
 
Example 9
Source File: BundleUtils.java    From dawnsci with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Get the java.io.File location of a bundle.
 * @param bundleName
 * @return
 * @throws Exception 
 */
public static File getBundleLocation(final Bundle bundle) throws IOException {
	return FileLocator.getBundleFile(bundle);
}