/** * Translated classpath to String (ENTRY PATH_SEPARATOR FLAGS) (PATH_SEPARATOR ENTRY PATH_SEPARATOR FLAGS)* * @param cp the classpath to translate * @return the translated classpath */ @NonNull private static String pathToFlaggedString( @NullAllowed ClassPath cp, final boolean checkArchiveFile) { final StringBuilder b = new StringBuilder(); if (cp == null) { cp = ClassPath.EMPTY; } for (final ClassPath.Entry cpe : cp.entries()) { //Entry.getRoot() returns root which is valid for deleted jar //in ClassPath.PROP_ROOTS event final boolean exists = Optional.ofNullable(cpe.getRoot()) .map((fo) -> (checkArchiveFile && FileUtil.isArchiveArtifact(fo)) ? FileUtil.getArchiveFile(fo) : fo) .map((fo) -> checkArchiveFile ? fo.isValid() : true) .orElse(Boolean.FALSE); append(b,cpe.getURL()) .append(File.pathSeparatorChar) .append(exists ? PATH_FLAG_EXISTS : 0); } return b.toString(); }
final ClassPath pp = validatePaths(); final Set<File> currentExitingFiles = pp.entries().stream() .map((e) -> e.getRoot()) .filter((fo) -> fo != null && fo.isValid()) .map((fo) -> FileUtil.isArchiveArtifact(fo) ? FileUtil.getArchiveFile(fo) : fo)
@NonNull static Set<? extends URL> getAptBuildGeneratedFolders(@NonNull final List<ClassPath.Entry> entries) { final Set<URL> roots = new HashSet<>(); for (ClassPath.Entry entry : entries) { roots.add(entry.getURL()); } for (ClassPath.Entry entry : entries) { final FileObject fo = entry.getRoot(); if (fo != null) { URL aptRoot; final APTUtils aptUtils = APTUtils.getIfExist(fo); if (aptUtils != null) { aptRoot = aptUtils.sourceOutputDirectory(); } else { aptRoot = AnnotationProcessingQuery.getAnnotationProcessingOptions(fo).sourceOutputDirectory(); } if (roots.contains(aptRoot)) { return Collections.singleton(aptRoot); } } } return Collections.<URL>emptySet(); }
URL url=entry.getURL(); if (!newPath.remove(url)) removed.add(entry.getRoot());
FileObject[] roots; if (entry.isValid()) { roots = new FileObject[]{entry.getRoot()}; } else { SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(entry.getURL());
@Override public Iterable<JavaFileObject> list(final Location l, final String packageName, final Set<JavaFileObject.Kind> kinds, final boolean recursive) { //Todo: Caching of results, needs listening on FS List<JavaFileObject> result = new ArrayList<JavaFileObject> (); String _name = packageName.replace('.','/'); //NOI18N if (_name.length() != 0) { _name+='/'; //NOI18N } for (ClassPath.Entry entry : this.sourceRoots.entries()) { if (ignoreExcludes || entry.includes(_name)) { FileObject root = entry.getRoot(); if (root != null) { FileObject tmpFile = root.getFileObject(_name); if (tmpFile != null && tmpFile.isFolder()) { Enumeration<? extends FileObject> files = tmpFile.getChildren (recursive); while (files.hasMoreElements()) { FileObject file = files.nextElement(); if (ignoreExcludes || entry.includes(file)) { final JavaFileObject.Kind kind = FileObjects.getKind(file.getExt()); if (kinds.contains(kind)) { result.add (FileObjects.sourceFileObject(file, root)); } } } } } } } return result; }
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 ); } } } } } } }
private File getClassFolderForSourceImpl (String baseName) throws IOException { List<ClassPath.Entry> entries = this.scp.entries(); int eSize = entries.size(); if (eSize == 1) { return getClassFolder(entries.get(0).getURL()); } if (eSize == 0) { return null; } final String[] parentName = splitParentName(baseName); for (ClassPath.Entry entry : entries) { FileObject root = entry.getRoot(); if (root != null) { FileObject parentFile = root.getFileObject(parentName[0]); if (parentFile != null) { if (parentFile.getFileObject(parentName[1], FileObjects.JAVA) != null) { return getClassFolder(entry.getURL()); } } } } return null; }
private File getClassFolderForApt(final String baseName) { String[] parentName = splitParentName(baseName); for (ClassPath.Entry entry : this.apt.entries()) { FileObject root = entry.getRoot(); if (root != null) { FileObject parentFile = root.getFileObject(parentName[0]); if (parentFile != null) { if (parentFile.getFileObject(parentName[1], FileObjects.JAVA) != null) { final URL classFolder = AptCacheForSourceQuery.getClassFolder(entry.getURL()); if (classFolder != null) { try { return BaseUtilities.toFile(classFolder.toURI()); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } } } } } } return null; }
@Override public JavaFileObject getJavaFileForInput (Location l, final String className, JavaFileObject.Kind kind) { String[] namePair = FileObjects.getParentRelativePathAndName (className); String ext = kind == JavaFileObject.Kind.CLASS ? FileObjects.SIG : kind.extension.substring(1); //tzezula: Clearly wrong in compile on save, but "class" is also wrong for (ClassPath.Entry entry : this.sourceRoots.entries()) { FileObject root = entry.getRoot(); if (root != null) { FileObject parent = root.getFileObject(namePair[0]); if (parent != null) { FileObject[] children = parent.getChildren(); for (FileObject child : children) { if (namePair[1].equals(child.getName()) && ext.equalsIgnoreCase(child.getExt()) && (ignoreExcludes || entry.includes(child))) { return FileObjects.sourceFileObject(child, root); } } } } } return null; }
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; }
@NonNull private static String pathToString(@NullAllowed ClassPath cp) { final StringBuilder b = new StringBuilder(); if (cp == null) { cp = ClassPath.EMPTY; } for (final ClassPath.Entry cpe : cp.entries()) { final FileObject fo = cpe.getRoot(); if (fo != null) { final URL u = fo.toURL(); append(b, u); } else if (hasSourceCache(cpe.getURL())) { final URL u = cpe.getURL(); append(b,u); } } return b.toString(); }
private FileObject[] findFile (final String relativePath) { for (ClassPath.Entry entry : this.sourceRoots.entries()) { if (ignoreExcludes || entry.includes(relativePath)) { FileObject root = entry.getRoot(); if (root != null) { FileObject file = root.getFileObject(relativePath); if (file != null) { return new FileObject[] {file, root}; } } } } return null; }
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; }