Skip to content

Commit

Permalink
Initial Bazel build definition
Browse files Browse the repository at this point in the history
  • Loading branch information
odisseus committed Feb 28, 2023
1 parent 07395a0 commit 9e4bcc1
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 23 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/ant.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ TEST-io.ipfs.api.APITest.*
.idea/*
api.iml

# Bazel
/bazel-*
/.ijwb/

10 changes: 10 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
java_library (
name = "maven_deps",
visibility = ["//visibility:public"],
exports = [
"@maven//:com_github_multiformats_java_multiaddr",
"@maven//:com_github_multiformats_java_multihash",
"@maven//:com_github_multiformats_java_multibase",
"@maven//:com_github_ipld_java_cid",
],
)
34 changes: 34 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

RULES_JVM_EXTERNAL_TAG = "4.5"
RULES_JVM_EXTERNAL_SHA = "b17d7388feb9bfa7f2fa09031b32707df529f26c91ab9e5d909eb1676badd9a6"

http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
artifacts = [
"junit:junit:4.13.2",
"org.hamcrest:hamcrest:2.2",
"com.github.multiformats:java-multiaddr:v1.4.10",
],
repositories = [
# Private repositories are supported through HTTP Basic auth
"https://jitpack.io",
"https://repo1.maven.org/maven2",
],
)
11 changes: 11 additions & 0 deletions src/main/java/io/ipfs/api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
java_library (
name = "core",
visibility = ["//visibility:public"],
srcs = glob(["*.java"]),
deps = [
"//src/main/java/io/ipfs/api/cbor:cbor",
"//:maven_deps",
],
)

#TODO generate a distribution JAR with all the classes and the manifest
8 changes: 8 additions & 0 deletions src/main/java/io/ipfs/api/cbor/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
java_library (
name = "cbor",
visibility = ["//visibility:public"],
srcs = glob(["*.java"]),
deps = [
"//:maven_deps",
],
)
3 changes: 2 additions & 1 deletion src/main/java/io/ipfs/api/cbor/CborDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import java.io.*;
import java.util.Arrays;

import static io.ipfs.api.cbor.CborConstants.*;
import static io.ipfs.api.cbor.CborType.*;
Expand All @@ -30,7 +31,7 @@ public CborDecoder(InputStream is) {
}

private static void fail(String msg, Object... args) throws IOException {
throw new IOException(msg + args);
throw new IOException(msg + Arrays.toString(args));
}

private static String lengthToString(int len) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/ipfs/api/demo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
java_binary (
name = "demo",
srcs = glob(["*.java"]),
main_class = "io.ipfs.api.demo.UsageMFSFilesAPI",
deps = [
"//src/main/java/io/ipfs/api:core",
"//:maven_deps",
],
)
15 changes: 15 additions & 0 deletions src/test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load(":test_utils.bzl", "junit_test")

filegroup(
name = "test-resources",
srcs = glob([
"resources/**",
]),
)

junit_test(test_class = "io.ipfs.api.AddTest")
junit_test(test_class = "io.ipfs.api.APITest")
junit_test(test_class = "io.ipfs.api.RecursiveAddTest")
junit_test(test_class = "io.ipfs.api.SimpleAddTest")
junit_test(test_class = "io.ipfs.api.VersionsTest")

12 changes: 12 additions & 0 deletions src/test/java/io/ipfs/api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
java_library (
name = "test-core",
visibility = ["//visibility:public"],
srcs = glob(["*.java"]),
deps = [
"//src/main/java/io/ipfs/api:core",
"//src/main/java/io/ipfs/api/cbor:cbor",
"//:maven_deps",
"@maven//:junit_junit",
"@maven//:org_hamcrest_hamcrest",
],
)
14 changes: 14 additions & 0 deletions src/test/test_utils.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def junit_test(test_class):
native.java_test(
name = test_class,
test_class = test_class,
runtime_deps = [
"//src/test/java/io/ipfs/api:test-core",
],
data = [
"//src/test:test-resources",
],
jvm_flags = [
"-Djava.security.manager=allow",
]
)

0 comments on commit 9e4bcc1

Please sign in to comment.