Skip to content

Commit e864767

Browse files
authored
Merge pull request #224 from sladkoff/build/kotlin
build: configure Kotlin support
2 parents de6af78 + 9a55383 commit e864767

File tree

3 files changed

+126
-56
lines changed

3 files changed

+126
-56
lines changed

pom.xml

+82-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2626
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
27+
<kotlin.version>1.9.22</kotlin.version>
2728
</properties>
2829

2930
<repositories>
@@ -91,19 +92,22 @@
9192
<version>5.4.0</version>
9293
<scope>test</scope>
9394
</dependency>
95+
<dependency>
96+
<groupId>org.jetbrains.kotlin</groupId>
97+
<artifactId>kotlin-stdlib-jdk8</artifactId>
98+
<version>${kotlin.version}</version>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.jetbrains.kotlin</groupId>
102+
<artifactId>kotlin-test</artifactId>
103+
<version>${kotlin.version}</version>
104+
<scope>test</scope>
105+
</dependency>
94106

95107
</dependencies>
96108

97109
<build>
98110
<plugins>
99-
<plugin>
100-
<groupId>org.apache.maven.plugins</groupId>
101-
<artifactId>maven-compiler-plugin</artifactId>
102-
<version>${maven-compiler-plugin.version}</version>
103-
<configuration>
104-
<release>17</release>
105-
</configuration>
106-
</plugin>
107111
<plugin>
108112
<groupId>org.apache.maven.plugins</groupId>
109113
<artifactId>maven-surefire-plugin</artifactId>
@@ -147,6 +151,76 @@
147151
</gitFlowConfig>
148152
</configuration>
149153
</plugin>
154+
<plugin>
155+
<groupId>org.jetbrains.kotlin</groupId>
156+
<artifactId>kotlin-maven-plugin</artifactId>
157+
<version>${kotlin.version}</version>
158+
<executions>
159+
<execution>
160+
<id>compile</id>
161+
<phase>compile</phase>
162+
<goals>
163+
<goal>compile</goal>
164+
</goals>
165+
<configuration>
166+
<sourceDirs>
167+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
168+
<sourceDir>${project.basedir}/src/main/java</sourceDir>
169+
<source>target/generated-sources/annotations</source>
170+
</sourceDirs>
171+
</configuration>
172+
</execution>
173+
<execution>
174+
<id>test-compile</id>
175+
<phase>test-compile</phase>
176+
<goals>
177+
<goal>test-compile</goal>
178+
</goals>
179+
<configuration>
180+
<sourceDirs>
181+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
182+
<sourceDir>${project.basedir}/src/test/java</sourceDir>
183+
<source>target/generated-test-sources/test-annotations</source>
184+
</sourceDirs>
185+
</configuration>
186+
</execution>
187+
</executions>
188+
<configuration>
189+
<jvmTarget>1.8</jvmTarget>
190+
</configuration>
191+
</plugin>
192+
<plugin>
193+
<groupId>org.apache.maven.plugins</groupId>
194+
<artifactId>maven-compiler-plugin</artifactId>
195+
<version>${maven-compiler-plugin.version}</version>
196+
<executions>
197+
<execution>
198+
<id>default-compile</id>
199+
<phase>none</phase>
200+
</execution>
201+
<execution>
202+
<id>default-testCompile</id>
203+
<phase>none</phase>
204+
</execution>
205+
<execution>
206+
<id>compile</id>
207+
<phase>compile</phase>
208+
<goals>
209+
<goal>compile</goal>
210+
</goals>
211+
</execution>
212+
<execution>
213+
<id>testCompile</id>
214+
<phase>test-compile</phase>
215+
<goals>
216+
<goal>testCompile</goal>
217+
</goals>
218+
</execution>
219+
</executions>
220+
<configuration>
221+
<release>17</release>
222+
</configuration>
223+
</plugin>
150224

151225
</plugins>
152226
</build>

src/main/java/de/sldk/mc/PrometheusExporter.java

-48
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@file:JvmName("PrometheusExporter")
2+
3+
package de.sldk.mc
4+
5+
import de.sldk.mc.config.PrometheusExporterConfig
6+
import org.bukkit.plugin.java.JavaPlugin
7+
import java.util.logging.Level
8+
9+
class PrometheusExporter : JavaPlugin() {
10+
private val config: PrometheusExporterConfig = PrometheusExporterConfig(this)
11+
private var server: MetricsServer? = null
12+
13+
@Override
14+
override fun onEnable() {
15+
config.loadDefaultsAndSave()
16+
config.enableConfiguredMetrics()
17+
startMetricsServer()
18+
}
19+
20+
private fun startMetricsServer() {
21+
val host = config[PrometheusExporterConfig.HOST]
22+
val port = config[PrometheusExporterConfig.PORT]
23+
24+
server = MetricsServer(host, port, this)
25+
26+
try {
27+
server?.start()
28+
getLogger().info("Started Prometheus metrics endpoint at: $host:$port")
29+
} catch (e: Exception) {
30+
getLogger().severe("Could not start embedded Jetty server: " + e.message)
31+
getServer().getPluginManager().disablePlugin(this)
32+
}
33+
}
34+
35+
@Override
36+
override fun onDisable() {
37+
try {
38+
server?.stop()
39+
} catch (e: Exception) {
40+
getLogger().log(Level.WARNING, "Failed to stop metrics server gracefully: " + e.message)
41+
getLogger().log(Level.FINE, "Failed to stop metrics server gracefully", e)
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)