Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
24 changes: 23 additions & 1 deletion core/src/main/java/dev/faststats/core/SimpleMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.16.0
version=0.17.0