Java Code Examples for org.openide.filesystems.FileObject.delete()

The following are Jave code examples for showing how to use delete() of the org.openide.filesystems.FileObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: DBSchemaManager.java   Source Code and License Vote up 6 votes
/**
 * Overwrites <code>dbschemaFile</code> with the contents of
 * <code>schemaElement</code>.
 */
private static void overwriteDBSchema(SchemaElement schemaElement, FileObject dbschemaFile, DBIdentifier dbschemaName) throws IOException {
    try {
        schemaElement.setName(dbschemaName);
    } catch (DBException e) {
        IOException ioe = new IOException(e.getMessage());
        ioe.initCause(e);
        throw ioe;
    }

    // cannot just overwrite the file, DBSchemaDataObject would not
    // notice the file has changed.
    FileObject parent = dbschemaFile.getParent();
    String fileName = dbschemaFile.getName();
    String fileExt = dbschemaFile.getExt();
    dbschemaFile.delete();
    FileObject newDBSchemaFile = parent.createData(fileName, fileExt);

    writeSchemaElement(schemaElement, newDBSchemaFile);
}
 
Example 2
Project: incubator-netbeans   File: FolderObjTest.java   Source Code and License Vote up 6 votes
public void testDelete2() throws IOException {
    File f = testFile;
    
    FileObject testFo = FileBasedFileSystem.getFileObject(testFile);
    assertNotNull(testFo);
    assertEquals(0,testFo.getChildren().length);
    
    FileObject newFolder = testFo.createFolder("testDelete2");
    assertNotNull(newFolder);
    assertEquals(1,testFo.getChildren().length);
    
    newFolder.delete();
    assertFalse(newFolder.isValid());
    assertEquals(0,testFo.getChildren().length);
    assertNull(testFo.getFileObject(newFolder.getNameExt()));
}
 
Example 3
Project: incubator-netbeans   File: CommonUtilities.java   Source Code and License Vote up 6 votes
/**
     * Close Memory Toolbar.
     */
    public static void closeMemoryToolbar(){
        // View|Toolbars|Memory        
        try {  // workaround for Issue #213828
            FileObject fo = FileUtil.getConfigFile("Toolbars/Memory");
            if (fo!=null) {
                fo.delete();
            }
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }        
//        closeToolbar(Bundle.getStringTrimmed("org.openide.actions.Bundle","View") + "|" +
//                Bundle.getStringTrimmed("org.netbeans.core.windows.actions.Bundle", "CTL_ToolbarsListAction") + "|" +
//                "Memory");
        maximizeWholeNetbeansWindow();
    }
 
Example 4
Project: incubator-netbeans   File: NbLoaderPool.java   Source Code and License Vote up 6 votes
public static void load() throws IOException {
    FileObject ser = getLoaderPoolStorage(false);
    if (ser != null) {
        try {
            ObjectInputStream ois = new NbObjectInputStream(ser.getInputStream());
            try {
                NbObjectInputStream.readSafely(ois);
            } finally {
                ois.close();
            }
        } catch (IOException x) {
            ser.delete(); // #144158: probably not valuable, just kill it
            throw x;
        }
    }
}
 
Example 5
Project: incubator-netbeans   File: BaseFileObjectTestHid.java   Source Code and License Vote up 6 votes
public void testLockFileAfterCrash() throws Exception {
    FileObject testFo = FileUtil.createData(root,"/testAfterCrash/testfile.data");
    File testFile = FileUtil.toFile(testFo);
  
    
    File lockFile = WriteLockUtils.getAssociatedLockFile(testFile);
    if (!lockFile.exists()) {
        assertTrue(lockFile.createNewFile());
    }
            
    assertTrue(lockFile.exists());

    FileObject lockFo = FileUtil.toFileObject(lockFile);        
    assertNull(lockFo);        
    testFo.delete();        
    
    
    lockFo = FileUtil.toFileObject(lockFile);        
    String msg = (lockFo != null) ? lockFo.toString() : "";
    assertNull(msg,lockFo);
}
 
Example 6
Project: incubator-netbeans   File: MatchingObjectNodeTest.java   Source Code and License Vote up 5 votes
/**
 * Test for bug 217984.
 */
public void testCreateNodeForInvalidDataObject() throws IOException {
    ResultModel rm = SearchTestUtils.createResultModelWithOneMatch();
    MatchingObject mo = rm.getMatchingObjects().get(0);
    DataObject dob = mo.getDataObject();
    FileObject fob = mo.getFileObject();
    Node original = dob.getNodeDelegate();
    fob.delete();
    // No exception should be thrown from the constructor.
    Node n = new MatchingObjectNode(original, Children.LEAF, mo, false);
    assertEquals("test.txt", n.getDisplayName());
}
 
Example 7
Project: incubator-netbeans   File: ShellRegistry.java   Source Code and License Vote up 5 votes
private void deleteCacheRoot(Reference<JShellEnvironment> ref, FileObject f) {
    synchronized (this) {
        if (fileIndex.get(f) != ref) {
            // reused.
            return;
        }
        fileIndex.remove(f);
        try {
            f.delete();
        } catch (IOException ex) {
            LOG.log(Level.WARNING, "Could not delete work root {0}: {1}", new Object[] { f, ex });
            ignoreNames.add(f.getNameExt());
        }
    }
}
 
Example 8
Project: incubator-netbeans   File: LayersBridge.java   Source Code and License Vote up 5 votes
@Override
public void deleteProfile (String profile) {
    FileObject root = FileUtil.getConfigFile(KEYMAPS_FOLDER);
    if (root == null) return;
    root = root.getFileObject (profile);
    if (root == null) return;
    try {
        root.delete ();
    } catch (IOException ex) {
        ErrorManager.getDefault ().notify (ex);
    }
}
 
Example 9
Project: incubator-netbeans   File: VersioningSystemTest.java   Source Code and License Vote up 5 votes
public void testInterceptor() throws IOException {
    File newFile = new File(rootDir, "vcs-tck-created.txt");
    assertFalse(newFile.exists());
    FileObject fo = FileUtil.toFileObject(rootDir);

    // test creation
    FileObject newfo = fo.createData("vcs-tck-created.txt");
    
    sleep(1000);

    // test delete
    newfo.delete();
}
 
Example 10
Project: incubator-netbeans   File: MultiModuleTest.java   Source Code and License Vote up 5 votes
public void testModuleSourcesChangesFires() throws IOException {
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    final FileObject modulesFolder = wd.createFolder("modules"); //NOI18N
    assertNotNull(modulesFolder);
    final FileObject classesFolder = modulesFolder.createFolder("module").createFolder("classes");        //NOI18N
    assertTrue(mtu.updateModuleRoots(false, "classes:resources",modulesFolder));   //NOI18N
    final SourceRoots modules = mtu.newModuleRoots(false);
    assertTrue(Arrays.equals(new FileObject[]{modulesFolder}, modules.getRoots()));
    final SourceRoots sources = mtu.newSourceRoots(false);
    assertEquals(
            Arrays.stream(new FileObject[]{classesFolder})
                .map((fo) -> fo.getPath())
                .sorted()
                .collect(Collectors.toList()),
            Arrays.stream(sources.getRoots())
                .map((fo) -> fo.getPath())
                .sorted()
                .collect(Collectors.toList()));
    final MultiModule model = MultiModule.getOrCreate(modules, sources);
    assertNotNull(model);
    ClassPath scp = model.getModuleSources("module");   //NOI18N
    assertNotNull(scp);
    assertEquals(Arrays.asList(classesFolder), Arrays.asList(scp.getRoots()));

    final MockPropertyChangeListener l = new MockPropertyChangeListener();
    scp.addPropertyChangeListener(l);
    final FileObject resourcesFolder = modulesFolder.getFileObject("module").createFolder("resources");        //NOI18N
    l.assertEvents(ClassPath.PROP_ROOTS);

    classesFolder.delete();
    l.assertEvents(ClassPath.PROP_ROOTS);
}
 
Example 11
Project: incubator-netbeans   File: ProcessorTest.java   Source Code and License Vote up 5 votes
@Override
protected void setUp() throws Exception {
    root = FileUtil.getConfigRoot();
    for (FileObject f : root.getChildren()) {
        f.delete();
    }
}
 
Example 12
Project: incubator-netbeans   File: TestUtilities.java   Source Code and License Vote up 5 votes
private static void deleteFileImpl(File workDir, String path) throws IOException{
    FileObject fo = FileUtil.toFileObject(new File(workDir, path));
    if (fo == null) {
        fo = FileUtil.getConfigFile(path); // NOI18N
        if (fo == null){
            return;
        }
    }
    fo.delete();        
}
 
Example 13
Project: incubator-netbeans   File: CompilationUnitTest.java   Source Code and License Vote up 5 votes
public void testNewCompilationUnitFromNonExistingTemplate() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");

    File fakeFile = new File(getWorkDir(), "Fake.java");
    FileObject fakeFO = FileUtil.createData(fakeFile);

    FileObject template = FileUtil.getConfigFile("Templates/Classes/Class.java");
    if (template != null) template.delete();
    template = FileUtil.getConfigFile("Templates/Classes/Empty.java");
    if(template != null) template.delete();

    FileObject testSourceFO = FileUtil.createData(testFile); assertNotNull(testSourceFO);
    ClassPath sourcePath = ClassPath.getClassPath(testSourceFO, ClassPath.SOURCE); assertNotNull(sourcePath);
    FileObject[] roots = sourcePath.getRoots(); assertEquals(1, roots.length);
    final FileObject sourceRoot = roots[0]; assertNotNull(sourceRoot);
    ClassPath compilePath = ClassPath.getClassPath(testSourceFO, ClassPath.COMPILE); assertNotNull(compilePath);
    ClassPath bootPath = ClassPath.getClassPath(testSourceFO, ClassPath.BOOT); assertNotNull(bootPath);
    ClasspathInfo cpInfo = ClasspathInfo.create(bootPath, compilePath, sourcePath);
    JavaSource javaSource = JavaSource.create(cpInfo, fakeFO);

    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void cancel() {
        }

        public void run(WorkingCopy workingCopy) throws Exception {
            workingCopy.toPhase(JavaSource.Phase.PARSED);
            TreeMaker make = workingCopy.getTreeMaker();
            String path = "zoo/Krtek.java";
            GeneratorUtilities genUtils = GeneratorUtilities.get(workingCopy);
            CompilationUnitTree newTree = genUtils.createFromTemplate(sourceRoot, path, ElementKind.CLASS);
            workingCopy.rewrite(null, newTree);
        }
    };
    ModificationResult result = javaSource.runModificationTask(task);
    result.commit();

    String res = TestUtilities.copyFileToString(new File(getDataDir().getAbsolutePath() + "/zoo/Krtek.java"));
    assertEquals(res, "package zoo;\n\n");
}
 
Example 14
Project: incubator-netbeans   File: FSFoldersInLookupTest.java   Source Code and License Vote up 5 votes
public void testInterfaceFoundInMyServices() throws Exception {
    assertNull("not found", Lookup.getDefault().lookup(Shared.class));
    FileObject fo = FileUtil.createData(root, "MyServices/sub/dir/2/" + Shared.class.getName().replace('.', '-') + ".instance");
    assertNotNull("found", Lookup.getDefault().lookup(Shared.class));
    fo.delete();
    assertNull("not found again", Lookup.getDefault().lookup(Shared.class));
}
 
Example 15
Project: incubator-netbeans   File: MultiModuleTest.java   Source Code and License Vote up 5 votes
public void testModuleSourcesChanges() throws IOException {
    final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
    final FileObject modulesFolder = wd.createFolder("modules"); //NOI18N
    assertNotNull(modulesFolder);
    final FileObject classesFolder = modulesFolder.createFolder("module").createFolder("classes");        //NOI18N
    assertTrue(mtu.updateModuleRoots(false, "classes:resources",modulesFolder));   //NOI18N
    final SourceRoots modules = mtu.newModuleRoots(false);
    assertTrue(Arrays.equals(new FileObject[]{modulesFolder}, modules.getRoots()));
    final SourceRoots sources = mtu.newSourceRoots(false);
    assertEquals(
            Arrays.stream(new FileObject[]{classesFolder})
                .map((fo) -> fo.getPath())
                .sorted()
                .collect(Collectors.toList()),
            Arrays.stream(sources.getRoots())
                .map((fo) -> fo.getPath())
                .sorted()
                .collect(Collectors.toList()));
    final MultiModule model = MultiModule.getOrCreate(modules, sources);
    assertNotNull(model);
    ClassPath scp = model.getModuleSources("module");   //NOI18N
    assertNotNull(scp);
    assertEquals(Arrays.asList(classesFolder), Arrays.asList(scp.getRoots()));

    final FileObject resourcesFolder = modulesFolder.getFileObject("module").createFolder("resources");        //NOI18N
    assertEquals(Arrays.asList(classesFolder, resourcesFolder), Arrays.asList(scp.getRoots()));

    classesFolder.delete();
    assertEquals(Arrays.asList(resourcesFolder), Arrays.asList(scp.getRoots()));
}
 
Example 16
Project: incubator-netbeans   File: GlobFileBuiltQueryTest.java   Source Code and License Vote up 5 votes
public void testBasicFunctionality() throws Exception {
    assertNotNull("have status for Foo.java", fooStatus);
    assertNotNull("have status for Bar.java", barStatus);
    assertNotNull("have status for FooTest.java", fooTestStatus);
    assertNull("non-matching file ignored", fbqi.getStatus(nonsense));
    assertFalse("Foo.java not built", fooStatus.isBuilt());
    assertFalse("Bar.java not built", barStatus.isBuilt());
    assertFalse("FooTest.java not built", fooTestStatus.isBuilt());
    FileObject fooClass = TestUtil.createFileFromContent(null, prj, "build/classes/pkg/Foo.class");
    assertTrue("Foo.java now built", fooStatus.isBuilt());
    Thread.sleep(PAUSE);
    TestUtil.createFileFromContent(null, prj, "src/pkg/Foo.java");
    assertFalse("Foo.class out of date", fooStatus.isBuilt());
    TestUtil.createFileFromContent(null, prj, "build/classes/pkg/Foo.class");
    assertTrue("Foo.class rebuilt", fooStatus.isBuilt());
    fooClass.delete();
    assertFalse("Foo.class deleted", fooStatus.isBuilt());
    TestUtil.createFileFromContent(null, prj, "build/test/classes/pkg/FooTest.class");
    assertTrue("FooTest.java now built", fooTestStatus.isBuilt());
    assertFalse("Bar.java still not built", barStatus.isBuilt());
    TestUtil.createFileFromContent(null, prj, "build/classes/pkg/Foo.class");
    assertTrue("Foo.java built again", fooStatus.isBuilt());
    DataObject.find(foo).setModified(true);
    assertFalse("Foo.java modified", fooStatus.isBuilt());
    DataObject.find(foo).setModified(false);
    assertTrue("Foo.java unmodified again", fooStatus.isBuilt());
    FileObject buildDir = prj.getFileObject("build");
    assertNotNull("build dir exists", buildDir);
    buildDir.delete();
    assertFalse("Foo.java not built (build dir gone)", fooStatus.isBuilt());
    assertFalse("Bar.java still not built", barStatus.isBuilt());
    assertFalse("FooTest.java not built (build dir gone)", fooTestStatus.isBuilt());
    // Just to check that you can delete a source file safely:
    bar.delete();
    barStatus.isBuilt();
}
 
Example 17
Project: incubator-netbeans   File: RevisionSetupSupportTest.java   Source Code and License Vote up 5 votes
private void cleanUpWC(File wc) throws IOException {
    if(wc.exists()) {
        File[] files = wc.listFiles();
        if(files != null) {
            for (File file : files) {
                if(!file.getName().equals("cache")) { // do not delete the cache
                    FileObject fo = FileUtil.toFileObject(file);
                    if (fo != null) {
                        fo.delete();
                    }
                }
            }
        }
    }
}
 
Example 18
Project: incubator-netbeans   File: DataShadowTranslateTest.java   Source Code and License Vote up 5 votes
/**
 * Checks translation on Shadows, which use FS name + path, not URI
 * @throws Exception 
 */
public void testFSNameAndPath() throws Exception {
    FileObject fo = FileUtil.getConfigRoot();
    
    FileObject origDir = fo.createFolder("origFolder3");
    
    // create empty real file with special and non-ASCII chars
    FileObject newFile = origDir.createData("moved-here.txt");
    
    // createa a fake file, just to get its URI right:
    FileObject fake = fo.createData("dead-file-location.old");
    
    final FileObject d = fo.createFolder("subfolder3");
    OutputStream ostm = d.createAndOpen("regularShadowURI.shadow");
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(ostm));
    
    bw.write(fake.getPath());
    bw.newLine();
    bw.write(fake.getFileSystem().getSystemName());
    bw.newLine();
    
    fake.delete();
    
    bw.close();
    
    FileObject fob = d.getFileObject("regularShadowURI.shadow");
    DataObject dd = DataObject.find(fob);
    
    assertTrue("Shadow must be translated, not broken", dd instanceof DataShadow);
    
    DataShadow ds = (DataShadow)dd;
    assertEquals("Shadow's original must be on the translated location", newFile, ds.getOriginal().getPrimaryFile());
}
 
Example 19
Project: incubator-netbeans   File: SourcePrefetcherTest.java   Source Code and License Vote up 5 votes
public void testDeletedFile() throws Exception {
    CompileTuple ct = files.iterator().next();
    final FileObject fo = URLMapper.findFileObject(ct.indexable.getURL());        
    fo.delete();
    
    JavaIndexerWorker.TEST_DO_PREFETCH = true;
    final LogHandler handler = new LogHandler();
    handler.expect("Using concurrent iterator, {0} workers");    //NOI18N
    final Logger log = Logger.getLogger(JavaIndexerWorker.class.getName());
    log.setLevel(Level.FINE);
    log.addHandler(handler);
    try {
        SourcePrefetcher pf = SourcePrefetcher.create(files, SuspendSupport.NOP);
        assertTrue(handler.isFound());
        final Deque<CompileTuple> got = new ArrayDeque<CompileTuple>(FILE_COUNT);
        while (pf.hasNext()) {
            ct = pf.next();
            try {
                if (ct != null) {
                    assertNotNull(getCache(ct.jfo));
                    got.offer(ct);
                }
            } finally {
                pf.remove();
            }
            if (ct != null) {
                assertNull(getCache(ct.jfo));
            }
        }
        final List<CompileTuple> allButFirst = new LinkedList<CompileTuple>(files);
        allButFirst.remove(0);
        assertCollectionsEqual(allButFirst,got);
    } finally {
        log.removeHandler(handler);
    }
}
 
Example 20
Project: incubator-netbeans   File: QuerySupportTest.java   Source Code and License Vote up 5 votes
@Override
protected void setUp() throws Exception {
    FileObject fo = FileUtil.getConfigFile("Services");
    if (fo != null) {
        fo.delete();
    }
    scratch = TestUtil.makeScratchDir(this);
    projdir = scratch.createFolder("proj");
    MockLookup.setInstances(
            new AntBasedProjectFactorySingleton(),
            AntBasedTestUtil.testAntBasedProjectType());
}