Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Aug 31, 2023
1 parent e6929a3 commit 5992bae
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 89 deletions.
8 changes: 4 additions & 4 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ public abstract interface class com/hexagonkt/core/logging/LoggingPort {
public abstract fun setLoggerLevel (Ljava/lang/String;Lcom/hexagonkt/core/logging/LoggingLevel;)V
}

public final class com/hexagonkt/core/logging/PrintLogger : com/hexagonkt/core/logging/LoggerPort {
public final class com/hexagonkt/core/logging/SystemLogger : com/hexagonkt/core/logging/LoggerPort {
public fun <init> (Ljava/lang/String;)V
public final fun component1 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;)Lcom/hexagonkt/core/logging/PrintLogger;
public static synthetic fun copy$default (Lcom/hexagonkt/core/logging/PrintLogger;Ljava/lang/String;ILjava/lang/Object;)Lcom/hexagonkt/core/logging/PrintLogger;
public final fun copy (Ljava/lang/String;)Lcom/hexagonkt/core/logging/SystemLogger;
public static synthetic fun copy$default (Lcom/hexagonkt/core/logging/SystemLogger;Ljava/lang/String;ILjava/lang/Object;)Lcom/hexagonkt/core/logging/SystemLogger;
public fun equals (Ljava/lang/Object;)Z
public final fun getName ()Ljava/lang/String;
public fun hashCode ()I
Expand All @@ -276,7 +276,7 @@ public final class com/hexagonkt/core/logging/PrintLogger : com/hexagonkt/core/l
public fun toString ()Ljava/lang/String;
}

public final class com/hexagonkt/core/logging/PrintLoggingAdapter : com/hexagonkt/core/logging/LoggingPort {
public final class com/hexagonkt/core/logging/SystemLoggingAdapter : com/hexagonkt/core/logging/LoggingPort {
public fun <init> ()V
public fun <init> (Lcom/hexagonkt/core/logging/LoggingLevel;)V
public synthetic fun <init> (Lcom/hexagonkt/core/logging/LoggingLevel;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package com.hexagonkt.core.logging
import kotlin.reflect.KClass

/**
* Manages Logs using [PrintLoggingAdapter]
* Manages Logs using [SystemLoggingAdapter]
*/
object LoggingManager {
var useColor: Boolean = true
var adapter: LoggingPort = PrintLoggingAdapter()
var adapter: LoggingPort = SystemLoggingAdapter()
var defaultLoggerName: String = "com.hexagonkt.core.logging"
set(value) {
require(value.isNotEmpty()) { "Default logger name cannot be empty string" }
Expand Down
16 changes: 0 additions & 16 deletions core/src/main/kotlin/com/hexagonkt/core/logging/PrintLogger.kt

This file was deleted.

28 changes: 28 additions & 0 deletions core/src/main/kotlin/com/hexagonkt/core/logging/SystemLogger.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.hexagonkt.core.logging

import com.hexagonkt.core.logging.LoggingLevel.*

data class SystemLogger(val name: String) : LoggerPort {

private val logger: System.Logger = System.getLogger(name)

override fun <E : Throwable> log(level: LoggingLevel, exception: E, message: (E) -> Any?) {
if (LoggingManager.isLoggerLevelEnabled(name, level))
logger.log(level(level), message(exception).toString(), exception)
}

override fun log(level: LoggingLevel, message: () -> Any?) {
if (LoggingManager.isLoggerLevelEnabled(name, level))
logger.log(level(level), message())
}

private fun level(level: LoggingLevel): System.Logger.Level =
when (level) {
TRACE -> System.Logger.Level.TRACE
DEBUG -> System.Logger.Level.DEBUG
INFO -> System.Logger.Level.INFO
WARN -> System.Logger.Level.WARNING
ERROR -> System.Logger.Level.ERROR
OFF -> System.Logger.Level.OFF
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package com.hexagonkt.core.logging
import com.hexagonkt.core.logging.LoggingLevel.INFO
import com.hexagonkt.core.require

// TODO Wrap these loggers using System.Logger:
// https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/System.Logger.html
class PrintLoggingAdapter(defaultLevel: LoggingLevel = INFO) : LoggingPort {
class SystemLoggingAdapter(defaultLevel: LoggingLevel = INFO) : LoggingPort {

private val loggerLevels: MutableMap<String, LoggingLevel> = mutableMapOf("" to defaultLevel)

override fun createLogger(name: String): LoggerPort =
PrintLogger(name)
SystemLogger(name)

override fun setLoggerLevel(name: String, level: LoggingLevel) {
loggerLevels[name] = level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class LoggingManagerTest {
// TODO Repeat this test on other logging adapters
@Test fun `Loggers are enabled and disabled at runtime`() {

LoggingManager.adapter = PrintLoggingAdapter()
LoggingManager.adapter = SystemLoggingAdapter()
val allLevels = LoggingLevel.values()

val ch = Logger("com.hx")
Expand Down
6 changes: 4 additions & 2 deletions gradle/application.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tasks.register("jpackage") {

final String options = findProperty("options")
final String icon = findProperty("icon")
final String modules = findProperty("modules") ?: "java.logging"
final String modules = findProperty("modules")
final String jarAllName = "$name-all-${version}.jar"
final java.nio.file.Path jarAll = buildDir.resolve("libs/$jarAllName")
final java.nio.file.Path jpackageJar = buildDir.resolve("jpackage/$jarAllName")
Expand All @@ -78,10 +78,12 @@ tasks.register("jpackage") {
"--description", project.description ?: name,
"--name", name,
"--input", tmp.absolutePath,
"--add-modules", modules,
"--main-jar", jarAllName
]

if (modules != null)
command += [ "--add-modules", modules ]

if (options != null)
command += [ "--java-options", options ]

Expand Down
1 change: 1 addition & 0 deletions site/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ nav:
- Core: core.md
- HTTP Server: http_server.md
- HTTP Client: http_client.md
- Serialization: serialization.md
- Templates: templates.md
- Gradle Helpers: gradle.md
- Maven Parent POM: maven.md
Expand Down
83 changes: 47 additions & 36 deletions site/pages/gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ The build process and imported build scripts (like the ones documented here) use
customize their behavior. It is possible to add/change variables of a build from the following
places:

1. In the project's `gradle.properties` file.
2. In your user's gradle configuration: `~/.gradle/gradle.properties`.
3. Passing them from the command line with the following switch: `-Pkey=val`.
4. Defining a project's extra property inside `build.gradle`. Ie: `project.ext.key='val'`.
1. Passing them from the command line with the following switch: `-P key=val`.
2. In the project's `gradle.properties` file.
3. Defining a project's extra property inside `build.gradle.kts`. Ie: `project.ext["key"] = "val"`.
4. In your user's gradle configuration: `~/.gradle/gradle.properties`.

For examples and reference, check [build.gradle.kts] and [gradle.properties].

Expand All @@ -20,25 +20,29 @@ These scripts can be added to your build to include a whole new capability to yo
To use them, you can import the online versions, or copy them to your `gradle` directory before
importing the script.

You can import these scripts by adding `apply from: $gradleScripts/$script.gradle` to your
`build.gradle` file some of them may require additional plugins inside the `plugins` section in the
root `build.gradle`. Check toolkit `build.gradle` files for examples.
You can import these scripts by adding `apply(from = "$gradleScripts/$script.gradle")` to your
`build.gradle.kts`, some of them may require additional plugins inside the `plugins` section in the
root `build.gradle.kts`. Check toolkit `build.gradle.kts` files for examples.

## Publish
This script set up the project/module for publishing in [Maven Central].

It publishes all artifacts attached to the `mavenJava` publication (check [kotlin.gradle] publishing
section) at the bare minimum binaries are published. For an Open Source project, you must include
sources and javadoc.
section).

The binaries are always published. For an Open Source project, you must also include sources and
javadoc.

To use it, apply `$gradleScripts/publish.gradle`.

To set up this script's parameters, check the [build variables section]. These helper settings are:

* bintrayKey (REQUIRED): if not defined will try to load BINTRAY_KEY environment variable.
* bintrayUser (REQUIRED): or BINTRAY_USER environment variable if not defined.
* license (REQUIRED): the license used in published POMs.
* vcsUrl (REQUIRED): code repository location.
* signingKey (REQUIRED): if not defined will try to load SIGNING_KEY environment variable.
* signingPassword (REQUIRED): or SIGNING_PASSWORD environment variable if not defined.
* ossrhUsername (REQUIRED): or OSSRH_USERNAME if not found.
* ossrhPassword (REQUIRED): or OSSRH_PASSWORD if not found.
* licenses (REQUIRED): the licenses used in published POMs.
* siteHost (REQUIRED): project's website.

[Maven Central]: https://search.maven.org
[kotlin.gradle]: https://github.com/hexagonkt/hexagon/blob/master/gradle/kotlin.gradle
Expand All @@ -54,7 +58,7 @@ All modules' Markdown files are added to the documentation and test classes endi
are available to be referenced as samples.

To use it, apply `$gradleScripts/dokka.gradle` and add the
`id 'org.jetbrains.dokka' version 'VERSION'` plugin to the root `build.gradle`.
`id("org.jetbrains.dokka") version("VERSION")` plugin to the root `build.gradle.kts`.

The format for the generated documentation will be `javadoc` to make it compatible with current
IDEs.
Expand All @@ -67,7 +71,7 @@ Create web icons (favicon and thumbnails for browsers/mobile) from SVG images (l
For image rendering you will need [rsvg] (librsvg2-bin) and [imagemagick] installed in the
development machine.

To use it, apply `$gradleScripts/icons.gradle` to your `build.gradle`.
To use it, apply `$gradleScripts/icons.gradle` to your `build.gradle.kts`.

To set up this script's parameters, check the [build variables section]. These helper settings are:

Expand Down Expand Up @@ -97,7 +101,7 @@ It sets up:
- Published artifacts (binaries and sources): sourcesJar task

To use it, apply `$gradleScripts/kotlin.gradle` and add the
`id 'org.jetbrains.kotlin.jvm' version 'VERSION'` plugin to the root `build.gradle`.
`id("org.jetbrains.kotlin.jvm") version("VERSION")` plugin to the root `build.gradle.kts`.

To set up this script's parameters, check the [build variables section]. These helper settings are:

Expand All @@ -121,17 +125,16 @@ Gradle's script for a service or application. It adds these extra tasks:
* jpackage: create a jpackage distribution including a JVM with a subset of the modules.
* tarJlink: compress Jpackage distribution in a single file.

To use it, apply `$gradleScripts/application.gradle` to your `build.gradle`.
To use it, apply `$gradleScripts/application.gradle` to your `build.gradle.kts`.

To set up this script's parameters, check the [build variables section]. These helper settings are:

* modules: comma separated list of modules to include in the generated JRE. By default:
`java.logging,java.management`.
* modules: comma separated list of modules to include in the generated JRE.
* options: JVM options passed to the jpackage generated launcher.
* icon: icon to be used in the jpackage distribution.
* applicationClass (REQUIRED): fully qualified name of the main class of the application.

To set up this script you need to add the main class name to your `build.gradle` file with the
To set up this script you need to add the main class name to your `build.gradle.kts` file with the
following code:

```groovy
Expand Down Expand Up @@ -163,7 +166,7 @@ The defined tasks are:
* createCa: creates `ca.p12` and import its public certificate inside `trust.p12`.
* createIdentities: creates the `<domain>.p12` store for all `sslDomain` variables.

To use it, apply `$gradleScripts/certificates.gradle` to your `build.gradle`.
To use it, apply `$gradleScripts/certificates.gradle` to your `build.gradle.kts`.

To set up this script's parameters, check the [build variables section]. These helper settings are:

Expand All @@ -186,23 +189,23 @@ To set up this script's parameters, check the [build variables section]. These h

## Lean
This script changes the default Gradle source layout to be less bulky. To use it you must apply the
`$gradleScripts/lean.gradle` script to your `build.gradle` file. It must be applied after the
`$gradleScripts/lean.gradle` script to your `build.gradle.kts` file. It must be applied after the
Kotlin plugin.

After applying this script, the source folders will be `${projectDir}/main` and
`${projectDir}/test`, and the resources will be stored also in these folders.

## Detekt
This script sets up the build to analyze the code with the [Detekt] static code analyzer. To use it
you must apply the `$gradleScripts/detekt.gradle` script to your `build.gradle` file. It must be
you must apply the `$gradleScripts/detekt.gradle` script to your `build.gradle.kts` file. It must be
applied after the Kotlin plugin.

For the script to work you need to add the plugin to the plugins build section before importing the
script. I.e.:

```kotlin
plugins {
id("io.gitlab.arturbosch.detekt") version "VERSION" apply false
id("io.gitlab.arturbosch.detekt") version("VERSION") apply(false)
}
```

Expand All @@ -223,8 +226,8 @@ The defined tasks are:
* upx: compress the native executable using 'upx'. NOTE: Makes binaries use more RAM!!!
* tarNative: compress native executable into a TAR file.

To use it you must apply the `$gradleScripts/native.gradle` script to your `build.gradle` file. It
must be applied after the Kotlin plugin.
To use it you must apply the `$gradleScripts/native.gradle` script to your `build.gradle.kts` file.
It must be applied after the Kotlin plugin.

For the script to work you need to add the plugin to the plugins build section before importing the
script. I.e.:
Expand All @@ -235,22 +238,30 @@ plugins {
}
```

To add configuration metadata in your libraries. you should run these commands:
If you want to create a native image for your application you should execute:

```bash
./gradlew -Pagent build
./gradlew metadataCopy
# After including the metadata you can publish your artifacts. I.e.:
./gradlew publishToMavenLocal
./gradlew nativeCompile
```

And if you want to create a native image for your application you should execute:
To set up this script's parameters, check the [build variables section]. These helper settings are:

```bash
./gradlew -Pagent nativeCompile
[GraalVM]: https://www.graalvm.org
[native image]: https://graalvm.github.io/native-build-tools/latest/index.html

## JMH
Sets up the build to run JMH benchmarks. To use it you must apply the `$gradleScripts/jmh.gradle`
script to your `build.gradle.kts` file.

For the script to work you need to add the plugin to the plugins build section before importing the
script. I.e.:

```kotlin
plugins {
id("me.champeau.jmh") version("VERSION") apply(false)
}
```

To set up this script's parameters, check the [build variables section]. These helper settings are:

[GraalVM]: https://www.graalvm.org
[native image]: https://graalvm.github.io/native-build-tools/latest/index.html
* jmhVersion: JMH version to be used. If not specified a tested JMH version will be used.
Loading

0 comments on commit 5992bae

Please sign in to comment.