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

The following examples show how to use org.openide.filesystems.FileObject#getData() . 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: JavaSourceHelper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static List<JavaSource> getJavaSources(Project project) {
    List<JavaSource> result = new ArrayList<JavaSource>();
    SourceGroup[] groups = SourceGroupSupport.getJavaSourceGroups(project);

    for (SourceGroup group : groups) {
        FileObject root = group.getRootFolder();
        Enumeration<? extends FileObject> files = root.getData(true);

        while (files.hasMoreElements()) {
            FileObject fobj = files.nextElement();

            if (fobj.getExt().equals(JAVA_EXT)) {
                JavaSource source = JavaSource.forFileObject(fobj);
                result.add(source);
            }
        }
    }

    return result;
}
 
Example 2
Source File: ApisupportAntUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Scan recursively through all folders in the given <code>dir</code> and
 * add every directory/package, which contains at least one file with the
 * given extension (probably class or java), into the given
 * <code>validPkgs</code> set. Added entries are in the form of regular java
 * package (x.y.z)
 */
private static void scanForPackages(final Set<FileObject> validPkgs, final FileObject dir, final String ext) {
    if (dir == null) {
        return;
    }
    for (Enumeration en1 = dir.getFolders(false); en1.hasMoreElements(); ) {
        FileObject subDir = (FileObject) en1.nextElement();
        if (VisibilityQuery.getDefault().isVisible(subDir)) {
            scanForPackages(validPkgs, subDir, ext);
        }
    }
    for (Enumeration en2 = dir.getData(false); en2.hasMoreElements(); ) {
        FileObject kid = (FileObject) en2.nextElement();
        if (kid.hasExt(ext) && Utilities.isJavaIdentifier(kid.getName())) {
            // at least one class inside directory -> valid package
            validPkgs.add(dir);
            break;
        }
    }
}
 
Example 3
Source File: JavaSourceHelper.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static List<JavaSource> getJavaSources(Project project) {
    List<JavaSource> result = new ArrayList<JavaSource>();
    SourceGroup[] groups = SourceGroupSupport.getJavaSourceGroups(project);

    for (SourceGroup group : groups) {
        FileObject root = group.getRootFolder();
        Enumeration<? extends FileObject> files = root.getData(true);

        while (files.hasMoreElements()) {
            FileObject fobj = files.nextElement();

            if (fobj.getExt().equals(JAVA_EXT)) {
                JavaSource source = JavaSource.forFileObject(fobj);
                result.add(source);
            }
        }
    }

    return result;
}
 
Example 4
Source File: JavaSourceHelper.java    From jeddict with Apache License 2.0 6 votes vote down vote up
public static List<JavaSource> getJavaSources(Project project) {
    List<JavaSource> result = new ArrayList<>();
    SourceGroup[] groups = getJavaSourceGroups(project);

    for (SourceGroup group : groups) {
        FileObject root = group.getRootFolder();
        Enumeration<? extends FileObject> files = root.getData(true);

        while (files.hasMoreElements()) {
            FileObject fobj = files.nextElement();

            if (fobj.getExt().equals(JAVA_EXT)) {
                JavaSource source = JavaSource.forFileObject(fobj);
                result.add(source);
            }
        }
    }

    return result;
}
 
Example 5
Source File: FileUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void processFolder(FileObject file, NameObtainer nameObtainer, SortedSet<String> result, boolean onlyRoots) {
    Enumeration<? extends FileObject> dataFiles = file.getData(false);
    Enumeration<? extends FileObject> folders = file.getFolders(false);

    if (dataFiles.hasMoreElements()) {
        while (dataFiles.hasMoreElements()) {
            FileObject kid = dataFiles.nextElement();
            if ((kid.hasExt("java") || kid.hasExt("class")) && Utilities.isJavaIdentifier(kid.getName())) {
                // at least one java or class inside directory -> valid package
                String packageName = nameObtainer.getPackageName(file);
                if (packageName == null) {
                    continue;
                }
                result.add(packageName);
                if (onlyRoots) {
                    // don't recurse into subfolders
                    return;
                } else {
                    // recurse inot subfolders
                    break;
                }
            }
        }
    }

    while (folders.hasMoreElements()) {
        processFolder(folders.nextElement(), nameObtainer, result, onlyRoots);
    }
}
 
Example 6
Source File: J2eeUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static FileObject getWebXmlFile(Project p) {
    SourceGroup[] groups = ProjectUtils.getSources(p).getSourceGroups("web");
    for (SourceGroup group : groups) {
        FileObject root = group.getRootFolder();
        java.util.Enumeration<? extends FileObject> files = root.getData(true);
        while (files.hasMoreElements()) {
            FileObject fobj = files.nextElement();
            if (fobj.getNameExt().equals("web.xml")) {
                return fobj;
            }
        }
    }
    return null;
}
 
Example 7
Source File: ResourceUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static File getServerResourcesFile(FileObject targetFolder, boolean search){
    File serverResource = null;
    if(targetFolder != null){
        FileObject setUpFolder = setUpExists(targetFolder);
        if (search) {
            // look in the 'web' project place
            FileObject metaInf = setUpFolder.getParent().getFileObject("web/WEB-INF"); // NOI18N
            if (null == metaInf) {
                // look in the 'ant' project place
                metaInf = setUpFolder.getParent().getFileObject("src/java/META-INF"); // NOI18N
                if (null == metaInf) {
                    // look in the 'maven' project place
                    metaInf = targetFolder.getParent().getFileObject("java/META-INF"); // NOI18N
                }
            }
            if (null != metaInf) {
                FileObject resourcesFO = metaInf.getFileObject(RESOURCE_FILES[0]);
                if (null == resourcesFO) {
                    resourcesFO = metaInf.getFileObject(RESOURCE_FILES[1]);
                }
                if (null != resourcesFO) {
                    return FileUtil.toFile(resourcesFO);
                }
            }
        }

        java.util.Enumeration en = setUpFolder.getData(false);
        while(en.hasMoreElements()){
            FileObject resourceFile = (FileObject)en.nextElement();
            File resource = FileUtil.toFile(resourceFile);
            if(resource.getName().equals(RESOURCE_FILES[1])){
                serverResource = resource;
            }
            if(resource.getName().equals(RESOURCE_FILES[0])){
                serverResource = resource;
                break;
            }
        }
    }
    return serverResource;
}