Java Code Examples for org.openide.filesystems.FileObject#refresh()

The following examples show how to use org.openide.filesystems.FileObject#refresh() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: netbeans   File: BaseFileObjectTestHid.java    License: Apache License 2.0 6 votes vote down vote up
public void testDeepStructureDelete() throws Exception {
    clearWorkDir();
    
    final File rf = new File(getWorkDir(), "wd");
    rf.mkdirs();
    
    FileObject root = FileUtil.toFileObject(rf);
    FileObject next = root;
    for (int i = 0; i < 10; i++) {
        next = next.createFolder("i" + i);
    }
    
    assertTrue("Is valid", root.isValid());
    assertTrue("Is valid leaft", next.isValid());
    
    clearWorkDir();
    assertFalse("Root file is gone", rf.exists());
    
    root.refresh();
    
    assertFalse("Became invalid", root.isValid());
    assertFalse("Leaf is invalid as well", next.isValid());
}
 
Example 2
Source Project: netbeans   File: WSITModelSupport.java    License: Apache License 2.0 6 votes vote down vote up
/** Creates new empty main client configuration file
 *
 */
static FileObject createMainConfig(FileObject folder, Collection<FileObject> createdFiles) {
    FileObject mainConfig = null;
    try {
        mainConfig = FileUtil.createData(folder, CONFIG_WSDL_CLIENT_PREFIX + "." + MAIN_CONFIG_EXTENSION); //NOI18N
        if ((mainConfig != null) && (mainConfig.isValid()) && !(mainConfig.isVirtual())) {
            if (createdFiles != null) {
                createdFiles.add(mainConfig);
            }
            FileWriter fw = new FileWriter(FileUtil.toFile(mainConfig));
            fw.write(NbBundle.getMessage(WSITEditor.class, "EMPTY_WSDL"));       //NOI18N
            fw.close();
            mainConfig.refresh(true);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return mainConfig;
}
 
Example 3
Source Project: netbeans   File: GrailsPluginSupport.java    License: Apache License 2.0 6 votes vote down vote up
private List<GrailsPlugin> loadInstalledPlugins10() {
    List<GrailsPlugin> plugins = new ArrayList<GrailsPlugin>();
    try {
        FileObject pluginsDir = project.getProjectDirectory().getFileObject("plugins"); //NOI18N
        if (pluginsDir != null && pluginsDir.isFolder()) {
            pluginsDir.refresh();
            for (FileObject child : pluginsDir.getChildren()) {
                if (child.isFolder()) {
                    FileObject descriptor = child.getFileObject("plugin.xml"); //NOI18N
                    if (descriptor != null && descriptor.canRead()) {
                        plugins.add(getPluginFromInputStream(descriptor.getInputStream(), null));
                    }
                }
            }
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
    Collections.sort(plugins);
    return plugins;
}
 
Example 4
Source Project: netbeans   File: FolderObjTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testFolderToFile() throws Exception {
    File f = new File(getWorkDir(), "classes");
    f.createNewFile();
    assertTrue("File created", f.isFile());
    
    FileObject fo = FileUtil.toFileObject(f);
    assertTrue("Is data", fo.isData());
    
    f.delete();
    f.mkdirs();
    assertTrue("Is dir", f.isDirectory());
    
    fo.refresh();
    
    assertFalse("No longer valid", fo.isValid());
    FileObject folder = FileUtil.toFileObject(f);
    assertNotNull("Folder found", folder);
    if (fo == folder) {
        fail("Should not be the same: " + folder);
    }
    assertTrue("Is folder", folder.isFolder());
}
 
Example 5
Source Project: netbeans   File: ChildrenSupportTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check that fix for bug 240156 {@link #testRefreshAfterCaseChange()}
 * doens't break anything.
 *
 * @throws IOException
 */
public void testChangeFileToDir() throws IOException {

    File dir = new File(getWorkDir(), "dir");
    dir.mkdir();
    FileObject dirFO = FileUtil.toFileObject(dir);

    File fileOrDir = new File(dir, "fileOrDir");
    fileOrDir.createNewFile();
    FileObject fileOrDirFO = FileUtil.toFileObject(fileOrDir);
    assertTrue(fileOrDirFO.isData());
    dirFO.refresh();

    fileOrDir.delete();
    dirFO.refresh();

    fileOrDir.mkdir();
    dirFO.refresh();

    fileOrDirFO = FileUtil.toFileObject(fileOrDir);
    assertTrue(fileOrDirFO.isFolder());
}
 
Example 6
Source Project: netbeans   File: BaseEEModuleImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * This call is used in in-place deployment. Returns the directory staging the contents of the archive.
 * This directory is the one from which the content entries returned by {@link #getArchiveContents} came from.
 *
 * @return FileObject for the content directory
 */
@Override
public FileObject getContentDirectory() throws IOException {
    File file = mavenproject().getOutputDirectory(false);
    FileObject fo = FileUtil.toFileObject(file.getParentFile());
    if (fo != null) {
        fo.refresh();
    }
    return FileUtil.toFileObject(file);
}
 
Example 7
Source Project: netbeans   File: ModuleDeleterImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void refreshModuleList () {
    // XXX: the modules list should be delete automatically when config/Modules/module.xml is removed
    FileObject modulesRoot = FileUtil.getConfigFile(ModuleDeactivator.MODULES); // NOI18N
    err.log (Level.FINE, "Call refresh on " + modulesRoot + " file object.");
    if (modulesRoot != null) {
        modulesRoot.refresh ();
    }
}
 
Example 8
Source Project: netbeans   File: WLServerLibraryManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void deployLibraries(Set<ServerLibraryDependency> libraries) throws ConfigurationException {
    Set<ServerLibraryDependency> notHandled = filterDeployed(libraries);

    Set<File> toDeploy = new HashSet<File>();
    Map<ServerLibrary, File> deployable = support.getDeployableFiles();
    for (Iterator<ServerLibraryDependency> it = notHandled.iterator(); it.hasNext(); ) {
        ServerLibraryDependency range = it.next();
        for (Map.Entry<ServerLibrary, File> entry : deployable.entrySet()) {
            if (range.versionMatches(entry.getKey())) {
                it.remove();
                toDeploy.add(entry.getValue());
                break;
            }
        }
    }

    if (!notHandled.isEmpty()) {
        throw new MissingLibrariesException(NbBundle.getMessage(WLServerLibraryManager.class, "MSG_DidNotFindServerLibraries"), notHandled);
    }

    try {
        deployFiles(toDeploy);
    } finally {
        FileObject fo = WLPluginProperties.getDomainConfigFileObject(manager);
        if (fo != null) {
            fo.refresh();
        }
    }
}
 
Example 9
Source Project: netbeans   File: FolderObjTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testFolderToFileWithParentRefresh() throws Exception {
    File f = new File(getWorkDir(), "classes");
    f.createNewFile();
    assertTrue("File created", f.isFile());
    
    FileObject fo = FileUtil.toFileObject(f);
    assertTrue("Is data", fo.isData());
    FileObject parent = fo.getParent();
    List<FileObject> arr = Arrays.asList(parent.getChildren());
    
    assertTrue("Contains " + fo + ": " +arr, arr.contains(fo));
    
    f.delete();
    f.mkdirs();
    assertTrue("Is dir", f.isDirectory());
    
    
    parent.refresh();
    
    assertFalse("No longer valid", fo.isValid());
    FileObject folder = FileUtil.toFileObject(f);
   
    if (fo == folder) {
        fail("Should not be the same: " + folder);
    }
    assertTrue("Is folder", folder.isFolder());
}
 
Example 10
Source Project: netbeans   File: ProvidedExtensionsTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testDeletedExternally() throws IOException {
    FileObject fo = FileUtil.toFileObject(getWorkDir());
    FileObject file = fo.createData("file");

    iListener.clear();
    FileUtil.toFile(file).delete();
    assertEquals(0, iListener.implsDeletedExternallyCalls);
    fo.refresh();
    assertEquals(1, iListener.implsDeletedExternallyCalls);
}
 
Example 11
Source Project: netbeans   File: RemoteClient.java    License: Apache License 2.0 5 votes vote down vote up
private File getLocalFile(File localFile, TransferFile transferFile) {
    File newFile = transferFile.resolveLocalFile(localFile);
    FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(newFile));
    if (fo != null) {
        fo.refresh();
    }
    return newFile;
}
 
Example 12
Source Project: netbeans   File: SourceFS.java    License: Apache License 2.0 5 votes vote down vote up
public FileObject createFile(String path, String content) {
    int i = path.lastIndexOf('/');
    String name = (i >= 0) ? path.substring(i + 1) : path;
    Item item = new Item(name, content);
    FileObject parent;
    synchronized (items) {
        items.put(path, item);
        parent = getExistingParent(path);
    }
    parent.refresh(true);
    return findResource(path);
}
 
Example 13
Source Project: netbeans   File: FileObjTest.java    License: Apache License 2.0 5 votes vote down vote up
private void doFileObjectForBrokenLink (boolean listFirst) throws Exception {
        clearWorkDir();
        File wd = new File(getWorkDir(), "wd");
        wd.mkdirs();

        File original = new File(wd, "original");
//        original.createNewFile();
        File lockFile = new File(wd, "wlock");
        for (int i = 1; i <= 2; ++i) {
            try {
                lockFile.delete();
                FileUtil.toFileObject(wd).refresh();
                ProcessBuilder pb = new ProcessBuilder().directory(wd).command(
                    new String[] { "ln", "-s", original.getName(), lockFile.getName() }
                );
                pb.start().waitFor();
                final List<String> names = Arrays.asList(lockFile.getParentFile().list());
                assertEquals("One file", 1, names.size());
                // file exists, or at least dir.listFiles lists the file
                assertTrue(names.contains(lockFile.getName()));
                // java.io.File.exists returns false
                assertFalse(lockFile.exists());

                if (listFirst) {
                    FileObject root = FileUtil.toFileObject(wd);
                    root.refresh();
                    List<FileObject> arr = Arrays.asList(root.getChildren());
                    assertEquals("Round " + i + " One files: " + arr, 1, arr.size());
                    assertEquals("Round " + i + "Has the right name", lockFile.getName(), arr.get(0).getName());
                }

                // and no FileObject is reated for such a file
                assertNotNull(FileUtil.toFileObject(lockFile));
            } finally {
                lockFile.delete();
            }
        }
    }
 
Example 14
Source Project: netbeans   File: StatFilesTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testRefreshFile() {
    FileObject fobj = getFileObject(testFile);
    monitor.reset();
    fobj.refresh();
    monitor.getResults().assertResult(4, StatFiles.ALL);
    monitor.getResults().assertResult(4, StatFiles.READ);
    //second time
    monitor.reset();
    fobj.refresh();
    monitor.getResults().assertResult(4, StatFiles.ALL);
    monitor.getResults().assertResult(4, StatFiles.READ);
}
 
Example 15
Source Project: netbeans   File: TestUtilities.java    License: Apache License 2.0 5 votes vote down vote up
private static void createFileImpl(File workDir, String path) throws IOException{
    FileObject fo = FileUtil.toFileObject(workDir);
    if (fo == null) {
        throw new IOException("Can't map '" + workDir.getAbsolutePath() + "' to the filesystem repository.");
    }

    String [] pathElements = path.split("/", -1);
    for (int i = 0; i < pathElements.length; i++ ) {
        String elementName = pathElements[i];

        if (elementName.length() == 0) {
            continue;
        }
        
        FileObject f = fo.getFileObject(elementName);
        if (f != null && f.isValid()) {
            fo = f;
        } else {
            if (i + 1 < pathElements.length) {
                fo = fo.createFolder(elementName);
            } else {
                // The last element in the path
                fo = fo.createData(elementName);
            }
        }
        
        fo.refresh();
    }
}
 
Example 16
Source Project: netbeans   File: CordovaPlatform.java    License: Apache License 2.0 4 votes vote down vote up
public static boolean isCordovaProject(Project project) {
    final FileObject root = project.getProjectDirectory();
    root.refresh();
    return root.getFileObject("hooks") != null || root.getFileObject(".cordova") != null; // NOI18N
}
 
Example 17
public FileObject[] listSavedHeapdumps(Lookup.Provider project, File directory) {
    try {
        FileObject snapshotsFolder = null;
                
        if (project == null && directory != null) {
            snapshotsFolder = FileUtil.toFileObject(directory);
        } else {
            snapshotsFolder = ProfilerStorage.getProjectFolder(project, false);
        }

        if (snapshotsFolder == null) {
            return new FileObject[0];
        }

        snapshotsFolder.refresh();

        FileObject[] children = snapshotsFolder.getChildren();

        ArrayList /*<FileObject>*/ files = new ArrayList /*<FileObject>*/();

        for (int i = 0; i < children.length; i++) {
            FileObject child = children[i];
            if (checkHprofFile(FileUtil.toFile(children[i])))
                files.add(child);
        }

        Collections.sort(files,
                         new Comparator() {
                public int compare(Object o1, Object o2) {
                    FileObject f1 = (FileObject) o1;
                    FileObject f2 = (FileObject) o2;

                    return f1.getName().compareTo(f2.getName());
                }
            });

        return (FileObject[])files.toArray(new FileObject[0]);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, Bundle.ResultsManager_ObtainSavedSnapshotsFailedMsg(e.getMessage()), e);

        return new FileObject[0];
    }
}
 
Example 18
Source Project: netbeans   File: ResultsManager.java    License: Apache License 2.0 4 votes vote down vote up
public FileObject[] listSavedSnapshots(Lookup.Provider project, File directory) {
    try {
        FileObject snapshotsFolder = null;
                
        if (project == null && directory != null) {
            snapshotsFolder = FileUtil.toFileObject(directory);
        } else {
            snapshotsFolder = ProfilerStorage.getProjectFolder(project, false);
        }

        if (snapshotsFolder == null) {
            return new FileObject[0];
        }

        snapshotsFolder.refresh();

        FileObject[] children = snapshotsFolder.getChildren();

        ArrayList /*<FileObject>*/ files = new ArrayList /*<FileObject>*/();

        for (int i = 0; i < children.length; i++) {
            FileObject child = children[i];

            if (child.getExt().equalsIgnoreCase(SNAPSHOT_EXTENSION)) {
                files.add(child);
            }
        }

        Collections.sort(files,
                         new Comparator() {
                public int compare(Object o1, Object o2) {
                    FileObject f1 = (FileObject) o1;
                    FileObject f2 = (FileObject) o2;

                    return f1.getName().compareTo(f2.getName());
                }
            });

        return (FileObject[])files.toArray(new FileObject[0]);
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, Bundle.ResultsManager_ObtainSavedSnapshotsFailedMsg(e.getMessage()), e);

        return new FileObject[0];
    }
}
 
Example 19
Source Project: netbeans   File: SourceUtilsTest.java    License: Apache License 2.0 3 votes vote down vote up
private void prepareTest() throws Exception {
    File work = getWorkDir();
    FileObject workFO = FileUtil.toFileObject(work);
    
    assertNotNull(workFO);
    
    FileObject sourceRoot = workFO.getFileObject("src");
    if (sourceRoot == null) {
        sourceRoot = workFO.createFolder("src");
    }
    FileObject buildRoot  = workFO.createFolder("build");
    FileObject cache = workFO.createFolder("cache");
    FileObject packageRoot = sourceRoot.getFileObject("sourceutils");
    if (packageRoot == null) {
        packageRoot = sourceRoot.createFolder("sourceutils");
    }
    
    SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cache);
    
    String capitalizedName = "T" + getName().substring(1);
    
    TestUtil.copyFiles(FileUtil.toFile(sourceRoot), "sourceutils/" + capitalizedName + ".java");
    
    packageRoot.refresh();
    
    FileObject testSource = packageRoot.getFileObject(capitalizedName + ".java");
    
    assertNotNull(testSource);

    SourceUtilsTestUtil.compileRecursively(sourceRoot);
    
    js = JavaSource.forFileObject(testSource);
    
    assertNotNull(js);
    
    info = SourceUtilsTestUtil.getCompilationInfo(js, JavaSource.Phase.RESOLVED);
    
    assertNotNull(info);
}
 
Example 20
Source Project: netbeans   File: JavadocTestSupport.java    License: Apache License 2.0 3 votes vote down vote up
protected void prepareTest(String code) throws Exception {
    clearWorkDir();
    
    FileObject workFO = FileUtil.toFileObject(getWorkDir());
    
    assertNotNull(workFO);
    
    FileObject sourceRoot = workFO.createFolder("src");
    FileObject buildRoot  = workFO.createFolder("build");
    
    FileObject data = FileUtil.createData(sourceRoot, "test/Test.java");
    
    TestUtilities.copyStringToFile(FileUtil.toFile(data), code);
    
    data.refresh();
    
    SourceUtilsTestUtil.prepareTest(sourceRoot, buildRoot, cacheFO);
    
    SourceUtilsTestUtil.compileRecursively(sourceRoot);
    
    DataObject od = DataObject.find(data);
    EditorCookie ec = od.getCookie(EditorCookie.class);
    
    assertNotNull(ec);
    
    doc = ec.openDocument();
    
    doc.putProperty(Language.class, JavaTokenId.language());
    doc.putProperty("mimeType", "text/x-java");
    
    JavaSource js = JavaSource.forFileObject(data);
    
    assertNotNull(js);
    
    info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
    
    assertNotNull(info);
    assertTrue(info.getDiagnostics().toString(), info.getDiagnostics().isEmpty());
}