Setup unit tests & format gradle files. (#3073)

This commit is contained in:
modmuss 2023-05-30 13:07:11 +01:00 committed by GitHub
parent 8cec7577f3
commit b3afc78b68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
54 changed files with 247 additions and 215 deletions

View file

@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
java: [17-jdk, 20-jdk]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:${{ matrix.java }}
options: --user root

View file

@ -6,7 +6,7 @@ on:
jobs:
labels:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: FabricMC/fabric-action-scripts@v2
with:

View file

@ -6,7 +6,7 @@ permissions:
jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:20-jdk
options: --user root

View file

@ -10,7 +10,7 @@ plugins {
id "idea"
id "maven-publish"
id 'jacoco'
id "fabric-loom" version "1.2.5" apply false
id "fabric-loom" version "1.2.7" apply false
id "com.diffplug.spotless" version "6.18.0"
id "org.ajoberstar.grgit" version "3.1.0"
id "com.matthewprenger.cursegradle" version "1.4.0"
@ -25,6 +25,7 @@ version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getB
logger.lifecycle("Building Fabric: " + version)
import net.fabricmc.loom.util.gradle.SourceSetHelper
import groovy.json.JsonSlurper
import org.apache.commons.codec.digest.DigestUtils
@ -139,7 +140,9 @@ allprojects {
setupRepositories(repositories)
}
if (it.name == "deprecated") return
if (it.name == "deprecated") {
return
}
apply plugin: "java-library"
apply plugin: "checkstyle"
@ -174,6 +177,11 @@ allprojects {
compileClasspath += testmod.compileClasspath
runtimeClasspath += testmod.runtimeClasspath
}
test {
compileClasspath += testmodClient.compileClasspath
runtimeClasspath += testmodClient.runtimeClasspath
}
}
loom {
@ -196,7 +204,9 @@ allprojects {
}
allprojects.each { p ->
if (project.name == "deprecated") return
if (project.name == "deprecated") {
return
}
loom.mods.register(p.name) {
sourceSet p.sourceSets.main
@ -218,6 +228,26 @@ allprojects {
testmodClientImplementation sourceSets.main.output
testmodClientImplementation sourceSets.client.output
testmodClientImplementation sourceSets.testmod.output
testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
testImplementation sourceSets.testmodClient.output
}
test {
useJUnitPlatform()
afterEvaluate {
// See: https://github.com/FabricMC/fabric-loader/pull/585
def classPathGroups = loom.mods.stream()
.map { modSettings ->
SourceSetHelper.getClasspath(modSettings, getProject()).stream()
.map(File.&getAbsolutePath)
.collect(Collectors.joining(File.pathSeparator))
}
.collect(Collectors.joining(File.pathSeparator+File.pathSeparator))
systemProperty("fabric.classPathGroups", classPathGroups)
}
}
tasks.withType(ProcessResources).configureEach {
@ -236,10 +266,10 @@ allprojects {
checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = "10.9.3"
toolVersion = "10.11.0"
}
tasks.withType(AbstractArchiveTask) {
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
@ -251,11 +281,11 @@ allprojects {
}
// Run this task after updating minecraft to regenerate any required resources
task generateResources {
tasks.register('generateResources') {
group = "fabric"
}
task testmodJar(type: Jar) {
tasks.register('testmodJar', Jar) {
from sourceSets.testmod.output
from sourceSets.testmodClient.output
destinationDirectory = new File(project.buildDir, "devlibs")
@ -278,7 +308,8 @@ allprojects {
}
}
task remapTestmodJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: testmodJar) {
tasks.register('remapTestmodJar', net.fabricmc.loom.task.RemapJarTask) {
dependsOn testmodJar
input = testmodJar.archiveFile
archiveClassifier = "testmod"
addNestedDependencies = false
@ -287,7 +318,7 @@ allprojects {
}
build.dependsOn remapTestmodJar
task validateMixinNames(type: net.fabricmc.loom.task.ValidateMixinNameTask) {
tasks.register('validateMixinNames', net.fabricmc.loom.task.ValidateMixinNameTask) {
source(sourceSets.main.output)
source(sourceSets.client.output)
source(sourceSets.testmod.output)
@ -302,7 +333,9 @@ remapTestmodJar {
def testModJarTasks = []
subprojects {
if (it.name == "deprecated" || !(it.file("src/testmod").exists() || it.file("src/testmodClient").exists())) return
if (it.name == "deprecated" || !(it.file("src/testmod").exists() || it.file("src/testmodClient").exists())) {
return
}
testModJarTasks += it.tasks.remapTestmodJar
}
@ -342,7 +375,9 @@ javadoc {
}
allprojects.each {
if (it.name == "deprecated") return
if (it.name == "deprecated") {
return
}
source(it.sourceSets.main.allJava)
source(it.sourceSets.client.allJava)
@ -353,7 +388,7 @@ javadoc {
failOnError true
}
task javadocJar(type: Jar) {
tasks.register('javadocJar', Jar) {
dependsOn javadoc
from javadoc.destinationDir
//Set as `fatjavadoc` to prevent an ide form trying to use this javadoc, over using the modules javadoc
@ -401,7 +436,10 @@ loom {
}
test.dependsOn runGametest
def coverageTasks = [runGametestCoverage, runAutoTestClientCoverage]
def coverageTasks = [
runGametestCoverage,
runAutoTestClientCoverage
]
jacoco {
coverageTasks.forEach {
@ -409,23 +447,24 @@ jacoco {
}
}
task coverage(type: JacocoReport, dependsOn: coverageTasks) {
tasks.register('coverage', JacocoReport) {
dependsOn coverageTasks
coverageTasks.forEach {
executionData it
}
// Add all source as input
allprojects { p ->
if (p.path.startsWith(":deprecated")) return
if (p.path.startsWith(":deprecated")) {
return
}
sourceSets p.sourceSets.main, p.sourceSets.client, p.sourceSets.testmod, p.sourceSets.testmodClient
}
// Exclude mixins
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: '**/mixin/**')
}))
}
}
configurations {
@ -447,15 +486,12 @@ dependencies {
import net.fabricmc.loom.util.Platform
// This is very far beyond loom's API if you copy this, you're on your own.
task runProductionAutoTestClient(type: JavaExec, dependsOn: [remapJar, remapTestmodJar]) {
tasks.register('runProductionAutoTestClient', JavaExec) {
dependsOn remapJar, remapTestmodJar, downloadAssets
classpath.from configurations.productionRuntime
mainClass = "net.fabricmc.loader.impl.launch.knot.KnotClient"
workingDir = file("run")
afterEvaluate {
dependsOn downloadAssets
}
doFirst {
classpath.from loom.minecraftProvider.minecraftClientJar
workingDir.mkdirs()
@ -479,7 +515,7 @@ task runProductionAutoTestClient(type: JavaExec, dependsOn: [remapJar, remapTest
}
}
task serverPropertiesJar(type: Jar) {
tasks.register('serverPropertiesJar', Jar) {
def propsFile = file("build/tmp/install.properties")
doFirst {
@ -494,7 +530,8 @@ task serverPropertiesJar(type: Jar) {
from(propsFile)
}
task runProductionAutoTestServer(type: JavaExec, dependsOn: [remapJar, remapTestmodJar, serverPropertiesJar]) {
tasks.register('runProductionAutoTestServer', JavaExec) {
dependsOn remapJar, remapTestmodJar, serverPropertiesJar
classpath.from configurations.productionRuntimeServer, serverPropertiesJar
mainClass = "net.fabricmc.installer.ServerLauncher"
workingDir = file("run")
@ -511,10 +548,21 @@ task runProductionAutoTestServer(type: JavaExec, dependsOn: [remapJar, remapTest
}
}
// Format all the gradle files
spotless {
groovyGradle {
target 'src/**/*.gradle', '*.gradle', 'gradle/*.gradle'
greclipse()
}
}
def addPomMetadataInformation(Project project, MavenPom pom) {
def modJsonFile = project.file("src/main/resources/fabric.mod.json")
if (!modJsonFile.exists())
if (!modJsonFile.exists()) {
modJsonFile = project.file("src/client/resources/fabric.mod.json")
}
def modJson = new JsonSlurper().parse(modJsonFile)
pom.name = modJson.name
pom.url = "https://github.com/FabricMC/fabric/tree/HEAD/${project.rootDir.relativePath(project.projectDir)}"
@ -543,7 +591,9 @@ def addPomMetadataInformation(Project project, MavenPom pom) {
}
subprojects {
if (it.name == "deprecated") return
if (it.name == "deprecated") {
return
}
dependencies {
testmodImplementation sourceSets.main.output
@ -608,7 +658,9 @@ publishing {
def depsNode = asNode().appendNode("dependencies")
subprojects.each {
// Dont depend on the deprecated modules in the main artifact.
if (it.path.startsWith(":deprecated")) return
if (it.path.startsWith(":deprecated")) {
return
}
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
@ -641,20 +693,22 @@ void setupRepositories(RepositoryHandler repositories) {
}
subprojects.each {
if (it.name == "deprecated") return
if (it.name == "deprecated") {
return
}
remapJar.dependsOn("${it.path}:remapJar")
}
// These modules are not included in the fat jar, maven will resolve them via the pom.
def devOnlyModules = [
"fabric-gametest-api-v1",
]
def devOnlyModules = ["fabric-gametest-api-v1",]
dependencies {
afterEvaluate {
subprojects.each {
if (it.name == "deprecated") return
if (it.name == "deprecated") {
return
}
api project(path: "${it.path}", configuration: "namedElements")
clientImplementation project("${it.path}:").sourceSets.client.output
@ -668,7 +722,9 @@ dependencies {
remapJar {
afterEvaluate {
subprojects.each {
if (it.name in devOnlyModules || it.name == "deprecated") return
if (it.name in devOnlyModules || it.name == "deprecated") {
return
}
// Include the signed or none signed jar from the sub project.
nestedJars.from project("${it.path}").tasks.getByName(signingEnabled ? "signRemapJar" : "remapJar")
@ -711,7 +767,10 @@ if (signingEnabled) {
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task github(dependsOn: (signingEnabled ? signRemapJar : remapJar)) {
import java.util.stream.Collectors
tasks.register('github') {
dependsOn(signingEnabled ? signRemapJar : remapJar)
onlyIf {
ENV.GITHUB_TOKEN
}
@ -741,7 +800,7 @@ modrinth {
}
// A task to ensure that the version being released has not already been released.
task checkVersion {
tasks.register('checkVersion') {
doFirst {
def xml = new URL("https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)

View file

@ -1,6 +1,4 @@
archivesBaseName = "fabric-blockrenderlayer-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-client-tags-api-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-convention-tags-v1',

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-command-api-v2"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-lifecycle-events-v1',

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-convention-tags-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-lifecycle-events-v1',

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-dimensions-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-command-api-v2',

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-entity-events-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-command-api-v2',

View file

@ -1,6 +1,4 @@
archivesBaseName = "fabric-events-interaction-v0"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-item-api-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-content-registries-v0',

View file

@ -5,6 +5,4 @@ loom {
accessWidenerPath = file("src/main/resources/fabric-lifecycle-events-v1.accesswidener")
}
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])

View file

@ -1,10 +1,6 @@
archivesBaseName = "fabric-message-api-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
'fabric-command-api-v2'
])
testDependencies(project, ['fabric-command-api-v2'])

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-models-v0"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-rendering-v1',

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-networking-api-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-command-api-v2',

View file

@ -6,9 +6,7 @@ moduleDependencies(project, [
'fabric-resource-loader-v0'
])
testDependencies(project, [
':fabric-command-api-v2'
])
testDependencies(project, [':fabric-command-api-v2'])
loom {
accessWidenerPath = file("src/main/resources/fabric-object-builder-api-v1.accesswidener")

View file

@ -5,9 +5,7 @@ loom {
accessWidenerPath = file("src/main/resources/fabric-particles-v1.accesswidener")
}
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
validateMixinNames {
// Loom needs to handle inner mixins better

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-renderer-api-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-block-api-v1',

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-rendering-data-attachment-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
loom {
accessWidenerPath = file("src/main/resources/fabric-rendering-data-attachment-v1.accesswidener")

View file

@ -1,6 +1,4 @@
archivesBaseName = "fabric-rendering-fluids-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])

View file

@ -1,9 +1,7 @@
archivesBaseName = "fabric-rendering-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])
testDependencies(project, [
':fabric-object-builder-api-v1'

View file

@ -1,6 +1,4 @@
archivesBaseName = "fabric-resource-conditions-api-v1"
version = getSubprojectVersion(project)
testDependencies(project, [
':fabric-gametest-api-v1'
])
testDependencies(project, [':fabric-gametest-api-v1'])

View file

@ -1,6 +1,4 @@
archivesBaseName = "fabric-screen-api-v1"
version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base'
])
moduleDependencies(project, ['fabric-api-base'])

View file

@ -4,7 +4,8 @@ version = getSubprojectVersion(project)
moduleDependencies(project, [
'fabric-api-base',
'fabric-api-lookup-api-v1',
'fabric-lifecycle-events-v1', // transitive dependency of API Lookup
'fabric-lifecycle-events-v1',
// transitive dependency of API Lookup
'fabric-rendering-fluids-v1',
])

View file

@ -34,7 +34,7 @@ task generateAccessWidener {
Path commonJar = loom.namedMinecraftProvider.parentMinecraftProvider.commonJar.path
try (def fs = FileSystems.newFileSystem(URI.create("jar:${commonJar.toUri()}"), [create: false])) {
FileSystems.newFileSystem(URI.create("jar:${commonJar.toUri()}"), [create: false]).withCloseable { fs ->
generateBlockConstructors(lines, fs)
lines.add("")
generateItemConstructors(lines, fs)
@ -43,7 +43,7 @@ task generateAccessWidener {
Path clientJar = loom.namedMinecraftProvider.parentMinecraftProvider.clientOnlyJar.path
try (def fs = FileSystems.newFileSystem(URI.create("jar:${clientJar.toUri()}"), [create: false])) {
FileSystems.newFileSystem(URI.create("jar:${clientJar.toUri()}"), [create: false]).withCloseable { fs ->
generateRenderPhaseFields(lines, fs)
}
@ -119,7 +119,7 @@ def generateRenderPhaseFields(List<String> lines, FileSystem fs) {
ClassNode loadClass(Path path) {
def node = new ClassNode()
try (def is = Files.newInputStream(path)) {
Files.newInputStream(path).withCloseable { is ->
new ClassReader(is).accept(node, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES)
}

View file

@ -5,7 +5,7 @@ fabric.loom.multiProjectOptimisation=true
version=0.82.1
minecraft_version=1.20-pre7
yarn_version=+build.1
loader_version=0.14.19
loader_version=0.14.21
installer_version=0.11.1
prerelease=true

View file

@ -8,7 +8,9 @@ import groovy.json.JsonSlurper
*/
subprojects {
if (it.name == "deprecated") return
if (it.name == "deprecated") {
return
}
// Create the task
task validateModules(type: ValidateModuleTask)
@ -42,7 +44,7 @@ class ValidateModuleTask extends DefaultTask {
clientOnlyMod = true
}
def json = new JsonSlurper().parse(file) as Map<String, Map<String, String>>
def json = new JsonSlurper().parse(file)
if (json.custom == null) {
throw new GradleException("Module ${project} does not have a custom value containing module lifecycle!")

View file

@ -30,7 +30,9 @@ class BumpVersionTask extends DefaultTask {
// Bump all versions. To be used when buildscript changes are made.
if (input == "allPatch") {
project.getChildProjects().values().forEach {
if (it.name == "deprecated") return
if (it.name == "deprecated") {
return
}
toUpdate.put(it, 2)
}
@ -68,7 +70,9 @@ class BumpVersionTask extends DefaultTask {
toUpdate.keySet().forEach { p ->
project.allprojects.each { cp ->
if (cp.name == "deprecated" || cp.name == "fabric-api") return
if (cp.name == "deprecated" || cp.name == "fabric-api") {
return
}
def config = cp.configurations.api
config.allDependencies.forEach { dep ->

View file

@ -1,6 +1,9 @@
import java.nio.file.Files
for (def sourceSet in [sourceSets.main, sourceSets.client]) {
for (def sourceSet in [
sourceSets.main,
sourceSets.client
]) {
// We have to capture the source set name for the lazy string literals,
// otherwise it'll just be whatever the last source set is in the list.
def sourceSetName = sourceSet.name

View file

@ -17,7 +17,12 @@ class ValidateAnnotations extends SourceTask {
@TaskAction
def run() {
for (def dir in ['api', 'impl', 'mixin', 'test']) {
for (def dir in [
'api',
'impl',
'mixin',
'test'
]) {
getSource().matching { include "net/fabricmc/fabric/$dir/" }.forEach {
if (it.isDirectory()) {
return

View file

@ -19,7 +19,7 @@
"FabricMC"
],
"depends": {
"fabricloader": ">=0.14.19",
"fabricloader": ">=0.14.21",
"java": ">=17",
"minecraft": ">=1.20- <1.20.1-"
},