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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <haible@clisp.cons.org>, 2001.
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
7304
1c4ed7637c24 Include <config.h> unconditionally.
Bruno Haible <bruno@clisp.org>
parents: 7017
diff changeset
18 #include <config.h>
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <alloca.h>
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 /* Specification. */
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include "javaexec.h"
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdio.h>
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdlib.h>
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <string.h>
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include "execute.h"
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include "classpath.h"
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #include "xsetenv.h"
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #include "error.h"
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #include "gettext.h"
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #define _(str) gettext (str)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 /* Survey of Java virtual machines.
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 A = does it work without CLASSPATH being set
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 B = does it work with CLASSPATH being set to empty
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 C = option to set CLASSPATH, other than setting it in the environment
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 T = test for presence
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 Program from A B C T
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 $JAVA unknown N Y n/a true
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 gij GCC 3.0 Y Y n/a gij --version >/dev/null
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 java JDK 1.1.8 Y Y -classpath P java -version 2>/dev/null
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 jre JDK 1.1.8 N Y -classpath P jre 2>/dev/null; test $? = 1
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 java JDK 1.3.0 Y Y -classpath P java -version 2>/dev/null
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 jview MS IE Y Y -cp P jview -? >nul; %errorlevel% = 1
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 The CLASSPATH is a colon separated list of pathnames. (On Windows: a
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 semicolon separated list of pathnames.)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 We try the Java virtual machines in the following order:
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 2. "gij", because it is a completely free JVM,
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 3. "java", because it is a standard JVM,
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 4. "jre", comes last because it requires a CLASSPATH environment variable,
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 5. "jview", on Windows only, because it is frequently installed.
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 We unset the JAVA_HOME environment variable, because a wrong setting of
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 this variable can confuse the JDK's javac.
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 */
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 bool
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 bool err = false;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 unsigned int nargs;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 char *old_JAVA_HOME;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 /* Count args. */
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 const char * const *arg;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 for (nargs = 0, arg = args; *arg != NULL; nargs++, arg++)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 ;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 /* First, try a class compiled to a native code executable. */
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 if (exe_dir != NULL)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 unsigned int i;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 /* Set CLASSPATH. */
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 argv[0] = exe_pathname;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 err = executer (class_name, exe_pathname, argv, private_data);
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 /* Reset CLASSPATH. */
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 reset_classpath (old_classpath);
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122
8948
a162347a0232 Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents: 8251
diff changeset
123 freea (argv);
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 goto done1;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 const char *java = getenv ("JAVA");
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 if (java != NULL && java[0] != '\0')
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174
39883
cd549182ef0e sh-filename: New module.
Bruno Haible <bruno@clisp.org>
parents: 19595
diff changeset
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
cd549182ef0e sh-filename: New module.
Bruno Haible <bruno@clisp.org>
parents: 19595
diff changeset
179 err = executer (java, BOURNE_SHELL, argv, private_data);
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
180
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
181 freea (command);
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
186 goto done1;
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 /* Unset the JAVA_HOME environment variable. */
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 old_JAVA_HOME = getenv ("JAVA_HOME");
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 if (old_JAVA_HOME != NULL)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
193 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
194 old_JAVA_HOME = xstrdup (old_JAVA_HOME);
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
195 unsetenv ("JAVA_HOME");
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
196 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 static bool gij_tested;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 static bool gij_present;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 if (!gij_tested)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 if (gij_present)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
245 freea (argv);
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
247 goto done2;
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 static bool java_tested;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 static bool java_present;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 if (!java_tested)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 if (java_present)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
300 freea (argv);
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
302 goto done2;
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 static bool jre_tested;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 static bool jre_present;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 if (!jre_tested)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 if (jre_present)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
354 freea (argv);
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
356 goto done2;
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 static bool jview_tested;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 static bool jview_present;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 if (!jview_tested)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381 if (jview_present)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
409 freea (argv);
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10391
diff changeset
411 goto done2;
5624
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 #endif
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416 if (!quiet)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417 error (0, 0, _("Java virtual machine not found, try installing gij or set $JAVA"));
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 err = true;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 done2:
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 if (old_JAVA_HOME != NULL)
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 {
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 xsetenv ("JAVA_HOME", old_JAVA_HOME, 1);
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 free (old_JAVA_HOME);
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 }
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 done1:
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 return err;
356a0afaf162 New module 'javaexec'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 }