Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#415 custom mainclass for Windows #442

Merged
merged 3 commits into from
Dec 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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