/** * Test whether one project is dependent on the other. * @param p1 dependent project * @param p2 main project * @return <code>true</code> if project <code>p1</code> depends on project <code>p2</code> */ private static boolean isDependent(Project p1, Project p2) { Set<URL> p1Roots = getProjectRoots(p1); Set<URL> p2Roots = getProjectRoots(p2); for (URL root : p2Roots) { Set<URL> dependentRoots = SourceUtils.getDependentRoots(root); for (URL sr : p1Roots) { if (dependentRoots.contains(sr)) { return true; } } } return false; }
/** * Test whether one project is dependent on the other. * @param p1 dependent project * @param p2 main project * @return <code>true</code> if project <code>p1</code> depends on project <code>p2</code> */ @SuppressWarnings("DMI_COLLECTION_OF_URLS") private static boolean isDependent(Project p1, Project p2) { Set<URL> p1Roots = getProjectRoots(p1); Set<URL> p2Roots = getProjectRoots(p2); for (URL root : p2Roots) { Set<URL> dependentRoots = SourceUtils.getDependentRoots(root); for (URL sr : p1Roots) { if (dependentRoots.contains(sr)) { return true; } } } return false; }
/** * Test whether one project is dependent on the other. * @param p1 dependent project * @param p2 main project * @return <code>true</code> if project <code>p1</code> depends on project <code>p2</code> */ @SuppressWarnings("DMI_COLLECTION_OF_URLS") private static boolean isDependent(Project p1, Project p2) { Set<URL> p1Roots = getProjectRoots(p1); Set<URL> p2Roots = getProjectRoots(p2); for (URL root : p2Roots) { Set<URL> dependentRoots = SourceUtils.getDependentRoots(root); for (URL sr : p1Roots) { if (dependentRoots.contains(sr)) { return true; } } } return false; }
/** * Returns the dependent source path roots for given source root. * It returns all the open project source roots which have either * direct or transitive dependency on the given source root. * @param root to find the dependent roots for * @return {@link Set} of {@link URL}s containing at least the * incoming root, never returns null. * @since 0.10 */ @NonNull @org.netbeans.api.annotations.common.SuppressWarnings(value = {"DMI_COLLECTION_OF_URLS"}, justification="URLs have never host part") public static Set<URL> getDependentRoots (@NonNull final URL root) { return getDependentRoots(root, true); }
public static ClasspathInfo getClasspathInfoFor(FileObject ... files) { assert files.length >0; Set<URL> dependentRoots = new HashSet(); for (FileObject fo: files) { Project p = null; if (fo!=null) p=FileOwnerQuery.getOwner(fo); if (p!=null) { URL sourceRoot = URLMapper.findURL(ClassPath.getClassPath(fo, ClassPath.SOURCE).findOwnerRoot(fo), URLMapper.INTERNAL); dependentRoots.addAll(SourceUtils.getDependentRoots(sourceRoot)); for (SourceGroup root:ProjectUtils.getSources(p).getSourceGroups("java")) { dependentRoots.add(URLMapper.findURL(root.getRootFolder(), URLMapper.INTERNAL)); } } else { for(ClassPath cp: GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) { for (FileObject root:cp.getRoots()) { dependentRoots.add(URLMapper.findURL(root, URLMapper.INTERNAL)); } } } } ClassPath rcp = ClassPathSupport.createClassPath(dependentRoots.toArray(new URL[dependentRoots.size()])); // ClassPath nullPath = ClassPathSupport.createClassPath(new FileObject[0]); ClassPath boot = ClassPath.getClassPath(files[0], ClassPath.BOOT); ClassPath compile = ClassPath.getClassPath(files[0], ClassPath.COMPILE); ClasspathInfo cpInfo = ClasspathInfo.create(boot, compile, rcp); return cpInfo; }