From a4f9037a0e45a41aca11c2e68d5faa5a476a004c Mon Sep 17 00:00:00 2001 From: Artem Tartakynov Date: Sun, 14 Dec 2014 16:02:01 +0600 Subject: [PATCH 1/3] added custom main test for windows batch --- .../windows/test-custom-main/build.sbt | 22 +++++++++++++++++++ .../test-custom-main/project/plugins.sbt | 1 + .../src/main/scala/CustomMain.scala | 3 +++ .../src/main/scala/Main.scala | 3 +++ src/sbt-test/windows/test-custom-main/test | 7 ++++++ 5 files changed, 36 insertions(+) create mode 100644 src/sbt-test/windows/test-custom-main/build.sbt create mode 100644 src/sbt-test/windows/test-custom-main/project/plugins.sbt create mode 100644 src/sbt-test/windows/test-custom-main/src/main/scala/CustomMain.scala create mode 100644 src/sbt-test/windows/test-custom-main/src/main/scala/Main.scala create mode 100644 src/sbt-test/windows/test-custom-main/test diff --git a/src/sbt-test/windows/test-custom-main/build.sbt b/src/sbt-test/windows/test-custom-main/build.sbt new file mode 100644 index 000000000..b1c504eee --- /dev/null +++ b/src/sbt-test/windows/test-custom-main/build.sbt @@ -0,0 +1,22 @@ +enablePlugins(JavaAppPackaging) + +name := "test-custom-main" + +version := "0.1.0" + +mainClass in Compile := Some("Main") + +TaskKey[Unit]("check-app-main") <<= (packageBin in Universal, streams) map { (zipFile, streams) => + val process = sbt.Process("target/universal/stage/bin/test-custom-main.bat") + val out = (process!!) + if (out.trim != "App Main Method") error("unexpected output: " + out) + () +} + +TaskKey[Unit]("check-custom-main") <<= (packageBin in Universal, streams) map { (zipFile, streams) => + val process = sbt.Process("target/universal/stage/bin/test-custom-main.bat", Seq("-main", "CustomMain")) + val out = (process!!) + if (out.trim != "Custom Main Method") error("unexpected output: " + out) + () +} + diff --git a/src/sbt-test/windows/test-custom-main/project/plugins.sbt b/src/sbt-test/windows/test-custom-main/project/plugins.sbt new file mode 100644 index 000000000..b53de154c --- /dev/null +++ b/src/sbt-test/windows/test-custom-main/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) diff --git a/src/sbt-test/windows/test-custom-main/src/main/scala/CustomMain.scala b/src/sbt-test/windows/test-custom-main/src/main/scala/CustomMain.scala new file mode 100644 index 000000000..51e6bea7f --- /dev/null +++ b/src/sbt-test/windows/test-custom-main/src/main/scala/CustomMain.scala @@ -0,0 +1,3 @@ +object CustomMain extends App { + println("Custom Main Method") +} diff --git a/src/sbt-test/windows/test-custom-main/src/main/scala/Main.scala b/src/sbt-test/windows/test-custom-main/src/main/scala/Main.scala new file mode 100644 index 000000000..682a5e2d6 --- /dev/null +++ b/src/sbt-test/windows/test-custom-main/src/main/scala/Main.scala @@ -0,0 +1,3 @@ +object Main extends App { + println("App Main Method") +} diff --git a/src/sbt-test/windows/test-custom-main/test b/src/sbt-test/windows/test-custom-main/test new file mode 100644 index 000000000..e5b91b2fe --- /dev/null +++ b/src/sbt-test/windows/test-custom-main/test @@ -0,0 +1,7 @@ +# Stage the distribution and ensure main class can be run. +> stage +$ exists target/universal/stage/bin/ +$ exists target/universal/stage/bin/test-custom-main.bat +> check-app-main +> check-custom-main + From bfc71587757dd55ea866ff8ae9bc051982cd6d06 Mon Sep 17 00:00:00 2001 From: Artem Tartakynov Date: Sun, 14 Dec 2014 16:02:46 +0600 Subject: [PATCH 2/3] added cli option to set a custom main class for windows batch --- .../typesafe/sbt/packager/archetypes/bat-template | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template index 8c4860655..81d386960 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template @@ -114,7 +114,12 @@ if "!_TEST_PARAM:~0,2!"=="-D" ( ) ) ) else ( - set _APP_ARGS=!_APP_ARGS! !_PARAM1! + if "%1"=="-main" ( + set CUSTOM_MAIN_CLASS=%2 + shift + ) else ( + set _APP_ARGS=!_APP_ARGS! !_PARAM1! + ) ) shift goto param_loop @@ -125,8 +130,14 @@ set _JAVA_OPTS=!_JAVA_OPTS! !_JAVA_PARAMS! @@APP_DEFINES@@ +if defined CUSTOM_MAIN_CLASS ( + set MAIN_CLASS=!CUSTOM_MAIN_CLASS! +) else ( + set MAIN_CLASS=!APP_MAIN_CLASS! +) + rem Call the application and pass all arguments unchanged. -"%_JAVACMD%" !_JAVA_OPTS! !@@APP_ENV_NAME@@_OPTS! -cp "%APP_CLASSPATH%" %APP_MAIN_CLASS% !_APP_ARGS! +"%_JAVACMD%" !_JAVA_OPTS! !@@APP_ENV_NAME@@_OPTS! -cp "%APP_CLASSPATH%" %MAIN_CLASS% !_APP_ARGS! if ERRORLEVEL 1 goto error goto end From 16b8c528228703b1a94bec2f51fefdd5e96fd1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A2=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D0=BA=D1=8B=D0=BD=D0=BE=D0=B2?= Date: Mon, 15 Dec 2014 10:25:32 +0600 Subject: [PATCH 3/3] fixed the wrong check (due to delayed expansion) in bat-template --- .../com/typesafe/sbt/packager/archetypes/bat-template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template b/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template index 81d386960..3556daae3 100644 --- a/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template +++ b/src/main/resources/com/typesafe/sbt/packager/archetypes/bat-template @@ -114,8 +114,8 @@ if "!_TEST_PARAM:~0,2!"=="-D" ( ) ) ) else ( - if "%1"=="-main" ( - set CUSTOM_MAIN_CLASS=%2 + if "!_TEST_PARAM!"=="-main" ( + call set CUSTOM_MAIN_CLASS=%%2 shift ) else ( set _APP_ARGS=!_APP_ARGS! !_PARAM1!