Java Code Examples for com.intellij.openapi.vfs.VirtualFile#delete()

The following examples show how to use com.intellij.openapi.vfs.VirtualFile#delete() . 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: ApplyFilePatchBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
public Result apply(final VirtualFile fileToPatch,
                    final ApplyPatchContext context,
                    final Project project,
                    FilePath pathBeforeRename,
                    Getter<CharSequence> baseContents,
                    CommitContext commitContext) throws IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("apply patch called for : " + fileToPatch.getPath());
  }
  if (myPatch.isNewFile()) {
    applyCreate(project, fileToPatch, commitContext);
  } else if (myPatch.isDeletedFile()) {
    FileEditorManager.getInstance(project).closeFile(fileToPatch);
    fileToPatch.delete(this);
  }
  else {
    return applyChange(project, fileToPatch, pathBeforeRename, baseContents);
  }
  return SUCCESS;
}
 
Example 2
Source File: RevisionsAndDiffsTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testRevisionsForFileCreatedWithSameNameAsDeletedOne() throws IOException {
  VirtualFile f = createFile("file.txt", "old");
  f.delete(this);
  f = createFile("file.txt", "new");

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(4, rr.size());

  Entry e = rr.get(0).findEntry();
  assertEquals("file.txt", e.getName());
  assertContent("new", e);

  assertNull(rr.get(1).findEntry());

  e = rr.get(2).findEntry();
  assertEquals("file.txt", e.getName());
  assertContent("old", e);

  assertNull(rr.get(3).findEntry());
}
 
Example 3
Source File: DifferenceReverterTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testRevertingContentChangeFromOldRevisionsWhenDirDoesNotExists() throws Exception {
  VirtualFile dir = myRoot.createChildDirectory(this, "dir");
  VirtualFile f = dir.createChildData(this, "foo.txt");

  f.setBinaryContent(new byte[]{1}, -1, 1000);
  f.setBinaryContent(new byte[]{2}, -1, 2000);

  dir.delete(this);

  revertChange(1);

  dir = myRoot.findChild("dir");
  assertNotNull(dir);
  f = dir.findChild("foo.txt");
  assertNotNull(f);
  assertEquals(1, f.contentsToByteArray()[0]);
  assertEquals(1000, f.getTimeStamp());
}
 
Example 4
Source File: UndoChangeRevertingVisitor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(MoveChange c) throws StopVisitingException {
  if (shouldRevert(c)) {
    VirtualFile f = myGateway.findVirtualFile(c.getPath());
    if (f != null) {
      try {
        VirtualFile parent = myGateway.findOrCreateFileSafely(c.getOldParent(), true);
        VirtualFile existing = parent.findChild(f.getName());
        if (existing != null) existing.delete(LocalHistory.VFS_EVENT_REQUESTOR);
        f.move(LocalHistory.VFS_EVENT_REQUESTOR, parent);
      }
      catch (IOException e) {
        throw new RuntimeIOException(e);
      }
    }
  }
  checkShouldStop(c);
}
 
Example 5
Source File: UndoChangeRevertingVisitor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(RenameChange c) throws StopVisitingException {
  if (shouldRevert(c)) {
    VirtualFile f = myGateway.findVirtualFile(c.getPath());
    if (f != null) {
      VirtualFile existing = f.getParent().findChild(c.getOldName());
      try {
        if (existing != null && !Comparing.equal(existing, f)) {
          existing.delete(LocalHistory.VFS_EVENT_REQUESTOR);
        }
        f.rename(LocalHistory.VFS_EVENT_REQUESTOR, c.getOldName());
      }
      catch (IOException e) {
        throw new RuntimeIOException(e);
      }
    }
  }
  checkShouldStop(c);
}
 
Example 6
Source File: UndoChangeRevertingVisitor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(CreateEntryChange c) throws StopVisitingException {
  if (shouldRevert(c)) {
    VirtualFile f = myGateway.findVirtualFile(c.getPath());
    if (f != null) {
      unregisterDelayedApplies(f);
      try {
        f.delete(LocalHistory.VFS_EVENT_REQUESTOR);
      }
      catch (IOException e) {
        throw new RuntimeIOException(e);
      }
    }
  }
  checkShouldStop(c);
}
 
Example 7
Source File: IntellijFolder.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Deletes the folder in the filesystem.
 *
 * @throws IOException if the resource is a file or the deletion failed
 * @see VirtualFile#delete(Object)
 */
private void deleteInternal() throws IOException {
  VirtualFile virtualFile = getVirtualFile();

  if (virtualFile == null || !virtualFile.exists()) {
    log.debug("Ignoring file deletion request for " + this + " as folder does not exist");

    return;
  }

  if (!virtualFile.isDirectory()) {
    throw new IOException("Failed to delete " + this + " as it is not a folder");
  }

  virtualFile.delete(IntellijFolder.this);
}
 
Example 8
Source File: PersistentFSTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testAccessingFileByID() throws Exception {
  File dir = createTempDirectory();
  File file = new File(dir, "test.txt");
  assertTrue(file.createNewFile());

  VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
  assertNotNull(vFile);

  int id = ((VirtualFileWithId)vFile).getId();

  assertSame(vFile, PersistentFS.getInstance().findFileById(id));
  vFile.delete(this);

  assertNull(PersistentFS.getInstance().findFileById(id));
}
 
Example 9
Source File: XBreakpointManagerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testRemoveFile() {
  final VirtualFile file = myTempFiles.createVFile("breakpoint", ".txt");
  myBreakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, file.getUrl(), 0, null);
  assertOneElement(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE));
  try {
    file.delete(this);
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
  assertEmpty(myBreakpointManager.getBreakpoints(MY_LINE_BREAKPOINT_TYPE));
}
 
Example 10
Source File: DifferenceReverter.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void revertRename(Entry l, VirtualFile file) throws IOException {
  String oldName = l.getName();
  if (!oldName.equals(file.getName())) {
    VirtualFile existing = file.getParent().findChild(oldName);
    if (existing != null) {
      existing.delete(this);
    }
    file.rename(this, oldName);
  }
}
 
Example 11
Source File: RevisionsAndDiffsTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testRevisionForDirectoryWithTheSameNameAsDeletedOne() throws IOException {
  VirtualFile dir = createDirectory("dir");
  dir.delete(this);
  dir = createDirectory("dir");

  List<Revision> rr = getRevisionsFor(dir);
  assertEquals(4, rr.size());
}
 
Example 12
Source File: RevisionsAndDiffsTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testRevisionsIfSomeFilesWereDeletedDuringChangeSet() throws IOException {
  VirtualFile dir = createDirectory("dir");
  VirtualFile f = createFile("dir/f.txt");
  getVcs().beginChangeSet();
  f.delete(this);

  List<Revision> rr = getRevisionsFor(dir);
  assertEquals(4, rr.size());
}
 
Example 13
Source File: DifferenceReverterTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testDeletionOfFileAndCreationOfDirAtTheSameTime() throws Exception {
  VirtualFile f = myRoot.createChildData(this, "foo.txt");

  getVcs().beginChangeSet();
  f.delete(this);
  myRoot.createChildDirectory(this, "foo.txt");
  getVcs().endChangeSet(null);

  revertLastChange();

  f = myRoot.findChild("foo.txt");
  assertNotNull(f);
  assertFalse(f.isDirectory());
}
 
Example 14
Source File: DifferenceReverterTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testDeletionOfDirAndCreationOfFileAtTheSameTime() throws Exception {
  VirtualFile f = myRoot.createChildDirectory(this, "foo.txt");

  getVcs().beginChangeSet();
  f.delete(this);
  myRoot.createChildData(this, "foo.txt");
  getVcs().endChangeSet(null);

  revertLastChange();

  f = myRoot.findChild("foo.txt");
  assertNotNull(f);
  assertTrue(f.isDirectory());
}
 
Example 15
Source File: PsiFileImplUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void doDelete(final PsiFile file) throws IncorrectOperationException {
  final PsiManagerImpl manager = (PsiManagerImpl)file.getManager();

  final VirtualFile vFile = file.getVirtualFile();
  try{
    vFile.delete(manager);
  }
  catch(IOException e){
    throw new IncorrectOperationException(e);
  }
}
 
Example 16
Source File: RevisionsAndDiffsTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testNoDifferenceForDirectoryWithEqualContents() throws IOException {
  VirtualFile dir = createDirectory("dir");
  VirtualFile f = createFile("dir/file.txt");
  f.delete(this);

  List<Revision> rr = getRevisionsFor(dir);

  assertTrue(rr.get(0).getDifferencesWith(rr.get(2)).isEmpty());
}
 
Example 17
Source File: DifferenceReverterTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testRevertingRenameFromOldRevisionsWhenDirDoesNotExists() throws Exception {
  VirtualFile dir = myRoot.createChildDirectory(this, "dir");
  VirtualFile f = dir.createChildData(this, "foo.txt");

  f.rename(this, "bar.txt");

  dir.delete(this);

  revertChange(1);

  dir = myRoot.findChild("dir");
  assertNotNull(dir);
  assertNotNull(dir.findChild("foo.txt"));
  assertNull(dir.findChild("bar.txt"));
}
 
Example 18
Source File: RevisionsAndDiffsTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testRevisionsForFileThatWasCreatedAndDeletedInOneChangeSet() throws IOException {
  getVcs().beginChangeSet();
  VirtualFile f = createFile("f.txt");
  getVcs().endChangeSet("1");
  f.delete(this);

  getVcs().beginChangeSet();
  f = createFile("f.txt");
  f.delete(this);
  getVcs().endChangeSet("2");

  getVcs().beginChangeSet();
  f = createFile("f.txt");
  getVcs().endChangeSet("3");

  getVcs().beginChangeSet();
  f.delete(this);
  f = createFile("f.txt");
  getVcs().endChangeSet("4");

  List<Revision> rr = getRevisionsFor(f);
  assertEquals(6, rr.size());
  assertEquals("4", rr.get(1).getChangeSetName());
  assertEquals("3", rr.get(2).getChangeSetName());
  assertEquals("2", rr.get(3).getChangeSetName());
  assertEquals(null, rr.get(4).getChangeSetName());
  assertEquals("1", rr.get(5).getChangeSetName());
}
 
Example 19
Source File: FileTypeManagerTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testIgnoredFiles() throws IOException {
  VirtualFile vFile = myFixture.getTempDirFixture().createFile(".svn", "");
  assertTrue(FileTypeManager.getInstance().isFileIgnored(vFile));
  vFile.delete(this);

  vFile = myFixture.getTempDirFixture().createFile("a.txt", "");
  assertFalse(FileTypeManager.getInstance().isFileIgnored(vFile));
}
 
Example 20
Source File: PatchingTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void clearRoot() throws IOException {
  for (VirtualFile f : myRoot.getChildren()) {
    f.delete(null);
  }
}