From bc15ac298dfc27b157a09b2d7b83814569fa1480 Mon Sep 17 00:00:00 2001 From: Jordan Sim-Smith Date: Thu, 8 Aug 2024 13:36:50 +1200 Subject: [PATCH] Configure dagger --- MODULE.bazel | 12 ++++++++++++ MODULE.bazel.lock | 5 ++++- immersion_tracker_api/BUILD.bazel | 17 +++++++++++++++++ .../immersiontracker/GetProgressHandler.java | 8 +++++++- .../jordansimsmith/immersiontracker/Hello.java | 13 +++++++++++++ .../ImmersionTrackerComponent.java | 8 ++++++++ 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/Hello.java create mode 100644 immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/ImmersionTrackerComponent.java diff --git a/MODULE.bazel b/MODULE.bazel index 1b3e487..4d1aed5 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -5,6 +5,15 @@ module( bazel_dep(name = "rules_java", version = "7.7.0") bazel_dep(name = "rules_jvm_external", version = "6.1") +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "dagger", + sha256 = "4062fa2cda8dab32d1961fb10ed50f40aca759149efb64dd5a08077a6fcb2fbc", + strip_prefix = "dagger-dagger-2.52", + url = "https://github.com/google/dagger/archive/dagger-2.52.zip", +) + maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") maven.install( artifacts = [ @@ -24,6 +33,9 @@ maven.install( "software.amazon.awssdk:dynamodb-enhanced:2.26.19", "com.google.guava:guava:33.2.1-jre", "com.amazonaws:aws-lambda-java-core:1.2.3", + "com.google.dagger:dagger:2.52", + "com.google.dagger:dagger-compiler:2.52", + "com.google.dagger:dagger-producers:2.52", ], ) use_repo(maven, "maven") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index e91e9db..95c5c90 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -1290,7 +1290,7 @@ "@@rules_jvm_external~//:extensions.bzl%maven": { "general": { "bzlTransitiveDigest": "Pq3YnJEflPAALx/UMykUnN3aA5bve0fNm/cuLvt/zvI=", - "usagesDigest": "s0eL47jL2r0N07wKfYiHIg2drG57rlfxt5BqjckYZEE=", + "usagesDigest": "xwPbWH6yakHmlR8DAMxHCjXY30aL2XbAaDztxrDcAJM=", "recordedFileInputs": { "@@rules_jvm_external~//rules_jvm_external_deps_install.json": "0bfbc915d9155df44d7a3b216e8f3c1fbcd110e358dd07637dc393583a5227e8", "@@contrib_rules_jvm~//contrib_rules_jvm_deps_install.json": "c65d8722c471d3b75be39f94e3c4a6ce19c4e377e96cb9b28746ac559f6267de" @@ -6672,6 +6672,9 @@ "{ \"group\": \"software.amazon.awssdk\", \"artifact\": \"dynamodb-enhanced\", \"version\": \"2.26.19\" }", "{ \"group\": \"com.google.guava\", \"artifact\": \"guava\", \"version\": \"33.2.1-jre\" }", "{ \"group\": \"com.amazonaws\", \"artifact\": \"aws-lambda-java-core\", \"version\": \"1.2.3\" }", + "{ \"group\": \"com.google.dagger\", \"artifact\": \"dagger\", \"version\": \"2.52\" }", + "{ \"group\": \"com.google.dagger\", \"artifact\": \"dagger-compiler\", \"version\": \"2.52\" }", + "{ \"group\": \"com.google.dagger\", \"artifact\": \"dagger-producers\", \"version\": \"2.52\" }", "{ \"group\": \"com.google.code.findbugs\", \"artifact\": \"jsr305\", \"version\": \"3.0.2\" }", "{ \"group\": \"com.google.code.gson\", \"artifact\": \"gson\", \"version\": \"2.8.9\" }", "{ \"group\": \"com.google.errorprone\", \"artifact\": \"error_prone_annotations\", \"version\": \"2.3.2\" }", diff --git a/immersion_tracker_api/BUILD.bazel b/immersion_tracker_api/BUILD.bazel index bc540fa..764399e 100644 --- a/immersion_tracker_api/BUILD.bazel +++ b/immersion_tracker_api/BUILD.bazel @@ -1,10 +1,27 @@ load("@contrib_rules_jvm//java:defs.bzl", "JUNIT5_DEPS", "java_test_suite") +load("@dagger//:workspace_defs.bzl", "dagger_rules") + +dagger_rules() + +HANDLERS = glob(["src/main/java/**/*Handler.java"]) + +java_library( + name = "lib", + srcs = glob( + ["src/main/java/**/*.java"], + exclude = HANDLERS, + ), + deps = [ + ":dagger", + ], +) java_binary( name = "get-progress-handler", srcs = glob(["src/main/java/com/jordansimsmith/immersiontracker/GetProgressHandler.java"]), create_executable = False, deps = [ + ":lib", "@maven//:com_amazonaws_aws_lambda_java_core", ], ) diff --git a/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/GetProgressHandler.java b/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/GetProgressHandler.java index 1f5fc77..bc6bbfe 100644 --- a/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/GetProgressHandler.java +++ b/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/GetProgressHandler.java @@ -4,8 +4,14 @@ import com.amazonaws.services.lambda.runtime.RequestHandler; public class GetProgressHandler implements RequestHandler { + private final Hello hello; + + public GetProgressHandler() { + this.hello = DaggerImmersionTrackerComponent.create().hello(); + } + @Override public String handleRequest(Object s, Context context) { - return "hello, world"; + return hello.hello(); } } diff --git a/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/Hello.java b/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/Hello.java new file mode 100644 index 0000000..a7e320c --- /dev/null +++ b/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/Hello.java @@ -0,0 +1,13 @@ +package com.jordansimsmith.immersiontracker; + +import javax.inject.Inject; + +public class Hello { + + @Inject + public Hello() {} + + public String hello() { + return "hello, world"; + } +} diff --git a/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/ImmersionTrackerComponent.java b/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/ImmersionTrackerComponent.java new file mode 100644 index 0000000..f53f83c --- /dev/null +++ b/immersion_tracker_api/src/main/java/com/jordansimsmith/immersiontracker/ImmersionTrackerComponent.java @@ -0,0 +1,8 @@ +package com.jordansimsmith.immersiontracker; + +import dagger.Component; + +@Component +public interface ImmersionTrackerComponent { + Hello hello(); +}