├── src ├── main │ ├── resources │ │ ├── application.properties │ │ ├── templates │ │ │ ├── footer.kts │ │ │ ├── user.kts │ │ │ ├── header.kts │ │ │ ├── users.kts │ │ │ └── index.kts │ │ ├── messages.properties │ │ ├── messages_en.properties │ │ ├── messages_fr.properties │ │ └── scripts │ │ │ └── render.kts │ └── kotlin │ │ └── io │ │ └── spring │ │ └── demo │ │ ├── User.kt │ │ ├── ViewController.kt │ │ ├── Application.kt │ │ └── Helpers.kt └── test │ └── kotlin │ └── io │ └── spring │ └── demo │ └── ApplicationTests.kt ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── settings.gradle.kts ├── README.md ├── gradlew.bat └── gradlew /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/main/resources/templates/footer.kts: -------------------------------------------------------------------------------- 1 | """ 2 | """ -------------------------------------------------------------------------------- /src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | title = Title 2 | user = User 3 | -------------------------------------------------------------------------------- /src/main/resources/messages_en.properties: -------------------------------------------------------------------------------- 1 | title = Users 2 | user = User 3 | -------------------------------------------------------------------------------- /src/main/resources/messages_fr.properties: -------------------------------------------------------------------------------- 1 | title = Utilisateurs 2 | user = Utilisateur 3 | -------------------------------------------------------------------------------- /src/main/resources/templates/user.kts: -------------------------------------------------------------------------------- 1 | import io.spring.demo.* 2 | 3 | "${i18n("user")} ${user.firstname} ${user.lastname}" -------------------------------------------------------------------------------- /src/main/kotlin/io/spring/demo/User.kt: -------------------------------------------------------------------------------- 1 | package io.spring.demo 2 | 3 | class User(val firstname: String, val lastname: String) 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdeleuze/kotlin-script-templating/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/templates/header.kts: -------------------------------------------------------------------------------- 1 | import io.spring.demo.i18n 2 | 3 | """ 4 | 5 | ${i18n("title")}""" -------------------------------------------------------------------------------- /src/main/resources/templates/users.kts: -------------------------------------------------------------------------------- 1 | import io.spring.demo.* 2 | 3 | """""" -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.2-all.zip 6 | -------------------------------------------------------------------------------- /src/main/resources/templates/index.kts: -------------------------------------------------------------------------------- 1 | import io.spring.demo.* 2 | 3 | """${include("header")} 4 |

Locale: FR | EN

5 |

${i18n("title")}

6 | ${include("users", mapOf(Pair("users", users)))} 7 | ${include("footer")}""" 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /build/ 3 | /classes/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | 6 | ### STS ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | nbproject/private/ 22 | build/ 23 | nbbuild/ 24 | dist/ 25 | nbdist/ 26 | .nb-gradle/ -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | maven("https://dl.bintray.com/kotlin/kotlin-dev") 5 | maven("https://repo.spring.io/milestone") 6 | } 7 | resolutionStrategy { 8 | eachPlugin { 9 | if (requested.id.id == "org.springframework.boot") { 10 | useModule("org.springframework.boot:spring-boot-gradle-plugin:${requested.version}") 11 | } 12 | if (requested.id.id == "org.jetbrains.kotlin.jvm") { 13 | useModule("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:${requested.version}") 14 | } 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/main/kotlin/io/spring/demo/ViewController.kt: -------------------------------------------------------------------------------- 1 | package io.spring.demo 2 | 3 | import org.springframework.stereotype.Controller 4 | import org.springframework.ui.Model 5 | import org.springframework.web.bind.annotation.GetMapping 6 | 7 | @Controller 8 | class ViewController { 9 | 10 | @GetMapping("/") 11 | fun render(model: Model): String { 12 | model.addAttribute("users", listOf( 13 | User("Juergen", "Hoeller"), 14 | User("Rossen", "Stoyanchev"), 15 | User("Brian", "Clozel"), 16 | User("Stéphane", "Nicoll"), 17 | User("Arjen", "Poutsma"), 18 | User("Sébastien", "Deleuze") 19 | )) 20 | return "index" 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /src/main/resources/scripts/render.kts: -------------------------------------------------------------------------------- 1 | import io.spring.demo.compilableEngine 2 | import org.springframework.web.servlet.view.script.RenderingContext 3 | import org.springframework.context.support.ResourceBundleMessageSource 4 | import javax.script.* 5 | import org.springframework.beans.factory.getBean 6 | import java.util.concurrent.ConcurrentHashMap 7 | 8 | fun render(template: String, model: Map, renderingContext: RenderingContext): String { 9 | var cache = renderingContext.applicationContext.getBean>() 10 | val compiledScript = cache.getOrPut(renderingContext.url, { compilableEngine().compile(template); }) 11 | val bindings = SimpleBindings(model) 12 | val messageSource = renderingContext.applicationContext.getBean() 13 | bindings.put("i18n", { code: String -> messageSource.getMessage(code, null, renderingContext.locale) }) 14 | bindings.put("include", { path: String -> renderingContext.templateLoader.apply("templates/$path.kts") }) 15 | bindings.put("cache", cache) 16 | return compiledScript.eval(bindings) as String 17 | } 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Spring Boot + Kotlin type safe template rendering with i18n and nested template support. 2 | **This feature is considered experimental** since there is a lot of things to wire manually, 3 | no cross-site scripting protection out of the box, the caching mechanism need to be improved, 4 | etc. 5 | 6 | It requires Spring Framework 5.2 and Kotlin 1.3.40+. 7 | 8 | Make sure to configure Spring Boot Gradle plugin as following to mke it working with Boot fat JAR. 9 | 10 | `build.gradle.kts` 11 | ```kotlin 12 | tasks.withType { 13 | requiresUnpack("**/kotlin-compiler-*.jar") 14 | } 15 | ``` 16 | 17 | These templates look like: 18 | 19 | ```kotlin 20 | import io.spring.demo.* 21 | 22 | """ 23 | ${include("header")} 24 |

${i18n("title")}

25 |
    26 | ${users.joinToLine{ "
  • ${i18n("user")} ${it.firstname} ${it.lastname}
  • " }} 27 |
28 | ${include("footer")} 29 | """ 30 | ``` 31 | 32 | To enable variable resolution in `.kts` files in IDEA, go to menu preferences -> Build, Execution, Deployement -> Compiler -> Kotlin Compiler and set: 33 | - Script templates class: `kotlin.script.templates.standard.ScriptTemplateWithBindings` 34 | - Script templates classpath: `/path/to/kotlin-script-runtime.jar` 35 | 36 | This may be configured automatically in future version of IDEA Kotlin plugin. 37 | 38 | Feel free to send pull requests to improve it! 39 | -------------------------------------------------------------------------------- /src/main/kotlin/io/spring/demo/Application.kt: -------------------------------------------------------------------------------- 1 | package io.spring.demo 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.boot.runApplication 5 | import org.springframework.context.annotation.Bean 6 | import org.springframework.web.servlet.i18n.LocaleChangeInterceptor 7 | import org.springframework.web.servlet.view.script.ScriptTemplateConfigurer 8 | import org.springframework.web.servlet.view.script.ScriptTemplateViewResolver 9 | import java.util.Locale 10 | import org.springframework.web.servlet.i18n.SessionLocaleResolver 11 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry 12 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer 13 | import java.util.concurrent.ConcurrentHashMap 14 | import javax.script.CompiledScript 15 | 16 | 17 | @SpringBootApplication 18 | class Application : WebMvcConfigurer { 19 | 20 | @Bean 21 | fun kotlinScriptConfigurer() = ScriptTemplateConfigurer().apply { 22 | engineName = "kotlin" 23 | setScripts("scripts/render.kts") 24 | renderFunction = "render" 25 | isSharedEngine = false 26 | } 27 | 28 | @Bean 29 | fun kotlinScriptViewResolver() = ScriptTemplateViewResolver().apply { 30 | setPrefix("templates/") 31 | setSuffix(".kts") 32 | } 33 | 34 | @Bean 35 | fun localeResolver() = SessionLocaleResolver().apply { 36 | setDefaultLocale(Locale.ENGLISH) 37 | } 38 | 39 | @Bean 40 | fun localeChangeInterceptor() = LocaleChangeInterceptor() 41 | 42 | override fun addInterceptors(registry: InterceptorRegistry) { 43 | registry.addInterceptor(localeChangeInterceptor()) 44 | } 45 | 46 | @Bean 47 | fun cache() = ConcurrentHashMap() 48 | 49 | } 50 | 51 | fun main(args: Array) { 52 | runApplication(*args) 53 | } 54 | -------------------------------------------------------------------------------- /src/main/kotlin/io/spring/demo/Helpers.kt: -------------------------------------------------------------------------------- 1 | package io.spring.demo 2 | 3 | import java.util.concurrent.ConcurrentHashMap 4 | import javax.script.Compilable 5 | import javax.script.CompiledScript 6 | import javax.script.ScriptEngineManager 7 | import javax.script.SimpleBindings 8 | import kotlin.script.templates.standard.ScriptTemplateWithBindings 9 | 10 | fun ScriptTemplateWithBindings.include(path: String, model: Map? = null) :String { 11 | val cache = bindings["cache"]!! as ConcurrentHashMap 12 | val includeBindings = if (model != null) { 13 | val b = SimpleBindings(LinkedHashMap(model)) 14 | b["include"] = bindings["include"] 15 | b["i18n"] = bindings["i18n"] 16 | b["cache"] = cache 17 | b 18 | } else { 19 | val b = SimpleBindings(bindings) 20 | b.remove("kotlin.script.state") 21 | b 22 | } 23 | val template = (bindings["include"] as (String) -> String).invoke(path) 24 | val compiledScript = cache.getOrPut(path) { compilableEngine().compile(template) } 25 | return compiledScript.eval(includeBindings) as String 26 | } 27 | 28 | fun ScriptTemplateWithBindings.i18n(code: String) = 29 | (bindings["i18n"] as (String) -> String).invoke(code) 30 | 31 | fun Iterable.joinToLine(function: (foo: T) -> String): String 32 | { return joinToString(separator = "\n") { foo -> function.invoke(foo) } } 33 | 34 | var ScriptTemplateWithBindings.users: List 35 | get() = bindings["users"] as List 36 | set(_) { throw UnsupportedOperationException()} 37 | 38 | var ScriptTemplateWithBindings.user: User 39 | get() = bindings["user"] as User 40 | set(_) { throw UnsupportedOperationException()} 41 | 42 | var ScriptTemplateWithBindings.title: String 43 | get() = bindings["title"] as String 44 | set(_) { throw UnsupportedOperationException()} 45 | 46 | fun compilableEngine() = ScriptEngineManager().getEngineByName("kotlin") as Compilable -------------------------------------------------------------------------------- /src/test/kotlin/io/spring/demo/ApplicationTests.kt: -------------------------------------------------------------------------------- 1 | package io.spring.demo 2 | 3 | import org.junit.jupiter.api.Assertions.assertEquals 4 | import org.junit.jupiter.api.Test 5 | import org.springframework.beans.factory.annotation.Autowired 6 | import org.springframework.boot.test.context.SpringBootTest 7 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment 8 | import org.springframework.boot.test.web.client.TestRestTemplate 9 | import org.springframework.boot.test.web.client.getForObject 10 | 11 | 12 | @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) 13 | class ApplicationTests(@Autowired val restTemplate: TestRestTemplate) { 14 | 15 | val englishContent = """ 16 | 17 | Users 18 |

Locale: FR | EN

19 |

Users

20 |
    21 |
  • User Juergen Hoeller
  • 22 |
  • User Rossen Stoyanchev
  • 23 |
  • User Brian Clozel
  • 24 |
  • User Stéphane Nicoll
  • 25 |
  • User Arjen Poutsma
  • 26 |
  • User Sébastien Deleuze
  • 27 |
28 | 29 | """ 30 | 31 | val frenchContent = """ 32 | 33 | Utilisateurs 34 |

Locale: FR | EN

35 |

Utilisateurs

36 |
    37 |
  • Utilisateur Juergen Hoeller
  • 38 |
  • Utilisateur Rossen Stoyanchev
  • 39 |
  • Utilisateur Brian Clozel
  • 40 |
  • Utilisateur Stéphane Nicoll
  • 41 |
  • Utilisateur Arjen Poutsma
  • 42 |
  • Utilisateur Sébastien Deleuze
  • 43 |
44 | 45 | """ 46 | 47 | @Test 48 | fun viewRenderingWithDefaultLocale() { 49 | assertEquals(englishContent, restTemplate.getForObject("/")) 50 | } 51 | 52 | @Test 53 | fun viewRenderingWithEnglishLocale() { 54 | assertEquals(englishContent, restTemplate.getForObject("/?locale=en")) 55 | } 56 | 57 | @Test 58 | fun viewRenderingWithFrenchLocale() { 59 | assertEquals(frenchContent, restTemplate.getForObject("/?locale=fr")) 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | --------------------------------------------------------------------------------