diff --git a/harness/apisupport.harness/windows-launcher-src/applauncher.cpp b/harness/apisupport.harness/windows-launcher-src/applauncher.cpp index f8163168ce66..9b17d9cd8c62 100644 --- a/harness/apisupport.harness/windows-launcher-src/applauncher.cpp +++ b/harness/apisupport.harness/windows-launcher-src/applauncher.cpp @@ -74,6 +74,10 @@ bool AppLauncher::initBaseNames() { return true; } +const char* AppLauncher::findUserDirViaEnvVar() { + return "IGNORE"; +} + bool AppLauncher::findUserDir(const char *str) { logMsg("AppLauncher::findUserDir()"); if (!NbLauncher::findUserDir(str)) { // will set userDir and possibly userHome. diff --git a/harness/apisupport.harness/windows-launcher-src/applauncher.h b/harness/apisupport.harness/windows-launcher-src/applauncher.h index 0801c8a316c1..93e2f3f0fce2 100644 --- a/harness/apisupport.harness/windows-launcher-src/applauncher.h +++ b/harness/apisupport.harness/windows-launcher-src/applauncher.h @@ -51,6 +51,7 @@ class AppLauncher : public NbLauncher { virtual void adjustHeapSize(); virtual bool findUserDir(const char *str); virtual bool findCacheDir(const char *str); + virtual const char* findUserDirViaEnvVar(); virtual const char * getDefUserDirOptName(); virtual const char * getDefCacheDirOptName(); virtual const char * getDefOptionsOptName(); 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 52097b2f28a5..c584d3024379 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; /** * @@ -270,14 +271,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(); @@ -308,8 +309,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..097b83c916ce 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 @@ -65,8 +71,17 @@ fi export DEFAULT_USERDIR_ROOT +if ! [ "$NETBEANS_USERDIR" = "IGNORE" ]; 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 +153,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..fbe3c88effd0 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="; @@ -74,6 +75,10 @@ int NbLauncher::start(char *cmdLine) { return start(args.getCount(), args.getArgs()); } +const char* NbLauncher::findUserDirViaEnvVar() { + return getenv(ENV_NETBEANS_USERDIR); +} + int NbLauncher::start(int argc, char *argv[]) { SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX); @@ -82,13 +87,26 @@ int NbLauncher::start(int argc, char *argv[]) { return -1; } - parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str()); + bool skipUserDir = false; + const char *userDirViaEnv = findUserDirViaEnvVar(); + if (userDirViaEnv != NULL) { + logMsg("NbLauncher::using NETBEANS_USERDIR env variable (%s)", userDirViaEnv); + string udve = userDirViaEnv; + if (udve == "IGNORE") { + 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 +132,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 +490,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 +504,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..440cc5ed0bf0 100644 --- a/nb/ide.launcher/windows/nblauncher.h +++ b/nb/ide.launcher/windows/nblauncher.h @@ -66,6 +66,7 @@ class NbLauncher { virtual bool initBaseNames(); virtual void addSpecificOptions(CmdArgs &args); virtual bool findUserDir(const char *str); + virtual const char* findUserDirViaEnvVar(); virtual bool findCacheDir(const char *str); virtual const char * getAppName(); virtual const char * getDefUserDirOptName(); @@ -80,7 +81,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..b2b6e3a8aa2e 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 IGNORE to instruct + the launcher to avoid these environment variable modifications. +

    +
    +
  • +