Ejemplo n.º 1
0
  /**
   * Performs a git clone to a temporary location and then copies the files over top the already
   * generated project. This is because git cannot clone into an existing directory.
   *
   * @param monitor
   * @throws Exception
   */
  protected void cloneAfter(IProgressMonitor monitor) throws Exception {
    SubMonitor sub =
        SubMonitor.convert(monitor, Messages.AbstractNewProjectWizard_CloningFromGitMsg, 100);
    // clone to tmp dir then copy files over top the project!
    File tmpFile = File.createTempFile("delete_me", "tmp"); // $NON-NLS-1$ //$NON-NLS-2$
    File dest = new File(tmpFile.getParent(), "git_clone_tmp"); // $NON-NLS-1$
    GitExecutable.instance()
        .clone(
            selectedTemplate.getLocation(),
            Path.fromOSString(dest.getAbsolutePath()),
            true,
            sub.newChild(85));

    IFileStore tmpClone = EFS.getStore(dest.toURI());
    // Wipe the .git folder before copying? Wipe the .project file before copying?
    IFileStore dotGit = tmpClone.getChild(".git"); // $NON-NLS-1$
    dotGit.delete(EFS.NONE, sub.newChild(2));

    IFileStore dotProject = tmpClone.getChild(IProjectDescription.DESCRIPTION_FILE_NAME);
    if (dotProject.fetchInfo().exists()) {
      dotProject.delete(EFS.NONE, sub.newChild(1));
    }
    // OK, copy the cloned template's contents over
    IFileStore projectStore = EFS.getStore(newProject.getLocationURI());
    tmpClone.copy(projectStore, EFS.OVERWRITE, sub.newChild(9));
    // Now get rid of the temp clone!
    tmpClone.delete(EFS.NONE, sub.newChild(3));
    sub.done();
  }
Ejemplo n.º 2
0
 /*
  * Resilient delete. Will retry a few times if necessary before giving up. This should
  * get rid of most issues with concurrent file access on Windows.
  */
 private void safeDelete(IFileStore root) throws CoreException {
   for (int i = 0; i < 3; i++)
     try {
       root.delete(EFS.NONE, null);
       // worked!
       return;
     } catch (CoreException e) {
       try {
         Thread.sleep(50 + 100 * i);
       } catch (InterruptedException e1) {
         // nah
       }
     }
   root.delete(EFS.NONE, null);
 }
Ejemplo n.º 3
0
 private void clean(IFileStore root, boolean deleteIfEmpty, IProgressMonitor monitor)
     throws CoreException {
   if (monitor.isCanceled()) throw new OperationCanceledException();
   if (isUMLFile(root) && MDDUtil.isGenerated(root.toURI())) {
     safeDelete(root);
     return;
   }
   IFileStore[] children = root.childStores(EFS.NONE, null);
   for (int i = 0; i < children.length; i++) clean(children[i], false, monitor);
   if (deleteIfEmpty && root.childStores(EFS.NONE, null).length == 0) root.delete(EFS.NONE, null);
 }
Ejemplo n.º 4
0
 private boolean handleDelete(
     HttpServletRequest request, HttpServletResponse response, IFileStore dir)
     throws JSONException, CoreException, ServletException, IOException {
   dir.delete(EFS.NONE, null);
   return true;
 }
Ejemplo n.º 5
0
  @Test
  public void testRemoteFileProxyOnSyncProject() {
    IRemoteFileProxy fileProxy = null;
    try {
      fileProxy = proxyManager.getFileProxy(syncProject.getProject());
      assertTrue("Should have returned a remote launcher", fileProxy instanceof RDTFileProxy);
    } catch (CoreException e) {
      fail("Should have returned a launcher: " + e.getCause());
    }
    String ds = fileProxy.getDirectorySeparator();
    assertNotNull(ds);

    SyncConfig config = getSyncConfig(syncProject.getProject());
    String projectLocation = config.getLocation();
    assertNotNull(projectLocation);
    IRemoteConnection conn = null;
    String connScheme = null;
    try {
      conn = config.getRemoteConnection();
      connScheme = conn.getConnectionType().getScheme();
    } catch (MissingConnectionException e) {
      fail("Unabled to get remote connection: " + e.getMessage());
    }

    /*
     *  Test getResource()
     */
    IFileStore fs = fileProxy.getResource(projectLocation);
    assertNotNull(fs);
    assertEquals(
        "Remote connection and FileStore schemes diverge", connScheme, fs.toURI().getScheme());
    // assertTrue(fs.fetchInfo().isDirectory());

    fs = fileProxy.getResource("/filenotexits");
    assertNotNull(fs);
    IFileInfo fileInfo = fs.fetchInfo();
    assertNotNull(fileInfo);
    assertFalse(fileInfo.exists());

    /*
     * Test getWorkingDir()
     */
    URI workingDir = fileProxy.getWorkingDir();
    assertNotNull(workingDir);
    assertEquals("Remote connection and URI schemes diverge", connScheme, workingDir.getScheme());

    /*
     * Test toPath()
     */
    URI uri = null;
    try {
      uri = new URI(connScheme, conn.getName(), projectLocation, null, null);
    } catch (URISyntaxException e) {
      fail("Failed to build URI for the test: " + e.getMessage());
    }
    assertEquals(projectLocation, fileProxy.toPath(uri));

    /*
     * Test it opens connection
     */
    assertNotNull(conn);
    conn.close();
    assertFalse(conn.isOpen());
    try {
      fileProxy = proxyManager.getFileProxy(syncProject.getProject());
      assertNotNull(fileProxy);
    } catch (CoreException e) {
      fail("Failed to obtain file proxy when connection is closed: " + e.getMessage());
    }
    fs = fileProxy.getResource("/tmp/somedir");
    assertNotNull(fs);
    assertFalse(fs.fetchInfo().exists());
    try {
      fs.mkdir(EFS.SHALLOW, new NullProgressMonitor());
    } catch (CoreException e) {
      fail("should be able to create a directory when connection is closed: " + e.getMessage());
    }
    assertTrue(fs.fetchInfo().exists());
    try {
      fs.delete(EFS.NONE, new NullProgressMonitor());
    } catch (CoreException e) {
      fail("Failed to delete file: " + e.getMessage());
    }
  }
Ejemplo n.º 6
0
  @Override
  public void create(InputStream content, int updateFlags, IProgressMonitor monitor)
      throws CoreException {
    final boolean monitorNull = monitor == null;
    monitor = Policy.monitorFor(monitor);
    try {
      String message =
          monitorNull ? "" : NLS.bind(Messages.resources_creating, getFullPath()); // $NON-NLS-1$
      monitor.beginTask(message, Policy.totalWork);
      checkValidPath(path, FILE, true);
      final ISchedulingRule rule = workspace.getRuleFactory().createRule(this);
      try {
        workspace.prepareOperation(rule, monitor);
        checkDoesNotExist();
        Container parent = (Container) getParent();
        ResourceInfo info = parent.getResourceInfo(false, false);
        parent.checkAccessible(getFlags(info));
        checkValidGroupContainer(parent, false, false);

        workspace.beginOperation(true);
        IFileStore store = getStore();
        IFileInfo localInfo = store.fetchInfo();
        if (BitMask.isSet(updateFlags, IResource.FORCE)) {
          if (!Workspace.caseSensitive) {
            if (localInfo.exists()) {
              String name = getLocalManager().getLocalName(store);
              if (name == null || localInfo.getName().equals(name)) {
                delete(true, null);
              } else {
                // The file system is not case sensitive and there is already a file
                // under this location.
                message =
                    NLS.bind(
                        Messages.resources_existsLocalDifferentCase,
                        new Path(store.toString()).removeLastSegments(1).append(name).toOSString());
                throw new ResourceException(
                    IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null);
              }
            }
          }
        } else {
          if (localInfo.exists()) {
            // return an appropriate error message for case variant collisions
            if (!Workspace.caseSensitive) {
              String name = getLocalManager().getLocalName(store);
              if (name != null && !localInfo.getName().equals(name)) {
                message =
                    NLS.bind(
                        Messages.resources_existsLocalDifferentCase,
                        new Path(store.toString()).removeLastSegments(1).append(name).toOSString());
                throw new ResourceException(
                    IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), message, null);
              }
            }
            message = NLS.bind(Messages.resources_fileExists, store.toString());
            throw new ResourceException(
                IResourceStatus.FAILED_WRITE_LOCAL, getFullPath(), message, null);
          }
        }
        monitor.worked(Policy.opWork * 40 / 100);

        info = workspace.createResource(this, updateFlags);
        boolean local = content != null;
        if (local) {
          try {
            internalSetContents(
                content,
                localInfo,
                updateFlags,
                false,
                Policy.subMonitorFor(monitor, Policy.opWork * 60 / 100));
          } catch (CoreException e) {
            // a problem happened creating the file on disk, so delete from the workspace and disk
            workspace.deleteResource(this);
            store.delete(EFS.NONE, null);
            throw e; // rethrow
          } catch (OperationCanceledException e) {
            // the operation of setting contents has been canceled, so delete the file from the
            // workspace and disk
            workspace.deleteResource(this);
            store.delete(EFS.NONE, null);
            throw e;
          }
        }
        internalSetLocal(local, DEPTH_ZERO);
        if (!local) getResourceInfo(true, true).clearModificationStamp();
      } catch (OperationCanceledException e) {
        workspace.getWorkManager().operationCanceled();
        throw e;
      } finally {
        workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
      }
    } finally {
      monitor.done();
      FileUtil.safeClose(content);
    }
  }