Java Code Examples for org.openide.filesystems.FileObject#delete()
The following examples show how to use
org.openide.filesystems.FileObject#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: J2seBuildScriptExtensionProvider.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void removeJaxWsExtension(final AntBuildExtender ext) throws IOException { AntBuildExtender.Extension extension = ext.getExtension(JAXWS_EXTENSION); if (extension!=null) { ProjectManager.mutex().writeAccess(new Runnable() { @Override public void run() { ext.removeExtension(JAXWS_EXTENSION); } }); // enable Compile on Save feature enableCompileOnSave(); ProjectManager.getDefault().saveProject(project); } FileObject jaxws_build = project.getProjectDirectory().getFileObject(TransformerUtils.JAXWS_BUILD_XML_PATH); if (jaxws_build != null) { FileLock fileLock = jaxws_build.lock(); if (fileLock!=null) { try { jaxws_build.delete(fileLock); } finally { fileLock.releaseLock(); } } } }
Example 2
Source File: FileChooserAccessory.java From netbeans with Apache License 2.0 | 6 votes |
@Messages({"# {0} - file location", "FileChooserAccessory_no_such_file=Cannot copy nonexistent path {0} to libraries folder."}) private void copyFiles(List<File> files, FileObject newRoot) throws IOException { List<File> fs = new ArrayList<File>(); for (File file : files) { FileObject fo = FileUtil.toFileObject(file); if (fo == null) { throw Exceptions.attachLocalizedMessage(new FileNotFoundException(file.toString()), FileChooserAccessory_no_such_file(file)); } FileObject newFO; if (fo.isFolder()) { newFO = copyFolderRecursively(fo, newRoot); } else { FileObject foExists = newRoot.getFileObject(fo.getName(), fo.getExt()); if (foExists != null) { foExists.delete(); } newFO = FileUtil.copyFile(fo, newRoot, fo.getName(), fo.getExt()); } fs.add(FileUtil.toFile(newFO)); } copiedRelativeFiles = getRelativeFiles(fs); }
Example 3
Source File: VCSInterceptorTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testFileCreatedLockedRenamedDeleted() throws IOException { File f = new File(dataRootDir, "workdir/root-test-versioned"); FileObject fo = FileUtil.toFileObject(f); fo = fo.createData("deleteme.txt"); File file = FileUtil.toFile(fo); FileLock lock = fo.lock(); fo.rename(lock, "deleteme", "now"); lock.releaseLock(); File file2 = FileUtil.toFile(fo); fo.delete(); assertTrue(inteceptor.getBeforeCreateFiles().contains(file)); assertTrue(inteceptor.getDoCreateFiles().contains(file)); assertTrue(inteceptor.getCreatedFiles().contains(file)); assertTrue(inteceptor.getBeforeEditFiles().contains(file)); assertTrue(inteceptor.getBeforeMoveFiles().contains(file)); assertTrue(inteceptor.getAfterMoveFiles().contains(file)); assertTrue(inteceptor.getBeforeDeleteFiles().contains(file2)); assertTrue(inteceptor.getDoDeleteFiles().contains(file2)); assertTrue(inteceptor.getDeletedFiles().contains(file2)); }
Example 4
Source File: DataFolderIndexTest.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void setUp () throws Exception { MockServices.setServices(Pool.class); ERR = org.openide.ErrorManager.getDefault().getInstance("TEST-" + getName()); FileObject old = FileUtil.getConfigFile("TestTemplates"); if (old != null) { old.delete(); } fo = FileUtil.getConfigRoot().createFolder("TestTemplates"); df = DataFolder.findFolder(fo); assertNotNull("DataFolder found for AA", df); df.getPrimaryFile().createData("marie"); df.getPrimaryFile().createData("jakub"); df.getPrimaryFile().createData("eva"); df.getPrimaryFile().createData("adam"); assertNotNull("Folder " + df + " has a children.", df.getChildren()); assertEquals("Folder " + df + " has 4 childs.", 4, df.getChildren().length); }
Example 5
Source File: ProjectJAXWSClientSupport.java From netbeans with Apache License 2.0 | 6 votes |
/** folder where xml client artifacts should be saved, e.g. WEB-INF/wsdl/client/SampleClient */ protected FileObject getWsdlFolderForClient(String name) throws IOException { FileObject globalWsdlFolder = getWsdlFolder(true); FileObject oldWsdlFolder = globalWsdlFolder.getFileObject("client/"+name); //NOI18N if (oldWsdlFolder!=null) { FileLock lock = oldWsdlFolder.lock(); try { oldWsdlFolder.delete(lock); } finally { lock.releaseLock(); } } FileObject clientWsdlFolder = globalWsdlFolder.getFileObject("client"); //NOI18N if (clientWsdlFolder==null) clientWsdlFolder = globalWsdlFolder.createFolder("client"); //NOI18N return clientWsdlFolder.createFolder(name); }
Example 6
Source File: VCSInterceptorTestCase.java From netbeans with Apache License 2.0 | 6 votes |
public void testDeleteVersionedFolder() throws Exception { // init inteceptor.deleteHandler = deleteHandler; FileObject fo = getVersionedFolder().createFolder("folder"); VCSFileProxy proxy = VCSFileProxy.createFileProxy(fo); logHandler.clear(); // delete fo.delete(); // test assertTrue(inteceptor.getBeforeDeleteFiles().contains(proxy)); assertTrue(inteceptor.getDoDeleteFiles().contains(proxy)); assertTrue(inteceptor.getDeletedFiles().contains(proxy)); assertInterceptedCalls( f(getDeleteHandlerFormat, proxy), f(deleteHandleFormat, proxy), f(deleteSuccessFormat, proxy) ); }
Example 7
Source File: BackupFacility2.java From netbeans with Apache License 2.0 | 5 votes |
/** * restore file, which was stored by backup(file) * * @param id identification of backup transaction * @throws java.io.IOException if restore failed. */ void restore(long id) throws IOException { BackupEntry entry = map.get(id); if (entry == null) { throw new IllegalArgumentException("Backup with id " + id + "does not exist"); // NOI18N } File backup = File.createTempFile("nbbackup", null); //NOI18N backup.deleteOnExit(); boolean exists = false; FileObject fo = entry.orig; if(!fo.isValid()) { // Try to restore FO FileObject file = FileUtil.toFileObject(FileUtil.toFile(fo)); fo = file == null? fo : file; } if (exists = fo.isValid()) { backup.createNewFile(); copy(fo, backup); } else { fo = createNewFile(fo); } if (entry.exists) { if (!tryUndoOrRedo(fo, entry)) { copy(entry.file, fo); } } else { fo.delete(); } entry.exists = exists; entry.file.delete(); if (backup.exists()) { entry.file = backup; } else { map.remove(id); } }
Example 8
Source File: BaseFileObjectTestHid.java From netbeans with Apache License 2.0 | 5 votes |
private void testComposeNameImpl(FileObject fo) throws IOException { assertTrue(fo.isValid() && fo.isData()); String fullName = fo.getNameExt(); String ext = fo.getExt(); String name = fo.getName(); FileObject parent = fo.getParent(); fo.delete(); FileObject fo2 = parent.createData(name, ext); assertEquals(fullName, fo2.getNameExt()); assertEquals(name, fo2.getName()); assertEquals(ext, fo2.getExt()); }
Example 9
Source File: FileObjectCrawlerTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testDeletedFiles() throws IOException { FileObject root = FileUtil.createFolder(new File(getWorkDir(), "src")); String [] paths = new String [] { "org/pckg1/file1.txt", "org/pckg1/pckg2/file1.txt", "org/pckg1/pckg2/file2.txt", "org/pckg2/" }; populateFolderStructure(root, paths); FileObjectCrawler crawler1 = new FileObjectCrawler(root, EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, CR, SuspendSupport.NOP); assertCollectedFiles("Wrong files collected", crawler1.getResources(), paths); assertCollectedFiles("Wrong files collected", crawler1.getAllResources(), paths); FileObject pckg2 = root.getFileObject("org/pckg1/pckg2"); FileObject org = root.getFileObject("org"); org.delete(); FileObjectCrawler crawler2 = new FileObjectCrawler(root, new FileObject [] { pckg2 }, EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, CR, SuspendSupport.NOP); assertCollectedFiles("There should be no files in " + root, crawler2.getResources()); assertNull("All resources should not be computed for subtree", crawler2.getAllResources()); FileObjectCrawler crawler3 = new FileObjectCrawler(root, EnumSet.<Crawler.TimeStampAction>of(Crawler.TimeStampAction.UPDATE), null, CR, SuspendSupport.NOP); assertCollectedFiles("There should be no files in " + root, crawler3.getResources()); assertCollectedFiles("There should be no files in " + root, crawler3.getAllResources()); assertCollectedFiles("All files in " + root + " should be deleted", crawler3.getDeletedResources()); }
Example 10
Source File: ProjectUtilities.java From netbeans with Apache License 2.0 | 5 votes |
public static URL copyAppletHTML(Project project, PropertyEvaluator props, FileObject profiledClassFile, String value) { try { String buildDirProp = props.getProperty("build.dir"); //NOI18N FileObject buildFolder = getOrCreateBuildFolder(project, buildDirProp); FileObject htmlFile; htmlFile = profiledClassFile.getParent().getFileObject(profiledClassFile.getName(), "html"); //NOI18N if (htmlFile == null) { htmlFile = profiledClassFile.getParent().getFileObject(profiledClassFile.getName(), "HTML"); //NOI18N } if (htmlFile == null) { return null; } FileObject existingFile = buildFolder.getFileObject(htmlFile.getName(), htmlFile.getExt()); if (existingFile != null) { existingFile.delete(); } htmlFile.copy(buildFolder, profiledClassFile.getName(), value).getURL(); return htmlFile.getURL(); } catch (IOException e) { ErrorManager.getDefault() .annotate(e, Bundle.ProjectUtilities_FailedCopyAppletFileMsg(e.getMessage())); ErrorManager.getDefault().notify(ErrorManager.ERROR, e); return null; } }
Example 11
Source File: JaxWsChildren.java From netbeans with Apache License 2.0 | 5 votes |
private FileObject getWsdlFolderForService(JAXWSSupport support, String name) throws IOException { FileObject globalWsdlFolder = support.getWsdlFolder(true); FileObject oldWsdlFolder = globalWsdlFolder.getFileObject(name); if (oldWsdlFolder!=null) { FileLock lock = oldWsdlFolder.lock(); try { oldWsdlFolder.delete(lock); } finally { lock.releaseLock(); } } return globalWsdlFolder.createFolder(name); }
Example 12
Source File: SingleModulePropertiesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testThatProjectWithoutBundleDoesNotThrowNPE_61469() throws Exception { FileObject pFO = TestBase.generateStandaloneModuleDirectory(getWorkDir(), "module1"); FileObject propsFO = FileUtil.toFileObject(new File(getWorkDir(), "module1/src/org/example/module1/resources/Bundle.properties")); propsFO.delete(); NbModuleProject p = (NbModuleProject) ProjectManager.getDefault().findProject(pFO); SingleModuleProperties props = loadProperties(p); simulatePropertiesOpening(props, p); }
Example 13
Source File: CopyResourcesOnSave.java From netbeans with Apache License 2.0 | 5 votes |
private void handleDeleteFileInDestDir(FileObject fo, String path, Tuple tuple, Project project) throws IOException { if (tuple != null) { // inside docbase path = path != null ? path : FileUtil.getRelativePath(tuple.root, fo); path = addTargetPath(path, tuple.resource); FileObject toDelete = tuple.destinationRoot.getFileObject(path); if (toDelete != null) { toDelete.delete(); } AdditionalDestination add = project.getLookup().lookup(AdditionalDestination.class); if (add != null) { add.delete(fo, path); } } }
Example 14
Source File: ApplicationTypeManager.java From visualvm with GNU General Public License v2.0 | 5 votes |
public boolean removeType(ApplicationType type) { FileObject def = defRepository.getFileObject(type.getDefName()); if (def != null) { try { def.delete(); appTypeCache.invalidateObject(type.getMainClass()); return true; } catch (IOException e) { } } return false; }
Example 15
Source File: InterceptorTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testBeforeEditBlocksFileDelete() throws IOException { File f = new File(getWorkDir(), "file"); f.createNewFile(); write(f, "1"); long ts = f.lastModified(); // change file and block the storing for some time right after the msg gets intercepted FileObject fo = FileUtil.toFileObject(f); LogHandler lhBocked = new LogHandler("beforeDelete for file " + getPath(f) + " was blocked", LogHandler.Compare.STARTS_WITH); long BLOCK_TIME = 5000; LogHandler lh = new LogHandler("finnished copy file " + getPath(f), LogHandler.Compare.STARTS_WITH); lh.block(BLOCK_TIME); long t = System.currentTimeMillis(); fo.delete(); assertTrue(lh.isDone()); // was blocked while storing if(System.currentTimeMillis() - t < BLOCK_TIME) { fail("should have been blocked for at least " + (BLOCK_TIME / 1000) + " seconds"); } assertTrue(lhBocked.isDone()); // was blocked in beforeEdit as well StoreEntry entry = LocalHistory.getInstance().getLocalHistoryStore().getStoreEntry(VCSFileProxy.createFileProxy(f), ts); assertNotNull(entry); assertEntry(entry, "1"); }
Example 16
Source File: HgCommandTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testDisableIBInFSEvents () throws Exception { CommandHandler handler = new CommandHandler(); Mercurial.LOG.addHandler(handler); Mercurial.LOG.setLevel(Level.ALL); File file = createFile(getWorkTreeDir(), "aaa"); commit(file); FileObject fo = FileUtil.toFileObject(file); fo.delete(); assertEquals(FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY, HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(file), null, null).get(file).getStatus()); assertFalse(handler.commandInvoked); fo.getParent().createData(file.getName()); assertNull(HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(file), null, null).get(file)); assertFalse(handler.commandInvoked); File copy = new File(file.getParentFile(), "copy"); fo.copy(fo.getParent(), copy.getName(), ""); assertEquals(FileInformation.STATUS_VERSIONED_ADDEDLOCALLY, HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(copy), null, null).get(copy).getStatus()); assertFalse(handler.commandInvoked); File renamed = new File(file.getParentFile(), "renamed"); FileLock lock = fo.lock(); fo.move(lock, fo.getParent(), renamed.getName(), ""); lock.releaseLock(); assertEquals(FileInformation.STATUS_VERSIONED_ADDEDLOCALLY, HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(renamed), null, null).get(renamed).getStatus()); assertEquals(FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY, HgCommand.getStatus(getWorkTreeDir(), Collections.<File>singletonList(file), null, null).get(file).getStatus()); assertFalse(handler.commandInvoked); }
Example 17
Source File: PackageViewTest.java From netbeans with Apache License 2.0 | 5 votes |
@RandomlyFails // NB-Core-Build #3802 public void testDefaultPackage() throws Exception { // Create children SourceGroup group = new SimpleSourceGroup( FileUtil.createFolder( root, "src" ) ); Children ch = PackageView.createPackageView( group ).getChildren(); // Default package should be there assertNodes( ch, new String[] { "<default package>" }, new int[] { 0 }, true ); // Needs to compute the nodes first // Default package should disappear FileObject a = FileUtil.createFolder( root, "src/a" ); assertNodes( ch, new String[] { "a", }, new int[] { 0, } ); // Default package should appear again FileObject someJava = FileUtil.createData( root, "src/Some.java" ); assertNodes( ch, new String[] { "<default package>", "a", }, new int[] { 1, 0, } ); // Disappear again someJava.delete(); assertNodes( ch, new String[] { "a", }, new int[] { 0, } ); // And appear again a.delete(); assertNodes( ch, new String[] { "<default package>" }, new int[] { 0 } ); }
Example 18
Source File: SeveralXmlModelTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testAddModelInSrc() throws IOException, InterruptedException{ FileObject fileObject = srcFO.getFileObject("META-INF/one.faces-config.xml"); if ( fileObject!= null ){ fileObject.delete(); } TestUtilities.copyStringToFileObject(srcFO, "META-INF/one.faces-config.xml", getFileContent("data/one.faces-config.xml")); TestUtilities.copyStringToFileObject(srcFO, "META-INF/two.faces-config.xml", getFileContent("data/two.faces-config.xml")); createJsfModel().runReadAction(new MetadataModelAction<JsfModel,Void>(){ public Void run( JsfModel model ) throws Exception { assertEquals( 2 , model.getModels().size()); List<Application> applications = model.getElements( Application.class); assertEquals( 1 , applications.size()); PropListener l = new PropListener(); model.addPropertyChangeListener(l); TestUtilities.copyStringToFileObject(srcFO, "WEB-INF/faces-config.xml", getFileContent("data/faces-config.xml")); l.waitForModelUpdate(); assertEquals( 3 , model.getModels().size()); assertEquals( 3 , model.getFacesConfigs().size()); applications = model.getElements( Application.class); assertEquals( 2 , applications.size()); return null; } }); }
Example 19
Source File: WebProject.java From netbeans with Apache License 2.0 | 5 votes |
private void handleDeleteFileInDestDir(String resourcePath) throws IOException { File deleted = null; FileObject webBuildBase = buildWeb == null ? null : helper.resolveFileObject(buildWeb); if (webBuildBase != null) { // project was built FileObject toDelete = webBuildBase.getFileObject(resourcePath); if (toDelete != null) { deleted = FileUtil.toFile(toDelete); toDelete.delete(); } if (deleted != null) { fireArtifactChange(Collections.singleton(ArtifactListener.Artifact.forFile(deleted))); } } }
Example 20
Source File: EntityGeneratorTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testGenerateJavaEE14() throws IOException { TestModule testModule = createEjb21Module(); FileObject sourceRoot = testModule.getSources()[0]; FileObject packageFileObject = sourceRoot.getFileObject("testGenerateJavaEE14"); if (packageFileObject != null) { packageFileObject.delete(); } packageFileObject = sourceRoot.createFolder("testGenerateJavaEE14"); // CMP Entity EJB in Java EE 1.4 EntityGenerator entityGenerator = new EntityGenerator("TestCmp", packageFileObject, true, true, true, "java.lang.Long", null, true); entityGenerator.generate(); EjbJar ejbJar = DDProvider.getDefault().getDDRoot(testModule.getDeploymentDescriptor()); EnterpriseBeans enterpriseBeans = ejbJar.getEnterpriseBeans(); Entity entity = (Entity) enterpriseBeans.findBeanByName(EnterpriseBeans.ENTITY, Entity.EJB_NAME, "TestCmp"); assertNotNull(entity); assertEquals("TestCmpEB", entity.getDefaultDisplayName()); assertEquals("TestCmp", entity.getEjbName()); assertEquals("testGenerateJavaEE14.TestCmpRemoteHome", entity.getHome()); assertEquals("testGenerateJavaEE14.TestCmpRemote", entity.getRemote()); assertEquals("testGenerateJavaEE14.TestCmpLocalHome", entity.getLocalHome()); assertEquals("testGenerateJavaEE14.TestCmpLocal", entity.getLocal()); assertEquals("testGenerateJavaEE14.TestCmp", entity.getEjbClass()); assertEquals("Container", entity.getPersistenceType()); assertEquals("java.lang.Long", entity.getPrimKeyClass()); assertFalse(entity.isReentrant()); assertEquals("TestCmp", entity.getAbstractSchemaName()); assertEquals(1, entity.getCmpField().length); assertEquals("pk", entity.getCmpField()[0].getFieldName()); assertEquals("pk", entity.getPrimkeyField()); assertFile( FileUtil.toFile(packageFileObject.getFileObject("TestCmp.java")), getGoldenFile("testGenerateJavaEE14/TestCmp.java"), FileUtil.toFile(packageFileObject) ); assertFile( FileUtil.toFile(packageFileObject.getFileObject("TestCmpLocal.java")), getGoldenFile("testGenerateJavaEE14/TestCmpLocal.java"), FileUtil.toFile(packageFileObject) ); assertFile( FileUtil.toFile(packageFileObject.getFileObject("TestCmpLocalHome.java")), getGoldenFile("testGenerateJavaEE14/TestCmpLocalHome.java"), FileUtil.toFile(packageFileObject) ); assertFile( FileUtil.toFile(packageFileObject.getFileObject("TestCmpRemote.java")), getGoldenFile("testGenerateJavaEE14/TestCmpRemote.java"), FileUtil.toFile(packageFileObject) ); assertFile( FileUtil.toFile(packageFileObject.getFileObject("TestCmpRemoteHome.java")), getGoldenFile("testGenerateJavaEE14/TestCmpRemoteHome.java"), FileUtil.toFile(packageFileObject) ); // BMP Entity EJB in Java EE 1.4 entityGenerator = new EntityGenerator("TestBmp", packageFileObject, false, true, false, "java.lang.Long", null, true); entityGenerator.generate(); entity = (Entity) enterpriseBeans.findBeanByName(EnterpriseBeans.ENTITY, Entity.EJB_NAME, "TestBmp"); assertNotNull(entity); assertEquals("TestBmpEB", entity.getDefaultDisplayName()); assertEquals("TestBmp", entity.getEjbName()); assertNull(entity.getHome()); assertNull(entity.getRemote()); assertEquals("testGenerateJavaEE14.TestBmpLocalHome", entity.getLocalHome()); assertEquals("testGenerateJavaEE14.TestBmpLocal", entity.getLocal()); assertEquals("testGenerateJavaEE14.TestBmp", entity.getEjbClass()); assertEquals("Bean", entity.getPersistenceType()); assertEquals("java.lang.Long", entity.getPrimKeyClass()); assertFalse(entity.isReentrant()); assertFile( FileUtil.toFile(packageFileObject.getFileObject("TestBmp.java")), getGoldenFile("testGenerateJavaEE14/TestBmp.java"), FileUtil.toFile(packageFileObject) ); assertFile( FileUtil.toFile(packageFileObject.getFileObject("TestBmpLocal.java")), getGoldenFile("testGenerateJavaEE14/TestBmpLocal.java"), FileUtil.toFile(packageFileObject) ); assertFile( FileUtil.toFile(packageFileObject.getFileObject("TestBmpLocalHome.java")), getGoldenFile("testGenerateJavaEE14/TestBmpLocalHome.java"), FileUtil.toFile(packageFileObject) ); assertNull(packageFileObject.getFileObject("TestBmpRemote.java")); assertNull(packageFileObject.getFileObject("TestBmpRemoteHome.java")); }