Mercurial > gnulib
annotate lib/javaexec.c @ 40186:8964917f9574
autoupdate
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Mon, 18 Feb 2019 08:02:49 -0800 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
5624 | 1 /* Execute a Java program. |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
39883
diff
changeset
|
2 Copyright (C) 2001-2003, 2006-2019 Free Software Foundation, Inc. |
5624 | 3 Written by Bruno Haible <haible@clisp.cons.org>, 2001. |
4 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8948
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
5624 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8948
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8948
diff
changeset
|
8 (at your option) any later version. |
5624 | 9 |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
5624 | 17 |
7304
1c4ed7637c24
Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents:
7017
diff
changeset
|
18 #include <config.h> |
5624 | 19 #include <alloca.h> |
20 | |
21 /* Specification. */ | |
22 #include "javaexec.h" | |
23 | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
27 | |
28 #include "execute.h" | |
29 #include "classpath.h" | |
30 #include "xsetenv.h" | |
31 #include "sh-quote.h" | |
10391
f0a681493fa6
New module 'xconcat-filename', split off from module 'concat-filename'.
Bruno Haible <bruno@clisp.org>
parents:
10197
diff
changeset
|
32 #include "concat-filename.h" |
5624 | 33 #include "xalloc.h" |
8948
a162347a0232
Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents:
8251
diff
changeset
|
34 #include "xmalloca.h" |
5624 | 35 #include "error.h" |
36 #include "gettext.h" | |
37 | |
38 #define _(str) gettext (str) | |
39 | |
40 | |
41 /* Survey of Java virtual machines. | |
42 | |
43 A = does it work without CLASSPATH being set | |
44 B = does it work with CLASSPATH being set to empty | |
45 C = option to set CLASSPATH, other than setting it in the environment | |
46 T = test for presence | |
47 | |
48 Program from A B C T | |
49 | |
50 $JAVA unknown N Y n/a true | |
51 gij GCC 3.0 Y Y n/a gij --version >/dev/null | |
52 java JDK 1.1.8 Y Y -classpath P java -version 2>/dev/null | |
53 jre JDK 1.1.8 N Y -classpath P jre 2>/dev/null; test $? = 1 | |
54 java JDK 1.3.0 Y Y -classpath P java -version 2>/dev/null | |
55 jview MS IE Y Y -cp P jview -? >nul; %errorlevel% = 1 | |
56 | |
57 The CLASSPATH is a colon separated list of pathnames. (On Windows: a | |
58 semicolon separated list of pathnames.) | |
59 | |
60 We try the Java virtual machines in the following order: | |
61 1. getenv ("JAVA"), because the user must be able to override our | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
62 preferences, |
5624 | 63 2. "gij", because it is a completely free JVM, |
64 3. "java", because it is a standard JVM, | |
65 4. "jre", comes last because it requires a CLASSPATH environment variable, | |
66 5. "jview", on Windows only, because it is frequently installed. | |
67 | |
68 We unset the JAVA_HOME environment variable, because a wrong setting of | |
69 this variable can confuse the JDK's javac. | |
70 */ | |
71 | |
72 bool | |
73 execute_java_class (const char *class_name, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
74 const char * const *classpaths, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
75 unsigned int classpaths_count, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
76 bool use_minimal_classpath, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
77 const char *exe_dir, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
78 const char * const *args, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
79 bool verbose, bool quiet, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
80 execute_fn *executer, void *private_data) |
5624 | 81 { |
82 bool err = false; | |
83 unsigned int nargs; | |
84 char *old_JAVA_HOME; | |
85 | |
86 /* Count args. */ | |
87 { | |
88 const char * const *arg; | |
89 | |
90 for (nargs = 0, arg = args; *arg != NULL; nargs++, arg++) | |
91 ; | |
92 } | |
93 | |
94 /* First, try a class compiled to a native code executable. */ | |
95 if (exe_dir != NULL) | |
96 { | |
10391
f0a681493fa6
New module 'xconcat-filename', split off from module 'concat-filename'.
Bruno Haible <bruno@clisp.org>
parents:
10197
diff
changeset
|
97 char *exe_pathname = xconcatenated_filename (exe_dir, class_name, EXEEXT); |
5624 | 98 char *old_classpath; |
8948
a162347a0232
Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents:
8251
diff
changeset
|
99 char **argv = (char **) xmalloca ((1 + nargs + 1) * sizeof (char *)); |
5624 | 100 unsigned int i; |
101 | |
102 /* Set CLASSPATH. */ | |
103 old_classpath = | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
104 set_classpath (classpaths, classpaths_count, use_minimal_classpath, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
105 verbose); |
5624 | 106 |
107 argv[0] = exe_pathname; | |
108 for (i = 0; i <= nargs; i++) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
109 argv[1 + i] = (char *) args[i]; |
5624 | 110 |
111 if (verbose) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
112 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
113 char *command = shell_quote_argv (argv); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
114 printf ("%s\n", command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
115 free (command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
116 } |
5624 | 117 |
118 err = executer (class_name, exe_pathname, argv, private_data); | |
119 | |
120 /* Reset CLASSPATH. */ | |
121 reset_classpath (old_classpath); | |
122 | |
8948
a162347a0232
Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents:
8251
diff
changeset
|
123 freea (argv); |
5624 | 124 |
125 goto done1; | |
126 } | |
127 | |
128 { | |
129 const char *java = getenv ("JAVA"); | |
130 if (java != NULL && java[0] != '\0') | |
131 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
132 /* Because $JAVA may consist of a command and options, we use the |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
133 shell. Because $JAVA has been set by the user, we leave all |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
134 all environment variables in place, including JAVA_HOME, and |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
135 we don't erase the user's CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
136 char *old_classpath; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
137 unsigned int command_length; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
138 char *command; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
139 char *argv[4]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
140 const char * const *arg; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
141 char *p; |
5624 | 142 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
143 /* Set CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
144 old_classpath = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
145 set_classpath (classpaths, classpaths_count, false, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
146 verbose); |
5624 | 147 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
148 command_length = strlen (java); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
149 command_length += 1 + shell_quote_length (class_name); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
150 for (arg = args; *arg != NULL; arg++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
151 command_length += 1 + shell_quote_length (*arg); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
152 command_length += 1; |
5624 | 153 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
154 command = (char *) xmalloca (command_length); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
155 p = command; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
156 /* Don't shell_quote $JAVA, because it may consist of a command |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
157 and options. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
158 memcpy (p, java, strlen (java)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
159 p += strlen (java); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
160 *p++ = ' '; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
161 p = shell_quote_copy (p, class_name); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
162 for (arg = args; *arg != NULL; arg++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
163 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
164 *p++ = ' '; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
165 p = shell_quote_copy (p, *arg); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
166 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
167 *p++ = '\0'; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
168 /* Ensure command_length was correctly calculated. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
169 if (p - command > command_length) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
170 abort (); |
5624 | 171 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
172 if (verbose) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
173 printf ("%s\n", command); |
5624 | 174 |
39883 | 175 argv[0] = BOURNE_SHELL; |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
176 argv[1] = "-c"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
177 argv[2] = command; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
178 argv[3] = NULL; |
39883 | 179 err = executer (java, BOURNE_SHELL, argv, private_data); |
5624 | 180 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
181 freea (command); |
5624 | 182 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
183 /* Reset CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
184 reset_classpath (old_classpath); |
5624 | 185 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
186 goto done1; |
5624 | 187 } |
188 } | |
189 | |
190 /* Unset the JAVA_HOME environment variable. */ | |
191 old_JAVA_HOME = getenv ("JAVA_HOME"); | |
192 if (old_JAVA_HOME != NULL) | |
193 { | |
194 old_JAVA_HOME = xstrdup (old_JAVA_HOME); | |
195 unsetenv ("JAVA_HOME"); | |
196 } | |
197 | |
198 { | |
199 static bool gij_tested; | |
200 static bool gij_present; | |
201 | |
202 if (!gij_tested) | |
203 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
204 /* Test for presence of gij: "gij --version > /dev/null" */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
205 char *argv[3]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
206 int exitstatus; |
5624 | 207 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
208 argv[0] = "gij"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
209 argv[1] = "--version"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
210 argv[2] = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
211 exitstatus = execute ("gij", "gij", argv, false, false, true, true, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
212 true, false, NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
213 gij_present = (exitstatus == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
214 gij_tested = true; |
5624 | 215 } |
216 | |
217 if (gij_present) | |
218 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
219 char *old_classpath; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
220 char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
221 unsigned int i; |
5624 | 222 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
223 /* Set CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
224 old_classpath = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
225 set_classpath (classpaths, classpaths_count, use_minimal_classpath, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
226 verbose); |
5624 | 227 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
228 argv[0] = "gij"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
229 argv[1] = (char *) class_name; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
230 for (i = 0; i <= nargs; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
231 argv[2 + i] = (char *) args[i]; |
5624 | 232 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
233 if (verbose) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
234 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
235 char *command = shell_quote_argv (argv); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
236 printf ("%s\n", command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
237 free (command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
238 } |
5624 | 239 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
240 err = executer ("gij", "gij", argv, private_data); |
5624 | 241 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
242 /* Reset CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
243 reset_classpath (old_classpath); |
5624 | 244 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
245 freea (argv); |
5624 | 246 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
247 goto done2; |
5624 | 248 } |
249 } | |
250 | |
251 { | |
252 static bool java_tested; | |
253 static bool java_present; | |
254 | |
255 if (!java_tested) | |
256 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
257 /* Test for presence of java: "java -version 2> /dev/null" */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
258 char *argv[3]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
259 int exitstatus; |
5624 | 260 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
261 argv[0] = "java"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
262 argv[1] = "-version"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
263 argv[2] = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
264 exitstatus = execute ("java", "java", argv, false, false, true, true, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
265 true, false, NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
266 java_present = (exitstatus == 0); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
267 java_tested = true; |
5624 | 268 } |
269 | |
270 if (java_present) | |
271 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
272 char *old_classpath; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
273 char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
274 unsigned int i; |
5624 | 275 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
276 /* Set CLASSPATH. We don't use the "-classpath ..." option because |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
277 in JDK 1.1.x its argument should also contain the JDK's classes.zip, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
278 but we don't know its location. (In JDK 1.3.0 it would work.) */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
279 old_classpath = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
280 set_classpath (classpaths, classpaths_count, use_minimal_classpath, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
281 verbose); |
5624 | 282 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
283 argv[0] = "java"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
284 argv[1] = (char *) class_name; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
285 for (i = 0; i <= nargs; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
286 argv[2 + i] = (char *) args[i]; |
5624 | 287 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
288 if (verbose) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
289 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
290 char *command = shell_quote_argv (argv); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
291 printf ("%s\n", command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
292 free (command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
293 } |
5624 | 294 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
295 err = executer ("java", "java", argv, private_data); |
5624 | 296 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
297 /* Reset CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
298 reset_classpath (old_classpath); |
5624 | 299 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
300 freea (argv); |
5624 | 301 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
302 goto done2; |
5624 | 303 } |
304 } | |
305 | |
306 { | |
307 static bool jre_tested; | |
308 static bool jre_present; | |
309 | |
310 if (!jre_tested) | |
311 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
312 /* Test for presence of jre: "jre 2> /dev/null ; test $? = 1" */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
313 char *argv[2]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
314 int exitstatus; |
5624 | 315 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
316 argv[0] = "jre"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
317 argv[1] = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
318 exitstatus = execute ("jre", "jre", argv, false, false, true, true, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
319 true, false, NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
320 jre_present = (exitstatus == 0 || exitstatus == 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
321 jre_tested = true; |
5624 | 322 } |
323 | |
324 if (jre_present) | |
325 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
326 char *old_classpath; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
327 char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
328 unsigned int i; |
5624 | 329 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
330 /* Set CLASSPATH. We don't use the "-classpath ..." option because |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
331 in JDK 1.1.x its argument should also contain the JDK's classes.zip, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
332 but we don't know its location. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
333 old_classpath = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
334 set_classpath (classpaths, classpaths_count, use_minimal_classpath, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
335 verbose); |
5624 | 336 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
337 argv[0] = "jre"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
338 argv[1] = (char *) class_name; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
339 for (i = 0; i <= nargs; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
340 argv[2 + i] = (char *) args[i]; |
5624 | 341 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
342 if (verbose) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
343 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
344 char *command = shell_quote_argv (argv); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
345 printf ("%s\n", command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
346 free (command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
347 } |
5624 | 348 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
349 err = executer ("jre", "jre", argv, private_data); |
5624 | 350 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
351 /* Reset CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
352 reset_classpath (old_classpath); |
5624 | 353 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
354 freea (argv); |
5624 | 355 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
356 goto done2; |
5624 | 357 } |
358 } | |
359 | |
19595
beb2ad957aca
Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
360 #if defined _WIN32 || defined __CYGWIN__ |
16214
ec738d6aeef5
Talk about "native Windows API", not "Win32".
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
361 /* Native Windows, Cygwin */ |
5624 | 362 { |
363 static bool jview_tested; | |
364 static bool jview_present; | |
365 | |
366 if (!jview_tested) | |
367 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
368 /* Test for presence of jview: "jview -? >nul ; test $? = 1" */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
369 char *argv[3]; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
370 int exitstatus; |
5624 | 371 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
372 argv[0] = "jview"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
373 argv[1] = "-?"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
374 argv[2] = NULL; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
375 exitstatus = execute ("jview", "jview", argv, false, false, true, true, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
376 true, false, NULL); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
377 jview_present = (exitstatus == 0 || exitstatus == 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
378 jview_tested = true; |
5624 | 379 } |
380 | |
381 if (jview_present) | |
382 { | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
383 char *old_classpath; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
384 char **argv = (char **) xmalloca ((2 + nargs + 1) * sizeof (char *)); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
385 unsigned int i; |
5624 | 386 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
387 /* Set CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
388 old_classpath = |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
389 set_classpath (classpaths, classpaths_count, use_minimal_classpath, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
390 verbose); |
5624 | 391 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
392 argv[0] = "jview"; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
393 argv[1] = (char *) class_name; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
394 for (i = 0; i <= nargs; i++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
395 argv[2 + i] = (char *) args[i]; |
5624 | 396 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
397 if (verbose) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
398 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
399 char *command = shell_quote_argv (argv); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
400 printf ("%s\n", command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
401 free (command); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
402 } |
5624 | 403 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
404 err = executer ("jview", "jview", argv, private_data); |
5624 | 405 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
406 /* Reset CLASSPATH. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
407 reset_classpath (old_classpath); |
5624 | 408 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
409 freea (argv); |
5624 | 410 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10391
diff
changeset
|
411 goto done2; |
5624 | 412 } |
413 } | |
414 #endif | |
415 | |
416 if (!quiet) | |
417 error (0, 0, _("Java virtual machine not found, try installing gij or set $JAVA")); | |
418 err = true; | |
419 | |
420 done2: | |
421 if (old_JAVA_HOME != NULL) | |
422 { | |
423 xsetenv ("JAVA_HOME", old_JAVA_HOME, 1); | |
424 free (old_JAVA_HOME); | |
425 } | |
426 | |
427 done1: | |
428 return err; | |
429 } |