# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

sh_bang_template = (" && ".join([
    "echo '#!/usr/bin/env bash' > $@",
    "echo \"# this script should run from the root of your workspace.\" >> $@",
    "echo \"set -e\" >> $@",
    "echo \"\" >> $@",
    "echo 'function bazel_cmd() {' >> $@",
    "echo '  if [[ `which bazelisk` ]]; then' >> $@",
    "echo '    bazelisk \"$$@\"' >> $@",
    "echo '  else' >> $@",
    "echo '    bazel \"$$@\"' >> $@",
    "echo '  fi' >> $@",
    "echo '}' >> $@",
    "echo \"\" >> $@",
    "echo 'if [[ \"$$VERBOSE\" ]]; then set -x ; fi' >> $@",
    "echo \"\" >> $@",
    "echo %s >> $@",
    "echo \"\" >> $@",
    "echo %s >> $@",
]))

def maven_package(
        version,
        repository = None,
        url = None,
        jar = {},
        src = {},
        doc = {},
        war = {}):
    build_cmd = ["bazel_cmd", "build", "'$$@'"]
    mvn_cmd = ["python", "tools/maven/mvn.py", "-v", version]
    api_cmd = mvn_cmd[:]
    api_targets = []
    for type, d in [("jar", jar), ("java-source", src), ("javadoc", doc)]:
        for a, t in sorted(d.items()):
            api_cmd.append("-s %s:%s:$(location %s)" % (a, type, t))
            api_targets.append(t)

    native.genrule(
        name = "gen_api_install",
        cmd = sh_bang_template % (
            " ".join(build_cmd + api_targets),
            " ".join(api_cmd + ["-a", "install"]),
        ),
        srcs = api_targets,
        outs = ["api_install.sh"],
        executable = True,
        testonly = True,
    )

    if repository and url:
        native.genrule(
            name = "gen_api_deploy",
            cmd = sh_bang_template % (
                " ".join(build_cmd + api_targets),
                " ".join(api_cmd + [
                    "-a",
                    "deploy",
                    "--repository",
                    repository,
                    "--url",
                    url,
                ]),
            ),
            srcs = api_targets,
            outs = ["api_deploy.sh"],
            executable = True,
            testonly = True,
        )

    war_cmd = mvn_cmd[:]
    war_targets = []
    for a, t in sorted(war.items()):
        war_cmd.append("-s %s:war:$(location %s)" % (a, t))
        war_targets.append(t)

    native.genrule(
        name = "gen_war_install",
        cmd = sh_bang_template % (
            " ".join(build_cmd + war_targets),
            " ".join(war_cmd + ["-a", "install"]),
        ),
        srcs = war_targets,
        outs = ["war_install.sh"],
        executable = True,
    )

    if repository and url:
        native.genrule(
            name = "gen_war_deploy",
            cmd = sh_bang_template % (
                " ".join(build_cmd + war_targets),
                " ".join(war_cmd + [
                    "-a",
                    "deploy",
                    "--repository",
                    repository,
                    "--url",
                    url,
                ]),
            ),
            srcs = war_targets,
            outs = ["war_deploy.sh"],
            executable = True,
        )
