Skip to content

Commit e9d8837

Browse files
authored
Merge pull request #6 from OneLiteFeatherNET/feature/remove-kotlin
Move from kotlin to java to reduce package size
2 parents bb0e017 + 137ad26 commit e9d8837

19 files changed

Lines changed: 389 additions & 401 deletions

File tree

README.md

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
## Description
88
Plugin Debug is a simple and modern library for collect some debug information of your plugin.
9-
This library is inspired by Debug Paste of @IntellectualSites
9+
This library is inspired by Debug Paste of @IntellectualSites [IntellectualSites](https://github.com/IntellectualSites)
10+
As a backend we use from lucko [bytebin](https://github.com/lucko/bytebin) service to host/upload the debug files
1011

1112
## Motivation
1213
We maintain now more than one plugin/software plugin in java. Now it's time to build an api/library to help us to provide better support for users there use our plugins.
@@ -37,30 +38,38 @@ dependencies {
3738
```kt
3839
dependencies {
3940
// Core
40-
implementation("dev.themeinerlp:plugin-debug:1.0.0")
41+
implementation("dev.themeinerlp:plugin-debug:1.1.0")
4142
// Bukkit Extension
42-
implementation("dev.themeinerlp.plugin-debug:bukkit-extension:1.0.0")
43+
implementation("dev.themeinerlp.plugin-debug:bukkit-extension:1.1.0")
4344
}
4445
```
4546
</details>
4647

47-
Example code(Kotlin):
48+
### Example
49+
50+
We have an example [gradle module](example) with an example bukkit command to retrieve a debug log.
51+
Also, we provide already a pre-hosted web ui for view your logs.
52+
53+
The hosted ui follows this structure:
54+
```
55+
https://debugpaste.onelitefeather.net/#/BYTEBIN_CODE/ENCODED_URL/
56+
```
57+
* BYTEBIN_CODE
58+
* The returned code from ByteBin Server when the upload is successfully
59+
* ENCODED_URL
60+
* The ByteBin Server URL encoded in a friendly style
61+
62+
---
63+
### Example code(Kotlin):
4864
```kt
49-
// Example json object
65+
// Example json object from GSON LIB
5066
val obj = JsonObject()
5167
obj.addProperty("Test", "Test")
5268

5369
val result =
5470
DebugBuilder.builder(BYTEBIN_BASE_URL)
55-
// For this is the bukkit extension required
56-
.enableLatestLogSpigot() // Adds the paper last log
57-
.defaultPaperDebugInformation() // Adds as a parseable yaml format some system relevant information from bukkit
5871
// Adds a file from path wrapped in a placeholder object
59-
.addFile(DebugFile(attollo.dataFolder.toPath().resolve("config.yml"),FileType.YAML,"Config as file object"))
60-
// Adds a file from path
61-
.addFile(attollo.dataFolder.toPath().resolve("config.yml"),FileType.YAML,"Config as file")
62-
// Add yaml formatted string to the debug
63-
.addYAML(attollo.config.saveToString(), "Config")
72+
.addFile(DebugFile(Path.of("config", "config.yml"), FileType.YAML, "Config as file object"))
6473
// Add a simple text to the debug
6574
.addText("Text test", "Text test")
6675
// Add json formatted string to the debug
@@ -76,19 +85,5 @@ val encodedUrl = URLEncoder.encode(
7685
val code = result.code
7786
// Prettified url
7887
val openUrl = "https://debugpaste.onelitefeather.net/#/$code/$encodedUrl/"
79-
val component = MiniMessage.miniMessage().deserialize("<#05b9ff>[Attollo] <yellow><click:OPEN_URL:'$openUrl'>Click <u>here</u> to open the debug paste</click>")
80-
```
81-
**For better formatting we used mini message also the two lines `enableLatestLogSpigot()` and `defaultPaperDebugInformation()` requires the Bukkit Extension.**
82-
83-
Example for java
84-
```java
85-
var obj = new JsonObject();
86-
obj.addProperty("Test", "Test");
87-
88-
var builder = DebugBuilder.builder(BYTEBIN_BASE_URL);
89-
builder = enableLatestLogSpigot(builder);
90-
builder = defaultPaperDebugInformation(builder);
91-
builder.addFile(new DebugFile(Path.of(""), FileType.YAML, "Config as file object"))
92-
.addFile(Path.of(""), FileType.YAML, "Config as file");
93-
var result = builder.upload();
88+
val component = MiniMessage.miniMessage().deserialize("<#05b9ff>[Example] <yellow><click:OPEN_URL:'$openUrl'>Click <u>here</u> to open the debug paste</click>")
9489
```

build.gradle.kts

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import org.ajoberstar.grgit.Grgit
22
import java.util.*
33

44
plugins {
5-
kotlin("jvm") version "1.8.21"
5+
java
66
id("org.ajoberstar.grgit") version "5.2.0"
77
`java-library`
88
`maven-publish`
99
signing
10-
id("org.jetbrains.dokka") version "1.8.10"
1110
}
1211

1312
if (!File("$rootDir/.git").exists()) {
@@ -22,7 +21,7 @@ if (!File("$rootDir/.git").exists()) {
2221
}
2322

2423
group = "dev.themeinerlp"
25-
var baseVersion by extra("1.0.0")
24+
var baseVersion by extra("1.1.0")
2625
var extension by extra("")
2726
var snapshot by extra("-SNAPSHOT")
2827

@@ -44,73 +43,27 @@ repositories {
4443
dependencies {
4544
implementation("net.lingala.zip4j:zip4j:2.11.5")
4645
implementation("com.google.code.gson:gson:2.10.1")
47-
// Test
48-
testImplementation("net.lingala.zip4j:zip4j:2.11.5")
49-
testImplementation("com.google.code.gson:gson:2.10.1")
50-
testImplementation(kotlin("test"))
5146
}
5247

5348
tasks {
5449
test {
5550
useJUnitPlatform()
5651
}
57-
dokkaHtml {
58-
dokkaSourceSets {
59-
named("main") {
60-
moduleName.set("Plugin Debug")
61-
includes.from("module.md")
62-
description = "A simple library to upload plugin debugs"
63-
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
64-
}
65-
}
66-
}
67-
dokkaJavadoc {
68-
dokkaSourceSets {
69-
named("main") {
70-
moduleName.set("Plugin Debug")
71-
description = "A simple library to upload plugin debugs"
72-
includes.from("module.md")
73-
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
74-
}
75-
}
76-
}
7752
}
7853

79-
kotlin {
80-
jvmToolchain(17)
81-
sourceSets.all {
82-
languageSettings {
83-
languageVersion = "2.0"
84-
}
54+
java {
55+
toolchain {
56+
languageVersion.set(JavaLanguageVersion.of(17))
8557
}
8658
}
8759

88-
val sourceJar by tasks.register<Jar>("kotlinJar") {
89-
from(sourceSets.main.get().allSource)
90-
archiveClassifier.set("sources")
91-
}
92-
val dokkaJavadocJar by tasks.register<Jar>("dokkaHtmlJar") {
93-
dependsOn(rootProject.tasks.dokkaHtml)
94-
from(rootProject.tasks.dokkaHtml.flatMap { it.outputDirectory })
95-
archiveClassifier.set("html-docs")
96-
}
97-
98-
val dokkaHtmlJar by tasks.register<Jar>("dokkaJavadocJar") {
99-
dependsOn(rootProject.tasks.dokkaJavadoc)
100-
from(rootProject.tasks.dokkaJavadoc.flatMap { it.outputDirectory })
101-
archiveClassifier.set("javadoc")
102-
}
103-
10460
publishing {
10561
publications {
10662
create<MavenPublication>("mavenJava") {
10763
from(components.findByName("java"))
10864
groupId = "dev.themeinerlp"
10965
artifactId = "plugin-debug"
11066
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
111-
artifact(dokkaJavadocJar)
112-
artifact(dokkaHtmlJar)
113-
artifact(sourceJar)
11467
pom {
11568
name.set("Plugin debug")
11669
description.set("A simple library to upload plugin debugs")

bukkit-extension/build.gradle.kts

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import org.ajoberstar.grgit.Grgit
22
import java.util.*
33

44
plugins {
5-
kotlin("jvm") version "1.8.21"
5+
java
66
`java-library`
77
`maven-publish`
88
signing
9-
id("org.jetbrains.dokka") version "1.8.10"
109
}
1110

1211
group = "dev.themeinerlp"
13-
var baseVersion by extra("1.0.0")
12+
var baseVersion by extra("1.1.0")
1413
var extension by extra("")
1514
var snapshot by extra("-SNAPSHOT")
1615

@@ -34,58 +33,19 @@ dependencies {
3433
compileOnly(rootProject)
3534
compileOnly("io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT")
3635
implementation("io.papermc:paperlib:1.0.8")
37-
testImplementation(platform("org.junit:junit-bom:5.9.3"))
38-
testImplementation("org.junit.jupiter:junit-jupiter")
3936
}
4037

4138
tasks {
4239
test {
4340
useJUnitPlatform()
4441
}
4542

46-
dokkaHtml {
47-
dokkaSourceSets {
48-
named("main") {
49-
moduleName.set("Plugin Debug Bukkit Extension")
50-
description = "Extends the main api with some nice features for bukkit"
51-
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
52-
}
53-
}
54-
}
55-
dokkaJavadoc {
56-
dokkaSourceSets {
57-
named("main") {
58-
moduleName.set("Plugin Debug Bukkit Extension")
59-
description = "Extends the main api with some nice features for bukkit"
60-
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
61-
}
62-
}
63-
}
64-
}
6543

66-
kotlin {
67-
jvmToolchain(17)
68-
sourceSets.all {
69-
languageSettings {
70-
languageVersion = "2.0"
71-
}
72-
}
73-
}
74-
75-
val sourceJar by tasks.register<Jar>("kotlinJar") {
76-
from(sourceSets.main.get().allSource)
77-
archiveClassifier.set("sources")
7844
}
79-
val dokkaJavadocJar by tasks.register<Jar>("dokkaHtmlJar") {
80-
dependsOn(rootProject.tasks.dokkaHtml)
81-
from(rootProject.tasks.dokkaHtml.flatMap { it.outputDirectory })
82-
archiveClassifier.set("html-docs")
83-
}
84-
85-
val dokkaHtmlJar by tasks.register<Jar>("dokkaJavadocJar") {
86-
dependsOn(rootProject.tasks.dokkaJavadoc)
87-
from(rootProject.tasks.dokkaJavadoc.flatMap { it.outputDirectory })
88-
archiveClassifier.set("javadoc")
45+
java {
46+
toolchain {
47+
languageVersion.set(JavaLanguageVersion.of(17))
48+
}
8949
}
9050

9151
publishing {
@@ -95,9 +55,6 @@ publishing {
9555
groupId = "dev.themeinerlp.plugin-debug"
9656
artifactId = "bukkit-extension"
9757
version = "%s%s".format(Locale.ROOT, baseVersion, snapshot)
98-
artifact(dokkaJavadocJar)
99-
artifact(dokkaHtmlJar)
100-
artifact(sourceJar)
10158
pom {
10259
name.set("Bukkit Extension")
10360
description.set("The extension for bukkit/paper/spigot for plugin debug")
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package dev.themeinerlp.plugindebug;
2+
3+
import io.papermc.lib.PaperLib;
4+
import io.papermc.paper.datapack.Datapack;
5+
import org.bukkit.Bukkit;
6+
import org.bukkit.configuration.file.YamlConfiguration;
7+
import org.bukkit.plugin.Plugin;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
import java.io.IOException;
11+
import java.lang.management.ManagementFactory;
12+
import java.nio.file.Files;
13+
import java.nio.file.Path;
14+
import java.util.Arrays;
15+
import java.util.regex.Pattern;
16+
17+
/**
18+
* Bukkit Debug builder
19+
*/
20+
public final class BukkitDebugBuilder extends DebugBuilder<BukkitDebugBuilder> {
21+
22+
private final Pattern privacyRegex = Pattern.compile("\\b(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\\.(1?[0-9]{1,2}|2[0-4][0-9]|25[0-5])\\b");
23+
private BukkitDebugBuilder(String uploadServer) {
24+
super(uploadServer);
25+
}
26+
27+
/**
28+
* Collects the latest log file from bukkit
29+
* @return the builder
30+
* @throws IOException if the file empty/null
31+
*/
32+
public BukkitDebugBuilder collectLatestSpigotLog() throws IOException {
33+
var latestLogFile = Path.of("logs", "latest.log");
34+
if (Files.size(latestLogFile) >= maxZipFileSize) throw new IllegalStateException(
35+
String.format("Latest log file is to big only %d bytes allowed", maxZipFileSize)
36+
);
37+
var tempLogFile = Files.createTempFile(tempFile, ".log");
38+
var cleanedList = Files.readAllLines(latestLogFile).stream().map(s -> s.replaceAll(privacyRegex.pattern(), "*")).toList();
39+
Files.write(tempLogFile, cleanedList);
40+
addFile(tempLogFile, FileType.LOG, "Latest Log");
41+
return this;
42+
}
43+
44+
/**
45+
* Collects default paper debug information
46+
* @return the bukkit builder
47+
* @throws IOException if the file empty/null
48+
*/
49+
50+
public BukkitDebugBuilder defaultPaperDebugInformation() throws IOException {
51+
var tempLogFile = Files.createTempFile(tempFile, ".yaml");
52+
var plugins = Arrays.asList(Bukkit.getServer().getPluginManager().getPlugins());
53+
plugins.sort(this::sortPluginByName);
54+
var debugInformation = new YamlConfiguration();
55+
debugInformation.set("server.version", Bukkit.getVersion());
56+
debugInformation.set("server.plugins", plugins.size());
57+
for (Plugin plugin : plugins) {
58+
var name = plugin.getName();
59+
debugInformation.set(String.format("server.plugin.%s.version", name), plugin.getDescription().getVersion());
60+
debugInformation.set(String.format("server.plugin.%s.main", name), plugin.getDescription().getMain());
61+
debugInformation.set(String.format("server.plugin.%s.authors", name), plugin.getDescription().getAuthors());
62+
debugInformation.set(String.format("server.plugin.%s.load-before", name), plugin.getDescription().getLoadBefore());
63+
debugInformation.set(String.format("server.plugin.%s.dependencies", name), plugin.getDescription().getDepend());
64+
debugInformation.set(String.format("server.plugin.%s.soft-dependencies", name), plugin.getDescription().getSoftDepend());
65+
debugInformation.set(String.format("server.plugin.%s.provides", name), plugin.getDescription().getProvides());
66+
debugInformation.set(String.format("server.plugin.%s.enabled", name), plugin.isEnabled());
67+
}
68+
if (PaperLib.isPaper()) {
69+
var dataPacks = Bukkit.getServer().getDatapackManager().getEnabledPacks();
70+
debugInformation.set("server.datapacks.count", dataPacks.size());
71+
debugInformation.set("server.datapacks.packs", dataPacks.stream().map(Datapack::getName).toList());
72+
}
73+
var runtime = Runtime.getRuntime();
74+
var rb = ManagementFactory.getRuntimeMXBean();
75+
debugInformation.set("uptime", rb.getUptime());
76+
debugInformation.set("jvm-flags", rb.getInputArguments());
77+
debugInformation.set("free-memory", runtime.freeMemory());
78+
debugInformation.set("max-memory", runtime.maxMemory());
79+
debugInformation.set("total-memory", runtime.totalMemory());
80+
debugInformation.set("available-processors", runtime.availableProcessors());
81+
debugInformation.set("java-name", rb.getVmName());
82+
debugInformation.set("java-version", System.getProperty("java.version"));
83+
debugInformation.set("java-vendor", System.getProperty("java.vendor"));
84+
debugInformation.set("operating-system", System.getProperty("os.name"));
85+
debugInformation.set("os-version", System.getProperty("os.version"));
86+
debugInformation.set("os-arch", System.getProperty("os.arch"));
87+
addYAML(debugInformation.saveToString(), "Default Paper Debug Information");
88+
return this;
89+
}
90+
91+
private int sortPluginByName(@NotNull Plugin A, @NotNull Plugin B) {
92+
return A.getName().compareTo(B.getName());
93+
}
94+
95+
/**
96+
* Creates a bukkit builder instance with the given bytebin server
97+
*
98+
* @param uploadServer bytebin server base url
99+
*/
100+
public static BukkitDebugBuilder builder(String uploadServer) {
101+
return new BukkitDebugBuilder(uploadServer);
102+
}
103+
104+
}

0 commit comments

Comments
 (0)