Skip to content

Commit

Permalink
doc: make sure libraries version are sync/up-to-date with Maven
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Sep 7, 2024
1 parent 036f079 commit 4b3ab1d
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/asciidoc/handlers/rate-limit.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Rate limit handler using https://github.com/vladimir-bukhtoyarov/bucket4j[Bucket

Add the dependency to your project:

[dependency, artifactId="bucket4j-core"]
[dependency, artifactId="bucket4j-core", version="{bucket4j_core_version}", subs="verbatim,attributes"]
.

.10 requests per minute
Expand Down
1 change: 0 additions & 1 deletion docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Style guidelines:
////

= Welcome to Jooby!
by Edgar Espina
{joobyVersion}

[discrete]
Expand Down
14 changes: 7 additions & 7 deletions docs/asciidoc/modules/avaje-inject.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

1) Add Avaje Inject to your project

[dependency, groupId="io.jooby", artifactId="jooby-avaje-inject", version="1.1.0"]
[dependency, artifactId="jooby-avaje-inject"]
.

2) Configure annotation processor

.Maven
[source, xml, role = "primary"]
[source, xml, role = "primary", subs="verbatim,attributes"]
----
<build>
<plugins>
Expand All @@ -21,7 +21,7 @@
<path>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject-generator</artifactId>
<version>10.3</version>
<version>{avaje_inject_version}</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand All @@ -31,14 +31,14 @@
----

.Gradle
[source, kotlin, role = "secondary"]
[source, kotlin, role = "secondary", subs="verbatim,attributes"]
----
plugins {
id "org.jetbrains.kotlin.kapt" version "1.9.10"
}
dependencies {
kapt 'io.avaje:avaje-inject-generator:10.0'
kapt 'io.avaje:avaje-inject-generator:{avaje.inject.version}'
}
----

Expand Down Expand Up @@ -127,7 +127,7 @@ public class App extends Jooby {
{
install(AvajeInjectModule.of()); <1>
mvc(MyController.class); <2>
mvc(MyController.class); <2>
}
public static void main(String[] args) {
Expand All @@ -143,7 +143,7 @@ fun main(args: Array<String>) {
runApp(args) {
install(AvajeInjectModule.of()) <1>
mvc(MyController::class) <2>
mvc(MyController::class) <2>
}
}
----
Expand Down
9 changes: 5 additions & 4 deletions docs/asciidoc/modules/avaje-validator.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Bean validation via https://avaje.io/validator/[Avaje Validator].
2) Configure annotation processor

.Maven
[source, xml, role = "primary"]
[source, xml, role = "primary", subs="verbatim,attributes"]
----
<build>
<plugins>
Expand All @@ -25,7 +25,7 @@ Bean validation via https://avaje.io/validator/[Avaje Validator].
<path>
<groupId>io.avaje</groupId>
<artifactId>avaje-validator-generator</artifactId>
<version>2.1</version>
<version>{avajeValidatorVersion}</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand All @@ -35,14 +35,14 @@ Bean validation via https://avaje.io/validator/[Avaje Validator].
----

.Gradle
[source, kotlin, role = "secondary"]
[source, kotlin, role = "secondary", subs="verbatim,attributes"]
----
plugins {
id "org.jetbrains.kotlin.kapt" version "1.9.10"
}
dependencies {
kapt 'io.avaje:avaje-validator-generator:2.1'
kapt 'io.avaje:avaje-validator-generator:{avajeValidatorVersion}'
}
----

Expand Down Expand Up @@ -177,6 +177,7 @@ It also supports validating list, array, and map of beans
catches `ConstraintViolationException` and transforms it into the following response:

.JSON:
[source, json]
----
{
"title": "Validation failed",
Expand Down
72 changes: 72 additions & 0 deletions docs/asciidoc/modules/awssdkv2.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
== AmazonWebServices

Amazon Web Services module for https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html[aws-sdk-java 2.x]

=== Usage

1) Add the dependency:

[dependency, artifactId="jooby-awssdk-v2", version="{aws_java_sdk_version}", subs="verbatim,attributes"]
.

2) Add required service dependency (S3 here):

[dependency, artifactId="s3"]
.

3) Add the `aws.accessKeyId` and `aws.secretKey` properties:

.application.conf
[source, properties]
----
aws.accessKeyId = "your access key id"
aws.secretKey = "your secret key"
----

This step is optional if you choose one of the https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials-chain.html[default credentials mechanism].

4) Install

.Java
[source,java,role="primary"]
----
import io.jooby.awssdkv2.AwsModule;
{
install(
new AwsModule() <1>
.setup(credentials -> { <2>
var s3 = S3Client.builder().build();
var s3transfer = S3TransferManager.builder().s3Client(s3).build();
return Stream.of(s3, s3transfer);
})
)
);
}
----

.Kotlin
[source, kt, role="secondary"]
----
import io.jooby.awssdkv2.AwsModule
{
install(
AwsModule() <1>
.setup { credentials -> <2>
val s3 = S3Client.builder().build()
val s3transfer = S3TransferManager.builder().s3Client(s3).build()
return Stream.of(s3, s3transfer)
}
)
);
}
----

<1> Install module
<2> Setup one or more services

Services created from setup function are:

- Registered in the application service registry, for require call usage or DI framework
- Services are shutdown at application shutdown time
1 change: 1 addition & 0 deletions docs/asciidoc/modules/hibernate-validator.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ It also supports validating list, array, and map of beans
catches `ConstraintViolationException` and transforms it into the following response:

.JSON:
[source, json]
----
{
"title": "Validation failed",
Expand Down
3 changes: 2 additions & 1 deletion docs/asciidoc/modules/modules.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ configuration properties.
Available modules are listed next.

=== Cloud
* link:/modules/aws[AWS]: Amazon Web Service module.
* link:/modules/awssdkv2[AWS-SDK v2]: Amazon Web Service module SDK 2.
* link:/modules/aws[AWS SDK v1]: Amazon Web Service module SDK 1.

=== Data
* link:/modules/ebean[Ebean]: Ebean ORM module.
Expand Down
23 changes: 15 additions & 8 deletions docs/src/main/java/io/jooby/adoc/DependencyProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
package io.jooby.adoc;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.Consumer;

import org.asciidoctor.ast.StructuralNode;
Expand All @@ -28,18 +25,28 @@ public Object process(StructuralNode parent, Reader reader, Map<String, Object>
List<String> lines = new ArrayList<>();
String[] artifactId = ((String) attributes.get("artifactId")).split("\\s*,\\s*");

var groupId = (String) attributes.get("groupId");
var version = (String) attributes.get("version");
if (version== null || version.trim().isEmpty()) {
if (artifactId.length== 1 && !artifactId[0].startsWith("jooby")) {
version = Optional.ofNullable(Dependencies.get(artifactId[0])).map(it -> it.version).orElse(null);
if (version== null) {
throw new IllegalArgumentException("Dependency without version: " + groupId + ":" + Arrays.toString(artifactId));
}
}
}
maven(
(String) attributes.get("groupId"),
groupId,
artifactId,
(String) attributes.get("version"),
version,
lines::add);

lines.add("");

gradle(
(String) attributes.get("groupId"),
groupId,
artifactId,
(String) attributes.get("version"),
version,
lines::add);
lines.add("");

Expand Down
6 changes: 6 additions & 0 deletions docs/src/main/java/io/jooby/adoc/DocApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public class DocApp extends Jooby {

Path site = DocGenerator.basedir().resolve("asciidoc").resolve("site");
assets("/*", site);

onStarted(() ->
getLog().info("Access to maven properties is available from ascii files. If you want to access to `${avaje.inject.version}` uses the `{avaje_inject_version}` syntax and make sure to set the `subs` attribute, like:\n\n" +
"[source, xml, role = \"primary\", subs=\"verbatim,attributes\"]\n" +
" .... {avaje_inject_version}\n")
);
}

public static void main(String[] args) throws Exception {
Expand Down
8 changes: 6 additions & 2 deletions docs/src/main/java/io/jooby/adoc/DocGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,12 @@ private static Options createOptions(Path basedir, Path outdir, String version,
// versions:
Document pom =
Jsoup.parse(DocGenerator.basedir().getParent().resolve("pom.xml").toFile(), "UTF-8");
pom.select("properties > *").stream()
.forEach(tag -> attributes.setAttribute(toJavaName(tag.tagName()), tag.text().trim()));
pom.select("properties > *").forEach(tag -> {
var tagName = tag.tagName();
var value = tag.text().trim();
Stream.of(tagName, tagName.replaceAll("[.-]", "_"), tagName.replaceAll("[.-]", "-"), toJavaName(tagName))
.forEach(key -> attributes.setAttribute(key, value));
});

attributes.setAttribute("joobyVersion", version);
attributes.setAttribute("date", DateTimeFormatter.ISO_INSTANT.format(Instant.now()));
Expand Down

0 comments on commit 4b3ab1d

Please sign in to comment.