diff --git a/rules_java_gapic/BUILD.bazel b/rules_java_gapic/BUILD.bazel index e69de29bb2..1d3f0b6c03 100644 --- a/rules_java_gapic/BUILD.bazel +++ b/rules_java_gapic/BUILD.bazel @@ -0,0 +1,20 @@ +load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") + +package(default_visibility = ["//visibility:public"]) + +exports_files(glob(["resources/**/*"])) + +pkg_tar( + name = "gradlew", + extension = "tar.gz", + files = { + "resources/gradle/gradle/wrapper/gradle-wrapper.jar": "gradle/wrapper/gradle-wrapper.jar", + "resources/gradle/gradle/wrapper/gradle-wrapper.properties": "gradle/wrapper/gradle-wrapper.properties", + "resources/gradle/gradlew": "gradlew", + "resources/gradle/gradlew.bat": "gradlew.bat", + }, + mode = "644", + modes = { + "gradlew": "555", + }, +) diff --git a/rules_java_gapic/java_gapic_pkg.bzl b/rules_java_gapic/java_gapic_pkg.bzl new file mode 100644 index 0000000000..51da072f5d --- /dev/null +++ b/rules_java_gapic/java_gapic_pkg.bzl @@ -0,0 +1,426 @@ +# Copyright 2019 Google LLC +# +# 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 +# +# https://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. + +load("@com_google_api_gax_java_properties//:dependencies.properties.bzl", "PROPERTIES") + +def _wrapPropertyNamesInBraces(properties): + wrappedProperties = {} + for k, v in properties.items(): + wrappedProperties["{{%s}}" % k] = v + return wrappedProperties + +_PROPERTIES = _wrapPropertyNamesInBraces(PROPERTIES) + +# ======================================================================== +# General packaging helpers. +# ======================================================================== + +def _construct_package_dir_paths(attr_package_dir, out_pkg, label_name): + if attr_package_dir: + package_dir = attr_package_dir + package_dir_expr = "../{}/".format(package_dir) + tar_cd_suffix = ".." + tar_prefix = attr_package_dir + else: + package_dir = label_name + package_dir_expr = "./" + tar_cd_suffix = "." + tar_prefix = "." + + # We need to include label in the path to eliminate possible output files duplicates + # (labels are guaranteed to be unique by bazel itself) + package_dir_path = "%s/%s/%s" % (out_pkg.dirname, label_name, package_dir) + return struct( + package_dir = package_dir, + package_dir_expr = package_dir_expr, + package_dir_path = package_dir_path, + package_dir_sibling_parent = out_pkg, + package_dir_sibling_basename = label_name, + tar_cd_suffix = tar_cd_suffix, + tar_prefix = tar_prefix, + ) + +def _put_dep_in_a_bucket(dep, dep_bucket, processed_deps): + if processed_deps.get(dep): + return + dep_bucket.append(dep) + processed_deps[dep] = True + +def _gapic_pkg_tar_impl(ctx): + deps = [] + for dep in ctx.attr.deps: + for f in dep.files.to_list(): + deps.append(f) + + paths = _construct_package_dir_paths( + ctx.attr.package_dir, + ctx.outputs.pkg, + ctx.label.name, + ) + + script = """ + mkdir -p {package_dir_path} + for dep in {deps}; do + tar -xzpf $dep -C {package_dir_path} + done + cd {package_dir_path}/{tar_cd_suffix} + tar -zchpf {tar_prefix}/{package_dir}.tar.gz {tar_prefix}/* + cd - + mv {package_dir_path}/{package_dir}.tar.gz {pkg} + rm -rf {package_dir_path} + """.format( + deps = " ".join(["'%s'" % d.path for d in deps]), + package_dir_path = paths.package_dir_path, + package_dir = paths.package_dir, + pkg = ctx.outputs.pkg.path, + tar_cd_suffix = paths.tar_cd_suffix, + tar_prefix = paths.tar_prefix, + ) + + ctx.actions.run_shell( + inputs = deps, + command = script, + outputs = [ctx.outputs.pkg], + ) + +# The Bazel's native gapic_pkg_tar rule behaves weirdly when package_dir parameter +# is specified (at least on some Linux machines it does not put all the files +# under the package_dir). As a workaround for that bug we provide the custom +# implementation of the gapic_pkg_tar rule. +gapic_pkg_tar = rule( + attrs = { + "deps": attr.label_list(mandatory = True), + "package_dir": attr.string(mandatory = False, default = ""), + "extension": attr.string(mandatory = False, default = "tar.gz"), + }, + outputs = {"pkg": "%{name}.%{extension}"}, + implementation = _gapic_pkg_tar_impl, +) + +# ======================================================================== +# Java Gapic package helpers. +# ======================================================================== +def _construct_extra_deps(scope_to_deps, versions_map): + label_name_to_maven_artifact = { + "policy_proto": "maven.com_google_api_grpc_proto_google_iam_v1", + "iam_policy_proto": "maven.com_google_api_grpc_proto_google_iam_v1", + "iam_java_proto": "maven.com_google_api_grpc_proto_google_iam_v1", + "iam_java_grpc": "maven.com_google_api_grpc_grpc_google_iam_v1", + "iam_policy_java_grpc": "maven.com_google_api_grpc_grpc_google_iam_v1", + } + extra_deps = {} + for scope, deps in scope_to_deps.items(): + for dep in deps: + pkg_dependency = _get_gapic_pkg_dependency_name(dep) + if pkg_dependency: + key = "{{%s}}" % pkg_dependency + if not extra_deps.get(key): + extra_deps[key] = "%s project(':%s')" % (scope, pkg_dependency) + elif _is_java_dependency(dep): + for f in dep[JavaInfo].transitive_deps.to_list(): + maven_artifact = label_name_to_maven_artifact.get(f.owner.name) + if not maven_artifact: + continue + key = "{{%s}}" % maven_artifact + if not extra_deps.get(key): + extra_deps[key] = "%s '%s'" % (scope, versions_map[key]) + + return "\n ".join(extra_deps.values()) + +def _is_java_dependency(dep): + return JavaInfo in dep + +def _is_source_dependency(dep): + return _is_java_dependency(dep) and hasattr(dep[JavaInfo], "source_jars") and dep.label.package != "jar" + +def _is_proto_dependency(dep): + return ProtoInfo in dep + +def _get_gapic_pkg_dependency_name(dep): + files_list = dep.files.to_list() + if not files_list or len(files_list) != 1: + return None + for ext in (".tar.gz", ".gz", ".tgz"): + if files_list[0].basename.endswith(ext): + return files_list[0].basename[:-len(ext)] + return None + +# ======================================================================== +# Java Gapic package rules. +# ======================================================================== + +def _java_gapic_build_configs_pkg_impl(ctx): + expanded_templates = [] + paths = _construct_package_dir_paths(ctx.attr.package_dir, ctx.outputs.pkg, ctx.label.name) + + substitutions = dict(ctx.attr.static_substitutions) + substitutions["{{extra_deps}}"] = _construct_extra_deps({ + "compile": ctx.attr.deps, + "testCompile": ctx.attr.test_deps, + }, substitutions) + + for template in ctx.attr.templates.items(): + expanded_template = ctx.actions.declare_file( + "%s/%s" % (paths.package_dir_sibling_basename, template[1]), + sibling = paths.package_dir_sibling_parent, + ) + expanded_templates.append(expanded_template) + ctx.actions.expand_template( + template = template[0].files.to_list()[0], + substitutions = substitutions, + output = expanded_template, + ) + + # Note the script is more complicated than it intuitively should be because of the limitations + # inherent to bazel execution environment: no absolute paths allowed, the generated artifacts + # must ensure uniqueness within a build. The template output directory manipulations are + # to modify default 555 file permissions on any generated by bazel file (exectuable read-only, + # which is not at all what we need for build files). There is no bazel built-in way to change + # the generated files permissions, also the actual files accessible by the script are symlinks + # and `chmod`, when applied to a directory, does not change the attributes of symlink targets + # inside the directory. Chaning the symlink target's permissions is also not an option, because + # they are on a read-only file system. + script = """ + mkdir -p {package_dir_path} + for templ in {templates}; do + cp $templ {package_dir_path}/ + done + chmod 644 {package_dir_path}/* + cd {package_dir_path}/{tar_cd_suffix} + tar -zchpf {tar_prefix}/{package_dir}.tar.gz {tar_prefix}/* + cd - + mv {package_dir_path}/{package_dir}.tar.gz {pkg} + """.format( + templates = " ".join(["'%s'" % f.path for f in expanded_templates]), + package_dir_path = paths.package_dir_path, + package_dir = paths.package_dir, + pkg = ctx.outputs.pkg.path, + tar_cd_suffix = paths.tar_cd_suffix, + tar_prefix = paths.tar_prefix, + ) + + ctx.actions.run_shell( + inputs = expanded_templates, + command = script, + outputs = [ctx.outputs.pkg], + ) + +java_gapic_build_configs_pkg = rule( + attrs = { + "deps": attr.label_list(mandatory = True), + "test_deps": attr.label_list(mandatory = False, allow_empty = True), + "package_dir": attr.string(mandatory = False), + "templates": attr.label_keyed_string_dict(mandatory = False, allow_files = True), + "static_substitutions": attr.string_dict(mandatory = False, allow_empty = True, default = {}), + }, + outputs = {"pkg": "%{name}.tar.gz"}, + implementation = _java_gapic_build_configs_pkg_impl, +) + +def _java_gapic_srcs_pkg_impl(ctx): + srcs = [] + proto_srcs = [] + for src_dep in ctx.attr.deps: + if _is_source_dependency(src_dep): + srcs.extend(src_dep[JavaInfo].source_jars) + if _is_proto_dependency(src_dep): + proto_srcs.extend(src_dep[ProtoInfo].check_deps_sources.to_list()) + + test_srcs = [] + for test_src_dep in ctx.attr.test_deps: + if _is_source_dependency(test_src_dep): + test_srcs.extend(test_src_dep[JavaInfo].source_jars) + + paths = _construct_package_dir_paths(ctx.attr.package_dir, ctx.outputs.pkg, ctx.label.name) + + # Note the script is more complicated than it intuitively should be because of limitations + # inherent to bazel execution environment: no absolute paths allowed, the generated artifacts + # must ensure uniqueness within a build. + script = """ + for src in {srcs}; do + mkdir -p {package_dir_path}/src/main/java + unzip -q -o $src -d {package_dir_path}/src/main/java + rm -r -f {package_dir_path}/src/main/java/META-INF + done + for proto_src in {proto_srcs}; do + mkdir -p {package_dir_path}/src/main/proto + cp -f --parents $proto_src {package_dir_path}/src/main/proto + done + for test_src in {test_srcs}; do + mkdir -p {package_dir_path}/src/test/java + unzip -q -o $test_src -d {package_dir_path}/src/test/java + rm -r -f {package_dir_path}/src/test/java/META-INF + done + cd {package_dir_path}/{tar_cd_suffix} + tar -zchpf {tar_prefix}/{package_dir}.tar.gz {tar_prefix}/* + cd - + mv {package_dir_path}/{package_dir}.tar.gz {pkg} + """.format( + srcs = " ".join(["'%s'" % f.path for f in srcs]), + proto_srcs = " ".join(["'%s'" % f.path for f in proto_srcs]), + test_srcs = " ".join(["'%s'" % f.path for f in test_srcs]), + package_dir_path = paths.package_dir_path, + package_dir = paths.package_dir, + pkg = ctx.outputs.pkg.path, + tar_cd_suffix = paths.tar_cd_suffix, + tar_prefix = paths.tar_prefix, + ) + + ctx.actions.run_shell( + inputs = srcs + proto_srcs + test_srcs, + command = script, + outputs = [ctx.outputs.pkg], + ) + +java_gapic_srcs_pkg = rule( + attrs = { + "deps": attr.label_list(mandatory = True), + "test_deps": attr.label_list(mandatory = False, allow_empty = True), + "package_dir": attr.string(mandatory = True), + }, + outputs = {"pkg": "%{name}.tar.gz"}, + implementation = _java_gapic_srcs_pkg_impl, +) + +def java_gapic_assembly_gradle_pkg( + name, + deps, + assembly_name = None, + **kwargs): + package_dir = name + if assembly_name: + package_dir = "google-cloud-%s-%s" % (assembly_name, name) + + # Rename to avoid target conflicts with the monolith. + proto_target = "proto-%s" % package_dir + proto_target_dep = [] + grpc_target = "grpc-%s" % package_dir + grpc_target_dep = [] + client_target = "gapic-%s" % package_dir + client_target_dep = [] + + client_deps = [] + client_test_deps = [] + grpc_deps = [] + proto_deps = [] + + processed_deps = {} #there is no proper Set in Starlark + for dep in deps: + # Use contains instead of endswith since microgenerator testing may use differently-named targets. + if "_java_gapic" in dep: + _put_dep_in_a_bucket(dep, client_deps, processed_deps) + _put_dep_in_a_bucket("%s_test" % dep, client_test_deps, processed_deps) + elif dep.endswith("_java_grpc"): + _put_dep_in_a_bucket(dep, grpc_deps, processed_deps) + else: + _put_dep_in_a_bucket(dep, proto_deps, processed_deps) + + if proto_deps: + _java_gapic_gradle_pkg( + name = proto_target, + template_label = Label("//rules_java_gapic:resources/gradle/proto.gradle.tmpl"), + deps = proto_deps, + **kwargs + ) + proto_target_dep = [":%s" % proto_target] + + if grpc_deps: + _java_gapic_gradle_pkg( + name = grpc_target, + template_label = Label("//rules_java_gapic:resources/gradle/grpc.gradle.tmpl"), + deps = proto_target_dep + grpc_deps, + **kwargs + ) + grpc_target_dep = ["%s" % grpc_target] + + if client_deps: + _java_gapic_gradle_pkg( + name = client_target, + template_label = Label("//rules_java_gapic:resources/gradle/client.gradle.tmpl"), + deps = proto_target_dep + client_deps, + test_deps = grpc_target_dep + client_test_deps, + **kwargs + ) + client_target_dep = ["%s" % client_target] + + _java_gapic_assembly_gradle_pkg( + name = name, + assembly_name = package_dir, + deps = proto_target_dep + grpc_target_dep + client_target_dep, + ) + +def _java_gapic_gradle_pkg( + name, + template_label, + deps, + test_deps = None, + project_deps = None, + test_project_deps = None, + **kwargs): + resource_target_name = "%s-resources" % name + + static_substitutions = dict(_PROPERTIES) + static_substitutions["{{name}}"] = name + + java_gapic_build_configs_pkg( + name = resource_target_name, + deps = deps, + test_deps = test_deps, + package_dir = name, + templates = { + template_label: "build.gradle", + }, + static_substitutions = static_substitutions, + ) + + srcs_gapic_pkg_target_name = "%s-srcs_pkg" % name + java_gapic_srcs_pkg( + name = srcs_gapic_pkg_target_name, + deps = deps, + test_deps = test_deps, + package_dir = name, + **kwargs + ) + + gapic_pkg_tar( + name = name, + extension = "tar.gz", + deps = [ + resource_target_name, + srcs_gapic_pkg_target_name, + ], + **kwargs + ) + +def _java_gapic_assembly_gradle_pkg(name, assembly_name, deps, visibility = None): + resource_target_name = "%s-resources" % assembly_name + java_gapic_build_configs_pkg( + name = resource_target_name, + deps = deps, + templates = { + Label("//rules_java_gapic:resources/gradle/assembly.gradle.tmpl"): "build.gradle", + Label("//rules_java_gapic:resources/gradle/settings.gradle.tmpl"): "settings.gradle", + }, + ) + + gapic_pkg_tar( + name = name, + extension = "tar.gz", + deps = [ + Label("//rules_java_gapic:gradlew"), + resource_target_name, + ] + deps, + package_dir = assembly_name, + visibility = visibility, + ) diff --git a/rules_java_gapic/resources/gradle/assembly.gradle.tmpl b/rules_java_gapic/resources/gradle/assembly.gradle.tmpl new file mode 100644 index 0000000000..3c0e59ee69 --- /dev/null +++ b/rules_java_gapic/resources/gradle/assembly.gradle.tmpl @@ -0,0 +1,29 @@ +buildscript { + repositories { + mavenLocal() + maven { + url 'https://plugins.gradle.org/m2/' + } + mavenCentral() + } +} + +subprojects { + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = 1.7 + targetCompatibility = 1.7 + + test { + testLogging { + events "passed", "skipped", "failed", "standardOut", "standardError" + exceptionFormat = 'full' + } + } + + repositories { + mavenLocal() + mavenCentral() + } +} diff --git a/rules_java_gapic/resources/gradle/client.gradle.tmpl b/rules_java_gapic/resources/gradle/client.gradle.tmpl new file mode 100644 index 0000000000..137f38d6f2 --- /dev/null +++ b/rules_java_gapic/resources/gradle/client.gradle.tmpl @@ -0,0 +1,61 @@ +buildscript { + repositories { + mavenCentral() + } +} + +apply plugin: 'java' + +description = 'GAPIC library for {{name}}' +group = 'com.google.cloud' +version = (findProperty('version') == 'unspecified') ? '0.0.0-SNAPSHOT' : version +sourceCompatibility = 1.7 +targetCompatibility = 1.7 + +repositories { + mavenCentral() + mavenLocal() +} + +compileJava.options.encoding = 'UTF-8' +javadoc.options.encoding = 'UTF-8' + +dependencies { + compile 'com.google.api:gax:{{version.gax}}' + testCompile 'com.google.api:gax:{{version.gax}}:testlib' + compile 'com.google.api:gax-grpc:{{version.gax_grpc}}' + testCompile 'com.google.api:gax-grpc:{{version.gax_grpc}}:testlib' + testCompile 'io.grpc:grpc-netty-shaded:{{version.io_grpc}}' + testCompile '{{maven.junit_junit}}' + {{extra_deps}} +} + +task smokeTest(type: Test) { + filter { + includeTestsMatching "*SmokeTest" + setFailOnNoMatchingTests false + } +} + +test { + exclude "**/*SmokeTest*" +} + +sourceSets { + main { + java { + srcDir 'src/main/java' + } + } +} + +clean { + delete 'all-jars' +} + +task allJars(type: Copy) { + dependsOn test, jar + into 'all-jars' + // Replace with `from configurations.testRuntime, jar` to include test dependencies + from configurations.runtime, jar +} diff --git a/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.jar b/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..e8c6bf7bb4 Binary files /dev/null and b/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.jar differ diff --git a/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.properties b/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..056e712818 --- /dev/null +++ b/rules_java_gapic/resources/gradle/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon May 02 22:26:16 PDT 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip diff --git a/rules_java_gapic/resources/gradle/gradlew b/rules_java_gapic/resources/gradle/gradlew new file mode 100755 index 0000000000..97fac783e1 --- /dev/null +++ b/rules_java_gapic/resources/gradle/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/rules_java_gapic/resources/gradle/gradlew.bat b/rules_java_gapic/resources/gradle/gradlew.bat new file mode 100644 index 0000000000..8a0b282aa6 --- /dev/null +++ b/rules_java_gapic/resources/gradle/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/rules_java_gapic/resources/gradle/grpc.gradle.tmpl b/rules_java_gapic/resources/gradle/grpc.gradle.tmpl new file mode 100644 index 0000000000..d5dfa3f3de --- /dev/null +++ b/rules_java_gapic/resources/gradle/grpc.gradle.tmpl @@ -0,0 +1,49 @@ +buildscript { + repositories { + mavenCentral() + } +} + +apply plugin: 'java' + +description = 'GRPC library for {{name}}' +group = 'com.google.api.grpc' +version = (findProperty('version') == 'unspecified') ? '0.0.0-SNAPSHOT' : version +sourceCompatibility = 1.7 +targetCompatibility = 1.7 + +repositories { + mavenCentral() + mavenLocal() +} + +dependencies { + compile 'io.grpc:grpc-stub:{{version.io_grpc}}' + compile 'io.grpc:grpc-protobuf:{{version.io_grpc}}' + {{extra_deps}} +} + +sourceSets { + main { + java { + srcDir 'src/main/java' + } + } +} + +task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives javadocJar, sourcesJar +} + +compileJava.options.encoding = 'UTF-8' +javadoc.options.encoding = 'UTF-8' diff --git a/rules_java_gapic/resources/gradle/proto.gradle.tmpl b/rules_java_gapic/resources/gradle/proto.gradle.tmpl new file mode 100644 index 0000000000..ad5e20fc33 --- /dev/null +++ b/rules_java_gapic/resources/gradle/proto.gradle.tmpl @@ -0,0 +1,53 @@ +buildscript { + repositories { + mavenCentral() + } +} + +apply plugin: 'java' + +description = 'PROTO library for {{name}}' +group = 'com.google.api.grpc' +version = (findProperty('version') == 'unspecified') ? '0.0.0-SNAPSHOT' : version +sourceCompatibility = 1.7 +targetCompatibility = 1.7 + +repositories { + mavenCentral() + mavenLocal() +} + +dependencies { + compile 'com.google.protobuf:protobuf-java:{{version.com_google_protobuf}}' + compile '{{maven.com_google_api_api_common}}' + compile '{{maven.com_google_api_grpc_proto_google_common_protos}}' + {{extra_deps}} +} + +sourceSets { + main { + resources { + srcDir 'src/main/proto' + } + java { + srcDir 'src/main/java' + } + } +} + +task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc +} + +task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource +} + +artifacts { + archives javadocJar, sourcesJar +} + +compileJava.options.encoding = 'UTF-8' +javadoc.options.encoding = 'UTF-8' diff --git a/rules_java_gapic/resources/gradle/settings.gradle.tmpl b/rules_java_gapic/resources/gradle/settings.gradle.tmpl new file mode 100644 index 0000000000..ef8c6b79a5 --- /dev/null +++ b/rules_java_gapic/resources/gradle/settings.gradle.tmpl @@ -0,0 +1,7 @@ +include rootDir.listFiles().findAll { + it.isDirectory() && !(it =~ ".*/\\..*") && !(it =~ "^\\..*") +}.collect { + it.getName() +}. toArray(new String[0]) + +