Skip to content

Commit 79ea9c9

Browse files
committed
Make sure netbeans in terminal means itself
1 parent b03bb6c commit 79ea9c9

File tree

8 files changed

+92
-17
lines changed

8 files changed

+92
-17
lines changed

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
*
@@ -267,14 +268,14 @@ private void doWork() {
267268
term.setEmulation("xterm"); // NOI18N
268269

269270
NativeProcessBuilder npb = NativeProcessBuilder.newProcessBuilder(env);
271+
final MacroMap envVars = npb.getEnvironment();
270272
// clear env modified by NB. Let it be initialized by started shell process
271-
npb.getEnvironment().put("LD_LIBRARY_PATH", "");// NOI18N
272-
npb.getEnvironment().put("DYLD_LIBRARY_PATH", "");// NOI18N
273-
273+
envVars.put("LD_LIBRARY_PATH", "");// NOI18N
274+
envVars.put("DYLD_LIBRARY_PATH", "");// NOI18N
274275
if (hostInfo.getOSFamily() == HostInfo.OSFamily.WINDOWS) {
275276
// /etc/profile changes directory to ${HOME} if this
276277
// variable is not set.
277-
npb.getEnvironment().put("CHERE_INVOKING", "1");// NOI18N
278+
envVars.put("CHERE_INVOKING", "1");// NOI18N
278279
}
279280

280281
final TerminalPinSupport support = TerminalPinSupport.getDefault();
@@ -305,8 +306,8 @@ private void doWork() {
305306
final String promptCommand = "printf \"\033]3;${PWD}\007\"; " // NOI18N
306307
+ IDE_OPEN + "() { printf \"\033]10;" + COMMAND_PREFIX + IDE_OPEN + " $*;\007\"; printf \"Opening $# file(s) ...\n\";}"; // NOI18N
307308
final String commandName = "PROMPT_COMMAND"; // NOI18N
308-
String usrPrompt = npb.getEnvironment().get(commandName);
309-
npb.getEnvironment().put(commandName,
309+
String usrPrompt = envVars.get(commandName);
310+
envVars.put(commandName,
310311
(usrPrompt == null)
311312
? promptCommand
312313
: promptCommand + ';' + usrPrompt

nb/ide.launcher/unix/netbeans

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,17 @@ fi
6565

6666
export DEFAULT_USERDIR_ROOT
6767

68+
if ! [ "$NETBEANS_USERDIR" = "nope" ]; then
69+
# make sure own launcher directory is on PATH as a fallback
70+
PATH=$PATH:$progdir
71+
fi
72+
6873
# #68373: look for userdir, but do not modify "$@"
69-
userdir="${netbeans_default_userdir}"
74+
if [ -z "$NETBEANS_USERDIR" ]; then
75+
userdir="${netbeans_default_userdir}"
76+
else
77+
userdir="$NETBEANS_USERDIR"
78+
fi
7079
cachedir="${netbeans_default_cachedir}"
7180

7281
founduserdir=""
@@ -138,6 +147,8 @@ launchNbexec() {
138147
then
139148
sh=/bin/bash
140149
fi
150+
NETBEANS_USERDIR=${userdir}
151+
export NETBEANS_USERDIR
141152
if [ "${founduserdir}" = "yes" ]; then
142153
exec $sh "$nbexec" "$@"
143154
else

nb/ide.launcher/windows/nblauncher.cpp

Lines changed: 30 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=";
@@ -82,13 +83,26 @@ int NbLauncher::start(int argc, char *argv[]) {
8283
return -1;
8384
}
8485

85-
parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str());
86+
bool skipUserDir = false;
87+
char *userDirViaEnv = getenv(ENV_NETBEANS_USERDIR);
88+
if (userDirViaEnv != NULL) {
89+
logMsg("NbLauncher::using NETBEANS_USERDIR env variable (%s)", userDirViaEnv);
90+
string udve = userDirViaEnv;
91+
if (udve == "nope") {
92+
skipUserDir = true;
93+
userDirViaEnv = NULL;
94+
} else {
95+
userDir = userDirViaEnv;
96+
}
97+
}
98+
99+
parseConfigFile((baseDir + "\\etc\\" + getAppName() + ".conf").c_str(), userDirViaEnv == NULL);
86100

87101
if (!parseArgs(argc, argv)) {
88102
return -1;
89103
}
90104
string oldUserDir = userDir;
91-
parseConfigFile((userDir + "\\etc\\" + getAppName() + ".conf").c_str());
105+
parseConfigFile((userDir + "\\etc\\" + getAppName() + ".conf").c_str(), userDirViaEnv == NULL);
92106
userDir = oldUserDir;
93107

94108
addExtraClusters();
@@ -114,6 +128,18 @@ int NbLauncher::start(int argc, char *argv[]) {
114128
if (!userDir.empty()) {
115129
newArgs.add(ARG_NAME_USER_DIR);
116130
newArgs.add(userDir.c_str());
131+
if (!skipUserDir) {
132+
string toSet = ENV_NETBEANS_USERDIR;
133+
toSet = toSet + "=" + userDir;
134+
putenv(toSet.c_str());
135+
136+
const char* path = getenv("PATH");
137+
if (path != NULL) {
138+
string setPath = "PATH=";
139+
setPath = setPath + path + ";" + baseDir + "\\bin\\";
140+
putenv(setPath.c_str());
141+
}
142+
}
117143
}
118144
if (!defUserDirRoot.empty()) {
119145
newArgs.add(ARG_DEFAULT_USER_DIR_ROOT);
@@ -460,7 +486,7 @@ bool NbLauncher::getOption(char *&str, const char *opt) {
460486
return false;
461487
}
462488

463-
bool NbLauncher::parseConfigFile(const char* path) {
489+
bool NbLauncher::parseConfigFile(const char* path, const bool searchUserDir) {
464490
logMsg("parseConfigFile(%s)", path);
465491
FILE *file = fopen(path, "r");
466492
if (!file) {
@@ -474,7 +500,7 @@ bool NbLauncher::parseConfigFile(const char* path) {
474500
if (*str == '#') {
475501
continue;
476502
}
477-
if (getOption(str, getDefUserDirOptName())) {
503+
if (searchUserDir && getOption(str, getDefUserDirOptName())) {
478504
findUserDir(str);
479505
logMsg("User dir: %s", userDir.c_str());
480506
} else if (getOption(str, getDefCacheDirOptName())) {

nb/ide.launcher/windows/nblauncher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class NbLauncher {
8080
NbLauncher(const NbLauncher& orig);
8181
bool readClusterFile();
8282
bool parseArgs(int argc, char *argv[]);
83-
bool parseConfigFile(const char* path);
83+
bool parseConfigFile(const char* path, const bool searchUserDir);
8484
bool getOption(char *&str, const char *opt);
8585
void addCluster(const char *cl);
8686
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>nope</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)