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

The following are Jave code examples for showing how to use isData() 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: SourcesHelperIssue258004Test.java   Source Code and License Vote up 6 votes
@Override
@CheckForNull
public Result isProject(@NonNull final FileObject projectDirectory) {
    final FileObject marker = projectDirectory.getFileObject(PATTERN);
    if (marker != null && marker.isData()) {
        return new Result(
                Lookup.EMPTY,
                new Callable<Project>() {
                    @Override
                    public Project call() throws Exception {
                        return new OpenedProject(projectDirectory);
                    }
                },
                "Automatic Project",    //NOI18N
                null);
    }
    return null;
}
 
Example 2
Project: incubator-netbeans   File: JavaTargetChooserPanel.java   Source Code and License Vote up 6 votes
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 3
Project: incubator-netbeans   File: JobCreator.java   Source Code and License Vote up 6 votes
public ProjectHudsonJobCreator forProject(Project project) {
    FileObject projectXml = project.getProjectDirectory().getFileObject("nbproject/project.xml"); // NOI18N
    if (projectXml != null && projectXml.isData()) {
        try {
            Document doc = XMLUtil.parse(new InputSource(projectXml.getURL().toString()), false, true, null, null);
            String type = XPathFactory.newInstance().newXPath().evaluate(
                    "/*/*[local-name(.)='type']", doc.getDocumentElement()); // NOI18N
            for (AntBasedJobCreator handler : Lookup.getDefault().lookupAll(AntBasedJobCreator.class)) {
                if (handler.type().equals(type)) {
                    return new JobCreator(project, handler.forProject(project));
                }
            }
        } catch (Exception x) {
            Logger.getLogger(JobCreator.class.getName()).log(Level.FINE, "Could not check type of " + projectXml, x);
        }
    }
    return null;
}
 
Example 4
Project: incubator-netbeans   File: GLFFilesCustomEditor.java   Source Code and License Vote up 6 votes
private static List<String> getSupportedMimeTypes () {
    List<String> result = new ArrayList<String> ();
    FileSystem fs = Repository.getDefault ().getDefaultFileSystem ();
    FileObject root = fs.findResource ("Editors");
    Enumeration e1 = root.getChildren (false);
    while (e1.hasMoreElements ()) {
        FileObject f1 = (FileObject) e1.nextElement ();
        if (f1.isData ()) continue;
        Enumeration e2 = f1.getChildren (false);
        while (e2.hasMoreElements ()) {
            FileObject f2 = (FileObject) e2.nextElement ();
            if (f2.isData ()) continue;
            FileObject fo = f2.getFileObject ("language.nbs");
            if (fo == null) continue;
            result.add (f1.getName () + '/' + f2.getName ());
        }
    }
    return result;
}
 
Example 5
Project: incubator-netbeans   File: ClassPath.java   Source Code and License Vote up 5 votes
private boolean isData(final FileObject fo) {
    Boolean isd = isDataResult.getAndSet(null);
    if (isd != null) {
        return isd;
    } else {
        return fo.isData();
    }
}
 
Example 6
Project: incubator-netbeans   File: RefactoringTestBase.java   Source Code and License Vote up 5 votes
protected void verifyContent(FileObject sourceRoot, File... files) throws Exception {
    List<FileObject> todo = new LinkedList<FileObject>();

    todo.add(sourceRoot);

    Map<String, String> content = new HashMap<String, String>();

    FileUtil.refreshFor(FileUtil.toFile(sourceRoot));

    while (!todo.isEmpty()) {
        FileObject file = todo.remove(0);

        if (file.isData()) {
            content.put(FileUtil.getRelativePath(sourceRoot, file), copyFileToString(FileUtil.toFile(file)));
        } else {
            todo.addAll(Arrays.asList(file.getChildren()));
        }
    }

    for (File f : files) {
        String fileContent = content.remove(f.filename);

        assertNotNull(f);
        assertNotNull(f.content);
        assertNotNull("Cannot find " + f.filename + " in map " + content, fileContent);
        assertEquals(getName() ,f.content.replaceAll("[ \t\r\n\n]+", " "), fileContent.replaceAll("[ \t\r\n\n]+", " "));
    }

    assertTrue(content.toString(), content.isEmpty());
}
 
Example 7
Project: incubator-netbeans   File: MavenSourcesImpl.java   Source Code and License Vote up 5 votes
/**
 * consult the SourceGroup cache, return true if anything changed..
 */
@Messages({
    "# {0} - name suffix", "SG_Generated_Sources=Generated Sources ({0})",
    "# {0} - name suffix", "SG_Generated_Test_Sources=Generated Test Sources ({0})"
})
private boolean checkGeneratedGroupCache(FileObject root, File rootFile, String nameSuffix, boolean test) {
    SourceGroup group = genSrcGroup.get(rootFile);
    if ((root == null || root.isData()) && group != null) {
        genSrcGroup.remove(rootFile);
        return true;
    }
    if (root == null || root.isData()) {
        return false;
    }
    boolean changed = false;
    String name = (test ? NAME_GENERATED_TEST_SOURCE : NAME_GENERATED_SOURCE) + nameSuffix;
    String displayName = test ? SG_Generated_Test_Sources(nameSuffix) : SG_Generated_Sources(nameSuffix);
    if (group == null) {
        group = new GeneratedGroup(project(), root, name, displayName);
        genSrcGroup.put(rootFile, group);
        changed = true;
    } else {
        if (!group.getRootFolder().isValid() || !group.getRootFolder().equals(root)) {
            group = new GeneratedGroup(project(), root, name, displayName);
            genSrcGroup.put(rootFile, group);
            changed = true;
        }
    }
    return changed;
}
 
Example 8
Project: incubator-netbeans   File: NbMavenProjectFactory.java   Source Code and License Vote up 5 votes
public @Override Project loadProject(FileObject fileObject, ProjectState projectState) throws IOException { 
    if (!isProject(fileObject)) {
        return null;
    }
    FileObject projectFile = fileObject.getFileObject("pom.xml"); //NOI18N
    if (projectFile == null || !projectFile.isData()) {
        return null;

    }
    atLeastOneMavenProjectAround.set(true);
    return new NbMavenProjectImpl(fileObject, projectFile, projectState);
}
 
Example 9
Project: incubator-netbeans   File: AnnotationViewDataImpl.java   Source Code and License Vote up 5 votes
private void computeInstances() {
    ArrayList<MarkProviderCreator> newCreators = new ArrayList<MarkProviderCreator>();
    ArrayList<UpToDateStatusProviderFactory> newFactories = new ArrayList<UpToDateStatusProviderFactory>();
    
    for(FileObject f : instanceFiles) {
        if (!f.isValid() || !f.isData()) {
            continue;
        }
        
        try {
            DataObject d = DataObject.find(f);
            InstanceCookie ic = d.getLookup().lookup(InstanceCookie.class);
            if (ic != null) {
                if (MarkProviderCreator.class.isAssignableFrom(ic.instanceClass())) {
                    MarkProviderCreator creator = (MarkProviderCreator) ic.instanceCreate();
                    newCreators.add(creator);
                } else if (UpToDateStatusProviderFactory.class.isAssignableFrom(ic.instanceClass())) {
                    UpToDateStatusProviderFactory factory = (UpToDateStatusProviderFactory) ic.instanceCreate();
                    newFactories.add(factory);
                }
            }
        } catch (Exception e) {
            LOG.log(Level.WARNING, null, e);
        }
    }
    
    this.creators = newCreators;
    this.factories = newFactories;
}
 
Example 10
Project: incubator-netbeans   File: BiIconEditor.java   Source Code and License Vote up 5 votes
/**
 * translates resource path defined in {@link java.beans.BeanInfo}'s subclass
 * that complies with {@link Class#getResource(java.lang.String) Class.getResource} format
 * to format complying with {@link ClassPath#getResourceName(org.openide.filesystems.FileObject) ClassPath.getResourceName}
 * @param resourcePath absolute path or path relative to package of BeanInfo's subclass
 * @param beanInfo BeanInfo's subclass
 * @return path as URL
 * @throws FileStateInvalidException invalid FileObject
 * @throws FileNotFoundException resource cannot be found
 */
private static URL resolveIconPath(String resourcePath, FileObject beanInfo)
        throws FileStateInvalidException, FileNotFoundException {
    ClassPath cp = ClassPath.getClassPath(beanInfo, ClassPath.SOURCE);
    String path = resourcePath.charAt(0) != '/'
            ? '/' + cp.getResourceName(beanInfo.getParent()) + '/' + resourcePath
            : resourcePath;
    FileObject res = cp.findResource(path);
    if (res != null && res.canRead() && res.isData()) {
        return res.getURL();
    } else {
        throw new FileNotFoundException(path);
    }
}
 
Example 11
Project: incubator-netbeans   File: RefTestBase.java   Source Code and License Vote up 5 votes
protected void verifyContent(FileObject sourceRoot, RefTestBase.File... files) throws Exception {
    List<FileObject> todo = new LinkedList<FileObject>();

    todo.add(sourceRoot);

    Map<String, String> content = new HashMap<String, String>();
    
    FileUtil.refreshFor(FileUtil.toFile(sourceRoot));

    while (!todo.isEmpty()) {
        FileObject file = todo.remove(0);

        if (file.isData()) {
            content.put(FileUtil.getRelativePath(sourceRoot, file), TestUtilities.copyFileToString(FileUtil.toFile(file)));
        } else {
            todo.addAll(Arrays.asList(file.getChildren()));
        }
    }

    for (RefTestBase.File f : files) {
        String fileContent = content.remove(f.filename);

        assertNotNull(f);
        assertNotNull(f.content);
        assertNotNull("Cannot find " + f.filename + " in map " + content, fileContent);
        assertEquals(getName() ,f.content.replaceAll("[ \t\n]+", " "), fileContent.replaceAll("[ \t\n]+", " "));
    }

    assertTrue(content.toString(), content.isEmpty());
}
 
Example 12
Project: incubator-netbeans   File: ModuleOraculum.java   Source Code and License Vote up 5 votes
boolean installModuleName(
        @NullAllowed FileObject root,
        @NullAllowed final FileObject fo) {
    if (fo != null && fo.isData() &&
            (FileObjects.MODULE_INFO.equals(fo.getName()) || FileObjects.CLASS.equals(fo.getExt()))) {
        //No needed to install module name for module-info or class file
        return false;
    }
    if (root == null && fo != null) {
        root = computeRootIfAbsent(fo, (f) -> {
            final ClassPath src = ClassPath.getClassPath(f, ClassPath.SOURCE);
            FileObject owner =  src != null ?
                    src.findOwnerRoot(f) :
                    null;
            if (owner == null && f.isData() && FileUtil.getMIMEType(f, null, JavacParser.MIME_TYPE) != null) {
                String pkg = parsePackage(f);
                String[] pkgElements = pkg.isEmpty() ?
                        new String[0] :
                        pkg.split("\\.");   //NOI18N
                owner = f.getParent();
                for (int i = 0; owner != null && i < pkgElements.length; i++) {
                    owner = owner.getParent();
                }
            }
            return owner;
        });
    }
    if (root == null || JavaIndex.hasSourceCache(root.toURL(), false)) {
        return false;
    }
    String name = computeModuleIfAbsent(root, (r) -> {
        final FileObject moduleInfo = r.getFileObject(FileObjects.MODULE_INFO,FileObjects.JAVA);
        if (moduleInfo == null || !moduleInfo.isData() || !moduleInfo.canRead()) {
            return null;
        }
        return SourceUtils.parseModuleName(moduleInfo);
    });
    moduleName.set(name);
    return true;
}
 
Example 13
Project: incubator-netbeans   File: Watcher.java   Source Code and License Vote up 5 votes
public static void register(FileObject fo) {
    Ext<?> ext = ext();
    if (ext == null) {
        return;
    }
    if (fo.isData()) {
        fo = fo.getParent();
    }
    ext.register(fo);
}
 
Example 14
Project: incubator-netbeans   File: DialogBinding.java   Source Code and License Vote up 5 votes
/**
 * Bind given component and given file together.
 *
 * @param fileObject to bind
 * @param offset position at which content of the component will be virtually placed
 * @param length how many characters replace from the original file
 * @param component component to bind
 */
public static void bindComponentToFile(FileObject fileObject, int offset, int length, JTextComponent component) {
    Parameters.notNull("fileObject", fileObject); //NOI18N
    Parameters.notNull("component", component); //NOI18N
    if (!fileObject.isValid() || !fileObject.isData()) {
        return;
    }
    if (offset < 0 || offset > fileObject.getSize()) {
        throw new IllegalArgumentException("Invalid offset=" + offset + "; file.size=" + fileObject.getSize()); //NOI18N
    }
    if (length < 0 || offset + length > fileObject.getSize()) {
        throw new IllegalArgumentException("Invalid lenght=" + length + "; offset=" + offset + ", file.size=" + fileObject.getSize()); //NOI18N
    }
    bind(component, null, fileObject, offset, -1, -1, length, fileObject.getMIMEType());
}
 
Example 15
Project: incubator-netbeans   File: DialogBinding.java   Source Code and License Vote up 5 votes
/**
 * Bind given component and given file together.
 * 
 * @param fileObject to bind
 * @param line an index (zero based) of the line where to place the component's content
 * @param column position (number of characters) at the line where to place the content
 * @param length how many characters replace from the original file
 * @param component component to bind
 *
 * @since 1.24
 */
public static void bindComponentToFile(FileObject fileObject, int line, int column, int length, JTextComponent component) {
    Parameters.notNull("fileObject", fileObject); //NOI18N
    Parameters.notNull("component", component); //NOI18N
    if (!fileObject.isValid() || !fileObject.isData()) {
        return;
    }
    if (line < 0 || column < 0) {
        throw new IllegalArgumentException("Invalid line=" + line + " or column=" + column); //NOI18N
    }
    bind(component, null, fileObject, -1, line, column, length, fileObject.getMIMEType());
}
 
Example 16
Project: incubator-netbeans   File: SourceMapsScanner.java   Source Code and License Vote up 5 votes
private void registerIfSourceMap(FileObject fo) {
    if (!fo.isValid() || !fo.isData() ||
        !fo.getExt().equalsIgnoreCase(SRC_MAP_EXT) ||
        !fo.canRead()) {

        return ;
    }
    LOG.log(Level.FINE, "  found source map (?) {0}", fo);
    SourceMap sm;
    try {
        sm = SourceMap.parse(fo.asText("UTF-8"));
    } catch (IOException | IllegalArgumentException ex) {
        return ;
    }
    FileObject compiledFO;
    String compiledFile = sm.getFile();
    if (compiledFile == null) {
        compiledFO = findCompiledFile(fo);
    } else {
        compiledFO = fo.getParent().getFileObject(compiledFile);
    }
    LOG.log(Level.FINE, "  have source map for generated file {0}", compiledFO);
    if (compiledFO != null) {
        synchronized (sourceMaps) {
            sourceMaps.put(fo, sm);
        }
        smt.registerTranslation(compiledFO, sm);
    }
}
 
Example 17
Project: incubator-netbeans   File: J2SEPlatformDefaultJavadocImpl.java   Source Code and License Vote up 4 votes
@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 18
Project: incubator-netbeans   File: ErrorAnnotator.java   Source Code and License Vote up 4 votes
@Override
public void run() {
    long startTime = System.currentTimeMillis();
    Collection<FileObject> toProcess;

    synchronized (ErrorAnnotator.this) {
        toProcess = ErrorAnnotator.this.toProcess;
        ErrorAnnotator.this.toProcess = null;
    }

    for (FileObject f : toProcess) {
        synchronized (ErrorAnnotator.this) {
            Integer currentState = knownFiles2Error.get(f);

            if (currentState != null && (currentState & INVALID) == 0) {
                continue;
            }
        }

        ensureListensOnFS(f);

        boolean recError = false;
        boolean nonRecError = false;
        if (f.isData()) {
            recError = nonRecError = TaskCache.getDefault().isInError(f, true);
        } else {
            ClassPath source = Utilities.getSourceClassPathFor (f);

            if (source == null) {
                //presumably not under an indexed root:
                Project p = FileOwnerQuery.getOwner(f);

                if (p != null) {
                    for (FileObject root : Utilities.findIndexedRootsUnderDirectory(p, f)) {
                        recError |= TaskCache.getDefault().isInError(root, true);
                    }
                }
            } else {
                recError = TaskCache.getDefault().isInError(f, true);
                nonRecError = TaskCache.getDefault().isInError(f, false);
            }
        }

        Integer value = (recError ? IN_ERROR_REC : 0) | (nonRecError ? IN_ERROR_NONREC : 0);
        boolean stateChanged;

        synchronized (ErrorAnnotator.this) {
            Integer origInteger = knownFiles2Error.get(f);
            int orig;

            if (origInteger != null) {
                orig = origInteger & ~INVALID;
            } else {
                orig = 0;
            }

            stateChanged = orig != value;
            knownFiles2Error.put(f, value);
        }

        if (stateChanged) {
            fireFileStatusChanged(Collections.singleton(f));
        }
    }

    long endTime = System.currentTimeMillis();
    if (Logger.getLogger(ErrorAnnotator.class.getName()).isLoggable(Level.FINE)) {
        Logger.getLogger(ErrorAnnotator.class.getName()).log(Level.FINE, "time spent in error annotations computation: {0}, cumulative time: {1}", new Object[] {(endTime - startTime), (cumulativeTime += (endTime - startTime))});
    }
}
 
Example 19
Project: incubator-netbeans   File: ProfileSupport.java   Source Code and License Vote up 4 votes
private boolean isImportant(@NonNull final FileObject file) {
    return file.isData() &&
        (FileObjects.CLASS.equals(file.getExt()) || FileObjects.SIG.equals(file.getExt()));
}
 
Example 20
Project: incubator-netbeans   File: RulesManager.java   Source Code and License Vote up 4 votes
/** 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;
}