Java Code Examples for org.openide.filesystems.FileUtil#isParentOf()

The following examples show how to use org.openide.filesystems.FileUtil#isParentOf() . 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: JavaSourceTestCase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ClassPath findClassPath(FileObject file, String type) {
    boolean found = false;
    for (FileObject root : roots) {
        if (root.equals(file) || FileUtil.isParentOf(root, file)) {
            found = true;
        }
    }
    if (!found) {
        return null;
    }
    if (ClassPath.SOURCE.equals(type)) {
        return srcCP;
    } else if (ClassPath.COMPILE.equals(type)) {
        return compileCP;
    } else if (ClassPath.BOOT.equals(type)) {
        return bootCP;
    }
    return null;
}
 
Example 2
Source File: PhysicalView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
static Node createNodeForSourceGroup(
        @NonNull final SourceGroup group,
        @NonNull final Project project) {
    if ("sharedlibraries".equals(group.getName())) { //NOI18N
        //HACK - ignore shared libs group in UI, it's only useful for version control commits.
        return null;
    }
    final FileObject rootFolder = group.getRootFolder();
    if (!rootFolder.isValid() || !rootFolder.isFolder()) {
        return null;
    }
    final FileObject projectDirectory = project.getProjectDirectory();
    return new ProjectIconNode(new GroupNode(
            project,
            group,
            projectDirectory.equals(rootFolder) || FileUtil.isParentOf(rootFolder, projectDirectory),
            DataFolder.findFolder(rootFolder)),
            true);
}
 
Example 3
Source File: JavaFXPlatformJavadoc.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NonNull
private Collection<? extends JavaPlatform> findJavaPlatforms(@NonNull final File jfxrt) {
    final JavaPlatform[] jps = JavaPlatformManager.getDefault().getPlatforms(
            null,
            new Specification(
                "j2se", //NOI18N
                null));
    final Collection<JavaPlatform> res = new ArrayList<JavaPlatform>(jps.length);
    final FileObject jfxrfFo = FileUtil.toFileObject(jfxrt);
    if (jfxrfFo != null) {
        for (JavaPlatform jp : jps) {
            for (FileObject installFolder : jp.getInstallFolders()) {
                if (FileUtil.isParentOf(installFolder, jfxrfFo)) {
                    res.add(jp);
                }
            }
        }
    }
    return res;
}
 
Example 4
Source File: RetoucheUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static boolean isOnSourceClasspath(FileObject fo) {
    Project p = FileOwnerQuery.getOwner(fo);
    if (p==null) return false;
    Project[] opened = OpenProjects.getDefault().getOpenProjects();
    for (int i = 0; i<opened.length; i++) {
        if (p.equals(opened[i]) || opened[i].equals(p)) {
            SourceGroup[] gr = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
            for (int j = 0; j < gr.length; j++) {
                if (fo==gr[j].getRootFolder()) return true;
                if (FileUtil.isParentOf(gr[j].getRootFolder(), fo))
                    return true;
            }
            return false;
        }
    }
    return false;
}
 
Example 5
Source File: ClassPathFileChooser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void selectNode(Node parent, FileObject fo) {
    for (Node n : parent.getChildren().getNodes(true)) {
        FileObject nodeFO = fileFromNode(n);
        if (nodeFO == fo) {
            try {
                if (fo.isFolder()) {
                    explorerManager.setExploredContext(n); // to expand the folder
                }
                explorerManager.setSelectedNodes(new Node[] { n });
            }
            catch (PropertyVetoException ex) { // should not happen
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
            }
            break;
        }
        else if (FileUtil.isParentOf(nodeFO, fo)) {
            selectNode(n, fo);
            break;
        }
    }
}
 
Example 6
Source File: BreakpointRuntimeSetter.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean acceptBreakpoint(JSLineBreakpoint lb) {
    FileObject fo = lb.getFileObject();
    if (fo == null) {
        return false;
    }
    if (RemoteFileCache.isRemoteFile(fo) != null) {
        return true;
    }
    if (FileUtil.toFile(fo) == null) {
        return true;
    }
    if (projectSourceRoots == null) {
        return true;
    }
    boolean isInPrjSources = false;
    for (FileObject psr : projectSourceRoots) {
        if (FileUtil.isParentOf(psr, fo)) {
            isInPrjSources = true;
            break;
        }
    }
    return isInPrjSources;
}
 
Example 7
Source File: DefaultClassPathProviderTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Result getSourceLevel(FileObject javaFile) {
    for (Map.Entry<FileObject,R> e : this.levels.entrySet()) {
        final FileObject root = e.getKey();
        if (root.equals(javaFile) || FileUtil.isParentOf(root, javaFile)) {
            return e.getValue();
        }
    }
    return null;
}
 
Example 8
Source File: TestUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static WebModule getWebModule(FileObject fo) {
    WebModule wm =  WebModule.getWebModule(fo);
    if (wm == null) {
        return null;
    }
    FileObject wmRoot = wm.getDocumentBase();
    if (fo == wmRoot || FileUtil.isParentOf(wmRoot, fo)) {
        return WebModule.getWebModule(fo);
    }
    return null;
}
 
Example 9
Source File: PhpUnitTestLocator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<Locations.Offset> filterPhpFiles(FileObject sourceRoot, Collection<Pair<FileObject, Integer>> files) {
    List<Locations.Offset> results = new ArrayList<>(files.size());
    for (Pair<FileObject, Integer> pair : files) {
        FileObject fileObject = pair.first();
        if (FileUtils.isPhpFile(fileObject)
                && FileUtil.isParentOf(sourceRoot, fileObject)) {
            results.add(new Locations.Offset(fileObject, pair.second()));
        }
    }
    return results;
}
 
Example 10
Source File: QuerySupportTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public ClassPath findClassPath(FileObject file, String type) {
    for (Map.Entry<FileObject,Map<String,ClassPath>> e : cps.entrySet()) {
        if (e.getKey().equals(file) || FileUtil.isParentOf(e.getKey(), file)) {
            return e.getValue().get(type);
        }
    }
    return null;
}
 
Example 11
Source File: View.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Node findPath(Node root, Object target) {
    // Check each child node in turn.
    Node[] kids = root.getChildren().getNodes(true);
    for (Node kid : kids) {
        // First ask natures.
        for (ProjectNature nature : Lookup.getDefault().lookupAll(ProjectNature.class)) {
            Node n = nature.findSourceFolderViewPath(project, kid, target);
            if (n != null) {
                return n;
            }
        }
        // Otherwise, check children and look for <source-folder>/<source-file> matches.
        if (target instanceof DataObject || target instanceof FileObject) {
            DataObject d = kid.getLookup().lookup(DataObject.class);
            if (d == null) {
                continue;
            }
            // Copied from org.netbeans.spi.java.project.support.ui.TreeRootNode.PathFinder.findPath:
            FileObject kidFO = d.getPrimaryFile();
            FileObject targetFO = target instanceof DataObject ? ((DataObject) target).getPrimaryFile() : (FileObject) target;
            if (kidFO == targetFO) {
                return kid;
            } else if (FileUtil.isParentOf(kidFO, targetFO)) {
                String relPath = FileUtil.getRelativePath(kidFO, targetFO);
                List<String> path = Collections.list(NbCollections.checkedEnumerationByFilter(new StringTokenizer(relPath, "/"), String.class, true)); // NOI18N
                // XXX see original code for justification
                path.set(path.size() - 1, targetFO.getName());
                try {
                    return NodeOp.findPath(kid, Collections.enumeration(path));
                } catch (NodeNotFoundException e) {
                    return null;
                }
            }
        }
    }
    return null;
}
 
Example 12
Source File: AutomaticModuleNameCompilerOptionsQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isOwned(
        @NonNull final FileObject file,
        @NonNull final SourceRoots roots) {
    for (FileObject root : roots.getRoots()) {
        if (root.equals(file) || FileUtil.isParentOf(root, file)) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: FileObjectIterator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isUnderRoots( FileObject fo ) {
    for( FileObject root : roots ) {
        if( FileUtil.isParentOf( root, fo ) )
            return true;
    }
    return false;
}
 
Example 14
Source File: AndroidProjects.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public static File findResFolderAsFile(Project project, FileObject layoutFo) {
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] resGroup = sources.getSourceGroups(AndroidConstants.SOURCES_TYPE_ANDROID_RES);
    for (SourceGroup sourceGroup : resGroup) {
        FileObject rootFolder = sourceGroup.getRootFolder();
        if (FileUtil.isParentOf(rootFolder, layoutFo)) {
            return FileUtil.toFile(rootFolder);
        }
    }
    if (resGroup.length > 0) {
        return FileUtil.toFile(resGroup[0].getRootFolder());
    }
    return null;
}
 
Example 15
Source File: WebProjectUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String relativePath(FileObject parent, FileObject child) {
    if (child.equals(parent)) {
        return ""; // NOI18N
    }
    if (!FileUtil.isParentOf(parent, child)) {
        throw new IllegalArgumentException("Cannot find relative path, " + parent + " is not parent of " + child);
    }
    return child.getPath().substring(parent.getPath().length() + 1);
}
 
Example 16
Source File: EarProjectOperations.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public List<FileObject> getDataFiles() {
    // add libraries folder if it is within project:
    AntProjectHelper helper = project.getAntProjectHelper();
    if (helper.getLibrariesLocation() != null) {
        File f = helper.resolveFile(helper.getLibrariesLocation());
        if (f != null && f.exists()) {
            FileObject libFolder = FileUtil.toFileObject(f).getParent();
            if (FileUtil.isParentOf(project.getProjectDirectory(), libFolder)) {
                return Collections.<FileObject>singletonList(libFolder);
            }
        }
    }
    return Collections.emptyList();
}
 
Example 17
Source File: SourceUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isIncluded (final ElementHandle<TypeElement> element, final ClasspathInfo cpInfo) {
    FileObject fobj = getFile (element,cpInfo);
    if (fobj == null) {
        //Not source
        return true;
    }
    ClassPath sourcePath = cpInfo.getClassPath(ClasspathInfo.PathKind.SOURCE);
    for (ClassPath.Entry e : sourcePath.entries()) {
        FileObject root = e.getRoot ();
        if (root != null && FileUtil.isParentOf(root,fobj)) {
            return e.includes(fobj);
        }
    }
    return true;
}
 
Example 18
Source File: SelectedTablesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean contains(FileObject file) throws IllegalArgumentException {
    return rootFolder.equals(file) || FileUtil.isParentOf(rootFolder, file);
}
 
Example 19
Source File: AntJUnitNodeOpener.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void openCallstackFrame(Node node, String frameInfo) {
       if(frameInfo.isEmpty()) { // user probably clicked on a failed test method node, find failing line within the testMethod using the stacktrace
           if (!(node instanceof JUnitTestMethodNode)) {
               return;
           }
       } else { // user probably clicked on a stacktrace node
           if (!(node instanceof JUnitCallstackFrameNode)) {
               return;
           }
       }
       // #213935 - copied from org.netbeans.modules.maven.junit.nodes.AntJUnitNodeOpener
       JUnitTestMethodNode methodNode = (JUnitTestMethodNode)UIJavaUtils.getTestMethodNode(node);
       FileLocator locator = methodNode.getTestcase().getSession().getFileLocator();
       if (locator == null) {
           return;
       }
       // Method node might belong to an inner class
       FileObject testfo = methodNode.getTestcase().getClassFileObject(true);
if(testfo == null) {
    return;
}
       final int[] lineNumStorage = new int[1];
       FileObject file = UIJavaUtils.getFile(frameInfo, lineNumStorage, locator);
       //lineNumStorage -1 means no regexp for stacktrace was matched.
       if ((file == null) && (methodNode.getTestcase().getTrouble() != null) && lineNumStorage[0] == -1) {
           //213935 we could not recognize the stack trace line and map it to known file
           //if it's a failure text, grab the testcase's own line from the stack.
           boolean methodNodeParentOfStackTraceNode = false;
           String[] st = methodNode.getTestcase().getTrouble().getStackTrace();
           if ((st != null) && (st.length > 0)) {
               int index = st.length - 1;
               //213935 we need to find the testcase linenumber to jump to.
               // and ignore the infrastructure stack lines in the process
               while (!testfo.equals(file) && index != -1 && !methodNodeParentOfStackTraceNode) {
                   file = UIJavaUtils.getFile(st[index], lineNumStorage, locator);
                   index = index - 1;
                   // if frameInfo.isEmpty() == true, user clicked on a failed method node. 
                   // Try to find if the stack trace node is relevant to the method node
                   if(file != null && frameInfo.isEmpty()) {
                       methodNodeParentOfStackTraceNode = FileUtil.isParentOf(testfo.getParent(), file);
                   }
               }
           }
       }
       UIJavaUtils.openFile(file, lineNumStorage[0]);
   }
 
Example 20
Source File: AbstractProjectSearchScope.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/**
 * @return True if {@code dir} is under directory {@code base}, or is
 * identical. False otherwise.
 */
private static boolean isUnderBase(FileObject base, FileObject dir) {
    return dir == base || FileUtil.isParentOf(base, dir);
}