From 7a86c872ddaffcb3c86a825c6c68b7d6d40e9308 Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Fri, 12 Nov 2021 13:06:20 +0100 Subject: [PATCH] Added parameter checks --- build.gradle | 77 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index e97b1dd..09490ee 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,79 @@ idea { } } + +if(JavaVersion.current() != JavaVersion.VERSION_1_8) { + throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) +} + +def checkPropertyExsists(String propertyName) { + if (project.hasProperty(propertyName) == false) { + throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/gradle.properties") + } +} + +checkPropertyExsists("modName") +checkPropertyExsists("modId") +checkPropertyExsists("modGroup") +checkPropertyExsists("minecraftVersion") +checkPropertyExsists("forgeVersion") +checkPropertyExsists("replaceGradleTokenInFile") +checkPropertyExsists("gradleTokenModId") +checkPropertyExsists("gradleTokenModName") +checkPropertyExsists("gradleTokenVersion") +checkPropertyExsists("gradleTokenGroupName") +checkPropertyExsists("apiPackage") +checkPropertyExsists("accessTransformersFile") +checkPropertyExsists("usesMixins") +checkPropertyExsists("mixinPlugin") +checkPropertyExsists("mixinsPackage") +checkPropertyExsists("coreModClass") +checkPropertyExsists("containsMixinsAndOrCoreModOnly") +checkPropertyExsists("usesShadowedDependencies") +checkPropertyExsists("developmentEnvironmentUserName") + +String targetPackage = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") +if(new File(targetPackage).exists() == false) { + throw new GradleException("Could not resolve \"modGroup\"! Could not find " + targetPackage) +} + +if(apiPackage) { + targetPackage = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + if(new File(targetPackage).exists() == false) { + throw new GradleException("Could not resolve \"apiPackage\"! Could not find " + targetPackage) + } +} + +if(accessTransformersFile) { + targetPackage = "src/main/resources/META-INF/" + accessTransformersFile + if(new File(targetPackage).exists() == false) { + throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetPackage) + } +} + +if(usesMixins.toBoolean()) { + if(mixinsPackage.isEmpty() || mixinPlugin.isEmpty()) { + throw new GradleException("\"mixinPlugin\" requires \"mixinsPackage\" and \"mixinPlugin\" to be set!") + } + + targetPackage = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/") + if(new File(targetPackage).exists() == false) { + throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find " + targetPackage) + } + + String targetFile = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java" + if(new File(targetFile).exists() == false) { + throw new GradleException("Could not resolve \"mixinPlugin\"! Could not find " + targetFile) + } +} + +if(coreModClass) { + String targetFile = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java" + if(new File(targetFile).exists() == false) { + throw new GradleException("Could not resolve \"coreModClass\"! Could not find " + targetFile) + } +} + configurations.all { resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS) @@ -62,10 +135,6 @@ group = modGroup archivesBaseName = modId minecraft { - if(JavaVersion.current() != JavaVersion.VERSION_1_8) { - throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) - } - version = minecraftVersion + "-" + forgeVersion + "-" + minecraftVersion runDir = "run"