private static void addSourceRoots(ClassPath ecp, List<FileObject> allSourceRoots, Set<FileObject> addedBinaryRoots, Set<FileObject> preferredRoots) { FileObject[] binaryRoots = ecp.getRoots(); for (FileObject fo : binaryRoots) { if (addedBinaryRoots.contains(fo)) { continue; } addedBinaryRoots.add(fo); FileObject[] roots = SourceForBinaryQuery.findSourceRoots(fo.toURL()).getRoots(); for (FileObject fr : roots) { if (!preferredRoots.contains(fr)) { allSourceRoots.add(fr); preferredRoots.add(fr); } } } }
private static void addSourceRoots(ClassPath ecp, List<FileObject> allSourceRoots, Set<FileObject> addedBinaryRoots, Set<FileObject> preferredRoots) { FileObject[] binaryRoots = ecp.getRoots(); for (FileObject fo : binaryRoots) { if (addedBinaryRoots.contains(fo)) { continue; } addedBinaryRoots.add(fo); FileObject[] roots = SourceForBinaryQuery.findSourceRoots(fo.toURL()).getRoots(); for (FileObject fr : roots) { if (!preferredRoots.contains(fr)) { allSourceRoots.add(fr); preferredRoots.add(fr); } } } }
continue; FileObject[] someRoots = SourceForBinaryQuery.findSourceRoots(binroot).getRoots(); result.addAll(Arrays.asList(someRoots));
FileObject[] roots = SourceForBinaryQuery.findSourceRoots(fo.getURL()).getRoots(); for (FileObject fr : roots) { if (!preferredRoots.contains(fr)) {
for (ClassPath cp : exec) { for (ClassPath.Entry entry : (java.util.List<ClassPath.Entry>)cp.entries()) { FileObject[] fos = SourceForBinaryQuery.findSourceRoots(entry.getURL()).getRoots(); for (int i=0; i< fos.length; i++) { try {
for(FileObject fo: rootsCP){ try{ FileObject[] aaa = SourceForBinaryQuery.findSourceRoots(fo.getURL()).getRoots(); roots.addAll(Arrays.asList(aaa)); }catch(Exception e){}
} else { SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(root.getURL()); for (FileObject srcRoot : res.getRoots()) { FileObject src = srcRoot.getFileObject(rel); if (src != null) {
for (Iterator<ClassPath.Entry> eit = cp.entries().iterator(); eit.hasNext();) { ClassPath.Entry entry = eit.next (); FileObject[] fos = SourceForBinaryQuery.findSourceRoots(entry.getURL()).getRoots(); for (int i=0; i< fos.length; i++) { try {
URL url = Utils.fileToURL(fs[i]); try { FileObject[] srcfos = SourceForBinaryQuery.findSourceRoots(url).getRoots(); for (int j = 0; j < srcfos.length; j++) { if (FileUtil.isArchiveFile(srcfos[j])) {
URL url = URLMapper.findURL(root, URLMapper.INTERNAL); SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(url); FileObject[] rootz = res.getRoots(); for (int i = 0; i < rootz.length; i++) { String path = packageName + file + ".java"; //NOI18N
result = this.delegate.getRoots(); if (result.length == 0) {
URL url = Utils.fileToURL(fs[i]); try { FileObject[] srcfos = SourceForBinaryQuery.findSourceRoots(url).getRoots(); for (int j = 0; j < srcfos.length; j++) { if (FileUtil.isArchiveFile(srcfos[j])) {
private static void collectConfigurationFilesFromClassPath(ClassPath cp, List<FileObject> configs, List<FileObject> configRoots) { for (ClassPath.Entry entry : cp.entries()) { FileObject roots[]; if (entry.isValid()) { roots = new FileObject[]{entry.getRoot()}; } else { // if classpath root does not exist then perhaps it is // a project which has not been built - use SourceForBinaryQuery // to use project sources instead: SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(entry.getURL()); roots = res.getRoots(); } for (FileObject root : roots) { configRoots.add(root); FileObject metaInf = root.getFileObject(META_INF); if (metaInf != null) { FileObject[] children = metaInf.getChildren(); for (FileObject fileObject : children) { String name = fileObject.getNameExt(); if (name.equals(FACES_CONFIG) || name.endsWith(FACES_CONFIG_SUFFIX)) { if(!configs.contains(fileObject)) { //do not duplicate configs.add( fileObject ); } } } } } } }
} else { SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(entry.getURL()); roots = res.getRoots();
ClassPath.Entry e = (ClassPath.Entry) it.next(); SourceForBinaryQuery.Result r = SourceForBinaryQuery.findSourceRoots(e.getURL()); FileObject[] sourceRoots = r.getRoots(); for (int i=0; i < sourceRoots.length; i++) {
private String classToSourceURL (FileObject fo, Log logger) { try { ClassPath cp = ClassPath.getClassPath (fo, ClassPath.EXECUTE); FileObject root = cp.findOwnerRoot (fo); String resourceName = cp.getResourceName (fo, '/', false); if (resourceName == null) { logger.info("Can not find classpath resource for "+fo+", skipping..."); return null; } int i = resourceName.indexOf ('$'); if (i > 0) resourceName = resourceName.substring (0, i); FileObject[] sRoots = SourceForBinaryQuery.findSourceRoots (root.getURL ()).getRoots (); ClassPath sourcePath = ClassPathSupport.createClassPath (sRoots); FileObject rfo = sourcePath.findResource (resourceName + ".java"); if (rfo == null) return null; return rfo.getURL ().toExternalForm (); } catch (FileStateInvalidException ex) { ex.printStackTrace (); return null; } }
@Override @NonNull public FileObject[] getSourceRoots () { if (getType() == Type.SOURCE) { final FileObject rootFo = getRoot(); if (rootFo == null) { return new FileObject[0]; } FileObject[] aptRoots = cachedAptRoots; if (!isValid(aptRoots)) { final URL aptGeneratedURL = getAPTSourceOutputDirectory(rootFo); final FileObject aptGeneratedRoot = aptGeneratedURL == null ? null: URLMapper.findFileObject(aptGeneratedURL); aptRoots = cachedAptRoots = aptGeneratedRoot == null ? new FileObject[0] : new FileObject[] {aptGeneratedRoot}; //Todo: ???? Add cache/s*/java/*/sources as well? } final FileObject[] res = new FileObject[1+aptRoots.length]; res[0] = rootFo; System.arraycopy(aptRoots, 0, res, 1, aptRoots.length); return res; } else { return SourceForBinaryQuery.findSourceRoots(this.root).getRoots(); } }
private static FileObject getFileFromClasspath(ClassPath cp, String classRelativePath) { for (ClassPath.Entry entry : cp.entries()) { FileObject roots[]; if (entry.isValid()) { roots = new FileObject[]{entry.getRoot()}; } else { SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(entry.getURL()); roots = res.getRoots(); } for (FileObject root : roots) { FileObject metaInf = root.getFileObject(classRelativePath); if (metaInf != null) { return metaInf; } } } return null; }
private static boolean isTest(final @NonNull FileObject root, final @NonNull Project project) { assert root != null; assert project != null; final ClassPath cp = ClassPath.getClassPath(root, ClassPath.COMPILE); for (ClassPath.Entry entry : cp.entries()) { final FileObject[] srcRoots = SourceForBinaryQuery.findSourceRoots(entry.getURL()).getRoots(); for (FileObject srcRoot : srcRoots) { if (project.equals(FileOwnerQuery.getOwner(srcRoot))) { return true; } } } return false; }
private static void sources(File targetFolder, FileObject[][] sources) throws MalformedURLException { if (sources[0] == null) { URL targetFolderURL = FileUtil.urlForArchiveOrDir(targetFolder); sources[0] = SourceForBinaryQuery.findSourceRoots(targetFolderURL).getRoots(); } }