/**
   * Creates new symbolic file system link from file or folder on project root to another file
   * system file. The filename can include relative path as a part of the name but the the path has
   * to be present on disk.
   *
   * @param project - project where to create the file.
   * @param linkName - name of the link being created.
   * @param realPath - file or folder on the file system, the target of the link.
   * @return file handle.
   * @throws UnsupportedOperationException on Windows where links are not supported.
   * @throws IOException...
   * @throws CoreException...
   */
  public static IResource createSymbolicLink(IProject project, String linkName, IPath realPath)
      throws IOException, CoreException, UnsupportedOperationException {

    if (!isSymbolicLinkSupported()) {
      throw new UnsupportedOperationException("Windows links .lnk are not supported.");
    }

    Assert.assertTrue(
        "Path for symbolic link does not exist: [" + realPath.toOSString() + "]",
        new File(realPath.toOSString()).exists());

    IPath linkedPath = project.getLocation().append(linkName);
    createSymbolicLink(linkedPath, realPath);

    IResource resource = project.getFile(linkName);
    resource.refreshLocal(IResource.DEPTH_ZERO, null);

    if (!resource.exists()) {
      resource = project.getFolder(linkName);
      resource.refreshLocal(IResource.DEPTH_ZERO, null);
    }
    Assert.assertTrue("Failed to create resource form symbolic link", resource.exists());

    externalFilesCreated.add(linkedPath.toOSString());
    ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, NULL_MONITOR);
    return resource;
  }
Exemple #2
0
 public void refreshOutputDir(final IProject project) throws CoreException {
   final IErlProject erlProject = ErlModelManager.getErlangModel().getErlangProject(project);
   final IPath outputDir = erlProject.getOutputLocation();
   final IResource ebinDir = project.findMember(outputDir);
   if (ebinDir != null) {
     ebinDir.refreshLocal(IResource.DEPTH_ONE, null);
   }
 }
Exemple #3
0
  private void buildMetaInf(IPath outputLocation, IProgressMonitor monitor)
      throws CoreException, JavaModelException {
    IProject project = getProject();
    IFolder metaInf = project.getFolder(META_INF);

    if (!metaInf.exists()) {
      error("META-INF folder not found for project: " + getProject().getName()); // $NON-NLS-1$
      return;
    }

    IFolder binFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputLocation);
    if (!binFolder.exists()) {
      binFolder.create(true, true, null);
    } else {
      binFolder.refreshLocal(IResource.DEPTH_ONE, null);
    }
    IFolder binaryMetaInf = binFolder.getFolder(META_INF);
    if (!binaryMetaInf.exists()) {
      binaryMetaInf.create(true, true, null);
    } else {
      binaryMetaInf.refreshLocal(IResource.DEPTH_ONE, null);
    }

    SubProgressMonitor sub = new SubProgressMonitor(monitor, 1);

    IResource[] children = metaInf.members();
    sub.beginTask(Messages.Builder_CopyMetaInfContent, children.length);
    for (IResource iResource : children) {
      if (!iResource.isTeamPrivateMember() && !iResource.isDerived()) {
        IPath target = binaryMetaInf.getFullPath().append(iResource.getName());
        IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(target);
        if (res != null && res.exists()) {
          if (DEBUG) {
            debug(res.getFullPath().toString() + " exists, deleting"); // $NON-NLS-1$
          }
          res.refreshLocal(IResource.DEPTH_INFINITE, null);
          res.delete(true, null);
          if (DEBUG) {
            debug(res.getFullPath().toString() + " deleted"); // $NON-NLS-1$
          }
        }
        iResource.copy(target, true, null);
        if (DEBUG) {
          debug(
              "Copied "
                  + iResource.getFullPath().toString()
                  + " to "
                  + target.toString()); // $NON-NLS-1$ //$NON-NLS-2$
        }
      }
      sub.worked(1);
    }
    monitor.done();
  }
 public static boolean refreshLocal(IWorkbenchWindow window, String param) {
   try {
     IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
     IResource resource = workspaceRoot.findMember(param);
     // refresh resource
     resource.refreshLocal(IResource.DEPTH_INFINITE, monitor);
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
   return true;
 }
Exemple #5
0
 private void refreshDirs(final IProject project, final OtpErlangObject element) {
   final OtpErlangList list = (OtpErlangList) element;
   for (final OtpErlangObject ebeam : list) {
     final OtpErlangString beam = (OtpErlangString) ebeam;
     IPath p = new Path(beam.stringValue());
     p = p.removeLastSegments(1);
     p = p.removeFirstSegments(project.getLocation().segmentCount());
     final String projectName = project.getName();
     // FIXME hardcoded "_erl" suffix
     if (projectName.endsWith("_erl")) {
       final String linkname = projectName.substring(0, projectName.length() - 4);
       p = new Path(linkname).append(p);
     }
     final IResource dir = project.findMember(p);
     if (dir != null) {
       try {
         dir.refreshLocal(IResource.DEPTH_ONE, null);
       } catch (final CoreException e) {
       }
     }
   }
 }
Exemple #6
0
 private void registerInWorkspaceIfNeeded() {
   IPath jarPath = fJarPackage.getAbsolutePharLocation();
   IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
   for (int i = 0; i < projects.length; i++) {
     IProject project = projects[i];
     // The Jar is always put into the local file system. So it can only be
     // part of a project if the project is local as well. So using getLocation
     // is currently save here.
     IPath projectLocation = project.getLocation();
     if (projectLocation != null && projectLocation.isPrefixOf(jarPath)) {
       try {
         jarPath = jarPath.removeFirstSegments(projectLocation.segmentCount());
         jarPath = jarPath.removeLastSegments(1);
         IResource containingFolder = project.findMember(jarPath);
         if (containingFolder != null && containingFolder.isAccessible())
           containingFolder.refreshLocal(IResource.DEPTH_ONE, null);
       } catch (CoreException ex) {
         // don't refresh the folder but log the problem
         PHPUiPlugin.log(ex);
       }
     }
   }
 }
 protected void do_refreshResources(IProgressMonitor pm) throws CoreException {
   lockingRule.refreshLocal(IResource.DEPTH_INFINITE, pm);
 }