From 432e88f3541f7a3fbb864c56283b1836c23a8c8f Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Wed, 12 May 2021 19:03:59 +0100 Subject: [PATCH] Add a simple java 16 project test --- .../test/integration/Java16ProjectTest.groovy | 49 +++++++++++++++++++ .../resources/projects/java16/build.gradle | 27 ++++++++++ .../projects/java16/gradle.properties | 9 ++++ .../resources/projects/java16/settings.gradle | 2 + .../java/net/fabricmc/example/ExampleMod.java | 14 ++++++ .../fabricmc/example/mixin/ExampleMixin.java | 15 ++++++ .../java16/src/main/resources/fabric.mod.json | 36 ++++++++++++++ .../src/main/resources/modid.mixins.json | 14 ++++++ 8 files changed, 166 insertions(+) create mode 100644 src/test/groovy/net/fabricmc/loom/test/integration/Java16ProjectTest.groovy create mode 100644 src/test/resources/projects/java16/build.gradle create mode 100644 src/test/resources/projects/java16/gradle.properties create mode 100644 src/test/resources/projects/java16/settings.gradle create mode 100644 src/test/resources/projects/java16/src/main/java/net/fabricmc/example/ExampleMod.java create mode 100644 src/test/resources/projects/java16/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java create mode 100644 src/test/resources/projects/java16/src/main/resources/fabric.mod.json create mode 100644 src/test/resources/projects/java16/src/main/resources/modid.mixins.json diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/Java16ProjectTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/Java16ProjectTest.groovy new file mode 100644 index 0000000..79fa87d --- /dev/null +++ b/src/test/groovy/net/fabricmc/loom/test/integration/Java16ProjectTest.groovy @@ -0,0 +1,49 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2016, 2017, 2018 FabricMC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.fabricmc.loom.test.integration + +import net.fabricmc.loom.test.util.ProjectTestTrait +import spock.lang.Specification +import spock.lang.Unroll + +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS + +class Java16ProjectTest extends Specification implements ProjectTestTrait { + @Override + String name() { + "java16" + } + + @Unroll + def "build (gradle #gradle)"() { + when: + def result = create("build", gradle) + then: + result.task(":build").outcome == SUCCESS + where: + gradle | _ + DEFAULT_GRADLE | _ + } +} diff --git a/src/test/resources/projects/java16/build.gradle b/src/test/resources/projects/java16/build.gradle new file mode 100644 index 0000000..b97f524 --- /dev/null +++ b/src/test/resources/projects/java16/build.gradle @@ -0,0 +1,27 @@ +plugins { + id 'fabric-loom' + id 'maven-publish' +} + +sourceCompatibility = JavaVersion.VERSION_16 +targetCompatibility = JavaVersion.VERSION_16 + +archivesBaseName = project.archives_base_name +version = project.mod_version +group = project.maven_group + +dependencies { + // To change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +} + +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" + it.options.release = 16 +} + +java { + withSourcesJar() +} diff --git a/src/test/resources/projects/java16/gradle.properties b/src/test/resources/projects/java16/gradle.properties new file mode 100644 index 0000000..0d8b3c7 --- /dev/null +++ b/src/test/resources/projects/java16/gradle.properties @@ -0,0 +1,9 @@ +org.gradle.jvmargs=-Xmx1G + +minecraft_version=21w19a +yarn_mappings=21w19a+build.1 +loader_version=0.11.2 + +mod_version = 1.0.0 +maven_group = com.example +archives_base_name = fabric-example-mod diff --git a/src/test/resources/projects/java16/settings.gradle b/src/test/resources/projects/java16/settings.gradle new file mode 100644 index 0000000..c162c36 --- /dev/null +++ b/src/test/resources/projects/java16/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = "fabric-example-mod" + diff --git a/src/test/resources/projects/java16/src/main/java/net/fabricmc/example/ExampleMod.java b/src/test/resources/projects/java16/src/main/java/net/fabricmc/example/ExampleMod.java new file mode 100644 index 0000000..e5ed082 --- /dev/null +++ b/src/test/resources/projects/java16/src/main/java/net/fabricmc/example/ExampleMod.java @@ -0,0 +1,14 @@ +package net.fabricmc.example; + +import net.fabricmc.api.ModInitializer; + +public class ExampleMod implements ModInitializer { + @Override + public void onInitialize() { + // This code runs as soon as Minecraft is in a mod-load-ready state. + // However, some things (like resources) may still be uninitialized. + // Proceed with mild caution. + + System.out.println("Hello Fabric world!"); + } +} diff --git a/src/test/resources/projects/java16/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java b/src/test/resources/projects/java16/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java new file mode 100644 index 0000000..83ee1a8 --- /dev/null +++ b/src/test/resources/projects/java16/src/main/java/net/fabricmc/example/mixin/ExampleMixin.java @@ -0,0 +1,15 @@ +package net.fabricmc.example.mixin; + +import net.minecraft.client.gui.screen.TitleScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(TitleScreen.class) +public class ExampleMixin { + @Inject(at = @At("HEAD"), method = "init()V") + private void init(CallbackInfo info) { + System.out.println("This line is printed by an example mod mixin!"); + } +} diff --git a/src/test/resources/projects/java16/src/main/resources/fabric.mod.json b/src/test/resources/projects/java16/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..9c6ccfa --- /dev/null +++ b/src/test/resources/projects/java16/src/main/resources/fabric.mod.json @@ -0,0 +1,36 @@ +{ + "schemaVersion": 1, + "id": "modid", + "version": "${version}", + + "name": "Example Mod", + "description": "This is an example description! Tell everyone what your mod is about!", + "authors": [ + "Me!" + ], + "contact": { + "homepage": "https://fabricmc.net/", + "sources": "https://github.com/FabricMC/fabric-example-mod" + }, + + "license": "CC0-1.0", + + "environment": "*", + "entrypoints": { + "main": [ + "net.fabricmc.example.ExampleMod" + ] + }, + "mixins": [ + "modid.mixins.json" + ], + + "depends": { + "fabricloader": ">=0.7.4", + "fabric": "*", + "minecraft": "1.16.x" + }, + "suggests": { + "another-mod": "*" + } +} diff --git a/src/test/resources/projects/java16/src/main/resources/modid.mixins.json b/src/test/resources/projects/java16/src/main/resources/modid.mixins.json new file mode 100644 index 0000000..21fe73a --- /dev/null +++ b/src/test/resources/projects/java16/src/main/resources/modid.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.fabricmc.example.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + ], + "client": [ + "ExampleMixin" + ], + "injectors": { + "defaultRequire": 1 + } +}