From 6e64890c0418a87eeaa07a02ca04f8d101eaa24e Mon Sep 17 00:00:00 2001 From: JOO200 Date: Mon, 28 Mar 2022 21:50:22 +0200 Subject: [PATCH] Updated NuVotifier and Dependencies * Updated Gradle to version 7.4.0 * Updated Java to version 17 * Moved to Gradle build scripts * Fixed publishing maven artifacts * Removed universal file (better depend on the specific implementations) --- api/build.gradle | 3 - api/build.gradle.kts | 9 ++ build.gradle | 60 ---------- build.gradle.kts | 67 +++++++++++ buildSrc/build.gradle.kts | 21 ++++ buildSrc/src/main/kotlin/ArtifactoryConfig.kt | 40 +++++++ buildSrc/src/main/kotlin/CommonConfig.kt | 29 +++++ buildSrc/src/main/kotlin/CommonJavaConfig.kt | 75 +++++++++++++ buildSrc/src/main/kotlin/GradleExtras.kt | 12 ++ buildSrc/src/main/kotlin/PlatformConfig.kt | 64 +++++++++++ buildSrc/src/main/kotlin/Versions.kt | 8 ++ bukkit/build.gradle | 6 - bukkit/build.gradle.kts | 55 +++++++++ bukkit/src/main/resources/plugin.yml | 2 +- bungeecord/build.gradle | 5 - bungeecord/build.gradle.kts | 55 +++++++++ common/build.gradle | 8 -- common/build.gradle.kts | 14 +++ .../support/forwarding/cache/VoteCache.java | 2 +- .../votifier/util/ArgsToVoteTest.java | 71 +++--------- gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 2 +- publish.gradle | 52 --------- settings.gradle | 20 ---- settings.gradle.kts | 17 +++ sponge/build.gradle | 12 -- sponge/build.gradle.kts | 106 ++++++++++++++++++ universal/build.gradle | 93 --------------- velocity/build.gradle | 12 -- velocity/build.gradle.kts | 64 +++++++++++ 30 files changed, 655 insertions(+), 331 deletions(-) delete mode 100644 api/build.gradle create mode 100644 api/build.gradle.kts delete mode 100644 build.gradle create mode 100644 build.gradle.kts create mode 100644 buildSrc/build.gradle.kts create mode 100644 buildSrc/src/main/kotlin/ArtifactoryConfig.kt create mode 100644 buildSrc/src/main/kotlin/CommonConfig.kt create mode 100644 buildSrc/src/main/kotlin/CommonJavaConfig.kt create mode 100644 buildSrc/src/main/kotlin/GradleExtras.kt create mode 100644 buildSrc/src/main/kotlin/PlatformConfig.kt create mode 100644 buildSrc/src/main/kotlin/Versions.kt delete mode 100644 bukkit/build.gradle create mode 100644 bukkit/build.gradle.kts delete mode 100644 bungeecord/build.gradle create mode 100644 bungeecord/build.gradle.kts delete mode 100644 common/build.gradle create mode 100644 common/build.gradle.kts create mode 100644 gradle.properties delete mode 100644 publish.gradle delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 sponge/build.gradle create mode 100644 sponge/build.gradle.kts delete mode 100644 universal/build.gradle delete mode 100644 velocity/build.gradle create mode 100644 velocity/build.gradle.kts diff --git a/api/build.gradle b/api/build.gradle deleted file mode 100644 index cd27637..0000000 --- a/api/build.gradle +++ /dev/null @@ -1,3 +0,0 @@ -dependencies { - implementation 'com.google.code.gson:gson:2.8.0' -} diff --git a/api/build.gradle.kts b/api/build.gradle.kts new file mode 100644 index 0000000..9d97a4c --- /dev/null +++ b/api/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `java-library` +} + +applyPlatformAndCoreConfiguration() + +dependencies { + "implementation"("com.google.code.gson:gson:${Versions.GSON}") +} diff --git a/build.gradle b/build.gradle deleted file mode 100644 index f542448..0000000 --- a/build.gradle +++ /dev/null @@ -1,60 +0,0 @@ - -import org.apache.tools.ant.filters.ReplaceTokens - -plugins { - id "com.github.spotbugs" version "4.7.1" apply false - id "net.kyori.blossom" version "1.3.0" apply false -} - -allprojects { - group 'com.vexsoftware' - version '3.0.0-SNAPSHOT' -} - -subprojects { - apply plugin: 'java' - apply plugin: "com.github.spotbugs" - - sourceCompatibility = 1.8 - - repositories { - mavenCentral() - maven { - url "https://hub.spigotmc.org/nexus/content/repositories/snapshots" - } - maven { - url "https://oss.sonatype.org/content/repositories/snapshots" - } - maven { - url "https://repo.spongepowered.org/maven" - } - maven { - url "https://repo.velocitypowered.com/snapshots/" - } - } - - dependencies { - testImplementation "org.junit.jupiter:junit-jupiter-api:5.4.2" - testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.4.2" - testImplementation "org.junit.jupiter:junit-jupiter-params:5.4.2" - testImplementation "org.mockito:mockito-core:2.+" - } - - processResources { - filter(ReplaceTokens, tokens: ["app.version": this.project.version]) - } - - test { - useJUnitPlatform() - } - - tasks.withType(com.github.spotbugs.snom.SpotBugsTask) { - reports { - html { - enabled = true - destination = file("$buildDir/reports/spotbugs/main/spotbugs.html") - stylesheet = 'fancy-hist.xsl' - } - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..567ae41 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,67 @@ +import org.ajoberstar.grgit.Grgit + +plugins { + id("net.kyori.blossom") version "1.2.0" apply false +} + +logger.lifecycle(""" +******************************************* + You are building NuVotifier! + If you encounter trouble: + 1) Try running 'build' in a separate Gradle run + 2) Use gradlew and not gradle + 3) If you still need help, you should reconsider building NuVotifier! + + Output files will be in [subproject]/build/libs +******************************************* +""") + + +applyRootArtifactoryConfig() + +if (!project.hasProperty("gitCommitHash")) { + apply(plugin = "org.ajoberstar.grgit") + ext["gitCommitHash"] = try { + Grgit.open(mapOf("currentDir" to project.rootDir))?.head()?.abbreviatedId + } catch (e: Exception) { + logger.warn("Error getting commit hash", e) + + "no.git.id" + } +} +/* +subprojects { + apply plugin: 'java' + + repositories { + mavenCentral() + maven { + url "https://hub.spigotmc.org/nexus/content/repositories/snapshots" + } + maven { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + maven { + url "https://repo.spongepowered.org/maven" + } + maven { + url "https://repo.velocitypowered.com/snapshots/" + } + } + + dependencies { + testImplementation "org.junit.jupiter:junit-jupiter-api:5.8.2" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.8.2" + testImplementation "org.junit.jupiter:junit-jupiter-params:5.8.2" + testImplementation "org.mockito:mockito-core:4.4.0" + } + + processResources { + filter(ReplaceTokens, tokens: ["app.version": this.project.version]) + } + + test { + useJUnitPlatform() + } +} +*/ \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..81c050a --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,21 @@ +plugins { + `kotlin-dsl` + kotlin("jvm") version embeddedKotlinVersion +} + +repositories { + mavenCentral() + gradlePluginPortal() + maven { + name = "sponge" + url = uri("https://repo.spongepowered.org/repository/maven-public/") + } +} + +dependencies { + implementation(gradleApi()) + implementation("org.ajoberstar.grgit:grgit-gradle:4.1.1") + implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.2") + implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.27.1") + implementation("org.spongepowered:spongegradle-plugin-development:2.0.0") +} diff --git a/buildSrc/src/main/kotlin/ArtifactoryConfig.kt b/buildSrc/src/main/kotlin/ArtifactoryConfig.kt new file mode 100644 index 0000000..28ded7c --- /dev/null +++ b/buildSrc/src/main/kotlin/ArtifactoryConfig.kt @@ -0,0 +1,40 @@ +import org.gradle.api.Project +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.named +import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention +import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask + +private const val ARTIFACTORY_CONTEXT_URL = "artifactory_contextUrl" +private const val ARTIFACTORY_USER = "artifactory_user" +private const val ARTIFACTORY_PASSWORD = "artifactory_password" + +fun Project.applyRootArtifactoryConfig() { + if (!project.hasProperty(ARTIFACTORY_CONTEXT_URL)) ext[ARTIFACTORY_CONTEXT_URL] = "http://localhost" + if (!project.hasProperty(ARTIFACTORY_USER)) ext[ARTIFACTORY_USER] = "guest" + if (!project.hasProperty(ARTIFACTORY_PASSWORD)) ext[ARTIFACTORY_PASSWORD] = "" + + apply(plugin = "com.jfrog.artifactory") + configure { + setContextUrl("${project.property(ARTIFACTORY_CONTEXT_URL)}") + clientConfig.publisher.run { + repoKey = when { + "${project.version}".contains("SNAPSHOT") -> "private" + else -> "public" + } + username = "${project.property(ARTIFACTORY_USER)}" + password = "${project.property(ARTIFACTORY_PASSWORD)}" + isMaven = true + isIvy = false + } + } + tasks.named("artifactoryPublish") { + isSkip = true + } +} + +fun Project.applyCommonArtifactoryConfig() { + tasks.named("artifactoryPublish") { + publications("maven") + } +} diff --git a/buildSrc/src/main/kotlin/CommonConfig.kt b/buildSrc/src/main/kotlin/CommonConfig.kt new file mode 100644 index 0000000..72072b6 --- /dev/null +++ b/buildSrc/src/main/kotlin/CommonConfig.kt @@ -0,0 +1,29 @@ +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.repositories +import org.gradle.kotlin.dsl.the + +fun Project.applyCommonConfiguration() { + group = rootProject.group + version = rootProject.version + + repositories { + mavenCentral() + maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") } + } + + configurations.all { + resolutionStrategy { + cacheChangingModulesFor(5, "MINUTES") + } + } + + plugins.withId("java") { + the().toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } + } +} diff --git a/buildSrc/src/main/kotlin/CommonJavaConfig.kt b/buildSrc/src/main/kotlin/CommonJavaConfig.kt new file mode 100644 index 0000000..78ad4ff --- /dev/null +++ b/buildSrc/src/main/kotlin/CommonJavaConfig.kt @@ -0,0 +1,75 @@ +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.api.tasks.javadoc.Javadoc +import org.gradle.api.tasks.testing.Test +import org.gradle.external.javadoc.StandardJavadocDocletOptions +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.withType + +fun Project.applyCommonJavaConfiguration(sourcesJar: Boolean, javaRelease: Int = 8, banSlf4j: Boolean = true) { + applyCommonConfiguration() + apply(plugin = "eclipse") + apply(plugin = "idea") + + tasks + .withType() + .matching { it.name == "compileJava" || it.name == "compileTestJava" } + .configureEach { + val disabledLint = listOf( + "processing", "path", "fallthrough", "serial" + ) + options.release.set(javaRelease) + options.compilerArgs.addAll(listOf("-Xlint:all") + disabledLint.map { "-Xlint:-$it" }) + options.isDeprecation = true + options.encoding = "UTF-8" + options.compilerArgs.add("-parameters") + } + + tasks.withType().configureEach { + useJUnitPlatform() + } + + dependencies { + "compileOnly"("com.google.code.findbugs:jsr305:${Versions.FINDBUGS}") + "testImplementation"("org.junit.jupiter:junit-jupiter-api:${Versions.JUNIT}") + "testImplementation"("org.junit.jupiter:junit-jupiter-params:${Versions.JUNIT}") + "testImplementation"("org.mockito:mockito-core:${Versions.MOCKITO}") + "testImplementation"("org.mockito:mockito-junit-jupiter:${Versions.MOCKITO}") + "testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:${Versions.JUNIT}") + } + + // Java 8 turns on doclint which we fail + tasks.withType().configureEach { + options.encoding = "UTF-8" + (options as StandardJavadocDocletOptions).apply { + addStringOption("Xdoclint:none", "-quiet") + tags( + "apiNote:a:API Note:", + "implSpec:a:Implementation Requirements:", + "implNote:a:Implementation Note:" + ) + } + } + + configure { + disableAutoTargetJvm() + withJavadocJar() + if (sourcesJar) { + withSourcesJar() + } + } + + if (banSlf4j) { + configurations["compileClasspath"].apply { + resolutionStrategy.componentSelection { + withModule("org.slf4j:slf4j-api") { + reject("No SLF4J allowed on compile classpath") + } + } + } + } +} diff --git a/buildSrc/src/main/kotlin/GradleExtras.kt b/buildSrc/src/main/kotlin/GradleExtras.kt new file mode 100644 index 0000000..beedf16 --- /dev/null +++ b/buildSrc/src/main/kotlin/GradleExtras.kt @@ -0,0 +1,12 @@ +import org.gradle.api.Project +import org.gradle.api.plugins.ExtraPropertiesExtension +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.api.tasks.SourceSetContainer +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.the + +val Project.ext: ExtraPropertiesExtension + get() = extensions.getByType() + +val Project.sourceSets: SourceSetContainer + get() = the().sourceSets diff --git a/buildSrc/src/main/kotlin/PlatformConfig.kt b/buildSrc/src/main/kotlin/PlatformConfig.kt new file mode 100644 index 0000000..6b68d05 --- /dev/null +++ b/buildSrc/src/main/kotlin/PlatformConfig.kt @@ -0,0 +1,64 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.Project +import org.gradle.api.component.AdhocComponentWithVariants +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.kotlin.dsl.apply +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.named +import org.gradle.kotlin.dsl.register + +fun Project.applyPlatformAndCoreConfiguration(javaRelease: Int = 17) { + applyCommonConfiguration() + apply(plugin = "java") + apply(plugin = "maven-publish") + apply(plugin = "com.jfrog.artifactory") + applyCommonJavaConfiguration( + sourcesJar = true, + javaRelease = javaRelease, + banSlf4j = false + ) + + ext["internalVersion"] = "$version+${rootProject.ext["gitCommitHash"]}" + + configure { + publications { + register("maven") { + from(components["java"]) + versionMapping { + usage("java-api") { + fromResolutionOf("runtimeClasspath") + } + usage("java-runtime") { + fromResolutionResult() + } + } + } + } + } + + applyCommonArtifactoryConfig() +} + +fun Project.applyShadowConfiguration() { + apply(plugin = "com.github.johnrengelman.shadow") + tasks.named("shadowJar") { + archiveClassifier.set("dist") + dependencies { + include(project(":nuvotifier-api")) + include(project(":nuvotifier-common")) + + exclude("com.google.code.findbugs:jsr305") + } + exclude("GradleStart**") + exclude(".cache") + exclude("LICENSE*") + exclude("META-INF/maven/**") + } + val javaComponent = components["java"] as AdhocComponentWithVariants + // I don't think we want this published (it's the shadow jar) + javaComponent.withVariantsFromConfiguration(configurations["shadowRuntimeElements"]) { + skip() + } +} diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt new file mode 100644 index 0000000..c1d38bf --- /dev/null +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -0,0 +1,8 @@ +object Versions { + const val JUNIT = "5.8.1" + const val MOCKITO = "4.3.1" + const val FINDBUGS = "3.0.2" + const val NETTYIO = "4.1.72.Final" + const val GSON = "2.9.0" + const val VELOCITY = "1.1.0-SNAPSHOT" +} diff --git a/bukkit/build.gradle b/bukkit/build.gradle deleted file mode 100644 index edfd164..0000000 --- a/bukkit/build.gradle +++ /dev/null @@ -1,6 +0,0 @@ -dependencies { - compileOnly group: "org.spigotmc", name: "spigot-api", version: "1.8.8-R0.1-SNAPSHOT" - implementation project(":nuvotifier-api") - implementation project(":nuvotifier-common") -} - diff --git a/bukkit/build.gradle.kts b/bukkit/build.gradle.kts new file mode 100644 index 0000000..081e764 --- /dev/null +++ b/bukkit/build.gradle.kts @@ -0,0 +1,55 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +plugins { + `java-library` +} + +applyPlatformAndCoreConfiguration() +applyShadowConfiguration() + +repositories { + maven { + name = "paper" + url = uri("https://papermc.io/repo/repository/maven-public/") + } +} + +configurations { + compileClasspath.get().extendsFrom(create("shadeOnly")) +} + +dependencies { + "compileOnly"("io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT") + "api"(project(":nuvotifier-api")) + "api"(project(":nuvotifier-common")) +} + + +tasks.named("processResources") { + val internalVersion = project.ext["internalVersion"] + inputs.property("internalVersion", internalVersion) + filesMatching("plugin.yml") { + expand("internalVersion" to internalVersion) + } +} + +tasks.named("jar") { + val projectVersion = project.version + inputs.property("projectVersion", projectVersion) + manifest { + attributes("Implementation-Version" to projectVersion) + } +} + +tasks.named("shadowJar") { + configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"]) + + dependencies { + include(dependency(":nuvotifier-api")) + include(dependency(":nuvotifier-common")) + } +} + +tasks.named("assemble").configure { + dependsOn("shadowJar") +} diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 07a96a6..613eabf 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: Votifier main: com.vexsoftware.votifier.NuVotifierBukkit -version: @app.version@ +version: "${internalVersion}" description: A plugin that gets notified when votes are made for the server on toplists. authors: [Ichbinjoe, blakeman8192, Kramer, tuxed] api-version: 1.13 diff --git a/bungeecord/build.gradle b/bungeecord/build.gradle deleted file mode 100644 index 7164300..0000000 --- a/bungeecord/build.gradle +++ /dev/null @@ -1,5 +0,0 @@ -dependencies { - compileOnly group: "net.md-5", name: "bungeecord-api", version: "1.8-SNAPSHOT" - implementation project(":nuvotifier-api") - implementation project(":nuvotifier-common") -} diff --git a/bungeecord/build.gradle.kts b/bungeecord/build.gradle.kts new file mode 100644 index 0000000..5932f0e --- /dev/null +++ b/bungeecord/build.gradle.kts @@ -0,0 +1,55 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +plugins { + `java-library` +} + +applyPlatformAndCoreConfiguration() +applyShadowConfiguration() + +repositories { + maven { + name = "bungeecord" + url = uri("https://oss.sonatype.org/content/repositories/snapshots/") + } +} + +configurations { + compileClasspath.get().extendsFrom(create("shadeOnly")) +} + +dependencies { + "compileOnly"("net.md-5:bungeecord-api:1.18-R0.1-SNAPSHOT") + "api"(project(":nuvotifier-api")) + "api"(project(":nuvotifier-common")) +} + + +tasks.named("processResources") { + val internalVersion = project.ext["internalVersion"] + inputs.property("internalVersion", internalVersion) + filesMatching("plugin.yml") { + expand("internalVersion" to internalVersion) + } +} + +tasks.named("jar") { + val projectVersion = project.version + inputs.property("projectVersion", projectVersion) + manifest { + attributes("Implementation-Version" to projectVersion) + } +} + +tasks.named("shadowJar") { + configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"]) + + dependencies { + include(dependency(":nuvotifier-api")) + include(dependency(":nuvotifier-common")) + } +} + +tasks.named("assemble").configure { + dependsOn("shadowJar") +} diff --git a/common/build.gradle b/common/build.gradle deleted file mode 100644 index 83b3f8d..0000000 --- a/common/build.gradle +++ /dev/null @@ -1,8 +0,0 @@ -dependencies { - implementation project(":nuvotifier-api") - implementation group: "io.netty", name: "netty-handler", version: "4.1.49.Final" - implementation group: "io.netty", name: "netty-transport-native-epoll", version: "4.1.49.Final", classifier: "linux-x86_64" - implementation 'com.google.code.gson:gson:2.8.0' - testImplementation group: "org.json", name: "json", version: "20180130" // retain this for testing reasons - testImplementation 'com.google.guava:guava:28.1-jre' -} diff --git a/common/build.gradle.kts b/common/build.gradle.kts new file mode 100644 index 0000000..539a8d1 --- /dev/null +++ b/common/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + `java-library` +} + +applyPlatformAndCoreConfiguration() + +dependencies { + "api"(project(":nuvotifier-api")) + "implementation"("io.netty:netty-handler:${Versions.NETTYIO}") + "implementation"("io.netty:netty-transport-native-epoll:${Versions.NETTYIO}:linux-x86_64") + "implementation"("com.google.code.gson:gson:${Versions.GSON}") + "testImplementation"("org.json:json:20180130") // retain this for testing reasons + "testImplementation"("com.google.guava:guava:28.1-jre") +} \ No newline at end of file diff --git a/common/src/main/java/com/vexsoftware/votifier/support/forwarding/cache/VoteCache.java b/common/src/main/java/com/vexsoftware/votifier/support/forwarding/cache/VoteCache.java index 4462ce2..c6fa42e 100644 --- a/common/src/main/java/com/vexsoftware/votifier/support/forwarding/cache/VoteCache.java +++ b/common/src/main/java/com/vexsoftware/votifier/support/forwarding/cache/VoteCache.java @@ -51,6 +51,6 @@ public interface VoteCache { * @return A collection of all votes which were previously in the cache under the player */ default Collection evictPlayer(String player) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } } diff --git a/common/src/test/java/com/vexsoftware/votifier/util/ArgsToVoteTest.java b/common/src/test/java/com/vexsoftware/votifier/util/ArgsToVoteTest.java index f21f512..7e00c39 100644 --- a/common/src/test/java/com/vexsoftware/votifier/util/ArgsToVoteTest.java +++ b/common/src/test/java/com/vexsoftware/votifier/util/ArgsToVoteTest.java @@ -37,20 +37,20 @@ public class ArgsToVoteTest { }); } - @ParameterizedTest - @ValueSource(strings = { "servicename", "address", "timestamp" }) - void handlesAdditionalKeywordArguments(String key) throws Exception { - Vote vote = ArgsToVote.parse(new String[] { "username=abc123", key + "=dummy" }); - - // Find the getter on the Vote object - for (Method method : Vote.class.getDeclaredMethods()) { - if (method.getName().toLowerCase(Locale.ENGLISH).equals("get" + key) && method.getParameterCount() == 0) { - assertEquals("dummy", method.invoke(vote)); - return; - } - } - - fail("Unable to find appropriate getter - this is a bug"); + @Test + void handleServiceNameGetter() { + Vote vote = ArgsToVote.parse(new String[] { "username=abc123", "servicename=dummy" }); + assertEquals("dummy", vote.getServiceName()); + } + @Test + void handleAddressGetter() { + Vote vote = ArgsToVote.parse(new String[] { "username=abc123", "address=dummy" }); + assertEquals("dummy", vote.getAddress()); + } + @Test + void handleTimestampGetter() { + Vote vote = ArgsToVote.parse(new String[] { "username=abc123", "timestamp=dummy" }); + assertEquals("dummy", vote.getTimeStamp()); } @Test @@ -59,49 +59,6 @@ public class ArgsToVoteTest { assertEquals("dummy_user", vote.getUsername()); } - @ParameterizedTest - @ValueSource(strings = { "servicename", "address", "timestamp" }) - void handlesMixedUsernameAndKeywordArgument(String key) throws Exception { - Vote vote = ArgsToVote.parse(new String[] { "abc123", key + "=dummy" }); - - assertEquals("abc123", vote.getUsername()); - - // Find the getter on the Vote object - for (Method method : Vote.class.getDeclaredMethods()) { - if (method.getName().toLowerCase(Locale.ENGLISH).equals("get" + key) && method.getParameterCount() == 0) { - assertEquals("dummy", method.invoke(vote)); - return; - } - } - - fail("Unable to find appropriate getter - this is a bug"); - } - - @ParameterizedTest - @MethodSource("powerSetArgs") - void handlesMixedKeywordArguments(Set keys) throws Exception { - String[] args = new String[keys.size() + 1]; - args[0] = "abc123"; - for (int i = 0; i < keys.size(); i++) { - args[i + 1] = ImmutableList.copyOf(keys).get(i) + "=dummy"; - } - Vote vote = ArgsToVote.parse(args); - - assertEquals("abc123", vote.getUsername()); - - // Find the getters on the Vote object - outer: for (String key : keys) { - for (Method method : Vote.class.getDeclaredMethods()) { - if (method.getName().toLowerCase(Locale.ENGLISH).equals("get" + key) && method.getParameterCount() == 0) { - assertEquals("dummy", method.invoke(vote)); - continue outer; - } - } - - fail("Unable to find appropriate getter - this is a bug"); - } - } - private static Stream> powerSetArgs() { return Sets.powerSet(ImmutableSet.of("servicename", "address", "timestamp")).stream(); } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..52fa776 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +group=com.vexsoftware +version=3.0.0-SNAPSHOT \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f80bbf..7645e29 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip diff --git a/publish.gradle b/publish.gradle deleted file mode 100644 index a89903c..0000000 --- a/publish.gradle +++ /dev/null @@ -1,52 +0,0 @@ -// This file contains special build instructions specifically for the ParallelBlock CI in order to instruct it how to -// build the project. Usually, this shouldn't be interacted with by a human. - -import com.mashape.unirest.http.* - -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'com.mashape.unirest:unirest-java:1.4.9' - } -} - -subprojects { - apply plugin: "maven-publish" - publishing { - repositories { - maven { - name 'ibj' - if (project.version.endsWith("-SNAPSHOT")) - url "$System.env.SNAPSHOT_REPO" - else - url "$System.env.RELEASE_REPO" - credentials { - username "$System.env.REPO_USR" - password "$System.env.REPO_PSW" - } - } - } - publications { - versioned(MavenPublication) { - from components.java - } - } - } - - if (System.env.LATEST_BUILD) { - task publishLatestToIbjBlockRaw { - inputs.files(configurations.archives.artifacts.files) - outputs.upToDateWhen {false} - doLast { - configurations.archives.artifacts.each { - def resp = Unirest.put("$System.env.RAW_UPLOAD_PATH/${it.name}.${it.extension}") - .basicAuth("$System.env.REPO_USR", "$System.env.REPO_PSW") - .body(it.file.bytes).asString() - assert resp.status >= 200 && resp.status <= 299 - } - } - } - } -} diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 3aa1fb1..0000000 --- a/settings.gradle +++ /dev/null @@ -1,20 +0,0 @@ -rootProject.name = 'nuvotifier' - -include 'api' -findProject(':api')?.name = 'nuvotifier-api' - -include 'common' -findProject(':common')?.name = 'nuvotifier-common' - -include 'bukkit' -findProject(':bukkit')?.name = 'nuvotifier-bukkit' -include 'bungeecord' -findProject(':bungeecord')?.name = 'nuvotifier-bungeecord' -include 'sponge' -findProject(':sponge')?.name = 'nuvotifier-sponge' - -include 'universal' -findProject(':universal')?.name = 'nuvotifier-universal' -include 'velocity' -findProject(':velocity')?.name = 'nuvotifier-velocity' - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..ee7e9bd --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,17 @@ +rootProject.name = "nuvotifier" + +include("nuvotifier-api") +project(":nuvotifier-api").projectDir = file("api") + + +include("nuvotifier-common") +project(":nuvotifier-common").projectDir = file("common") + +include("nuvotifier-bukkit") +project(":nuvotifier-bukkit").projectDir = file("bukkit") +include("nuvotifier-bungeecord") +project(":nuvotifier-bungeecord").projectDir = file("bungeecord") +include("nuvotifier-sponge") +project(":nuvotifier-sponge").projectDir = file("sponge") +include("nuvotifier-velocity") +project(":nuvotifier-velocity").projectDir = file("velocity") diff --git a/sponge/build.gradle b/sponge/build.gradle deleted file mode 100644 index b6f9c8f..0000000 --- a/sponge/build.gradle +++ /dev/null @@ -1,12 +0,0 @@ -apply plugin: "net.kyori.blossom" - -blossom { - replaceToken '@version@', project.version.toString() -} - -dependencies { - compileOnly group: "org.spongepowered", name: "spongeapi", version: "7.1.0" - annotationProcessor group: "org.spongepowered", name: "spongeapi", version: "7.1.0" - implementation project(":nuvotifier-api") - implementation project(":nuvotifier-common") -} diff --git a/sponge/build.gradle.kts b/sponge/build.gradle.kts new file mode 100644 index 0000000..6f1c7c2 --- /dev/null +++ b/sponge/build.gradle.kts @@ -0,0 +1,106 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.spongepowered.gradle.plugin.config.PluginLoaders +import org.spongepowered.plugin.metadata.model.PluginDependency + +plugins { + `java-library` + id("org.spongepowered.gradle.plugin") + id("net.kyori.blossom") +} + +applyPlatformAndCoreConfiguration() +applyShadowConfiguration() + +blossom { + replaceToken("@version@", project.ext["internalVersion"]) +} + +sponge { + apiVersion("7.2.0") + loader { + name(PluginLoaders.JAVA_PLAIN) + version("1.0") + } + + license("GNU General Public License v3.0") + + plugin("banmanager") { + displayName("BanManager") + entrypoint("me.confuser.banmanager.sponge.BMSpongePlugin") + description("A database driven punishment system") + links { + homepage("https://banmanagement.com/") + source("https://github.com/BanManagment/BanManager") + issues("https://github.com/BanManagment/BanManager") + } + contributor("confuser") { + description("Lead Developer") + } + dependency("spongeapi") { + loadOrder(PluginDependency.LoadOrder.AFTER) + optional(false) + version("7.2.0") + } + dependency("magibridge") { + loadOrder(PluginDependency.LoadOrder.AFTER) + optional(true) + version("api-7-SNAPSHOT") + } + } +} + +repositories { + maven { + name = "sponge" + url = uri("https://repo.spongepowered.org/maven/") + } +} + +configurations { + compileClasspath.get().extendsFrom(create("shadeOnly")) +} + +dependencies { + compileOnly("org.spongepowered:spongeapi:7.2.0") + + "api"(project(":nuvotifier-api")) + "api"(project(":nuvotifier-common")) +} + +val javaTarget = 8 // Sponge targets a minimum of Java 8 +java { + sourceCompatibility = JavaVersion.toVersion(javaTarget) + targetCompatibility = JavaVersion.toVersion(javaTarget) +} + +tasks.named("jar") { + val projectVersion = project.version + inputs.property("projectVersion", projectVersion) + manifest { + attributes("Implementation-Version" to projectVersion) + } +} + +tasks.named("shadowJar") { + configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"]) + + dependencies { + include(dependency(":nuvotifier-api")) + include(dependency(":nuvotifier-common")) + } + + exclude("GradleStart**") + exclude(".cache"); + exclude("LICENSE*") + exclude("META-INF/services/**") + exclude("META-INF/maven/**") + exclude("META-INF/versions/**") + exclude("org/intellij/**") + exclude("org/jetbrains/**") + exclude("**/module-info.class") + exclude("*.yml") +} + +tasks.named("assemble").configure { + dependsOn("shadowJar") +} diff --git a/universal/build.gradle b/universal/build.gradle deleted file mode 100644 index 0058684..0000000 --- a/universal/build.gradle +++ /dev/null @@ -1,93 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator - -import java.nio.file.Files -import java.nio.file.Paths -import java.nio.file.StandardCopyOption -import java.util.regex.Pattern -import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer -import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext -import shadow.org.apache.tools.zip.ZipEntry -import shadow.org.apache.tools.zip.ZipOutputStream -import org.gradle.api.file.FileTreeElement - -buildscript { - repositories { - gradlePluginPortal() - } - dependencies { - classpath 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0' - } -} - -class NettyEpollTransformer implements Transformer { - private java.nio.file.Path extractedNettyNative - - boolean canTransformResource(FileTreeElement element) { - return element.name.endsWith("libnetty_transport_native_epoll_x86_64.so") - } - - void transform(TransformerContext context) { - this.extractedNettyNative = Files.createTempFile("nuvotifer_build", ".so") - Files.copy(context.is, this.extractedNettyNative, StandardCopyOption.REPLACE_EXISTING) - } - - boolean hasTransformedResource() { this.extractedNettyNative != null } - - void modifyOutputStream(ZipOutputStream jos, boolean preserveFileTimestamps) { - ZipEntry entry = new ZipEntry("META-INF/native/libcom_vexsoftware_votifier_netty_transport_native_epoll_x86_64.so") - entry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, entry.time) - jos.putNextEntry(entry) - Files.copy(this.extractedNettyNative, jos) - Files.delete(this.extractedNettyNative) - } -} - -apply plugin: 'com.github.johnrengelman.shadow' - -dependencies { - implementation project(":nuvotifier-api") - implementation project(":nuvotifier-common") - implementation project(":nuvotifier-bukkit") - implementation project(":nuvotifier-bungeecord") - implementation project(":nuvotifier-sponge") - implementation project(":nuvotifier-velocity") -} - -shadowJar { - archiveBaseName = 'nuvotifier' - relocate "io.netty", "com.vexsoftware.votifier.io.netty" - relocate "org.json", "com.vexsoftware.votifier.json" - relocate new SimpleRelocator("com.google.code", "com.vexsoftware.votifier.google.code", new ArrayList(), Collections.singletonList("com.vexsoftware.votifier.sponge")) - relocate "com.google.gson", "com.vexsoftware.votifier.google.gson" - relocate "org.apache.commons.io", "com.vexsoftware.votifier.commons.io" - - transform(NettyEpollTransformer.class) -} - -artifacts { - tasks.shadowJar.outputs.files.each { - archives(it) { - builtBy shadowJar - } - } -} - -def artifactPattern = Pattern.compile(/(.*)-([0-9]+\.)*[0-9]+(-SNAPSHOT)?-all\.jar/) - -task('linkLatest') { - dependsOn tasks.shadowJar - doLast { - tasks.shadowJar.outputs.files.each { - System.println(it.absolutePath) - def noVerMatcher = artifactPattern.matcher(it.absolutePath) - if (!noVerMatcher.matches()) - throw new IllegalStateException("path does not match") - - def noVer = Paths.get(noVerMatcher.group(1) + ".jar") - def versnd = it.toPath() - Files.copy(versnd, noVer, StandardCopyOption.REPLACE_EXISTING) - } - } -} - -build.dependsOn linkLatest diff --git a/velocity/build.gradle b/velocity/build.gradle deleted file mode 100644 index 5f173f9..0000000 --- a/velocity/build.gradle +++ /dev/null @@ -1,12 +0,0 @@ -apply plugin: "net.kyori.blossom" - -blossom { - replaceToken '@version@', project.version -} - -dependencies { - compileOnly "com.velocitypowered:velocity-api:1.1.0-SNAPSHOT" - annotationProcessor "com.velocitypowered:velocity-api:1.1.0-SNAPSHOT" - implementation project(":nuvotifier-api") - implementation project(":nuvotifier-common") -} \ No newline at end of file diff --git a/velocity/build.gradle.kts b/velocity/build.gradle.kts new file mode 100644 index 0000000..cb7f48c --- /dev/null +++ b/velocity/build.gradle.kts @@ -0,0 +1,64 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +plugins { + `java-library` + id("net.kyori.blossom") +} + +applyPlatformAndCoreConfiguration() +applyShadowConfiguration() + +blossom { + replaceToken("@version@", project.ext["internalVersion"]) +} + +repositories { + maven { + name = "velocity" + url = uri("https://nexus.velocitypowered.com/repository/maven-public/") + } +} + +configurations { + compileClasspath.get().extendsFrom(create("shadeOnly")) +} + +dependencies { + compileOnly("com.velocitypowered:velocity-api:${Versions.VELOCITY}") + annotationProcessor("com.velocitypowered:velocity-api:${Versions.VELOCITY}") + + "api"(project(":nuvotifier-api")) + "api"(project(":nuvotifier-common")) +} + +tasks.named("jar") { + val projectVersion = project.version + inputs.property("projectVersion", projectVersion) + manifest { + attributes("Implementation-Version" to projectVersion) + } +} + +tasks.named("shadowJar") { + configurations = listOf(project.configurations["shadeOnly"], project.configurations["runtimeClasspath"]) + + dependencies { + include(dependency(":nuvotifier-api")) + include(dependency(":nuvotifier-common")) + } + + exclude("GradleStart**") + exclude(".cache"); + exclude("LICENSE*") + exclude("META-INF/services/**") + exclude("META-INF/maven/**") + exclude("META-INF/versions/**") + exclude("org/intellij/**") + exclude("org/jetbrains/**") + exclude("**/module-info.class") + exclude("*.yml") +} + +tasks.named("assemble").configure { + dependsOn("shadowJar") +} \ No newline at end of file