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

The following are Jave code examples for showing how to use equals() 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.
+ Save this method
Example 1
Project: incubator-netbeans   File: BrowserSupport.java   View Source Code Vote up 6 votes
/**
 * Returns URL which was opened in the browser and which was associated with
 * given FileObject. That is calling load(URL, FileObject) creates mapping 
 * between FileObject in IDE side and URL in browser side and this method 
 * allows to use the mapping to retrieve URL.
 * 
 * If checkDependentFiles parameter is set to true then 
 * DependentFileQuery.isDependent will be consulted to check whether URL opened
 * in the browser does not depend on given FileObject. If answer is yes than
 * any change in this FileObject should be reflected in browser and URL
 * should be refreshed in browser.
 */
public URL getBrowserURL(FileObject fo, boolean checkDependentFiles) {
    Project project = FileOwnerQuery.getOwner(fo);
    if (file == null || currentURL == null) {
        return null;
    }
    if (checkDependentFiles) {
        if ( file.equals( project.getProjectDirectory() ) || DependentFileQuery.isDependent(file, fo)) {
            // Two cases :
            // - a project was "Run" and we have no idea which exact project's 
            //   file was opened in browser;
            //   because "fo" belongs to the project we could say
            //   that URL corresponding for this fo is project's URL;
            //   let's first check other opened browsers for better match and
            //   if nothing better is found we can return project's URL
            // - <code>file</code> depends on <code>fo</code>
            return currentURL;
        }
    } 
    if (fo.equals(file)) {
        return currentURL;
    }
    return null;
}
 
Example 2
Project: incubator-netbeans   File: TemplatesPanel.java   View Source Code Vote up 6 votes
private static Node getTemplateNode(FileObject fo, FileObject rootFO) {
    if (rootFO.equals(fo)) {
        return getTemplateRootNode();
    }
    Node parent = getTemplateNode(fo.getParent(), rootFO);
    if (parent == null) {
        return null;
    }
    Children ch = parent.getChildren();
    for (Node node : ch.getNodes(true)) {
        if (fo.equals(node.getLookup().lookup(FileObject.class))) {
            return node;
        }
    }
    return null;
}
 
Example 3
Project: incubator-netbeans   File: ModuleNode.java   View Source Code Vote up 6 votes
@NonNull
private static FileObject getModuleFolder(@NonNull FileObject srcRoot) {
    final ClassPath msp = ClassPath.getClassPath(srcRoot, JavaClassPathConstants.MODULE_SOURCE_PATH);
    if (msp == null) {
        return srcRoot;
    }
    final FileObject owner = msp.findOwnerRoot(srcRoot);
    if (owner == null) {
        return srcRoot;
    }
    FileObject prev = srcRoot;
    while (!srcRoot.equals(owner)) {
        prev = srcRoot;
        srcRoot = srcRoot.getParent();
    }
    return prev;
}
 
Example 4
Project: incubator-netbeans   File: BaseProcessor.java   View Source Code Vote up 6 votes
protected void compileReferences(Project project, FileObject fileObject) {
    if (project == null) {
        // we need project for dependencies
        LOGGER.log(Level.INFO, "Cannot compile 'import' file {0}, no project", fileObject);
        return;
    }
    try {
        DependenciesGraph dependenciesGraph = CssIndex.get(project).getDependencies(fileObject);
        for (FileObject referring : dependenciesGraph.getAllReferingFiles()) {
            if (fileObject.equals(referring)) {
                // ignore myself
                continue;
            }
            processFile(project, referring, null, null);
        }
    } catch (IOException ex) {
        LOGGER.log(Level.WARNING, null, ex);
    }
}
 
Example 5
Project: incubator-netbeans   File: MavenFileEncodingQueryImpl.java   View Source Code Vote up 5 votes
private FileObject isWithin(URI[] res, FileObject file) throws MalformedURLException {
    for (URI ur : res) {
        FileObject fo = URLMapper.findFileObject(ur.toURL());
        if (fo != null && (fo.equals(file) || FileUtil.isParentOf(fo, file))) {
            return fo;
        } 
    }
    return null;
    
}
 
Example 6
Project: incubator-netbeans   File: FolderChildren.java   View Source Code Vote up 5 votes
final Node createNode(FolderChildrenPair pair) {
    DataObject obj;
    long time = System.currentTimeMillis();
    Node ret = null;
    try {
        FileObject pf = pair.primaryFile;
        obj = DataObject.find (pf);
        if (
            obj.isValid() &&
            pf.equals(obj.getPrimaryFile()) &&
            (filter == null || filter.acceptDataObject (obj))
        ) {
            ret = obj.getClonedNodeDelegate (filter);
            if (!obj.isValid()) {
                // #153008 - DataObject became invalid meanwhile
                ret = null;
            }
        } 
    } catch (DataObjectNotFoundException e) {
        Logger.getLogger(FolderChildren.class.getName()).log(Level.FINE, null, e);
    } finally {
        long took = System.currentTimeMillis() - time;
        if (err.isLoggable(Level.FINE)) {
            err.log(Level.FINE, "createNodes: {0} took: {1} ms", new Object[]{pair, took});
            err.log(Level.FINE, "  returning: {0}", ret);
        }
    }
    return ret;
}
 
Example 7
Project: incubator-netbeans   File: ProfileProblemsProviderImpl.java   View Source Code Vote up 5 votes
@Override
public boolean equals(@NullAllowed Object other) {
    if (other == this) {
        return true;
    }
    if (!(other instanceof ProfileResolver)) {
        return false;
    }
    final ProfileResolver otherResolver = (ProfileResolver) other;
    final FileObject projDir = antProjectHelper.getProjectDirectory();
    final FileObject otherProjDir = otherResolver.antProjectHelper.getProjectDirectory();
    return
        currentProfile.equals(otherResolver.currentProfile) &&
        (projDir == null ? otherProjDir == null : projDir.equals(otherProjDir));
}
 
Example 8
Project: incubator-netbeans   File: DependentFileQuery.java   View Source Code Vote up 5 votes
/**
 * Does "master" FileObject depends on "dependent" FileObject? Typical usage will
 * be to answer questions like "does foo.html depends on style.css?"
 */
public static boolean isDependent(FileObject master, FileObject dependent) {
    if (dependent.equals(master)) {
        return true;
    }
    for (DependentFileQueryImplementation impl : lookup.allInstances()) {
        if (impl.isDependent(master, dependent) == DependentFileQueryImplementation.Dependency.YES) {
            return true;
        }
    }
    
    return false;
}
 
Example 9
Project: incubator-netbeans   File: UnitTestForSourceQueryImpl.java   View Source Code Vote up 5 votes
private URL[] find(FileObject file, SourceRoots from, SourceRoots to) {
    Project p = FileOwnerQuery.getOwner(file);
    if (p == null) {
        return null;
    }
    for (FileObject fromRoot : from.getRoots()) {
        if (fromRoot.equals(file)) {
            return to.getRootURLs();
        }
    }
    return null;
}
 
Example 10
Project: incubator-netbeans   File: SourceAnalyzerTest.java   View Source Code Vote up 5 votes
@Override
public Result getSourceLevel(FileObject javaFile) {
    final FileObject _root = root;
    if (_root != null && (_root.equals(javaFile) || FileUtil.isParentOf(_root, javaFile))) {
        return R;
    }
    return null;
}
 
Example 11
Project: incubator-netbeans   File: Actions.java   View Source Code Vote up 5 votes
private static DataShadow findShadow (DataFolder f, DataObject dobj) {
    FileObject fo = dobj.getPrimaryFile();
    if (fo != null) {
        DataObject [] arr = f.getChildren();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] instanceof DataShadow) {
                DataShadow obj = (DataShadow) arr[i];
                if (fo.equals(obj.getOriginal().getPrimaryFile())) {
                    return obj;
                }
            }
        }
    }
    return null;
}
 
Example 12
Project: incubator-netbeans   File: DiskFileKey.java   View Source Code Vote up 5 votes
public boolean equals(Object o) {
    if (this == o) return true;

    if (o instanceof DiskFileKey) {

        DiskFileKey key = (DiskFileKey) o;

        if (hashCode != key.hashCode) return false;
        FileObject fo2 = key.fileObject;
        FileObject fo = fileObject;

        if (fo == fo2) return true;

        try {
            FileSystem fs = fo.getFileSystem();
            FileSystem fs2 = fo2.getFileSystem();
            if (fs.equals(fs2)) {
                return fo.equals(fo2);
            } else {
                // fallback use absolute paths (cache them)
                if (absolutePath == null) {
                    File f = FileUtil.toFile(fo);
                    absolutePath = f.getAbsolutePath();
                }
                if (key.absolutePath == null) {
                    File f2 = FileUtil.toFile(fo2);
                    key.absolutePath = f2.getAbsolutePath();
                }
                return absolutePath.equals(key.absolutePath);
            }
        } catch (FileStateInvalidException e) {
            ErrorManager err = ErrorManager.getDefault();
            err.notify(e);
        }
    }
    return false;
}
 
Example 13
Project: incubator-netbeans   File: DiffSidebarManager.java   View Source Code Vote up 5 votes
private boolean matches(DiffSidebar sidebar, Set<FileObject> fileObjects) {
    if (fileObjects == null) return true;
    for (FileObject fileObject : fileObjects) {
        if (fileObject.equals(sidebar.getFileObject())) return true;
    }
    return false;
}
 
Example 14
Project: incubator-netbeans   File: CPUtils.java   View Source Code Vote up 5 votes
/**
 * Gets {@link CPCssIndexModel}s for all referred or related files (transitionally)
 *
 * @param allRelatedFiles if true the map will takes into account file relations regardless the direction of the imports. 
 * if false then also referred files are taken into account.
 * @param file the base file
 * @param excludeTheBaseFile if true, model for the file passed as argument is not added to the result map.
 * @return
 */
public static Map<FileObject, CPCssIndexModel> getIndexModels(FileObject file, DependencyType dependencyType, boolean excludeTheBaseFile) throws IOException {
    Map<FileObject, CPCssIndexModel> models = new LinkedHashMap<>();
    Project project = FileOwnerQuery.getOwner(file);
    if (project != null) {
        CssIndex index = CssIndex.get(project);
    DependenciesGraph dependencies = index.getDependencies(file);
    Collection<FileObject> referred = dependencies.getFiles(dependencyType);
    for (FileObject reff : referred) {
        if (excludeTheBaseFile && reff.equals(file)) {
            //skip current file (it is included to the referred files list)
            continue;
        }
        if (file.isSymbolicLink() && reff.getPath().equals(file.readSymbolicLinkPath())) {
            continue;
        }
        if (!reff.getPath().contains(project.getProjectDirectory().getPath())) {
            continue;
        }
        
        CPCssIndexModel cpIndexModel = (CPCssIndexModel) index.getIndexModel(CPCssIndexModel.Factory.class, reff);
        if (cpIndexModel != null) {
            models.put(reff, cpIndexModel);
        }

    }
    }
    return models;
}
 
Example 15
Project: incubator-netbeans   File: MavenSharabilityQueryImpl.java   View Source Code Vote up 4 votes
public @Override SharabilityQuery.Sharability getSharability(URI uri) {
    //#119541 for the project's root, return MIXED right away.
    File file = FileUtil.normalizeFile(Utilities.toFile(uri));
    FileObject fo = FileUtil.toFileObject(file);
    if (fo != null && fo.equals(project.getProjectDirectory())) {
        return SharabilityQuery.Sharability.MIXED;
    }
    File basedir = FileUtil.toFile(project.getProjectDirectory());
    // is this condition necessary?
    if (!file.getAbsolutePath().startsWith(basedir.getAbsolutePath())) {
        return SharabilityQuery.Sharability.UNKNOWN;
    }
    if (basedir.equals(file.getParentFile())) {
        // Interesting cases are of direct children.
        if (file.getName().equals("pom.xml")) { // NOI18N
            return SharabilityQuery.Sharability.SHARABLE;
        }
        if ("nbproject".equals(file.getName())) { //NOI18N
            // screw the netbeans profiler directory creation.
            // #98662
            return SharabilityQuery.Sharability.NOT_SHARABLE;
        }
        if (file.getName().startsWith("nbactions")) { //NOI18N
            //non shared custom configurations shall not be added to version control.
            M2ConfigProvider configs = project.getLookup().lookup(M2ConfigProvider.class);
            if (configs != null) {
                Collection<M2Configuration> col = configs.getNonSharedConfigurations();
                for (M2Configuration conf : col) {
                    if (file.getName().equals(M2Configuration.getFileNameExt(conf.getId()))) {
                        return SharabilityQuery.Sharability.NOT_SHARABLE;
                    }
                }
            }
        }
        if (file.getName().equals("src")) { // NOI18N
            // hardcoding this name since Maven will only report particular subtrees
            return SharabilityQuery.Sharability.SHARABLE; // #174010
        }
    }

    //this part is slow if invoked on built project that is not opened (needs to load the embedder)
    //can it be replaced with code not touching the embedder?
    MavenProject proj = project.getLookup().lookup(NbMavenProject.class).getMavenProject();
    Build build = proj.getBuild();
    if (build != null && build.getDirectory() != null) {
        File target = new File(build.getDirectory());
        if (target.equals(file) || file.getAbsolutePath().startsWith(target.getAbsolutePath())) {
            return SharabilityQuery.Sharability.NOT_SHARABLE;
        }
    }

    // Some other subdir with potentially unknown contents.
    if (file.isDirectory()) {
        return SharabilityQuery.Sharability.MIXED;
    } else {
        return SharabilityQuery.Sharability.UNKNOWN;
    }
}
 
Example 16
Project: incubator-netbeans   File: ProjectsRootNodePhysicalViewModeSourcesTest.java   View Source Code Vote up 4 votes
@Override public boolean contains(FileObject file) {
    return file.equals(root);
}
 
Example 17
Project: incubator-netbeans   File: VisibilitySupport.java   View Source Code Vote up 4 votes
boolean isVisible(
    @NonNull FileObject file,
    @NullAllowed final FileObject root) {
    long st = 0L;
    if (LOGGER.isLoggable(Level.FINER)) {
        st = System.currentTimeMillis();
    }
    try {
        final VisibilityQuery vq = VisibilityQuery.getDefault();
        final Deque<FileObject> fta = new ArrayDeque<FileObject>();
        Boolean vote = null;
        boolean folder = false;
        while (root != null && !root.equals(file)) {
            vote = visibilityCache.get(file);
            if (vote != null) {
                break;
            }
            if (folder || file.isFolder()) {
                fta.offer(file);
            }
            if (!vq.isVisible(file)) {
                vote = Boolean.FALSE;
                break;
            }
            file = file.getParent();
            folder = true;
        }
        if (vote == null) {
            vote = vq.isVisible(file);
            fta.offer(file);
        }
        if (!fta.isEmpty()) {
            synchronized(visibilityCache) {
                for (FileObject nf : fta) {
                    visibilityCache.put(nf, vote);
                }
            }
        }
        return vote;
    } finally {
        if (LOGGER.isLoggable(Level.FINER)) {
            LOGGER.log(
                Level.FINER,
                "reportVisibilityOverhead: {0}",    //NOI18N
                (System.currentTimeMillis() - st));
        }
    }
}
 
Example 18
Project: incubator-netbeans   File: UnitTestsCompilerOptionsQueryImpl.java   View Source Code Vote up 4 votes
private static boolean isArtifact(
        @NonNull final FileObject root,
        @NonNull final FileObject file) {
    return root.equals(file) || FileUtil.isParentOf(root, file);
}
 
Example 19
Project: incubator-netbeans   File: ActiveConfigActionTest.java   View Source Code Vote up 4 votes
public boolean isProject(FileObject projectDirectory) {
    return projectDirectory.equals(toCreate.fo);
}
 
Example 20
Project: incubator-netbeans   File: CanYouQueryFromRenameTest.java   View Source Code Vote up 4 votes
protected FileObject findPrimaryFile(FileObject fo) {
    if (fo.hasExt("txt") || fo.equals(instanceFile)) {
        return fo;
    }
    return null;
}