Skip to content

Conversation

@jtulach
Copy link
Contributor

@jtulach jtulach commented Nov 10, 2025

If you invoke the launcher with a relative path, that relative path is set to NETBEANS_USERDIR. The moment you change the local directory in the terminal this invalidates the reference as now the relative path resolves to a different directory.
On Linux invoked as ./nbbuild/netbeans/bin/netbeans --userdir x we used to get:

Image

This PR "absolutizes" both paths. The NETBEANS_USERDIR as well as the path to the bin directory.

absolute path

Gets printed in the NetBeans terminal window now.

@neilcsmith-net
Copy link
Member

I have a concern that this is done in a different way to how other paths are absolutized in the launcher script. I also don't think we can rely on realpath being available on all platforms we might want to support - eg. it's in latest macOS but not all the versions supported by current JDKs. If I'm reading correctly it was added to the POSIX standard in 2024.

@matthiasblaesing
Copy link
Contributor

matthiasblaesing commented Nov 11, 2025

@jtulach please have a look at this code:

old=`pwd`
cd "$progdir"/..
basedir=`pwd`
cd "$old"

I think this is what @neilcsmith-net meant by "a different way to how other paths are absolutized". My understanding is, that this saves the current directory into variable old, then cds to the path denoted by parent of $progdir. Invoking pwd will now give you the path when the parent of $progdir is resolved against the current directory. That value is stored into $basedir for later usage. As we are now at the wrong location in the directory tree, we cd back into the start directory (using the value from $old).

This might not be the most efficient way, but it looks sane to me and is small enough to be copyable (IMHO).

As a test you can create resolve.sh like this:

#!/bin/bash

old=`pwd`
cd "$1"
resolved=`pwd`
cd "$old"

echo "Resolved path: '$resolved'";

In my test session my shell is opened in /home/matthias/test, now I get:

matthias@enterprise:~/test$ resolve.sh ../tmp/yubikey\ pkcs11\ broken/src/
Resolved path: '/home/matthias/tmp/yubikey pkcs11 broken/src'
matthias@enterprise:~/test$

Which is the expected answer.

@neilcsmith-net
Copy link
Member

There is also -

absolutize_paths() {
while read path; do
if [ -d "$path" ]; then
(cd "$path" 2>/dev/null && pwd)
else
echo "$path"
fi
done
}

@jtulach
Copy link
Contributor Author

jtulach commented Nov 16, 2025

  • I was using the latest master build of NetBeans on my Mac for a week and yes, this relative paths issue is a problem

realpath ... was added to the POSIX standard in 2024
@neilcsmith-net wrote: there also is absolutize_paths

  • yes, introducing new dependency on realpath didn't feel quite right
  • reusing existing code that does the trick makes me feel 99.9% safe

@matthiasblaesing wrote: basedir computation ... looks sane to me and is small enough to be copyable

  • I wasn't aware of absolute_paths even I should have been ...
  • with the discovery of existence of absolute_paths we could even reuse the code when computing basedir:
netbeans$ git diff
diff --git nb/ide.launcher/unix/netbeans nb/ide.launcher/unix/netbeans
index 3f65db67a3..a62ff77da3 100644
--- nb/ide.launcher/unix/netbeans
+++ nb/ide.launcher/unix/netbeans
@@ -33,10 +33,6 @@ while [ -h "$PRG" ]; do
 done
 
 progdir=`dirname "$PRG"`
-old=`pwd`
-cd "$progdir"/..
-basedir=`pwd`
-cd "$old"
 
 case "`uname -s -m`" in
     Darwin*)
@@ -68,6 +64,7 @@ absolutize_paths() {
 }
 
 # $HOME can be used as it is present on mac OS and
+basedir=`echo "$progdir"/.. | absolutize_paths`
 BASEDIR=$basedir
 
 if [ -f "$basedir"/etc/netbeans.conf ] ; then
  • such a change isn't part of this PR yet (I try to avoid changing something that works)
  • but I can include it, if it passes your review

Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. Looks sane to me. Did a quick local run and both PATH and NETBEANS_USERDIR have absolute paths.

@jtulach jtulach changed the title Use realpath to absolutize relative paths Use absolutize_paths to make userdir and path absolute Nov 17, 2025
@jtulach jtulach changed the title Use absolutize_paths to make userdir and path absolute Use absolutize_paths to make userdir and path absolute Nov 17, 2025
@jtulach jtulach merged commit 3521265 into apache:master Nov 17, 2025
30 checks passed
@mbien mbien added this to the NB29 milestone Nov 17, 2025
@jtulach
Copy link
Contributor Author

jtulach commented Dec 19, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants