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

The following examples show how to use org.eclipse.core.runtime.FileLocator#resolve() . 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: DEUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static String getFilePathFormURL( URL url ) throws Exception
{
	if ( url != null )
	{
		URL localURL = FileLocator.resolve( url );
		if ( "bundleresource".equals( url.getProtocol( ) ) )
			return localURL.getPath( );
		else if ( localURL != null
				&& "file".equals( localURL.getProtocol( ) ) )
			return localURL.toURI( ).getSchemeSpecificPart( );
		else
			return null;
	}
	else
		return null;
}
 
Example 2
Source File: ClassListerTest.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("nls")
@Test
   public void testListPublicClasses( ) throws IOException
{
	URL classFolderURL = C1.class.getResource( "." );
	if ( !classFolderURL.getProtocol( ).equals( "file" ))
	{
		classFolderURL = FileLocator.resolve( classFolderURL );
	}
	String[] classes = ClassLister.listClasses( new URL[]{classFolderURL} );
	Set<String> cs = new HashSet<String>( Arrays.asList( classes ) );
	assertEquals( cs.size( ), 3 );
	assertTrue( cs.contains( "C1" ));
	assertTrue( cs.contains( "inner.C1" ));
	assertTrue( cs.contains( "inner.C1.C2" ));

}
 
Example 3
Source File: DockerConfig.java    From doclipser with Eclipse Public License 1.0 6 votes vote down vote up
public DockerConfig() {
    final URL url = Resources.getResource(Constants.PROPERTY_FILE_NAME);
    Properties properties = readPropertyFile(url);
    
    
    version = properties.getProperty(Constants.PROPERTY_DOCKER_API_VERSION);
    uri = properties.getProperty(Constants.PROPERTY_DOCKER_URI);
    username = properties.getProperty(Constants.PROPERTY_USERNAME);
    password = properties.getProperty(Constants.PROPERTY_PASSWORD);
    email = properties.getProperty(Constants.PROPERTY_EMAIL);
    serverAddress = properties
            .getProperty(Constants.PROPERTY_DOCKER_SERVER_ADDRESS);
    dockerCertPath = properties
            .getProperty(Constants.PROPERTY_DOCKER_CERT_PATH);

    URL fullUrl = null;
    try {
        fullUrl = FileLocator.resolve(url);
    } catch (IOException e) {
        e.printStackTrace();
    }
    propertiesFileFullPath = fullUrl == null ? null : fullUrl.getPath();
}
 
Example 4
Source File: CodewindTestPlugin.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static String getBundleFullLocationPath(Bundle bundle) {
    if (bundle == null) {
        return null;
    }
    URL installURL = bundle.getEntry("/");
    String installLocation = null;
    try {
        URL realURL = FileLocator.resolve(installURL);
        installLocation = realURL.getFile();

        // Drop the beginning and end /
        if (installLocation != null && installLocation.startsWith("/") && installLocation.indexOf(":") > 0) {
            installLocation = installLocation.substring(1);
            // Make sure the path ends with a '/'		
            if (!installLocation.endsWith("/")) {
                installLocation = installLocation + "/";
            }
        }
    } catch (IOException e) {
        System.out.println("Could not get the Plugin Full location Path:" + " getPluginFullLocationPath()");
    }
    return installLocation;
}
 
Example 5
Source File: FormatterHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGoogleFormatterFilePath() throws Exception {
	try {
		String text =
		//@formatter:off
				"package org.sample;\n\n" +
				"public class Baz {\n" +
				"  String name;\n" +
				"}\n";
			//@formatter:on"
		ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", text);
		String uri = JDTUtils.toURI(unit);
		TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
		FormattingOptions options = new FormattingOptions(2, true);// ident == 2 spaces
		DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
		Bundle bundle = Platform.getBundle(JavaLanguageServerTestPlugin.PLUGIN_ID);
		URL googleFormatter = bundle.getEntry("/formatter resources/eclipse-java-google-style.xml");
		URL url = FileLocator.resolve(googleFormatter);
		File file = ResourceUtils.toFile(URIUtil.toURI(url));
		preferenceManager.getPreferences().setFormatterUrl(file.getAbsolutePath());
		FormatterManager.configureFormatter(preferenceManager, projectsManager);
		List<? extends TextEdit> edits = server.formatting(params).get();
		assertNotNull(edits);
		String newText = TextEditUtil.apply(unit, edits);
		assertEquals(text, newText);
	} finally {
		preferenceManager.getPreferences().setFormatterUrl(null);
		FormatterManager.configureFormatter(preferenceManager, projectsManager);
	}
}
 
Example 6
Source File: PlatformUtils.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Expects the bundle to have a META-INF/MANIFEST.MF set and to exist.
 * 
 * @param symbolicName
 * @return
 * @throws IOException
 */
public static String getBundleJarPath(String symbolicName)
		throws IOException {
	String MANIFESTPath = "/META-INF/MANIFEST.MF";
	URL pluginManifLoc = FileLocator
			.resolve(FileLocator.find(Platform.getBundle(symbolicName),
					new Path(MANIFESTPath), null));
	return getBundleJarPathInternal(MANIFESTPath, pluginManifLoc);
}
 
Example 7
Source File: FileUtils.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private static URL getFileURL( URL url ){
	try{
		url = FileLocator.resolve(url);
		return FileLocator.toFileURL(url);
	}
	catch(IOException e){
		return null;
	}
}
 
Example 8
Source File: GdtPreferences.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Attempts to register the SDK from a bundle.
 */
private static void registerBundleSdk(Bundle bundle) throws CoreException {
  try {
    IPath propPath = new Path(SDK_REGISTRANT_PROPERTY_FILE);
    URL propUrl = FileLocator.find(bundle, propPath, (Map<String, String>) null);
    if (propUrl != null) {
      InputStream instream = propUrl.openStream();
      Properties props = new Properties();
      props.load(instream);
      String sdkType = props.getProperty(SDK_BUNDLE_MARKER_PROPERTY);
      String sdkPrefix = props.getProperty(SDK_PATH_PREFIX_PROPERTY);
      if (sdkType != null && sdkPrefix != null) {
        IPath sdkPrefixPath = new Path(sdkPrefix);
        URL sdkPathUrl = FileLocator.find(bundle, sdkPrefixPath, (Map<String, String>) null);
        if (sdkPathUrl == null) {
          // Automatic SDK registration failed. This is expected in dev mode.
          CorePluginLog.logWarning("Failed to register SDK: " + sdkPrefix);
          return;
        }
        // resolve needed to switch from bundleentry to file url
        sdkPathUrl = FileLocator.resolve(sdkPathUrl);
        if (sdkPathUrl != null) {
          if ("file".equals(sdkPathUrl.getProtocol())) {
            GWTSdkRegistrant.registerSdk(sdkPathUrl, sdkType);
          }
        }
      }
    }
  } catch (IOException e) {
    throw new CoreException(new Status(IStatus.WARNING, GdtPlugin.PLUGIN_ID, e.getLocalizedMessage(), e));
  }
}
 
Example 9
Source File: FormatterHandlerTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGoogleFormatter() throws Exception {
	try {
		String text =
		//@formatter:off
				"package org.sample;\n\n" +
				"public class Baz {\n" +
				"  String name;\n" +
				"}\n";
			//@formatter:on"
		ICompilationUnit unit = getWorkingCopy("src/org/sample/Baz.java", text);
		String uri = JDTUtils.toURI(unit);
		TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uri);
		FormattingOptions options = new FormattingOptions(2, true);// ident == 2 spaces
		DocumentFormattingParams params = new DocumentFormattingParams(textDocument, options);
		Bundle bundle = Platform.getBundle(JavaLanguageServerTestPlugin.PLUGIN_ID);
		URL googleFormatter = bundle.getEntry("/formatter resources/eclipse-java-google-style.xml");
		URL url = FileLocator.resolve(googleFormatter);
		preferenceManager.getPreferences().setFormatterUrl(url.toExternalForm());
		FormatterManager.configureFormatter(preferenceManager, projectsManager);
		List<? extends TextEdit> edits = server.formatting(params).get();
		assertNotNull(edits);
		String newText = TextEditUtil.apply(unit, edits);
		assertEquals(text, newText);
	} finally {
		preferenceManager.getPreferences().setFormatterUrl(null);
		FormatterManager.configureFormatter(preferenceManager, projectsManager);
	}
}
 
Example 10
Source File: BundleClasspathUriResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private URI findResourceInBundle(Bundle bundle, URI classpathUri)
        throws MalformedURLException, IOException {
    Path fullPath = new Path(classpathUri.path());
    if (bundle != null) {
        String projectRelativePath = "/" + fullPath;
        URL resourceUrl = bundle.getResource(projectRelativePath);
        if (resourceUrl != null) {
        	URL resolvedUrl = FileLocator.resolve(resourceUrl);
            URI normalizedURI = URI.createURI(
                    resolvedUrl.toString(), true);
            return normalizedURI;
        }
    }
    return classpathUri;
}
 
Example 11
Source File: BazelAspectLocationImpl.java    From eclipse with Apache License 2.0 5 votes vote down vote up
private static File getAspectWorkspace() {
  try {
    URL url = Platform.getBundle(Activator.PLUGIN_ID).getEntry("resources");
    URL resolved = FileLocator.resolve(url);
    return new File(resolved.getPath());
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example 12
Source File: SootClasspathVariableInitializer.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Code copied from AJDT implementation http://www.eclipse.org/ajdt
 * org.eclipse.ajdt.internal.core.AspectJRTInitializer
 * @param relativePath 
 */
private static String getSootFilePath(String relativePath) {

	StringBuffer cpath = new StringBuffer();

	// This returns the bundle with the highest version or null if none
	// found
	// - for Eclipse 3.0 compatibility
	Bundle ajdeBundle = Platform
			.getBundle(LIBRARY_PLUGIN_NAME);

	String pluginLoc = null;
	// 3.0 using bundles instead of plugin descriptors
	if (ajdeBundle != null) {
		URL installLoc = ajdeBundle.getEntry("/"); //$NON-NLS-1$
		URL resolved = null;
		try {
			resolved = FileLocator.resolve(installLoc);
			pluginLoc = resolved.toExternalForm();
		} catch (IOException e) {
		}
	}
	if (pluginLoc != null) {
		if (pluginLoc.startsWith("file:")) { //$NON-NLS-1$
			cpath.append(pluginLoc.substring("file:".length())); //$NON-NLS-1$
			cpath.append(relativePath); //$NON-NLS-1$
		}
	}

	String sootJarPath = null;
	
	// Verify that the file actually exists at the plugins location
	// derived above. If not then it might be because we are inside
	// a runtime workbench. Check under the workspace directory.
	if (new File(cpath.toString()).exists()) {
		// File does exist under the plugins directory
		sootJarPath = cpath.toString();
	} else {
		// File does *not* exist under plugins. Try under workspace...
		IPath rootPath = SootPlugin.getWorkspace().getRoot()
				.getLocation();
		IPath installPath = rootPath.removeLastSegments(1);
		cpath = new StringBuffer().append(installPath.toOSString());
		cpath.append(File.separator);
		// TODO: what if the workspace isn't called workspace!!!
		cpath.append("workspace"); //$NON-NLS-1$
		cpath.append(File.separator);
		cpath.append(LIBRARY_PLUGIN_NAME);
		cpath.append(File.separator);
		cpath.append("aspectjrt.jar"); //$NON-NLS-1$

		// Only set the aspectjrtPath if the jar file exists here.
		if (new File(cpath.toString()).exists())
			sootJarPath = cpath.toString();
	}
	
	return sootJarPath;
}
 
Example 13
Source File: OnTheFlyJavaCompiler.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param url the location of the class file.
 */
protected URL resolveBundleResourceURL(URL url) throws IOException {
	return FileLocator.resolve(url);
}
 
Example 14
Source File: OnTheFlyJavaCompiler.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected URL resolveBundleResourceURL(URL url) throws IOException {
	return FileLocator.resolve(url);
}
 
Example 15
Source File: ESBJavaRoutinesProvider.java    From tesb-studio-se with Apache License 2.0 4 votes vote down vote up
public URL getTalendRoutinesFolder() throws IOException {
    URL url = Activator.getDefault().getBundle()
            .getEntry("routines/system"); //$NON-NLS-1$
    return FileLocator.resolve(url);
}
 
Example 16
Source File: OnTheFlyJavaCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param url the location of the class file.
 */
protected URL resolveBundleResourceURL(URL url) throws IOException {
	return FileLocator.resolve(url);
}
 
Example 17
Source File: Core.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Private method used by Core.start() method to start the HttpService.
 */
private void startHttpService() {

	// The service cannot be started without a valid bundle context since we
	// are no longer using Declarative Services.
	if (bundleContext != null) {
		// Grab the service reference and the service
		httpServiceRef = bundleContext.getServiceReference(HttpService.class);

		// If it is good to go, start up the webserver
		if (httpServiceRef != null) {

			// Local Declaration
			Dictionary<String, String> servletParams = new Hashtable<>();

			// Get the service
			httpService = bundleContext.getService(httpServiceRef);

			// Set the parameters
			servletParams.put("javax.ws.rs.Application", Core.class.getName());

			// Register the service
			try {
				// Get the bundle
				Bundle bundle = null;
				bundle = bundleContext.getBundle();
				// Make sure we got a valid bundle
				if (bundle == null) {
					logger.info("ICE Core Bundle was null! No web service started.");
					return;
				}

				// Find the root location and the jaas_config file
				URL resourceURL = bundle.getEntry("");
				URL configFileURL = bundle.getEntry("jaas_config.txt");
				// Resolve the URLs to be absolute
				resourceURL = FileLocator.resolve(resourceURL);
				configFileURL = FileLocator.resolve(configFileURL);
				HttpContext httpContext = new BasicAuthSecuredContext(resourceURL, configFileURL,
						"ICE Core Server Configuration");
				httpService.registerServlet("/ice", new ServletContainer(this), servletParams, httpContext);
			} catch (ServletException | NamespaceException | IOException e) {
				logger.error(getClass().getName() + " Exception!", e);
			}
			logger.info("ICE Core Server loaded and web service started!");
		} else {
			logger.info("ICE Core Server loaded, but without webservice.");
		}
	} else {
		logger.info("HTTP Service Unavailable.");
	}

	return;
}
 
Example 18
Source File: OnTheFlyJavaCompiler.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected URL resolveBundleResourceURL(URL url) throws IOException {
	return FileLocator.resolve(url);
}