Java Code Examples for org.eclipse.core.runtime.URIUtil#toFile()

The following examples show how to use org.eclipse.core.runtime.URIUtil#toFile() . 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: CheckConfigurationFactory.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Copy the checkstyle configuration of a check configuration into another configuration.
 *
 * @param source
 *          the source check configuration
 * @param target
 *          the target check configuartion
 * @throws CheckstylePluginException
 *           Error copying the configuration
 */
public static void copyConfiguration(ICheckConfiguration source, ICheckConfiguration target)
        throws CheckstylePluginException {

  try {

    // use the export function ;-)
    File targetFile;

    targetFile = URIUtil.toFile(target.getResolvedConfigurationFileURL().toURI());

    File sourceFile = URIUtil.toFile(source.getResolvedConfigurationFileURL().toURI());

    // copying from a file to the same file will destroy it.
    if (Objects.equals(targetFile, sourceFile)) {
      return;
    }

    exportConfiguration(targetFile, source);
  } catch (URISyntaxException e) {
    CheckstylePluginException.rethrow(e);
  }
}
 
Example 2
Source File: ConfigurationType.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Gets the property resolver for this configuration type used to expand property values within
 * the checkstyle configuration.
 *
 * @param checkConfiguration
 *          the actual check configuration
 * @return the property resolver
 * @throws IOException
 *           error creating the property resolver
 * @throws URISyntaxException
 *           if configuration file URL cannot be resolved
 */
protected PropertyResolver getPropertyResolver(ICheckConfiguration config,
        CheckstyleConfigurationFile configFile) throws IOException, URISyntaxException {

  MultiPropertyResolver multiResolver = new MultiPropertyResolver();
  multiResolver.addPropertyResolver(new ResolvablePropertyResolver(config));

  File f = URIUtil.toFile(configFile.getResolvedConfigFileURL().toURI());
  if (f != null) {
    multiResolver.addPropertyResolver(new StandardPropertyResolver(f.toString()));
  } else {
    multiResolver.addPropertyResolver(
            new StandardPropertyResolver(configFile.getResolvedConfigFileURL().toString()));
  }

  multiResolver.addPropertyResolver(new ClasspathVariableResolver());
  multiResolver.addPropertyResolver(new SystemPropertyResolver());

  if (configFile.getAdditionalPropertiesBundleStream() != null) {
    ResourceBundle bundle = new PropertyResourceBundle(
            configFile.getAdditionalPropertiesBundleStream());
    multiResolver.addPropertyResolver(new ResourceBundlePropertyResolver(bundle));
  }

  return multiResolver;
}
 
Example 3
Source File: InternalConfigurationType.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void notifyCheckConfigRemoved(ICheckConfiguration checkConfiguration)
        throws CheckstylePluginException {
  super.notifyCheckConfigRemoved(checkConfiguration);

  // remove the configuration file from the workspace metadata
  URL configFileURL = checkConfiguration.getResolvedConfigurationFileURL();
  if (configFileURL != null) {

    try {
      File configFile = URIUtil.toFile(configFileURL.toURI());

      if (configFile != null) {
        configFile.delete();
      }
    } catch (URISyntaxException e) {
      CheckstylePluginException.rethrow(e);
    }
  }
}
 
Example 4
Source File: DataflowProjectCreator.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private DataflowProjectValidationStatus validateProjectLocation() {
  if (!customLocation || projectLocation == null) {
    return DataflowProjectValidationStatus.OK;
  }

  File file = URIUtil.toFile(projectLocation);
  if (file == null) {
    return DataflowProjectValidationStatus.LOCATION_NOT_LOCAL;
  }
  if (!file.exists()) {
    return DataflowProjectValidationStatus.NO_SUCH_LOCATION;
  }
  if (!file.isDirectory()) {
    return DataflowProjectValidationStatus.LOCATION_NOT_DIRECTORY;
  }
  return DataflowProjectValidationStatus.OK;
}
 
Example 5
Source File: TestVMType.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static File getFakeJDKsLocation() {
	Bundle bundle = Platform.getBundle(JavaLanguageServerTestPlugin.PLUGIN_ID);
	try {
		URL url = FileLocator.toFileURL(bundle.getEntry(FAKE_JDK));
		File file = URIUtil.toFile(URIUtil.toURI(url));
		return file;
	} catch (IOException | URISyntaxException e) {
		JavaLanguageServerPlugin.logException(e.getMessage(), e);
		return null;
	}
}
 
Example 6
Source File: TmfTraceManagerUtilityTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test the {@link TmfTraceManager#getTemporaryDirPath} method.
 * @throws URISyntaxException
 *              in case of URI syntax error
 */
@Test
public void testTemporaryDirPath() throws URISyntaxException {
    String tempDirPath = TmfTraceManager.getTemporaryDirPath();
    assertTrue(tempDirPath.endsWith(TEMP_DIR_NAME));

    String property = System.getProperty("osgi.instance.area"); //$NON-NLS-1$
    File dir = URIUtil.toFile(URIUtil.fromString(property));
    String basePath = dir.getAbsolutePath();
    assertTrue(tempDirPath.startsWith(basePath));
}
 
Example 7
Source File: DeleteEditorFileHandler.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private static File getFile( IEditorInput editorInput ) {
  File result = null;
  if( editorInput instanceof IPathEditorInput ) {
    IPathEditorInput pathEditorInput = ( IPathEditorInput )editorInput;
    result = pathEditorInput.getPath().toFile();
  } else if( editorInput instanceof IURIEditorInput ) {
    IURIEditorInput uriEditorInput = ( IURIEditorInput )editorInput;
    result = URIUtil.toFile( uriEditorInput.getURI() );
  }
  return result;
}
 
Example 8
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the {@link File} of a <code>file:</code> URL. This method tries to recover from bad URLs,
 * e.g. the unencoded form we used to use in persistent storage.
 * 
 * @param url a <code>file:</code> URL
 * @return the file
 * @since 3.9
 */
public static File toFile(URL url) {
	try {
		return URIUtil.toFile(url.toURI());
	} catch (URISyntaxException e) {
		JavaPlugin.log(e);
		return new File(url.getFile());
	}
}
 
Example 9
Source File: ResourceUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static File toFile(URI uri) {
	if (Platform.OS_WIN32.equals(Platform.getOS())) {
		return URIUtil.toFile(uri);
	}
	return new File(uri);
}
 
Example 10
Source File: JavaDocLocations.java    From eclipse.jdt.ls with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Returns the {@link File} of a <code>file:</code> URL. This method tries to
 * recover from bad URLs, e.g. the unencoded form we used to use in persistent
 * storage.
 *
 * @param url
 *            a <code>file:</code> URL
 * @return the file
 * @since 3.9
 */
public static File toFile(URL url) {
	try {
		return URIUtil.toFile(url.toURI());
	} catch (URISyntaxException e) {
		//JavaPlugin.log(e);
		return new File(url.getFile());
	}
}