Skip to content

Commit

Permalink
feat (java): Introduce initial Maven & JBang support
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Dec 29, 2024
1 parent a3c7c74 commit d9fcbc0
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
37 changes: 37 additions & 0 deletions docs/dev/jbang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
SPDX-License-Identifier: Apache-2.0
Copyright 2024 The Enola <https://enola.dev> 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.
-->

# JBang

Java developers (not end-users) can use Enola via [JBang](https://www.jbang.dev/).

<!-- TODO [`learn/jbang`](https://github.com/enola-dev/enola/tree/main/learn/jbang) --> `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

<!-- TODO Improve JBang integration:
1. Build Enola on JitPack, and remove the need for step #1.
2. Move `learn/jbang` out into a separate Git repo?
(But then how to test it in CI?
A Monorepo is very nice for that.
Perhaps just write a script to automagically extract (copy) it into a small repo?
-->
9 changes: 5 additions & 4 deletions java/dev/enola/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
jdk:
- openjdk21

install:
- tools/maven/install.bash
24 changes: 24 additions & 0 deletions learn/jbang/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
SPDX-License-Identifier: Apache-2.0
Copyright 2024 The Enola <https://enola.dev> 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.
-->

# Using Enola.dev with JBang

See documentation, [local](../../docs/dev/jbang.md) or on <!--
TODO [docs.enola.dev](https://docs.enola.dev/dev/jbang/)! --> docs.enola.dev!

This is tested by `//tools/maven/test.bash`.
28 changes: 28 additions & 0 deletions learn/jbang/hello.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> 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());
}
2 changes: 1 addition & 1 deletion mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ nav:
# - Java:
# - Maven:
# - JavaDoc:
# - JBang:
- JBang: dev/jbang.md
# - Contributors:
- Set-Up: dev/setup.md
- IDE: dev/ide.md
Expand Down
29 changes: 29 additions & 0 deletions tools/maven/install.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2023-2024 The Enola <https://enola.dev> 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=
22 changes: 22 additions & 0 deletions tools/maven/test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2023-2024 The Enola <https://enola.dev> 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
3 changes: 3 additions & 0 deletions tools/test-ci/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d9fcbc0

Please sign in to comment.