Skip to content

Commit

Permalink
Refactor and expose the control of tomcat bundle (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaqi committed Jul 6, 2020
1 parent 1a1c1ec commit 809dab0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
10 changes: 10 additions & 0 deletions tools/base/tomcat_constants.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Some shared variables between tomcat BUILD file and bazel file.
"""

TOMCAT_VERSIONS = {
7: "apache-tomcat-7.0.104",
8: "apache-tomcat-8.5.56",
9: "apache-tomcat-9.0.36",
10: "apache-tomcat-10.0.0-M6",
}
33 changes: 17 additions & 16 deletions tools/tomcat/BUILD
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
load("//tools/base:wget.bzl", "wget")
load("//tools/base:untar.bzl", "untar")
load("//tools/base:tomcat_constants.bzl", "TOMCAT_VERSIONS")

package(default_visibility = ["//visibility:public"])

wget(
name = "apache-tomcat-7.0.104.tar.gz",
url = "http://dist.cyclopsgroup.org/download/tomcat/apache-tomcat-7.0.104.tar.gz",
name = "tomcat_7.tar.gz",
url = "http://dist.cyclopsgroup.org/download/tomcat/%s.tar.gz" % TOMCAT_VERSIONS[7],
)

untar(
name = "tomcat-7",
tars = [":tomcat-7.0.104.tar.gz"],
name = "tomcat_7",
tars = [":tomcat_7.tar.gz"],
)

wget(
name = "tomcat-8.5.56.tar.gz",
url = "http://dist.cyclopsgroup.org/download/tomcat/apache-tomcat-8.5.56.tar.gz",
name = "tomcat_8.tar.gz",
url = "http://dist.cyclopsgroup.org/download/tomcat/%s.tar.gz" % TOMCAT_VERSIONS[8],
)

untar(
name = "tomcat-8",
tars = [":tomcat-8.5.56.tar.gz"],
name = "tomcat_8",
tars = [":tomcat_8.tar.gz"],
)

wget(
name = "tomcat-9.0.36.tar.gz",
url = "http://dist.cyclopsgroup.org/download/tomcat/apache-tomcat-9.0.36.tar.gz",
name = "tomcat_9.tar.gz",
url = "http://dist.cyclopsgroup.org/download/tomcat/%s.tar.gz" % TOMCAT_VERSIONS[9],
)

untar(
name = "tomcat-9",
tars = [":tomcat-9.0.36.tar.gz"],
name = "tomcat_9",
tars = [":tomcat_9.tar.gz"],
)

wget(
name = "tomcat-10.0.0-M6.tar.gz",
url = "http://dist.cyclopsgroup.org/download/tomcat/apache-tomcat-10.0.0-M6.tar.gz",
name = "tomcat_10.tar.gz",
url = "http://dist.cyclopsgroup.org/download/tomcat/%s.tar.gz" % TOMCAT_VERSIONS[10],
)

untar(
name = "tomcat-10",
tars = [":tomcat-10.0.0-M6.tar.gz"],
name = "tomcat_10",
tars = [":tomcat_10.tar.gz"],
)

exports_files([
Expand Down
21 changes: 10 additions & 11 deletions tools/tomcat/tomcat.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Bazel build rule for running war file with tomcat.
"""

load("//tools/base:tomcat_constants.bzl", "TOMCAT_VERSIONS")

def _link_file(ctx, src_path, dest_path):
dest_file = ctx.actions.declare_symlink(dest_path)
ctx.actions.symlink(output = dest_file, target_path = src_path)
Expand All @@ -25,7 +27,6 @@ def _create_webapp(ctx):
command = " && ".join(commands),
)

# return _link_file(ctx, ctx.file.app_dir.path, dest_dir), ctx.file.app_dir
return dest_file, ctx.file.app_dir

def _create_tomcat_base(ctx):
Expand Down Expand Up @@ -124,29 +125,27 @@ _tomcat_binary = rule(
executable = True,
)

TOMCAT_BUNDLES = {
7: ["//tools/tomcat:tomcat-7", "apache-tomcat-7.0.104"],
8: ["//tools/tomcat:tomcat-8", "apache-tomcat-8.5.56"],
9: ["//tools/tomcat:tomcat-9", "apache-tomcat-9.0.36"],
}

def tomcat_binary(
name,
visibility = None,
war_file = None,
app_dir = None,
app_name = "ROOT",
version = 9,
tomcat_bundle = None,
jvm_opts = []):
if war_file == None and app_dir == None:
fail("war_file or app_dir must be specified.")

if war_file != None and app_dir != None:
fail("Only one of war_file and app_dir should be specified.")

tomcat_bundle = TOMCAT_BUNDLES[version]
path = TOMCAT_VERSIONS[version]
if path == None:
fail("Invalid version %s, these versions are acceptable: %s." % (version, TOMCAT_VERSIONS.keys))

if tomcat_bundle == None:
fail("Invalid version %s, these versions are acceptable: %s." % (version, TOMCAT_BUNDLES.keys))
tomcat_bundle = "//tools/tomcat:tomcat_%s" % version

return _tomcat_binary(
name = name,
Expand All @@ -156,6 +155,6 @@ def tomcat_binary(
app_dir = app_dir,
is_app_dir = (war_file == None),
jvm_opts = jvm_opts,
tomcat_bundle = tomcat_bundle[0],
tomcat_bundle_path = tomcat_bundle[1],
tomcat_bundle = tomcat_bundle,
tomcat_bundle_path = path,
)

0 comments on commit 809dab0

Please sign in to comment.