diff --git a/build.gradle.kts b/build.gradle.kts index 0334ebf..af66f31 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,6 +46,18 @@ subprojects { withJavadocJar() } + val generateFastStatsProperties by tasks.registering { + val outputDir = layout.buildDirectory.dir("generated/resources/faststats") + outputs.dir(outputDir) + doLast { + val file = outputDir.get().file("META-INF/faststats.properties").asFile + file.parentFile.mkdirs() + file.writeText("name=${project.name}\nversion=${project.version}\n") + } + } + + sourceSets.main { resources.srcDir(generateFastStatsProperties) } + tasks.compileJava { options.release.set(javaVersion) } diff --git a/core/src/main/java/dev/faststats/core/SimpleMetrics.java b/core/src/main/java/dev/faststats/core/SimpleMetrics.java index 5db5fa8..4004362 100644 --- a/core/src/main/java/dev/faststats/core/SimpleMetrics.java +++ b/core/src/main/java/dev/faststats/core/SimpleMetrics.java @@ -49,6 +49,20 @@ public abstract class SimpleMetrics implements Metrics { private final URI url; private final boolean debug; + private final String SDK_NAME; + private final String SDK_VERSION; + + { + final var properties = new Properties(); + try (final var stream = getClass().getResourceAsStream("/META-INF/faststats.properties")) { + if (stream != null) properties.load(stream); + } catch (final IOException ignored) { + } + this.SDK_NAME = properties.getProperty("name", "unknown"); + this.SDK_VERSION = properties.getProperty("version", "unknown"); + System.out.println(SDK_NAME + "/" + SDK_VERSION); + } + @Contract(mutates = "io") @SuppressWarnings("PatternValidation") protected SimpleMetrics(final Factory factory, final Config config) throws IllegalStateException { @@ -191,7 +205,7 @@ private boolean submitNow() throws IOException { .header("Content-Encoding", "gzip") .header("Content-Type", "application/octet-stream") .header("Authorization", "Bearer " + getToken()) - .header("User-Agent", "FastStats Metrics") + .header("User-Agent", "FastStats Metrics " + getSdkName() + "/" + getSdkVersion()) .timeout(Duration.ofSeconds(3)) .uri(url) .build(); @@ -227,6 +241,14 @@ private boolean submitNow() throws IOException { } } + private String getSdkName() { + return SDK_NAME; + } + + private String getSdkVersion() { + return SDK_VERSION; + } + private final String javaVersion = System.getProperty("java.version"); private final String osArch = System.getProperty("os.arch"); private final String osName = System.getProperty("os.name"); diff --git a/gradle.properties b/gradle.properties index e6bc754..9f28a3f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.16.0 +version=0.17.0