You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "lahodaj (via GitHub)" <gi...@apache.org> on 2023/08/11 10:33:19 UTC
[GitHub] [netbeans] lahodaj opened a new pull request, #6329: Support for multi-file source launcher.
lahodaj opened a new pull request, #6329:
URL: https://github.com/apache/netbeans/pull/6329
This patch is adding a support for (the future) multi-file source launcher:
https://openjdk.org/jeps/8304400
I was thinking (and tried for a bit) to mask this as a project, but it seemed the incompatibilities between "just a group of files" and "project" are too big. So, the patch enhances the needed queries to handle files in non-project directories (hopefully) reasonably well.
I've created a separate module to host the support for source launcher, to not pollute `java.api.common`.
Note this improves the handling of single-file source launching under debugger, when there's a package clause present (as long as the directory structure matches the package clause).
---
**^Add meaningful description above**
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
- are all your own work, and you have the right to contribute them.
- are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).
Please make sure (eg. `git log`) that all commits have a valid name and email address for you in the Author field.
If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1849034436
This seems to be a minimal hotfix:
```diff
diff --git a/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java b/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java
index 9939a96e8152..3c9d9099224a 100644
--- a/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java
+++ b/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java
@@ -25,6 +25,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.modules.java.file.launcher.api.SourceLauncher;
@@ -43,6 +45,8 @@ import org.openide.util.Exceptions;
*/
public class SharedRootData {
+ private static final Logger LOG = Logger.getLogger(SharedRootData.class.getName());
+
private static final Map<FileObject, SharedRootData> root2Data = new HashMap<>();
public static synchronized void ensureRootRegistered(FileObject root) {
@@ -104,11 +108,14 @@ public class SharedRootData {
}
String joinedCommandLine = SourceLauncher.joinCommandLines(options.values());
try {
- if (!joinedCommandLine.equals(root.getAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS))) {
+ if (
+ !root.getFileSystem().isReadOnly() // Skip read-only FSes (like JarFileSystem)
+ && !joinedCommandLine.equals(root.getAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS))
+ ) {
root.setAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS, joinedCommandLine);
}
} catch (IOException ex) {
- Exceptions.printStackTrace(ex);
+ LOG.log(Level.INFO, "Failed to set " + SingleSourceFileUtil.FILE_VM_OPTIONS + " for " + root.getPath(), ex);
}
}
diff --git a/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java b/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java
index 47a8bad00c02..7f5061d3fac4 100644
--- a/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java
+++ b/java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java
@@ -92,7 +92,7 @@ public class MultiSourceRootProvider implements ClassPathProvider {
if (DISABLE_MULTI_SOURCE_ROOT) return null;
synchronized (this) {
//XXX: what happens if there's a Java file in user's home???
- if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ if (file.isValid() && file.isData() && "text/x-java".equals(file.getMIMEType())) {
return file2SourceCP.computeIfAbsent(file, f -> {
try {
String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
```
I think the general problem is `Exceptions.printStackTrace(ex);`. That function does more than just logging the problem it also seems to block further processing. Switching to a regular logger seems sensible and less intrusive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1298270797
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
Review Comment:
is it OK, if more CPListeners is created for a single file (the coIA is not synchronized) ?
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
+ Project p = FileOwnerQuery.getOwner(f);
+ if (p != null && (p.getLookup().lookup(AccessibilityQueryImplementation2.class) != null ||
+ p.getLookup().lookup(AccessibilityQueryImplementation.class) != null)) {
+ //if there's a project-based AccessibilityQuery for this file, don't provide the generic results
+ return null;
+ }
+ ClassPath sourcePath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
+ if (sourcePath == null) {
+ return null;
+ }
+ ClassPathListener cpl = sourcePath2Listener.computeIfAbsent(sourcePath, sp -> new ClassPathListener(sourcePath));
+ return new ResultImpl(cpl, sourcePath, folder);
+ });
+ }
+
+ private static final class ResultImpl implements Result, ChangeListener {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final ClassPathListener listener;
+ private final Reference<ClassPath> sourcePath;
+ private final Reference<FileObject> folder;
+
+ public ResultImpl(ClassPathListener listener, ClassPath sourcePath, FileObject folder) {
+ this.listener = listener;
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.folder = new WeakReference<>(folder);
+ listener.addChangeListener(this);
+ }
+
+ @Override
+ public AccessibilityQuery.Accessibility getAccessibility() {
+ ClassPath sourcePath = this.sourcePath.get();
+ FileObject folder = this.folder.get();
+ Set<String> exported = listener.getExportedPackages();
+
+ if (sourcePath == null || folder == null || exported == null) {
+ return AccessibilityQuery.Accessibility.UNKNOWN;
+ }
+ String packageName = sourcePath.getResourceName(folder).replace('/', '.');
+ return exported.contains(packageName) ? AccessibilityQuery.Accessibility.EXPORTED
+ : AccessibilityQuery.Accessibility.PRIVATE;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.removeChangeListener(listener);
+ }
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ cs.fireChange();
+ }
+
+ }
+
+ private static final class ClassPathListener implements PropertyChangeListener {
+
+ private static final RequestProcessor WORKER = new RequestProcessor(ClassPathListener.class.getName(), 1, false, false);
+ private static final int DELAY = 100;
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final AtomicReference<Set<String>> exportedPackages = new AtomicReference<>(null);
+ private final Reference<ClassPath> sourcePath;
+ private final Task parseTask;
+ private final Task rootsTask;
+ private final FileChangeAdapter folderListener = new FileChangeAdapter() {
+ @Override
+ public void fileDataCreated(FileEvent fe) {
+ if (fe.getFile().getNameExt().equalsIgnoreCase("module-info.java")) {
+ rootsTask.schedule(DELAY);
+ }
+ }
+ };
+ private final FileChangeAdapter moduleInfoListener = new FileChangeAdapter() {
+ @Override
+ public void fileChanged(FileEvent fe) {
+ parseTask.schedule(DELAY);
+ }
+ };
+
+ public ClassPathListener(ClassPath sourcePath) {
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.parseTask = WORKER.create(() -> {
+ FileObject moduleInfo = sourcePath.findResource("module-info.java");
+ Set<String> exported;
+
+ if (moduleInfo != null) {
+ exported = new HashSet<>();
+
+ try {
+ String code = moduleInfo.asText();
+ JavacTask compilerTask = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, Collections.singleton(new TextJFO(code, moduleInfo.toURI())));
+ CompilationUnitTree cut = compilerTask.parse().iterator().next();
+ ModuleTree mt = cut.getModule();
+ if (mt != null) {
+ for (DirectiveTree dt : mt.getDirectives()) {
+ if (dt.getKind() == Kind.EXPORTS) {
+ ExportsTree et = (ExportsTree) dt;
+ if (et.getModuleNames() == null || et.getModuleNames().isEmpty()) {
+ exported.add(et.getPackageName().toString());
+ }
+ }
+ }
+ }
+ } catch (IOException ex) {
+ //TODO: log
+ ex.printStackTrace();
+ }
+ } else {
+ exported = null;
+ }
+
+ exportedPackages.set(exported);
+ cs.fireChange();
+ });
+ sourcePath.addPropertyChangeListener(this);
+ rootsTask = WORKER.create(() -> {
+ ClassPath cp = ClassPathListener.this.sourcePath.get();
+ for (FileObject root : cp.getRoots()) {
+ root.removeFileChangeListener(folderListener);
Review Comment:
I don't understand this -- it does not remove listeneres from obsoleted CP roots (= not present now) IMHO.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.openide.filesystems.FileAttributeEvent;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class SharedRootData {
+
+ private static final Pattern ENABLE_PREVIEW_PATTERN = Pattern.compile("(^|[ \t])--enable-preview($|[ \t])");
+ private static final Pattern SOURCE_PATTERN = Pattern.compile("(^|[ \t])--source[ \t]+([0-9]+(\\.[0-9]+)*)($|[ \t])");
+ private static Map<FileObject, SharedRootData> root2Data = new HashMap<>();
+
+ public static synchronized void ensureRootRegistered(FileObject root) {
+ root2Data.computeIfAbsent(root, r -> new SharedRootData(r));
+ }
+
+ public static synchronized @CheckForNull SharedRootData getDataForRoot(FileObject root) {
+ return root2Data.get(root);
+ }
+
+ private final FileObject root;
+ private final Properties options = new Properties();
+ private final FileChangeListener listener = new FileChangeAdapter() {
+ @Override
+ public void fileAttributeChanged(FileAttributeEvent fe) {
+ Map<String, String> newProperties = new HashMap<>();
+
+ addPropertiesFor(fe.getFile(), newProperties);
+ setNewProperties(newProperties);
+ }
+ };
+
+ private SharedRootData(FileObject root) {
+ this.root = root;
+ root.addRecursiveListener(listener);
+ Enumeration<? extends FileObject> todo = root.getChildren(true);
+ Map<String, String> newProperties = new HashMap<>();
+ while (todo.hasMoreElements()) {
+ FileObject current = todo.nextElement();
+ addPropertiesFor(current, newProperties);
+ }
+ setNewProperties(newProperties);
+ }
+
+ private void addPropertiesFor(FileObject file, Map<String, String> newProperties) {
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ newProperties.put(FileUtil.getRelativePath(root, file), (String) file.getAttribute(SingleSourceFileUtil.FILE_VM_OPTIONS));
+ }
+ }
+
+ private synchronized void setNewProperties(Map<String, String> newProperties) {
+ if (newProperties.isEmpty()) {
+ return ;
+ }
+ for (String key : newProperties.keySet()) {
+ String value = newProperties.get(key);
+ if (value == null) {
+ options.remove(key);
+ } else {
+ options.setProperty(key, value);
+ }
+ }
+ Map<String, String> joinedOptions = new HashMap<>();
+ for (String key : options.stringPropertyNames()) {
+ String value = options.getProperty(key);
+ if (ENABLE_PREVIEW_PATTERN.matcher(value).find()) {
+ joinedOptions.put("--enable-preview", null);
+ }
+ Matcher sourceMatcher = SOURCE_PATTERN.matcher(value);
+ if (sourceMatcher.find()) {
+ //TODO: merging sources!
+ joinedOptions.put("--source", sourceMatcher.group(2));
Review Comment:
:warning: This is an important TODO !
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
+ Project p = FileOwnerQuery.getOwner(f);
+ if (p != null && (p.getLookup().lookup(AccessibilityQueryImplementation2.class) != null ||
+ p.getLookup().lookup(AccessibilityQueryImplementation.class) != null)) {
+ //if there's a project-based AccessibilityQuery for this file, don't provide the generic results
+ return null;
+ }
+ ClassPath sourcePath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
+ if (sourcePath == null) {
+ return null;
+ }
+ ClassPathListener cpl = sourcePath2Listener.computeIfAbsent(sourcePath, sp -> new ClassPathListener(sourcePath));
+ return new ResultImpl(cpl, sourcePath, folder);
+ });
+ }
+
+ private static final class ResultImpl implements Result, ChangeListener {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final ClassPathListener listener;
+ private final Reference<ClassPath> sourcePath;
+ private final Reference<FileObject> folder;
+
+ public ResultImpl(ClassPathListener listener, ClassPath sourcePath, FileObject folder) {
+ this.listener = listener;
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.folder = new WeakReference<>(folder);
+ listener.addChangeListener(this);
+ }
+
+ @Override
+ public AccessibilityQuery.Accessibility getAccessibility() {
+ ClassPath sourcePath = this.sourcePath.get();
+ FileObject folder = this.folder.get();
+ Set<String> exported = listener.getExportedPackages();
+
+ if (sourcePath == null || folder == null || exported == null) {
+ return AccessibilityQuery.Accessibility.UNKNOWN;
+ }
+ String packageName = sourcePath.getResourceName(folder).replace('/', '.');
+ return exported.contains(packageName) ? AccessibilityQuery.Accessibility.EXPORTED
+ : AccessibilityQuery.Accessibility.PRIVATE;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.removeChangeListener(listener);
+ }
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ cs.fireChange();
+ }
+
+ }
+
+ private static final class ClassPathListener implements PropertyChangeListener {
+
+ private static final RequestProcessor WORKER = new RequestProcessor(ClassPathListener.class.getName(), 1, false, false);
+ private static final int DELAY = 100;
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final AtomicReference<Set<String>> exportedPackages = new AtomicReference<>(null);
+ private final Reference<ClassPath> sourcePath;
+ private final Task parseTask;
+ private final Task rootsTask;
+ private final FileChangeAdapter folderListener = new FileChangeAdapter() {
+ @Override
+ public void fileDataCreated(FileEvent fe) {
+ if (fe.getFile().getNameExt().equalsIgnoreCase("module-info.java")) {
+ rootsTask.schedule(DELAY);
+ }
+ }
+ };
+ private final FileChangeAdapter moduleInfoListener = new FileChangeAdapter() {
+ @Override
+ public void fileChanged(FileEvent fe) {
+ parseTask.schedule(DELAY);
+ }
+ };
+
+ public ClassPathListener(ClassPath sourcePath) {
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.parseTask = WORKER.create(() -> {
+ FileObject moduleInfo = sourcePath.findResource("module-info.java");
+ Set<String> exported;
+
+ if (moduleInfo != null) {
+ exported = new HashSet<>();
+
+ try {
+ String code = moduleInfo.asText();
+ JavacTask compilerTask = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, Collections.singleton(new TextJFO(code, moduleInfo.toURI())));
+ CompilationUnitTree cut = compilerTask.parse().iterator().next();
+ ModuleTree mt = cut.getModule();
+ if (mt != null) {
+ for (DirectiveTree dt : mt.getDirectives()) {
+ if (dt.getKind() == Kind.EXPORTS) {
+ ExportsTree et = (ExportsTree) dt;
+ if (et.getModuleNames() == null || et.getModuleNames().isEmpty()) {
+ exported.add(et.getPackageName().toString());
+ }
+ }
+ }
+ }
+ } catch (IOException ex) {
+ //TODO: log
+ ex.printStackTrace();
+ }
+ } else {
+ exported = null;
+ }
+
+ exportedPackages.set(exported);
+ cs.fireChange();
+ });
+ sourcePath.addPropertyChangeListener(this);
+ rootsTask = WORKER.create(() -> {
+ ClassPath cp = ClassPathListener.this.sourcePath.get();
+ for (FileObject root : cp.getRoots()) {
Review Comment:
Null check `cp`.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/LauncherSourceLevelQueryImpl.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.modules.java.file.launcher.SharedRootData;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.*;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author lahvac
+ */
+@ServiceProvider(service=SourceLevelQueryImplementation2.class, position=9_999)
+public class LauncherSourceLevelQueryImpl implements SourceLevelQueryImplementation2 {
+
+ @Override
+ public Result getSourceLevel(FileObject javaFile) {
+ //for files, DefaultSourceLevelQueryImpl will respond:
+ if (javaFile.isFolder()) {
Review Comment:
Shouldn't it bail out if `FileOwnerQuery.getOwner(javaFile) != null` ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
Review Comment:
Get the value from a system property ... or is it just for local troubleshooting ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
+ return cp;
+ }
+
+ folder = folder.getParent();
+ }
+
+ return null;
+ }
+ }
+ }
+
+ public synchronized boolean isSourceLauncher(FileObject file) {
+ for (FileObject root : root2SourceCP.keySet()) {
+ if (FileUtil.isParentOf(root, file) || root.equals(file)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private ClassPath getBootPath(FileObject file) {
+ if (isSourceLauncher(file)) {
+ return JavaPlatformManager.getDefault()
+ .getDefaultPlatform()
+ .getBootstrapLibraries();
+ }
+
+ return null;
+ }
+
+ private static final Set<JavaTokenId> IGNORED_TOKENS = EnumSet.of(
+ JavaTokenId.BLOCK_COMMENT,
+ JavaTokenId.JAVADOC_COMMENT,
+ JavaTokenId.LINE_COMMENT,
+ JavaTokenId.WHITESPACE
+ );
+
+ static String findPackage(String fileContext) {
Review Comment:
Question: given that `package` statement has to be a first non-comment, non-whitespace content in the file, more lightweight search can be done (just skipping whitespaces and comments). Not sure if the performance would increase enough to leverage the impl pain.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/SingleSourceCompilerOptQueryImpl.java:
##########
@@ -37,10 +44,15 @@ public class SingleSourceCompilerOptQueryImpl implements CompilerOptionsQueryImp
@Override
public CompilerOptionsQueryImplementation.Result getOptions(FileObject file) {
- String fileName = file.getName();
Result res = null;
if (SingleSourceFileUtil.isSingleSourceFile(file)) {
- res = new ResultImpl(file);
+ return new ResultImpl(file);
+ }
+ if (file.isFolder()) {
+ SharedRootData data = SharedRootData.getDataForRoot(file);
Review Comment:
Results depends on whether `getSourcePath()` was called for this or sibling file.
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/CompilerOptionsQueryImpl.java:
##########
@@ -107,10 +108,13 @@ private synchronized Configuration getConfiguration(NbCodeLanguageClient client)
//copied from SingleSourceFileUtil:
static boolean isSingleSourceFile(FileObject fObj) {
Project p = FileOwnerQuery.getOwner(fObj);
- if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
+ if (p != null) {
+ return false;
+ }
+ if (!fObj.isFolder() && !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
Review Comment:
Possibly inverted condition for isFolder() ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.openide.filesystems.FileAttributeEvent;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class SharedRootData {
+
+ private static final Pattern ENABLE_PREVIEW_PATTERN = Pattern.compile("(^|[ \t])--enable-preview($|[ \t])");
+ private static final Pattern SOURCE_PATTERN = Pattern.compile("(^|[ \t])--source[ \t]+([0-9]+(\\.[0-9]+)*)($|[ \t])");
Review Comment:
Would be great, if it supported Javac 8 syntax (1.8, 1.7) too.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/api/SourceLauncher.java:
##########
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.api;
+
+import org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Lookup;
+
+public class SourceLauncher {
Review Comment:
`final` + javadoc
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.openide.filesystems.FileAttributeEvent;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class SharedRootData {
+
+ private static final Pattern ENABLE_PREVIEW_PATTERN = Pattern.compile("(^|[ \t])--enable-preview($|[ \t])");
+ private static final Pattern SOURCE_PATTERN = Pattern.compile("(^|[ \t])--source[ \t]+([0-9]+(\\.[0-9]+)*)($|[ \t])");
+ private static Map<FileObject, SharedRootData> root2Data = new HashMap<>();
+
+ public static synchronized void ensureRootRegistered(FileObject root) {
+ root2Data.computeIfAbsent(root, r -> new SharedRootData(r));
+ }
+
+ public static synchronized @CheckForNull SharedRootData getDataForRoot(FileObject root) {
+ return root2Data.get(root);
+ }
+
+ private final FileObject root;
+ private final Properties options = new Properties();
+ private final FileChangeListener listener = new FileChangeAdapter() {
+ @Override
+ public void fileAttributeChanged(FileAttributeEvent fe) {
+ Map<String, String> newProperties = new HashMap<>();
+
+ addPropertiesFor(fe.getFile(), newProperties);
+ setNewProperties(newProperties);
Review Comment:
:warning: Question: the Listener is attached recursively; `addPropertiesFor` will create a single key from the file's relative path. Then `setNewProperties` will remove all other file's entries ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.openide.filesystems.FileAttributeEvent;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class SharedRootData {
+
+ private static final Pattern ENABLE_PREVIEW_PATTERN = Pattern.compile("(^|[ \t])--enable-preview($|[ \t])");
+ private static final Pattern SOURCE_PATTERN = Pattern.compile("(^|[ \t])--source[ \t]+([0-9]+(\\.[0-9]+)*)($|[ \t])");
+ private static Map<FileObject, SharedRootData> root2Data = new HashMap<>();
Review Comment:
Can be final
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/SingleSourceCompilerOptQueryImpl.java:
##########
@@ -16,16 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.netbeans.modules.java.api.common.singlesourcefile;
+package org.netbeans.modules.java.file.launcher.queries;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.event.ChangeListener;
+import org.netbeans.api.project.FileOwnerQuery;
Review Comment:
Unused
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/indexer/CompilerOptionsIndexer.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.indexer;
+
+import org.netbeans.modules.java.file.launcher.SharedRootData;
+import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.modules.parsing.spi.indexing.Context;
+import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
+import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
+import org.netbeans.modules.parsing.spi.indexing.Indexable;
+
+/**
+ *
+ * @author lahvac
+ */
+public class CompilerOptionsIndexer extends CustomIndexer {
+
+
+ @Override
+ protected void index(Iterable<? extends Indexable> files, Context context) {
+ if (FileOwnerQuery.getOwner(context.getRoot()) != null) {
+ return ; //ignore roots under projects
+ }
+ SharedRootData.ensureRootRegistered(context.getRoot());
+ }
+
+
+ @MimeRegistration(mimeType="text/x-java", service=CustomIndexerFactory.class, position=1_000)
+ public static final class FactoryImpl extends CustomIndexerFactory {
+
+ @Override
+ public CustomIndexer createIndexer() {
+ return new CompilerOptionsIndexer();
+ }
+
+ @Override
+ public boolean supportsEmbeddedIndexers() {
+ return true;
+ }
+
+ @Override
+ public void filesDeleted(Iterable<? extends Indexable> deleted, Context context) {
+ //TODO:
Review Comment:
what's here to do ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/LauncherSourceLevelQueryImpl.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.modules.java.file.launcher.SharedRootData;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.*;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author lahvac
+ */
+@ServiceProvider(service=SourceLevelQueryImplementation2.class, position=9_999)
+public class LauncherSourceLevelQueryImpl implements SourceLevelQueryImplementation2 {
+
+ @Override
+ public Result getSourceLevel(FileObject javaFile) {
+ //for files, DefaultSourceLevelQueryImpl will respond:
+ if (javaFile.isFolder()) {
+ while (javaFile != null) {
+ SharedRootData d = SharedRootData.getDataForRoot(javaFile);
+ if (d != null) {
+ return new ResultImpl();
+ }
+ javaFile = javaFile.getParent();
+ }
+ }
+
+ return null;
+ }
+
+ private static final class ResultImpl implements Result {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
Review Comment:
:warning: `cs` is never called to fire changes
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
+ Project p = FileOwnerQuery.getOwner(f);
+ if (p != null && (p.getLookup().lookup(AccessibilityQueryImplementation2.class) != null ||
+ p.getLookup().lookup(AccessibilityQueryImplementation.class) != null)) {
+ //if there's a project-based AccessibilityQuery for this file, don't provide the generic results
+ return null;
+ }
+ ClassPath sourcePath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
+ if (sourcePath == null) {
+ return null;
+ }
+ ClassPathListener cpl = sourcePath2Listener.computeIfAbsent(sourcePath, sp -> new ClassPathListener(sourcePath));
+ return new ResultImpl(cpl, sourcePath, folder);
+ });
+ }
+
+ private static final class ResultImpl implements Result, ChangeListener {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final ClassPathListener listener;
+ private final Reference<ClassPath> sourcePath;
+ private final Reference<FileObject> folder;
+
+ public ResultImpl(ClassPathListener listener, ClassPath sourcePath, FileObject folder) {
+ this.listener = listener;
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.folder = new WeakReference<>(folder);
+ listener.addChangeListener(this);
+ }
+
+ @Override
+ public AccessibilityQuery.Accessibility getAccessibility() {
+ ClassPath sourcePath = this.sourcePath.get();
+ FileObject folder = this.folder.get();
+ Set<String> exported = listener.getExportedPackages();
+
+ if (sourcePath == null || folder == null || exported == null) {
+ return AccessibilityQuery.Accessibility.UNKNOWN;
+ }
+ String packageName = sourcePath.getResourceName(folder).replace('/', '.');
+ return exported.contains(packageName) ? AccessibilityQuery.Accessibility.EXPORTED
+ : AccessibilityQuery.Accessibility.PRIVATE;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.removeChangeListener(listener);
+ }
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ cs.fireChange();
+ }
+
+ }
+
+ private static final class ClassPathListener implements PropertyChangeListener {
+
+ private static final RequestProcessor WORKER = new RequestProcessor(ClassPathListener.class.getName(), 1, false, false);
+ private static final int DELAY = 100;
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final AtomicReference<Set<String>> exportedPackages = new AtomicReference<>(null);
+ private final Reference<ClassPath> sourcePath;
+ private final Task parseTask;
+ private final Task rootsTask;
+ private final FileChangeAdapter folderListener = new FileChangeAdapter() {
+ @Override
+ public void fileDataCreated(FileEvent fe) {
+ if (fe.getFile().getNameExt().equalsIgnoreCase("module-info.java")) {
+ rootsTask.schedule(DELAY);
+ }
+ }
+ };
+ private final FileChangeAdapter moduleInfoListener = new FileChangeAdapter() {
+ @Override
+ public void fileChanged(FileEvent fe) {
+ parseTask.schedule(DELAY);
+ }
+ };
+
+ public ClassPathListener(ClassPath sourcePath) {
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.parseTask = WORKER.create(() -> {
+ FileObject moduleInfo = sourcePath.findResource("module-info.java");
+ Set<String> exported;
+
+ if (moduleInfo != null) {
+ exported = new HashSet<>();
+
+ try {
+ String code = moduleInfo.asText();
+ JavacTask compilerTask = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, Collections.singleton(new TextJFO(code, moduleInfo.toURI())));
+ CompilationUnitTree cut = compilerTask.parse().iterator().next();
+ ModuleTree mt = cut.getModule();
+ if (mt != null) {
+ for (DirectiveTree dt : mt.getDirectives()) {
+ if (dt.getKind() == Kind.EXPORTS) {
+ ExportsTree et = (ExportsTree) dt;
+ if (et.getModuleNames() == null || et.getModuleNames().isEmpty()) {
+ exported.add(et.getPackageName().toString());
+ }
+ }
+ }
+ }
+ } catch (IOException ex) {
+ //TODO: log
+ ex.printStackTrace();
+ }
+ } else {
+ exported = null;
+ }
+
+ exportedPackages.set(exported);
+ cs.fireChange();
+ });
+ sourcePath.addPropertyChangeListener(this);
Review Comment:
Nitpick: attach listener only after rootsTask is initialized (race)
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
+ Project p = FileOwnerQuery.getOwner(f);
+ if (p != null && (p.getLookup().lookup(AccessibilityQueryImplementation2.class) != null ||
+ p.getLookup().lookup(AccessibilityQueryImplementation.class) != null)) {
+ //if there's a project-based AccessibilityQuery for this file, don't provide the generic results
+ return null;
+ }
+ ClassPath sourcePath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
+ if (sourcePath == null) {
+ return null;
+ }
+ ClassPathListener cpl = sourcePath2Listener.computeIfAbsent(sourcePath, sp -> new ClassPathListener(sourcePath));
+ return new ResultImpl(cpl, sourcePath, folder);
+ });
+ }
+
+ private static final class ResultImpl implements Result, ChangeListener {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final ClassPathListener listener;
+ private final Reference<ClassPath> sourcePath;
+ private final Reference<FileObject> folder;
+
+ public ResultImpl(ClassPathListener listener, ClassPath sourcePath, FileObject folder) {
+ this.listener = listener;
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.folder = new WeakReference<>(folder);
+ listener.addChangeListener(this);
+ }
+
+ @Override
+ public AccessibilityQuery.Accessibility getAccessibility() {
+ ClassPath sourcePath = this.sourcePath.get();
+ FileObject folder = this.folder.get();
+ Set<String> exported = listener.getExportedPackages();
+
+ if (sourcePath == null || folder == null || exported == null) {
Review Comment:
Consider a situation:
A client gets AccessibilityQuery.Result and forgots about the FileObject. Could the FileObject expire and make the Result to start returning UNKNOWN ?
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
+ Project p = FileOwnerQuery.getOwner(f);
+ if (p != null && (p.getLookup().lookup(AccessibilityQueryImplementation2.class) != null ||
+ p.getLookup().lookup(AccessibilityQueryImplementation.class) != null)) {
+ //if there's a project-based AccessibilityQuery for this file, don't provide the generic results
+ return null;
+ }
+ ClassPath sourcePath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
+ if (sourcePath == null) {
+ return null;
+ }
+ ClassPathListener cpl = sourcePath2Listener.computeIfAbsent(sourcePath, sp -> new ClassPathListener(sourcePath));
Review Comment:
I thought that just ResultImpl hard-references CPL, so that forgetting results will release CPLs ... or is it intentional to keep CPLs as a form of cache ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/LauncherSourceLevelQueryImpl.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.modules.java.file.launcher.SharedRootData;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.*;
Review Comment:
Unused ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
+ return cp;
+ }
+
+ folder = folder.getParent();
+ }
+
+ return null;
+ }
+ }
+ }
+
+ public synchronized boolean isSourceLauncher(FileObject file) {
+ for (FileObject root : root2SourceCP.keySet()) {
+ if (FileUtil.isParentOf(root, file) || root.equals(file)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private ClassPath getBootPath(FileObject file) {
+ if (isSourceLauncher(file)) {
+ return JavaPlatformManager.getDefault()
+ .getDefaultPlatform()
+ .getBootstrapLibraries();
+ }
+
+ return null;
+ }
+
+ private static final Set<JavaTokenId> IGNORED_TOKENS = EnumSet.of(
+ JavaTokenId.BLOCK_COMMENT,
+ JavaTokenId.JAVADOC_COMMENT,
+ JavaTokenId.LINE_COMMENT,
+ JavaTokenId.WHITESPACE
+ );
+
+ static String findPackage(String fileContext) {
+ TokenHierarchy<String> th = TokenHierarchy.create(fileContext, true, JavaTokenId.language(), IGNORED_TOKENS, null);
+ TokenSequence<JavaTokenId> ts = th.tokenSequence(JavaTokenId.language());
+
+ ts.moveStart();
+
+ while (ts.moveNext()) {
+ if (ts.token().id() == JavaTokenId.PACKAGE) {
Review Comment:
Should the cycle really (possibly) read the whole file, especially for default-package sources ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/LauncherSourceLevelQueryImpl.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.modules.java.file.launcher.SharedRootData;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.*;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author lahvac
+ */
+@ServiceProvider(service=SourceLevelQueryImplementation2.class, position=9_999)
+public class LauncherSourceLevelQueryImpl implements SourceLevelQueryImplementation2 {
+
+ @Override
+ public Result getSourceLevel(FileObject javaFile) {
+ //for files, DefaultSourceLevelQueryImpl will respond:
+ if (javaFile.isFolder()) {
+ while (javaFile != null) {
+ SharedRootData d = SharedRootData.getDataForRoot(javaFile);
+ if (d != null) {
+ return new ResultImpl();
+ }
+ javaFile = javaFile.getParent();
Review Comment:
Hm, wouldn't it help to locate a potential 'owning' shared root faster, if the root Map would be a TreeMap sorted by path ? Just an idea. I sort of don't like the traversal up to the root :) but the same is done by FileOwnerQuery, I admit.
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
+ Project p = FileOwnerQuery.getOwner(f);
+ if (p != null && (p.getLookup().lookup(AccessibilityQueryImplementation2.class) != null ||
+ p.getLookup().lookup(AccessibilityQueryImplementation.class) != null)) {
+ //if there's a project-based AccessibilityQuery for this file, don't provide the generic results
+ return null;
+ }
+ ClassPath sourcePath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
+ if (sourcePath == null) {
+ return null;
+ }
+ ClassPathListener cpl = sourcePath2Listener.computeIfAbsent(sourcePath, sp -> new ClassPathListener(sourcePath));
+ return new ResultImpl(cpl, sourcePath, folder);
+ });
+ }
+
+ private static final class ResultImpl implements Result, ChangeListener {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final ClassPathListener listener;
+ private final Reference<ClassPath> sourcePath;
+ private final Reference<FileObject> folder;
+
+ public ResultImpl(ClassPathListener listener, ClassPath sourcePath, FileObject folder) {
+ this.listener = listener;
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.folder = new WeakReference<>(folder);
+ listener.addChangeListener(this);
+ }
+
+ @Override
+ public AccessibilityQuery.Accessibility getAccessibility() {
+ ClassPath sourcePath = this.sourcePath.get();
+ FileObject folder = this.folder.get();
+ Set<String> exported = listener.getExportedPackages();
+
+ if (sourcePath == null || folder == null || exported == null) {
+ return AccessibilityQuery.Accessibility.UNKNOWN;
+ }
+ String packageName = sourcePath.getResourceName(folder).replace('/', '.');
+ return exported.contains(packageName) ? AccessibilityQuery.Accessibility.EXPORTED
+ : AccessibilityQuery.Accessibility.PRIVATE;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.removeChangeListener(listener);
+ }
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ cs.fireChange();
+ }
+
+ }
+
+ private static final class ClassPathListener implements PropertyChangeListener {
+
+ private static final RequestProcessor WORKER = new RequestProcessor(ClassPathListener.class.getName(), 1, false, false);
+ private static final int DELAY = 100;
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final AtomicReference<Set<String>> exportedPackages = new AtomicReference<>(null);
+ private final Reference<ClassPath> sourcePath;
+ private final Task parseTask;
+ private final Task rootsTask;
+ private final FileChangeAdapter folderListener = new FileChangeAdapter() {
+ @Override
+ public void fileDataCreated(FileEvent fe) {
+ if (fe.getFile().getNameExt().equalsIgnoreCase("module-info.java")) {
+ rootsTask.schedule(DELAY);
+ }
+ }
+ };
+ private final FileChangeAdapter moduleInfoListener = new FileChangeAdapter() {
+ @Override
+ public void fileChanged(FileEvent fe) {
+ parseTask.schedule(DELAY);
+ }
+ };
+
+ public ClassPathListener(ClassPath sourcePath) {
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.parseTask = WORKER.create(() -> {
+ FileObject moduleInfo = sourcePath.findResource("module-info.java");
+ Set<String> exported;
+
+ if (moduleInfo != null) {
+ exported = new HashSet<>();
+
+ try {
+ String code = moduleInfo.asText();
+ JavacTask compilerTask = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, Collections.singleton(new TextJFO(code, moduleInfo.toURI())));
+ CompilationUnitTree cut = compilerTask.parse().iterator().next();
+ ModuleTree mt = cut.getModule();
+ if (mt != null) {
+ for (DirectiveTree dt : mt.getDirectives()) {
+ if (dt.getKind() == Kind.EXPORTS) {
+ ExportsTree et = (ExportsTree) dt;
+ if (et.getModuleNames() == null || et.getModuleNames().isEmpty()) {
+ exported.add(et.getPackageName().toString());
+ }
+ }
+ }
+ }
+ } catch (IOException ex) {
+ //TODO: log
+ ex.printStackTrace();
Review Comment:
a failed `module-info` parse results in empty set of exported packages (not null). OK ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
Review Comment:
`MODULE_BOOT_PATH` handled, but not `MODULE_CLASS_PATH` ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
Review Comment:
Unused ?
##########
java/java.file.launcher/nbproject/project.xml:
##########
@@ -0,0 +1,268 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.apisupport.project</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
+ <code-name-base>org.netbeans.modules.java.file.launcher</code-name-base>
+ <module-dependencies>
+ <dependency>
+ <code-name-base>org.netbeans.api.annotations.common</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.48</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.api.debugger.jpda</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>3.30</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.api.java</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.86</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.api.java.classpath</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.74</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.api.templates</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>1.28</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.libs.javacapi</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>8.44</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.60</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.extexecution</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>1.69</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.extexecution.base</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>1.28</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.56</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.java.platform</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.62</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.java.project.ui</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.95</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.lexer</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>1.84</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.parsing.indexing</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>9.29</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.projectapi</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.91</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.queries</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.63</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.filesystems</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>9.33</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.io</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>1.69</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.loaders</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.90</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.modules</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.68</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.nodes</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.65</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.util</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>9.28</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.util.lookup</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>8.54</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.util.ui</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>9.29</specification-version>
+ </run-dependency>
+ </dependency>
+ </module-dependencies>
+ <test-dependencies>
+ <test-type>
+ <name>unit</name>
+ <test-dependency>
+ <code-name-base>org.netbeans.libs.junit4</code-name-base>
+ <compile-dependency/>
+ </test-dependency>
+ <test-dependency>
+ <code-name-base>org.netbeans.modules.java.j2seplatform</code-name-base>
+ <compile-dependency/>
+ </test-dependency>
+ <test-dependency>
+ <code-name-base>org.netbeans.modules.java.source.base</code-name-base>
+ <compile-dependency/>
+ <test/>
+ </test-dependency>
+ <test-dependency>
+ <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
+ <recursive/>
+ <compile-dependency/>
+ </test-dependency>
+ <test-dependency>
+ <code-name-base>org.netbeans.modules.projectapi.nb</code-name-base>
+ <compile-dependency/>
+ </test-dependency>
+ </test-type>
+ </test-dependencies>
+ <friend-packages>
Review Comment:
Hm, we should e.g. come up with a plan to publish the API, so it won't stay just friend forever as many others ... we have too many friends already.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
Review Comment:
equalsIgnoreCase -- maybe just on case-insensitive OSes (Win) ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
+ return cp;
+ }
+
+ folder = folder.getParent();
+ }
+
+ return null;
+ }
+ }
+ }
+
+ public synchronized boolean isSourceLauncher(FileObject file) {
+ for (FileObject root : root2SourceCP.keySet()) {
+ if (FileUtil.isParentOf(root, file) || root.equals(file)) {
+ return true;
+ }
+ }
+
+ return false;
Review Comment:
if no root is found and the file is Java, a lookup can be done to trigger the logic in `getSourcePath` eventually defining a root. May return bad results, if called before `getSourcePath` for java files in the subtree structure.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
Review Comment:
This can lead to an inconsistent answer if no .java file is queried before: the result could be `null`, but after a .java is queried in the proper subtree, subsequent query on a non-java file starts to return non-`null`.
I'm not sure if this is fixable.
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java:
##########
@@ -311,7 +312,10 @@ public void indexingComplete(Set<URL> indexedRoots) {
delegates = this.delegates.toArray(new TextDocumentServiceImpl[this.delegates.size()]);
}
for (TextDocumentServiceImpl delegate : delegates) {
- delegate.reRunDiagnostics();
+ ProxyLookup augmentedLookup = new ProxyLookup(Lookup.getDefault(), Lookups.fixed(delegate.client));
Review Comment:
I'd suggest to place `delegate.client` before defautl Lookup.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1408053664
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,300 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.WeakHashMap;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=9_999),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2AllPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ClassPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ModulePath = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.COMPILE:
+ return attributeBasedPath(file, file2AllPath, "-classpath", "-cp", "--class-path", "--module-path", "-p");
+ case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return attributeBasedPath(file, file2ClassPath, "-classpath", "-cp", "--class-path");
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return attributeBasedPath(file, file2ModulePath, "--module-path", "-p");
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
Review Comment:
This is unfortunately quite tricky. The CP must be registered in the `GlobalPathRegistry` (so that refactoring would work), so it will never be freed anyway. The current state is that these objects is basically perpetual (until the VM is closed, of course). I am afraid I don't have a good idea how to improve that. Probably the most realistic thing that comes to my mind is to free roots that are "unused" for an extended period of time. Which has its own problems, of course.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1840321585
If there are no objections, I'll rebase, squash and if GH Actions are green integrate. Seems now is a good time - there should be some time to find and fix issues before the next release. Also 'JEP 458: Launch Multi-File Source-Code Programs' has been integrated today, so it is a high time to have a support for it. (JEP 458 is not the only usecase for this, but it is one of the major ones.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1857867731
@lahodaj @matthiasblaesing i believe this causes another regression take the following snippet:
```java
import java.util.stream.Gatherers;
public class SingleFileProgram {
public static void main(String[] args) {
System.out.println(Gatherers.class);
}
}
```
open it in NB 20 started on JDK 22ea (build 27+ required)
- you should see a hint suggesting to enable preview, run that hint
- everything should be fine, errors will go away
repeat with master started on JDK 22ea
- hint will successfully add the `--enable-preview --source 22` line to the file properties
- however, the errors will not go away, even after NB restart
- (small followup bug: running the hint again will now add another `--enable-preview` flag to the properties)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1410337948
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java:
##########
@@ -315,7 +316,10 @@ public void indexingComplete(Set<URL> indexedRoots) {
delegates = this.delegates.toArray(new TextDocumentServiceImpl[this.delegates.size()]);
}
for (TextDocumentServiceImpl delegate : delegates) {
- delegate.reRunDiagnostics();
+ ProxyLookup augmentedLookup = new ProxyLookup(Lookups.fixed(delegate.client), Lookup.getDefault());
+ Lookups.executeWith(augmentedLookup, () -> {
Review Comment:
I don't think we have that - but you could eventually expose it from `LspServerState` implemented by `LanguageServerImpl` . Maybe just make a comment that the lookup is different so when an issue pops up, this conversation will be reminded.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1850798410
@lahodaj for the changes I created #6832
For `Exceptions.printStrackTrace` I got the feeling, that once that is invoked, further executions of that code path is blocked until the problem is acknowledged, but that might be just a misinterpretation/misobservation ;-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1310354827
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.openide.filesystems.FileAttributeEvent;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class SharedRootData {
+
+ private static final Pattern ENABLE_PREVIEW_PATTERN = Pattern.compile("(^|[ \t])--enable-preview($|[ \t])");
+ private static final Pattern SOURCE_PATTERN = Pattern.compile("(^|[ \t])--source[ \t]+([0-9]+(\\.[0-9]+)*)($|[ \t])");
+ private static Map<FileObject, SharedRootData> root2Data = new HashMap<>();
+
+ public static synchronized void ensureRootRegistered(FileObject root) {
+ root2Data.computeIfAbsent(root, r -> new SharedRootData(r));
+ }
+
+ public static synchronized @CheckForNull SharedRootData getDataForRoot(FileObject root) {
+ return root2Data.get(root);
+ }
+
+ private final FileObject root;
+ private final Properties options = new Properties();
+ private final FileChangeListener listener = new FileChangeAdapter() {
+ @Override
+ public void fileAttributeChanged(FileAttributeEvent fe) {
+ Map<String, String> newProperties = new HashMap<>();
+
+ addPropertiesFor(fe.getFile(), newProperties);
+ setNewProperties(newProperties);
Review Comment:
No, because the previous values are persisted in the `options` field. But, it is true a file's options are not cleared when the file is deleted. I'll fix that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1310244277
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SharedRootData.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.openide.filesystems.FileAttributeEvent;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author lahvac
+ */
+public class SharedRootData {
+
+ private static final Pattern ENABLE_PREVIEW_PATTERN = Pattern.compile("(^|[ \t])--enable-preview($|[ \t])");
+ private static final Pattern SOURCE_PATTERN = Pattern.compile("(^|[ \t])--source[ \t]+([0-9]+(\\.[0-9]+)*)($|[ \t])");
Review Comment:
But, it does, doesn't it? `([0-9]+(\\.[0-9]+)*)` seems to cover `1.8` and `1.7`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1409097332
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java:
##########
@@ -315,7 +316,10 @@ public void indexingComplete(Set<URL> indexedRoots) {
delegates = this.delegates.toArray(new TextDocumentServiceImpl[this.delegates.size()]);
}
for (TextDocumentServiceImpl delegate : delegates) {
- delegate.reRunDiagnostics();
+ ProxyLookup augmentedLookup = new ProxyLookup(Lookups.fixed(delegate.client), Lookup.getDefault());
+ Lookups.executeWith(augmentedLookup, () -> {
Review Comment:
Please note this runs outside of the event loop, this runs when indexing finishes in a background thread, so the client is not set.
Note this also relates to what settings are used during indexing - there are merged settings across all clients for used by the indexing (see `SingleFileOptionsQueryImpl.globalOptions`), but for the editor, we can use the sharper per-client settings.
##########
java/java.lsp.server/vscode/src/nbcode.ts:
##########
@@ -75,7 +75,7 @@ export function launch(
}
ideArgs.push(...extraArgs);
- if (env['netbeans_debug'] && extraArgs && extraArgs.find(s => s.includes("--list"))) {
+ if (extraArgs && extraArgs.find(s => s.includes("--list"))) {
Review Comment:
Oops, this is a mistake, will fix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1416481776
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java:
##########
@@ -68,15 +73,15 @@ static FileObject getJavaFileWithoutProjectFromLookup(Lookup lookup) {
return null;
}
- static boolean isSingleSourceFile(FileObject fObj) {
+ public static boolean isSingleSourceFile(FileObject fObj) {
Project p = FileOwnerQuery.getOwner(fObj);
if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
return false;
}
return true;
}
- static Process compileJavaSource(FileObject fileObject) {
+ public static Process compileJavaSource(FileObject fileObject) {
FileObject javac = JavaPlatformManager.getDefault().getDefaultPlatform().findTool("javac"); //NOI18N
Review Comment:
> I think I (and possibly others) are considering separating the runtime JDK and the JavaPlatform used by projects in VS Code extension. Maybe by changing the result of JavaPlatformManager.getDefaultPlatform().
yes but since free floating java files are not associated with a project, users can't even influence on which JDK they want to run the single/multi-file-java-program (SMFJP?). Which is independent of the default JDK vs nb runtime discussion. Controlling this over the default JDK is one way of doing this, but what if users don't want to run a file on the default JDK but on a specific JDK?
A JDK selector could be potentially added to the file properties, just like we have in maven/ant/gradle projects.

> But I would prefer to avoid doing that here - this PR is complex enough on it own.
agreed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1849579306
@matthiasblaesing, seems sensible to me. Will you please open a PR?
Regarding `Exceptions.printStrackTrace` not sure what you mean. I don't think it does anything super special.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1857947602
Uh, I always forget that the `java.lsp.server` runs in ordinary IDE run as well, so any services registered there would be used for ordinary runs as well, like, in this case `org.netbeans.modules.java.lsp.server.singlesourcefile.SingleFileOptionsQueryImpl`. Will move the registration into `nbcode`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1416481776
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java:
##########
@@ -68,15 +73,15 @@ static FileObject getJavaFileWithoutProjectFromLookup(Lookup lookup) {
return null;
}
- static boolean isSingleSourceFile(FileObject fObj) {
+ public static boolean isSingleSourceFile(FileObject fObj) {
Project p = FileOwnerQuery.getOwner(fObj);
if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
return false;
}
return true;
}
- static Process compileJavaSource(FileObject fileObject) {
+ public static Process compileJavaSource(FileObject fileObject) {
FileObject javac = JavaPlatformManager.getDefault().getDefaultPlatform().findTool("javac"); //NOI18N
Review Comment:
> I think I (and possibly others) are considering separating the runtime JDK and the JavaPlatform used by projects in VS Code extension. Maybe by changing the result of JavaPlatformManager.getDefaultPlatform().
yes but since java files are not associated with a project, users can't even influence on which JDK they want to run the single/multi-file-java-program (SMFJP?). Which is independent of the default JDK vs nb runtime discussion. Controlling this over the default JDK is one way of doing this, but what if users don't want to run a file on the default JDK but on a specific JDK?
A JDK selector could be potentially added to the file properties, just like we have in maven/ant/gradle projects.

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1310366510
##########
java/java.file.launcher/nbproject/project.xml:
##########
@@ -0,0 +1,268 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.apisupport.project</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
+ <code-name-base>org.netbeans.modules.java.file.launcher</code-name-base>
+ <module-dependencies>
+ <dependency>
+ <code-name-base>org.netbeans.api.annotations.common</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.48</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.api.debugger.jpda</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>3.30</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.api.java</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.86</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.api.java.classpath</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.74</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.api.templates</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>1.28</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.libs.javacapi</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>8.44</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.60</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.extexecution</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>1.69</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.extexecution.base</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>1.28</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.java.lexer</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.56</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.java.platform</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.62</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.java.project.ui</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.95</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.lexer</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>2</release-version>
+ <specification-version>1.84</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.parsing.indexing</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>9.29</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.projectapi</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.91</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.netbeans.modules.queries</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <release-version>1</release-version>
+ <specification-version>1.63</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.filesystems</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>9.33</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.io</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>1.69</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.loaders</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.90</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.modules</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.68</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.nodes</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>7.65</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.util</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>9.28</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.util.lookup</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>8.54</specification-version>
+ </run-dependency>
+ </dependency>
+ <dependency>
+ <code-name-base>org.openide.util.ui</code-name-base>
+ <build-prerequisite/>
+ <compile-dependency/>
+ <run-dependency>
+ <specification-version>9.29</specification-version>
+ </run-dependency>
+ </dependency>
+ </module-dependencies>
+ <test-dependencies>
+ <test-type>
+ <name>unit</name>
+ <test-dependency>
+ <code-name-base>org.netbeans.libs.junit4</code-name-base>
+ <compile-dependency/>
+ </test-dependency>
+ <test-dependency>
+ <code-name-base>org.netbeans.modules.java.j2seplatform</code-name-base>
+ <compile-dependency/>
+ </test-dependency>
+ <test-dependency>
+ <code-name-base>org.netbeans.modules.java.source.base</code-name-base>
+ <compile-dependency/>
+ <test/>
+ </test-dependency>
+ <test-dependency>
+ <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
+ <recursive/>
+ <compile-dependency/>
+ </test-dependency>
+ <test-dependency>
+ <code-name-base>org.netbeans.modules.projectapi.nb</code-name-base>
+ <compile-dependency/>
+ </test-dependency>
+ </test-type>
+ </test-dependencies>
+ <friend-packages>
Review Comment:
I think I would like to gain some experience with this, before making an API like this public. It may turn out we may need to handle the source launcher differently.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1311319341
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/CompilerOptionsQueryImpl.java:
##########
@@ -107,10 +108,13 @@ private synchronized Configuration getConfiguration(NbCodeLanguageClient client)
//copied from SingleSourceFileUtil:
static boolean isSingleSourceFile(FileObject fObj) {
Project p = FileOwnerQuery.getOwner(fObj);
- if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
+ if (p != null) {
+ return false;
+ }
+ if (!fObj.isFolder() && !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
Review Comment:
I don't think so - if it is a file (i.e. not a folder),and does not have the `java` extension, then stop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1407713032
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/api/SourceLauncher.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.api;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.modules.SpecificationVersion;
+import org.openide.util.Lookup;
+
+/**Holds utilities for source file launcher.
+ *
+ */
+public final class SourceLauncher {
+
+ private static final String ENABLE_PREVIEW = "--enable-preview";
+ private static final String SOURCE = "--source";
+ private static final String CLASS_PATH = "--class-path";
+ private static final String CLASSPATH = "-classpath";
+ private static final String CP = "-cp";
+ private static final String MODULE_PATH = "--module-path";
+ private static final String P = "-p";
+
+ /**Returns {@code true} if and only if the given file is known as a
+ * file that is handled by a source file launcher. This, in particular,
+ * typically means the file is outside of a project.
+ *
+ * @param file the file to test
+ * @return {@code true} if and only if the file is known as a file handled by the
+ * source launcher. {@code false} otherwise.
+ */
+ public static boolean isSourceLauncherFile(FileObject file) {
+ MultiSourceRootProvider msrp = Lookup.getDefault().lookup(MultiSourceRootProvider.class);
+ return msrp != null && msrp.isSourceLauncher(file);
+ }
+
+ public static String joinCommandLines(Iterable<? extends String> inputLines) {
+ Map<String, String> joinedOptions = new HashMap<>();
+
+ for (String value : inputLines) {
+ List<String> args = SingleSourceFileUtil.parseLine(value);
+
+ for (int i = 0; i < args.size(); i++) {
+ switch (args.get(i)) {
+ case ENABLE_PREVIEW:
+ joinedOptions.put(ENABLE_PREVIEW, null);
+ break;
+ case CLASSPATH: case CLASS_PATH: case CP:
+ if (i + 1 < args.size()) {
+ joinedOptions.put(CLASS_PATH, mergePaths(joinedOptions.get(CLASS_PATH), args.get(i + 1)));
+ i++;
+ }
+ break;
+ case MODULE_PATH: case P:
+ if (i + 1 < args.size()) {
+ joinedOptions.put(MODULE_PATH, mergePaths(joinedOptions.get(MODULE_PATH), args.get(i + 1)));
+ i++;
+ }
+ break;
+ case SOURCE:
+ if (i + 1 < args.size()) {
+ String version = args.get(i + 1);
+ String testVersion = version;
+ if (testVersion.startsWith("1.")) {
+ testVersion = testVersion.substring(2);
+ }
+ String existingVersion = joinedOptions.get("--source");
Review Comment:
nitpick: use existing constants for strings.
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java:
##########
@@ -315,7 +316,10 @@ public void indexingComplete(Set<URL> indexedRoots) {
delegates = this.delegates.toArray(new TextDocumentServiceImpl[this.delegates.size()]);
}
for (TextDocumentServiceImpl delegate : delegates) {
- delegate.reRunDiagnostics();
+ ProxyLookup augmentedLookup = new ProxyLookup(Lookups.fixed(delegate.client), Lookup.getDefault());
+ Lookups.executeWith(augmentedLookup, () -> {
Review Comment:
probably not needed, but `Server.ConsumeWithLookup` also passes sessionLookup contents and `OperationContext` to client requests.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,300 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.WeakHashMap;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=9_999),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2AllPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ClassPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ModulePath = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.COMPILE:
+ return attributeBasedPath(file, file2AllPath, "-classpath", "-cp", "--class-path", "--module-path", "-p");
+ case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return attributeBasedPath(file, file2ClassPath, "-classpath", "-cp", "--class-path");
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return attributeBasedPath(file, file2ModulePath, "--module-path", "-p");
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
+ return cp;
+ }
+
+ folder = folder.getParent();
+ }
+
+ return null;
+ }
+ }
+ }
+
+ private synchronized FileObject getSourceRootImpl(FileObject file) {
+ for (FileObject root : root2SourceCP.keySet()) {
+ if (FileUtil.isParentOf(root, file) || root.equals(file)) {
Review Comment:
nitpick: flip the clauses, equals() is faster and hopefully peopel won't write much 'single source' packages.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,300 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.WeakHashMap;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=9_999),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2AllPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ClassPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ModulePath = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.COMPILE:
+ return attributeBasedPath(file, file2AllPath, "-classpath", "-cp", "--class-path", "--module-path", "-p");
+ case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return attributeBasedPath(file, file2ClassPath, "-classpath", "-cp", "--class-path");
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return attributeBasedPath(file, file2ModulePath, "--module-path", "-p");
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
Review Comment:
weak = ? Do you want to store Reference<Classpath> instead of Classpath in the map ?
##########
java/java.lsp.server/vscode/src/nbcode.ts:
##########
@@ -75,7 +75,7 @@ export function launch(
}
ideArgs.push(...extraArgs);
- if (env['netbeans_debug'] && extraArgs && extraArgs.find(s => s.includes("--list"))) {
+ if (extraArgs && extraArgs.find(s => s.includes("--list"))) {
Review Comment:
Why was the env variable condition removed ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/LauncherSourceLevelQueryImpl.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.util.List;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author lahvac
+ */
+@ServiceProvider(service=SourceLevelQueryImplementation2.class, position=9_999)
+public class LauncherSourceLevelQueryImpl implements SourceLevelQueryImplementation2 {
+
+ @Override
+ public Result getSourceLevel(FileObject javaFile) {
+ SingleFileOptionsQueryImplementation.Result delegate = SingleSourceFileUtil.getOptionsFor(javaFile);
+
+ if (delegate != null) {
+ return new ResultImpl(delegate);
+ } else {
+ return null;
+ }
+ }
+
+ private static final class ResultImpl implements ChangeListener, Result {
+
+ private static final String DEFAULT_SOURCE_LEVEL =
+ JavaPlatformManager.getDefault().getDefaultPlatform().getSpecification().getVersion().toString();
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final SingleFileOptionsQueryImplementation.Result delegate;
+ private String sourceLevel;
+
+ public ResultImpl(SingleFileOptionsQueryImplementation.Result delegate) {
+ this.delegate = delegate;
+ this.delegate.addChangeListener(this);
+ updateDelegate();
+ }
+
+ private void updateDelegate() {
+ List<String> parsed = SingleSourceFileUtil.parseLine(delegate.getOptions());
+ String sourceLevel = DEFAULT_SOURCE_LEVEL;
+
+ for (int i = 0; i < parsed.size(); i++) {
+ if ("--source".equals(parsed.get(i)) && i + 1 < parsed.size()) {
+ sourceLevel = parsed.get(i + 1);
+ }
+ }
+
+ synchronized (this) {
+ this.sourceLevel = sourceLevel;
Review Comment:
nitpick: only fire changes if != ?
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,300 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.WeakHashMap;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=9_999),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2AllPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ClassPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ModulePath = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.COMPILE:
+ return attributeBasedPath(file, file2AllPath, "-classpath", "-cp", "--class-path", "--module-path", "-p");
+ case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return attributeBasedPath(file, file2ClassPath, "-classpath", "-cp", "--class-path");
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return attributeBasedPath(file, file2ModulePath, "--module-path", "-p");
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
+ return cp;
+ }
+
+ folder = folder.getParent();
+ }
+
+ return null;
+ }
+ }
+ }
+
+ private synchronized FileObject getSourceRootImpl(FileObject file) {
+ for (FileObject root : root2SourceCP.keySet()) {
+ if (FileUtil.isParentOf(root, file) || root.equals(file)) {
+ return root;
+ }
+ }
+
+ return null;
+ }
+
+ public FileObject getSourceRoot(FileObject file) {
+ FileObject root = getSourceRootImpl(file);
+
+ if (root == null) {
+ getSourcePath(file);
+ root = getSourceRootImpl(file);
+ }
+
+ return root;
+ }
+
+ public boolean isSourceLauncher(FileObject file) {
+ return getSourceRoot(file) != null;
+ }
+
+ private ClassPath getBootPath(FileObject file) {
+ if (isSourceLauncher(file)) {
+ return JavaPlatformManager.getDefault()
+ .getDefaultPlatform()
+ .getBootstrapLibraries();
+ }
+
+ return null;
+ }
+
+ private static final Set<JavaTokenId> IGNORED_TOKENS = EnumSet.of(
+ JavaTokenId.BLOCK_COMMENT,
+ JavaTokenId.JAVADOC_COMMENT,
+ JavaTokenId.LINE_COMMENT,
+ JavaTokenId.WHITESPACE
+ );
+
+ private static final Set<JavaTokenId> STOP_TOKENS = EnumSet.of(
Review Comment:
maybe `import` could also stop - or is it intentional to allow for common order mismatches ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1298582905
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/LauncherSourceLevelQueryImpl.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.modules.java.file.launcher.SharedRootData;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.*;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author lahvac
+ */
+@ServiceProvider(service=SourceLevelQueryImplementation2.class, position=9_999)
+public class LauncherSourceLevelQueryImpl implements SourceLevelQueryImplementation2 {
+
+ @Override
+ public Result getSourceLevel(FileObject javaFile) {
+ //for files, DefaultSourceLevelQueryImpl will respond:
+ if (javaFile.isFolder()) {
+ while (javaFile != null) {
+ SharedRootData d = SharedRootData.getDataForRoot(javaFile);
+ if (d != null) {
+ return new ResultImpl();
+ }
+ javaFile = javaFile.getParent();
+ }
+ }
+
+ return null;
+ }
+
+ private static final class ResultImpl implements Result {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
Review Comment:
:warning: `cs` is never called to fire changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1846188041
And this also indicates that this is fishy:
```
Parent does not exist /tmp/vcs-1701986802781/vcs-1701986926097
Parent exists: /tmp/vcs-1701986802781
Has children []
msg
Parent does not exist /tmp/vcs-1701986802781/vcs-1701986926097
Parent exists: /tmp/vcs-1701986802781
Has children []
Caused: java.io.FileNotFoundException: Can't read /tmp/vcs-1701986802781/vcs-1701986926097/CargoPanel.java
at org.netbeans.modules.masterfs.filebasedfs.fileobjects.FileObj.getInputStream(FileObj.java:194)
at org.openide.filesystems.FileObject.asBytes(FileObject.java:687)
[catch] at org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider.lambda$getSourcePath$1(MultiSourceRootProvider.java:98)
at java.base/java.util.Map.computeIfAbsent(Map.java:1054)
at org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider.getSourcePath(MultiSourceRootProvider.java:96)
at org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider.getSourceRoot(MultiSourceRootProvider.java:160)
at org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider.isSourceLauncher(MultiSourceRootProvider.java:168)
at org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider.getBootPath(MultiSourceRootProvider.java:172)
at org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider.findClassPath(MultiSourceRootProvider.java:86)
at org.netbeans.api.java.classpath.ClassPath.getClassPath(ClassPath.java:667)
at org.netbeans.api.java.source.ClasspathInfo.create(ClasspathInfo.java:412)
at org.netbeans.api.java.source.ClasspathInfo.create(ClasspathInfo.java:287)
at org.netbeans.modules.java.source.parsing.JavacParser.init(JavacParser.java:282)
at org.netbeans.modules.java.source.parsing.JavacParser.parseImpl(JavacParser.java:427)
at org.netbeans.modules.java.source.parsing.JavacParser.parse(JavacParser.java:366)
at org.netbeans.modules.parsing.impl.TaskProcessor.callParse(TaskProcessor.java:598)
at org.netbeans.modules.parsing.impl.SourceCache.getResult(SourceCache.java:230)
at org.netbeans.modules.parsing.api.ResultIterator.getParserResult(ResultIterator.java:115)
at org.netbeans.api.java.source.JavaSource$MultiTask.run(JavaSource.java:496)
at org.netbeans.modules.parsing.impl.TaskProcessor.callUserTask(TaskProcessor.java:586)
at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:132)
at org.netbeans.modules.parsing.api.ParserManager$UserTaskAction.run(ParserManager.java:116)
at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:181)
at org.netbeans.modules.parsing.impl.TaskProcessor$2.call(TaskProcessor.java:178)
at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:153)
at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:335)
at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(DataObjectEnvFactory.java:118)
at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:67)
at org.netbeans.modules.parsing.impl.TaskProcessor.runUserTask(TaskProcessor.java:178)
at org.netbeans.modules.parsing.api.ParserManager.parse(ParserManager.java:83)
at org.netbeans.api.java.source.JavaSource.runUserActionTaskImpl(JavaSource.java:454)
at org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:425)
at org.netbeans.modules.java.JavaNode$IconTask$SourceIcon.computeIcon(JavaNode.java:518)
at org.netbeans.modules.java.JavaNode$IconTask.run(JavaNode.java:480)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1420)
at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2035)
ALL [null]: Cannot read file CargoPanel.java in /tmp/vcs-1701986802781/vcs-1701986926097.
Parent does not exist /tmp/vcs-1701986802781/vcs-1701986926097
Parent exists: /tmp/vcs-1701986802781
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1310224150
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
+ Project p = FileOwnerQuery.getOwner(f);
+ if (p != null && (p.getLookup().lookup(AccessibilityQueryImplementation2.class) != null ||
+ p.getLookup().lookup(AccessibilityQueryImplementation.class) != null)) {
+ //if there's a project-based AccessibilityQuery for this file, don't provide the generic results
+ return null;
+ }
+ ClassPath sourcePath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
+ if (sourcePath == null) {
+ return null;
+ }
+ ClassPathListener cpl = sourcePath2Listener.computeIfAbsent(sourcePath, sp -> new ClassPathListener(sourcePath));
+ return new ResultImpl(cpl, sourcePath, folder);
+ });
+ }
+
+ private static final class ResultImpl implements Result, ChangeListener {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final ClassPathListener listener;
+ private final Reference<ClassPath> sourcePath;
+ private final Reference<FileObject> folder;
+
+ public ResultImpl(ClassPathListener listener, ClassPath sourcePath, FileObject folder) {
+ this.listener = listener;
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.folder = new WeakReference<>(folder);
+ listener.addChangeListener(this);
+ }
+
+ @Override
+ public AccessibilityQuery.Accessibility getAccessibility() {
+ ClassPath sourcePath = this.sourcePath.get();
+ FileObject folder = this.folder.get();
+ Set<String> exported = listener.getExportedPackages();
+
+ if (sourcePath == null || folder == null || exported == null) {
+ return AccessibilityQuery.Accessibility.UNKNOWN;
+ }
+ String packageName = sourcePath.getResourceName(folder).replace('/', '.');
+ return exported.contains(packageName) ? AccessibilityQuery.Accessibility.EXPORTED
+ : AccessibilityQuery.Accessibility.PRIVATE;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.removeChangeListener(listener);
+ }
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ cs.fireChange();
+ }
+
+ }
+
+ private static final class ClassPathListener implements PropertyChangeListener {
+
+ private static final RequestProcessor WORKER = new RequestProcessor(ClassPathListener.class.getName(), 1, false, false);
+ private static final int DELAY = 100;
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final AtomicReference<Set<String>> exportedPackages = new AtomicReference<>(null);
+ private final Reference<ClassPath> sourcePath;
+ private final Task parseTask;
+ private final Task rootsTask;
+ private final FileChangeAdapter folderListener = new FileChangeAdapter() {
+ @Override
+ public void fileDataCreated(FileEvent fe) {
+ if (fe.getFile().getNameExt().equalsIgnoreCase("module-info.java")) {
+ rootsTask.schedule(DELAY);
+ }
+ }
+ };
+ private final FileChangeAdapter moduleInfoListener = new FileChangeAdapter() {
+ @Override
+ public void fileChanged(FileEvent fe) {
+ parseTask.schedule(DELAY);
+ }
+ };
+
+ public ClassPathListener(ClassPath sourcePath) {
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.parseTask = WORKER.create(() -> {
+ FileObject moduleInfo = sourcePath.findResource("module-info.java");
+ Set<String> exported;
+
+ if (moduleInfo != null) {
+ exported = new HashSet<>();
+
+ try {
+ String code = moduleInfo.asText();
+ JavacTask compilerTask = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, Collections.singleton(new TextJFO(code, moduleInfo.toURI())));
+ CompilationUnitTree cut = compilerTask.parse().iterator().next();
+ ModuleTree mt = cut.getModule();
+ if (mt != null) {
+ for (DirectiveTree dt : mt.getDirectives()) {
+ if (dt.getKind() == Kind.EXPORTS) {
+ ExportsTree et = (ExportsTree) dt;
+ if (et.getModuleNames() == null || et.getModuleNames().isEmpty()) {
+ exported.add(et.getPackageName().toString());
+ }
+ }
+ }
+ }
+ } catch (IOException ex) {
+ //TODO: log
+ ex.printStackTrace();
Review Comment:
I think that's what I intended. If there's a module-info.java *and* we can't parse, then we can't know which packages are exported. (OTOH, I don't think the exception can ordinarily happen - we provide an input source file that does not throw it, and we only parse.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1810116760
@sdedic, I believe I've updated the patch based on your comments, and generally improved it. Could you please take a look? Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1409302767
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java:
##########
@@ -315,7 +316,10 @@ public void indexingComplete(Set<URL> indexedRoots) {
delegates = this.delegates.toArray(new TextDocumentServiceImpl[this.delegates.size()]);
}
for (TextDocumentServiceImpl delegate : delegates) {
- delegate.reRunDiagnostics();
+ ProxyLookup augmentedLookup = new ProxyLookup(Lookups.fixed(delegate.client), Lookup.getDefault());
+ Lookups.executeWith(augmentedLookup, () -> {
Review Comment:
Ah, sorry, I misunderstood this to say this code is not needed. I suspect we don't have a meaningful `OperationContext` (as this runs asynchronously, and we probably should report any progress here anyway). Is there a way to get the `sessionLookup`? I don't think it is strictly necessary, but we could include that, in case it would be useful later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1411414616
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java:
##########
@@ -68,15 +73,15 @@ static FileObject getJavaFileWithoutProjectFromLookup(Lookup lookup) {
return null;
}
- static boolean isSingleSourceFile(FileObject fObj) {
+ public static boolean isSingleSourceFile(FileObject fObj) {
Project p = FileOwnerQuery.getOwner(fObj);
if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
return false;
}
return true;
}
- static Process compileJavaSource(FileObject fileObject) {
+ public static Process compileJavaSource(FileObject fileObject) {
FileObject javac = JavaPlatformManager.getDefault().getDefaultPlatform().findTool("javac"); //NOI18N
Review Comment:
Thinking about adding a JDK selector to the file properties of single source programs for NB 21 to decouple it from the runtime JDK. Is something like this planned? Will this still work in VSCode?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1858255682
FYI, opened:
https://github.com/apache/netbeans/pull/6854
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1979227695
@lahodaj I'm just updating a couple of platform applications to NB21, and the addition of the `java.file.launcher` dependency in `refactoring.java` is causing some issues. I'd really like to not bring in that dependency and its dependencies (particularly as I have to use the kill switch too).
Is there any way we could achieve what you need in `refactoring.java` in NB22 while removing the hard dependency?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1311256901
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
Review Comment:
Yes, until we see a file, we will not know about it. I don't quite see a way around this, I'm afraid.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
+ return cp;
+ }
+
+ folder = folder.getParent();
+ }
+
+ return null;
+ }
+ }
+ }
+
+ public synchronized boolean isSourceLauncher(FileObject file) {
+ for (FileObject root : root2SourceCP.keySet()) {
+ if (FileUtil.isParentOf(root, file) || root.equals(file)) {
+ return true;
+ }
+ }
+
+ return false;
Review Comment:
As above - until we see a file, we will not know about it. I don't quite see a way around this, I'm afraid.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1847354917
Uh sorry for this. I'll be looking into it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#issuecomment-1846144801
It seems this integration causes issues in indexing:
```
java.io.IOException: Setting attribute not allowed for JarFileSystem [/home/matthias/bin/jdk-17/lib/src.zip!java.base <- single_file_vm_options=]
at org.openide.filesystems.JarFileSystem.writeAttribute(JarFileSystem.java:622)
at org.openide.filesystems.JarFileSystem$Impl.writeAttribute(JarFileSystem.java:1173)
at org.openide.filesystems.AbstractFileObject.setAttribute(AbstractFileObject.java:342)
at org.openide.filesystems.AbstractFileObject.setAttribute(AbstractFileObject.java:325)
[catch] at org.netbeans.modules.java.file.launcher.SharedRootData.setNewProperties(SharedRootData.java:108)
at org.netbeans.modules.java.file.launcher.SharedRootData.<init>(SharedRootData.java:84)
at org.netbeans.modules.java.file.launcher.SharedRootData.lambda$ensureRootRegistered$0(SharedRootData.java:49)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1220)
at org.netbeans.modules.java.file.launcher.SharedRootData.ensureRootRegistered(SharedRootData.java:49)
at org.netbeans.modules.java.file.launcher.indexer.CompilerOptionsIndexer.index(CompilerOptionsIndexer.java:41)
at org.netbeans.modules.parsing.spi.indexing.Indexable$MyAccessor$2.run(Indexable.java:138)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.runIndexer(RepositoryUpdater.java:274)
at org.netbeans.modules.parsing.spi.indexing.Indexable$MyAccessor.index(Indexable.java:136)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.doIndex(RepositoryUpdater.java:2749)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.lambda$index$0(RepositoryUpdater.java:2626)
at org.netbeans.modules.parsing.impl.indexing.errors.TaskCache.refreshTransaction(TaskCache.java:540)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.index(RepositoryUpdater.java:2625)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$AbstractRootsWork.lambda$scanSource$3(RepositoryUpdater.java:5735)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.lambda$runInContext$4(RepositoryUpdater.java:2119)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.runInContext(RepositoryUpdater.java:2117)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.runInContext(RepositoryUpdater.java:2098)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater.access$1400(RepositoryUpdater.java:135)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$AbstractRootsWork.scanSource(RepositoryUpdater.java:5770)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$AbstractRootsWork.scanSources(RepositoryUpdater.java:5443)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$RootsWork.getDone(RepositoryUpdater.java:5075)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Work.doTheWork(RepositoryUpdater.java:3452)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task._run(RepositoryUpdater.java:6197)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task.access$3400(RepositoryUpdater.java:5855)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.lambda$call$0(RepositoryUpdater.java:6116)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:288)
at org.netbeans.modules.parsing.impl.RunWhenScanFinishedSupport.performScan(RunWhenScanFinishedSupport.java:83)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.call(RepositoryUpdater.java:6116)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task$2.call(RepositoryUpdater.java:6112)
at org.netbeans.modules.masterfs.filebasedfs.utils.FileChangedManager.priorityIO(FileChangedManager.java:153)
at org.netbeans.modules.masterfs.providers.ProvidedExtensions.priorityIO(ProvidedExtensions.java:335)
at org.netbeans.modules.parsing.nb.DataObjectEnvFactory.runPriorityIO(DataObjectEnvFactory.java:118)
at org.netbeans.modules.parsing.impl.Utilities.runPriorityIO(Utilities.java:67)
at org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater$Task.run(RepositoryUpdater.java:6112)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1420)
at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
at org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2035)
```
My indication is, that the issue is rooted in classes introduced in this PR and I observe this since a few minutes where I merged recent changes from master.
@lahodaj please have a look
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1409287832
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/api/SourceLauncher.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.api;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.modules.SpecificationVersion;
+import org.openide.util.Lookup;
+
+/**Holds utilities for source file launcher.
+ *
+ */
+public final class SourceLauncher {
+
+ private static final String ENABLE_PREVIEW = "--enable-preview";
+ private static final String SOURCE = "--source";
+ private static final String CLASS_PATH = "--class-path";
+ private static final String CLASSPATH = "-classpath";
+ private static final String CP = "-cp";
+ private static final String MODULE_PATH = "--module-path";
+ private static final String P = "-p";
+
+ /**Returns {@code true} if and only if the given file is known as a
+ * file that is handled by a source file launcher. This, in particular,
+ * typically means the file is outside of a project.
+ *
+ * @param file the file to test
+ * @return {@code true} if and only if the file is known as a file handled by the
+ * source launcher. {@code false} otherwise.
+ */
+ public static boolean isSourceLauncherFile(FileObject file) {
+ MultiSourceRootProvider msrp = Lookup.getDefault().lookup(MultiSourceRootProvider.class);
+ return msrp != null && msrp.isSourceLauncher(file);
+ }
+
+ public static String joinCommandLines(Iterable<? extends String> inputLines) {
+ Map<String, String> joinedOptions = new HashMap<>();
+
+ for (String value : inputLines) {
+ List<String> args = SingleSourceFileUtil.parseLine(value);
+
+ for (int i = 0; i < args.size(); i++) {
+ switch (args.get(i)) {
+ case ENABLE_PREVIEW:
+ joinedOptions.put(ENABLE_PREVIEW, null);
+ break;
+ case CLASSPATH: case CLASS_PATH: case CP:
+ if (i + 1 < args.size()) {
+ joinedOptions.put(CLASS_PATH, mergePaths(joinedOptions.get(CLASS_PATH), args.get(i + 1)));
+ i++;
+ }
+ break;
+ case MODULE_PATH: case P:
+ if (i + 1 < args.size()) {
+ joinedOptions.put(MODULE_PATH, mergePaths(joinedOptions.get(MODULE_PATH), args.get(i + 1)));
+ i++;
+ }
+ break;
+ case SOURCE:
+ if (i + 1 < args.size()) {
+ String version = args.get(i + 1);
+ String testVersion = version;
+ if (testVersion.startsWith("1.")) {
+ testVersion = testVersion.substring(2);
+ }
+ String existingVersion = joinedOptions.get("--source");
Review Comment:
Fixed.
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,300 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.WeakHashMap;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
+import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation;
+import org.netbeans.spi.java.classpath.ClassPathFactory;
+import org.netbeans.spi.java.classpath.ClassPathImplementation;
+import static org.netbeans.spi.java.classpath.ClassPathImplementation.PROP_RESOURCES;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.PathResourceImplementation;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=9_999),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
+
+ //TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
+ private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> root2SourceCP = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2AllPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ClassPath = new WeakHashMap<>();
+ private Map<FileObject, ClassPath> file2ModulePath = new WeakHashMap<>();
+
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ switch (type) {
+ case ClassPath.SOURCE: return getSourcePath(file);
+ case ClassPath.COMPILE:
+ return attributeBasedPath(file, file2AllPath, "-classpath", "-cp", "--class-path", "--module-path", "-p");
+ case JavaClassPathConstants.MODULE_CLASS_PATH:
+ return attributeBasedPath(file, file2ClassPath, "-classpath", "-cp", "--class-path");
+ case JavaClassPathConstants.MODULE_COMPILE_PATH:
+ return attributeBasedPath(file, file2ModulePath, "--module-path", "-p");
+ case ClassPath.BOOT:
+ case JavaClassPathConstants.MODULE_BOOT_PATH:
+ return getBootPath(file);
+ }
+ return null;
+ }
+
+ private ClassPath getSourcePath(FileObject file) {
+ if (DISABLE_MULTI_SOURCE_ROOT) return null;
+ synchronized (this) {
+ //XXX: what happens if there's a Java file in user's home???
+ if (file.isData() && "text/x-java".equals(file.getMIMEType())) {
+ return file2SourceCP.computeIfAbsent(file, f -> {
+ try {
+ String content = new String(file.asBytes(), FileEncodingQuery.getEncoding(file));
+ String packName = findPackage(content);
+ FileObject root = file.getParent();
+
+ if (packName != null) {
+ List<String> packageParts = Arrays.asList(packName.split("\\."));
+
+ Collections.reverse(packageParts);
+
+ for (String packagePart : packageParts) {
+ if (!root.getNameExt().equalsIgnoreCase(packagePart)) {
+ //ignore files outside of proper package structure,
+ //those may too easily lead to using a too general
+ //directory as a root, leading to too much indexing:
+ return null;
+ }
+ root = root.getParent();
+ }
+ }
+
+ return root2SourceCP.computeIfAbsent(root, r -> { //XXX: weak....
+ ClassPath srcCP = ClassPathSupport.createClassPath(r);
+ GlobalPathRegistry.getDefault().register(ClassPath.SOURCE, new ClassPath[] {srcCP});
+ return srcCP;
+ });
+ } catch (IOException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ return null;
+ });
+ } else {
+ FileObject folder = file;
+
+ while (!folder.isRoot()) {
+ ClassPath cp = root2SourceCP.get(folder);
+
+ if (cp != null) {
+ return cp;
+ }
+
+ folder = folder.getParent();
+ }
+
+ return null;
+ }
+ }
+ }
+
+ private synchronized FileObject getSourceRootImpl(FileObject file) {
+ for (FileObject root : root2SourceCP.keySet()) {
+ if (FileUtil.isParentOf(root, file) || root.equals(file)) {
Review Comment:
Fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "mbien (via GitHub)" <gi...@apache.org>.
mbien commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1416481776
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java:
##########
@@ -68,15 +73,15 @@ static FileObject getJavaFileWithoutProjectFromLookup(Lookup lookup) {
return null;
}
- static boolean isSingleSourceFile(FileObject fObj) {
+ public static boolean isSingleSourceFile(FileObject fObj) {
Project p = FileOwnerQuery.getOwner(fObj);
if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
return false;
}
return true;
}
- static Process compileJavaSource(FileObject fileObject) {
+ public static Process compileJavaSource(FileObject fileObject) {
FileObject javac = JavaPlatformManager.getDefault().getDefaultPlatform().findTool("javac"); //NOI18N
Review Comment:
> I think I (and possibly others) are considering separating the runtime JDK and the JavaPlatform used by projects in VS Code extension. Maybe by changing the result of JavaPlatformManager.getDefaultPlatform().
yes but since free floating java files are not associated with a project, users can't even influence on which JDK they want to run the single/multi-file-java-program (SMFJP?). Which is independent of the default JDK vs nb runtime discussion. Controlling this over the default JDK is one way of doing this, but what if users don't want to run a file on the default JDK but on a specific JDK?
A JDK selector could be potentially added to the file properties, just like we have in maven/ant/gradle projects.

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1415171412
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/SingleSourceFileUtil.java:
##########
@@ -68,15 +73,15 @@ static FileObject getJavaFileWithoutProjectFromLookup(Lookup lookup) {
return null;
}
- static boolean isSingleSourceFile(FileObject fObj) {
+ public static boolean isSingleSourceFile(FileObject fObj) {
Project p = FileOwnerQuery.getOwner(fObj);
if (p != null || !fObj.getExt().equalsIgnoreCase("java")) { //NOI18N
return false;
}
return true;
}
- static Process compileJavaSource(FileObject fileObject) {
+ public static Process compileJavaSource(FileObject fileObject) {
FileObject javac = JavaPlatformManager.getDefault().getDefaultPlatform().findTool("javac"); //NOI18N
Review Comment:
I think I (and possibly others) are considering separating the runtime JDK and the JavaPlatform used by projects in VS Code extension. Maybe by changing the result of `JavaPlatformManager.getDefaultPlatform()`.
This is because the extension will/may require some relatively new JDK, but the projects may be developed for an older version.
I don't think anyone really tried that so far, though. (Jaroslav did some change in this direction for Maven long time ago, I think, but we need something more general.)
For source launcher, we could add a UI to select the JDK - it probably would not work in VS Code, but the same is true for JDK selection for other project types. If you want to look at that, you are of course welcome to. Or someone else might get to it, although I can't promise that, of course.
But I would prefer to avoid doing that here - this PR is complex enough on it own.
Thanks for the comment!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj merged PR #6329:
URL: https://github.com/apache/netbeans/pull/6329
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1409242306
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java:
##########
@@ -315,7 +316,10 @@ public void indexingComplete(Set<URL> indexedRoots) {
delegates = this.delegates.toArray(new TextDocumentServiceImpl[this.delegates.size()]);
}
for (TextDocumentServiceImpl delegate : delegates) {
- delegate.reRunDiagnostics();
+ ProxyLookup augmentedLookup = new ProxyLookup(Lookups.fixed(delegate.client), Lookup.getDefault());
+ Lookups.executeWith(augmentedLookup, () -> {
Review Comment:
Understood. My point was that this wrapper sets up "client" (remembered in the past) for the given TextDocumentServiceImpl instance; so eventually a server > client notification/request finds its target. But an eventual Progress API call made during the TextDocumentService processing (that assumes OperationContext) will not find its per-client data.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "sdedic (via GitHub)" <gi...@apache.org>.
sdedic commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1298285664
##########
java/java.api.common/src/org/netbeans/modules/java/api/common/queries/GenericModuleInfoAccessibilityQuery.java:
##########
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.api.common.queries;
+
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.DirectiveTree;
+import com.sun.source.tree.ExportsTree;
+import com.sun.source.tree.ModuleTree;
+import com.sun.source.tree.Tree.Kind;
+import com.sun.source.util.JavacTask;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.queries.AccessibilityQuery;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation;
+import org.netbeans.spi.java.queries.AccessibilityQueryImplementation2;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.RequestProcessor;
+import org.openide.util.RequestProcessor.Task;
+import org.openide.util.lookup.ServiceProvider;
+
+@ServiceProvider(service=AccessibilityQueryImplementation2.class)
+public class GenericModuleInfoAccessibilityQuery implements AccessibilityQueryImplementation2 {
+
+ private final Map<ClassPath, ClassPathListener> sourcePath2Listener = new WeakHashMap<>();
+ private final Map<FileObject, Result> path2Result = new WeakHashMap<>();
+
+ @Override
+ public Result isPubliclyAccessible(FileObject folder) {
+ return path2Result.computeIfAbsent(folder, f -> {
+ Project p = FileOwnerQuery.getOwner(f);
+ if (p != null && (p.getLookup().lookup(AccessibilityQueryImplementation2.class) != null ||
+ p.getLookup().lookup(AccessibilityQueryImplementation.class) != null)) {
+ //if there's a project-based AccessibilityQuery for this file, don't provide the generic results
+ return null;
+ }
+ ClassPath sourcePath = ClassPath.getClassPath(folder, ClassPath.SOURCE);
+ if (sourcePath == null) {
+ return null;
+ }
+ ClassPathListener cpl = sourcePath2Listener.computeIfAbsent(sourcePath, sp -> new ClassPathListener(sourcePath));
+ return new ResultImpl(cpl, sourcePath, folder);
+ });
+ }
+
+ private static final class ResultImpl implements Result, ChangeListener {
+
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final ClassPathListener listener;
+ private final Reference<ClassPath> sourcePath;
+ private final Reference<FileObject> folder;
+
+ public ResultImpl(ClassPathListener listener, ClassPath sourcePath, FileObject folder) {
+ this.listener = listener;
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.folder = new WeakReference<>(folder);
+ listener.addChangeListener(this);
+ }
+
+ @Override
+ public AccessibilityQuery.Accessibility getAccessibility() {
+ ClassPath sourcePath = this.sourcePath.get();
+ FileObject folder = this.folder.get();
+ Set<String> exported = listener.getExportedPackages();
+
+ if (sourcePath == null || folder == null || exported == null) {
+ return AccessibilityQuery.Accessibility.UNKNOWN;
+ }
+ String packageName = sourcePath.getResourceName(folder).replace('/', '.');
+ return exported.contains(packageName) ? AccessibilityQuery.Accessibility.EXPORTED
+ : AccessibilityQuery.Accessibility.PRIVATE;
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ cs.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ cs.removeChangeListener(listener);
+ }
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ cs.fireChange();
+ }
+
+ }
+
+ private static final class ClassPathListener implements PropertyChangeListener {
+
+ private static final RequestProcessor WORKER = new RequestProcessor(ClassPathListener.class.getName(), 1, false, false);
+ private static final int DELAY = 100;
+ private final ChangeSupport cs = new ChangeSupport(this);
+ private final AtomicReference<Set<String>> exportedPackages = new AtomicReference<>(null);
+ private final Reference<ClassPath> sourcePath;
+ private final Task parseTask;
+ private final Task rootsTask;
+ private final FileChangeAdapter folderListener = new FileChangeAdapter() {
+ @Override
+ public void fileDataCreated(FileEvent fe) {
+ if (fe.getFile().getNameExt().equalsIgnoreCase("module-info.java")) {
+ rootsTask.schedule(DELAY);
+ }
+ }
+ };
+ private final FileChangeAdapter moduleInfoListener = new FileChangeAdapter() {
+ @Override
+ public void fileChanged(FileEvent fe) {
+ parseTask.schedule(DELAY);
+ }
+ };
+
+ public ClassPathListener(ClassPath sourcePath) {
+ this.sourcePath = new WeakReference<>(sourcePath);
+ this.parseTask = WORKER.create(() -> {
+ FileObject moduleInfo = sourcePath.findResource("module-info.java");
+ Set<String> exported;
+
+ if (moduleInfo != null) {
+ exported = new HashSet<>();
+
+ try {
+ String code = moduleInfo.asText();
+ JavacTask compilerTask = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, Collections.singleton(new TextJFO(code, moduleInfo.toURI())));
+ CompilationUnitTree cut = compilerTask.parse().iterator().next();
+ ModuleTree mt = cut.getModule();
+ if (mt != null) {
+ for (DirectiveTree dt : mt.getDirectives()) {
+ if (dt.getKind() == Kind.EXPORTS) {
+ ExportsTree et = (ExportsTree) dt;
+ if (et.getModuleNames() == null || et.getModuleNames().isEmpty()) {
+ exported.add(et.getPackageName().toString());
+ }
+ }
+ }
+ }
+ } catch (IOException ex) {
+ //TODO: log
+ ex.printStackTrace();
+ }
+ } else {
+ exported = null;
+ }
+
+ exportedPackages.set(exported);
+ cs.fireChange();
+ });
+ sourcePath.addPropertyChangeListener(this);
+ rootsTask = WORKER.create(() -> {
+ ClassPath cp = ClassPathListener.this.sourcePath.get();
+ for (FileObject root : cp.getRoots()) {
Review Comment:
Null check `cp`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] Support for multi-file source launcher. [netbeans]
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1415177002
##########
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java:
##########
@@ -315,7 +316,10 @@ public void indexingComplete(Set<URL> indexedRoots) {
delegates = this.delegates.toArray(new TextDocumentServiceImpl[this.delegates.size()]);
}
for (TextDocumentServiceImpl delegate : delegates) {
- delegate.reRunDiagnostics();
+ ProxyLookup augmentedLookup = new ProxyLookup(Lookups.fixed(delegate.client), Lookup.getDefault());
+ Lookups.executeWith(augmentedLookup, () -> {
Review Comment:
Thanks - I've added this:
https://github.com/apache/netbeans/pull/6329/commits/40afb5565210f5535e55ca5153d42e19cbb06052
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1310387659
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/MultiSourceRootProvider.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.classpath.GlobalPathRegistry;
+import org.netbeans.api.java.classpath.JavaClassPathConstants;
+import org.netbeans.api.java.lexer.JavaTokenId;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.api.queries.FileEncodingQuery;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Exceptions;
+import org.openide.util.lookup.ServiceProvider;
+import org.openide.util.lookup.ServiceProviders;
+
+@ServiceProviders({
+ @ServiceProvider(service=ClassPathProvider.class, position=100_000),
+ @ServiceProvider(service=MultiSourceRootProvider.class)
+})
+public class MultiSourceRootProvider implements ClassPathProvider {
+
+ public static boolean DISABLE_MULTI_SOURCE_ROOT = false;
Review Comment:
Mostly for tests. But we can add a system property if desired.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1310365151
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/indexer/CompilerOptionsIndexer.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.indexer;
+
+import org.netbeans.modules.java.file.launcher.SharedRootData;
+import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.modules.parsing.spi.indexing.Context;
+import org.netbeans.modules.parsing.spi.indexing.CustomIndexer;
+import org.netbeans.modules.parsing.spi.indexing.CustomIndexerFactory;
+import org.netbeans.modules.parsing.spi.indexing.Indexable;
+
+/**
+ *
+ * @author lahvac
+ */
+public class CompilerOptionsIndexer extends CustomIndexer {
+
+
+ @Override
+ protected void index(Iterable<? extends Indexable> files, Context context) {
+ if (FileOwnerQuery.getOwner(context.getRoot()) != null) {
+ return ; //ignore roots under projects
+ }
+ SharedRootData.ensureRootRegistered(context.getRoot());
+ }
+
+
+ @MimeRegistration(mimeType="text/x-java", service=CustomIndexerFactory.class, position=1_000)
+ public static final class FactoryImpl extends CustomIndexerFactory {
+
+ @Override
+ public CustomIndexer createIndexer() {
+ return new CompilerOptionsIndexer();
+ }
+
+ @Override
+ public boolean supportsEmbeddedIndexers() {
+ return true;
+ }
+
+ @Override
+ public void filesDeleted(Iterable<? extends Indexable> deleted, Context context) {
+ //TODO:
Review Comment:
Will be handled on a different place.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] lahodaj commented on a diff in pull request #6329: Support for multi-file source launcher.
Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on code in PR #6329:
URL: https://github.com/apache/netbeans/pull/6329#discussion_r1310373699
##########
java/java.file.launcher/src/org/netbeans/modules/java/file/launcher/queries/LauncherSourceLevelQueryImpl.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.java.file.launcher.queries;
+
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.java.platform.JavaPlatformManager;
+import org.netbeans.modules.java.file.launcher.SharedRootData;
+import org.netbeans.spi.java.queries.SourceLevelQueryImplementation2;
+import org.openide.*;
+import org.openide.filesystems.FileObject;
+import org.openide.util.ChangeSupport;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ *
+ * @author lahvac
+ */
+@ServiceProvider(service=SourceLevelQueryImplementation2.class, position=9_999)
+public class LauncherSourceLevelQueryImpl implements SourceLevelQueryImplementation2 {
+
+ @Override
+ public Result getSourceLevel(FileObject javaFile) {
+ //for files, DefaultSourceLevelQueryImpl will respond:
+ if (javaFile.isFolder()) {
Review Comment:
This will only be called (I hope!) if the `ProjectSourceLevelQueryImpl2` will not answer. And SharedData should not be present for files under projects. And `FOQ` will do the same traversing up the file path. So, going through the parents does not seem to do any harm.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists