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
105 changes: 68 additions & 37 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id 'java-library'
id 'maven-publish'
id 'checkstyle'
id 'com.gradleup.shadow' version '8.3.5'
id "org.jetbrains.kotlin.jvm" version "2.0.21"
}

version = System.getenv('GITHUB_VERSION') ?: 'local'
Expand All @@ -14,11 +17,23 @@ compileJava {
targetCompatibility = JavaVersion.VERSION_17
}

// todo: Enable test when convert them to use mockbukkit like mv-core
compileTestJava {
compileKotlin {
// We're not using Kotlin in the plugin itself, just tests!
enabled = false
}

compileTestJava {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

compileTestKotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
javaParameters.set(true)
}
}

repositories {
mavenLocal()
mavenCentral()
Expand Down Expand Up @@ -55,14 +70,15 @@ repositories {

dependencies {
// Spigot
implementation('org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT') {
compileOnly('org.spigotmc:spigot-api:1.21.3-R0.1-SNAPSHOT') {
exclude group: 'junit', module: 'junit'
}

// Core
// TODO update to correct version once we have it published
implementation 'org.mvplugins.multiverse.core:multiverse-core:5.0.0-SNAPSHOT'


// Config
api 'com.dumptruckman.minecraft:JsonConfiguration:1.2-SNAPSHOT'
api 'net.minidev:json-smart:2.5.1'
Expand All @@ -82,9 +98,18 @@ dependencies {
}

// Tests
testImplementation 'com.github.MilkBowl:VaultAPI:1.7.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:3.11.2'
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.21'
testImplementation 'org.mockbukkit.mockbukkit:mockbukkit-v1.21:4.24.1'
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation 'com.natpryce:hamkrest:1.8.0.1'
testImplementation 'org.mockito.kotlin:mockito-kotlin:4.1.0'

// hk2 for annotation processing only
compileOnly('org.glassfish.hk2:hk2-api:3.0.3') {
exclude group: '*', module: '*'
}
annotationProcessor 'org.glassfish.hk2:hk2-metadata-generator:3.0.3'
testAnnotationProcessor 'org.glassfish.hk2:hk2-metadata-generator:3.0.3'
}


Expand All @@ -97,37 +122,27 @@ tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}

tasks.withType(JavaCompile) {
configure(options) {
options.compilerArgs << '-Aorg.glassfish.hk2.metadata.location=META-INF/hk2-locator/Multiverse-Inventories'
}
}

tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8'
}


configurations {
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
it.outgoing.artifact(shadowJar)
}
}

publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/Multiverse/Multiverse-Inventories"
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
configurations.findAll { !it.name.startsWith('test') }.each {
it.exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}


processResources {
def props = [version: "${project.version}"]
inputs.properties props
Expand All @@ -141,44 +156,60 @@ processResources {
outputs.upToDateWhen { false }
}


checkstyle {
toolVersion = '6.1.1'
configFile file('config/mv_checks.xml')
ignoreFailures = true
}


javadoc {
source = sourceSets.main.allJava
classpath = configurations.compileClasspath
}


project.configurations.api.canBeResolved = true

shadowJar {
relocate 'com.dumptruckman.minecraft.util.Logging', 'org.mvplugins.multiverse.inventories.utils.InvLogging'
relocate 'com.dumptruckman.minecraft.util.DebugLog', 'org.mvplugins.multiverse.inventories.utils.DebugFileLogger'
relocate 'com.dumptruckman.bukkit.configuration', 'org.mvplugins.multiverse.inventories.utils.configuration'
relocate 'io.papermc.lib', 'org.mvplugins.multiverse.inventories.utils.paperlib'
relocate 'net.minidev.json', 'org.mvplugins.multiverse.inventories.utils.json'
relocate 'net.minidev', 'org.mvplugins.multiverse.inventories.utils.minidev'

configurations = [project.configurations.api]

archiveClassifier.set('')

dependencies {
exclude(dependency {
it.moduleGroup == 'org.jetbrains.kotlin'
})
exclude(dependency {
it.moduleGroup == 'org.jetbrains'
})
exclude(dependency {
it.moduleGroup == 'org.ow2.asm'
})
}
}

build.dependsOn shadowJar
jar.enabled = false

tasks.register('runHabitatGenerator', JavaExec) {
classpath = configurations["compileClasspath"]
mainClass.set('org.mvplugins.multiverse.external.jvnet.hk2.generator.HabitatGenerator')

args = [
'--file', "build/libs/multiverse-inventories-$version" + ".jar",
'--locator', 'Multiverse-Inventories',
]
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/Multiverse/Multiverse-Inventories"
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
tasks.named("build") { finalizedBy("runHabitatGenerator") }
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mvplugins.multiverse.inventories;

import com.dumptruckman.minecraft.util.Logging;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.core.api.event.MVConfigReloadEvent;
import org.mvplugins.multiverse.core.api.event.MVDebugModeEvent;
import org.mvplugins.multiverse.core.api.event.MVDumpsDebugInfoEvent;
Expand Down Expand Up @@ -36,7 +37,6 @@
import org.bukkit.inventory.InventoryHolder;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import uk.co.tggl.pluckerpluck.multiinv.MultiInv;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.mvplugins.multiverse.core.inject.PluginServiceLocator;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jakarta.inject.Provider;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.annotations.Service;
import org.mvplugins.multiverse.external.vavr.control.Try;
import uk.co.tggl.pluckerpluck.multiinv.MultiInv;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mvplugins.multiverse.inventories;

import org.bukkit.plugin.Plugin;
import org.mvplugins.multiverse.core.inject.binder.JavaPluginBinder;
import org.mvplugins.multiverse.core.submodules.MVPlugin;
import org.mvplugins.multiverse.external.glassfish.hk2.utilities.binding.ScopedBindingBuilder;
Expand All @@ -14,6 +15,6 @@ protected MultiverseInventoriesPluginBinder(@NotNull MultiverseInventories plugi
@Override
protected ScopedBindingBuilder<MultiverseInventories> bindPluginClass
(ScopedBindingBuilder<MultiverseInventories> bindingBuilder) {
return super.bindPluginClass(bindingBuilder).to(MVPlugin.class).to(MultiverseInventories.class);
return super.bindPluginClass(bindingBuilder).to(Plugin.class).to(MVPlugin.class).to(MultiverseInventories.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.annotations.Service;

@Service
@CommandAlias("mvinv")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.annotations.Service;

import java.util.List;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.annotations.Service;

import java.util.Collection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.annotations.Service;

@Service
@CommandAlias("mvinv")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax;
import org.mvplugins.multiverse.external.jakarta.inject.Inject;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.external.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.annotations.Service;

@Service
@CommandAlias("mvinv")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.mvplugins.multiverse.inventories

import kotlin.test.Test
import kotlin.test.assertNotNull

open class MockBukkitTest : TestWithMockBukkit() {

@Test
fun `MockBukkit loads the plugin`() {
assertNotNull(multiverseInventories)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.mvplugins.multiverse.inventories

import com.dumptruckman.minecraft.util.Logging
import org.bukkit.Location
import org.bukkit.configuration.MemorySection
import org.bukkit.configuration.file.YamlConfiguration
import org.mockbukkit.mockbukkit.MockBukkit
import org.mvplugins.multiverse.core.MultiverseCore
import org.mvplugins.multiverse.core.inject.PluginServiceLocator
import org.mvplugins.multiverse.core.utils.TestingMode
import org.mvplugins.multiverse.inventories.mock.MVServerMock
import kotlin.test.*

/**
* Basic abstract test class that sets up MockBukkit and MultiverseCore.
*/
abstract class TestWithMockBukkit {

protected lateinit var server: MVServerMock
protected lateinit var multiverseCore: MultiverseCore
protected lateinit var multiverseInventories: MultiverseInventories
protected lateinit var serviceLocator : PluginServiceLocator

@BeforeTest
fun setUpMockBukkit() {
TestingMode.enable()
server = MockBukkit.mock(MVServerMock())
multiverseCore = MockBukkit.load(MultiverseCore::class.java)
multiverseInventories = MockBukkit.load(MultiverseInventories::class.java)
Logging.setDebugLevel(3)
serviceLocator = multiverseInventories.serviceLocator
assertNotNull(server.commandMap)
}

@AfterTest
fun tearDownMockBukkit() {
MockBukkit.unmock()
}

fun getResourceAsText(path: String): String? = object {}.javaClass.getResource(path)?.readText()

fun assertConfigEquals(expectedPath: String, actualPath: String) {
val actualString = multiverseInventories.dataFolder.toPath().resolve(actualPath).toFile().readText()
val expectedString = getResourceAsText(expectedPath)
assertNotNull(expectedString)

val actualYaml = YamlConfiguration()
actualYaml.loadFromString(actualString)
val actualYamlKeys = HashSet(actualYaml.getKeys(true))

val expectedYaml = YamlConfiguration()
expectedYaml.loadFromString(expectedString)
val expectedYamlKeys = HashSet(expectedYaml.getKeys(true))

for (key in expectedYamlKeys) {
assertNotNull(actualYamlKeys.remove(key), "Key $key is missing in actual config")
val actualValue = actualYaml.get(key)
if (actualValue is MemorySection) {
continue
}
assertEquals(expectedYaml.get(key), actualYaml.get(key), "Value for $key is different.")
}
for (key in actualYamlKeys) {
assertNull(actualYaml.get(key), "Key $key is present in actual config when it should be empty.")
}

assertEquals(0, actualYamlKeys.size,
"Actual config has more keys than expected config. The following keys are missing: $actualYamlKeys")
}

fun assertLocationEquals(expected: Location?, actual: Location?) {
assertEquals(expected?.world, actual?.world, "Worlds don't match for location comparison ($expected, $actual)")
assertEquals(expected?.x, actual?.x, "X values don't match for location comparison ($expected, $actual)")
assertEquals(expected?.y, actual?.y, "Y values don't match for location comparison ($expected, $actual)")
assertEquals(expected?.z, actual?.z, "Z values don't match for location comparison ($expected, $actual)")
assertEquals(expected?.yaw, actual?.yaw, "Yaw values don't match for location comparison ($expected, $actual)")
assertEquals(expected?.pitch, actual?.pitch, "Pitch values don't match for location comparison ($expected, $actual)")
}
}
Loading
Loading