Java 类org.eclipse.core.runtime.URIUtil 实例源码

项目:Equella    文件:WorkspaceJarModelManager.java   
private boolean isPluginJar(IFile file)
{
    if( "jar".equals(file.getFileExtension()) )
    {
        URI jarURI = URIUtil.toJarURI(file.getLocationURI(), JPFProject.MANIFEST_PATH);
        try
        {
            JarEntry jarFile = ((JarURLConnection) jarURI.toURL().openConnection()).getJarEntry();
            return jarFile != null;
        }
        catch( IOException e )
        {
            // Bad zip
        }
    }
    return false;
}
项目:google-cloud-eclipse    文件:DataflowProjectCreator.java   
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;
}
项目:Source    文件:UiIdeMappingUtils.java   
/**
 * Gets the {@link IPath} from the given {@link IEditorInput}.
 * 
 * @param editorInput
 *            the {@link IEditorInput}
 * @return the {@link IPath} from the given {@link IEditorInput} if any, <code>null</code> otherwise
 */
public static IPath getPath(final IEditorInput editorInput) {
    final IPath path;
    if (editorInput instanceof ILocationProvider) {
        path = ((ILocationProvider)editorInput).getPath(editorInput);
    } else if (editorInput instanceof IURIEditorInput) {
        final URI uri = ((IURIEditorInput)editorInput).getURI();
        if (uri != null) {
            final File osFile = URIUtil.toFile(uri);
            if (osFile != null) {
                path = Path.fromOSString(osFile.getAbsolutePath());
            } else {
                path = null;
            }
        } else {
            path = null;
        }
    } else {
        path = null;
    }
    return path;
}
项目:triquetrum    文件:PythonHelper.java   
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();
}
项目:triquetrum    文件:PythonHelper.java   
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();
}
项目:p2-installer    文件:InstallDescription.java   
/**
 * Returns a URI for a specification.
 * 
 * @param spec Specification
 * @param base Base location
 * @return URI or <code>null</code>
 */
protected URI getURI(String spec, URI base) {
    // Bad specification
    if (spec.startsWith("@"))
        return null;

    URI uri = null;
    try {
        uri = URIUtil.fromString(spec);
        String uriScheme = uri.getScheme();
        // Handle jar scheme special to support relative paths
        if ((uriScheme != null) && uriScheme.equals("jar")) { //$NON-NLS-1$
            String path = uri.getSchemeSpecificPart().substring("file:".length()); //$NON-NLS-1$
            URI relPath = URIUtil.append(base, path);
            uri = new URI("jar:" + relPath.toString());  //$NON-NLS-1$
        }
        else {
            uri = URIUtil.makeAbsolute(uri, base);
        }
    } catch (URISyntaxException e) {
        LogHelper.log(new Status(IStatus.ERROR, Installer.ID, "Invalid URL in install description: " + spec, e)); //$NON-NLS-1$
    }

    return uri;
}
项目:asup    文件:JDTSourceManagerImpl.java   
private QLibrary adapt(QJob job, IProject project) {

        try {
            if (!project.isOpen())
                project.open(null);

            IFile file = project.getFile("META-INF/MANIFEST.MF");
            InputStream is = file.getContents();

            Manifest manifest = new Manifest(is);
            Attributes attributes = manifest.getMainAttributes();
            QLibrary lib = QOperatingSystemLibraryFactory.eINSTANCE.createLibrary();
            lib.setLibrary(job.getSystem().getSystemLibrary());
            lib.setName(URIUtil.lastSegment(project.getLocationURI()));
            lib.setText(attributes.getValue("Bundle-Name"));

            is.close();

            return lib;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
项目:Equella    文件:JarPluginModelImpl.java   
@Override
protected InputStream getInputStream() throws CoreException
{
    URI uri = ((IFile) underlyingResource).getLocationURI();
    try
    {
        return URIUtil.toJarURI(uri, JPFProject.MANIFEST_PATH).toURL().openStream();
    }
    catch( IOException e )
    {
        return null;
    }
}
项目:pgcodekeeper    文件:InternalIgnoreList.java   
/**
 * Returns path to %workspace%/.metadata/.plugins/%this_plugin%/.pgcodekeeperignore.<br>
 * Handles {@link URISyntaxException} using {@link ExceptionNotifier}.
 *
 * @return path or null in case {@link URISyntaxException} has been handled.
 */
static Path getInternalIgnoreFile() {
    try {
        return Paths.get(URIUtil.toURI(Platform.getInstanceLocation().getURL()))
                .resolve(".metadata").resolve(".plugins").resolve(PLUGIN_ID.THIS) //$NON-NLS-1$ //$NON-NLS-2$
                .resolve(FILE.IGNORED_OBJECTS);
    } catch (URISyntaxException ex) {
        ExceptionNotifier.notifyDefault(Messages.InternalIgnoreList_error_workspace_path, ex);
        return null;
    }
}
项目:eclipse.jdt.ls    文件:ResourceUtils.java   
/**
 * Fix uris by adding missing // to single file:/ prefix
 */
public static String fixURI(URI uri) {
    if (Platform.OS_WIN32.equals(Platform.getOS())) {
        uri = URIUtil.toFile(uri).toURI();
    }
    String uriString = uri.toString();
    return uriString.replaceFirst("file:/([^/])", "file:///$1");
}
项目:eclipse.jdt.ls    文件:JDTUtils.java   
public static URI toURI(String uriString) {
    if (uriString == null || uriString.isEmpty()) {
        return null;
    }
    try {
        URI uri = new URI(uriString);
        if (Platform.OS_WIN32.equals(Platform.getOS()) && URIUtil.isFileURI(uri)) {
            uri = URIUtil.toFile(uri).toURI();
        }
        return uri;
    } catch (URISyntaxException e) {
        JavaLanguageServerPlugin.logException("Failed to resolve "+uriString, e);
        return null;
    }
}
项目:eclipse.jdt.ls    文件:TestVMType.java   
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;
    }
}
项目:fluentmark    文件:FileUtils.java   
/**
 * Loads the content of a file from within a bundle. Returns null if not found.
 * 
 * @param pathname of the file within the bundle.
 * @return null if not found.
 */
public static String fromBundle(String pathname) {
    Bundle bundle = Platform.getBundle(FluentMkUI.PLUGIN_ID);
    URL url = bundle.getEntry(pathname);
    if (url == null) return null;
    try {
        url = FileLocator.toFileURL(url);
        return read(URIUtil.toFile(URIUtil.toURI(url)));
    } catch (Exception e) {
        Log.error(e);
        return "";
    }
}
项目:triquetrum    文件:TestRunner.java   
private String getExampleScriptsHome() throws IOException, URISyntaxException {
  String location = System.getProperty(OVERRIDE_LOCATION_PROPERTY);
  if (location != null) {
    return location;
  }

  URL url = new URL("platform:/plugin/" + PLUGIN_ID + "/scripts");
  URL fileURL = FileLocator.toFileURL(url);
  File exampleScriptsHome = new File(URIUtil.toURI(fileURL));
  if (!exampleScriptsHome.exists()) {
    throw new IOException("Failed to find " + PLUGIN_ID + "/scripts, expected it here: " + exampleScriptsHome);
  }
  return exampleScriptsHome.toString();
}
项目:triquetrum    文件:PythonService.java   
private static String getSystemScriptsHome() throws IOException, URISyntaxException {
  URL url = new URL("platform:/plugin/" + PLUGIN_ID + "/scripts");
  URL fileURL = FileLocator.toFileURL(url);
  File systemScriptsHome = new File(URIUtil.toURI(fileURL));
  if (!systemScriptsHome.exists()) {
    throw new IOException("Failed to find " + PLUGIN_ID + "/scripts, expected it here: " + systemScriptsHome);
  }
  return systemScriptsHome.toString();
}
项目:che    文件:JavaDocLocations.java   
/**
 * Returns the {@link java.io.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) {
    LOG.error(e.getMessage(), e);
    return new File(url.getFile());
  }
}
项目:eclipse-extras    文件:DeleteEditorFileHandler.java   
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;
}
项目:p2-installer    文件:Installer.java   
/**
 * Resolves an install file.
 * 
 * @param site File URI or <code>null</code>.
 * @param filename File name
 * @return File URI
 * @throws URISyntaxException on invalid syntax
 */
private URI resolveFile(String site, String filename) throws URISyntaxException {
    // If no URL was given from the outside, look for file 
    // relative to where the installer is running.  This allows the installer to be self-contained
    if (site == null)
        site = filename;

    URI propsURI = URIUtil.fromString(site);
    if (!propsURI.isAbsolute()) {
        String installerInstallArea = System.getProperty(IInstallConstants.OSGI_INSTALL_AREA);
        if (installerInstallArea == null)
            throw new IllegalStateException(InstallMessages.Error_NoInstallArea);

        // Get the locale
        String locale = Platform.getNL();
        // Check for locale installer description
        propsURI = URIUtil.append(URIUtil.fromString(installerInstallArea), locale);
        propsURI = URIUtil.append(propsURI, site);
        File installerDescription = URIUtil.toFile(propsURI);
        // If not found, use default install description
        if (!installerDescription.exists()) {
            propsURI = URIUtil.append(URIUtil.fromString(installerInstallArea), site);
            installerDescription = URIUtil.toFile(propsURI);
            if (!installerDescription.exists()) {
                propsURI = null;
            }
        }
    }

    return propsURI;
}
项目:p2-installer    文件:Installer.java   
/**
 * Returns the path to an install file.
 * 
 * @param site File
 * @return Install file
 * @throws URISyntaxException on bad format
 */
public File getInstallFile(String site) throws URISyntaxException {
    String installArea = System.getProperty(IInstallConstants.OSGI_INSTALL_AREA);
    URI fileUri = URIUtil.append(URIUtil.fromString(installArea), site);
    File file = URIUtil.toFile(fileUri);

    return file;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaDocLocations.java   
/**
 * 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());
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavadocConfigurationBlock.java   
private void validateURL(URL location) throws MalformedURLException, URISyntaxException {
    URI path= URIUtil.toURI(location);
    URI index = URIUtil.append(path, "index.html"); //$NON-NLS-1$
    URI packagelist = URIUtil.append(path, "package-list"); //$NON-NLS-1$
    URL indexURL = URIUtil.toURL(index);
    URL packagelistURL = URIUtil.toURL(packagelist);

    boolean suc= checkURLConnection(indexURL) && checkURLConnection(packagelistURL);
    if (suc) {
        showConfirmValidationDialog(indexURL);
    } else {
        MessageDialog.openWarning(fShell, fTitle, fInvalidMessage);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocConfigurationBlock.java   
private void validateURL(URL location) throws MalformedURLException, URISyntaxException {
    URI path= URIUtil.toURI(location);
    URI index = URIUtil.append(path, "index.html"); //$NON-NLS-1$
    URI packagelist = URIUtil.append(path, "package-list"); //$NON-NLS-1$
    URL indexURL = URIUtil.toURL(index);
    URL packagelistURL = URIUtil.toURL(packagelist);

    boolean suc= checkURLConnection(indexURL) && checkURLConnection(packagelistURL);
    if (suc) {
        showConfirmValidationDialog(indexURL);
    } else {
        MessageDialog.openWarning(fShell, fTitle, fInvalidMessage);
    }
}
项目:robotpy-eclipse-plugins    文件:RobotLaunchShortcut.java   
/**
 * Runs the ant script using the correct target for the indicated mode (deploy to cRIO or just compile)
 * @param activeProj The project that the script will be run on/from
 * @param mode The mode it will be run in (ILaunchManager.RUN_MODE or ILaunchManager.DEBUG_MODE)
 */
protected void launch(FileOrResource resource, String mode){

    ILaunchConfigurationWorkingCopy workingCopy;

    try {
        ILaunchConfiguration conf = pydevLauncher.createDefaultLaunchConfigurationWithoutSaving(new FileOrResource[] { resource });

        workingCopy = conf.getWorkingCopy();

        // We have to pass the right args to robot.py AND we need to run our preexec
        // python script to make sure the environment is ok, so we can warn the user
        // -> pydev uses sitecustomize.py, but this seems easier.. 

        String args = "\"" + workingCopy.getAttribute(Constants.ATTR_LOCATION, "") + "\" " + getArgs();
        workingCopy.setAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, args);

        // set to our preexec
        URL url = new URL(WPILibPythonPlugin.getDefault().getBundle().getEntry("/resources/py/"), "preexec.py");
        File file = URIUtil.toFile(FileLocator.toFileURL(url).toURI());

        workingCopy.setAttribute(Constants.ATTR_LOCATION, getAbsPath(file));

    } catch (CoreException|IOException|URISyntaxException e) {
        RobotLaunchShortcut.reportError(null, e);
        return;
    }

    DebugUITools.launch(workingCopy, mode);
}
项目:asup    文件:JDTSourceManagerImpl.java   
private <T extends QObjectNameable> IFolder getFolder(QSourceEntry parent, Class<T> type, boolean create) {

        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = root.getProject(URIUtil.lastSegment(parent.getRoot().getLocation()));

        // TODO da eliminare
        if (parent.isRoot() && type == null)
            return project.getFolder("src");

        java.net.URI location = URIUtil.removeFileExtension(parent.getLocation());

        if (type != null) {
            location = URIUtil.append(location, bundlePath);
            location = URIUtil.append(location, getFolderName(type));
        }

        location = URIUtil.makeRelative(location, parent.getRoot().getLocation());

        IFolder folder = project.getFolder(location.toString());
        if (!folder.exists() && create) {
            try {
                folder.create(true, true, null);
            } catch (CoreException e) {
                return null;
            }
        }
        if (!folder.exists())
            return null;

        return folder;
    }
项目:pgcodekeeper    文件:ApgdiffUtils.java   
/**
 * @param url url should NOT be URL-encoded
 */
public static File getFileFromOsgiRes(URL url) throws URISyntaxException, IOException {
    return new File(
            URIUtil.toURI(url.getProtocol().equals("file") ?
                    url : FileLocator.toFileURL(url)));
}
项目:pgcodekeeper    文件:PgDbParser.java   
private static Path getPathToObject(String name) throws URISyntaxException {
    return Paths.get(URIUtil.toURI(Platform.getInstanceLocation().getURL()))
            .resolve(".metadata").resolve(".plugins").resolve(PLUGIN_ID.THIS) //$NON-NLS-1$ //$NON-NLS-2$
            .resolve("projects").resolve(name + ".ser"); //$NON-NLS-1$ //$NON-NLS-2$
}
项目:google-cloud-eclipse    文件:DataflowProjectCreator.java   
@Override
public void run(IProgressMonitor monitor)
    throws InvocationTargetException, InterruptedException, OperationCanceledException {
  if (!isValid()) {
    throw new ProjectCreationException(
        "Cannot create a project with invalid or incomplete inputs",
        "Validation Failures: " + validate());
  }
  SubMonitor progress = SubMonitor.convert(monitor, 5);
  checkCancelled(progress);

  ProjectImportConfiguration projectImportConfiguration = new ProjectImportConfiguration();
  if (projectNameTemplate != null) {
    projectImportConfiguration.setProjectNameTemplate(projectNameTemplate);
  }

  checkCancelled(progress);

  Archetype archetype = new Archetype();
  archetype.setGroupId(DataflowMavenCoordinates.GROUP_ID);
  archetype.setArtifactId(template.getArtifactId());

  Properties archetypeProperties = new Properties();
  archetypeProperties.setProperty("targetPlatform", getTargetPlatform());

  IPath location = null;
  if (customLocation) {
    location = org.eclipse.core.filesystem.URIUtil.toPath(projectLocation);
  }

  Set<ArtifactVersion> archetypeVersions;
  if (Strings.isNullOrEmpty(archetypeVersion)) {
    // TODO: Configure the creator with a targeted Major Version
    archetypeVersions = defaultArchetypeVersions(template, majorVersion);
  } else {
    archetypeVersions =
        Collections.<ArtifactVersion>singleton(new DefaultArtifactVersion(archetypeVersion));
  }

  List<IProject> projects = Collections.emptyList();
  List<CoreException> failures = new ArrayList<>();
  MultiStatus status = new MultiStatus(DataflowCorePlugin.PLUGIN_ID, 38, 
      "Creating dataflow maven archetypes", null);

  for (ArtifactVersion attemptedVersion : archetypeVersions) {
    checkCancelled(progress);
    // TODO: See if this can be done without using the toString method
    archetype.setVersion(attemptedVersion.toString());
    try {
      projects = projectConfigurationManager.createArchetypeProjects(location, archetype,
          // TODO: Get the version string from the user as well.
          mavenGroupId, mavenArtifactId, "0.0.1-SNAPSHOT", packageString, archetypeProperties,
          projectImportConfiguration, progress.newChild(4));
      break;
    } catch (CoreException ex) {
      IStatus child = StatusUtil.error(this, ex.getMessage(), ex);
      status.merge(child);
      failures.add(ex);
    }
  }
  if (projects.isEmpty()) { // failures only matter if no version succeeded
    StatusUtil.setErrorStatus(this, "Error loading dataflow archetypes", status);
    for (CoreException failure : failures) {
      DataflowCorePlugin.logError(failure, "CoreException while creating new Dataflow Project");
    }
  } else {
    SubMonitor natureMonitor = SubMonitor.convert(progress.newChild(1), projects.size());
    for (IProject project : projects) {
      try {
        DataflowJavaProjectNature.addDataflowJavaNatureToProject(
            project, natureMonitor.newChild(1));
        setPreferences(project);
      } catch (CoreException e) {
        DataflowCorePlugin.logError(e,
            "CoreException while adding Dataflow Nature to created project %s", project.getName());
      }
    }
  }
  monitor.done();
}
项目:eclipse.jdt.ls    文件:ResourceUtils.java   
public static File toFile(URI uri) {
    if (Platform.OS_WIN32.equals(Platform.getOS())) {
        return URIUtil.toFile(uri);
    }
    return new File(uri);
}
项目:APICloud-Studio    文件:LocalWebServerHttpRequestHandler.java   
private void handleRequest(HttpRequest request, HttpResponse response, boolean head) throws HttpException,
        IOException, CoreException, URISyntaxException
{
    String target = URLDecoder.decode(request.getRequestLine().getUri(), IOUtil.UTF_8);
    URI uri = URIUtil.fromString(target);
    IFileStore fileStore = uriMapper.resolve(uri);
    IFileInfo fileInfo = fileStore.fetchInfo();
    if (fileInfo.isDirectory())
    {
        fileInfo = getIndex(fileStore);
        if (fileInfo.exists())
        {
            fileStore = fileStore.getChild(fileInfo.getName());
        }
    }
    if (!fileInfo.exists())
    {
        response.setStatusCode(HttpStatus.SC_NOT_FOUND);
        response.setEntity(createTextEntity(MessageFormat.format(
                Messages.LocalWebServerHttpRequestHandler_FILE_NOT_FOUND, uri.getPath())));
    }
    else if (fileInfo.isDirectory())
    {
        response.setStatusCode(HttpStatus.SC_FORBIDDEN);
        response.setEntity(createTextEntity(Messages.LocalWebServerHttpRequestHandler_FORBIDDEN));
    }
    else
    {
        response.setStatusCode(HttpStatus.SC_OK);
        if (head)
        {
            response.setEntity(null);
        }
        else
        {
            File file = fileStore.toLocalFile(EFS.NONE, new NullProgressMonitor());
            final File temporaryFile = (file == null) ? fileStore.toLocalFile(EFS.CACHE, new NullProgressMonitor())
                    : null;
            response.setEntity(new NFileEntity((file != null) ? file : temporaryFile, getMimeType(fileStore
                    .getName()))
            {
                @Override
                public void close() throws IOException
                {
                    try
                    {
                        super.close();
                    }
                    finally
                    {
                        if (temporaryFile != null && !temporaryFile.delete())
                        {
                            temporaryFile.deleteOnExit();
                        }
                    }
                }
            });
        }
    }
}
项目:birt    文件:MoveResourceDialog.java   
/**
 * Constructs a dialog for moving resource.
 * 
 * @param files
 */
public MoveResourceDialog( final Collection<File> files )
{
    super( false, false, null );
    setTitle( Messages.getString( "MoveResourceDialog.Title" ) );
    setMessage( Messages.getString( "MoveResourceDialog.Message" ) );
    setDoubleClickSelects( true );
    setAllowMultiple( false );
    setHelpAvailable( false );
    setEmptyFolderShowStatus( IResourceContentProvider.ALWAYS_SHOW_EMPTYFOLDER );
    setValidator( new ISelectionStatusValidator( ) {

        public IStatus validate( Object[] selection )
        {
            for ( Object s : selection )
            {
                if ( s instanceof ResourceEntry )
                {
                    URL url = ( (ResourceEntry) s ).getURL( );
                    try {
                        url = URIUtil.toURI(url).toURL();
                    } catch (Exception e1) {
                    }
                    for ( File f : files )
                    {
                        try
                        {
                            if ( url.equals( f.getParentFile( )
                                    .toURI( )
                                    .toURL( ) )
                                    || url.equals( f.toURI( ).toURL( ) ) )
                                return new Status( IStatus.ERROR,
                                        ReportPlugin.REPORT_UI,
                                        "" );
                        }
                        catch ( MalformedURLException e )
                        {
                        }
                    }
                }
            }
            return new Status( IStatus.OK, ReportPlugin.REPORT_UI, "" );
        }
    } );
}
项目:emf.utils    文件:RootPreferencePage.java   
private void addListener(Link infoLabel) {
    infoLabel.addListener (SWT.Selection, new Listener() {
        @SuppressWarnings("restriction")
        @Override
        public void handleEvent(Event event) {
            try {
                switch (event.text) {
                    case "CUSTOM_REGISTRY_CLASS":
                        SpyIDEUtil.openClass("io.github.abelgomez.emf.packageregistry", "io.github.abelgomez.emf.packageregistry.impl.ObservableEPackageRegistryImpl");
                        break;
                    case "EXTENSION_POINT":
                        URL url = FileLocator.find(Platform.getBundle("org.eclipse.emf.ecore"), new Path("schema/package_registry_implementation.exsd"), null);
                        url = FileLocator.resolve(url);
                        // The url is unencoded, so we can treat it like a path, splitting it based on the jar suffix '!'
                        String stringUrl = url.getPath();
                        int jarSuffix = stringUrl.indexOf('!');
                        String fileUrl = stringUrl.substring(0, jarSuffix);
                        URI uri = URIUtil.toURI(new URL(fileUrl));
                        File jarFile = URIUtil.toFile(uri);
                        String schemaEntryName = stringUrl.substring(jarSuffix + 1);
                        if (schemaEntryName.startsWith("/")) { //$NON-NLS-1$
                            schemaEntryName = schemaEntryName.substring(1);
                        }
                        // Open the schema in a new editor
                        SchemaEditor.openSchema(jarFile, schemaEntryName);
                        break;
                    case "DEFAULT_REGISTRY":
                        SpyIDEUtil.openClass("org.eclipse.emf.ecore", "org.eclipse.emf.ecore.impl.EPackageRegistryImpl");
                        break;
                    case "CUSTOM_REGISTRY_PLUGIN":
                        SpyIDEUtil.openBundleManifest("io.github.abelgomez.emf.packageregistry");
                        break;
                    default:
                        break;
                }
            } catch (Throwable t) {
                MessageDialog.openError(getShell(), "Error", 
                        NLS.bind("Unable to open link in new editor ({0})", t.toString()));
            }
        }
    });
}
项目:target-baselines    文件:TargetBaselinePreferencePage.java   
private static IApiComponent[] addComponents(IApiBaseline baseline, ITargetDefinition targetDefinition, IProgressMonitor monitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.configuring_baseline, 50);
    IApiComponent[] result = null;
    try {
        // Acquire the service
        ITargetPlatformService service = (ITargetPlatformService) ApiPlugin.getDefault().acquireService(ITargetPlatformService.class.getName());
        IApiBaselineManager manager = ApiPlugin.getDefault().getApiBaselineManager();

        // Since this method is specific to Target's and the target would have to resolve,
        // if OSGi is not running then the environment is not in a valid state and we cannot 
        // proceed.
        if (service == null || manager == null) {
            return null;
        }

        Util.updateMonitor(subMonitor, 1);
        subMonitor.subTask(Messages.resolving_target_definition);

        ITargetLocation[] containers = targetDefinition.getTargetLocations();
        if (containers == null) {
            return null;
        }

        subMonitor.setWorkRemaining(30 * containers.length);
        List<TargetBundle> targetBundles = new ArrayList<TargetBundle>(79);
        for (int i = 0; i < containers.length; i++) {
            containers[i].resolve(targetDefinition, subMonitor.newChild(15));
            targetBundles.addAll(Arrays.asList(containers[i].getBundles()));
        }

        List<IApiComponent> components = new ArrayList<IApiComponent>(targetBundles.size());
        if (targetBundles.size() > 0) {
            subMonitor.setWorkRemaining(targetBundles.size());
            for (int i = 0; i < targetBundles.size(); i++) {
                Util.updateMonitor(subMonitor, 1);
                TargetBundle bundle = targetBundles.get(i);
                if (!bundle.isSourceBundle()) {
                    IApiComponent component = ApiModelFactory.newApiComponent(baseline, URIUtil.toFile(bundle.getBundleInfo().getLocation()).getAbsolutePath());
                    if (component != null) {
                        subMonitor.subTask(NLS.bind(Messages.adding_component__0, component.getSymbolicName()));
                        components.add(component);
                    }
                }
            }
        }

        IApiBaseline existing = manager.getApiBaseline(baseline.getName());
        if (existing != null) {
            manager.removeApiBaseline(existing.getName());
        }
        manager.addApiBaseline(baseline);

        result = components.toArray(new IApiComponent[components.size()]);
        if (result != null) {
            baseline.addApiComponents(result);
            return result;
        }

        return new IApiComponent[0];
    }
    finally {
        subMonitor.done();
    }
}