Skip to content

Commit

Permalink
feat: #81 Migrate ExportContext to Kotlin. Use dokka plugin instead o…
Browse files Browse the repository at this point in the history
…f maven-javadoc-plugin to support Kotlin classes and not fail.
  • Loading branch information
dmitry-weirdo committed Nov 21, 2024
1 parent fbd0e59 commit 70b2799
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 34 deletions.
38 changes: 32 additions & 6 deletions kgstatsSrv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,27 @@
</plugin>

<!-- see https://kotlinlang.org/docs/maven.html#compile-kotlin-and-java-sources -->
<!-- see https://kotlinlang.org/docs/lombok.html#maven -->
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<extensions>true</extensions> <!-- You can set this option
to automatically take information about lifecycles -->
<extensions>true</extensions> <!-- You can set this option to automatically take information about lifecycles -->

<configuration>
<compilerPlugins>
<plugin>lombok</plugin>
</compilerPlugins>
<pluginOptions>
<option>lombok:config=${project.basedir}/src/main/java/lombok.config</option>
</pluginOptions>
</configuration>

<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal> <!-- You can skip the <goals> element
if you enable extensions for the plugin -->
<goal>compile</goal> <!-- You can skip the <goals> element if you enable extensions for the plugin -->
</goals>
<configuration>
<sourceDirs>
Expand All @@ -173,8 +182,7 @@
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal> <!-- You can skip the <goals> element
if you enable extensions for the plugin -->
<goal>test-compile</goal> <!-- You can skip the <goals> element if you enable extensions for the plugin -->
</goals>
<configuration>
<sourceDirs>
Expand All @@ -184,6 +192,24 @@
</configuration>
</execution>
</executions>

<!-- Enable use Lombok-generated code from Java classes in Kotlin -->
<!-- see https://github.com/kotlin-hands-on/kotlin-lombok-examples/blob/master/kotlin_lombok_maven/nokapt/pom.xml -->
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-lombok</artifactId>
<version>${kotlin.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
-->
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
21 changes: 21 additions & 0 deletions kgstatsSrv/src/main/java/ru/klavogonki/statistics/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ public class Config {
// @see ExportContext
private String statisticsPagesRootDir;

// Explicit non-Lombok getters added to make the usage from the Kotlin clas work (see ExportContext).
public int getMinPlayerId() {
return minPlayerId;
}

public int getMaxPlayerId() {
return maxPlayerId;
}

public OffsetDateTime getDataDownloadStartDate() {
return dataDownloadStartDate;
}

public OffsetDateTime getDataDownloadEndDate() {
return dataDownloadEndDate;
}

public String getStatisticsPagesRootDir() {
return statisticsPagesRootDir;
}

@JsonProperty(access = JsonProperty.Access.READ_ONLY) // do not de-serialize, there is no setter and no field
public int getTotalPlayers() {
return maxPlayerId - minPlayerId + 1;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ru.klavogonki.statistics.export

import ru.klavogonki.statistics.Config
import ru.klavogonki.statistics.util.DateUtils
import java.time.LocalDateTime

// todo: probably we don't require this class, all fields are already present in Config
// todo: remove @JvmField annotations after moving all the using classes to Kotlin
data class ExportContext(
@JvmField val webRootDir: String,
@JvmField val minPlayerId: Int,
@JvmField val maxPlayerId: Int,
@JvmField val dataDownloadStartDate: LocalDateTime,
@JvmField val dataDownloadEndDate: LocalDateTime
) {
constructor(config: Config): this(
// we can use property-access from a Java class when there is an explicit geter
// but the lombok-generated getters do NOT work

webRootDir = config.statisticsPagesRootDir,
minPlayerId = config.minPlayerId,
maxPlayerId = config.maxPlayerId,

// todo: think about UTC timeZone
// todo: also change to OffsetDateTime
dataDownloadStartDate = DateUtils.convertToUtcLocalDateTime(config.dataDownloadStartDate),

// todo: think about UTC timeZone
// todo: also change to OffsetDateTime
dataDownloadEndDate = DateUtils.convertToUtcLocalDateTime(config.dataDownloadEndDate)
)
}
41 changes: 40 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version>
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>

<maven-javadoc-plugin.version>3.11.1</maven-javadoc-plugin.version>
<maven-dokka-plugin.version>1.9.20</maven-dokka-plugin.version>

<maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
<openapi-generator-maven-plugin.version>5.0.0</openapi-generator-maven-plugin.version>
<build-helper-maven-plugin.version>3.6.0</build-helper-maven-plugin.version>
Expand Down Expand Up @@ -138,13 +141,19 @@
<version>${maven-war-plugin.version}</version>
</plugin>

<!--
maven-javadoc-plugin does NOT support the Kotlin code
see https://kotlinlang.org/docs/maven.html#generate-documentation
-->

<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<show>private</show>
<!-- see https://stackoverflow.com/a/61884267/8534088 -->
&lt;!&ndash; see https://stackoverflow.com/a/61884267/8534088 &ndash;&gt;
<detectJavaApiLink>false</detectJavaApiLink>
</configuration>
<executions>
Expand All @@ -157,6 +166,36 @@
</execution>
</executions>
</plugin>
-->


<!--
todo: dokka does not generate docs for the Kotlin classes (at least in the javadoc format)
see C:\java\kgparser\kgstatsSrv\target\dokkaJavadoc\index.html
-->
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>${maven-dokka-plugin.version}</version>
<executions>
<execution>
<!-- <phase>pre-site</phase>-->
<phase>package</phase>
<goals>
<goal>dokka</goal>
<goal>javadoc</goal>
</goals>
</execution>
</executions>

<configuration>
<sourceDirectories>
<dir>${project.basedir}/src/main/kotlin</dir>
<dir>${project.basedir}/src/main/java</dir>
</sourceDirectories>
</configuration>
</plugin>

</plugins>
</build>
Expand Down

0 comments on commit 70b2799

Please sign in to comment.