Skip to content

Commit 1225c08

Browse files
author
Vladimir Kotal
committed
make it possible to run bare java
fix MacOS java detection
1 parent 616b579 commit 1225c08

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

tools/java.py

100644100755
Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env python3
2+
13
# CDDL HEADER START
24
#
35
# The contents of this file are subject to the terms of the
@@ -25,6 +27,8 @@
2527
from utils import is_exe
2628
import os
2729
import argparse
30+
import sys
31+
import logging
2832

2933

3034
class Java(Command):
@@ -77,7 +81,7 @@ def FindJava(self, logger):
7781
elif system_name == 'Darwin':
7882
cmd = Command('/usr/libexec/java_home')
7983
cmd.execute()
80-
java = cmd.getoutputstr()
84+
java = os.path.join(cmd.getoutputstr(), 'bin', 'java')
8185
elif system_name == 'Linux':
8286
link_path = '/etc/alternatives/java'
8387
if os.path.exists(link_path):
@@ -95,8 +99,40 @@ def get_javaparser():
9599
help='path to java binary')
96100
parser.add_argument('-J', '--java_opts',
97101
help='java options', action='append')
98-
parser.add_argument('-a', '--jar', required=True,
99-
help='Path to jar archive to run')
102+
103+
group = parser.add_mutually_exclusive_group(required=True)
104+
group.add_argument('-a', '--jar',
105+
help='Path to jar archive to run')
106+
group.add_argument('-c', '--classpath',
107+
help='Class path')
108+
100109
parser.add_argument('options', nargs='+', help='options')
101110

102111
return parser
112+
113+
114+
if __name__ == '__main__':
115+
116+
parser = argparse.ArgumentParser(description='java wrapper',
117+
parents=[get_javaparser()])
118+
parser.add_argument('-m', '--mainclass', required=True,
119+
help='Main class')
120+
121+
args = parser.parse_args()
122+
123+
if args.debug:
124+
logging.basicConfig(level=logging.DEBUG)
125+
else:
126+
logging.basicConfig()
127+
128+
logger = logging.getLogger(os.path.basename(sys.argv[0]))
129+
130+
java = Java(args.options, logger=logger, java=args.java,
131+
jar=args.jar, java_opts=args.java_opts,
132+
classpath=args.classpath, main_class=args.mainclass)
133+
java.execute()
134+
ret = java.getretcode()
135+
if ret is None or ret != 0:
136+
logger.error(java.getoutputstr())
137+
logger.error("java command failed (return code {})".format(ret))
138+
sys.exit(1)

0 commit comments

Comments
 (0)