Commit Graph

90 Commits

Author SHA1 Message Date
Ethan Atkins 6faf460a1b Add loop to SelectMainClass
Rather than exiting when the user enters an invalid line, we can
reprompt them.
2020-07-10 13:37:54 -07:00
Ethan Atkins 017e3e7f2c Improve SelectMainClass output
This ensures that super shell lines are cleared.
2020-06-24 19:19:06 -07:00
Ethan Atkins 079cf2178c Add ClearScreenAfterCursor
This communicates intent better than clearScreen(0).
2020-05-01 13:02:48 -07:00
Ethan Atkins 44ef718448 Improve run command warning
When the user inputs `run` or `runMain` we shouldn't print the warning
about multiple classes because in the case of run they already will be
prompted to select the classes and in the case of runMain, they are
already required to specify the class name.

Bonus:
 * improve punctuation
 * add clear screen to selector dialogue
 * print selector dialogue in one call to println -- this should prevent
   the possibility of messages from other threads being interlaced with
   the dialogue
2020-05-01 12:35:43 -07:00
Eugene Yokota 2396b449fe Contraband 0.4.6 2020-04-24 17:44:15 -04:00
Eugene Yokota 3ce4d22b84 integrate with VirtualFile changes
Ref https://github.com/sbt/zinc/pull/712
2020-04-24 17:44:14 -04:00
Ethan Atkins 2c473fc31d Improve ClassLoader layering error message
When a class on the project classpath is loaded via reflection by one of
the parents of the project classloader, sbt run can fail with a
mysterious ClassNotFoundException. This is expected behavior but it
wasn't previously explained to the user.

Ref https://github.com/sbt/sbt/issues/5410.
2020-02-01 14:42:21 -08:00
Eugene Yokota 54b3405f42 apply -Yno-lub
To demonstrate [-Yno-lub](http://eed3si9n.com/stricter-scala-with-ynolub), this shows the code changes that removes lubing (Not all subprojects are done).

After I made the changes, I switched the Scala back to normal 2.12.10.
2019-10-13 23:46:23 -04:00
Ethan Atkins cfa29bafe7 Close classloader in ScalaRun.run
It is necessary to close the run classloader in order to reuse the
dependency layer in the next run. If the loader needs to survive past
the main method, as is the case with `run` and `runMain`, then the
runWithLoader api should be used instead.

This mostly restores the behavior of classloader closing to 1.3.0 for
the tasks that use ScalaRun except for `run` and `runMain`. But unlike
1.3.0, if the classloader is closed it can still spawn a zombie
classloader.

Fixes #5124.
2019-09-24 12:22:03 -07:00
Ethan Atkins d371faf90a Manage classloader in BackgroundJobService
In https://github.com/sbt/sbt/issues/5075 we realized that sbt 1.3.0
introduces a regression where it closes the classloader used to invoke
the main method for in process run before all of its non-daemon threads
have terminated. To fix this and still close the classloader, I add a
method, runInBackgroundWithLoader that provides the background job
services with an optional classloader that it can close after the job
completes.

This cleanly merges and works with 1.3.x as well.
2019-09-14 14:52:18 -07:00
Eugene Yokota f0f55c38a5 quote run argument if it contains a whitespace
Fixes #4834
2019-06-24 19:32:55 -04:00
Ethan Atkins 67df72ab01 Properly close a number of classloaders
I discovered there were a number of places where closing a ClassLoader
didn't work correctly because I was assuming it was a URLClassLoader
when it was actually a ClasspathFilter. I also incorrectly imported the
wrong kind of URLClassLoader in Run.scala. Finally, I close the
SbtMetaBuildClassLoader when xMain exits now.
2019-05-02 14:38:33 -07:00
Eugene Yokota 1e157b991a apply formatting 2019-04-20 03:23:54 -04:00
Ethan Atkins a4f1d23d71 Close test and run classloaders
It's good practice to call close on a URLClassLoader when we're done
with it.
2019-04-02 20:53:37 -07:00
Ethan Atkins 8ef5a67b64 Add better error message if run fails
It is possible with the new layering strategies that tests may fail if a
java package private class is accessed across classloader layers. This
will result in an IllegalAccessError that is hard to debug. With this
commit, I add an error message that will be displayed if run throws an
IllegalAccessError that suggests that the user try the
ScalaInstance layering strategy or the flat layering strategy.
2019-04-02 20:53:37 -07:00
Ethan Atkins a06f5435c6 Use layered ClassLoaders in run and test tasks
Using the data structures that I added in the previous commits, it is
now possible to rework the run and test task to use (configurable)
layered class loaders. The layering strategy is globally set to
LayeringStrategy.Default. The default strategy leads to what is
effectively a three layered ClassLoader for the both the test and run
tasks. The first layer contains the scala instance (and test framework
loader in the test task). The second layer contains all of the
dependencies for the configuration while the third layer contains the
project artifacts.

The layering strategy is very easily changed both at the Global or
Configuration level, e.g. adding
Test / layeringStrategy := LayeringStrategy.Flat
to the project build.sbt will make the test task not even use the scala
instance and instead a create a single layer containing the full
classpath of the test task.

I also tried to ensure that all of the ClassLoaders have good toString
overrides so that it's easy to see how the ClassLoader is constructed
with, e.g. `show testLoader`, in the sbt console.

In this commit, the ClassLoaderCache instances are settings. In the next
commit, I make them tasks so that we can easily clear out the caches
with a command.
2019-01-30 08:55:22 -08:00
Ethan Atkins 6725b39a84 Bump io to 1.3.0-M3
I had to turn off -Xfatal-warnings in commandProj because after updating
io, commandProj depends on the deprecated EventMonitor class. In #4335,
I stop using EventMonitor, but deprecate the Watched class which is both
defined and used (as an unused attribute key) in commandProj. I think we
can probably get rid of Watched in 1.4.x and certainly in a hypothetical
2.x, so hopefully we can restore -Xfatal-warnings sooner than later.

I also had to replace uses of IO.classLocationFile with
IO.classLocationPath to avoid compilation failures due to
-Xfatal-warnings.
2018-10-08 13:59:34 -07:00
Eugene Yokota 4b23036c63 contraband 0.4.1 2018-09-18 16:56:19 -04:00
Eugene Yokota 4ff4f6e45e Update header 2018-09-14 04:53:36 -04:00
Eugene Yokota 306ee82db3 Use MessageOnlyException for "Nonzero exit code" 2018-06-27 07:09:59 -04:00
Dale Wijnand 8f4b8abb7b
Run scalafmt & test:scalafmt 2018-04-24 16:12:10 +01:00
Eugene Yokota c2837c7714 Merge branch 'wip/bumpsbt' into wip/merge-1.1.x 2018-03-27 10:16:10 -04:00
Dale Wijnand dd4de14593
Upgrade to contraband 0.4.0 2018-03-12 15:39:07 +00:00
Dale Wijnand ed5a8c118b
Upgrade to contraband 0.3.3 2018-03-08 12:49:38 +00:00
Dale Wijnand 90cd60f3b9
Merge branch '1.1.x' into merge-1.1.x-into-1.x
* 1.1.x:
  Use Java's redirectInput rather than sys.process's connectInput
  Re-write toolboxClasspath to use sbt-buildinfo
  Cleanup generateToolboxClasspath
  Upgrade to sbt-buildinfo 0.8.0
  Fix how fullClasspath is defined in TestBuildInfo
  delete buildinfo.BuildInfo from sbt main

Conflicts:
	project/plugins.sbt
2018-02-28 10:30:53 +00:00
Jason Zaugg b0f52510e0 Use Java's redirectInput rather than sys.process's connectInput
Fixes #3737
2018-02-26 11:30:30 +10:00
Dale Wijnand 113656aed1
Remove compile warnings 2018-01-16 11:17:01 +00:00
Simon Schäfer 187a861194 Fix unused pattern match vals in run project 2017-10-19 13:07:24 +02:00
Dale Wijnand a41727fb17
Add, configure & enforce file headers 2017-10-05 09:03:40 +01:00
Dale Wijnand 805b76f3d4
Add back, re-configure & re-enable Scalafmt 2017-08-10 16:35:23 +01:00
Eugene Yokota 7b2b7d696b Don't wrap InputStream for Windows
Ref #3282

We used to wrap InputStream so it will inject Thread.sleep, which then allows the thread to be cancelled, emulating a non-blocking readLine. This trick doesn't seem to work for Windows.
For non-Cygwin, actually just removing the wrapping does the job, but I couldn't get it to work for Cygwin.

To test, run some command via network, and then type `show name` into the terminal. On Cygwin, it will not respond.
2017-07-22 03:34:10 -04:00
Eugene Yokota 00a9dd14a4 Bump Contraband to latest 2017-07-17 01:05:30 -04:00
jvican 26cfe0cb7b
Remove any reference to `F0` and `F1`
Syncs with https://github.com/sbt/zinc/pull/359 and
https://github.com/sbt/util/pull/84.
2017-07-14 17:29:06 +02:00
Eugene Yokota efa3b1d340
Bump to latest io, scalajson, sjsonnew, contraband, util, lm, zinc 2017-07-06 11:05:24 +01:00
Eugene Yokota 3724277704 migrate ForkOptions to Contraband 2017-05-12 05:22:08 -04:00
Eugene Yokota da046791e0 Apply Scalafmt formatting 2017-04-21 04:48:31 -04:00
Dale Wijnand a6015793e2
Code formatting only changes 2017-04-11 14:32:38 +01:00
eugene yokota e23fa31f08 Merge pull request #2810 from kzys/remove-process-extra
Remove ProcessExtra and the use of java.lang.ProcessBuilder
2017-01-21 17:06:41 -05:00
Eugene Yokota 1e960b324c Implement copyClasspath for bgRun
Copies products to the workind directory, and the rest to the serviceTempDir of this service, both wrapped in SHA-1 hash of the file contents. This is intended to mimize the file copying and accumulation of the unused JAR file. Since working directory is wiped out when the background job ends, the product JAR is deleted too. Meanwhile, the rest of the dependencies are cached for the duration of this service.
2017-01-20 13:02:31 -05:00
Eugene Yokota 74cfbd4a9c Implement bgRun based on sbt-core-next 2017-01-20 13:02:31 -05:00
Josh Soref 524579d87a spelling: evaluate 2017-01-20 08:13:44 +00:00
Josh Soref c81894e45b spelling: command 2017-01-20 08:10:32 +00:00
Dale Wijnand 43821667bf
Upgrade scalariform version 2016-12-11 12:13:11 +00:00
Kazuyoshi Kato 1f2c00cc56 Remove ProcessExtra and the use of java.lang.ProcessBuilder
Fixes #2736.
2016-10-27 19:31:46 -07:00
Dale Wijnand 84c611af36 Remove unused vals/defs 2016-07-12 14:31:35 +01:00
Dale Wijnand deea82542c Remove unused imports 2016-07-12 11:55:10 +01:00
Dale Wijnand 222a970080 Kill some vars 2016-07-07 01:39:52 +01:00
Dale Wijnand 8226ed7682 Cleanup runProj 2016-06-21 08:09:29 +01:00
Eugene Yokota 5f9e6e4aad Don't use test artifacts from other projects
Fixes #2597
2016-05-12 12:45:09 -04:00
Martin Duhem a2abb6eeb6 Update to latest version of incremental, fix imports 2015-09-16 10:16:03 +02:00