You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jl...@apache.org on 2017/12/06 22:31:45 UTC
[incubator-netbeans] branch jdk-javac updated: Fixing some problems
with indexing - ensuring file managers know where to put output files;
correcting detection of erroneous files.
This is an automated email from the ASF dual-hosted git repository.
jlahoda pushed a commit to branch jdk-javac
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/jdk-javac by this push:
new 1c8c1e5 Fixing some problems with indexing - ensuring file managers know where to put output files; correcting detection of erroneous files.
1c8c1e5 is described below
commit 1c8c1e52e5abb48eb05aaff392ea630d9e04cb83
Author: Jan Lahoda <jl...@netbeans.org>
AuthorDate: Wed Dec 6 23:31:10 2017 +0100
Fixing some problems with indexing - ensuring file managers know where to put output files; correcting detection of erroneous files.
---
.../source/indexing/DiagnosticListenerImpl.java | 4 ++
.../java/source/indexing/VanillaCompileWorker.java | 20 +++++----
.../java/source/parsing/OutputFileManager.java | 47 +++++++++++++++++-----
.../java/source/parsing/ProxyFileManager.java | 3 ++
4 files changed, 56 insertions(+), 18 deletions(-)
diff --git a/java.source.base/src/org/netbeans/modules/java/source/indexing/DiagnosticListenerImpl.java b/java.source.base/src/org/netbeans/modules/java/source/indexing/DiagnosticListenerImpl.java
index 75c564c..817f56b 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/indexing/DiagnosticListenerImpl.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/indexing/DiagnosticListenerImpl.java
@@ -62,6 +62,10 @@ public class DiagnosticListenerImpl implements DiagnosticListener<JavaFileObject
return result;
}
+ public List<Diagnostic<? extends JavaFileObject>> peekDiagnostics(JavaFileObject file) {
+ return diagnostics.getOrDefault(file.toUri(), Collections.emptyList());
+ }
+
public void cleanDiagnostics() {
diagnostics.clear();
}
diff --git a/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java b/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
index b329e4f..1ec005d 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
@@ -48,11 +48,12 @@ import java.util.Map.Entry;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.stream.Collectors;
-import javax.annotation.processing.Processor;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.TypeElement;
+import javax.tools.Diagnostic.Kind;
+import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.queries.CompilerOptionsQuery;
@@ -151,14 +152,14 @@ final class VanillaCompileWorker extends CompileWorker {
Log.instance(jt.getContext()).nerrors = 0;
} catch (CancelAbort ca) {
if (context.isCancelled() && JavaIndex.LOG.isLoggable(Level.FINEST)) {
- JavaIndex.LOG.log(Level.FINEST, "SuperOnePassCompileWorker was canceled in root: " + FileUtil.getFileDisplayName(context.getRoot()), ca); //NOI18N
+ JavaIndex.LOG.log(Level.FINEST, "VanillaCompileWorker was canceled in root: " + FileUtil.getFileDisplayName(context.getRoot()), ca); //NOI18N
}
} catch (Throwable t) {
if (JavaIndex.LOG.isLoggable(Level.WARNING)) {
final ClassPath bootPath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.BOOT);
final ClassPath classPath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE);
final ClassPath sourcePath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE);
- final String message = String.format("SuperOnePassCompileWorker caused an exception\nFile: %s\nRoot: %s\nBootpath: %s\nClasspath: %s\nSourcepath: %s", //NOI18N
+ final String message = String.format("VanillaCompileWorker caused an exception\nFile: %s\nRoot: %s\nBootpath: %s\nClasspath: %s\nSourcepath: %s", //NOI18N
fileObjects.values().iterator().next().indexable.getURL().toString(),
FileUtil.getFileDisplayName(context.getRoot()),
bootPath == null ? null : bootPath.toString(),
@@ -189,6 +190,8 @@ final class VanillaCompileWorker extends CompileWorker {
Log log = Log.instance(jt.getContext());
JavaCompiler compiler = JavaCompiler.instance(jt.getContext());
Set<JavaFileObject> haveErrors = new HashSet<>();
+ JavaFileManager fm = jt.getContext().get(JavaFileManager.class);
+ fm.handleOption(OutputFileManager.OPTION_SET_CURRENT_ROOT, Collections.singleton(context.getRootURI().toString()).iterator());
try {
final Iterable<? extends Element> types = jt.enter(trees);
if (context.isCancelled()) {
@@ -262,8 +265,9 @@ final class VanillaCompileWorker extends CompileWorker {
modifiedTypes.addAll(aTypes);
}
ExecutableFilesIndex.DEFAULT.setMainClass(context.getRoot().toURL(), active.indexable.getURL(), main[0]);
- if (!dc.getDiagnostics(active.jfo).isEmpty())
+ if (dc.peekDiagnostics(active.jfo).stream().anyMatch(d -> d.getKind() == Kind.ERROR)) {
haveErrors.add(active.jfo);
+ }
JavaCustomIndexer.setErrors(context, active, dc);
}
if (context.isCancelled()) {
@@ -319,7 +323,7 @@ final class VanillaCompileWorker extends CompileWorker {
final ClassPath bootPath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.BOOT);
final ClassPath classPath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE);
final ClassPath sourcePath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE);
- final String message = String.format("SuperOnePassCompileWorker caused an exception\nRoot: %s\nBootpath: %s\nClasspath: %s\nSourcepath: %s", //NOI18N
+ final String message = String.format("VanillaCompileWorker caused an exception\nRoot: %s\nBootpath: %s\nClasspath: %s\nSourcepath: %s", //NOI18N
FileUtil.getFileDisplayName(context.getRoot()),
bootPath == null ? null : bootPath.toString(),
classPath == null ? null : classPath.toString(),
@@ -331,7 +335,7 @@ final class VanillaCompileWorker extends CompileWorker {
if (isLowMemory(null)) {
return ParsingOutput.lowMemory(moduleName.name, file2FQNs, addedTypes, addedModules, createdFiles, finished, modifiedTypes, aptGenerated);
} else if (JavaIndex.LOG.isLoggable(Level.FINEST)) {
- JavaIndex.LOG.log(Level.FINEST, "SuperOnePassCompileWorker was canceled in root: " + FileUtil.getFileDisplayName(context.getRoot()), ca); //NOI18N
+ JavaIndex.LOG.log(Level.FINEST, "VanillaCompileWorker was canceled in root: " + FileUtil.getFileDisplayName(context.getRoot()), ca); //NOI18N
}
} catch (Throwable t) {
if (t instanceof ThreadDeath) {
@@ -342,7 +346,7 @@ final class VanillaCompileWorker extends CompileWorker {
final ClassPath bootPath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.BOOT);
final ClassPath classPath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE);
final ClassPath sourcePath = javaContext.getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE);
- final String message = String.format("SuperOnePassCompileWorker caused an exception\nRoot: %s\nBootpath: %s\nClasspath: %s\nSourcepath: %s", //NOI18N
+ final String message = String.format("VanillaCompileWorker caused an exception\nRoot: %s\nBootpath: %s\nClasspath: %s\nSourcepath: %s", //NOI18N
FileUtil.getFileDisplayName(context.getRoot()),
bootPath == null ? null : bootPath.toString(),
classPath == null ? null : classPath.toString(),
@@ -351,6 +355,8 @@ final class VanillaCompileWorker extends CompileWorker {
JavaIndex.LOG.log(level, message, t); //NOI18N
}
}
+ } finally {
+ fm.handleOption(OutputFileManager.OPTION_SET_CURRENT_ROOT, Collections.<String>emptySet().iterator());
}
return ParsingOutput.failure(moduleName.name, file2FQNs, addedTypes, addedModules, createdFiles, finished, modifiedTypes, aptGenerated);
}
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/OutputFileManager.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/OutputFileManager.java
index cad92d6..d0a7db4 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/parsing/OutputFileManager.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/OutputFileManager.java
@@ -21,13 +21,14 @@ package org.netbeans.modules.java.source.parsing;
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -35,7 +36,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
-import javax.tools.JavaFileManager;
import javax.tools.JavaFileManager.Location;
import javax.tools.JavaFileObject;
import javax.tools.JavaFileObject.Kind;
@@ -57,6 +57,8 @@ import org.openide.util.BaseUtilities;
*/
public class OutputFileManager extends CachingFileManager {
+ public static final String OPTION_SET_CURRENT_ROOT = "set-current-root";
+
private static final Logger LOG = Logger.getLogger(OutputFileManager.class.getName());
/**
* Exception used to signal that the sourcepath is broken (project is deleted)
@@ -71,6 +73,7 @@ public class OutputFileManager extends CachingFileManager {
private final ModuleSourceFileManager moduleSourceFileManager;
private Pair<URI,File> cachedClassFolder;
private Iterable<Set<Location>> cachedModuleLocations;
+ private URL root;
/** Creates a new instance of CachingFileManager */
public OutputFileManager(
@@ -154,16 +157,21 @@ public class OutputFileManager extends CachingFileManager {
throws IOException, UnsupportedOperationException, IllegalArgumentException {
assert pkgName != null;
assert relativeName != null;
- URL siblingURL = siblings.hasSibling() ? siblings.getSibling() : sibling == null ? null : sibling.toUri().toURL();
- if (siblingURL == null) {
- throw new IllegalArgumentException ("sibling == null");
- }
- File activeRoot = getClassFolderForSourceImpl (siblingURL);
- if (activeRoot == null) {
- activeRoot = getClassFolderForApt(siblingURL);
+ File activeRoot;
+ if (root != null) {
+ activeRoot = getClassFolder(root);
+ } else {
+ URL siblingURL = siblings.hasSibling() ? siblings.getSibling() : sibling == null ? null : sibling.toUri().toURL();
+ if (siblingURL == null) {
+ throw new IllegalArgumentException ("sibling == null");
+ }
+ activeRoot = getClassFolderForSourceImpl (siblingURL);
if (activeRoot == null) {
- //Deleted project
- throw new InvalidSourcePath ();
+ activeRoot = getClassFolderForApt(siblingURL);
+ if (activeRoot == null) {
+ //Deleted project
+ throw new InvalidSourcePath ();
+ }
}
}
assertValidRoot(activeRoot, l);
@@ -172,6 +180,23 @@ public class OutputFileManager extends CachingFileManager {
return tx.createFileObject(l, file, activeRoot,null,null);
}
+ @Override
+ public boolean handleOption(String head, Iterator<String> tail) {
+ if (OPTION_SET_CURRENT_ROOT.equals(head)) {
+ if (tail.hasNext()) {
+ try {
+ root = new URL(tail.next());
+ } catch (MalformedURLException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ } else {
+ root = null;
+ }
+ return true;
+ } else {
+ return super.handleOption(head, tail);
+ }
+ }
@Override
public javax.tools.FileObject getFileForInput(Location l, String pkgName, String relativeName) {
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/ProxyFileManager.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/ProxyFileManager.java
index 2fb8348..e2604a7 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/parsing/ProxyFileManager.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/ProxyFileManager.java
@@ -750,6 +750,9 @@ public final class ProxyFileManager implements JavaFileManager {
createPatchFileManager();
createModuleSrcFileManager();
}
+ if (OutputFileManager.OPTION_SET_CURRENT_ROOT.equals(hint)) {
+ createOutputFileManager();
+ }
final List<JavaFileManager> res = new ArrayList<>(emitted.length);
for (JavaFileManager jfm : emitted) {
if (jfm != null) {
--
To stop receiving notification emails like this one, please contact
['"commits@netbeans.apache.org" <co...@netbeans.apache.org>'].