JaroslavTulach closed pull request #546: When copying build output classfiles
as a last resort when indexing w…
URL: https://github.com/apache/incubator-netbeans/pull/546
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
index d7203ad0d0..00ddbd5051 100644
---
a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
+++
b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
@@ -87,6 +87,8 @@
import org.netbeans.modules.java.source.parsing.FileObjects;
import org.netbeans.modules.java.source.parsing.JavacParser;
import org.netbeans.modules.java.source.parsing.OutputFileManager;
+import org.netbeans.modules.java.source.usages.BinaryAnalyser;
+import org.netbeans.modules.java.source.usages.ClassIndexImpl;
import org.netbeans.modules.java.source.usages.ExecutableFilesIndex;
import org.netbeans.modules.parsing.spi.indexing.Context;
import org.netbeans.modules.parsing.spi.indexing.Indexable;
@@ -395,7 +397,12 @@ public void run() throws IOException {
if (binaryFO == null)
continue;
FileManagerTransaction fmtx =
TransactionContext.get().get(FileManagerTransaction.class);
- copyRecursively(binaryFO, cache, cache, filter, fmtx);
+ List<File> copied = new ArrayList<>();
+ copyRecursively(binaryFO, cache, cache, filter, fmtx,
copied);
+ final ClassIndexImpl cii =
javaContext.getClassIndexImpl();
+ if (cii != null) {
+ cii.getBinaryAnalyser().analyse(context, cache,
copied);
+ }
}
});
done.get();
@@ -406,7 +413,7 @@ public void run() throws IOException {
return ParsingOutput.success(moduleName.name, file2FQNs, addedTypes,
addedModules, createdFiles, finished, modifiedTypes, aptGenerated);
}
- private static void copyRecursively(FileObject source, File targetRoot,
File target, Set<String> filter, FileManagerTransaction fmtx) throws
IOException {
+ private static void copyRecursively(FileObject source, File targetRoot,
File target, Set<String> filter, FileManagerTransaction fmtx, List<File>
copied) throws IOException {
if (source.isFolder()) {
if (target.exists() && !target.isDirectory()) {
throw new IOException("Cannot create folder: " +
target.getAbsolutePath() + ", already exists as a file.");
@@ -418,7 +425,7 @@ private static void copyRecursively(FileObject source, File
targetRoot, File tar
String name = f.getNameExt();
if (name.endsWith(".class"))
name = name.substring(0, name.length() -
FileObjects.CLASS.length()) + FileObjects.SIG;
- copyRecursively(f, targetRoot, new File(target, name), filter,
fmtx);
+ copyRecursively(f, targetRoot, new File(target, name), filter,
fmtx, copied);
}
} else {
if (target.isDirectory()) {
@@ -438,8 +445,10 @@ private static void copyRecursively(FileObject source,
File targetRoot, File tar
copy = true;
}
- if (copy)
+ if (copy) {
copyFile(source,
fmtx.createFileObject(StandardLocation.CLASS_OUTPUT, target, targetRoot, null,
null));
+ copied.add(target);
+ }
}
}
diff --git
a/java/java.source.base/src/org/netbeans/modules/java/source/usages/BinaryAnalyser.java
b/java/java.source.base/src/org/netbeans/modules/java/source/usages/BinaryAnalyser.java
index b5390636fb..8ad9d9fa95 100644
---
a/java/java.source.base/src/org/netbeans/modules/java/source/usages/BinaryAnalyser.java
+++
b/java/java.source.base/src/org/netbeans/modules/java/source/usages/BinaryAnalyser.java
@@ -345,8 +345,17 @@ private static IdentLevel resolveIdentLevel() {
*/
@NonNull
public final Changes analyse (final @NonNull Context ctx) throws
IOException, IllegalArgumentException {
+ return analyse(ctx, createProcessor(ctx));
+ }
+
+ @NonNull
+ public final Changes analyse (final @NonNull Context ctx, File root,
Iterable<File> files) throws IOException, IllegalArgumentException {
+ return analyse(ctx, new EnumerateFilesProcessor(ctx, root, files));
+ }
+
+ @NonNull
+ private Changes analyse (final @NonNull Context ctx, final @NonNull
RootProcessor p) throws IOException, IllegalArgumentException {
Parameters.notNull("ctx", ctx); //NOI18N
- final RootProcessor p = createProcessor(ctx);
if (p.execute()) {
if (!p.hasChanges() && timeStampsEmpty()) {
assert refs.isEmpty();
@@ -1391,6 +1400,72 @@ protected boolean executeImpl() throws IOException {
}
}
+ private final class EnumerateFilesProcessor extends RootProcessor {
+ private final File todoRoot;
+ private final Iterable<File> todo;
+
+ public EnumerateFilesProcessor(
+ final @NonNull Context ctx,
+ final @NonNull File todoRoot,
+ final @NonNull Iterable<File> todo) throws IOException {
+ super(ctx);
+ this.todoRoot = todoRoot;
+ this.todo = todo;
+ }
+
+ @Override
+ @NonNull
+ protected boolean executeImpl() throws IOException {
+ for (File file : todo) {
+ long fileMTime = file.lastModified();
+ String relativePath =
FileObjects.convertFolder2Package(FileObjects.getRelativePath(todoRoot, file),
File.separatorChar);
+ report(
+
ElementHandleAccessor.getInstance().create(ElementKind.OTHER, relativePath),
+ fileMTime);
+ if (!isUpToDate (relativePath, fileMTime)) {
+ markChanged();
+ toDelete.add(Pair.<String,String>of (relativePath,null));
+ try {
+ InputStream in = new BufferedInputStream(new
FileInputStream(file));
+ try {
+ analyse(in);
+ } catch (InvalidClassFormatException |
RuntimeException icf) {
+ LOGGER.log(
+ Level.WARNING,
+ "Invalid class file format: {0}", //NOI18N
+ file.getAbsolutePath());
+ LOGGER.log(
+ Level.INFO,
+ "Class File Exception Details",
//NOI18N
+ icf);
+ } finally {
+ in.close();
+ }
+ } catch (IOException ex) {
+ //unreadable file?
+ LOGGER.log(Level.WARNING, "Cannot read file: {0}",
file.getAbsolutePath()); //NOI18N
+ LOGGER.log(Level.FINE, null, ex);
+ }
+ if (lmListener.isLowMemory()) {
+ flush();
+ }
+ }
+ if (isCancelled()) {
+ return false;
+ }
+ }
+ for (String deleted : getTimeStamps().second()) {
+ if (FileObjects.MODULE_INFO.equals(deleted)) {
+ delete(null,String.format("%s.%s",
FileObjects.MODULE_INFO, FileObjects.CLASS)); //NOI18N
+ } else {
+ delete(deleted, null); //TODO
+ }
+ markChanged();
+ }
+ return true;
+ }
+ }
+
private final class PathProcessor extends RootProcessor {
private final URL rootURL;
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists