netbeans
netbeans copied to clipboard
Support for relative paths in the source file launcher's paths; automatic expanding of modular paths.
The VS Code extension supports the (multi-)source file launcher using the RUN CONFIGURATION explorer tab. One can specify the command line options, which are then used when starting a file in the workspace.
There are a few problems with that:
- options like
-classpathcould contain relative paths, but NB will not resolve them - the default working directory is weird - it is the directory in which the file-to-run resides. That made sense for single-source launcher, but not anymore. And while runtime will resolve relative paths, it will resolve them to this weird working directory
- for
--module-path, the elements specified may be modules, or a directory, which contains the modules. But NB will only see module path which contains modules, and will not resolve modules inside the specified directory
This patch:
- when needed, computes "relevant" default working directory for files - it is a) the workspace folder that encloses the given file (which should be the common case), or, if that fails to find a workspace folder b) the workspace folder that is enclosed by the file's source root (for the case where the user opens just a part of the source root)
- this relevant default working directory is then used as the working directory, unless overridden by the user
- the working directory (either computed as above, or explicit) is used the base to resolve relative paths
- when a module path contains a directory which does not contain
module-info.class, it is interpreted as a directory consisting of a collection of modules, and will expand the module path to include these modules. This includes listening on the directory content, and updates to the module path when the content changes
FWIW, see: https://github.com/oracle/javavscode/issues/74
feel free to ignore the failing macos fs test. It tests things which the file system impl doesn't guarantee - we have to fix this at some point / clean up the fs tests in general, since the macos test isn't even platform specific.
Looking forward to test-drive this feature! 🤓
Unless there are objections, I'll integrate once/if tests will pass.
I saw this exception twice in CI logs of this PR: https://github.com/apache/netbeans/actions/runs/9366885368/attempts/1 https://github.com/apache/netbeans/actions/runs/9319212924/attempts/1
I don't remember this being a common failure. (CV tests on linux typically don't need retries) edit: looking further into this, this seems to be cross platform, I see the same exception on win, mac and linux and I can't find it in CI runs of the master branch.
@lahodaj do you think this relates to the changes made here?
NbModuleSuite has been started with failOnMessage(OFF) and failOnException(INFO). The following failures have been captured:
[org.openide.util.RequestProcessor] THREAD: org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider MSG: Error in RequestProcessor org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider$AttributeBasedClassPathImplementation$$Lambda$428/0x0000000400a262c8
org.openide.util.RequestProcessor$FastItem: java.lang.NullPointerException: Cannot invoke "java.util.concurrent.atomic.AtomicReference.get()" because "this.processorModulePath" is null
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.concurrent.atomic.AtomicReference.get()" because "this.processorModulePath" is null
org.netbeans.modules.java.source.indexing.APTUtils.validatePaths(APTUtils.java:348)
org.netbeans.modules.java.source.indexing.APTUtils.verifyAttributes(APTUtils.java:452)
org.netbeans.modules.java.source.indexing.APTUtils.stateChanged(APTUtils.java:307)
org.netbeans.modules.java.source.indexing.APTUtils.propertyChange(APTUtils.java:316)
java.desktop/java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:343)
java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:335)
org.netbeans.api.java.classpath.ClassPath.firePropertyChange(ClassPath.java:691)
org.netbeans.api.java.classpath.ClassPath$SPIListener.propertyChange(ClassPath.java:1328)
org.openide.util.WeakListenerImpl$PropertyChange.propertyChange(WeakListenerImpl.java:189)
java.desktop/java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:343)
java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:335)
java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:268)
org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider$AttributeBasedClassPathImplementation.doUpdateDelegates(MultiSourceRootProvider.java:371)
org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1420)
org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
org.openide.util.lookup.Lookups.executeWith(Lookups.java:287)
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2035)
I saw this exception twice in CI logs of this PR: https://github.com/apache/netbeans/actions/runs/9366885368/attempts/1 https://github.com/apache/netbeans/actions/runs/9319212924/attempts/1
I don't remember this being a common failure. (CV tests on linux typically don't need retries) edit: looking further into this, this seems to be cross platform, I see the same exception on win, mac and linux and I can't find it in CI runs of the master branch.
@lahodaj do you think this relates to the changes made here?
NbModuleSuite has been started with failOnMessage(OFF) and failOnException(INFO). The following failures have been captured: [org.openide.util.RequestProcessor] THREAD: org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider MSG: Error in RequestProcessor org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider$AttributeBasedClassPathImplementation$$Lambda$428/0x0000000400a262c8 org.openide.util.RequestProcessor$FastItem: java.lang.NullPointerException: Cannot invoke "java.util.concurrent.atomic.AtomicReference.get()" because "this.processorModulePath" is null Caused by: java.lang.NullPointerException: Cannot invoke "java.util.concurrent.atomic.AtomicReference.get()" because "this.processorModulePath" is null org.netbeans.modules.java.source.indexing.APTUtils.validatePaths(APTUtils.java:348) org.netbeans.modules.java.source.indexing.APTUtils.verifyAttributes(APTUtils.java:452) org.netbeans.modules.java.source.indexing.APTUtils.stateChanged(APTUtils.java:307) org.netbeans.modules.java.source.indexing.APTUtils.propertyChange(APTUtils.java:316) java.desktop/java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:343) java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:335) org.netbeans.api.java.classpath.ClassPath.firePropertyChange(ClassPath.java:691) org.netbeans.api.java.classpath.ClassPath$SPIListener.propertyChange(ClassPath.java:1328) org.openide.util.WeakListenerImpl$PropertyChange.propertyChange(WeakListenerImpl.java:189) java.desktop/java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:343) java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:335) java.desktop/java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:268) org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider$AttributeBasedClassPathImplementation.doUpdateDelegates(MultiSourceRootProvider.java:371) org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1420) org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45) org.openide.util.lookup.Lookups.executeWith(Lookups.java:287) org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2035)
Hmm, I think there's surely a latent bug in APTUtils - it starts to listen before the fields are initialized, so if the even arrives quickly, it may cause issues. The thing that might have change here is that now the event might realistically arrive. I've tried to improve the listening here:
https://github.com/apache/netbeans/pull/7382/commits/3e47c08121e60aa7a972a7b791b8fd9a6b387a7e
Let's see how that goes.
@lahodaj thanks! this looks much better. The retry script didn't trigger for the CV tests in this run which is a good sign. (I am not counting the mac networking test since this is a separate issue https://github.com/apache/netbeans/pull/7410)
this seems to be causing an exceptions when the code formatting options are opened (e.g via options dialog or project properties window):
SEVERE [org.openide.util.RequestProcessor]: Error in RequestProcessor org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider$AttributeBasedClassPathImplementation$$Lambda/0x00007fbde7e949a8
java.lang.IllegalArgumentException: URI scheme is not "file"
at java.base/java.io.File.<init>(File.java:423)
at org.openide.util.BaseUtilities.toFile(BaseUtilities.java:1617)
at org.openide.util.Utilities.toFile(Utilities.java:2174)
at org.netbeans.modules.java.file.launcher.queries.MultiSourceRootProvider$AttributeBasedClassPathImplementation.doUpdateDelegates(MultiSourceRootProvider.java:302)
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)
filled https://github.com/apache/netbeans/issues/7508 so that we don't forget about this