Skip to content

Commit 4e65bab

Browse files
committed
feat(java): java implementation of dotprompt
1 parent 267ead1 commit 4e65bab

21 files changed

+1926
-47
lines changed

.github/workflows/publish_java.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
17+
name: Publish Java Package
18+
19+
on:
20+
release:
21+
types: [created]
22+
23+
jobs:
24+
publish-java:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Set up JDK 21
32+
uses: actions/setup-java@v4
33+
with:
34+
java-version: '21'
35+
distribution: 'temurin'
36+
37+
- name: Setup Bazel
38+
uses: bazelbuild/setup-bazelisk@v3
39+
40+
- name: Import GPG key
41+
id: import_gpg
42+
uses: crazy-max/ghaction-import-gpg@v6
43+
with:
44+
gpg_private_key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
45+
passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
46+
47+
- name: Publish to Maven Central
48+
env:
49+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
50+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
51+
run: |
52+
./scripts/publish-java.sh \
53+
"${{ steps.import_gpg.outputs.keyring }}" \
54+
"${{ secrets.MAVEN_GPG_PASSPHRASE }}" \
55+
"$MAVEN_USERNAME" \
56+
"$MAVEN_PASSWORD"

docs/contributing/coding_guidelines.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ You are an expert Python developer contributing to the Google Dotprompt project.
77
- **Language**: Python.
88
- **Environment Management**: Use `uv` for packaging and environment management.
99

10+
### Libraries
11+
- **JSON**: Use **Jackson** for JSON parsing and serialization. Avoid Gson.
12+
- **Testing**: Use **Google Truth** (`com.google.truth.Truth`) for assertions. Use JUnit 4/5 for test runners.
13+
- **Async**: Use **Dagger Producers** for asynchronous operations where applicable.
14+
- **Utilities**: Use **Guava** for immutable collections and common utilities.
15+
- **Dependency Injection**: Use **Dagger** for dependency injection.
16+
1017
## 2. Typing & Style
1118
- **Type Unions**: Use the pipe operator `|` (PEP 604) for union types (e.g., `int | str`) instead of `typing.Union`. Use `| None` for optional types.
1219
- **Generics**: Use standard collection generics (PEP 585) like `list`, `dict`, `tuple` (lowercase) for type hints instead of `typing.List`, `typing.Dict`.

java.MODULE.bazel

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ maven.install(
5050
"com.google.truth:truth:1.4.4",
5151
"com.github.jknack:handlebars:4.4.0",
5252
"com.google.guava:guava:33.4.8-jre",
53+
"com.google.dagger:dagger:2.55",
54+
"com.google.dagger:dagger-compiler:2.55",
55+
"com.google.dagger:dagger-producers:2.55",
56+
"com.fasterxml.jackson.core:jackson-databind:2.18.2",
57+
"com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.2",
58+
"javax.inject:javax.inject:1",
5359
],
5460
lock_file = "//:maven_install.json",
5561
repositories = [

java/com/google/dotprompt/BUILD.bazel

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,83 @@
1313
# limitations under the License.
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
16+
17+
load("@rules_java//java:defs.bzl", "java_library", "java_test")
18+
load("@rules_jvm_external//:defs.bzl", "java_export")
19+
20+
java_library(
21+
name = "dotprompt",
22+
srcs = glob(
23+
["**/*.java"],
24+
exclude = ["**/*Test.java"],
25+
),
26+
deps = [
27+
"@maven//:com_fasterxml_jackson_core_jackson_annotations",
28+
"@maven//:com_fasterxml_jackson_core_jackson_core",
29+
"@maven//:com_fasterxml_jackson_core_jackson_databind",
30+
"@maven//:com_fasterxml_jackson_dataformat_jackson_dataformat_yaml",
31+
"@maven//:com_github_jknack_handlebars",
32+
"@maven//:com_google_dagger_dagger",
33+
"@maven//:com_google_dagger_dagger_producers",
34+
"@maven//:com_google_guava_guava",
35+
"@maven//:javax_inject_javax_inject",
36+
],
37+
visibility = ["//visibility:public"],
38+
)
39+
40+
java_export(
41+
name = "dotprompt_pkg",
42+
maven_coordinates = "com.google.dotprompt:dotprompt:0.1.0",
43+
pom_template = "pom_template.xml",
44+
visibility = ["//visibility:public"],
45+
runtime_deps = [":dotprompt"],
46+
)
47+
48+
java_test(
49+
name = "DotpromptTest",
50+
srcs = ["DotpromptTest.java"],
51+
test_class = "com.google.dotprompt.DotpromptTest",
52+
deps = [
53+
":dotprompt",
54+
"@maven//:com_google_guava_guava",
55+
"@maven//:com_google_truth_truth",
56+
"@maven//:junit_junit",
57+
],
58+
)
59+
60+
java_test(
61+
name = "SpecTest",
62+
srcs = ["SpecTest.java"],
63+
data = ["//spec"],
64+
test_class = "com.google.dotprompt.SpecTest",
65+
deps = [
66+
":dotprompt",
67+
"@maven//:com_fasterxml_jackson_core_jackson_databind",
68+
"@maven//:com_fasterxml_jackson_dataformat_jackson_dataformat_yaml",
69+
"@maven//:com_google_guava_guava",
70+
"@maven//:com_google_truth_truth",
71+
"@maven//:junit_junit",
72+
],
73+
)
74+
75+
java_test(
76+
name = "PromptLoaderTest",
77+
srcs = ["PromptLoaderTest.java"],
78+
test_class = "com.google.dotprompt.PromptLoaderTest",
79+
deps = [
80+
":dotprompt",
81+
"@maven//:com_google_truth_truth",
82+
"@maven//:junit_junit",
83+
],
84+
)
85+
86+
java_test(
87+
name = "ModelTest",
88+
srcs = ["ModelTest.java"],
89+
test_class = "com.google.dotprompt.ModelTest",
90+
deps = [
91+
":dotprompt",
92+
"@maven//:com_google_truth_truth",
93+
"@maven//:junit_junit",
94+
],
95+
)

0 commit comments

Comments
 (0)