Introduce 'kotlin' script for running programs

'kotlin' is to 'kotlinc' what 'java' is to 'javac'. However it will support
much more: running class by name, jar, scripts, expressions, REPL
This commit is contained in:
Alexander Udalov
2015-06-14 18:26:01 +03:00
parent 3c4b2994a9
commit 4dc29bf0b2
13 changed files with 429 additions and 33 deletions
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash --posix
# Copyright 2010-2015 JetBrains s.r.o.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
export KOTLIN_RUNNER=1
"$(dirname "$(which "$0")")"/kotlinc "$@"
+20
View File
@@ -0,0 +1,20 @@
@echo off
rem Copyright 2010-2015 JetBrains s.r.o.
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
setlocal
set _KOTLIN_RUNNER=1
call %~dps0kotlinc.bat %*
+14 -16
View File
@@ -9,8 +9,6 @@
# PARTICULAR PURPOSE.
##############################################################################
[ -n "$KOTLIN_COMPILER" ] || KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
cygwin=false;
case "`uname`" in
CYGWIN*) cygwin=true ;;
@@ -34,11 +32,8 @@ if $cygwin; then
KOTLIN_HOME=`cygpath --windows --short-name "$KOTLIN_HOME"`
fi
[ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx256M -Xms32M -noverify"
[ -n "$JAVA_OPTS" ] || JAVA_OPTS="-Xmx256M -Xms32M"
# break out -D and -J options and add them to JAVA_OPTS as well
# so they reach the underlying JVM in time to do some good. The
# -D options will be available as system properties.
declare -a java_args
declare -a kotlin_args
@@ -59,17 +54,20 @@ while [ $# -gt 0 ]; do
esac
done
# reset "$@" to the remaining args
set -- "${kotlin_args[@]}"
if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
JAVACMD="$JAVA_HOME/bin/java"
fi
"${JAVACMD:=java}" \
$JAVA_OPTS \
"${java_args[@]}" \
-cp "${KOTLIN_HOME}/lib/kotlin-preloader.jar" \
org.jetbrains.kotlin.preloading.Preloader \
-cp "${KOTLIN_HOME}/lib/kotlin-compiler.jar" \
$KOTLIN_COMPILER "$@"
declare -a kotlin_app
if [ -n "$KOTLIN_RUNNER" ];
then
java_args=("${java_args[@]}" "-Dkotlin.home=${KOTLIN_HOME}")
kotlin_app=("${KOTLIN_HOME}/lib/kotlin-runner.jar" "org.jetbrains.kotlin.runner.Main")
else
[ -n "$KOTLIN_COMPILER" ] || KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
java_args=("${java_args[@]}" "-noverify")
kotlin_app=("${KOTLIN_HOME}/lib/kotlin-preloader.jar" "org.jetbrains.kotlin.preloading.Preloader" "-cp" "${KOTLIN_HOME}/lib/kotlin-compiler.jar" $KOTLIN_COMPILER)
fi
"${JAVACMD:=java}" $JAVA_OPTS "${java_args[@]}" -cp "${kotlin_app[@]}" "${kotlin_args[@]}"
+2 -1
View File
@@ -14,6 +14,7 @@ rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
set KOTLIN_COMPILER=org.jetbrains.kotlin.cli.js.K2JSCompiler
setlocal
set _KOTLIN_COMPILER=org.jetbrains.kotlin.cli.js.K2JSCompiler
call %~dps0kotlinc.bat %*
+12 -7
View File
@@ -13,10 +13,10 @@ rem We adopt the following conventions:
rem - System/user environment variables start with a letter
rem - Local batch variables start with an underscore ('_')
@setlocal
setlocal
call :set_home
if "%KOTLIN_COMPILER%"=="" set KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
if "%_KOTLIN_COMPILER%"=="" set _KOTLIN_COMPILER=org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
if not "%JAVA_HOME%"=="" (
if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe"
@@ -25,11 +25,16 @@ if not "%JAVA_HOME%"=="" (
if "%_JAVACMD%"=="" set _JAVACMD=java
rem We use the value of the JAVA_OPTS environment variable if defined
set _JAVA_OPTS=-Xmx256M -Xms32M -noverify
set _JAVA_OPTS=-Xmx256M -Xms32M
"%_JAVACMD%" %_JAVA_OPTS% -cp "%_KOTLIN_HOME%\lib\kotlin-preloader.jar" ^
org.jetbrains.kotlin.preloading.Preloader -cp "%_KOTLIN_HOME%\lib\kotlin-compiler.jar" ^
%KOTLIN_COMPILER% %*
if not "%_KOTLIN_RUNNER%"=="" (
"%_JAVACMD%" %_JAVA_OPTS% "-Dkotlin.home=%_KOTLIN_HOME%" -cp "%_KOTLIN_HOME%\lib\kotlin-runner.jar" ^
org.jetbrains.kotlin.runner.Main %*
) else (
"%_JAVACMD%" %_JAVA_OPTS% -noverify -cp "%_KOTLIN_HOME%\lib\kotlin-preloader.jar" ^
org.jetbrains.kotlin.preloading.Preloader -cp "%_KOTLIN_HOME%\lib\kotlin-compiler.jar" ^
%_KOTLIN_COMPILER% %*
)
exit /b %ERRORLEVEL%
goto end
@@ -44,5 +49,5 @@ rem # subroutines
goto :eof
:end
@endlocal
endlocal