JaroslavTulach commented on a change in pull request #1123: Use .class files instead of compiling the sources URL: https://github.com/apache/incubator-netbeans/pull/1123#discussion_r257722427
########## File path: java/java.source.base/src/org/netbeans/modules/java/source/indexing/JavaCustomIndexer.java ########## @@ -147,6 +151,76 @@ protected void index(final Iterable<? extends Indexable> files, final Context co JavaIndex.LOG.fine("Ignoring request with no root"); //NOI18N return; } + BinaryForSourceQuery.Result2 binRes = BinaryForSourceQuery.findBinaryRoots2(root.toURL()); + if (binRes.preferBinaries()) { + final URL[] binaryRoots = binRes.getRoots(); + final FileObject[] binaryRootsFo = new FileObject[binaryRoots.length]; + Long newestFile = null; + int at = 0; + for (URL u : binaryRoots) { + FileObject ufo = URLMapper.findFileObject(u); + if (ufo == null) { + newestFile = null; + break; + } + binaryRootsFo[at++] = ufo; + Enumeration<? extends FileObject> en = ufo.getChildren(true); + while (en.hasMoreElements()) { + FileObject ch = en.nextElement(); + long modified = ch.lastModified().getTime(); + if (newestFile == null || newestFile < modified) { + newestFile = modified; + } + } + } + + boolean binariesAreNewer = true; + for (Indexable index : files) { + if (!binariesAreNewer) { + break; + } + FileObject fo = context.getRoot().getFileObject(index.getRelativePath()); + if (newestFile == null || fo == null || fo.lastModified().getTime() > newestFile) { + binariesAreNewer = false; + break; + } + } + + if (binariesAreNewer) { + JavaIndex.LOG.log(Level.FINE, "Using binaries for {0}", FileUtil.getFileDisplayName(root)); // NOI18N + File copyTo = JavaIndex.getClassFolder(context); + at = 0; + for (URL singleBinaryRoot : binaryRoots) { + FileObject singleBinaryRootFo = binaryRootsFo[at++]; + JavaBinaryIndexer.doIndex(context, singleBinaryRoot); + JavaIndex.LOG.log(Level.FINE, " copying from {0} to {1}", new Object[] { FileUtil.getFileDisplayName(singleBinaryRootFo), copyTo }); // NOI18N + Enumeration<? extends FileObject> en = singleBinaryRootFo.getChildren(true); + while (en.hasMoreElements()) { + FileObject ch = en.nextElement(); + if (!ch.isData()) { + continue; + } + String path = FileUtil.getRelativePath(singleBinaryRootFo, ch.getParent()); + if (path == null) { + continue; + } + String name = ch.getNameExt(); + if (ch.hasExt("class")) { + name = ch.getName() + ".sig"; + } + File toDir = new File(copyTo, path.replace('/', File.separatorChar)); + toDir.mkdirs(); + File to = new File(toDir, name); + try (OutputStream os = new FileOutputStream(to); InputStream is = ch.getInputStream()) { + FileUtil.copy(is, os); + } + } + } Review comment: Is c1dc05a8138b correct? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org For additional commands, e-mail: notifications-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists