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

The following examples show how to use org.openide.filesystems.FileObject#getChildren() . 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: TemplateAttrProvider.java    License: Apache License 2.0 6 votes vote down vote up
public static String findLicenseByMavenProjectContent(MavenProject mp) {
    // try to match the project's license URL and the mavenLicenseURL attribute of license template
    FileObject licensesFO = FileUtil.getConfigFile("Templates/Licenses"); //NOI18N
    if (licensesFO == null) {
        return null;
    }
    FileObject[] licenseFiles = licensesFO.getChildren();
    for (License license : mp.getLicenses()) {
        String url = license.getUrl();
        if (url != null) {
            for (FileObject fo : licenseFiles) {
                String str = (String)fo.getAttribute("mavenLicenseURL"); //NOI18N
                if (str != null && Arrays.asList(str.split(" ")).contains(url)) {
                    if (fo.getName().startsWith("license-")) { // NOI18N
                        return fo.getName().substring("license-".length()); //NOI18N
                    } else {
                        Logger.getLogger(TemplateAttrProvider.class.getName()).log(Level.WARNING, "Bad license file name {0} (expected to start with ''license-'' prefix)", fo.getName());
                    }
                    break;
                }
            }
        }
    }
    return null;
}
 
Example 2
Source Project: netbeans   File: ResultsManager.java    License: Apache License 2.0 6 votes vote down vote up
public int getSnapshotsCountFor(Lookup.Provider project) {
    int count = 0;
    try {
        FileObject snapshotsFolder = ProfilerStorage.getProjectFolder(project, false);
        FileObject[] children;
        
        if (snapshotsFolder == null) {
            return count;
        }
        snapshotsFolder.refresh();
        children = snapshotsFolder.getChildren();
        for (FileObject child : children) {
            if (child.getExt().equalsIgnoreCase(SNAPSHOT_EXTENSION) ||
                checkHprofFile(FileUtil.toFile(child))) count++;
        }
    } catch (IOException e) {
        LOGGER.log(Level.SEVERE, Bundle.ResultsManager_ObtainSavedSnapshotsFailedMsg(e.getMessage()), e);            
    }
    return count;
}
 
Example 3
Source Project: netbeans   File: HeapDumpWatch.java    License: Apache License 2.0 6 votes vote down vote up
private void monitor(String path) throws IllegalArgumentException {
    if ((path == null) || (path.length() == 0)) {
        throw new IllegalArgumentException("The path \"" + path + "\" can't be null."); // NOI18N
    }

    FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(new File(path)));

    if (fo != null) {
        if (!fo.isFolder()) {
            throw new IllegalArgumentException("The given path \"" + path + "\" is invalid. It must be a folder"); // NOI18N
        }

        fo.getChildren();
        fo.addFileChangeListener(listener);
        monitoredPath = fo;
    }
}
 
Example 4
Source Project: opensim-gui   File: gui.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Generic method to invoke commands available from the menu bar. The actionName passed in is usually
 * the concatentaion of the words making the menu items:
 * e.g. performAction("FileOpen") is equivalent to picking the cascade menu File->Open Model
 * 
 * @param actionName
 */
static public void performAction(String actionName) {
    FileObject myActionsFolder = FileUtil.getConfigFile("Actions/Edit");
    FileObject[] myActionsFolderKids = myActionsFolder.getChildren();
    for (FileObject fileObject : myActionsFolderKids) {
        //Probably want to make this more robust,
        //but the point is that here we find a particular Action:
        if (fileObject.getName().contains(actionName)) {
            try {
                DataObject dob = DataObject.find(fileObject);
                InstanceCookie ic = dob.getLookup().lookup(InstanceCookie.class);
                if (ic != null) {
                    Object instance = ic.instanceCreate();
                    if (instance instanceof CallableSystemAction) {
                        CallableSystemAction a = (CallableSystemAction) instance;
                        a.performAction();
                    }
                }
                break;
            } catch (Exception e) {
                ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
             }
        }
    }

}
 
Example 5
@CheckForNull
ProjectConvertor.Result isProject(@NonNull final FileObject folder) {
    for (FileObject fo : folder.getChildren()) {
        if (requiredPattern.matcher(fo.getNameExt()).matches()) {
            return getProjectConvertor().isProject(folder);
        }
    }
    return null;
}
 
Example 6
Source Project: netbeans   File: WebFolderListener.java    License: Apache License 2.0 5 votes vote down vote up
private void renameFolder(FileObject folderObject, String oldFolderName, String newFolderName) {
    FileObject[] fileObjs = folderObject.getChildren();
    for (FileObject file : fileObjs) {

        if (file.isFolder()) {
            renameFolder(file, oldFolderName, newFolderName);
        } else {
            String newDisplayName = Page.getFolderDisplayName(webFolder, file);
            String oldDisplayName = newDisplayName.replaceFirst(newFolderName, oldFolderName);
            renameFile(file, oldDisplayName, newDisplayName);
        }
    }
}
 
Example 7
Source Project: netbeans   File: ServerRegistry.java    License: Apache License 2.0 5 votes vote down vote up
private void fetchInstances(Server server) {
    FileObject dir = FileUtil.getConfigFile(DIR_INSTALLED_SERVERS);
    FileObject[] ch = dir.getChildren();
    for (int i = 0; i < ch.length; i++) {
        String url = (String) ch[i].getAttribute(URL_ATTR);
        if (url != null && server.handlesUri(url)) {
            addInstance(ch[i]);
        }
    }
}
 
Example 8
/**
 * Recursively collects the java files from the given folder into the
 * given <code>result</code>.
 */
public static void collectChildren(FileObject folder, List<FileObject> result) {
    for (FileObject child : folder.getChildren()) {
        if (RefactoringUtil.isJavaFile(child)) {
            result.add(child);
        } else if (child.isFolder()) {
            collectChildren(child, result);
        }
    }
}
 
Example 9
Source Project: netbeans   File: SourceFileManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<JavaFileObject> list(final Location l, final String packageName, final Set<JavaFileObject.Kind> kinds, final boolean recursive) {
    //Todo: Caching of results, needs listening on FS
    List<JavaFileObject> result = new ArrayList<JavaFileObject> ();
    String _name = packageName.replace('.','/');    //NOI18N
    if (_name.length() != 0) {
        _name+='/';                                 //NOI18N
    }
    for (ClassPath.Entry entry : this.sourceRoots.entries()) {
        if (ignoreExcludes || entry.includes(_name)) {
            FileObject root = entry.getRoot();
            if (root != null) {
                FileObject tmpFile = root.getFileObject(_name);
                if (tmpFile != null && tmpFile.isFolder()) {
                    Enumeration<? extends FileObject> files = tmpFile.getChildren (recursive);
                    while (files.hasMoreElements()) {
                        FileObject file = files.nextElement();
                        if (ignoreExcludes || entry.includes(file)) {
                            final JavaFileObject.Kind kind = FileObjects.getKind(file.getExt());                                
                            if (kinds.contains(kind)) {                        
                                result.add (FileObjects.sourceFileObject(file, root));
                            }
                        }
                    }
                }
            }
        }
    }
    return result;
}
 
Example 10
private void registerOperatorUIs() {
    FileObject fileObj = FileUtil.getConfigFile("OperatorUIs");
    if(fileObj == null) {
        SystemUtils.LOG.warning("No operatorUIs found.");
        return;
    }
    final FileObject[] files = fileObj.getChildren();
    final List<FileObject> orderedFiles = FileUtil.getOrder(Arrays.asList(files), true);
    for (FileObject file : orderedFiles) {
        OperatorUIDescriptor operatorUIDescriptor = null;
        try {
            operatorUIDescriptor = createOperatorUIDescriptor(file);
        } catch (Exception e) {
            SystemUtils.LOG.severe(String.format("Failed to create operatorUI from layer.xml path '%s'", file.getPath()));
        }
        if (operatorUIDescriptor != null) {
            // must have only one operatorUI per operator
            final OperatorUIDescriptor existingDescriptor = operatorUIDescriptors.get(operatorUIDescriptor.getOperatorName());
            if (existingDescriptor != null) {
                SystemUtils.LOG.info(String.format("OperatorUI [%s] has been redeclared for [%s]!\n",
                                                   operatorUIDescriptor.getId(), operatorUIDescriptor.getOperatorName()));
            }

            operatorUIDescriptors.put(operatorUIDescriptor.getOperatorName(), operatorUIDescriptor);
            SystemUtils.LOG.fine(String.format("New operatorUI added from layer.xml path '%s': %s",
                                               file.getPath(), operatorUIDescriptor.getOperatorName()));
        }
    }
}
 
Example 11
Source Project: netbeans   File: SvnUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Determines all files and folders that belong to a given project and adds them to the supplied Collection.
 *
 * @param filteredFiles destination collection of Files
 * @param project project to examine
 */
public static void addProjectFiles(Collection<File> filteredFiles, Collection<File> rootFiles, Collection<File> rootFilesExclusions, Project project) {
    FileStatusCache cache = Subversion.getInstance().getStatusCache();
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup [] sourceGroups = sources.getSourceGroups(Sources.TYPE_GENERIC);
    for (int j = 0; j < sourceGroups.length; j++) {
        SourceGroup sourceGroup = sourceGroups[j];
        FileObject srcRootFo = sourceGroup.getRootFolder();
        File rootFile = FileUtil.toFile(srcRootFo);
        if (rootFile == null || (cache.getStatus(rootFile).getStatus() & FileInformation.STATUS_MANAGED) == 0) continue;
        rootFiles.add(rootFile);
        boolean containsSubprojects = false;
        FileObject [] rootChildren = srcRootFo.getChildren();
        Set<File> projectFiles = new HashSet<File>(rootChildren.length);
        for (int i = 0; i < rootChildren.length; i++) {
            FileObject rootChildFo = rootChildren[i];
            if (isAdministrative(rootChildFo.getNameExt())) continue;
            File child = FileUtil.toFile(rootChildFo);
            if (child == null) {
                continue;
            }
            if (sourceGroup.contains(rootChildFo)) {
                // TODO: #60516 deep scan is required here but not performed due to performace reasons
                projectFiles.add(child);
            } else {
                int status = cache.getStatus(child).getStatus();
                if (status != FileInformation.STATUS_NOTVERSIONED_EXCLUDED) {
                    rootFilesExclusions.add(child);
                    containsSubprojects = true;
                }
            }
        }
        if (containsSubprojects) {
            filteredFiles.addAll(projectFiles);
        } else {
            filteredFiles.add(rootFile);
        }
    }
}
 
Example 12
public String[] getSounds() {
    FileObject assetsFolder = getAssetFolder();
    if (assetsFolder == null) {
        return new String[]{};
    }
    Enumeration<FileObject> assets = (Enumeration<FileObject>) assetsFolder.getChildren(true);
    ArrayList<String> list = new ArrayList<String>();
    while (assets.hasMoreElements()) {
        FileObject asset = assets.nextElement();
        if (asset.getExt().equalsIgnoreCase("wav") || asset.getExt().equalsIgnoreCase("ogg")) {
            list.add(getRelativeAssetPath(asset.getPath()));
        }
    }
    return list.toArray(new String[list.size()]);
}
 
Example 13
Source Project: netbeans   File: KitsTrackerImpl.java    License: Apache License 2.0 5 votes vote down vote up
private static void _reload(Set<String> set, List<FileObject> eventSources) {
    // Get the root of the MimeLookup registry
    FileObject fo = FileUtil.getConfigFile("Editors"); //NOI18N

    // Generally may not exist (e.g. in tests)
    if (fo != null) {
        // Go through mime type types
        FileObject [] types = fo.getChildren();
        for(int i = 0; i < types.length; i++) {
            if (!isValidType(types[i])) {
                continue;
            }

            // Go through mime type subtypes
            FileObject [] subTypes = types[i].getChildren();
            for(int j = 0; j < subTypes.length; j++) {
                if (!isValidSubtype(subTypes[j])) {
                    continue;
                }

                String mimeType = types[i].getNameExt() + "/" + subTypes[j].getNameExt(); //NOI18N
                set.add(mimeType);
            }

            eventSources.add(types[i]);
        }

        eventSources.add(fo);
    }
}
 
Example 14
Source Project: netbeans   File: TemplatesPanel.java    License: Apache License 2.0 5 votes vote down vote up
private void settingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsButtonActionPerformed
    FileObject dir = FileUtil.getConfigFile(TEMPLATES_FOLDER+"/Properties");
    if (dir == null) {
        settingsButton.setEnabled(false);
        return ;
    }
    for (Enumeration<? extends FileObject> en = dir.getChildren(true); en.hasMoreElements(); ) {
        FileObject fo = en.nextElement();
        try {
            DataObject dobj = DataObject.find(fo);
            EditCookie ec = dobj.getLookup().lookup(EditCookie.class);
            if (ec != null) {
                ec.edit ();
            } else {
                OpenCookie oc = dobj.getLookup().lookup(OpenCookie.class);
                if (oc != null) {
                    oc.open ();
                } else {
                    continue;
                }
            }
            // Close the Templates dialog
            closeDialog(this);
        } catch (DataObjectNotFoundException ex) {
            continue;
        }
    }
}
 
Example 15
Source Project: netbeans   File: AutomaticRegistration.java    License: Apache License 2.0 5 votes vote down vote up
private static int unregisterWebLogicInstance(String clusterDirValue,
        String serverDirValue, String domainDirValue) {
    // tell the infrastructure that the userdir is cluster dir
    System.setProperty("netbeans.user", clusterDirValue); // NOI18N

    // we could do this via registry, but the classspath would explode
    FileObject serverInstanceDir = FileUtil.getConfigFile("J2EE/InstalledServers"); // NOI18N

    if (serverInstanceDir == null) {
        LOGGER.log(Level.INFO, "The config/J2EE/InstalledServers folder does not exist."); // NOI18N
        return 2;
    }

    Pattern pattern = Pattern.compile(
            "^" + Pattern.quote(WLDeploymentFactory.URI_PREFIX) // NOI18N
            + "(.+):(.+):" // NOI18N
            + Pattern.quote(serverDirValue)
            + ":" + Pattern.quote(domainDirValue) + "$"); // NOI18N

    try {
        for (FileObject f : serverInstanceDir.getChildren()) {
            String url = f.getAttribute(InstanceProperties.URL_ATTR).toString();
            if (url != null) {
                if (pattern.matcher(url).matches()) {
                    f.delete();
                    return 0;
                }
            }
        }
    } catch (IOException ex) {
        LOGGER.log(Level.INFO, "Cannot unregister the default WebLogic server."); // NOI18N
        LOGGER.log(Level.INFO, null, ex);
        return 6;
    }
    return 0;
}
 
Example 16
private List<String> getAllPolicyIds(Map<String,String> descriptions) {
    File home = platformImpl.getMiddlewareHome();
    FileObject middlewareHome = FileUtil.toFileObject(FileUtil.normalizeFile(home));
    FileObject modules = middlewareHome.getFileObject(ORACLE_COMMON_MODULES); //NOI18N
    if (modules == null) {
        return Collections.emptyList();
    }
    FileObject policiesFolder = null;
    for (FileObject folder : modules.getChildren()) {
        if (folder.getName().startsWith("oracle.wsm.policies")) {
            // NOI18N
            policiesFolder = folder;
            break;
        }
    }
    if (policiesFolder == null) {
        return Collections.emptyList();
    }
    FileObject[] jars = policiesFolder.getChildren();
    FileObject policies = null;
    for (FileObject jar : jars) {
        FileObject archiveRoot = FileUtil.getArchiveRoot(jar);
        policies = archiveRoot.getFileObject("META-INF/policies/oracle/"); //      NOI18N
        if (policies != null) {
            break;
        }
    }
    List<String> allIds = new LinkedList<String>();
    if (policies != null) {
        for (FileObject fileObject : policies.getChildren()) {
            String name = fileObject.getName();
            allIds.add(name);
            if ( descriptions!= null ){ 
                descriptions.put( name , readFile(fileObject) );
            }
        }
    }
    return allIds;
}
 
Example 17
Source Project: netbeans   File: ProjectOperations.java    License: Apache License 2.0 5 votes vote down vote up
private void restoreConfigurations (final Operations original) {
    final FileSystem fs = original.configs;
    original.configs = null;
    if (fs != null) {
        try {
            FileObject fo = fs.getRoot().getFileObject("config.properties");        //NOI18N
            if (fo != null) {
                FileObject privateFolder = FileUtil.createFolder(project.getProjectDirectory(), "nbproject/private");  //NOI18N
                if (privateFolder != null) {
                    // #131857: SyncFailedException : check for file existence before FileUtil.copyFile
                    FileObject oldFile = privateFolder.getFileObject(fo.getName(), fo.getExt());
                    if (oldFile != null) {
                        //Probably delete outside of IDE + move. First try to repair FS cache
                        privateFolder.refresh();
                        oldFile = privateFolder.getFileObject(fo.getName(), fo.getExt());
                        if (oldFile != null) {
                            //The file still exists, delete it.
                            oldFile.delete();
                        }
                    }

                    FileUtil.copyFile(fo, privateFolder, fo.getName());
                }
            }
            fo = fs.getRoot().getFileObject("configs");                             //NOI18N
            if (fo != null) {
                FileObject configsFolder = FileUtil.createFolder(project.getProjectDirectory(), "nbproject/private/configs");  //NOI18N
                if (configsFolder != null) {
                    for (FileObject child : fo.getChildren()) {
                        FileUtil.copyFile(child, configsFolder, child.getName());
                    }
                }
            }
        } catch (IOException ioe) {
            Exceptions.printStackTrace(ioe);
        }
    }
}
 
Example 18
Source Project: netbeans   File: ModuleChangeHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void refreshGroupsFolder () {
    FileObject [] arr = groupsModuleFolder.getChildren();

    groupsModuleChildren.clear();
    for (FileObject fo : arr) {
        if (fo.isFolder()) {
            groupsModuleChildren.add(fo);
            fo.getChildren();  // #156573 - to get events about children
        }
    }
}
 
Example 19
Source Project: netbeans   File: ResultsManager.java    License: Apache License 2.0 4 votes vote down vote up
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 20
Source Project: netbeans   File: TestUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Returns full names of all primary Java classes
 * withing the specified folder (non-recursive).
 *
 * @param  packageFolder  folder to search
 * @param  classPath  classpath to be used for the search
 * @return  list of full names of all primary Java classes
 *          within the specified package
 */
public static List<String> getJavaFileNames(FileObject packageFolder, ClasspathInfo cpInfo) {
    FileObject[] children = packageFolder.getChildren();
    if (children.length == 0) {
        return Collections.<String>emptyList();
    }
    
    final Collection<FileObject> javaFiles = new ArrayList<FileObject>(children.length);
    for (FileObject child : children) {
        if (!child.isFolder()
                && child.isValid()
                && child.getMIMEType().equals(JAVA_MIME_TYPE)) {
            javaFiles.add(child);
        }
    }
    if (javaFiles.isEmpty()) {
        return Collections.<String>emptyList();
    }

    FileObject[] javaFilesArr = (javaFiles.size() == children.length)
                                ? children
                                : javaFiles.toArray(new FileObject[javaFiles.size()]);
    final JavaSource source = JavaSource.create(cpInfo, javaFilesArr);
    if (source == null) {
        ErrorManager.getDefault().log(
                ErrorManager.EXCEPTION,
                "Could not get JavaSource for files "               //NOI18N
                        + javaFilesArr);
        return Collections.<String>emptyList();
    }

    List<ElementHandle<TypeElement>> topClasses;
    try {
        topClasses = TopClassFinder.findMainTopClasses(source);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        topClasses = null;
    }
    if ((topClasses == null) || topClasses.isEmpty()) {
        return Collections.<String>emptyList();
    }
        
    final List<String> result = new ArrayList<String>(topClasses.size());
    for (ElementHandle<TypeElement> topClassHandle : topClasses) {
        result.add(topClassHandle.getQualifiedName());
    }
    return result.isEmpty() ? Collections.<String>emptyList() : result;
}