From 79ea9c910cbae7e65b2338bcaf18a0b815f0163b Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Sun, 5 Oct 2025 06:31:33 +0200 Subject: [PATCH 1/4] Make sure netbeans in terminal means itself --- .../terminal/action/TerminalSupportImpl.java | 13 ++++--- nb/ide.launcher/unix/netbeans | 13 ++++++- nb/ide.launcher/windows/nblauncher.cpp | 34 +++++++++++++++-- nb/ide.launcher/windows/nblauncher.h | 2 +- nb/ide.launcher/windows/netbeans.exe.manifest | 2 +- .../windows/netbeans64.exe.manifest | 2 +- nb/ide.launcher/windows/version.h | 6 +-- nb/o.n.upgrader/arch.xml | 37 +++++++++++++++++++ 8 files changed, 92 insertions(+), 17 deletions(-) diff --git a/ide/dlight.terminal/src/org/netbeans/modules/dlight/terminal/action/TerminalSupportImpl.java b/ide/dlight.terminal/src/org/netbeans/modules/dlight/terminal/action/TerminalSupportImpl.java index 8f3229d5e3b6..a1dbff1fc69d 100644 --- a/ide/dlight.terminal/src/org/netbeans/modules/dlight/terminal/action/TerminalSupportImpl.java +++ b/ide/dlight.terminal/src/org/netbeans/modules/dlight/terminal/action/TerminalSupportImpl.java @@ -72,6 +72,7 @@ import org.openide.windows.OutputWriter; import static org.netbeans.lib.terminalemulator.Term.ExternalCommandsConstants.*; +import org.netbeans.modules.nativeexecution.api.util.MacroMap; /** * @@ -267,14 +268,14 @@ private void doWork() { term.setEmulation("xterm"); // NOI18N NativeProcessBuilder npb = NativeProcessBuilder.newProcessBuilder(env); + final MacroMap envVars = npb.getEnvironment(); // clear env modified by NB. Let it be initialized by started shell process - npb.getEnvironment().put("LD_LIBRARY_PATH", "");// NOI18N - npb.getEnvironment().put("DYLD_LIBRARY_PATH", "");// NOI18N - + envVars.put("LD_LIBRARY_PATH", "");// NOI18N + envVars.put("DYLD_LIBRARY_PATH", "");// NOI18N if (hostInfo.getOSFamily() == HostInfo.OSFamily.WINDOWS) { // /etc/profile changes directory to ${HOME} if this // variable is not set. - npb.getEnvironment().put("CHERE_INVOKING", "1");// NOI18N + envVars.put("CHERE_INVOKING", "1");// NOI18N } final TerminalPinSupport support = TerminalPinSupport.getDefault(); @@ -305,8 +306,8 @@ private void doWork() { final String promptCommand = "printf \"\033]3;${PWD}\007\"; " // NOI18N + IDE_OPEN + "() { printf \"\033]10;" + COMMAND_PREFIX + IDE_OPEN + " $*;\007\"; printf \"Opening $# file(s) ...\n\";}"; // NOI18N final String commandName = "PROMPT_COMMAND"; // NOI18N - String usrPrompt = npb.getEnvironment().get(commandName); - npb.getEnvironment().put(commandName, + String usrPrompt = envVars.get(commandName); + envVars.put(commandName, (usrPrompt == null) ? promptCommand : promptCommand + ';' + usrPrompt diff --git a/nb/ide.launcher/unix/netbeans b/nb/ide.launcher/unix/netbeans index d92b25288a66..f2ea7bd2a57e 100644 --- a/nb/ide.launcher/unix/netbeans +++ b/nb/ide.launcher/unix/netbeans @@ -65,8 +65,17 @@ fi export DEFAULT_USERDIR_ROOT +if ! [ "$NETBEANS_USERDIR" = "nope" ]; then + # make sure own launcher directory is on PATH as a fallback + PATH=$PATH:$progdir +fi + # #68373: look for userdir, but do not modify "$@" -userdir="${netbeans_default_userdir}" +if [ -z "$NETBEANS_USERDIR" ]; then + userdir="${netbeans_default_userdir}" +else + userdir="$NETBEANS_USERDIR" +fi cachedir="${netbeans_default_cachedir}" founduserdir="" @@ -138,6 +147,8 @@ launchNbexec() { then sh=/bin/bash fi + NETBEANS_USERDIR=${userdir} + export NETBEANS_USERDIR if [ "${founduserdir}" = "yes" ]; then exec $sh "$nbexec" "$@" else diff --git a/nb/ide.launcher/windows/nblauncher.cpp b/nb/ide.launcher/windows/nblauncher.cpp index 653940971a3b..082aaf8e438a 100644 --- a/nb/ide.launcher/windows/nblauncher.cpp +++ b/nb/ide.launcher/windows/nblauncher.cpp @@ -34,6 +34,7 @@ using namespace std; const char *NbLauncher::NBEXEC_FILE_PATH = NBEXEC_DLL; +const char *ENV_NETBEANS_USERDIR="NETBEANS_USERDIR"; const char *NbLauncher::OPT_NB_DEFAULT_USER_DIR = "netbeans_default_userdir="; const char *NbLauncher::OPT_NB_DEFAULT_CACHE_DIR = "netbeans_default_cachedir="; const char *NbLauncher::OPT_NB_DEFAULT_OPTIONS = "netbeans_default_options="; @@ -82,13 +83,26 @@ int NbLauncher::start(int argc, char *argv[]) { return -1; } - parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str()); + bool skipUserDir = false; + char *userDirViaEnv = getenv(ENV_NETBEANS_USERDIR); + if (userDirViaEnv != NULL) { + logMsg("NbLauncher::using NETBEANS_USERDIR env variable (%s)", userDirViaEnv); + string udve = userDirViaEnv; + if (udve == "nope") { + skipUserDir = true; + userDirViaEnv = NULL; + } else { + userDir = userDirViaEnv; + } + } + + parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str(), userDirViaEnv == NULL); if (!parseArgs(argc, argv)) { return -1; } string oldUserDir = userDir; - parseConfigFile((userDir + "\\etc\\" + getAppName() + ".conf").c_str()); + parseConfigFile((userDir + "\\etc\\" + getAppName() + ".conf").c_str(), userDirViaEnv == NULL); userDir = oldUserDir; addExtraClusters(); @@ -114,6 +128,18 @@ int NbLauncher::start(int argc, char *argv[]) { if (!userDir.empty()) { newArgs.add(ARG_NAME_USER_DIR); newArgs.add(userDir.c_str()); + if (!skipUserDir) { + string toSet = ENV_NETBEANS_USERDIR; + toSet = toSet + "=" + userDir; + putenv(toSet.c_str()); + + const char* path = getenv("PATH"); + if (path != NULL) { + string setPath = "PATH="; + setPath = setPath + path + ";" + baseDir + "\\bin\\"; + putenv(setPath.c_str()); + } + } } if (!defUserDirRoot.empty()) { newArgs.add(ARG_DEFAULT_USER_DIR_ROOT); @@ -460,7 +486,7 @@ bool NbLauncher::getOption(char *&str, const char *opt) { return false; } -bool NbLauncher::parseConfigFile(const char* path) { +bool NbLauncher::parseConfigFile(const char* path, const bool searchUserDir) { logMsg("parseConfigFile(%s)", path); FILE *file = fopen(path, "r"); if (!file) { @@ -474,7 +500,7 @@ bool NbLauncher::parseConfigFile(const char* path) { if (*str == '#') { continue; } - if (getOption(str, getDefUserDirOptName())) { + if (searchUserDir && getOption(str, getDefUserDirOptName())) { findUserDir(str); logMsg("User dir: %s", userDir.c_str()); } else if (getOption(str, getDefCacheDirOptName())) { diff --git a/nb/ide.launcher/windows/nblauncher.h b/nb/ide.launcher/windows/nblauncher.h index f2934ea0394e..c3d25f827cc5 100644 --- a/nb/ide.launcher/windows/nblauncher.h +++ b/nb/ide.launcher/windows/nblauncher.h @@ -80,7 +80,7 @@ class NbLauncher { NbLauncher(const NbLauncher& orig); bool readClusterFile(); bool parseArgs(int argc, char *argv[]); - bool parseConfigFile(const char* path); + bool parseConfigFile(const char* path, const bool searchUserDir); bool getOption(char *&str, const char *opt); void addCluster(const char *cl); void addExtraClusters(); diff --git a/nb/ide.launcher/windows/netbeans.exe.manifest b/nb/ide.launcher/windows/netbeans.exe.manifest index 554f74f3e958..1202515168d7 100644 --- a/nb/ide.launcher/windows/netbeans.exe.manifest +++ b/nb/ide.launcher/windows/netbeans.exe.manifest @@ -20,7 +20,7 @@ --> - diff --git a/nb/ide.launcher/windows/netbeans64.exe.manifest b/nb/ide.launcher/windows/netbeans64.exe.manifest index e06169128842..ca649006938f 100644 --- a/nb/ide.launcher/windows/netbeans64.exe.manifest +++ b/nb/ide.launcher/windows/netbeans64.exe.manifest @@ -22,7 +22,7 @@ - diff --git a/nb/ide.launcher/windows/version.h b/nb/ide.launcher/windows/version.h index 6394da52b453..d59e02aacf79 100644 --- a/nb/ide.launcher/windows/version.h +++ b/nb/ide.launcher/windows/version.h @@ -19,9 +19,9 @@ #define COMPANY "" #define COMPONENT "Apache NetBeans IDE Launcher" -#define VER "101.3.0.0" -#define FVER 101,3,0,0 -#define BUILD_ID "101300" +#define VER "101.4.0.0" +#define FVER 101,4,0,0 +#define BUILD_ID "101400" #define INTERNAL_NAME "netbeans" #define COPYRIGHT "Based on Apache NetBeans from the Apache Software Foundation and is licensed under Apache License Version 2.0" #define NAME "Apache NetBeans IDE Launcher" diff --git a/nb/o.n.upgrader/arch.xml b/nb/o.n.upgrader/arch.xml index fa19f78c3c57..49d8df517d01 100644 --- a/nb/o.n.upgrader/arch.xml +++ b/nb/o.n.upgrader/arch.xml @@ -621,6 +621,43 @@ clusters' fully qualified paths separated by path.separator (semicolon on Windows, colon on Unices) +

+ When the netbeans launcher starts, it also manipulates + (reads and writes) following properties: +

+
    +
  • +

    + If this environment variable is set to a valid value, + then its value is used as default user dir + instead of netbeans_default_userdir read from + the config file. +

    +

    + When the value of user dir is finally determined by the launcher + (by considering default values, value of this environment variable + and --userdir CLI switch, etc.) the launcher sets + NETBEANS_USERDIR environment variable for itself + and its subprocesses. +

    +

    + That way executing netbeans in the NetBeans internal + terminal will know what's the userdir of the surrouding NetBeans + and will open files in the same instance just as + #8756 illustrates. +

    +

    + The launcher also modifies the PATH variable + by appending its own diretory - making sure typing netbeans + gets handled in the internal NetBeans terminal at all. + In the unusual and rare cases when opt-out of this + behavior maybe needed, just + set the environment variable to nope to instruct + the launcher to avoid these environment variable modifications. +

    +
    +
  • +
From 1e13163dd9ae0f9dcb91fbf2cc0404815589b0ff Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Thu, 9 Oct 2025 11:39:17 +0200 Subject: [PATCH 2/4] Using IGNORE instead of nope --- nb/ide.launcher/unix/netbeans | 2 +- nb/ide.launcher/windows/nblauncher.cpp | 2 +- nb/o.n.upgrader/arch.xml | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/nb/ide.launcher/unix/netbeans b/nb/ide.launcher/unix/netbeans index f2ea7bd2a57e..548ca6c4ab69 100644 --- a/nb/ide.launcher/unix/netbeans +++ b/nb/ide.launcher/unix/netbeans @@ -65,7 +65,7 @@ fi export DEFAULT_USERDIR_ROOT -if ! [ "$NETBEANS_USERDIR" = "nope" ]; then +if ! [ "$NETBEANS_USERDIR" = "IGNORE" ]; then # make sure own launcher directory is on PATH as a fallback PATH=$PATH:$progdir fi diff --git a/nb/ide.launcher/windows/nblauncher.cpp b/nb/ide.launcher/windows/nblauncher.cpp index 082aaf8e438a..999a71eadcf4 100644 --- a/nb/ide.launcher/windows/nblauncher.cpp +++ b/nb/ide.launcher/windows/nblauncher.cpp @@ -88,7 +88,7 @@ int NbLauncher::start(int argc, char *argv[]) { if (userDirViaEnv != NULL) { logMsg("NbLauncher::using NETBEANS_USERDIR env variable (%s)", userDirViaEnv); string udve = userDirViaEnv; - if (udve == "nope") { + if (udve == "IGNORE") { skipUserDir = true; userDirViaEnv = NULL; } else { diff --git a/nb/o.n.upgrader/arch.xml b/nb/o.n.upgrader/arch.xml index 49d8df517d01..b2b6e3a8aa2e 100644 --- a/nb/o.n.upgrader/arch.xml +++ b/nb/o.n.upgrader/arch.xml @@ -647,13 +647,13 @@ #8756 illustrates.

- The launcher also modifies the PATH variable - by appending its own diretory - making sure typing netbeans - gets handled in the internal NetBeans terminal at all. - In the unusual and rare cases when opt-out of this - behavior maybe needed, just - set the environment variable to nope to instruct - the launcher to avoid these environment variable modifications. + The launcher also modifies the PATH variable + by appending its own diretory - making sure typing netbeans + gets handled in the internal NetBeans terminal at all. + In the unusual and rare cases when opt-out of this + behavior maybe needed, just + set the environment variable to IGNORE to instruct + the launcher to avoid these environment variable modifications.

From b0a20a223392ab937ca074b75a58529fd7c40a7e Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Thu, 9 Oct 2025 03:22:38 -0700 Subject: [PATCH 3/4] On Cygwin immediately invoke netbeans64.exe or netbeans.exe --- nb/ide.launcher/unix/netbeans | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nb/ide.launcher/unix/netbeans b/nb/ide.launcher/unix/netbeans index 548ca6c4ab69..192277b01731 100644 --- a/nb/ide.launcher/unix/netbeans +++ b/nb/ide.launcher/unix/netbeans @@ -38,12 +38,18 @@ cd "$progdir"/.. basedir=`pwd` cd "$old" -case "`uname`" in +case "`uname -s -m`" in Darwin*) # set default userdir and cachedir on Mac OS X DEFAULT_USERDIR_ROOT="${HOME}/Library/Application Support/NetBeans" DEFAULT_CACHEDIR_ROOT=${HOME}/Library/Caches/NetBeans ;; + CYGWIN*_64) + exec $progdir/netbeans64.exe $* + ;; + CYGWIN*) + exec $progdir/netbeans.exe $* + ;; *) # set default userdir and cachedir on unix systems DEFAULT_USERDIR_ROOT=${HOME}/.netbeans From 54edd84bc2fae331afbf1b672de0b0f6be6db387 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Fri, 10 Oct 2025 08:54:04 +0200 Subject: [PATCH 4/4] Shield against space in path --- nb/ide.launcher/unix/netbeans | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nb/ide.launcher/unix/netbeans b/nb/ide.launcher/unix/netbeans index 192277b01731..c05a24486457 100644 --- a/nb/ide.launcher/unix/netbeans +++ b/nb/ide.launcher/unix/netbeans @@ -45,11 +45,11 @@ case "`uname -s -m`" in DEFAULT_CACHEDIR_ROOT=${HOME}/Library/Caches/NetBeans ;; CYGWIN*_64) - exec $progdir/netbeans64.exe $* - ;; + exec "$progdir/netbeans64.exe" $* + ;; CYGWIN*) - exec $progdir/netbeans.exe $* - ;; + exec "$progdir/netbeans.exe" $* + ;; *) # set default userdir and cachedir on unix systems DEFAULT_USERDIR_ROOT=${HOME}/.netbeans