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

The following examples show how to use org.eclipse.core.runtime.FileLocator#find() . 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: TmfCoreTestPlugin.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Return a path to a file relative to this plugin's base directory
 *
 * @param relativePath
 *            The path relative to the plugin's root directory
 * @return The path corresponding to the relative path in parameter
 */
public static @NonNull IPath getAbsoluteFilePath(String relativePath) {
    Plugin plugin = TmfCoreTestPlugin.getDefault();
    if (plugin == null) {
        /*
         * Shouldn't happen but at least throw something to get the test to
         * fail early
         */
        throw new IllegalStateException();
    }
    URL location = FileLocator.find(plugin.getBundle(), new Path(relativePath), null);
    try {
        return new Path(FileLocator.toFileURL(location).getPath());
    } catch (IOException e) {
        throw new IllegalStateException();
    }
}
 
Example 2
Source File: XBookmarksPlugin.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param imgid IMG_* constant
 * @return Image 
 */
public Image getCachedBookmarkImage(int bookmarkNum) { // 0..9
    if (hmCachedImages == null || bookmarkNum < 0 || bookmarkNum > 9) { 
        return null; // hbz
    }
    Integer key = new Integer(IMGID_BOOKMARKS + bookmarkNum);
    Image img = hmCachedImages.get(key);
    if (img == null) {
        IPath path = new Path(String.format(IMG_SOURCES_BOOKMARKS, bookmarkNum)); 
        URL   url  = FileLocator.find(XBookmarksPlugin.getDefault().getBundle(), path, null);
        if (url != null) {
            img = ImageDescriptor.createFromURL(url).createImage();
        }
        if (img != null) {
            hmCachedImages.put(key, img);
        }
    }
    return img;
}
 
Example 3
Source File: EclipseUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns all the trace options for a particular bundle
 * 
 * @param bundle
 * @return
 */
public static Properties getTraceOptions(Bundle bundle)
{
	Path path = new Path(".options"); //$NON-NLS-1$
	URL fileURL = FileLocator.find(bundle, path, null);
	if (fileURL != null)
	{
		InputStream in;
		try
		{
			in = fileURL.openStream();
			Properties options = new Properties();
			options.load(in);
			return options;
		}
		catch (IOException e1)
		{
		}
	}

	return new Properties();

}
 
Example 4
Source File: CtfCoreTestPlugin.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Return a path to a file relative to this plugin's base directory
 *
 * @param relativePath
 *            The path relative to the plugin's root directory
 * @return The path corresponding to the relative path in parameter
 */
public static IPath getAbsoluteFilePath(String relativePath) {
    CtfCoreTestPlugin plugin = CtfCoreTestPlugin.getDefault();
    if (plugin == null) {
        /*
         * Shouldn't happen but at least throw something to get the test to
         * fail early
         */
        throw new IllegalStateException();
    }
    URL location = FileLocator.find(plugin.getBundle(), new Path(relativePath), null);
    try {
        return new Path(FileLocator.toFileURL(location).getPath());
    } catch (IOException e) {
        throw new IllegalStateException();
    }
}
 
Example 5
Source File: Activator.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Return a path to a file relative to this plugin's base directory
 *
 * @param relativePath
 *            The path relative to the plugin's root directory
 * @return The path corresponding to the relative path in parameter
 */
public static IPath getAbsoluteFilePath(String relativePath) {
    Activator plugin = Activator.getDefault();
    if (plugin == null) {
        /*
         * Shouldn't happen but at least throw something to get the test to
         * fail early
         */
        throw new IllegalStateException();
    }
    URL location = FileLocator.find(plugin.getBundle(), new Path(relativePath), null);
    try {
        return new Path(FileLocator.toFileURL(location).getPath());
    } catch (IOException e) {
        throw new IllegalStateException();
    }
}
 
Example 6
Source File: RouteTreeLabelProvider.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
@Override
public Image getImage(Object element) {
   if (element instanceof IProject) {
      return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_PROJECT);
   }
   if (element instanceof IResource) {
      return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
   }
   if (element instanceof Route) {
      Bundle bundle = FrameworkUtil.getBundle(RouteTreeLabelProvider.class);
      URL url = FileLocator.find(bundle, new Path("icons/obj16/Route.gif"), null);
      ImageDescriptor imageDcr = ImageDescriptor.createFromURL(url);
      return imageDcr.createImage();
   }
   return null;
}
 
Example 7
Source File: Activator.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Gets the absolute path from a path relative to this plugin's root
 *
 * @param relativePath
 *            The path relative to this plugin
 * @return The absolute path corresponding to this relative path
 */
public static @NonNull IPath getAbsolutePath(Path relativePath) {
    Activator plugin2 = getDefault();
    if (plugin2 == null) {
        /*
         * Shouldn't happen but at least throw something to get the test to
         * fail early
         */
        throw new IllegalStateException();
    }
    URL location = FileLocator.find(plugin2.getBundle(), relativePath, null);
    try {
        IPath path = new Path(FileLocator.toFileURL(location).getPath());
        return path;
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 8
Source File: AbstractAcuteTest.java    From aCute with Eclipse Public License 2.0 6 votes vote down vote up
/**
 *
 * @param projectName the name that will be used as prefix for the project, and that will be used to find
 * the content of the project from the plugin "projects" folder
 * @throws IOException
 * @throws CoreException
 * @throws InterruptedException
 */
protected IProject provisionProject(String projectName) throws IOException, CoreException, InterruptedException {
	URL url = FileLocator.find(Platform.getBundle("org.eclipse.acute.tests"), Path.fromPortableString("projects/" + projectName), Collections.emptyMap());
	url = FileLocator.toFileURL(url);
	File folder = new File(url.getFile());
	if (folder != null && folder.exists()) {
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName + "_" + getClass().getName() + "_" + System.currentTimeMillis());
		project.create(new NullProgressMonitor());
		this.provisionedProjects.put(projectName, project);
		FileUtils.copyDirectory(folder, project.getLocation().toFile());
		// workaround for https://github.com/OmniSharp/omnisharp-node-client/issues/265
		ProcessBuilder dotnetRestoreBuilder = new ProcessBuilder(AcutePlugin.getDotnetCommand(), "restore");
		dotnetRestoreBuilder.directory(project.getLocation().toFile());
		assertEquals(0, dotnetRestoreBuilder.start().waitFor());
		project.open(new NullProgressMonitor());
		project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
		return project;
	} else {
		return null;
	}
}
 
Example 9
Source File: ImportItemWizardAction.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Constructor
 * 
 * @param window
 *            The window that should be used by the action
 */
public ImportItemWizardAction(IWorkbenchWindow window) {

	// Set the window handle
	workbenchWindow = window;

	// Set the text properties.
	setId(ID);
	setText("&Import an Item");
	setToolTipText("Import an input file for an Item into ICE.");

	// Find the client bundle
	Bundle bundle = FrameworkUtil.getBundle(ImportItemWizardAction.class);
	Path imagePath = new Path("icons"
			+ System.getProperty("file.separator") + "itemImport.gif");
	URL imageURL = FileLocator.find(bundle, imagePath, null);
	setImageDescriptor(ImageDescriptor.createFromURL(imageURL));

	return;
}
 
Example 10
Source File: ZoomOutToolEntry.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private static ImageDescriptor findIconImageDescriptor(String iconPath) {
    String pluginId = "org.eclipse.gmf.runtime.diagram.ui.providers";
    Bundle bundle = Platform.getBundle(pluginId);
    try
    {
        if (iconPath != null) {
            URL fullPathString = FileLocator.find(bundle, new Path(iconPath), null);
            fullPathString = fullPathString != null ? fullPathString : new URL(iconPath);
            if (fullPathString != null) {
                return ImageDescriptor.createFromURL(fullPathString);
            }
        }
    }
    catch (MalformedURLException e)
    {
        Trace.catching(DiagramUIPlugin.getInstance(),
            DiagramUIDebugOptions.EXCEPTIONS_CATCHING,
            DefaultPaletteProvider.class, e.getLocalizedMessage(), e); 
        Log.error(DiagramUIPlugin.getInstance(),
            DiagramUIStatusCodes.RESOURCE_FAILURE, e.getMessage(), e);
    }
    
    return null;
}
 
Example 11
Source File: TextTraceTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testInitTrace() throws Exception {
    URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(PATH), null);
    String path = FileLocator.toFileURL(location).toURI().getPath();
    SyslogTrace trace = new SyslogTrace();
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(PATH));
    trace.initTrace(resource, path, SyslogEvent.class);
    assertEquals("getEventType",      SyslogEvent.class, trace.getEventType());
    assertEquals("getPath",      fTestFile.toURI().getPath(), trace.getPath());
    assertEquals("getName",      NAME, trace.getName());
    assertEquals("getCacheSize", 100, trace.getCacheSize());
    trace.dispose();
}
 
Example 12
Source File: JavaPluginImages.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static ImageDescriptor createImageDescriptor(Bundle bundle, IPath path, boolean useMissingImageDescriptor) {
	URL url= FileLocator.find(bundle, path, null);
	if (url != null) {
		return ImageDescriptor.createFromURL(url);
	}
	if (useMissingImageDescriptor) {
		return ImageDescriptor.getMissingImageDescriptor();
	}
	return null;
}
 
Example 13
Source File: UIEplPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the specified image descriptor and registers it
 */
private void createImageDescriptor(String id, ImageRegistry reg)
{
	URL url = FileLocator.find(getBundle(), new Path(ICON_PATH).append(id), null);
	ImageDescriptor desc = ImageDescriptor.createFromURL(url);
	reg.put(id, desc);
}
 
Example 14
Source File: SharedImages.java    From aem-eclipse-developer-tools with Apache License 2.0 5 votes vote down vote up
public static ImageDescriptor createImageDescriptor(Bundle bundle, IPath path) {
    URL url = FileLocator.find(bundle, path, null);
    if (url != null) {
        return ImageDescriptor.createFromURL(url);
    }
    return null;
}
 
Example 15
Source File: XYDataProviderBaseTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get the full path to a test file from this class's bundle.
 *
 * @param bundlePath
 *            path from the bundle
 * @return the absolute path
 */
private String getFullPath(String bundlePath) {
    try {
        Bundle bundle = FrameworkUtil.getBundle(this.getClass());
        URL location = FileLocator.find(bundle, new Path(bundlePath), null);
        URI uri = FileLocator.toFileURL(location).toURI();
        return new File(uri).getAbsolutePath();
    } catch (Exception e) {
        fail(e.toString());
        return null;
    }
}
 
Example 16
Source File: FilterColorEditorTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test Class setup
 */
@BeforeClass
public static void init() {
    SWTBotUtils.initialize();

    /* set up test trace */
    URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
    URI uri;
    try {
        uri = FileLocator.toFileURL(location).toURI();
        fTestFile = new File(uri);
    } catch (URISyntaxException | IOException e) {
        fail(e.getMessage());
    }

    assumeTrue(fTestFile.exists());

    /* Set up for swtbot */
    SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";

    fLogger.removeAllAppenders();
    fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    fBot = new SWTWorkbenchBot();

    /* Finish waiting for eclipse to load */
    WaitUtils.waitForJobs();

    ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
    fHighlight = ImageHelper.adjustExpectedColor(colorRegistry.get(HIGHLIGHT_COLOR_DEFINITION_ID).getRGB());
    fGreen = ImageHelper.adjustExpectedColor(GREEN);
}
 
Example 17
Source File: TraceControlUstSessionTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Perform pre-test initialization.
 *
 * @throws Exception
 *         if the initialization fails for some reason
 */
@Before
public void setUp() throws Exception {
    fFacility = TraceControlTestFacility.getInstance();
    fFacility.init();
    URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
    File testfile = new File(FileLocator.toFileURL(location).toURI());
    fTestFile = testfile.getAbsolutePath();
}
 
Example 18
Source File: FontMappingManagerFactory.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected String getEmbededFontPath( )
{
	Bundle bundle = Platform
			.getBundle( "org.eclipse.birt.report.engine.fonts" ); //$NON-NLS-1$
	if ( bundle == null )
	{
		return null;
	}
	Path path = new Path( "/fonts" ); //$NON-NLS-1$

	URL fileURL = FileLocator.find( bundle, path, null );
	if ( null == fileURL )
		return null;
	String fontPath = null;
	try
	{
		// 171369 patch provided by Arne Degenring <[email protected]>
		fontPath = FileLocator.toFileURL( fileURL ).getPath( );
		if ( fontPath != null && fontPath.length( ) >= 3 &&
				fontPath.charAt( 2 ) == ':' )
		{
			// truncate the first '/';
			return fontPath.substring( 1 );
		}
		else
		{
			return fontPath;
		}
	}
	catch ( IOException ioe )
	{
		logger.log( Level.WARNING, ioe.getMessage( ), ioe );
		return null;
	}
}
 
Example 19
Source File: MetadataLoader.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Process all metadata files via the metadata reader returned by createMetadataReader
 * 
 * @param monitor
 * @param reader
 * @param resources
 */
private void loadMetadata(IProgressMonitor monitor, T reader, String... resources)
{
	SubMonitor subMonitor = SubMonitor.convert(monitor, resources.length);

	for (String resource : resources)
	{
		URL url = FileLocator.find(this.getBundle(), new Path(resource), null);

		if (url != null)
		{
			InputStream stream = null;

			try
			{
				stream = url.openStream();

				reader.loadXML(stream, url.toString());
			}
			catch (Throwable t)
			{
				IdeLog.logError(IndexPlugin.getDefault(), Messages.MetadataLoader_Error_Loading_Metadata
						+ resource, t);
			}
			finally
			{
				if (stream != null)
				{
					try
					{
						stream.close();
					}
					catch (IOException e)
					{
					}
				}
			}
		}

		subMonitor.worked(1);
	}

	subMonitor.done();
}
 
Example 20
Source File: ApplicationWorkbenchAdvisor.java    From tracecompass with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Declares an IDE-specific workbench image.
 *
 * Declares all IDE-specific workbench images. This includes both "shared"
 * images (named in ( @link IDE.SharedImages} ) and internal images (named in
 * {@link org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages}).
 *
 * @param symbolicName
 *            the symbolic name of the image
 * @param path
 *            the path of the image file; this path is relative to the base
 *            of the IDE plug-in
 * @param shared
 *            <code>true</code> if this is a shared image, and
 *            <code>false</code> if this is not a shared image
 */
private void declareWorkbenchImage(Bundle ideBundle, String symbolicName, String path, boolean shared) {
    URL url = FileLocator.find(ideBundle, new Path(path), null);
    ImageDescriptor desc = ImageDescriptor.createFromURL(url);
    getWorkbenchConfigurer().declareImage(symbolicName, desc, shared);
}