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

The following examples show how to use org.openide.filesystems.FileObject#isData() . 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: NewProjectIterator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void collectFiles(FileObject parent, Collection<FileObject> accepted, SharabilityQuery.Sharability parentSharab) {
    for (FileObject fo : parent.getChildren()) {
        if (!VisibilityQuery.getDefault().isVisible(fo)) {
            // #66765: ignore invisible files/folders, like CVS subdirectory
            continue;
        }
        SharabilityQuery.Sharability sharab;
        if (parentSharab == SharabilityQuery.Sharability.UNKNOWN || parentSharab == SharabilityQuery.Sharability.MIXED) {
            sharab = SharabilityQuery.getSharability(fo);
        } else {
            sharab = parentSharab;
        }
        if (sharab == SharabilityQuery.Sharability.NOT_SHARABLE) {
            continue;
        }
        if (fo.isData() && !fo.isVirtual()) {
            accepted.add(fo);
        } else if (fo.isFolder()) {
            accepted.add(fo);
            collectFiles(fo, accepted, sharab);
        }
    }
}
 
Example 2
Source File: NbGradleProjectFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
static boolean isProjectCheck(FileObject dir, final boolean preferMaven) {
    if (dir == null || FileUtil.toFile(dir) == null) {
        return false;
    }
    FileObject pom = dir.getFileObject("pom.xml"); //NOI18N
    if (pom != null && pom.isData()) {
        if (preferMaven) {
            return false;
        }
        final FileObject parent = dir.getParent();
        if (parent != null && parent.getFileObject("pom.xml") != null) { // NOI18N
            return isProjectCheck(parent, preferMaven);
        }
    }
    File suspect = FileUtil.toFile(dir);
    GradleFiles files = new GradleFiles(suspect);
    if (!files.isRootProject()) {
        Boolean inSubDirCache = GradleProjectCache.isKnownSubProject(files.getRootDir(), suspect);
        return inSubDirCache != null ? inSubDirCache : files.isProject();
    } else {
        return true;
    }
}
 
Example 3
Source File: ModuleTargetChooserPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean isValidModule (FileObject root, final String path) {
    //May be null when nothing selected in the GUI.
    if (root == null) {
        return false;
    }
    if (path == null) {
        return false;
    }
    final StringTokenizer st = new StringTokenizer(path,".");   //NOI18N
    while (st.hasMoreTokens()) {
        root = root.getFileObject(st.nextToken());
        if (root == null) {
            return true;
        }
        else if (root.isData()) {
            return false;
        }
    }
    return true;
}
 
Example 4
Source File: RunTestsCommand.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private FileObject findFolderWithTest(Lookup context) {
    FileObject[] files = CommandUtils.filesForContextOrSelectedNodes(context);
    if (files.length != 1) {
        return null;
    }
    FileObject file = files[0];
    if (!file.isFolder()) {
        return null;
    }
    Enumeration<? extends FileObject> children = file.getChildren(true);
    while (children.hasMoreElements()) {
        FileObject child = children.nextElement();
        if (child.isData()
                && isTestFile(child)
                && FileUtils.isPhpFile(child)) {
            return file;
        }
    }
    return null;
}
 
Example 5
Source File: SourceUtilsTestUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void compileRecursively(FileObject sourceRoot) throws Exception {
        List<FileObject> queue = new LinkedList<FileObject>();
        
        queue.add(sourceRoot);
        
        while (!queue.isEmpty()) {
            FileObject file = queue.remove(0);
            
            if (file.isData()) {
//                CountDownLatch l = RepositoryUpdater.getDefault().scheduleCompilationAndWait(file, sourceRoot);
//                l.await(60, TimeUnit.SECONDS);
                IndexingManager.getDefault().refreshIndexAndWait(sourceRoot.getURL(), Collections.singleton(file.getURL()));
            } else {
                queue.addAll(Arrays.asList(file.getChildren()));
            }
        }
    }
 
Example 6
Source File: JavaTargetChooserPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean isValidPackage (FileObject root, final String path) {
    //May be null when nothing selected in the GUI.
    if (root == null) {
        return false;
    }
    if (path == null) {
        return false;
    }
    final StringTokenizer tk = new StringTokenizer(path,".");   //NOI18N
    while (tk.hasMoreTokens()) {
        root = root.getFileObject(tk.nextToken());
        if (root == null) {
            return true;
        }
        else if (root.isData()) {
            return false;
        }
    }
    return true;
}
 
Example 7
Source File: DefaultFaceletLibraries.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Collection<FileObject> findLibraryDescriptors(FileObject classpathRoot, String suffix) {
        Collection<FileObject> files = new ArrayList<>();
        Enumeration<? extends FileObject> fos = classpathRoot.getChildren(true); //scan all files in the jar
        while (fos.hasMoreElements()) {
            FileObject file = fos.nextElement();
            if(!file.isValid() || !file.isData()) {
                continue;
}
            if (file.getNameExt().toLowerCase(Locale.US).endsWith(suffix)) { //NOI18N
                //found library, create a new instance and cache it
                files.add(file);
            }
        }
        return files;
    }
 
Example 8
Source File: JavadocAndSourceRootDetection.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static FileObject findAllSourceRoots(final FileObject folder, final Collection<? super FileObject> result,
        final AtomicBoolean canceled, final int depth) {
    if (depth == SRC_TRAVERSE_DEEPTH) {
        return null;
    }
    if (!VisibilityQuery.getDefault().isVisible(folder)) {
        return null;
    }
    if (isRecursiveSymLink(folder)) {
        return null;
    }
    final FileObject[] children = folder.getChildren();
    for (FileObject child : children) {
        if (canceled != null && canceled.get()) {
            return null;
        } else if (child.isData() && "text/x-java".equals(FileUtil.getMIMEType(child, "text/x-java"))) {   //NOI18N
            final FileObject root = findPackageRoot(child);
            if (root != null) {
                result.add(root);
            }
            return root;
        } else if (child.isFolder()) {
            final FileObject upTo = findAllSourceRoots(child, result, canceled, depth+1);
            if (upTo != null && !upTo.equals(child)) {
                return upTo;
            }
        }
    }
    return null;
}
 
Example 9
Source File: Watcher.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void register(FileObject fo) {
    Ext<?> ext = ext();
    if (ext == null) {
        return;
    }
    if (fo.isData()) {
        fo = fo.getParent();
    }
    ext.register(fo);
}
 
Example 10
Source File: ZendPhpFrameworkProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isInPhpModule(PhpModule phpModule) {
    FileObject sourceDirectory = phpModule.getSourceDirectory();
    if (sourceDirectory == null) {
        // broken project
        return false;
    }
    FileObject zfProject = sourceDirectory.getFileObject(".zfproject.xml"); // NOI18N
    return zfProject != null && zfProject.isData() && zfProject.isValid();
}
 
Example 11
Source File: ConfigurationFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<FileObject> getConfigFilesRecursively(FileObject parent) {
    List<FileObject> result = new ArrayList<>();
    for (FileObject child : parent.getChildren()) {
        if (VisibilityQuery.getDefault().isVisible(child)) {
            if (child.isData()
                    && (CONFIG_FILE_EXTENSIONS.contains(child.getExt().toLowerCase()) || FileUtils.isPhpFile(child))) {
                result.add(child);
            } else if (child.isFolder()) {
                result.addAll(getConfigFilesRecursively(child));
            }
        }
    }
    return result;
}
 
Example 12
Source File: Utils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Image loadIcon(FileObject iconFile, int type) {
    if (iconFile != null && iconFile.isData()) {
        try (InputStream in = iconFile.getInputStream()) {
            return ImageIO.read(in);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return Node.EMPTY.getIcon(type);
}
 
Example 13
Source File: Watcher.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isWatched(FileObject fo) {
    Ext<?> ext = ext();
    if (ext == null) {
        return false;
    }
    if (fo.isData()) {
        fo = fo.getParent();
    }
    return ext.isWatched(fo);
}
 
Example 14
Source File: WildflyStartRunnable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String findLogManager(String serverDirPath) {
    StringBuilder logManagerPath = new StringBuilder(serverDirPath);
    logManagerPath.append(File.separatorChar).append("modules").append(File.separatorChar).append("system");
    logManagerPath.append(File.separatorChar).append("layers").append(File.separatorChar).append("base");
    logManagerPath.append(File.separatorChar).append("org").append(File.separatorChar).append("jboss");
    logManagerPath.append(File.separatorChar).append("logmanager").append(File.separatorChar).append("main");
    FileObject logManagerDir = FileUtil.toFileObject(new File(logManagerPath.toString()));
    for (FileObject child : logManagerDir.getChildren()) {
        if (child.isData() && "jar".equalsIgnoreCase(child.getExt())) {
            return child.getPath();
        }
    }
    return "";
}
 
Example 15
Source File: FileSearchUtility.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static FileObject guessDocBase(FileObject dir) {
    FileObject potentialDocBase = null;
    Enumeration<FileObject> ch = getChildrenToDepth(dir, 3, true);
    while (ch.hasMoreElements ()) {
        FileObject f = ch.nextElement ();
        if (f.isData() && f.getExt().equals("jsp")) { //NOI18N
            return f.getParent();
        } else if (f.isFolder() && (f.getName().equalsIgnoreCase("web") || f.getName().equalsIgnoreCase("webroot"))) { //NOI18N
            potentialDocBase = f;
        }
    }
    
    return potentialDocBase;
}
 
Example 16
Source File: CleanupProjectAction.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void scanFiles(final FileObject folder, final ArrayList<String> paths) {
    FileObject[] children = folder.getChildren();
    for (FileObject fileObject : children) {
        boolean stay = false;
        if (fileObject.isFolder() && !fileObject.isVirtual()) {
            scanFiles(fileObject, paths);
            stay = true;
        } else if (fileObject.isData()) {
            if ("png".equalsIgnoreCase(fileObject.getExt())
                    || "jpg".equalsIgnoreCase(fileObject.getExt())
                    || "dds".equalsIgnoreCase(fileObject.getExt())
                    || "dae".equalsIgnoreCase(fileObject.getExt())
                    || "bmp".equalsIgnoreCase(fileObject.getExt())) {
                for (String path : paths) {
                    if (fileObject.getPath().endsWith(path)) {
                        stay = true;
                    }
                }
                if (!stay) {
                    try {
                        Logger.getLogger(CleanupProjectAction.class.getName()).log(Level.INFO, "Delete unused file {0}", fileObject);
                        fileObject.delete();
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            }
        }
    }
}
 
Example 17
Source File: Hinter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to find the instance associated with a file.
 * If it is a folder, or not a {@code *.instance} file, null is returned.
 * If it has an {@code instanceCreate} attribute, that is used, else
 * {@code instanceClass}, and finally the class implied by the filename.
 * @param file any file
 * @return a methodvalue or newvalue attribute, or null
 * @see #findAndModifyDeclaration
 */
public @CheckForNull Object instanceAttribute(FileObject file) {
    if (!file.isData() || !file.hasExt("instance")) {
        return null; // not supporting *.settings etc. for now
    }
    Object instanceCreate = file.getAttribute("literal:instanceCreate");
    if (instanceCreate != null) {
        return instanceCreate;
    }
    Object clazz = file.getAttribute("instanceClass");
    if (clazz != null) {
        return "new:" + clazz;
    }
    return "new:" + file.getName().replace('-', '.');
}
 
Example 18
Source File: SourceUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean isJava(final FileObject fo) {
    return  "java".equalsIgnoreCase(fo.getExt()) && fo.isData(); //NOI18N
}
 
Example 19
Source File: J2SEPlatformDefaultJavadocImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull
Collection<? extends URI> accept(@NonNull FileObject fo) {
    if (fo.canRead()) {
        if (fo.isFolder()) {
            if ("docs".equals(fo.getName())) {  //NOI18N
                return Collections.singleton(fo.toURI());
            }
        } else if (fo.isData()) {
            final String nameExt = fo.getNameExt();
            final String vendorPath = VENDOR_DOCS.get(nameExt);
            if (vendorPath != null) {
                if (FileUtil.isArchiveFile(fo)) {
                    try {
                        return Collections.singleton(
                            new URL (FileUtil.getArchiveRoot(fo.toURL()).toExternalForm() + vendorPath).toURI());
                    } catch (MalformedURLException | URISyntaxException e) {
                        LOG.log(
                            Level.INFO,
                            "Invalid Javadoc URI for file : {0}, reason: {1}",
                            new Object[]{
                                FileUtil.getFileDisplayName(fo),
                                e.getMessage()
                        });
                        //pass
                    }
                }
            } else if (DOCS_FILE_PATTERN.matcher(nameExt).matches() && !JAVAFX_FILE_PATTERN.matcher(nameExt).matches()) {
                final FileObject root = FileUtil.getArchiveRoot(fo);
                if (root != null) {
                    final List<URI> roots = new ArrayList<>(DOCS_PATHS.size());
                    for (String path : DOCS_PATHS) {
                        final FileObject docRoot = root.getFileObject(path);
                        if (docRoot != null) {
                            roots.add(docRoot.toURI());
                        }
                    }
                    return Collections.unmodifiableCollection(roots);
                }
            }
        }
    }
    return Collections.emptySet();
}
 
Example 20
Source File: RulesManager.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Read rules from system filesystem */
private List<Pair<Rule,FileObject>> readRules( FileObject folder ) {
    List<Pair<Rule,FileObject>> rules = new LinkedList<Pair<Rule,FileObject>>();
    
    if (folder == null) {
        return rules;
    }

    Queue<FileObject> q = new LinkedList<FileObject>();
    
    q.offer(folder);
    
    while(!q.isEmpty()) {
        FileObject o = q.poll();
        
        o.removeFileChangeListener(this);
        o.addFileChangeListener(this);
        
        if (o.isFolder()) {
            q.addAll(Arrays.asList(o.getChildren()));
            continue;
        }
        
        if (!o.isData()) {
            continue;
        }
        
        String name = o.getNameExt().toLowerCase();

        if ( o.canRead() ) {
            Rule r = null;
            if ( name.endsWith( INSTANCE_EXT ) ) {
                r = instantiateRule(o);
            }
            if ( r != null ) {
                rules.add( new Pair<Rule,FileObject>( r, o ) );
            }
        }
    }
    return rules;
}