Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.

Commit b17477b

Browse files
committed
Initial commit
0 parents  commit b17477b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3686
-0
lines changed

.gitignore

+646
Large diffs are not rendered by default.

LICENSE

Whitespace-only changes.

README.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# 🐻‍❄️🌂 Noelware Analytics for JVM
2+
> *JVM support for using [Noelware Analytics](https://analytics.noelware.org) for your applications.*
3+
>
4+
> <kbd>v0.1-alpha</kbd> | [:scroll: **Documentation**](https://analytics.noelware.org/docs/support/jvm)
5+
6+
**Noelware Analytics for JVM** (`analytics-jvm`) is a library to support client and server support of the Noelware Analytics
7+
[protocol](https://analytics.noelware.org/docs/protocol) for the JVM with Kotlin support.
8+
9+
The library comes in a form of plugins to plug in external sources to include in your Noelware Analytics instance that can be visualised
10+
on the web dashboard.
11+
12+
## Usage
13+
### Client
14+
You will need the instance service token to use the client for yourself.
15+
16+
```java
17+
// Add the "org.noelware.analytics:client:<VERSION>" to the project before
18+
// copying.
19+
20+
import org.noelware.analytics.client.blocking.BlockingAnalyticsClient;
21+
import org.noelware.analytics.client.responses.ConnectionAckResponse;
22+
import org.noelware.analytics.client.responses.InstanceStatsResponse;
23+
import org.noelware.analytics.client.query.QueryBuilder;
24+
25+
// The client also supports asynchronous clients that use the CompletableFuture
26+
// API. This will only demonstrate the blocking APIs.
27+
public class Program {
28+
public static void main(String[] args) {
29+
final BlockingAnalyticsClient client = new BlockingAnalyticsClient.Builder()
30+
.setServiceToken("<token from dashboard>")
31+
.editChannelBuilder(builder -> {
32+
// builder => the gRPC channel builder
33+
builder.usePlaintext();
34+
})
35+
.build();
36+
37+
final ConnectionAckResponse res = client.connect();
38+
System.out.println("connected? " + res.connected() ? "yes" : "no");
39+
40+
final InstanceStatsResponse stats = client.collectStats();
41+
System.out.println(stats);
42+
}
43+
}
44+
```
45+
46+
### Server
47+
You will still need your instance service token to validate requests from incoming traffic. The service token holds as a way to
48+
block traffic that isn't from any client that doesn't have the service token available.
49+
50+
```java
51+
import org.noelware.analytics.server.plugins.jvm.JvmMemoryPoolPlugin;
52+
import org.noelware.analytics.server.plugins.jvm.JvmThreadsPlugin;
53+
import org.noelware.analytics.server.AnalyticsServerBuilder;
54+
import org.noelware.analytics.server.AnalyticsServer;
55+
56+
public class Program {
57+
public static void main(String[] args) {
58+
final AnalyticsServer server = new AnalyticsServerBuilder()
59+
.withPort(55123)
60+
.withPlugins(new JvmMemoryPoolPlugin(), new JvmThreadsPlugin())
61+
.withServiceToken("<service token from dashboard>")
62+
.build();
63+
64+
server.runBlocking();
65+
}
66+
}
67+
```
68+
69+
## Installation
70+
### Gradle (Groovy)
71+
```groovy
72+
repositories {
73+
maven 'https://maven.noelware.org'
74+
gradlePluginPortal()
75+
mavenCentral()
76+
}
77+
78+
dependencies {
79+
implementation 'org.noelware.analytics:bom:<VERSION>'
80+
}
81+
```
82+
83+
### Gradle (Kotlin DSL)
84+
```kotlin
85+
repositories {
86+
maven("https://maven.noelware.org")
87+
gradlePluginPortal()
88+
mavenCentral()
89+
}
90+
91+
dependencies {
92+
implementation("org.noelware.analytics:bom:<VERSION>")
93+
}
94+
```
95+
96+
### Maven
97+
```xml
98+
<repositories>
99+
<repository>
100+
<url>https://maven.noelware.org</url>
101+
</repository>
102+
</repositories>
103+
104+
<dependencies>
105+
<dependency>
106+
<group>org.noelware.analytics</group>
107+
<artifactId>bom</artifactId>
108+
<version>{VERSION}</version>
109+
<type>pom</type>
110+
</dependency>
111+
</dependencies>
112+
```
113+
114+
## Contributing
115+
;-; coming soon! ;-;
116+
117+
## License
118+
**Noelware Analytics for JVM** (`analytics-jvm`) is released under the **MIT License** by Noelware, with love. :3

assets/HEADING

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* 🐻‍❄️🌂 analytics-jvm: Client and server implementation of Noelware Analytics in Java, supported for both Java and Kotlin
3+
* Copyright (c) 2022 Noelware <[email protected]>
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+

build.gradle.kts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* 🐻‍❄️🌂 analytics-jvm: Client and server implementation of Noelware Analytics in Java, supported for both Java and Kotlin
3+
* Copyright (c) 2022 Noelware <[email protected]>
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/

buildSrc/build.gradle.kts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* 🐻‍❄️🌂 analytics-jvm: Client and server implementation of Noelware Analytics in Java, supported for both Java and Kotlin
3+
* Copyright (c) 2022 Noelware <[email protected]>
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
plugins {
25+
`kotlin-dsl`
26+
}
27+
28+
repositories {
29+
maven("https://maven.floofy.dev/repo/releases")
30+
gradlePluginPortal()
31+
mavenCentral()
32+
mavenLocal()
33+
}
34+
35+
dependencies {
36+
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.11.0")
37+
implementation("com.google.protobuf:protobuf-gradle-plugin:0.9.1")
38+
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.7.20")
39+
implementation(kotlin("gradle-plugin", "1.7.10"))
40+
implementation("dev.floofy.commons:gradle:2.3.0")
41+
implementation(gradleApi())
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
* 🐻‍❄️🌂 analytics-jvm: Client and server implementation of Noelware Analytics in Java, supported for both Java and Kotlin
3+
* Copyright (c) 2022 Noelware <[email protected]>
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
25+
import org.noelware.analytics.gradle.*
26+
import dev.floofy.utils.gradle.*
27+
import gradle.kotlin.dsl.accessors._9aab0383dfc03b3173a99d0f5dd3559b.publishing
28+
import java.io.StringReader
29+
import java.util.*
30+
31+
plugins {
32+
id("com.diffplug.spotless")
33+
id("org.jetbrains.dokka")
34+
`maven-publish`
35+
`java-library`
36+
kotlin("jvm")
37+
}
38+
39+
group = "org.noelware.charted"
40+
version = "$VERSION"
41+
42+
repositories {
43+
maven("https://repo.perfectdreams.net/")
44+
mavenCentral()
45+
mavenLocal()
46+
noelware()
47+
noel()
48+
}
49+
50+
dependencies {
51+
api(kotlin("stdlib"))
52+
}
53+
54+
spotless {
55+
kotlin {
56+
licenseHeaderFile("${rootProject.projectDir}/assets/HEADING")
57+
trimTrailingWhitespace()
58+
endWithNewline()
59+
60+
// We can't use the .editorconfig file, so we'll have to specify it here
61+
// issue: https://github.com/diffplug/spotless/issues/142
62+
ktlint()
63+
.setUseExperimental(true)
64+
.editorConfigOverride(mapOf(
65+
"indent_size" to "4",
66+
"disabled_rules" to "colon-spacing,annotation-spacing,filename,no-wildcard-imports",
67+
"ij_kotlin_allow_trailing_comma" to "false",
68+
"ktlint_code_style" to "official",
69+
"no-unused-imports" to "true",
70+
"no-unit-return" to "true",
71+
"no-consecutive-blank-lines" to "true",
72+
"experimental:fun-keyword-spacing" to "true",
73+
"experimental:unnecessary-parentheses-before-trailing-lambda" to "true"
74+
))
75+
}
76+
}
77+
78+
java {
79+
sourceCompatibility = JAVA_VERSION
80+
targetCompatibility = JAVA_VERSION
81+
}
82+
83+
val fullPath = path.substring(1).replace(':', '-')
84+
// transforms ":client" -> "client"
85+
//
86+
// for this case, the full jar file will be "analytics-client-{VERSION}.jar"
87+
// or "analytics-server-{VERSION}.jar"
88+
89+
tasks {
90+
withType<Jar> {
91+
archiveFileName by "analytics-$fullPath-$VERSION.jar"
92+
manifest {
93+
attributes(
94+
"Implementation-Version" to "$VERSION",
95+
"Implementation-Vendor" to "Noelware, LLC. [[email protected]]",
96+
"Implementation-Title" to "charted-server"
97+
)
98+
}
99+
}
100+
101+
withType<KotlinCompile> {
102+
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
103+
kotlinOptions.javaParameters = true
104+
kotlinOptions.jvmTarget = JAVA_VERSION.toString()
105+
}
106+
}
107+
108+
// ~+~ setup publishing here ~+~
109+
// Get the `publishing.properties` file from the `gradle/` directory
110+
// in the root project.
111+
val publishingPropsFile = file("${rootProject.projectDir}/gradle/publishing.properties")
112+
val publishingProps = Properties()
113+
114+
// If the file exists, let's get the input stream
115+
// and load it.
116+
if (publishingPropsFile.exists()) {
117+
publishingProps.load(publishingPropsFile.inputStream())
118+
} else {
119+
// Check if we do in environment variables
120+
val accessKey = System.getenv("NOELWARE_PUBLISHING_ACCESS_KEY") ?: ""
121+
val secretKey = System.getenv("NOELWARE_PUBLISHING_SECRET_KEY") ?: ""
122+
123+
if (accessKey.isNotEmpty() && secretKey.isNotEmpty()) {
124+
val data = """
125+
|s3.accessKey=$accessKey
126+
|s3.secretKey=$secretKey
127+
""".trimMargin()
128+
129+
publishingProps.load(StringReader(data))
130+
}
131+
}
132+
133+
// Check if we have the `NOELWARE_PUBLISHING_ACCESS_KEY` and `NOELWARE_PUBLISHING_SECRET_KEY` environment
134+
// variables, and if we do, set it in the publishing.properties loader.
135+
val snapshotRelease: Boolean = run {
136+
val env = System.getenv("NOELWARE_PUBLISHING_IS_SNAPSHOT") ?: "false"
137+
env == "true"
138+
}
139+
140+
val sourcesJar by tasks.registering(Jar::class) {
141+
archiveClassifier.set("sources")
142+
from(sourceSets.main.get().allSource)
143+
}
144+
145+
val javadocJar by tasks.registering(Jar::class) {
146+
group = JavaBasePlugin.DOCUMENTATION_GROUP
147+
description = "Assemble Kotlin documentation with Dokka"
148+
149+
archiveClassifier.set("javadoc")
150+
from(tasks.dokkaHtml)
151+
dependsOn(tasks.dokkaHtml)
152+
}
153+
154+
publishing {
155+
publications {
156+
create<MavenPublication>("analytics") {
157+
createPublicationMeta(project, "kotlin", sourcesJar, javadocJar)
158+
}
159+
}
160+
161+
repositories {
162+
val url = if (snapshotRelease) "s3://maven.noelware.org/snapshots" else "s3://maven.noelware.org"
163+
maven(url) {
164+
credentials(AwsCredentials::class) {
165+
this.accessKey = publishingProps.getProperty("s3.accessKey") ?: ""
166+
this.secretKey = publishingProps.getProperty("s3.secretKey") ?: ""
167+
}
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)