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
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ public static List<Path[]> resolve() {

final String fileName = path.getFileName().toString();

if (false) {
if (fileName.startsWith("junit-") || fileName.startsWith("mockito-")) {
if (Bootstrap.DEBUG) {
System.out.println("Ignored: " + path);
}
continue;
}

if (bootNames.contains(fileName)) {
if (bootNames.contains(fileName) || fileName.startsWith("org.jacoco.core-")) {
if (Bootstrap.DEBUG) {
System.out.println("Boot: " + path);
}
Expand Down
43 changes: 21 additions & 22 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.gradle.ext.compiler
import org.jetbrains.gradle.ext.delegateActions
import org.jetbrains.gradle.ext.settings
import org.spongepowered.gradle.vanilla.task.DecompileJarTask
import java.util.Locale

Expand Down Expand Up @@ -170,12 +173,28 @@ dependencies {
testImplementation(libs.mockito.junitJupiter) {
exclude(group = "org.junit.jupiter", module = "junit-jupiter-api")
}

testImplementation(libs.mixin)
}

minecraft {
accessWideners(main.resources.filter { it.name.endsWith(".accesswidener") })
}

idea {
project.settings {
delegateActions {
delegateBuildRunToGradle = false
testRunner = org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.GRADLE
}
compiler {
addNotNullAssertions = false
useReleaseOption = true
parallelCompilation = true
}
}
}

allprojects {
configurations.configureEach {
resolutionStrategy.dependencySubstitution {
Expand All @@ -186,7 +205,6 @@ allprojects {
}
}

apply(plugin = "org.jetbrains.gradle.plugin.idea-ext")
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "net.kyori.indra.licenser.spotless")
Expand All @@ -210,22 +228,6 @@ allprojects {
}
}

idea {
if (project != null) {
(project as ExtensionAware).extensions["settings"].run {
(this as ExtensionAware).extensions.getByType(org.jetbrains.gradle.ext.ActionDelegationConfig::class).run {
delegateBuildRunToGradle = false
testRunner = org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.PLATFORM
}
extensions.getByType(org.jetbrains.gradle.ext.IdeaCompilerConfiguration::class).run {
addNotNullAssertions = false
useReleaseOption = JavaVersion.current().isJava10Compatible
parallelCompilation = true
}
}
}
}

java {
val targetJavaVersion = JavaVersion.toVersion(apiJavaTarget.toInt())
sourceCompatibility = targetJavaVersion
Expand Down Expand Up @@ -270,14 +272,10 @@ allprojects {
val spongeSnapshotRepo: String? by project
val spongeReleaseRepo: String? by project
tasks {
val emptyAnnotationProcessors = objects.fileCollection()
withType(JavaCompile::class).configureEach {
options.compilerArgs.addAll(listOf("-Xmaxerrs", "1000"))
options.encoding = "UTF-8"
options.release.set(apiJavaTarget.toInt())
if (project.name != "testplugins" && System.getProperty("idea.sync.active") != null) {
options.annotationProcessorPath = emptyAnnotationProcessors // hack so IntelliJ doesn't try to run Mixin AP
}
}

withType(PublishToMavenRepository::class).configureEach {
Expand Down Expand Up @@ -437,7 +435,8 @@ tasks {
}

test {
useJUnitPlatform()
// tests can only be run in subprojects
enabled = false
}

check {
Expand Down
63 changes: 60 additions & 3 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.minecraftforge.gradle.common.util.RunConfig
import net.minecraftforge.gradle.userdev.UserDevExtension
import org.gradle.api.tasks.JavaExec
import org.gradle.internal.DefaultTaskExecutionRequest
import org.spongepowered.gradle.impl.AWToAT
Expand All @@ -22,6 +21,7 @@ plugins {
id("implementation-structure")
alias(libs.plugins.blossom)
alias(libs.plugins.forgeGradle)
jacoco
}

val commonProject = parent!!
Expand Down Expand Up @@ -89,6 +89,7 @@ val commonAppLaunch = commonProject.sourceSets.named("applaunch")
val commonAppLaunchConf = commonProject.sourceSets.named("applaunchConfig")
val commonMixins = commonProject.sourceSets.named("mixins")
val commonMain = commonProject.sourceSets.named("main")
val commonTest = commonProject.sourceSets.named("test")

// SpongeForge source sets
// Service layer
Expand Down Expand Up @@ -167,6 +168,12 @@ val main by sourceSets.named("main") {
spongeImpl.addDependencyToRuntimeOnly(bootstrapMain.get(), this)
spongeImpl.addDependencyToRuntimeOnly(bootstrapForge.get(), this)
}
val testSources = sourceSets.named("test") {
spongeImpl.addDependencyToImplementation(commonTest.get(), this)

spongeImpl.addDependencyToImplementation(bootstrapMain.get(), this)
spongeImpl.addDependencyToImplementation(bootstrapForge.get(), this)
}

configurations.configureEach {
// Fix that can be found in Forge MDK too
Expand All @@ -175,6 +182,10 @@ configurations.configureEach {
}
}

configurations.testRuntimeOnly {
exclude(module = "testplugins")
}

dependencies {
"minecraft"("net.minecraftforge:forge:$minecraftVersion-$forgeVersion")

Expand Down Expand Up @@ -213,6 +224,21 @@ dependencies {
testPluginsProject?.also {
runtimeOnly(project(it.path))
}

testImplementation(platform(apiLibs.junit.bom))
testImplementation(apiLibs.junit.api)
testImplementation(apiLibs.junit.params)
testImplementation(apiLibs.junit.launcher)
testRuntimeOnly(apiLibs.junit.engine)

testImplementation(libs.mockito.core)
testImplementation(libs.mockito.junitJupiter) {
exclude(group = "org.junit.jupiter", module = "junit-jupiter-api")
}

testRuntimeOnly(libs.jacoco.core) {
exclude(group = "org.ow2.asm")
}
}

val awFiles: Set<File> = files(commonMain.get().resources, main.resources).filter { it.name.endsWith(".accesswidener") }.files
Expand All @@ -221,7 +247,7 @@ AWToAT.convert(awFiles, atFile)

val mixinConfigs: MutableSet<String> = spongeImpl.mixinConfigurations

extensions.configure(UserDevExtension::class) {
minecraft {
mappings("official", "1.21.4")
accessTransformers.from(atFile)
reobf = false
Expand All @@ -246,7 +272,7 @@ extensions.configure(UserDevExtension::class) {
}

afterEvaluate {
extensions.configure(UserDevExtension::class) {
minecraft {
// Configure bootstrap dev
val bootFileNames = spongeImpl.buildRuntimeFileNames(serviceLayerConfig.get()) // service in boot during dev
val gameShadedFileNames = spongeImpl.buildRuntimeFileNames(gameShadedLibrariesConfig.get())
Expand Down Expand Up @@ -399,6 +425,37 @@ tasks {
assemble {
dependsOn(universalJar)
}

test {
useJUnitPlatform()

testClassesDirs = commonTest.get().output.classesDirs + testSources.get().output.classesDirs

val runServer = minecraft.runs.getByName("server")
jvmArgs(runServer.jvmArgs)
jvmArgs("-Dsponge.test.args=" + runServer.args.joinToString(" "))
jvmArgs("-Dsponge.jacoco.packages=org.spongepowered")
workingDir = layout.buildDirectory.dir("test-run").get().asFile

doFirst {
// reset test directory
workingDir.deleteRecursively()
workingDir.mkdirs()
workingDir.resolve("eula.txt").writeText("eula=true")
}

extensions.configure(JacocoTaskExtension::class) {
excludeClassLoaders = listOf("cpw.mods.modlauncher.TransformingClassLoader")
}

finalizedBy(jacocoTestReport)
}

jacocoTestReport {
sourceSets(commonAppLaunchConf.get(), commonAppLaunch.get(), commonLaunch.get(), commonAccessors.get(), commonMixins.get(), commonMain.get())
sourceSets(appLaunch, launch, lang, accessors, mixins, main)
dependsOn(test)
}
}

if (IdeHelper.isIdeaSync()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.regression.registry;
package org.spongepowered.forge.lang.locator;

import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.forgespi.locating.IModLocator;

public final class Test3Tile extends TileEntity { }
/**
* Hack.
* FML ClasspathLocator in our test env wants to load the lang/resources directory without a union, causing a conflict.
* Fortunately, when it detects certain services, it just skips the directory.
*/
public abstract class DummyModLocator implements IModLocator {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.spongepowered.forge.lang.locator.DummyModLocator
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.util;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.ExtendWith;
import org.spongepowered.common.test.UnitTestExtension;


@Disabled
@ExtendWith(UnitTestExtension.class)
public class ReflectionTest {
package org.spongepowered.forge.locator;

import net.minecraftforge.forgespi.locating.IModLocator;

/**
* Hack.
* FML ClasspathLocator in our test env wants to load the main/resources directory without a union, causing a conflict.
* Fortunately, when it detects certain services, it just skips the directory.
*/
public abstract class DummyModLocator implements IModLocator {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.spongepowered.forge.locator.DummyModLocator
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.test.block;
package org.spongepowered.forge;

import net.minecraft.world.level.block.Block;
import org.junit.jupiter.api.Test;
import org.spongepowered.api.Sponge;

public class SpongeBlock extends Block {
public SpongeBlock(Properties param0) {
super(param0);
}
public class ServerTest {

@Test
public void serverAvailable() {
Sponge.server();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,29 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.test.stub.registry;
package org.spongepowered.forge.boot;

import org.spongepowered.api.ResourceKey;
import org.spongepowered.common.test.stub.StubKey;
import org.spongepowered.plugin.PluginContainer;
import org.junit.platform.launcher.LauncherSession;
import org.junit.platform.launcher.LauncherSessionListener;
import org.spongepowered.common.applaunch.test.TestGameAccess;

public class StubRegistryFactory implements ResourceKey.Factory{
public class SpongeSessionListener implements LauncherSessionListener {
private ClassLoader previousLoader;

@Override
public ResourceKey of(final String namespace, final String value) {
return new StubKey(namespace, value);
}
public void launcherSessionOpened(final LauncherSession session) {
this.previousLoader = Thread.currentThread().getContextClassLoader();

@Override
public ResourceKey of(final PluginContainer plugin, final String value) {
return new StubKey(plugin.metadata().id(), value);
try {
Thread.currentThread().setContextClassLoader(SpongeTestBoot.getGameClassLoader());
} catch (Exception e) {
throw new RuntimeException(e);
}
}

@Override
public ResourceKey resolve(final String formatted) {
return new StubKey(formatted.split(":")[0], formatted.split(":")[1]);
public void launcherSessionClosed(final LauncherSession session) {
TestGameAccess.shutdownGame();
Thread.currentThread().setContextClassLoader(this.previousLoader);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.common.launch.mixin;
package org.spongepowered.forge.boot;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.common.SpongeImplHooks;
import org.spongepowered.bootstrap.forge.ForgeBootstrap;
import org.spongepowered.common.applaunch.test.TestGameAccess;

@Mixin(value = SpongeImplHooks.class, remap = false)
public class SpongeImplHooksMixin_Test {
public class SpongeTestBoot {

/**
* @author gabizou - unit test
* @reason unit test.
*
* @return
*/
@Overwrite
public static boolean isMainThread() {
return true;
public static ClassLoader getGameClassLoader() throws Exception {
if (TestGameAccess.getGameClassLoader() == null) {
final String[] args = System.getProperty("sponge.test.args").split(" ");
System.setProperty("sponge.test.active", "true");
new ForgeBootstrap(args).devBoot(false);
}
return TestGameAccess.getGameClassLoader();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.spongepowered.forge.boot.SpongeSessionListener
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ projectDescription=The SpongeAPI implementation targeting vanilla Minecraft and

mixinConfigs=mixins.sponge.accessors.json,mixins.sponge.api.json,mixins.sponge.concurrent.json,mixins.sponge.core.json,\
mixins.sponge.entityactivation.json,mixins.sponge.exploit.json,mixins.sponge.inventory.json,mixins.sponge.movementcheck.json,\
mixins.sponge.tracker.json,mixins.sponge.ipforward.json,mixins.sponge.optimization.json
mixins.sponge.tracker.json,mixins.sponge.ipforward.json,mixins.sponge.optimization.json,mixins.sponge.test.json
superClassChanges=common.superclasschange

minecraftVersion=1.21.4
Expand Down
Loading
Loading