Skip to content

Commit

Permalink
Merge pull request #442 from tartakynov/custom-main-windows
Browse files Browse the repository at this point in the history
#415 custom mainclass for Windows
  • Loading branch information
muuki88 committed Dec 16, 2014
2 parents 59c2b9f + 16b8c52 commit 353a11a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ if "!_TEST_PARAM:~0,2!"=="-D" (
)
)
) else (
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
if "!_TEST_PARAM!"=="-main" (
call set CUSTOM_MAIN_CLASS=%%2
shift
) else (
set _APP_ARGS=!_APP_ARGS! !_PARAM1!
)
)
shift
goto param_loop
Expand All @@ -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

Expand Down
22 changes: 22 additions & 0 deletions src/sbt-test/windows/test-custom-main/build.sbt
Original file line number Diff line number Diff line change
@@ -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)
()
}

1 change: 1 addition & 0 deletions src/sbt-test/windows/test-custom-main/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object CustomMain extends App {
println("Custom Main Method")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Main extends App {
println("App Main Method")
}
7 changes: 7 additions & 0 deletions src/sbt-test/windows/test-custom-main/test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 353a11a

Please sign in to comment.