Skip to content

Commit

Permalink
Some gradle deprecation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Dec 18, 2024
1 parent 4fc7e41 commit e154232
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id "fabric-loom" version "1.9.2" apply false
id "com.diffplug.spotless" version "6.20.0"
id "org.ajoberstar.grgit" version "5.2.2"
id "me.modmuss50.remotesign" version "0.4.0" apply false
id "me.modmuss50.remotesign" version "0.5.0" apply false
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
}

Expand Down Expand Up @@ -388,7 +388,7 @@ javadoc {

classpath = files(sourceSets.main.compileClasspath, sourceSets.client.compileClasspath)
include("**/api/**")
failOnError true
failOnError = true
}

tasks.register('javadocJar', Jar) {
Expand Down
51 changes: 38 additions & 13 deletions gradle/module-validation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ subprojects {
}

// Create the task
task validateModules(type: ValidateModuleTask)
tasks.register("validateModules", ValidateModuleTask)
}

/**
Expand All @@ -26,38 +26,63 @@ subprojects {
* }
* }</pre>
*/
class ValidateModuleTask extends DefaultTask {
abstract class ValidateModuleTask extends DefaultTask {
@InputFile
@Optional
abstract RegularFileProperty getFmj()

@InputFile
@Optional
abstract RegularFileProperty getClientFmj()

@Input
abstract Property<String> getProjectName()

@Input
abstract Property<String> getProjectPath()

@Input
abstract Property<String> getLoaderVersion()

ValidateModuleTask() {
group = "verification"

// Hook up validation to check task
project.tasks.check.dependsOn(this)

fmj.set(project.file("src/main/resources/fabric.mod.json"))
clientFmj.set(project.file("src/client/resources/fabric.mod.json"))

projectName.set(project.name)
projectPath.set(project.path)
loaderVersion.set(project.loader_version)
}

@TaskAction
void validate() {
def clientOnlyMod = false
def file = (project.file("src/main/resources/fabric.mod.json") as File)

def file = fmj.get().asFile

if (!file.exists()) {
file = (project.file("src/client/resources/fabric.mod.json") as File)
file = clientFmj.get().asFile
clientOnlyMod = true
}

def json = new JsonSlurper().parse(file)

if (json.custom == null) {
throw new GradleException("Module ${project} does not have a custom value containing module lifecycle!")
throw new GradleException("Module ${projectName.get()} does not have a custom value containing module lifecycle!")
}

def moduleLifecycle = json.custom.get("fabric-api:module-lifecycle")

if (moduleLifecycle == null) {
throw new GradleException("Module ${project} does not have module lifecycle in custom values!")
throw new GradleException("Module ${projectName.get()} does not have module lifecycle in custom values!")
}

if (!moduleLifecycle instanceof String) {
throw new GradleException("Module ${project} has an invalid module lifecycle value. The value must be a string but read a ${moduleLifecycle.class}")
throw new GradleException("Module ${projectName.get()} has an invalid module lifecycle value. The value must be a string but read a ${moduleLifecycle.class}")
}

// Validate the lifecycle value
Expand All @@ -66,20 +91,20 @@ class ValidateModuleTask extends DefaultTask {
case "experimental":
break
case "deprecated":
if (!project.path.startsWith(":deprecated")) {
throw new GradleException("Deprecated module ${project} must be in the deprecated sub directory.")
if (!projectPath.get().startsWith(":deprecated")) {
throw new GradleException("Deprecated module ${projectName.get()} must be in the deprecated sub directory.")
}
break
default:
throw new GradleException("Module ${project} has an invalid module lifecycle ${json.custom.get('fabric-api:module-lifecycle')}")
throw new GradleException("Module ${projectName.get()} has an invalid module lifecycle ${json.custom.get('fabric-api:module-lifecycle')}")
}

if (json.depends == null) {
throw new GradleException("Module ${project} does not have a depends value!")
throw new GradleException("Module ${projectName.get()} does not have a depends value!")
}

if (json.depends.fabricloader != ">=${project.loader_version}") {
throw new GradleException("Module ${project} does not have a valid fabricloader value! Got \"${json.depends.fabricloader}\" but expected \">=${project.loader_version}\"")
if (json.depends.fabricloader != ">=${loaderVersion.get()}") {
throw new GradleException("Module ${projectName.get()} does not have a valid fabricloader value! Got \"${json.depends.fabricloader}\" but expected \">=${project.loader_version}\"")
}
}
}
11 changes: 9 additions & 2 deletions gradle/package-info.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,24 @@ for (def sourceSet in [
clean.dependsOn cleanTask
}

class GenerateImplPackageInfos extends DefaultTask {
abstract class GenerateImplPackageInfos extends DefaultTask {
@InputFile
File header

@Input
abstract Property<String> getProjectName()

@SkipWhenEmpty
@InputDirectory
final DirectoryProperty sourceRoot = project.objects.directoryProperty()

@OutputDirectory
final DirectoryProperty outputDir = project.objects.directoryProperty()

GenerateImplPackageInfos() {
projectName.set(project.name)
}

@TaskAction
def run() {
def output = outputDir.get().asFile.toPath()
Expand Down Expand Up @@ -66,7 +73,7 @@ class GenerateImplPackageInfos extends DefaultTask {
def packageName = relativePath.toString().replace(File.separator, '.')
it.write("""$headerText
|/**
| * Implementation code for ${project.name}.
| * Implementation code for ${projectName.get()}.
| */
|@ApiStatus.Internal
|package $packageName;
Expand Down

0 comments on commit e154232

Please sign in to comment.