public static void deleteFile(VirtualFile file) { try { file.delete(StudyUtils.class); } catch (IOException e) { LOG.error(e); } }
public void testRevertingMoveFromOldRevisionsWhenDirDoesNotExists() throws Exception { VirtualFile dir1 = myRoot.createChildDirectory(this, "dir1"); VirtualFile dir2 = myRoot.createChildDirectory(this, "dir2"); VirtualFile f = dir1.createChildData(this, "foo.txt"); f.move(this, dir2); dir1.delete(this); dir2.delete(this); revertChange(2); dir1 = myRoot.findChild("dir1"); assertNotNull(dir1); assertNull(myRoot.findChild("dir2")); assertNotNull(dir1.findChild("foo.txt")); }
public void testRevertingFromOldRevisionsWhenFileAlreadyDeleted() throws Exception { VirtualFile f = myRoot.createChildData(this, "foo.txt"); f.delete(this); revertChange(1); assertNull(myRoot.findChild("foo.txt")); }
public static void deleteFile(@NotNull Object requestor, @NotNull VirtualFile virtualFile) throws IOException { AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(null); try { virtualFile.delete(requestor); } catch (FileNotFoundException e) { throw new ReadOnlyModificationException(virtualFile); } finally { token.finish(); } }
public void testFileDeletion() throws Exception { VirtualFile f = myRoot.createChildData(this, "foo.txt"); f.setBinaryContent(new byte[] {123}, -1, 4000); f.delete(this); revertLastChange(); f = myRoot.findChild("foo.txt"); assertNotNull(f); assertEquals(123, f.contentsToByteArray()[0]); assertEquals(4000, f.getTimeStamp()); }
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()); }
private void delete(File file) throws IOException { VirtualFile vFile = myFileSystem.findFileByIoFile(file); if (vFile != null) { AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(getClass()); try { vFile.delete(this); } finally { token.finish(); } } if (file.exists()) { FileUtil.delete(file); } }
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")); }
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()); }
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()); } context.addAffectedFile(getTarget(fileToPatch)); if (myPatch.isNewFile()) { applyCreate(fileToPatch, commitContext); } else if (myPatch.isDeletedFile()) { FileEditorManagerImpl.getInstance(project).closeFile(fileToPatch); fileToPatch.delete(this); } else { return applyChange(project, fileToPatch, pathBeforeRename, baseContents); } return SUCCESS; }
private static void doAction( final Project project, final GenerateSchemaFromInstanceDocumentDialog dialog) { FileDocumentManager.getInstance().saveAllDocuments(); final String url = dialog.getUrl().getText(); final VirtualFile relativeFile = VfsUtilCore.findRelativeFile( ExternalResourceManager.getInstance().getResourceLocation(url), null); VirtualFile relativeFileDir; if (relativeFile == null) { Messages.showErrorDialog( project, XmlBundle.message("file.doesnt.exist", url), XmlBundle.message("error")); return; } else { relativeFileDir = relativeFile.getParent(); } if (relativeFileDir == null) { Messages.showErrorDialog( project, XmlBundle.message("file.doesnt.exist", url), XmlBundle.message("error")); return; } @NonNls List<String> parameters = new LinkedList<String>(); parameters.add("-design"); parameters.add(DESIGN_TYPES.get(dialog.getDesignType())); parameters.add("-simple-content-types"); parameters.add(CONTENT_TYPES.get(dialog.getSimpleContentType())); parameters.add("-enumerations"); String enumLimit = dialog.getEnumerationsLimit(); parameters.add("0".equals(enumLimit) ? "never" : enumLimit); parameters.add("-outDir"); final String dirPath = relativeFileDir.getPath(); parameters.add(dirPath); final File expectedSchemaFile = new File(dirPath + File.separator + relativeFile.getName() + "0.xsd"); if (expectedSchemaFile.exists()) { if (!expectedSchemaFile.delete()) { Messages.showErrorDialog( project, XmlBundle.message("cant.delete.file", expectedSchemaFile.getPath()), XmlBundle.message("error")); return; } } parameters.add("-outPrefix"); parameters.add(relativeFile.getName()); parameters.add(url); File xsd = new File(dirPath + File.separator + dialog.getTargetSchemaName()); final VirtualFile xsdFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xsd); if (xsdFile != null) { ApplicationManager.getApplication() .runWriteAction( () -> { try { xsdFile.delete(null); } catch (IOException e) { // } }); } Inst2Xsd.main(ArrayUtil.toStringArray(parameters)); if (expectedSchemaFile.exists()) { final boolean renamed = expectedSchemaFile.renameTo(xsd); if (!renamed) { Messages.showErrorDialog( project, XmlBundle.message("cant.rename.file", expectedSchemaFile.getPath(), xsd.getPath()), XmlBundle.message("error")); } } VirtualFile xsdVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(xsd); if (xsdVFile != null) { FileEditorManager.getInstance(project).openFile(xsdVFile, true); } else { Messages.showErrorDialog( project, XmlBundle.message("xml2xsd.generator.error.message"), XmlBundle.message("xml2xsd.generator.error")); } }