File tree 8 files changed +32
-16
lines changed
packages/src/common/scripts
main/java/org/elasticsearch/packaging/test
8 files changed +32
-16
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,11 @@ def sh_install_deps(config,
346
346
echo "==> Java is not installed"
347
347
return 1
348
348
}
349
+ cat \< \< JAVA > /etc/profile.d/java_home.sh
350
+ if [ -z "\\ \$ JAVA_HOME" ]; then
351
+ export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
352
+ fi
353
+ JAVA
349
354
ensure tar
350
355
ensure curl
351
356
ensure unzip
@@ -382,6 +387,7 @@ Defaults env_keep += "BATS_UTILS"
382
387
Defaults env_keep += "BATS_TESTS"
383
388
Defaults env_keep += "PACKAGING_ARCHIVES"
384
389
Defaults env_keep += "PACKAGING_TESTS"
390
+ Defaults env_keep += "JAVA_HOME"
385
391
SUDOERS_VARS
386
392
chmod 0440 /etc/sudoers.d/elasticsearch_vars
387
393
SHELL
Original file line number Diff line number Diff line change 25
25
fi
26
26
27
27
if [ -z " $JAVA " ]; then
28
- err_exit " could not find java; set JAVA_HOME or ensure java is in PATH "
28
+ err_exit " could not find java; set JAVA_HOME"
29
29
fi
30
30
31
31
case " $1 " in
Original file line number Diff line number Diff line change @@ -41,11 +41,12 @@ if [ -x "$JAVA_HOME/bin/java" ]; then
41
41
else
42
42
set +e
43
43
JAVA=` which java`
44
+ echo " warning: Falling back to java on path. This behavior is deprecated. Specify JAVA_HOME"
44
45
set -e
45
46
fi
46
47
47
48
if [ ! -x " $JAVA " ]; then
48
- echo " could not find java; set JAVA_HOME or ensure java is in PATH " >&2
49
+ echo " could not find java; set JAVA_HOME" >&2
49
50
exit 1
50
51
fi
51
52
Original file line number Diff line number Diff line change @@ -20,11 +20,12 @@ rem now set the path to java
20
20
if defined JAVA_HOME (
21
21
set JAVA = " %JAVA_HOME% \bin\java.exe"
22
22
) else (
23
+ echo warning: Falling back to java on path. This behavior is deprecated. Specify JAVA_HOME
23
24
for %%I in (java.exe) do set JAVA = " %%~$PATH:I "
24
25
)
25
26
26
27
if not exist %JAVA% (
27
- echo could not find java; set JAVA_HOME or ensure java is in PATH 1 >& 2
28
+ echo could not find java; set JAVA_HOME 1 >& 2
28
29
exit /b 1
29
30
)
30
31
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ public void test30AbortWhenJavaMissing() {
126
126
);
127
127
128
128
assertThat (runResult .exitCode , is (1 ));
129
- assertThat (runResult .stderr , containsString ("could not find java; set JAVA_HOME or ensure java is in PATH " ));
129
+ assertThat (runResult .stderr , containsString ("could not find java; set JAVA_HOME" ));
130
130
});
131
131
132
132
Platforms .onLinux (() -> {
@@ -136,7 +136,7 @@ public void test30AbortWhenJavaMissing() {
136
136
sh .run ("chmod -x '" + javaPath + "'" );
137
137
final Result runResult = sh .runIgnoreExitCode (bin .elasticsearch .toString ());
138
138
assertThat (runResult .exitCode , is (1 ));
139
- assertThat (runResult .stderr , containsString ("could not find java; set JAVA_HOME or ensure java is in PATH " ));
139
+ assertThat (runResult .stderr , containsString ("could not find java; set JAVA_HOME" ));
140
140
} finally {
141
141
sh .run ("chmod +x '" + javaPath + "'" );
142
142
}
Original file line number Diff line number Diff line change @@ -83,15 +83,16 @@ public void onlyCompatibleDistributions() {
83
83
84
84
public void test05InstallFailsWhenJavaMissing () {
85
85
final Shell sh = new Shell ();
86
- final Result java = sh .run ("command -v java " );
86
+ final Result javaHomeOutput = sh .run ("echo $JAVA_HOME " );
87
87
88
- final Path originalJavaPath = Paths .get (java .stdout .trim ());
89
- final Path relocatedJavaPath = originalJavaPath .getParent ().resolve ("java.relocated" );
88
+ final Path javaHome = Paths .get (javaHomeOutput .stdout .trim ());
89
+ final Path originalJavaPath = javaHome .resolve ("bin" ).resolve ("java" );
90
+ final Path relocatedJavaPath = javaHome .resolve ("bin" ).resolve ("java.relocated" );
90
91
try {
91
92
mv (originalJavaPath , relocatedJavaPath );
92
93
final Result installResult = runInstallCommand (distribution ());
93
94
assertThat (installResult .exitCode , is (1 ));
94
- assertThat (installResult .stderr , containsString ("could not find java; set JAVA_HOME or ensure java is in PATH " ));
95
+ assertThat (installResult .stderr , containsString ("could not find java; set JAVA_HOME" ));
95
96
} finally {
96
97
mv (relocatedJavaPath , originalJavaPath );
97
98
}
Original file line number Diff line number Diff line change 170
170
sudo chmod +x $JAVA
171
171
172
172
[ " $status " -eq 1 ]
173
- local expected=" could not find java; set JAVA_HOME or ensure java is in PATH "
173
+ local expected=" could not find java; set JAVA_HOME"
174
174
[[ " $output " == * " $expected " * ]] || {
175
175
echo " Expected error message [$expected ] but found: $output "
176
176
false
Original file line number Diff line number Diff line change 30
30
# specific language governing permissions and limitations
31
31
# under the License.
32
32
33
+ env_file () {
34
+ if is_dpkg; then
35
+ echo " /etc/default/elasticsearch"
36
+ fi
37
+ if is_rpm; then
38
+ echo " /etc/sysconfig/elasticsearch"
39
+ fi
40
+ }
33
41
34
42
# Export some useful paths.
35
43
export_elasticsearch_paths () {
@@ -40,15 +48,11 @@ export_elasticsearch_paths() {
40
48
export ESDATA=" /var/lib/elasticsearch"
41
49
export ESLOG=" /var/log/elasticsearch"
42
50
export ESPIDDIR=" /var/run/elasticsearch"
43
- if is_dpkg; then
44
- export ESENVFILE=" /etc/default/elasticsearch"
45
- fi
46
- if is_rpm; then
47
- export ESENVFILE=" /etc/sysconfig/elasticsearch"
48
- fi
51
+ export ESENVFILE=$( env_file)
49
52
export PACKAGE_NAME=${PACKAGE_NAME:- " elasticsearch-oss" }
50
53
}
51
54
55
+
52
56
# Install the rpm or deb package.
53
57
# -u upgrade rather than install. This only matters for rpm.
54
58
# -v the version to upgrade to. Defaults to the version under test.
@@ -88,6 +92,9 @@ install_package() {
88
92
else
89
93
skip " Only rpm or deb supported"
90
94
fi
95
+
96
+ # pass through java home to package
97
+ echo " JAVA_HOME=\" $JAVA_HOME \" " >> $( env_file)
91
98
}
92
99
93
100
# Checks that all directories & files are correctly installed after a deb or
You can’t perform that action at this time.
0 commit comments