/**
   * Returns the link target location entered by the user.
   *
   * @return the link target location entered by the user. null if the user chose not to create a
   *     link.
   */
  public URI getLinkTargetURI() {
    if (!createLink) {
      return null;
    }
    // resolve path variable if we have a relative path
    if (!linkTarget.startsWith("/")) { // $NON-NLS-1$
      IPathVariableManager pathVariableManager =
          RemoteResourcesPlugin.getWorkspace().getPathVariableManager();
      try {

        URI path = new URI(linkTarget.replace(java.io.File.separatorChar, '/'));
        URI resolved = pathVariableManager.resolveURI(path);
        if (path != resolved) {
          // we know this is a path variable, but return unresolved
          // path so resource will be created with variable intact
          return path;
        }
      } catch (URISyntaxException e) {
        // link target is not a valid URI. Fall through to handle this
        // below
      }
    }

    FileSystemConfiguration configuration = getSelectedConfiguration();
    if (configuration == null) {
      return URIUtil.toURI(linkTarget);
    }
    // validate non-local file system location
    return configuration.getContributor().getURI(linkTarget);
  }
 protected void doFSSetUp() throws Exception {
   repositoryPath = getRandomLocation();
   URI uri = URIUtil.toURI(repositoryPath); // encoded
   StringBuffer sb = new StringBuffer();
   sb.append(GitFileSystem.SCHEME_GIT);
   sb.append("://test/");
   sb.append(uri.toString());
   sb.append("?/");
   baseStore = EFS.getStore(URI.create(sb.toString()));
   baseStore.mkdir(EFS.NONE, null);
 }
 /**
  * Returns the URI for the specific editor input.
  *
  * @param input the editor input
  * @return the URI, or null if none could be determined
  */
 public static URI getURI(IEditorInput input) {
   if (input instanceof IFileEditorInput) {
     return ((IFileEditorInput) input).getFile().getLocationURI();
   }
   if (input instanceof IURIEditorInput) {
     return ((IURIEditorInput) input).getURI();
   }
   if (input instanceof IPathEditorInput) {
     return URIUtil.toURI(((IPathEditorInput) input).getPath());
   }
   return null;
 }
  public void testVirtualFolderInLinkedFolder() {
    // setup handles
    IFolder topFolder = existingProject.getFolder("topFolder");
    IFolder linkedFolder = topFolder.getFolder("linkedFolder");
    IFolder subFolder = linkedFolder.getFolder("subFolder");
    IFolder virtualFolder = subFolder.getFolder("virtualFolder");

    IPath linkedFolderLocation = getRandomLocation();
    IPath subFolderLocation = linkedFolderLocation.append(subFolder.getName());

    try {
      try {
        // create the structure on disk
        linkedFolderLocation.toFile().mkdir();
        subFolderLocation.toFile().mkdir();

        // create the structure in the workspace
        ensureExistsInWorkspace(topFolder, true);
        linkedFolder.createLink(linkedFolderLocation, IResource.NONE, getMonitor());
        virtualFolder.create(IResource.VIRTUAL, true, getMonitor());
      } catch (CoreException e) {
        fail("1.0", e);
      }

      // assert locations
      assertEquals("2.0", linkedFolderLocation, linkedFolder.getLocation());
      assertEquals(
          "3.0", linkedFolderLocation.append(subFolder.getName()), subFolder.getLocation());
      assertTrue("4.0", virtualFolder.isVirtual());
      assertTrue("5.0", virtualFolder.getLocation() == null);

      // assert URIs
      assertEquals("6.0", URIUtil.toURI(linkedFolderLocation), linkedFolder.getLocationURI());
      assertEquals("7.0", URIUtil.toURI(subFolderLocation), subFolder.getLocationURI());
      // assertTrue("8.0", virtualFolder.getLocationURI() == null);
    } finally {
      Workspace.clear(subFolderLocation.toFile());
      Workspace.clear(linkedFolderLocation.toFile());
    }
  }
  private ISourceContainer getArchiveSourceContainer(String location) throws JavaModelException {
    IWorkspaceRoot root = PDELaunchingPlugin.getWorkspace().getRoot();
    IFile[] containers = root.findFilesForLocationURI(URIUtil.toURI(location));
    for (int i = 0; i < containers.length; i++) {
      IJavaElement element = JavaCore.create(containers[i]);
      if (element instanceof IPackageFragmentRoot) {
        IPackageFragmentRoot archive = (IPackageFragmentRoot) element;
        IPath path = archive.getSourceAttachmentPath();
        if (path == null || path.segmentCount() == 0) continue;

        IPath rootPath = archive.getSourceAttachmentRootPath();
        boolean detectRootPath = rootPath != null && rootPath.segmentCount() > 0;

        IFile archiveFile = root.getFile(path);
        if (archiveFile.exists()) return new ArchiveSourceContainer(archiveFile, detectRootPath);

        File file = path.toFile();
        if (file.exists())
          return new ExternalArchiveSourceContainer(file.getAbsolutePath(), detectRootPath);
      }
    }
    return null;
  }
 /**
  * Returns the resource being edited in the given workbench part.
  *
  * @param part Workbench part to checm.
  * @return Resource being edited.
  */
 protected static IResource getResource(IWorkbenchPart part) {
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   if (part instanceof IEditorPart) {
     IEditorInput editorInput = ((IEditorPart) part).getEditorInput();
     IResource resource = null;
     if (editorInput instanceof IFileEditorInput) {
       resource = ((IFileEditorInput) editorInput).getFile();
     } else if (editorInput instanceof ExternalEditorInput) {
       resource = ((ExternalEditorInput) editorInput).getMarkerResource();
     }
     if (resource != null) return resource;
     /* This file is not in a project, let default case handle it */
     ILocationProvider provider =
         (ILocationProvider) editorInput.getAdapter(ILocationProvider.class);
     if (provider != null) {
       IPath location = provider.getPath(editorInput);
       if (location != null) {
         IFile[] files = root.findFilesForLocationURI(URIUtil.toURI(location));
         if (files.length > 0 && files[0].isAccessible()) return files[0];
       }
     }
   }
   return root;
 }
 /**
  * Returns the current project location URI as entered by the user, or <code>null</code> if a
  * valid project location has not been entered.
  *
  * @return the project location URI, or <code>null</code>
  */
 public URI getLocationURI() {
   String path = getLocationPath().toOSString();
   return URIUtil.toURI(path);
 }
 public static URI getTmpURIPath(final String fileName) {
   return URIUtil.toURI(getTmpPath(fileName).toPortableString());
 }
 /**
  * Returns the current project location path as entered by the user, or <code>null</code> if the
  * project should be created in the workspace.
  *
  * @return the project location path or its anticipated initial value.
  */
 public URI getProjectLocationURI() {
   if (fLocationGroup.isLocationInWorkspace()) {
     return null;
   }
   return URIUtil.toURI(fLocationGroup.getLocation());
 }
 /**
  * Returns the current project location path as entered by the user, or <code>null</code> if the
  * project should be created in the workspace. Note that the last segment of the path is the
  * project name.
  *
  * @return the project location path or its anticipated initial value.
  */
 public URI getProjectLocationURI() {
   if (fLocationGroup.isDefaultLocation()) {
     return null;
   }
   return URIUtil.toURI(fLocationGroup.getLocation());
 }