Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Bazel build definition #216

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.1.0
23 changes: 0 additions & 23 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/

8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
java_library (
name = "maven_test_deps",
visibility = ["//src/test/java:__subpackages__"],
exports = [
"@maven//:junit_junit",
"@maven//:org_hamcrest_hamcrest",
],
)
127 changes: 127 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
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",
],
repositories = [
# Private repositories are supported through HTTP Basic auth
"https://jitpack.io",
"https://repo1.maven.org/maven2",
],
)

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")

MULTIADDR_BUILD_FILE = """
filegroup(
name = "main_srcs",
srcs = glob(["src/main/java/**"]),
)

java_library(
name = "core",
srcs = [":main_srcs"],
deps = [
"@multihash//:core",
"@multibase//:core",
"@cid//:core",
],
visibility = ["//visibility:public"],
)
"""

new_git_repository(
name = "multiaddr",
remote = "https://github.com/multiformats/java-multiaddr.git",
tag = "v1.4.12",
build_file_content = MULTIADDR_BUILD_FILE,
)

MULTIHASH_BUILD_FILE = """
filegroup(
name = "main_srcs",
srcs = glob(["src/main/java/**"]),
)

java_library(
name = "core",
srcs = [":main_srcs"],
deps = [
"@multibase//:core",
],
visibility = ["//visibility:public"],
)
"""

new_git_repository(
name = "multihash",
remote = "https://github.com/multiformats/java-multihash.git",
tag = "v1.3.4",
build_file_content = MULTIHASH_BUILD_FILE,
)

MULTIBASE_BUILD_FILE = """
filegroup(
name = "main_srcs",
srcs = glob(["src/main/java/**"]),
)

java_library(
name = "core",
srcs = [":main_srcs"],
visibility = ["//visibility:public"],
)
"""

new_git_repository(
name = "multibase",
remote = "https://github.com/multiformats/java-multibase.git",
tag = "v1.1.1",
build_file_content = MULTIBASE_BUILD_FILE,
)

CID_BUILD_FILE = """
filegroup(
name = "main_srcs",
srcs = glob(["src/main/java/**"]),
)

java_library(
name = "core",
srcs = [":main_srcs"],
deps = [
"@multihash//:core",
"@multibase//:core",
],
visibility = ["//visibility:public"],
)
"""

new_git_repository(
name = "cid",
remote = "https://github.com/ipld/java-cid.git",
tag = "v1.3.8",
build_file_content = CID_BUILD_FILE,
)
14 changes: 14 additions & 0 deletions src/main/java/io/ipfs/api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
java_library (
name = "core",
visibility = ["//visibility:public"],
srcs = glob(["*.java"]),
deps = [
"@multiaddr//:core",
"@multihash//:core",
"@multibase//:core",
"@cid//:core",
"//src/main/java/io/ipfs/api/cbor:cbor",
],
)

#TODO generate a distribution JAR with all the classes and the manifest
10 changes: 10 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,10 @@
java_library (
name = "cbor",
visibility = ["//visibility:public"],
srcs = glob(["*.java"]),
deps = [
"@multiaddr//:core",
"@multihash//:core",
"@cid//:core",
],
)
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
11 changes: 11 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,11 @@
java_binary (
name = "demo",
srcs = glob(["*.java"]),
main_class = "io.ipfs.api.demo.UsageMFSFilesAPI",
deps = [
"//src/main/java/io/ipfs/api:core",
"@multiaddr//:core",
"@multihash//:core",
"@cid//:core",
],
)
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")

7 changes: 6 additions & 1 deletion src/test/java/io/ipfs/api/APITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,13 @@ public void addArgsTest() {
assertEquals("args toQueryString() format", "inline=true&cid-version=1", queryStr);
}

@Test
public void failOnPurposeTest() {
assertEquals(1, 2);
}

// this api is disabled until deployment over IPFS is enabled
public void updateTest() throws IOException {
private void updateTest() throws IOException {
Object check = ipfs.update.check();
Object update = ipfs.update();
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/io/ipfs/api/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
java_library (
name = "test-core",
visibility = ["//visibility:public"],
srcs = glob(["*.java"]),
deps = [
"@multiaddr//:core",
"@multihash//:core",
"@multibase//:core",
"@cid//:core",
"//src/main/java/io/ipfs/api:core",
"//src/main/java/io/ipfs/api/cbor:cbor",
"//:maven_test_deps",
],
)
11 changes: 11 additions & 0 deletions src/test/test_utils.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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",
],
)