diff --git a/documentation/src/main/minisite/content/_partials/ci.jshell.main.java b/documentation/src/main/minisite/content/_partials/ci.jshell.main.java new file mode 100644 index 00000000000..6a51592d213 --- /dev/null +++ b/documentation/src/main/minisite/content/_partials/ci.jshell.main.java @@ -0,0 +1,21 @@ +import io.yupiik.kubernetes.bindings.v1_24_3.v1.*; + +class Generator { + public void generate() { + final var output = Files.createDirectories(Path.of("target/k8s-descriptors")); + + final var deployment = new Deployment() + .spec(new DeploymentSpec() + /* ... */); + + Files.writeString( + output.resolve("my-deployment.json"), + deployment.asJson()); + } +} + +class Runner { // enables to code in an IDE even if not needed by JShell + public static void main(final String... args) throws Exception { + new Generator().generate(); + } +} diff --git a/documentation/src/main/minisite/content/ci-setup.adoc b/documentation/src/main/minisite/content/ci-setup.adoc index 897cfdf6ef7..169f938487c 100644 --- a/documentation/src/main/minisite/content/ci-setup.adoc +++ b/documentation/src/main/minisite/content/ci-setup.adoc @@ -100,6 +100,14 @@ include::{partialsdir}/ci.jshell.java[] <.> A small trick to write a readable script is to enable multiline snippet by wrapping the code in a block (rest of the code is similar to previous ones), <.> Finally when finished we exit JShell. +TIP: a way to write the script as a standard Java code with classes and a final standard main class (`Runner`). This will enable you to setup the dependencies in your IDE and run the main as a standard class (ensure to name your file `.java`). +Then to execute it through JShell - where `/exit` is needed - use this command: `echo 'Runner.main();/exit' | jshell --class-path .... --startup .java`. +This will automatically load your script and exeute the main before exiting the shell. +[source,java] +---- +include::{partialsdir}/ci.jshell.main.java[] +---- + == JBang Setup link:https://www.jbang.dev/[JBang] can also be used to generate your descriptors.