From d9fcbc02fb2289884a6651ff4f0f6fcab86195ef Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Sun, 29 Dec 2024 19:29:22 +0100 Subject: [PATCH] feat (java): Introduce initial Maven & JBang support --- .pre-commit-config.yaml | 2 ++ .vscode/extensions.json | 3 ++- .vscode/settings.json | 7 +++++-- docs/dev/jbang.md | 37 +++++++++++++++++++++++++++++++++++++ java/dev/enola/BUILD | 9 +++++---- jitpack.yml | 5 +++++ learn/jbang/README.md | 24 ++++++++++++++++++++++++ learn/jbang/hello.java | 28 ++++++++++++++++++++++++++++ mkdocs.yaml | 2 +- tools/maven/install.bash | 29 +++++++++++++++++++++++++++++ tools/maven/test.bash | 22 ++++++++++++++++++++++ tools/test-ci/test.bash | 3 +++ 12 files changed, 163 insertions(+), 8 deletions(-) create mode 100644 docs/dev/jbang.md create mode 100644 jitpack.yml create mode 100644 learn/jbang/README.md create mode 100644 learn/jbang/hello.java create mode 100755 tools/maven/install.bash create mode 100755 tools/maven/test.bash diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 695bf835e..578465662 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -115,6 +115,8 @@ repos: - id: pretty-format-java # Keep this version in sync with the same version in .vscode/settings.json args: [--autofix, --aosp, --google-java-formatter-version=1.25.1] + # See https://github.com/google/google-java-format/issues/1216 + exclude: learn/jbang - repo: https://github.com/DavidAnson/markdownlint-cli2 rev: v0.16.0 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 47724dcca..7928d830a 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -18,7 +18,8 @@ "stardog-union.vscode-langserver-turtle", "zazuko.vscode-rdf-sketch", "redhat.vscode-yaml", - "gruntfuggly.todo-tree" + "gruntfuggly.todo-tree", + "jbangdev.jbang-vscode" ], "unwantedRecommendations": [ // https://github.com/kshetline/ligatures-limited/issues/39 diff --git a/.vscode/settings.json b/.vscode/settings.json index 088a65668..62c705658 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -164,7 +164,10 @@ "tools": false, "web": false, "BUILT": false, - ".built": true, - "third_party": false + ".built": false, + "third_party": false, + ".jbang": false, + "META-INF": false, + "learn": false } } diff --git a/docs/dev/jbang.md b/docs/dev/jbang.md new file mode 100644 index 000000000..8960fa8c5 --- /dev/null +++ b/docs/dev/jbang.md @@ -0,0 +1,37 @@ + + +# JBang + +Java developers (not end-users) can use Enola via [JBang](https://www.jbang.dev/). + + `learn/jbang` +has an example project illustrating how this works; clone and go there, and then: + +1. `tools/maven/install.bash` +1. `cd learn/jbang` +1 `./jbang hello.java` will run an example using Enola +1. `./jbang edit --sandbox --open=code hello.java` opens an IDE + + diff --git a/java/dev/enola/BUILD b/java/dev/enola/BUILD index 448578562..a4297f69c 100644 --- a/java/dev/enola/BUILD +++ b/java/dev/enola/BUILD @@ -15,7 +15,7 @@ # limitations under the License. load("@rules_java//java:defs.bzl", "java_library") -# TODO load("@rules_jvm_external//:defs.bzl", "java_export") +load("@rules_jvm_external//:defs.bzl", "java_export") java_library( name = "api", @@ -30,10 +30,11 @@ java_library( ], ) -# TODO java_export -java_library( +java_export( name = "enola", - # TODO maven_coordinates = "dev.enola:enola:main-SNAPSHOT", + maven_coordinates = "dev.enola:enola:0.0.1-SNAPSHOT", + # TODO Fix JavaDoc generation which somehow breaks the build; see https://github.com/enola-dev/enola/issues/491 + tags = ["no-javadocs"], visibility = ["//:__subpackages__"], runtime_deps = [ "//java/dev/enola/common", diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 000000000..4ff23750a --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,5 @@ +jdk: + - openjdk21 + +install: + - tools/maven/install.bash diff --git a/learn/jbang/README.md b/learn/jbang/README.md new file mode 100644 index 000000000..0204ca4be --- /dev/null +++ b/learn/jbang/README.md @@ -0,0 +1,24 @@ + + +# Using Enola.dev with JBang + +See documentation, [local](../../docs/dev/jbang.md) or on docs.enola.dev! + +This is tested by `//tools/maven/test.bash`. diff --git a/learn/jbang/hello.java b/learn/jbang/hello.java new file mode 100644 index 000000000..501225d2a --- /dev/null +++ b/learn/jbang/hello.java @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2024 The Enola Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//JAVA 21 +//COMPILE_OPTIONS --enable-preview -source 21 +//RUNTIME_OPTIONS --enable-preview +//DEPS dev.enola:enola:0.0.1-SNAPSHOT + +import static java.lang.System.out; + +void main() { + out.println("Hello World: " + dev.enola.common.Version.get()); +} diff --git a/mkdocs.yaml b/mkdocs.yaml index df58c8aa2..149821753 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -88,7 +88,7 @@ nav: # - Java: # - Maven: # - JavaDoc: - # - JBang: + - JBang: dev/jbang.md # - Contributors: - Set-Up: dev/setup.md - IDE: dev/ide.md diff --git a/tools/maven/install.bash b/tools/maven/install.bash new file mode 100755 index 000000000..cc8ee4126 --- /dev/null +++ b/tools/maven/install.bash @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2023-2024 The Enola Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euox pipefail + +# This installs the Maven Artifacts into a local repository... + +bazelisk build //java/dev/enola + +./java/mvnw install:install-file \ + -Dfile=bazel-bin/java/dev/enola/enola-project.jar \ + -Dsources=bazel-bin/java/dev/enola/enola-project-src.jar \ + -DpomFile=bazel-bin/java/dev/enola/enola-pom.xml + +# TODO -Djavadoc= diff --git a/tools/maven/test.bash b/tools/maven/test.bash new file mode 100755 index 000000000..8ba58823a --- /dev/null +++ b/tools/maven/test.bash @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2023-2024 The Enola Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euox pipefail + +tools/maven/install.bash + +learn/jbang/jbang learn/jbang/hello.java diff --git a/tools/test-ci/test.bash b/tools/test-ci/test.bash index 088f4f803..8adcdc761 100755 --- a/tools/test-ci/test.bash +++ b/tools/test-ci/test.bash @@ -39,3 +39,6 @@ tools/git/test.bash # Test distros: 1. End-user distributed executable fat über JAR, 2. Container Image tools/distro/test.bash + +# Test Maven repo, via JBang integration support +tools/maven/test.bash