forked from graalvm/mx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mx_webserver.py
69 lines (60 loc) · 2.93 KB
/
mx_webserver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
# ----------------------------------------------------------------------------------------------------
#
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# ----------------------------------------------------------------------------------------------------
#
from __future__ import print_function
import mx
from argparse import ArgumentParser
@mx.command(suite_name="mx",
command_name='webserver',
usage_msg='[options] [root]',
auto_add=False)
@mx.suite_context_free
def webserver(args):
"""start or bundle a simple webserver with a web site"""
parser = ArgumentParser(prog='mx webserver', description='Start a webserver to serve the site at root or '
'bundle the site along with the server into an executable jar.')
parser.add_argument('-a', '--archive', help='instead of starting the server, create an executable jar in <path> '
'containing the server and the site at root such that `java -jar <path>` will start a server '
'for the site and open a browser at its root.', metavar='<path>')
parser.add_argument('-p', '--port', help='local port on which the server should listen', metavar='<num>')
parser.add_argument('--no-browse', help='do not open default web browser on the served site', action='store_true')
parser.add_argument('root', metavar='root')
args = parser.parse_args(args)
project = 'com.oracle.mxtool.webserver'
mainClass = project + '.WebServer'
mx.build(['--no-daemon', '--dependencies', project])
coreCp = mx.classpath([project])
jdk = mx.get_jdk(tag='default')
java_args = mx.get_runtime_jvm_args(project, coreCp, jdk=jdk)
java_args += [mainClass]
if args.archive:
java_args.append('--archive=' + args.archive)
if args.port:
java_args.append('--port=' + args.port)
if args.no_browse:
java_args.append('--no-browse')
java_args.append(args.root)
mx.run_java(java_args, jdk=jdk)