diff --git a/build.gradle b/build.gradle index 825145de..3bc7efa1 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'maven-publish' import java.nio.file.* -sourceCompatibility = 1.8 +sourceCompatibility = 1.17 // Avoid weird configuration-time dependency bugs // Fun fact: this line of code single-handedly fixed an error I spent two hours debugging. @@ -20,8 +20,8 @@ if (!project.hasProperty("maps")) { } if (project.hasProperty("release_version")) { - if (!project.property("release_version").startsWith("2021")) { - throw new StopExecutionException("release version must start with 2021!") + if (!project.property("release_version").startsWith("2022")) { + throw new StopExecutionException("release version must start with 2022!") } } @@ -39,7 +39,7 @@ dependencies { scala group: 'org.scala-lang', name: 'scala-reflect', version: '2.11.7' } -def serverJar = new File(project(":engine").libsDir, "engine.jar") +def serverJar = new File(project(":engine").libsDirectory.getAsFile().get(), "engine.jar") task buildMap(type: JavaExec, dependsOn: [':engine:build']) { main = 'battlecode.world.maps.' + project.property('buildMap') @@ -152,8 +152,6 @@ task runFromClient(type: JavaExec, dependsOn: [':engine:build', ':internal-test- } - - task run(dependsOn: ['headless']) {} task runClient { @@ -271,7 +269,6 @@ task releaseClientLinux32(type: Zip, dependsOn: ['prodClient']) { } - task updateVersion() { // new File("frontend/public/version.txt").write(project.findProperty('release_version')) } @@ -296,11 +293,10 @@ publishing { publications { server(MavenPublication) { groupId 'org.battlecode' - artifactId 'battlecode21' + artifactId 'battlecode22' version project.findProperty('release_version') ?: 'NONSENSE' artifact release_main - artifact release_docs { classifier 'javadoc' @@ -312,15 +308,15 @@ publishing { clientWin(MavenPublication) { groupId 'org.battlecode' - artifactId 'battlecode21-client-win' + artifactId 'battlecode22-client-win' version project.findProperty('release_version') ?: 'NONSENSE' artifact releaseClientWin } - + clientMac(MavenPublication) { groupId 'org.battlecode' - artifactId 'battlecode21-client-mac' + artifactId 'battlecode22-client-mac' version project.findProperty('release_version') ?: 'NONSENSE' artifact releaseClientMac @@ -328,7 +324,7 @@ publishing { clientLinux(MavenPublication) { groupId 'org.battlecode' - artifactId 'battlecode21-client-linux' + artifactId 'battlecode22-client-linux' version project.findProperty('release_version') ?: 'NONSENSE' artifact releaseClientLinux @@ -336,7 +332,7 @@ publishing { clientWin32(MavenPublication) { groupId 'org.battlecode' - artifactId 'battlecode21-client-win-32' + artifactId 'battlecode22-client-win-32' version project.findProperty('release_version') ?: 'NONSENSE' artifact releaseClientWin32 @@ -344,7 +340,7 @@ publishing { clientLinux32(MavenPublication) { groupId 'org.battlecode' - artifactId 'battlecode21-client-linux-32' + artifactId 'battlecode22-client-linux-32' version project.findProperty('release_version') ?: 'NONSENSE' artifact releaseClientLinux32 diff --git a/engine/build.gradle b/engine/build.gradle index 28e9c605..2432b70c 100644 --- a/engine/build.gradle +++ b/engine/build.gradle @@ -1,8 +1,6 @@ - - apply plugin: 'java' -sourceCompatibility = 1.8 +sourceCompatibility = 1.17 sourceSets { main { @@ -30,7 +28,7 @@ repositories { } dependencies { - compile ( + implementation ( [group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'], [group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'], @@ -38,9 +36,9 @@ dependencies { [group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'], [group: 'commons-cli', name: 'commons-cli', version: '1.3.1'], [group: 'commons-io', name: 'commons-io', version: '2.4'], - [group: 'org.ow2.asm', name: 'asm', version: '5.0.4'], - [group: 'org.ow2.asm', name: 'asm-tree', version: '5.0.4'], - + [group: 'org.ow2.asm', name: 'asm', version: '9.1'], + [group: 'org.ow2.asm', name: 'asm-tree', version: '9.1'], + // Flatbuffers [group: 'com.google.flatbuffers', name: 'flatbuffers-java', version: '1.11.0'], @@ -56,11 +54,8 @@ dependencies { ) - // Javadoc manipulation libraries - compile files(System.getenv('JAVA_HOME') + '/lib/tools.jar') - // Testing dependencies - testCompile ( + testImplementation ( [group: 'junit', name: 'junit', version: '4.12'], [group: 'org.mockito', name: 'mockito-core', version: '1.10.19'], [group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'] @@ -68,16 +63,17 @@ dependencies { } jar { + duplicatesStrategy(DuplicatesStrategy.EXCLUDE) from { - configurations.testCompile.collect { it.isDirectory() ? it : zipTree(it) } + configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } } } javadoc { includes = ["**/common/**"] - options.windowTitle = "Battlecode 2017" + options.windowTitle = "Battlecode 2022" options.classpath = sourceSets.main.compileClasspath as List - options.doclet = "com.sun.tools.doclets.standard.Standard" + options.doclet = "jdk.javadoc.doclet.StandardDoclet" options.taglets = ["battlecode.doc.CostlyMethodTaglet", "battlecode.doc.RobotTypeTaglet"] options.tagletPath = ( sourceSets.main.output.classesDirs as List )+ sourceSets.main.compileClasspath } diff --git a/engine/src/main/battlecode/common/MapLocation.java b/engine/src/main/battlecode/common/MapLocation.java index 12884b5d..9e4ce920 100644 --- a/engine/src/main/battlecode/common/MapLocation.java +++ b/engine/src/main/battlecode/common/MapLocation.java @@ -8,7 +8,7 @@ * This class is an immutable representation of two-dimensional coordinates * in the battlecode world. */ -public final strictfp class MapLocation implements Serializable, Comparable { +public final class MapLocation implements Serializable, Comparable { private static final long serialVersionUID = -8945913587066072824L; /** diff --git a/engine/src/main/battlecode/common/RobotController.java b/engine/src/main/battlecode/common/RobotController.java index 086da698..79bdc689 100644 --- a/engine/src/main/battlecode/common/RobotController.java +++ b/engine/src/main/battlecode/common/RobotController.java @@ -8,7 +8,7 @@ * controls the newly created robot. */ @SuppressWarnings("unused") -public strictfp interface RobotController { +public interface RobotController { // ********************************* // ****** GLOBAL QUERY METHODS ***** diff --git a/engine/src/main/battlecode/common/RobotType.java b/engine/src/main/battlecode/common/RobotType.java index e770275a..6da91bcc 100644 --- a/engine/src/main/battlecode/common/RobotType.java +++ b/engine/src/main/battlecode/common/RobotType.java @@ -12,46 +12,49 @@ public enum RobotType { * Archons are portable buildings that heal and generate robots. * Losing all archons means losing the game. * - * @battlecode.doc.robot */ + * @battlecode.doc.robottype */ ARCHON ( 0, 250, 10, 24, 1000, -2, 20, 34, 20000), // BCL BCG AC MC HP DMG AR VR BL /** - * Alchemist's laboratory - * Converts lead into gold + * Alchemist's laboratory. + * Converts lead into gold. * - * @battlecode.doc.robot */ + * @battlecode.doc.robottype */ LABORATORY (800, 0, 10, 24, 100, 0, 0, 53, 5000), // BCL BCG AC MC HP DMG AR VR BL /** - * Guard turret - */ + * Watchtower building. + * + * @battlecode.doc.robottype */ WATCHTOWER (180, 0, 10, 24, 130, 5, 20, 34, 10000), // BCL BCG AC MC HP DMG AR VR BL /** * Can mine gold or lead at their or an adjacent location. * - * @battlecode.doc.robot */ + * @battlecode.doc.robottype */ MINER ( 50, 0, 2, 20, 40, 0, 2, 20, 7500), // BCL BCG AC MC HP DMG AR VR BL /** * Can build and repair buildings. * - * @battlecode.doc.robot */ + * @battlecode.doc.robottype */ BUILDER ( 40, 0, 10, 20, 30, -1, 5, 20, 7500), // BCL BCG AC MC HP DMG AR VR BL - + /** * Ranged attacking robot. - */ + * + * @battlecode.doc.robottype */ SOLDIER ( 75, 0, 10, 16, 50, 3, 13, 20, 10000), // BCL BCG AC MC HP DMG AR VR BL - + /** * Gold robot, causes Anomalies. - */ + * + * @battlecode.doc.robottype */ SAGE ( 0, 50, 200, 25, 100, 45, 13, 20, 10000) // BCL BCG AC MC HP DMG AR VR BL ; @@ -303,4 +306,4 @@ public int getGoldDropped(int level) { this.visionRadiusSquared = visionRadiusSquared; this.bytecodeLimit = bytecodeLimit; } -} \ No newline at end of file +} diff --git a/engine/src/main/battlecode/doc/CostlyMethodTaglet.java b/engine/src/main/battlecode/doc/CostlyMethodTaglet.java index 614d87c7..f735ebf7 100644 --- a/engine/src/main/battlecode/doc/CostlyMethodTaglet.java +++ b/engine/src/main/battlecode/doc/CostlyMethodTaglet.java @@ -1,11 +1,13 @@ package battlecode.doc; -import battlecode.instrumenter.TeamClassLoaderFactory; -import battlecode.instrumenter.bytecode.MethodCostUtil; -import com.sun.javadoc.Tag; -import com.sun.tools.doclets.Taglet; +import java.util.List; +import java.util.Set; + +import com.sun.source.doctree.DocTree; +import javax.lang.model.element.Element; +import jdk.javadoc.doclet.Taglet; -import java.util.Map; +import battlecode.instrumenter.bytecode.MethodCostUtil; /** * A taglet for the "battlecode.doc.costlymethod" annotation. @@ -13,54 +15,33 @@ */ @SuppressWarnings("unused") public class CostlyMethodTaglet implements Taglet { - public static final String TAG_NAME = "battlecode.doc.costlymethod"; - @SuppressWarnings("unused") - public static void register(Map map) { - map.put(TAG_NAME, new CostlyMethodTaglet()); + @Override + public Set getAllowedLocations() { + return Set.of(Taglet.Location.METHOD); } + @Override public String getName() { return TAG_NAME; } - public boolean inConstructor() { - return false; - } - - public boolean inField() { - return false; - } - - public boolean inMethod() { - return true; - } - - public boolean inOverview() { - return false; - } - - public boolean inPackage() { - return false; - } - - public boolean inType() { - return false; - } - + @Override public boolean isInlineTag() { return false; } - public String toString(Tag tag) { - final String methodName = tag.holder().name(); - final String fileName = tag.holder().position().file().toString(); - - // Note: this makes an assumption that this method is in the battlecode/ package. - final String className = fileName.substring(fileName.lastIndexOf("battlecode/"), - fileName.length() - 5); // remove .java + @Override + public String toString(List tags, Element element) { + if (tags.size() != 1) { + throw new IllegalArgumentException("Too many @"+TAG_NAME+" tags: "+tags.size()); + } + Element parent = element.getEnclosingElement(); + return docFor(element.getSimpleName().toString(), parent.getSimpleName().toString()); + } + public String docFor(String methodName, String className) { final MethodCostUtil.MethodData data = MethodCostUtil.getMethodData(className, methodName); @@ -78,12 +59,4 @@ public String toString(Tag tag) { + cost + ""; } - - public String toString(Tag[] tags) { - if (tags.length != 1) { - throw new IllegalArgumentException("Too many @"+TAG_NAME+"tags: "+tags.length); - } - - return toString(tags[0]); - } } diff --git a/engine/src/main/battlecode/doc/RobotTypeTaglet.java b/engine/src/main/battlecode/doc/RobotTypeTaglet.java index 2cdb93c5..cf0a755f 100644 --- a/engine/src/main/battlecode/doc/RobotTypeTaglet.java +++ b/engine/src/main/battlecode/doc/RobotTypeTaglet.java @@ -1,13 +1,16 @@ package battlecode.doc; -import battlecode.common.RobotType; -import com.sun.javadoc.Tag; -import com.sun.tools.doclets.Taglet; - import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Map; +import java.util.List; +import java.util.Set; + +import com.sun.source.doctree.DocTree; +import javax.lang.model.element.Element; +import jdk.javadoc.doclet.Taglet; + +import battlecode.common.RobotType; /** * Taglet for annotating the individual variants of RobotType. @@ -16,44 +19,27 @@ public class RobotTypeTaglet implements Taglet { public static final String TAG_NAME = "battlecode.doc.robottype"; - public static void register(Map map) { - map.put(TAG_NAME, new RobotTypeTaglet()); + @Override + public Set getAllowedLocations() { + return Set.of(Taglet.Location.FIELD); } + @Override public String getName() { return TAG_NAME; } - public boolean inConstructor() { - return false; - } - - public boolean inField() { - return true; - } - - public boolean inMethod() { - return false; - } - - public boolean inOverview() { - return false; - } - - public boolean inPackage() { - return false; - } - - public boolean inType() { - return false; - } - + @Override public boolean isInlineTag() { return false; } - public String toString(Tag tag) { - throw new IllegalArgumentException("The robot tag may not be used inline."); + @Override + public String toString(List tags, Element element) { + if (tags.size() != 1) { + throw new IllegalArgumentException("Too many @"+TAG_NAME+" tags: "+tags.size()); + } + return docFor(element.getSimpleName().toString()); } static public void append(StringBuilder builder, String label, String value) { @@ -197,17 +183,11 @@ public String docFor(String variant) { builder.append("
"); appendField(builder, rt, "bytecodeLimit"); } + + // TODO: add docs for methods } catch (Exception e) { e.printStackTrace(); } return builder.toString(); } - - public String toString(Tag[] tags) { - if (tags.length != 1) { - throw new IllegalArgumentException("Too many @"+TAG_NAME+"tags: "+tags.length); - } - - return docFor(tags[0].holder().name()); - } } diff --git a/engine/src/main/battlecode/instrumenter/bytecode/ClassReferenceUtil.java b/engine/src/main/battlecode/instrumenter/bytecode/ClassReferenceUtil.java index 2ec66f05..1365351c 100644 --- a/engine/src/main/battlecode/instrumenter/bytecode/ClassReferenceUtil.java +++ b/engine/src/main/battlecode/instrumenter/bytecode/ClassReferenceUtil.java @@ -112,6 +112,7 @@ private boolean shouldAddInstrumentedPrefix(String className) { if (className.startsWith("java/util/invoke") || // Don't override JVM internals className.startsWith("java/util/jar") || className.startsWith("java/util/zip") || + className.startsWith("jdk/internal") || className.equals("java/util/Iterator") || className.equals("java/util/concurrent/TimeUnit")) return false; diff --git a/engine/src/main/battlecode/instrumenter/bytecode/InstrumentingClassVisitor.java b/engine/src/main/battlecode/instrumenter/bytecode/InstrumentingClassVisitor.java index 0d0ffae1..71b942c2 100644 --- a/engine/src/main/battlecode/instrumenter/bytecode/InstrumentingClassVisitor.java +++ b/engine/src/main/battlecode/instrumenter/bytecode/InstrumentingClassVisitor.java @@ -43,7 +43,7 @@ public InstrumentingClassVisitor(final ClassVisitor cv, boolean checkDisallowed, boolean debugMethodsEnabled, boolean profilerEnabled) throws InstrumentationException { - super(Opcodes.ASM5, cv); + super(Opcodes.ASM9, cv); this.loader = loader; this.silenced = silenced; this.checkDisallowed = checkDisallowed; diff --git a/engine/src/main/battlecode/instrumenter/bytecode/InstrumentingMethodVisitor.java b/engine/src/main/battlecode/instrumenter/bytecode/InstrumentingMethodVisitor.java index 5ab0e4ae..2685790a 100644 --- a/engine/src/main/battlecode/instrumenter/bytecode/InstrumentingMethodVisitor.java +++ b/engine/src/main/battlecode/instrumenter/bytecode/InstrumentingMethodVisitor.java @@ -67,7 +67,7 @@ public InstrumentingMethodVisitor(final MethodVisitor mv, boolean checkDisallowed, boolean debugMethodsEnabled, boolean profilerEnabled) { - super(ASM5, access, methodName, methodDesc, signature, exceptions); + super(ASM9, access, methodName, methodDesc, signature, exceptions); this.methodWriter = mv; this.loader = loader; diff --git a/engine/src/main/battlecode/instrumenter/bytecode/InterfaceReader.java b/engine/src/main/battlecode/instrumenter/bytecode/InterfaceReader.java index c1f11034..750d4684 100644 --- a/engine/src/main/battlecode/instrumenter/bytecode/InterfaceReader.java +++ b/engine/src/main/battlecode/instrumenter/bytecode/InterfaceReader.java @@ -30,7 +30,7 @@ class InterfaceReader extends ClassVisitor { private String[] interfaces = null; public InterfaceReader(TeamClassLoaderFactory factory) { - super(Opcodes.ASM5); + super(Opcodes.ASM9); this.factory = factory; } diff --git a/engine/src/main/battlecode/server/GameMaker.java b/engine/src/main/battlecode/server/GameMaker.java index 9032b68a..72a4abf2 100644 --- a/engine/src/main/battlecode/server/GameMaker.java +++ b/engine/src/main/battlecode/server/GameMaker.java @@ -32,7 +32,7 @@ /** * Writes a game to a flatbuffer, hooray. */ -public strictfp class GameMaker { +public class GameMaker { /** * The protocol expects a series of valid state transitions; diff --git a/engine/src/main/battlecode/server/Server.java b/engine/src/main/battlecode/server/Server.java index b098bb42..93a8fbad 100644 --- a/engine/src/main/battlecode/server/Server.java +++ b/engine/src/main/battlecode/server/Server.java @@ -15,7 +15,7 @@ * configuration parameters to the game engine and engine output to an abstract * match data sink. */ -public strictfp class Server implements Runnable { +public class Server implements Runnable { /** * The GameInfo that signals the server to terminate when it is encountered on the game queue. */ diff --git a/engine/src/main/battlecode/world/GameMapIO.java b/engine/src/main/battlecode/world/GameMapIO.java index 4687e428..8d64b730 100644 --- a/engine/src/main/battlecode/world/GameMapIO.java +++ b/engine/src/main/battlecode/world/GameMapIO.java @@ -22,7 +22,7 @@ * This class contains the code for reading a flatbuffer map file and converting it * to a proper LiveMap. */ -public final strictfp class GameMapIO { +public final class GameMapIO { /** * The loader we use if we can't find a map in the correct path. */ diff --git a/engine/src/main/battlecode/world/GameWorld.java b/engine/src/main/battlecode/world/GameWorld.java index a5ba0bef..7849ea3d 100644 --- a/engine/src/main/battlecode/world/GameWorld.java +++ b/engine/src/main/battlecode/world/GameWorld.java @@ -14,7 +14,7 @@ * The primary implementation of the GameWorld interface for containing and * modifying the game map and the objects on it. */ -public strictfp class GameWorld { +public class GameWorld { /** * The current round we're running. */ diff --git a/engine/src/main/battlecode/world/InternalRobot.java b/engine/src/main/battlecode/world/InternalRobot.java index 74a88d80..1f12229a 100644 --- a/engine/src/main/battlecode/world/InternalRobot.java +++ b/engine/src/main/battlecode/world/InternalRobot.java @@ -13,7 +13,7 @@ * - tiebreak by creation time (priority to later creation) * - tiebreak by robot ID (priority to lower ID) */ -public strictfp class InternalRobot implements Comparable { +public class InternalRobot implements Comparable { private final RobotControllerImpl controller; private final GameWorld gameWorld; diff --git a/engine/src/main/battlecode/world/LiveMap.java b/engine/src/main/battlecode/world/LiveMap.java index cd870337..44304c3b 100644 --- a/engine/src/main/battlecode/world/LiveMap.java +++ b/engine/src/main/battlecode/world/LiveMap.java @@ -14,7 +14,7 @@ * It is named LiveMap to distinguish it from a battlecode.schema.GameMap, * which represents a serialized LiveMap. */ -public strictfp class LiveMap { +public class LiveMap { /** * The width and height of the map. diff --git a/engine/src/main/battlecode/world/ObjectInfo.java b/engine/src/main/battlecode/world/ObjectInfo.java index 5a04b130..a89718b0 100644 --- a/engine/src/main/battlecode/world/ObjectInfo.java +++ b/engine/src/main/battlecode/world/ObjectInfo.java @@ -26,7 +26,7 @@ * This class is used to hold information about the robots * in the game world. */ -public strictfp class ObjectInfo { +public class ObjectInfo { private final int mapWidth; private final int mapHeight; private final MapLocation mapTopLeft; diff --git a/engine/src/main/battlecode/world/RobotControllerImpl.java b/engine/src/main/battlecode/world/RobotControllerImpl.java index 80acd90e..a92977fe 100644 --- a/engine/src/main/battlecode/world/RobotControllerImpl.java +++ b/engine/src/main/battlecode/world/RobotControllerImpl.java @@ -18,7 +18,7 @@ * All overriden methods should assertNotNull() all of their (Object) arguments, * if those objects are not explicitly stated to be nullable. */ -public final strictfp class RobotControllerImpl implements RobotController { +public final class RobotControllerImpl implements RobotController { /** * The world the robot controlled by this controller inhabits. diff --git a/example-bots/build.gradle b/example-bots/build.gradle index b1fcd065..34207fbb 100644 --- a/example-bots/build.gradle +++ b/example-bots/build.gradle @@ -33,15 +33,15 @@ sourceSets { } dependencies { - compile project(':engine') + implementation project(':engine') // scala - compile group: 'org.scala-lang', name: 'scala-library', version: '2.12.1' + implementation group: 'org.scala-lang', name: 'scala-library', version: '2.12.1' // Testing dependencies - testCompile 'junit:junit:4.12' + testImplementation 'junit:junit:4.12' } jar { diff --git a/example-bots/src/main/examplefuncsplayer/RobotPlayer.java b/example-bots/src/main/examplefuncsplayer/RobotPlayer.java index 865e0697..f72a617b 100644 --- a/example-bots/src/main/examplefuncsplayer/RobotPlayer.java +++ b/example-bots/src/main/examplefuncsplayer/RobotPlayer.java @@ -8,7 +8,7 @@ * The run() method inside this class is like your main function: this is what we'll call once your robot * is created! */ -public strictfp class RobotPlayer { +public class RobotPlayer { /** * We will use this variable to count the number of turns this robot has been alive. diff --git a/gradle.properties b/gradle.properties index 1565098d..7eda40cd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,4 @@ maps=maptestsmall profilerEnabled=false source=src mapLocation=maps -release_version=2021.3.0.5 +release_version=2022.0.1.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf0..7454180f 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7c4388a9..84d1f85f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 83f2acfd..1b6c7873 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/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,78 +17,113 @@ # ############################################################################## -## -## 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/master/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_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${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"' # 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 - ;; - 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 + # Determine the Java command to use to start the JVM. 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 @@ -97,7 +132,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 @@ -105,84 +140,95 @@ 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*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + 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=$((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 -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") +# 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. -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -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" "$@" diff --git a/gradlew.bat b/gradlew.bat index 24467a14..ac1b06f9 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -51,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -61,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell