diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml index 9815b22..8f18de9 100644 --- a/.github/workflows/sonar.yml +++ b/.github/workflows/sonar.yml @@ -40,4 +40,4 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - run: ./gradlew build sonarqube \ No newline at end of file + run: ./gradlew build sonar \ No newline at end of file diff --git a/api/build.gradle.kts b/api/build.gradle.kts index aefdf72..71c8db1 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -1,25 +1 @@ -val minecraft_version: String by extra -val mod_version: String by extra -val mod_id: String by extra -val xmlutil_version: String by extra - -plugins { - id("org.spongepowered.gradle.vanilla") version ("0.2.1-SNAPSHOT") - id("org.jetbrains.kotlin.jvm") - id("org.jetbrains.kotlin.plugin.serialization") -} - -base { - archivesName.set("${mod_id}-api") -} - -minecraft { - version(minecraft_version) -} - -dependencies { - compileOnly("org.spongepowered:mixin:0.8.5") - - implementation("io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}") - implementation("io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}") -} \ No newline at end of file +common() \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 92bc08d..84734a9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,89 +1,25 @@ -import groovy.util.Node -import groovy.util.NodeList -import java.time.LocalDateTime - -val mod_version: String by extra -val mod_name: String by extra val mod_id: String by extra -val mod_author: String by extra -val minecraft_version: String by extra -val repository: String by extra -val artifactGroup: String by extra +val mod_version: String by extra +val xmlutil_version: String by extra plugins { - java idea - id("maven-publish") - id("org.jetbrains.kotlin.jvm") version ("1.8.21") apply (false) - id("org.jetbrains.kotlin.plugin.serialization") version ("1.8.21") apply (false) - id("org.sonarqube") version "4.2.0.3129" + id("net.somethingcatchy.gradle") version ("0.0.6") } -subprojects { - apply(plugin = "maven-publish") - apply(plugin = "org.jetbrains.kotlin.jvm") - - java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(17)) - } - withSourcesJar() - withJavadocJar() - } - - tasks.withType { - val now = LocalDateTime.now().toString() - - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - from(rootProject.file("LICENSE")) { - rename { "${it}_${mod_name}" } - } - - manifest { - attributes( - mapOf( - "Specification-Title" to mod_name, - "Specification-Vendor" to mod_author, - "Specification-Version" to mod_version, - "Implementation-Title" to name, - "Implementation-Version" to archiveVersion, - "Implementation-Vendor" to mod_author, - "Implementation-Timestamp" to now, - ) - ) - } - } +withKotlin() - //tasks.named("sourcesJar") { - // duplicatesStrategy = DuplicatesStrategy.EXCLUDE - // from(rootProject.file("LICENSE")) { - // rename { "${it}_${mod_name}" } - // } - //} +mod { + includedLibraries.set(setOf( + "io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}", + "io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}", + )) +} +subprojects { repositories { - mavenCentral() - - maven { - url = uri("https://repo.spongepowered.org/repository/maven-public/") - content { - includeGroup("org.spongepowered") - } - } - - maven { - url = uri("https://api.modrinth.com/maven") - content { - includeGroup("maven.modrinth") - } - } - - maven { - url = uri("https://www.cursemaven.com") - content { - includeGroup("curse.maven") - } - } + modrinthMaven() + curseMaven() maven { url = uri("https://maven.theillusivec4.top/") @@ -93,82 +29,25 @@ subprojects { } maven { - url = uri("https://thedarkcolour.github.io/KotlinForForge/") + url = uri("https://maven.blamejared.com") content { - includeGroup("thedarkcolour") + includeGroup("vazkii.botania") } } } - // Disables Gradle's custom module metadata from being published to maven. The - // metadata includes mapped dependencies which are not reasonably consumable by - // other mod developers. - tasks.withType { - enabled = false - } - - tasks.withType { - // this will ensure that this task is redone when the versions change. - inputs.property("version", version) - - filesMatching(listOf("META-INF/mods.toml", "pack.mcmeta", "fabric.mod.json", "${mod_id}.mixins.json")) { - expand( - mapOf( - "mod_version" to mod_version, - "mod_name" to mod_name, - "mod_id" to mod_id, - "mod_author" to mod_author, - "repository" to repository, - ) - ) - } - } - - val env = System.getenv() - - publishing { + enablePublishing { repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/${repository}") - version = mod_version - credentials { - username = env["GITHUB_ACTOR"] - password = env["GITHUB_TOKEN"] - } - } - } - publications { - create("gpr") { - groupId = artifactGroup - artifactId = "${mod_id}-${project.name}" - version = mod_version - from(components["java"]) - - pom.withXml { - val node = asNode() - val list = node.get("dependencies") as NodeList - list.forEach { node.remove(it as Node) } - } - } + githubPackages(this@subprojects) } } -} -sonarqube { - properties { - property("sonar.projectVersion", version) - property("sonar.projectKey", mod_id) + tasks.withType { + exclude("datapacks") } } -subprojects { - sonarqube { - properties { - property("sonar.branch", this@subprojects.name) - } - } -} +enableSonarQube() idea { module.excludeDirs.add(file("web")) diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 26b4150..25393be 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,36 +1,14 @@ -val minecraft_version: String by extra -val mod_version: String by extra -val mod_id: String by extra -val xmlutil_version: String by extra - plugins { - id("org.spongepowered.gradle.vanilla") version ("0.2.1-SNAPSHOT") - id("org.jetbrains.kotlin.jvm") - id("org.jetbrains.kotlin.plugin.serialization") -} - -base { - archivesName.set("${mod_id}-common") + jacoco } -minecraft { - version(minecraft_version) +common { + dependOn(project(":api")) } dependencies { - compileOnly("org.spongepowered:mixin:0.8.5") - - implementation("io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}") - implementation("io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}") - testImplementation("org.jetbrains.kotlin:kotlin-test") testImplementation("io.github.origin-energy:java-snapshot-testing-junit5:4.0.6") - - implementation(project(":api")) -} - -sourceSets["main"].resources { - srcDir(project.file("src/generated/resources")) } tasks.test { @@ -39,4 +17,10 @@ tasks.test { events("passed", "skipped", "failed") } workingDir = project.file("run") + + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) } \ No newline at end of file diff --git a/fabric/src/main/resources/data/minecraft/tags/worldgen/world_preset/normal.json b/common/src/main/resources/data/minecraft/tags/worldgen/world_preset/normal.json similarity index 100% rename from fabric/src/main/resources/data/minecraft/tags/worldgen/world_preset/normal.json rename to common/src/main/resources/data/minecraft/tags/worldgen/world_preset/normal.json diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 8500980..11fc8af 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -1,94 +1,17 @@ -val minecraft_version: String by extra -val mod_version: String by extra -val mod_id: String by extra -val fabric_loader_version: String by extra -val fabric_version: String by extra -val xmlutil_version: String by extra val create_fabric_version: String by extra -plugins { - id("fabric-loom") version ("1.0-SNAPSHOT") - id("idea") - id("org.jetbrains.kotlin.jvm") - id("org.jetbrains.kotlin.plugin.serialization") -} +fabric { + enableMixins() -base { - archivesName.set("${mod_id}-fabric") -} + dataGen() -val dependencyProjects = listOf( - project(":api"), - project(":common"), -) + dependOn(project(":api")) + dependOn(project(":common")) +} dependencies { - minecraft("com.mojang:minecraft:${minecraft_version}") - mappings(loom.officialMojangMappings()) - - modImplementation("net.fabricmc:fabric-loader:${fabric_loader_version}") - modImplementation("net.fabricmc.fabric-api:fabric-api:${fabric_version}") - - implementation(include("io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}")!!) - implementation(include("io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}")!!) - - modImplementation("net.fabricmc:fabric-language-kotlin:1.9.1+kotlin.1.8.10") - modRuntimeOnly("maven.modrinth:create-fabric:${create_fabric_version}") - - dependencyProjects.forEach { implementation(it) } -} - -loom { - //accessWidenerPath.set(file("src/main/resources/${mod_id}.accesswidener")) - mixin { - defaultRefmapName.set("${mod_id}.refmap.json") - } - - runs { - named("client") { - client() - configName = "Fabric Client" - runDir("run") - } - named("server") { - server() - configName = "Fabric Server" - runDir("run/server") - } - create("data ") { - client() - configName = "Fabric Datagen" - runDir("run/datagen") - - vmArg("-Dfabric-api.datagen") - vmArg("-Dfabric-api.datagen.output-dir=${project(":common").file("src/generated/resources")}") - vmArg("-Dfabric-api.datagen.modid=${mod_id}") - } - forEach { run -> - run.ideConfigGenerated(true) - } - } - - mods { - create(mod_id) { - sourceSet(sourceSets.main.get()) - dependencyProjects.forEach { - sourceSet(it.sourceSets.main.get()) - } - } - } -} - -tasks.withType { - dependencyProjects.forEach { - source(it.sourceSets["main"].allSource) - } } -tasks.jar { - from(sourceSets.main.get().output) - dependencyProjects.forEach { - from(it.sourceSets.main.get().output) - } -} \ No newline at end of file +uploadToCurseforge() +uploadToModrinth() diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 7d84b9b..348f712 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -34,7 +34,7 @@ "fabricloader": ">=0.14", "fabric": "*", "minecraft": ">=1.19.2", - "fabric-language-kotlin": ">=1.7.1+kotlin.1.6.10", + "fabric-language-kotlin": "^1.9.0", "java": ">=17" } } diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 1326dbb..7fd59ab 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -1,143 +1,29 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.spongepowered.asm.gradle.plugins.MixinExtension - -val minecraft_version: String by extra -val mod_version: String by extra -val mod_id: String by extra -val xmlutil_version: String by extra -val forge_version: String by extra val curios_forge_version: String by extra +val botania_version: String by extra -buildscript { - dependencies { - classpath("org.spongepowered:mixingradle:0.7-SNAPSHOT") - } -} - -plugins { - id("net.minecraftforge.gradle") version ("5.1.+") - id("idea") - id("org.jetbrains.kotlin.jvm") - id("org.jetbrains.kotlin.plugin.serialization") -} +forge { + enableMixins() -base { - archivesName.set("${mod_id}-forge") + dependOn(project(":api")) + dependOn(project(":common")) } -apply(plugin = "org.spongepowered.mixin") - -configure { - add(sourceSets.main.get(), "${mod_id}.refmap.json") - config("${mod_id}.mixins.json") -} - -val dependencyProjects = listOf( - project(":api"), - project(":common"), -) - -minecraft { - mappings("official", minecraft_version) - - val ideaModule = "${rootProject.name.replace(" ", "_")}.${project.name}.main" - - runs { - create("client") { - workingDirectory(project.file("run")) - taskName("Client") - } - - create("server") { - workingDirectory(project.file("run/server")) - taskName("Server") - } - - create("data") { - taskName("Data") - - args( - "--mod", - mod_id, - "--all", - "--output", - file("src/generated/resources/"), - "--existing", - file("src/main/resources") - ) - } - - forEach { config -> - config.ideaModule(ideaModule) - - config.property("mixin.env.remapRefMap", "true") - config.property("mixin.env.refMapRemappingFile", "${projectDir}/build/createSrgToMcp/output.srg") - config.mods { - create(mod_id) { - source(sourceSets.main.get()) - dependencyProjects.forEach { - source(it.sourceSets.main.get()) - } - } - } - } - } -} - -fun DependencyHandlerScope.include(dependencyNotation: String) { - implementation(dependencyNotation) - jarJar(dependencyNotation) { - jarJar.ranged(this, "[${version},)") - } -} - -jarJar.enable() dependencies { - minecraft("net.minecraftforge:forge:${minecraft_version}-${forge_version}") - implementation("com.google.code.findbugs:jsr305:3.0.2") - - dependencyProjects.forEach { implementation(it) } - - implementation("thedarkcolour:kotlinforforge:3.9.1") - - include("io.github.pdvrieze.xmlutil:core-jvm:${xmlutil_version}") - include("io.github.pdvrieze.xmlutil:serialization-jvm:${xmlutil_version}") - - //runtimeOnly fg.deobf("vazkii.autoreglib:AutoRegLib:${arl_version}") - - //runtimeOnly fg.deobf("com.github.glitchfiend:TerraBlender-forge:${minecraft_version}-${terrablender_version}") - //runtimeOnly fg.deobf("curse.maven:quark-243121:${quark_version}") - //runtimeOnly fg.deobf("curse.maven:bop-220318:${bop_version}") + if (!env.isCI) { + //modRuntimeOnly("vazkii.autoreglib:AutoRegLib:${arl_version}") - //runtimeOnly fg.deobf("vazkii.patchouli:Patchouli:${minecraft_version}-${patchouli_version}") - //runtimeOnly fg.deobf("top.theillusivec4.curios:curios-forge:${minecraft_version}-${curios_version}") - //runtimeOnly fg.deobf("vazkii.botania:Botania:${minecraft_version}-${botania_version}") - - annotationProcessor("org.spongepowered:mixin:0.8.5:processor") -} - -tasks.withType { - dependencyProjects.forEach { - source(it.sourceSets["main"].allSource) - } -} - -tasks.withType { - dependencyProjects.forEach { - source(it.sourceSets["main"].allSource) - } -} + //modRuntimeOnly("com.github.glitchfiend:TerraBlender-forge:${mc_version}-${terrablender_version}") + //modRuntimeOnly("curse.maven:quark-243121:${quark_version}") + //modRuntimeOnly("curse.maven:bop-220318:${bop_version}") -tasks.jar { - finalizedBy("reobfJar") + //modRuntimeOnly("vazkii.patchouli:Patchouli:${mc_version}-${patchouli_version}") + //modRuntimeOnly("top.theillusivec4.curios:curios-forge:${mc_version}-${curios_version}") - from(sourceSets.main.get().output) - dependencyProjects.forEach { - from(it.sourceSets.main.get().output) + //modRuntimeOnly("vazkii.botania:Botania:${botania_version}") } } -tasks.jarJar { - finalizedBy("reobfJarJar") - classifier = "" +uploadToCurseforge() +uploadToModrinth { + syncBodyFromReadme() } \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index d51d234..be89da5 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -5,23 +5,30 @@ issueTrackerURL = "https://github.com/PssbleTrngle/${repository}/issues" showAsResourcePack = false [[mods]] -modId = "${mod_id}" -version = "${mod_version}" -displayName = "${mod_name}" -authors = "${mod_author}" -description = '''Skygrid''' -credits = "Sethbling for the original idea" + modId = "${mod_id}" + version = "${mod_version}" + displayName = "${mod_name}" + authors = "${mod_author}" + description = '''Skygrid''' + credits = "Sethbling for the original idea" [[dependencies.${mod_id}]] -modId = "forge" -mandatory = true -versionRange = "[43,)" -ordering = "NONE" -side = "BOTH" + modId = "forge" + mandatory = true + versionRange = "[43,)" + ordering = "NONE" + side = "BOTH" [[dependencies.${mod_id}]] -modId = "minecraft" -mandatory = true -versionRange = "[1.19.2,)" -ordering = "NONE" -side = "BOTH" + modId = "minecraft" + mandatory = true + versionRange = "[1.19.2,)" + ordering = "NONE" + side = "BOTH" + +[[dependencies.${mod_id}]] + modId="kotlinforforge" + mandatory=true + versionRange="[3.9.1,)" + ordering="NONE" + side="BOTH" diff --git a/gradle.properties b/gradle.properties index de22e12..a6b1ce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,29 +1,32 @@ +# Gradle +org.gradle.jvmargs=-Xmx3G +org.gradle.daemon=false +kotlin.code.style=official + # Project +mod_id=skygrid +mod_name=Skygrid +mod_author=possible_triangle mod_version=0.0.0-dev -artifactGroup=com.possible_triangle +release_type=release +maven_group=com.possible_triangle # Common -minecraft_version=1.19.2 +mc_version=1.19.2 # Forge forge_version=43.2.0 # Fabric -fabric_version=0.76.0+1.19.2 -fabric_loader_version=0.14.19 +fabric_api_version=0.76.0+1.19.2 +fabric_loader_version=0.14.21 -# Mod options -mod_name=Skygrid -mod_author=possible_triangle -mod_id=skygrid +# Dependencies +xmlutil_version=0.86.1 -# Gradle -org.gradle.jvmargs=-Xmx3G -org.gradle.daemon=false -kotlin.code.style=official +kotlin_fabric_version=1.9.2+kotlin.1.8.10 +kotlin_forge_version=3.9.1 -# Dependencies -xmlutil_version=0.86.0 jei_version=11.0.0.206 #arl_version=1.7-53.110 #quark_version=3652951 @@ -31,9 +34,10 @@ jei_version=11.0.0.206 #bop_version=3616582 #curios_version=5.0.5.1 #patchouli_version=64 -#botania_version=428 +botania_version=1.19.2-440-FORGE create_fabric_version=0.5.1-b-build.1089+mc1.19.2 +# Publishing repository=pssbletrngle/skygrid curseforge_project_id=316763 modrinth_project_id=ZcyZJ2Es \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 60c76b3..37aef8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists \ No newline at end of file +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index b4f908a..aeb74cb 100644 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env bash +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,98 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MSYS* | MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +118,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,7 +129,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -106,78 +137,109 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -ARGV=("$@") -eval set -- $DEFAULT_JVM_OPTS -IFS=$' -' read -rd '' -a JAVA_OPTS_ARR <<< "$(echo $JAVA_OPTS | xargs -n1)" -IFS=$' -' read -rd '' -a GRADLE_OPTS_ARR <<< "$(echo $GRADLE_OPTS | xargs -n1)" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' -exec "$JAVACMD" "$@" "${JAVA_OPTS_ARR[@]}" "${GRADLE_OPTS_ARR[@]}" "-Dorg.gradle.appname=$APP_BASE_NAME" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "${ARGV[@]}" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal