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

Custom mainclass #319

Merged
merged 7 commits into from
Aug 20, 2014
Merged

Custom mainclass #319

merged 7 commits into from
Aug 20, 2014

Conversation

jkutner
Copy link
Contributor

@jkutner jkutner commented Aug 12, 2014

The PR allows for a custom main class as an arg to the bash script. The primary motivation for this is adding the ability to run something like the following to get a repl for an app:

./target/universal/stage/bin/my-app -main scala.tools.nsc.MainGenericRunner -usejavacp

The above requires adding the following to your build.sbt of course:

libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-compiler" % _ )

If this PR is acceptable I will take the time to add this to the bat-template as well.

@lightbend-cla-validator

Hi @jkutner,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Typesafe Contributors License Agreement:

http://typesafe.com/contribute/cla

@jkutner
Copy link
Contributor Author

jkutner commented Aug 12, 2014

This would fix #80 I believe

@muuki88
Copy link
Contributor

muuki88 commented Aug 12, 2014

LGTM. This should be easily testable? Can you provide a test within in the universal
suite which builds a simple app with two executable scala files and run both in the test
and check the output?

It would be even more awesome if you could add a little documentation for it.
See Developer Guide for more details on how to build/check the docs.

@jkutner
Copy link
Contributor Author

jkutner commented Aug 12, 2014

sure. i'll do both and update the PR

@jkutner
Copy link
Contributor Author

jkutner commented Aug 18, 2014

I have tried to create test for this, and I'm having trouble. I think I don't understand the testing framework. Can you look at my test project under universal/staging-custom-main and tell me what to do next?

@kardapoltsev
Copy link
Member

Now you could run your test with
scripted universal/staging-custom-main
Also you could add custom task to bulid.sbt and implement your own tests (see other tests for examples).

@jkutner
Copy link
Contributor Author

jkutner commented Aug 19, 2014

I tried to follow the example of the existing tests, but I'm stuck testing for my bin/ dir and I don't know why. My test fails with this error no matter what I try:

Caused by: java.lang.RuntimeException: Test script error: File(s) did not exist: [ /var/folders/mk/w8gpswvs1tl70bhj60s4kvy40000gn/T/sbt_cdc73125/staging-custom-main/stage-custom-main-0.1.0/bin ]

Am I doing something obviously wrong?

@kardapoltsev
Copy link
Member

Some suggestions about debugging. Are you sure where do you extract zip? Try to add $ pause command after unzip and check real file tree.

@muuki88
Copy link
Contributor

muuki88 commented Aug 19, 2014

Ah, nice trick with the $ pause. I'm using good old println, like this

TaskKey[Unit]("print-dir") <<= (baseDirectory, streams) map { (t, streams) =>
  streams.log.warn("----------------------------")
  (t).listFiles foreach (f => streams.log.warn(f.getAbsolutePath))
}

The error

Anyway, I found the error. The problem is that there are multiple mainClass classes.
The makeUniversalBinScript in JavaApp is responsible for creating the correct mappings.
However it seems to get confused with multiple main classes.

The fix

Setting a specific main class helps.

mainClass in Compile := Some("Main")

Note that is must be scoped to Compile!

@jkutner
Copy link
Contributor Author

jkutner commented Aug 19, 2014

Thanks @kardapoltsev and @muuki88 -- i am wiser now :) The test is passing. I will update the docs soon.

@muuki88
Copy link
Contributor

muuki88 commented Aug 20, 2014

Brilliant! Thanks @jkutner

muuki88 added a commit that referenced this pull request Aug 20, 2014
@muuki88 muuki88 merged commit 8950f15 into sbt:master Aug 20, 2014
@muuki88
Copy link
Contributor

muuki88 commented Aug 20, 2014

Merged into v0.7.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request universal Zip, tar.gz, tgz and bash issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants