diff --git a/examples/java-export/BUILD b/examples/java-export/BUILD index 74810c93..64bddd30 100644 --- a/examples/java-export/BUILD +++ b/examples/java-export/BUILD @@ -1,5 +1,4 @@ load("@rules_jvm_external//:defs.bzl", "java_export", "maven_bom") - # To export the file, run: # # `bazel run //:example-export.publish --define "maven_repo=file://$(pwd)/repository"` @@ -9,6 +8,9 @@ load("@rules_jvm_external//:defs.bzl", "java_export", "maven_bom") java_export( name = "example-export", + extra_artifacts = { + "release": "//src/main/java/com/github/bazelbuild/rulesjvmexternal/example/export:tar", + }, maven_coordinates = "com.example:bazel-example:0.0.1", runtime_deps = [ "//src/main/java/com/github/bazelbuild/rulesjvmexternal/example/export", diff --git a/examples/java-export/src/main/java/com/github/bazelbuild/rulesjvmexternal/example/export/BUILD b/examples/java-export/src/main/java/com/github/bazelbuild/rulesjvmexternal/example/export/BUILD index d8717ddd..337de2aa 100644 --- a/examples/java-export/src/main/java/com/github/bazelbuild/rulesjvmexternal/example/export/BUILD +++ b/examples/java-export/src/main/java/com/github/bazelbuild/rulesjvmexternal/example/export/BUILD @@ -1,4 +1,5 @@ load("@rules_jvm_external//:defs.bzl", "artifact") +load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") java_library( name = "export", @@ -11,3 +12,12 @@ java_library( artifact("com.google.guava:guava"), ], ) + +pkg_tar( + name = "tar", + srcs = glob(["*"]), + extension = "tar.gz2", + visibility = [ + "//:__pkg__", + ], +) diff --git a/private/rules/java_export.bzl b/private/rules/java_export.bzl index 06b8acc9..6b8d877a 100644 --- a/private/rules/java_export.bzl +++ b/private/rules/java_export.bzl @@ -12,6 +12,7 @@ def java_export( visibility = None, tags = [], testonly = None, + extra_artifacts = {}, **kwargs): """Extends `java_library` to allow maven artifacts to be uploaded. @@ -91,6 +92,7 @@ def java_export( testonly, lib_name, javadocopts, + extra_artifacts, ) def maven_export( @@ -103,7 +105,8 @@ def maven_export( tags, testonly, lib_name, - javadocopts): + javadocopts, + extra_artifacts): """Helper rule to reuse this code for both java_export and kt_jvm_export. After a library has already been created (either a kt_jvm_library or @@ -162,6 +165,9 @@ def maven_export( testonly = testonly, ) + extra_artifacts_targets = extra_artifacts.values() + extra_classifiers = extra_artifacts.keys() + pom_file( name = "%s-pom" % name, target = ":%s" % lib_name, @@ -172,6 +178,8 @@ def maven_export( ) maven_publish( + extra_artifacts = extra_artifacts_targets, + extra_classifiers = extra_classifiers, name = "%s.publish" % name, coordinates = maven_coordinates, pom = "%s-pom" % name, diff --git a/private/rules/maven_publish.bzl b/private/rules/maven_publish.bzl index 8be0e769..7ccf27aa 100644 --- a/private/rules/maven_publish.bzl +++ b/private/rules/maven_publish.bzl @@ -5,13 +5,15 @@ MavenPublishInfo = provider( "javadocs": "Javadoc jar file for documentation files", "artifact_jar": "Jar with the code and metadata for execution", "source_jar": "Jar with the source code for review", + "extra_classifiers": "Extra classifiers for Artifacts", + "extra_artifacts": "Extra artifacts such as tars, wars", }, ) _TEMPLATE = """#!/usr/bin/env bash echo "Uploading {coordinates} to {maven_repo}" -{uploader} {maven_repo} {gpg_sign} {user} {password} {coordinates} {pom} {artifact_jar} {source_jar} {javadoc} +{uploader} {maven_repo} {gpg_sign} {user} {password} {coordinates} {pom} {artifact_jar} {source_jar} {javadoc} {extra_classifiers} {extra_artifacts} """ def _maven_publish_impl(ctx): @@ -27,6 +29,7 @@ def _maven_publish_impl(ctx): artifacts_short_path = ctx.file.artifact_jar.short_path if ctx.file.artifact_jar else "''" source_short_path = ctx.file.source_jar.short_path if ctx.file.source_jar else "''" javadocs_short_path = ctx.file.javadocs.short_path if ctx.file.javadocs else "''" + extra_artifacts = [file.short_path for file in ctx.files.extra_artifacts] ctx.actions.write( output = executable, @@ -42,10 +45,12 @@ def _maven_publish_impl(ctx): artifact_jar = artifacts_short_path, source_jar = source_short_path, javadoc = javadocs_short_path, + extra_classifiers = ",".join(ctx.attr.extra_classifiers), + extra_artifacts = ",".join(extra_artifacts), ), ) - files = [ctx.file.pom] + files = ctx.files.extra_artifacts + [ctx.file.pom] if ctx.file.artifact_jar: files.append(ctx.file.artifact_jar) if ctx.file.source_jar: @@ -104,6 +109,8 @@ When signing with GPG, the current default key is used. "source_jar": attr.label( allow_single_file = True, ), + "extra_classifiers": attr.string_list(), + "extra_artifacts": attr.label_list(), "_uploader": attr.label( executable = True, cfg = "exec", diff --git a/private/tools/java/rules/jvm/external/maven/MavenPublisher.java b/private/tools/java/rules/jvm/external/maven/MavenPublisher.java index 432bb64b..6364feaf 100644 --- a/private/tools/java/rules/jvm/external/maven/MavenPublisher.java +++ b/private/tools/java/rules/jvm/external/maven/MavenPublisher.java @@ -87,6 +87,8 @@ public static void main(String[] args) throws IOException, InterruptedException, Path binJar = getPathIfSet(args[6]); Path srcJar = getPathIfSet(args[7]); Path docJar = getPathIfSet(args[8]); + String extraClassifiers = args[9]; + String extraArtifacts = args[10]; try { List> futures = new ArrayList<>(); @@ -104,6 +106,10 @@ public static void main(String[] args) throws IOException, InterruptedException, futures.add(upload(repo, credentials, coords, "-javadoc.jar", docJar, gpgSign)); } + if(extraClassifiers != null && extraArtifacts != null) { + uploadextraArtifacts(repo, credentials, coords, extraClassifiers, extraArtifacts); + } + CompletableFuture all = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); all.get(30, MINUTES); } finally { @@ -165,6 +171,37 @@ private static CompletableFuture upload( return CompletableFuture.allOf(uploads.toArray(new CompletableFuture[0])); } + private static CompletableFuture uploadextraArtifacts( + String repo, + Credentials credentials, + Coordinates coords, + String extraClassifiers, + String extraArtifacts + ){ + List> uploads = new ArrayList<>(); + String[] extraClassifiersArr = extraClassifiers.split(","); + String[] extraArtifactsArr = extraArtifacts.split(","); + System.out.println("Working Directory = " + System.getProperty("user.dir")); + System.out.println(Arrays.toString(extraClassifiersArr)); + System.out.println(Arrays.toString(extraArtifactsArr)); + for(int index=0; index[0])); + } + private static String toSha1(byte[] toHash) { return toHexS("%040x", "SHA-1", toHash); }