Skip to content

Commit 8e2bc77

Browse files
authored
#8756: Make sure netbeans in embedded terminal means itself
2 parents d0afe36 + b188f09 commit 8e2bc77

File tree

10 files changed

+109
-18
lines changed

10 files changed

+109
-18
lines changed

harness/apisupport.harness/windows-launcher-src/applauncher.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ bool AppLauncher::initBaseNames() {
7474
return true;
7575
}
7676

77+
const char* AppLauncher::findUserDirViaEnvVar() {
78+
return "IGNORE";
79+
}
80+
7781
bool AppLauncher::findUserDir(const char *str) {
7882
logMsg("AppLauncher::findUserDir()");
7983
if (!NbLauncher::findUserDir(str)) { // will set userDir and possibly userHome.

harness/apisupport.harness/windows-launcher-src/applauncher.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class AppLauncher : public NbLauncher {
5151
virtual void adjustHeapSize();
5252
virtual bool findUserDir(const char *str);
5353
virtual bool findCacheDir(const char *str);
54+
virtual const char* findUserDirViaEnvVar();
5455
virtual const char * getDefUserDirOptName();
5556
virtual const char * getDefCacheDirOptName();
5657
virtual const char * getDefOptionsOptName();

ide/dlight.terminal/src/org/netbeans/modules/dlight/terminal/action/TerminalSupportImpl.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.openide.windows.OutputWriter;
7373

7474
import static org.netbeans.lib.terminalemulator.Term.ExternalCommandsConstants.*;
75+
import org.netbeans.modules.nativeexecution.api.util.MacroMap;
7576

7677
/**
7778
*
@@ -270,14 +271,14 @@ private void doWork() {
270271
term.setEmulation("xterm"); // NOI18N
271272

272273
NativeProcessBuilder npb = NativeProcessBuilder.newProcessBuilder(env);
274+
final MacroMap envVars = npb.getEnvironment();
273275
// clear env modified by NB. Let it be initialized by started shell process
274-
npb.getEnvironment().put("LD_LIBRARY_PATH", "");// NOI18N
275-
npb.getEnvironment().put("DYLD_LIBRARY_PATH", "");// NOI18N
276-
276+
envVars.put("LD_LIBRARY_PATH", "");// NOI18N
277+
envVars.put("DYLD_LIBRARY_PATH", "");// NOI18N
277278
if (hostInfo.getOSFamily() == HostInfo.OSFamily.WINDOWS) {
278279
// /etc/profile changes directory to ${HOME} if this
279280
// variable is not set.
280-
npb.getEnvironment().put("CHERE_INVOKING", "1");// NOI18N
281+
envVars.put("CHERE_INVOKING", "1");// NOI18N
281282
}
282283

283284
final TerminalPinSupport support = TerminalPinSupport.getDefault();
@@ -308,8 +309,8 @@ private void doWork() {
308309
final String promptCommand = "printf \"\033]3;${PWD}\007\"; " // NOI18N
309310
+ IDE_OPEN + "() { printf \"\033]10;" + COMMAND_PREFIX + IDE_OPEN + " $*;\007\"; printf \"Opening $# file(s) ...\n\";}"; // NOI18N
310311
final String commandName = "PROMPT_COMMAND"; // NOI18N
311-
String usrPrompt = npb.getEnvironment().get(commandName);
312-
npb.getEnvironment().put(commandName,
312+
String usrPrompt = envVars.get(commandName);
313+
envVars.put(commandName,
313314
(usrPrompt == null)
314315
? promptCommand
315316
: promptCommand + ';' + usrPrompt

nb/ide.launcher/unix/netbeans

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ cd "$progdir"/..
3838
basedir=`pwd`
3939
cd "$old"
4040

41-
case "`uname`" in
41+
case "`uname -s -m`" in
4242
Darwin*)
4343
# set default userdir and cachedir on Mac OS X
4444
DEFAULT_USERDIR_ROOT="${HOME}/Library/Application Support/NetBeans"
4545
DEFAULT_CACHEDIR_ROOT=${HOME}/Library/Caches/NetBeans
4646
;;
47+
CYGWIN*_64)
48+
exec "$progdir/netbeans64.exe" "$@"
49+
;;
50+
CYGWIN*)
51+
exec "$progdir/netbeans.exe" "$@"
52+
;;
4753
*)
4854
# set default userdir and cachedir on unix systems
4955
DEFAULT_USERDIR_ROOT=${HOME}/.netbeans
@@ -65,8 +71,17 @@ fi
6571

6672
export DEFAULT_USERDIR_ROOT
6773

74+
if ! [ "$NETBEANS_USERDIR" = "IGNORE" ]; then
75+
# make sure own launcher directory is on PATH as a fallback
76+
PATH=$PATH:$progdir
77+
fi
78+
6879
# #68373: look for userdir, but do not modify "$@"
69-
userdir="${netbeans_default_userdir}"
80+
if [ -z "$NETBEANS_USERDIR" ]; then
81+
userdir="${netbeans_default_userdir}"
82+
else
83+
userdir="$NETBEANS_USERDIR"
84+
fi
7085
cachedir="${netbeans_default_cachedir}"
7186

7287
founduserdir=""
@@ -138,6 +153,8 @@ launchNbexec() {
138153
then
139154
sh=/bin/bash
140155
fi
156+
NETBEANS_USERDIR=${userdir}
157+
export NETBEANS_USERDIR
141158
if [ "${founduserdir}" = "yes" ]; then
142159
exec $sh "$nbexec" "$@"
143160
else

nb/ide.launcher/windows/nblauncher.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
using namespace std;
3535

3636
const char *NbLauncher::NBEXEC_FILE_PATH = NBEXEC_DLL;
37+
const char *ENV_NETBEANS_USERDIR="NETBEANS_USERDIR";
3738
const char *NbLauncher::OPT_NB_DEFAULT_USER_DIR = "netbeans_default_userdir=";
3839
const char *NbLauncher::OPT_NB_DEFAULT_CACHE_DIR = "netbeans_default_cachedir=";
3940
const char *NbLauncher::OPT_NB_DEFAULT_OPTIONS = "netbeans_default_options=";
@@ -74,6 +75,10 @@ int NbLauncher::start(char *cmdLine) {
7475
return start(args.getCount(), args.getArgs());
7576
}
7677

78+
const char* NbLauncher::findUserDirViaEnvVar() {
79+
return getenv(ENV_NETBEANS_USERDIR);
80+
}
81+
7782
int NbLauncher::start(int argc, char *argv[]) {
7883
SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
7984

@@ -82,13 +87,26 @@ int NbLauncher::start(int argc, char *argv[]) {
8287
return -1;
8388
}
8489

85-
parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str());
90+
bool skipUserDir = false;
91+
const char *userDirViaEnv = findUserDirViaEnvVar();
92+
if (userDirViaEnv != NULL) {
93+
logMsg("NbLauncher::using NETBEANS_USERDIR env variable (%s)", userDirViaEnv);
94+
string udve = userDirViaEnv;
95+
if (udve == "IGNORE") {
96+
skipUserDir = true;
97+
userDirViaEnv = NULL;
98+
} else {
99+
userDir = userDirViaEnv;
100+
}
101+
}
102+
103+
parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str(), userDirViaEnv == NULL);
86104

87105
if (!parseArgs(argc, argv)) {
88106
return -1;
89107
}
90108
string oldUserDir = userDir;
91-
parseConfigFile((userDir + "\\etc\\" + getAppName() + ".conf").c_str());
109+
parseConfigFile((userDir + "\\etc\\" + getAppName() + ".conf").c_str(), userDirViaEnv == NULL);
92110
userDir = oldUserDir;
93111

94112
addExtraClusters();
@@ -114,6 +132,18 @@ int NbLauncher::start(int argc, char *argv[]) {
114132
if (!userDir.empty()) {
115133
newArgs.add(ARG_NAME_USER_DIR);
116134
newArgs.add(userDir.c_str());
135+
if (!skipUserDir) {
136+
string toSet = ENV_NETBEANS_USERDIR;
137+
toSet = toSet + "=" + userDir;
138+
putenv(toSet.c_str());
139+
140+
const char* path = getenv("PATH");
141+
if (path != NULL) {
142+
string setPath = "PATH=";
143+
setPath = setPath + path + ";" + baseDir + "\\bin\\";
144+
putenv(setPath.c_str());
145+
}
146+
}
117147
}
118148
if (!defUserDirRoot.empty()) {
119149
newArgs.add(ARG_DEFAULT_USER_DIR_ROOT);
@@ -460,7 +490,7 @@ bool NbLauncher::getOption(char *&str, const char *opt) {
460490
return false;
461491
}
462492

463-
bool NbLauncher::parseConfigFile(const char* path) {
493+
bool NbLauncher::parseConfigFile(const char* path, const bool searchUserDir) {
464494
logMsg("parseConfigFile(%s)", path);
465495
FILE *file = fopen(path, "r");
466496
if (!file) {
@@ -474,7 +504,7 @@ bool NbLauncher::parseConfigFile(const char* path) {
474504
if (*str == '#') {
475505
continue;
476506
}
477-
if (getOption(str, getDefUserDirOptName())) {
507+
if (searchUserDir && getOption(str, getDefUserDirOptName())) {
478508
findUserDir(str);
479509
logMsg("User dir: %s", userDir.c_str());
480510
} else if (getOption(str, getDefCacheDirOptName())) {

nb/ide.launcher/windows/nblauncher.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class NbLauncher {
6666
virtual bool initBaseNames();
6767
virtual void addSpecificOptions(CmdArgs &args);
6868
virtual bool findUserDir(const char *str);
69+
virtual const char* findUserDirViaEnvVar();
6970
virtual bool findCacheDir(const char *str);
7071
virtual const char * getAppName();
7172
virtual const char * getDefUserDirOptName();
@@ -80,7 +81,7 @@ class NbLauncher {
8081
NbLauncher(const NbLauncher& orig);
8182
bool readClusterFile();
8283
bool parseArgs(int argc, char *argv[]);
83-
bool parseConfigFile(const char* path);
84+
bool parseConfigFile(const char* path, const bool searchUserDir);
8485
bool getOption(char *&str, const char *opt);
8586
void addCluster(const char *cl);
8687
void addExtraClusters();

nb/ide.launcher/windows/netbeans.exe.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
-->
2222
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
23-
<assemblyIdentity version="101.3.0.0"
23+
<assemblyIdentity version="101.4.0.0"
2424
processorArchitecture="x86"
2525
name="netbeans.exe"
2626
type="win32"/>

nb/ide.launcher/windows/netbeans64.exe.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
2323
<!-- Use processorArchitecture="x86", which is the value used by the 64-bit
2424
javaw.exe on Java 10.0.2 and Java 11ea. -->
25-
<assemblyIdentity version="101.3.0.0"
25+
<assemblyIdentity version="101.4.0.0"
2626
processorArchitecture="x86"
2727
name="netbeans64.exe"
2828
type="win32"/>

nb/ide.launcher/windows/version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919

2020
#define COMPANY ""
2121
#define COMPONENT "Apache NetBeans IDE Launcher"
22-
#define VER "101.3.0.0"
23-
#define FVER 101,3,0,0
24-
#define BUILD_ID "101300"
22+
#define VER "101.4.0.0"
23+
#define FVER 101,4,0,0
24+
#define BUILD_ID "101400"
2525
#define INTERNAL_NAME "netbeans"
2626
#define COPYRIGHT "Based on Apache NetBeans from the Apache Software Foundation and is licensed under Apache License Version 2.0"
2727
#define NAME "Apache NetBeans IDE Launcher"

nb/o.n.upgrader/arch.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,43 @@
621621
clusters' fully qualified paths separated by path.separator (semicolon on Windows, colon on Unices)
622622
</api></li>
623623
</ul>
624+
<p>
625+
When the <code>netbeans</code> launcher starts, it also manipulates
626+
(reads and writes) following properties:
627+
</p>
628+
<ul>
629+
<li><api name="NETBEANS_USERDIR" category="devel" group="property" type="export">
630+
<p>
631+
If this <em>environment variable</em> is set to a valid value,
632+
then its value is used as default user dir
633+
instead of <code>netbeans_default_userdir</code> read from
634+
the config file.
635+
</p>
636+
<p>
637+
When the value of user dir is finally determined by the launcher
638+
(by considering default values, value of this environment variable
639+
and <code>--userdir</code> CLI switch, etc.) the launcher sets
640+
<code>NETBEANS_USERDIR</code> environment variable for itself
641+
and its subprocesses.
642+
</p>
643+
<p>
644+
That way executing <code>netbeans</code> in the NetBeans internal
645+
terminal will know what's the userdir of the surrouding NetBeans
646+
and will open files in the same instance just as
647+
<a href="https://github.com/apache/netbeans/pull/8756">#8756 illustrates</a>.
648+
</p>
649+
<p>
650+
The launcher also modifies the <code>PATH</code> variable
651+
by appending its own diretory - making sure typing <code>netbeans</code>
652+
gets handled in the internal NetBeans terminal at all.
653+
In the unusual and rare cases when <b>opt-out</b> of this
654+
behavior maybe needed, just
655+
set the environment variable to <code>IGNORE</code> to instruct
656+
the launcher to avoid these environment variable modifications.
657+
</p>
658+
</api>
659+
</li>
660+
</ul>
624661
</answer>
625662

626663

0 commit comments

Comments
 (0)