Commit Graph

364 Commits

Author SHA1 Message Date
Ethan Atkins a1580bafbf Improve error message
Previously, the invalid commands would be wrapped in 'Left($CMD)'.
2018-10-10 18:35:30 -07:00
Ethan Atkins dc4f705500 Add support to rebuild a '~' task by pressing 'r'
Sometimes a user may want to rerun their task even if the source files
haven't changed. Presently this is a little annoying because you have to
hit enter to stop the build and then up arrow or <ctrl+r> plus enter to
rebuild. It's more convenient to just be able to press the 'r' key to
re-run the task.

To implement this, I had to make the watch task set up a jline terminal
so that System.in would be character buffered instead of line buffered.
Furthermore, I took advantage of the NonBlockingInputStream
implementation provided by jline to wrap System.in. This was necessary
because even with the jline terminal, System.in.available doesn't return
> 0 until a newline character is entered. Instead, the
NonBlockingInputStream does provide a peek api with a timeout that will
return the next unread key off of System.in if there is one available.
This can be use to proxy available in the WrappedNonBlockingInputStream.

To ensure maximum user flexibility, I also update the watchHandleInput Key to
take an InputStream and return an Action. This setting will now receive
the wrapped System.in, which will allow the user to create their own
keybindings for watch actions without needing to use jline themselves.

Future work might make it more straightforward to go back to a line
buffered input if that is what the user desires.
2018-10-09 12:09:42 -07:00
Ethan Atkins b155ffb77b Add support for polling some directories
It is not always possible to monitor a directory using OS file system
events. For example, inotify does not work with nfs. To work around
this, I add support for a hybrid FileTreeViewConfig that caches a
portion of the file system and monitors it with os file system
notification, but that polls a subset of the directories. When we query
the view using list or listEntries, we will actually query the file
system for the polling directories while we will read from the cache for
the remainder. When we are not in a continuous build (~ *), there is no
polling of the pollingDirectories but the cache will continue to update
the regular directories in the background. When we are in a continuous
build, we use a PollingWatchService to poll the pollingDirectories and
continue to use the regular repository callbacks for the other
directories.

I suspect that #4179 may be resolved by adding the directories for which
monitoring is not working to the pollingDirectories task.
2018-10-09 12:09:42 -07:00
Ethan Atkins 2b2b84f589 Use FileTreeDataView to collect files
Now that we have the fileTreeView task, we can generalized the process
of collecting files from the view (which may or may not actually cache
the underlying file tree). I moved the implementation of collectFiles
and addBaseSources into the new FileManagement object because Defaults
is already too large of a file. When we query the view, we also need to
register the directory we're listing because if the underlying view is a
cache, we must call register before any entries will be available.
Because FileTreeDataView doesn't have a register method, I implement
registration with a simple implicit class that pattern matches on the
underlying type and only calls register if it is actually a
FileRepository.

A side effect of this change is that the underlying files returned by
collectFiles and appendBaseSources are StampedFile instances. This is so
that in a subsequent commit, I can add a Zinc external hook that will
read these stamps from the files in the source input array rather than
compute the stamp on the fly. This leads to a substantial reduction in
Zinc startup time for projects with many source files. The file filters
also may be applied more quickly because the isDirectory property (which
we check for all source files) is read from a cached value rather than
requiring a stat.

I had to update a few of the scripted tests to use the `1.2.0`
FileTreeViewConfig because those tests would copy a file and then
immediately re-compile. The latency of cache invalidation is O(1-10ms),
but not instantaneous so it's necessary to either use a non-caching
FileTreeView or add a sleep between updates and compilation. I chose the
former.
2018-10-09 12:09:42 -07:00
Ethan Atkins d31fae59f7 Add global file repository task
Every time that the compile task is run, there are potentially a large
number of iops that must occur in order for sbt to generate the source
file list as well as for zinc to check which files have changed since
the last build. This can lead to a noticeable delay between when a build
is started (either manually or by triggered execution) and when
compilation actually begins. To reduce this latency, I am adding a
global view of the file system that will be stored in
BasicKeys.globalFileTreeView.

To make this work, I introduce the StampedFile trait, which augments the
java.io.File class with a stamp method that returns the zinc stamp for
the file. For source files, this will be a hash of the file, while for
binaries, it is just the last modified time. In order to gain access to
the sbt.internal.inc.Stamper class, I had to append addSbtZinc to the
commandProj configurations.

This view may or may not use an in-memory cache of the file system tree
to return the results. Because there is always the risk of the cache
getting out of sync with the actual file system, I both make it optional
to use a cache and provide a mechanism for flushing the cache. Moreover,
the in-memory cache implementation in sbt.io, which is backed by a
swoval FileTreeRepository, has the property that touching a monitored
directory invalidates the entire directory within the cache, so the
flush command isn't even strictly needed in general.

Because caching is optional, the global is of a FileTreeDataView, which
doesn't specify a caching strategy. Subsequent commits will make use of
this to potentially speed up incremental compilation by caching the
Stamps of the source files so that zinc does not need to compute the
hashes itself and will allow for continuous builds to use the cache to
monitor events instead of creating a new, standalone FileEventMonitor.
2018-10-09 12:09:42 -07:00
Ethan Atkins 4347d21248 Add support for user defined Actions
It may be useful for users to be able to return their own custom
Action types in the Config callbacks. For a contrived example, a user
could add a jar file in the .ivy2 directory to the watch sources and
trigger a reboot full when that jar changes.
2018-10-09 12:09:42 -07:00
Ethan Atkins 28fd4a1e61 Add the ability to halt watch on failure
There may be instances where the user may wish to stop the watch if an
error occurs running the task. To facilitate this, I add boolean
parameter, lastStatus, to watchShouldTerminate. The value is computed by
modifying the state used to run the task to have a custom onFailure
command. If the task fails, the returned state will have the onFailure
command will be enqueued at the head of the remaining commands. The
result of the task then becomes true if the custom onFailure is not
present in the remaining commands and false if it is. We don't actually
run this command, so it's just implemented with the identity function.

I also updated Watched.watch to return an Action instead of Unit. This
enables us to return a failed state if Watched.watch returns
HandleError.
2018-10-09 12:09:41 -07:00
Ethan Atkins 7d3d3c71d6 Refactor Watched
This commit reworks Watched to be more testable and extensible. It also
adds some small features. The previous implementation presented a number
of challenges:

1) It relied on external side effects to terminate the watch, which was
   difficult to test
2) It exposed irrelevant implementation details to the user in the
   methods that exposed the WatchState as a parameter.
3) It spun up two worker threads. One was to monitor System.in for user
   input. The other was to poll the watch service for events and write
   them to a queue. The user input thread actually broke '~console'
   because nearly every console session will hit the <enter> key, which
   would eventually cause the watch to stop when the user exited the
   console.

To address (1), I add the shouldTerminate method to WatchConfig. This
takes the current watch iteration is input and if the function returns
true, the watch will stop.

To address (2), I replace the triggeredMessage and watchingMessage keys
with watchTriggeredMessage and watchStartMessage. The latter two keys
are functions that do not take the WatchState as parameters. Both
functions take the current iteration count as a parameter and the
watchTriggeredMessage also has a parameter for the path that triggered
the build.

To address (3), I stop using the sbt.internal.io.EventMonitor and
instead use the sbt.io.FileEventMonitor. The latter class is similar to
the former except that it's polling method accepts a duration, which may
be finite or infinite) and returns all of the events that occurred since
it was last polled. By adding the ability to poll for a finite amount of
time, we can interleave polling for events with polling System.in for
user input, all on the main thread. This eliminates the two extraneous
threads and fixes the '~console' use case I described before.

I also let the user configure the function that reads from System.in via
the watchHandleInput method. In fact, this method need not read from
System.in at all since it's just () => Watched.Action. The reason that
it isn't () => Boolean is that I'd like to leave open the option for the
ability to trigger a build via user input, not just terminating the
watch. My initial idea was to add the ability to type 'r' to re-build in
addition to <enter> to exit. This doesn't work without integrating
jline though because the input is buffered. Regardless, for testing
purposes, it gives us the ability to add a timeout to the watch by
making handleInput return true when a deadline expires.

The tests are a bit wonky because I still need to rely on side effects
in the logging methods to orchestrate the sequence of file events that
I'd like to test. While I could move some of this logic into a
background thread, there still needs to be coordination between the
state of the watch and the background thread. I think it's easier to
reason about when all of the work occurs on the same thread, even if it
makes these user provided functions impure.

I deprecated all of the previous watch related keys that are no longer
used with the new infrastructure. To avoid breaking existing builds, I
make the watchConfig task use the deprecated logging methods if they are
defined in the user's builds, but sbt will not longer set the default
values. For the vast majority of users, it should be straightforward to
migrate their builds to use the new keys.  My hunch is that the of the
deprecated keys, only triggeredMessage is widely used (in conjunction
with the clear screen method) and it is dead simple to replace it with
watchTriggeredMessage.

Note: The FileTreeViewConfig class is not really necessary for this commit.
It will become more important in a subsequent commit which introduces an
optional global file system cache.
2018-10-08 22:00:50 -07:00
Ethan Atkins 7764dc42ae Move executeContinuously into LegacyWatched
This helps keep Watched.scala more manageable until we can potentially
remove this code.
2018-10-08 22:00:50 -07:00
Ethan Atkins 28aa1de32a Refactor continuous execution
This commit makes watch event logging work in the '~' command. The
previous design of the command made this difficult, so there is a
significant re-design of the implementation of '~'. I believe that this
redesign will allow the feature to be maintained and improved more
easily moving forward. With the redesign, it is now possible to test the
business logic of the watch command (and I add a rudimentary test that I
will build upon in subsequent commits).

A bonus of this redesign is that now if the user tries to watch an
invalid command, the watch will immediately terminate with an error
rather than get stuck waiting for events when the task can never
possibly succeed.

The previous implementation of the '~' command makes it difficult
to dynamically control the implementation arguments because it is
implemented in the command project which makes it unable to depend on
any task keys that are defined in the build. It works around this by
putting all of it's configuration in the Watched attribute which is
stored globally. This would not have been necessary if the function had
been defined in the main project where it could just extract the value
of the watched task rather than relying on the global attribute value.
Moreover, because it cannot depend on tasks, it makes it nigh impossible
to use the logging framework within the '~' command.

Another issue with the previous implementation is that it's somewhat
difficult to reason about. The executeContinuously has effectively two
entry points: one for the first time the command is run and one for each
subsequent invocation when a new build is triggered. The successive
invocations are triggered by prepending commands to run to the previous
state. This is made recursive by prepending the initial command (that
was prefixed with '~'. Which branch we're in is determined by checking
for the existence of a temporary attribute, that we must ensure that we
remove when the build is stopped. This makes a lot of behavior non-local and
difficult for an outsider who is less familiar with sbt to understand.

Broadly, this refactor does two things:
1) Move the definition of continuous from BasicCommands to BuiltInCommands
2) Re-work the implementation to be executed in code rather than using
   the sbt dsl.

The first part is simple. We just add an implementation of continuous to
BuiltInCommands and remove it from the list of BasicCommands. We need to
leave in the legacy implementation for binary compatibility. I also
moved all of the actual implementation logic into Watched, which makes
maintenance easier since most of the logic is in one place.

The second part is more complicated. Rather than rely on the sbt dsl
(e.g. `(ClearOnFailure :: next :: FailureWall :: repeat :: s)`) to
parse and run the command. We manually parse the command and generate a
task of type `() => State`. We don't actually need to do anything with
the generated state because we're going to return the original state at
the end of the command no matter what. With this task, we can then
create a tail recursive function that repeatedly executes the task until
the watch is terminated.

The parsing is handled in the Watch.command method (which is where I
moved the refactored BasicCommands.continuous implementation). The
actual task running and monitoring is handled in Watched.watch. This
method has no reference to the sbt state, which makes it testable. It sets
up an event monitor and then delegates the recursive monitoring to a
small nested function, Watched.watch.impl. One nice thing about this
approach is that it is very easy to reason about the life cycle of the
EventMonitor. The recursive call is within a try { } finally { } where
the monitor and stdin are guaranteed to be cleared at the end.

Adding support for a custom (and default) watch logger is trivial with
the new infrastructure and is done via the watchLogger TaskKey.

There was a small reporting race condition that was introduced by the
change to (2). Because the new implementation is able to bypass command
parsing for triggered builds, the watch message would usually end up
being printed before the task outcome was fully logged. To work around
this, I made the watch and triggered messages be logged rather than
printed directly to stdout. As a result, the only user visible result of
this change should be that instead of seeing:
"1. Waiting for source changes in project foo... (press enter to interrupt)",
users will now see:
"[info] 1. Waiting for source changes in project foo... (press enter to interrupt)".
2018-10-08 22:00:50 -07:00
Ethan Atkins da54e2fbd3 Deprecate unused method 2018-10-08 22:00:50 -07:00
Ethan Atkins 3e62b983a2 Remove intellij warnings 2018-10-08 22:00:50 -07:00
eugene yokota a943543291
Merge pull request #4334 from eatkins/state-ops
Add an implicit class for StateOps
2018-09-16 02:40:12 -04:00
Eugene Yokota 4ff4f6e45e Update header 2018-09-14 04:53:36 -04:00
Ethan Atkins 88aa60ea49 Add an implicit class for StateOps
The State file in intellij was littered with red squiggly lines wherever
the extension methods of State called a different extension method of
State.  These went away when I switched to an implicit class, which is
the preferred way of adding extension methods since scala 2.10. As a
bonus, I was able to switch the implicit class to be a value class, so
it should not actually make a new object in most use cases.

I had to re-implement the stateOps method to delegate to the implicit
class for binary compatibility.
2018-08-28 15:45:54 -07:00
eugene yokota cf31a11b69
Merge branch '1.x' into help-sbt-new 2018-06-27 22:15:02 -04:00
eugene yokota 773d35dadd
Merge pull request #4231 from steinybot/fix/3432
Add warning for unknown configurations
2018-06-27 20:59:43 -04:00
Jason Pickens c9aa0c5285 Add warning for unknown project configurations. 2018-06-27 18:25:10 +12:00
Eugene Yokota f3038167a5 Fork server if it's not running
Fixes https://github.com/sbt/sbt/issues/3508

This forks an instance of sbt in the background when it's not running already.

```
$ time sbt -client compile
Getting org.scala-sbt sbt 1.2.0-SNAPSHOT  (this may take some time)...
:: retrieving :: org.scala-sbt#boot-app
	confs: [default]
	79 artifacts copied, 0 already retrieved (28214kB/130ms)
[info] entering *experimental* thin client - BEEP WHIRR
[info] server was not detected. starting an instance
[info] waiting for the server...
[info] waiting for the server...
[info] server found
> compile
[success] completed
sbt -client compile  9.25s user 2.39s system 33% cpu 34.893 total
$ time sbt -client compile
[info] entering *experimental* thin client - BEEP WHIRR
> compile
[success] completed
sbt -client compile  3.55s user 1.68s system 107% cpu 4.889 total
```
2018-06-25 22:37:22 -04:00
Eugene Yokota 3eb76125e0 implement batch mode 2018-06-25 22:26:13 -04:00
Eugene Yokota 5c202a564b skip debug log 2018-06-25 22:26:13 -04:00
Eugene Yokota 1a1f530985 implement -client option 2018-06-25 22:26:13 -04:00
Eugene Yokota 18c6b04b47 Fix thin client to use LSP
Fixes https://github.com/sbt/sbt/issues/2798
2018-06-25 22:26:13 -04:00
Eugene Yokota 932f911483 addPluginSbtFile command
Fixes https://github.com/sbt/sbt/issues/1502

This adds `--addPluginSbtFile=<file>` command, which adds the given .sbt file to the plugin build.
Using this mechanism editors or IDEs can start a build with required plugin.

```
$ cat /tmp/extra.sbt
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.7")

$ sbt --addPluginSbtFile=/tmp/extra.sbt
...
sbt:helloworld> plugins
In file:/xxxx/hellotest/
  ...
  sbtassembly.AssemblyPlugin: enabled in root
```
2018-06-18 01:50:36 -04:00
Eugene Yokota 86427c7ce7 Merge branch '1.1.x' into wip/merge-1.1.x 2018-06-12 23:33:47 -04:00
Holden Karau 6214408783 Add support for --error. 2018-05-15 05:31:58 -07:00
Ethan Atkins d3ac5274b3 Revert back to non-blocking watch termination condition
A thread blocking on System.in.read() cannot be interrupted, so check
System.in.available before blocking. This is how it used to work. It
requires https://github.com/sbt/io/pull/149 or else a cpu will be
pegged by the EventMonitor user input thread spinning on
System.in.available.
2018-05-08 13:26:58 -07:00
Eugene Yokota d8fe09f007 Adjust to upstream change 2018-05-05 05:02:53 -04:00
Eugene Yokota 28e90ea09b Merge branch '1.1.x' into wip/merge-1.1.x 2018-04-29 14:31:30 -04:00
Dale Wijnand 3a4bc8dc0b
Dropped deprecated "compat" commands & strings
Fixes #4089
2018-04-26 14:04:05 +01:00
Eugene Yokota d90f273420 Remove deprecated commands -, --, and ---
86ae3c8c59 deprecated -, --, and ---.
This removes the deprecated commands.
2018-04-26 05:02:21 -04:00
Dale Wijnand 8f4b8abb7b
Run scalafmt & test:scalafmt 2018-04-24 16:12:10 +01:00
Ethan Atkins 754385125a Use new EventMonitor in executeContinuously
In https://github.com/sbt/io/pull/142, I add a new api for watching for
source file events. This commit updates sbt to use the new EventMonitor
based api. The EventMonitor has an anti-entropy parameter, so that
multiple events on the same file in a short window of time do not
trigger a build. I add a key to tune it.

The implementation of executeContinuously is pretty similar. The main
changes are that shouldTerminate now blocks (EventMonitor spins up a
thread to check the termination condition) and that the
EventMonitor.watch method only returns a Boolean. This is because
the event monitor contains mutable state. It does, however, have a
state() method that returns an immutable snapshot of the state.
2018-04-23 10:02:29 -07:00
Eugene Yokota 707bf08c4e Add new closewatch mode 2018-04-05 20:29:26 -04:00
Ethan Atkins fff32db7ce Use MacOSXWatchService instead of PollingWatchService
This watch service should be more responsive and significantly reduce
the disk overhead of the polling based service for large repos.
2018-03-28 17:11:30 -07:00
Dale Wijnand 289077a405
Re-introduce Command.process
This was an unnecessary removal in
e83564a6b7.
2018-03-28 16:37:07 +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 00ce32f102
Cleanup CommandChannel 2018-03-20 09:17:55 +00:00
Dale Wijnand 9c0ac90ee9
Make Watched use State#handleError 2018-03-19 15:21:15 +00:00
eugene yokota 4efce7e877
Merge pull request #3991 from dwijnand/ExecStatusEvent-exitCode
Add an optional exitCode to ExecStatusEvent so clients can use it
2018-03-16 00:27:17 +09:00
Eugene Yokota 0433440c59 move ServerHandler to internal per review 2018-03-13 23:42:40 +09:00
Eugene Yokota f13465246c include the full body in debug message 2018-03-13 23:02:45 +09:00
Eugene Yokota cd9f0d2711 make sbt server extensible
Fixes #3890

Here's an example:

```scala
    Global / serverHandlers += ServerHandler({ callback =>
      import callback._
      import sjsonnew.BasicJsonProtocol._
      import sbt.internal.protocol.JsonRpcRequestMessage
      ServerIntent(
        {
          case r: JsonRpcRequestMessage if r.method == "lunar/helo" =>
            jsonRpcNotify("lunar/oleh", "")
            ()
        },
        PartialFunction.empty
      )
```
2018-03-13 23:02:45 +09:00
Dale Wijnand dd4de14593
Upgrade to contraband 0.4.0 2018-03-12 15:39:07 +00:00
Ethan Atkins 5df1d8e23f Cache watch service
I noticed that my custom WatchService was never cleaned up by sbt and
realized that after every build we were making a new WatchService. At
the same time, we were reusing the WatchState from the previous run,
which was using the original WatchService. This was particularly
problematic because it prevented us from registering any paths with the
new watch service. This may have prevented some of the file updates
from being seen by the watch service. Moreover, because we lost the
reference to the original WatchService, there was no way to clean it up,
which was a resource leak.

May be related to #3775, #3695
2018-03-09 06:11:52 -05:00
Dale Wijnand ed5a8c118b
Upgrade to contraband 0.3.3 2018-03-08 12:49:38 +00:00
eugene yokota 92c95ce290
Merge pull request #3997 from eed3si9n/wip/test-status-thread-safety
Fix race condition in non-forked, parallel tests.
2018-03-07 16:18:55 -05:00
Dale Wijnand 7b11729f8c
Cleanup State#process 2018-03-06 11:59:26 +00:00
Dale Wijnand 2effe0845f
Cleanup IPC 2018-03-06 11:59:26 +00:00
Jason Zaugg 0bea7e9e18 Fix race condition in non-forked, parallel tests.
Non forked tests that are run in parallel groups can call into
a single instance of TestStatusReporter concurrently.

This seems to be limited to the startGroup/endGroup/testEvent
methods called in:

  a41727fb17/testing/src/main/scala/sbt/TestFramework.scala (L100-L124)

Which itself is called within:

  a41727fb17/testing/src/main/scala/sbt/TestFramework.scala (L203-L229)

Creating the `runnables` that are run in parallel (in builds so configured):

  a6eb1260c8/main-actions/src/main/scala/sbt/Tests.scala (L222-L230)

We believe this to be the cause of the hang witnessed in
the a suite of Scalacheck-framework tests in the Scala
build:

  https://github.com/scala/scala-jenkins-infra/issues/249

This commit uses a concurrent map to support concurrent
status updates.
2018-03-05 18:23:03 +10:00
Dale Wijnand 76e2f550ec
Merge branch '1.1.x' into merge-1.1.x-into-1.x
* 1.1.x:
  Update mimaPreviousArtifacts/sbt.version
  Introduce SBT_GLOBAL_SERVER_DIR env var to override too long paths
  Handle very long socket file paths on UNIX

Conflicts:
	project/build.properties
2018-02-14 14:38:07 +00:00
Dale Wijnand 4e038c91ce
Introduce SBT_GLOBAL_SERVER_DIR env var to override too long paths 2018-02-12 17:57:26 +00:00
Eugene Yokota 3db0e09b33 Merge branch '1.1.x' into wip/1.1.1
# Conflicts:
#	main/src/main/scala/sbt/internal/CommandExchange.scala
#	main/src/main/scala/sbt/internal/ConsoleProject.scala
#	notes/1.0.2/sample.md
#	notes/1.1.1/sample.md
#	notes/sample.md
#	sbt/src/test/scala/sbt/ServerSpec.scala
2018-02-09 23:55:23 -05:00
eugene yokota 54eb6c2d6b
Merge pull request #3929 from eed3si9n/wip/servertest2
Backport server testing as a unit test
2018-02-07 21:18:35 -05:00
Eugene Yokota a2347332ab Use ipcsocket 2018-02-07 17:46:23 -05:00
Steve Waldman 96b9429669 Rework false-defaulting 'suppressServer' to true-defaulting 'autoStartServer'. 2018-02-06 11:49:46 -08:00
Steve Waldman 0aa133d276 Implement 'suppressServer' setting, for builds and plugins that prefer to be conservative about exposure to other processes. 2018-02-05 23:11:42 -08:00
Eugene Yokota 50f3dd2e20 Use ipcsocket 2018-01-30 23:21:10 -05:00
Dale Wijnand 286758e2ba
Minor cleanups 2018-01-30 07:29:17 +00:00
Dale Wijnand 113656aed1
Remove compile warnings 2018-01-16 11:17:01 +00:00
Dale Wijnand d1071002be
Merge pull request #3790 from eatkins/cache-watch-service
Cache WatchService in continuous builds
2018-01-12 15:17:51 +00:00
Dale Wijnand a0b27d29b7
Merge pull request #3854 from sbt/1.1.x
1.1.x
2018-01-08 11:16:26 +00:00
Eugene Yokota 0a3900f53d Add Library interface
Fixes #3821

Initially I missed why #3821 was failing.

Looking at it again, the error message reads:

```
Caused by: java.lang.IllegalArgumentException: Interface (NGWin32NamedPipeLibrary) of library=kernel32 does not extend Library
        at com.sun.jna.Native.loadLibrary(Native.java:566)
        at sbt.internal.NGWin32NamedPipeLibrary.<clinit>(NGWin32NamedPipeLibrary.java:38)
        ... 7 more
```

Inside `Native.loadLibrary`, it requires the "library" interface to extend `com.sun.jna.Library`, which this adds.
2017-12-22 16:10:46 -05:00
Eugene Yokota 06ffb4f440 warn about multiple instance once
Fixes #3823

When you launch a second instance of sbt on a build, prior to this change it was displaying `java.io.IOException: sbt server is already running` on every command. This make it a bit less aggressive, and just display a warning once.

```
[warn] Is another instance of sbt is running on this build?
[warn] Running multiple instances is unsupported
```
2017-12-20 10:09:03 -05:00
eugene yokota 34d311f9ce
Merge pull request #3807 from dwijnand/remove-warnings
Remove warnings
2017-12-19 13:18:59 -05:00
eugene yokota de4af16434
Merge pull request #3818 from sbt/1.1.x
Merge 1.1.x to 1.x
2017-12-18 20:55:11 -05:00
Dale Wijnand 5f0852818b
Add project id to watching message
We redefine watchingMessage in project scope so we can use
thisProjectRef to make the watching message more precise.

Fixes #2038
2017-12-15 01:49:14 +00:00
Eugene Yokota 06b85919ba
Encode POSIX file path to URI using u3 (file:///)
Ref https://github.com/sbt/io/pull/96

Under RFC 8089, both u1 and u3 are legal, but many of the other platforms expect traditional u3.
This will increase the compatibility/usability of sbt server, for example to integrate with Vim.
2017-12-12 16:27:14 +00:00
Dale Wijnand d99147d18c
Remove all warnings from commandProj 2017-12-12 13:02:20 +00:00
Dale Wijnand 4a5ff4fc0d
Remove all warnings from completeProj 2017-12-12 13:02:19 +00:00
PanAeon 184390fed2
Merge branch '1.x' into help-sbt-new 2017-12-11 16:57:40 +00:00
Eugene Yokota 322f9b31cd Only the first session starts the server
Currently the server will try to start even if there are existing sbt sessions. This causes the second session to take over the server for Unix domain socket.

This adds a check before the server comes up and make sure that the socket is not taken.
2017-12-05 09:14:18 -05:00
Ethan Atkins ca7171ed17 Cache watch service
I noticed that my custom WatchService was never cleaned up by sbt and
realized that after every build we were making a new WatchService. At
the same time, we were reusing the WatchState from the previous run,
which was using the original WatchService. This was particularly
problematic because it prevented us from registering any paths with the
new watch service. This may have prevented some of the file updates
from being seen by the watch service. Moreover, because we lost the
reference to the original WatchService, there was no way to clean it up,
which was a resource leak.

May be related to #3775, #3695
2017-12-02 18:23:19 -08:00
Eugene Yokota 93b3391167 Fixes server log hardcoded to debug level
Fixes #3786

To configure the log level of the server, this introduces a new task key named `serverLog`. The idea is to set this using `Global / serverLog / logLevel`. It will also check the global log level, and if all else fails, fallback to Warn.

```
    lazy val level: Level.Value = (s get serverLogLevel) orElse (s get logLevel) match {
      case Some(x) => x
      case None    => Level.Warn
    }
```
2017-12-02 15:20:54 -05:00
Eugene Yokota c5d578815c catch IOException intead of SocketException
`NGUnixDomainSocket` throws `java.io.IOException` instead of `SocketException`, probably because `SocketException` does not expose the contructor with a `Throwable` parameter.
To allow clients to disconnect, we need to catch `IOException`.
2017-11-29 22:42:58 -05:00
Eugene Yokota ef61a1efa7 Read just the amount of bytes available 2017-11-27 21:37:37 -05:00
Eugene Yokota f785750fc4 IPC Unix domain socket for sbt server
In addition to TCP, this adds sbt server support for IPC (interprocess communication) using Unix domain socket and Windows named pipe.

The use of Unix domain socket has performance and security benefits.
2017-11-27 21:37:31 -05:00
Eugene Yokota 0c803214aa IPC Unix Domain Socket and Windows Named Pipe sockets
The Java socket implementation for IPC is lifted from facebook/nailgun.

af623fdded/
2017-11-27 21:36:25 -05:00
Saniya Tech b5e05e1fc1
Merge branch '1.x' into fix-3693 2017-11-04 09:52:35 -04:00
Miklos Martin 1f89e3dc02 move nameOption to the trait 2017-11-03 06:39:53 +01:00
Miklos Martin 951c78a4d7 better naming + value class 2017-11-03 06:39:53 +01:00
Miklos Martin 8dacb72f9d Fixes #3297 and #3531
Add commandName as an extension method in Command
2017-11-03 06:39:53 +01:00
Saniya Tech 8757a4c6ac Removes reference to version 0.14.0 from a warning message 2017-10-31 17:09:20 -04:00
Eugene Yokota 6ac4571197 Adds "reboot dev"
This adds a new option `dev` to the `reboot` command, which deletes the only the current sbt artifacts from the boot directory. `reboot dev` reads actively from `build.properties` instead of using the current state since `reboot` can restart into another sbt version.

In general, `reboot dev` is intended for the local development of sbt.

Fixes #3590
2017-10-25 03:19:10 -04:00
PanAeon 27a30a933a fix sbt help new does not explain how to use sbt new 2017-10-24 19:08:56 +01:00
Simon Schäfer ede94cb34c Fix unused pattern vals warnings in main-command project 2017-10-19 13:07:24 +02:00
Michael Stringer a3c34c6c0a
Add system property to revert to old polling fs watcher
This adds a sbt.watch.mode system property that if set to 'polling' will
use PollingWatchService instead of WatchServiceAdapter (nio).

On macOS this will default to 'polling' and on all others 'nio'.

This is a temporary workaround for users affected by #3527
2017-10-09 18:01:33 +01:00
Dale Wijnand a41727fb17
Add, configure & enforce file headers 2017-10-05 09:03:40 +01:00
Eugene Yokota 0c1c380f71 begins language server protocol
This is the first cut for the Language Server Protocol on top of server that is still work in progress.

With this change, sbt is able to invoke `compile` task on saving files in VS Code.
2017-10-02 04:01:13 -04:00
Eugene Yokota d5e24979bf Reference token file using URI and full file path
Node didn't seem to like read URI out of the box, and I am not sure if File -> URI -> File conversion is universally accepted.

Ref sbt/sbt#3088
2017-09-25 01:35:49 -04:00
Eugene Yokota 252e803de8 expand the token out to 128-bits 2017-09-22 01:30:27 -04:00
Eugene Yokota 348a077797 implement tokenfile authentication 2017-09-21 23:05:48 -04:00
Eugene Yokota 9d40404915 JSON port file
This implements JSON-based port file. Thoughout the lifetime of the sbt server there will be `cwd / "project" / "target" / "active.json"`, which contains `url` field.

Using this `url` the potential client, such as IDEs can find out which port number to hit.

Ref #3508
2017-09-17 19:19:56 -04:00
Eugene Yokota f21d190a65 `sbt.server.autostart` flag and startServer
Adds JVM flag `sbt.server.autostart` to enable/disable the automatic starting of sbt server with the sbt shell.

This also adds a new command `startServer` to manually start the server.
2017-09-16 03:24:30 -04:00
eugene yokota caf2fa2cb8 Merge pull request #3523 from guillaumebort/1.0.x
Sbt server could miss some messages
2017-09-15 23:31:13 -04:00
Răzvan Flavius Panda 0124a8ad0e Fix unused imports warnings 2017-09-15 16:35:08 +01:00
Guillaume Bort b355aa66e4 Sbt server could miss some messages
If the read buffer contains more that 2 messages, we need to consume them all before blocking on socket read again. For that we have to loop until the buffer does not contain anymore the message delimiter character.

Same problem in the client ServerConnection code.
2017-09-13 13:18:38 +02:00
Martin Duhem c1b86c7534
Address review comments 2017-08-18 15:51:53 +02:00
Dale Wijnand 805b76f3d4
Add back, re-configure & re-enable Scalafmt 2017-08-10 16:35:23 +01:00
Eugene Yokota a58b1ebce0 Keep ConsoleChannel open
Fixes #3282

For now, don't try to shutdown ConsoleChannel while the network is processing the command in the background.
2017-07-22 03:35:42 -04:00
Eugene Yokota 00a9dd14a4 Bump Contraband to latest 2017-07-17 01:05:30 -04:00
Martin Duhem 3fe068a4c1 Adapt to changes in ConsoleAppender 2017-07-15 17:15:42 +02:00
Eugene Yokota efa3b1d340
Bump to latest io, scalajson, sjsonnew, contraband, util, lm, zinc 2017-07-06 11:05:24 +01:00
Martin Duhem 0daca42c29 Adapt to use the new `WatchService`
This commit adapts `Watched` so that it supports the new `WatchService`
infrastructure introduced in sbt/io. The goal of this infrastructure is
to provide and API for and several implementations of services that
monitor changes to the file system.

The service to use to monitor the file system can be configured with the
key `watchService`.
2017-07-02 00:28:04 -04:00
Dale Wijnand e4be5f4a09 Remove the "hit [ENTER] to switch to interactive mode" feature
In sbt 0.13.15, in addition to notifying the user about the existence of
sbt's shell, a feature was added to allow the user to switch to sbt's
shell - a more pro-active approach to just displaying a message.

Unfortunately sbt is often unintentionally invoked in shell scripts in
"interactive mode" when no interaction is expected by, for exmaple,
invoking `sbt package` instead of `sbt package < /dev/null`. In that
case hitting [ENTER] would silently trigger sbt to run its shell,
easily wrecking the script. In addition to that I was unhappy with the
implementation as it created a tight coupling between sbt's command
processing abstraction to sbt's shell command.

If you want to stay in sbt's shell after running a task like `package`
then invoke sbt like so:

    sbt package shell

Fixes #3091
2017-05-26 21:42:41 -04:00
Dale Wijnand b54c0ff059 Notify users about shell only if compile is present
This is a change in strategy.

The motivation is the need to find a good balance between:

  + informing the uninformed that would benefit from this information, &
  + not spamming the already informed

Making it dependent on "compile" being present in remainingCommands will
probably make it trigger for, for example, Maven users who are used to
running "mvn compile" and always run "sbt compile", and who therefore
are unneccesarily suffering terribly slow compile speeds by starting up
the jvm and sbt every time.

Fixes #3091
Fixes #3097
2017-05-26 21:33:49 -04:00
Eugene Yokota da046791e0 Apply Scalafmt formatting 2017-04-21 04:48:31 -04:00
Eugene Yokota 86342d0bdd server is now called shell
server command is renamed to shell,
and the old shell command is called oldshell.
2017-04-14 16:35:54 -04:00
Eugene Yokota 0e8459ad66 Better error message if socket is taken
We need to communicate the error states in the thread, so I added a `Future[Unit]` called `ready`.

If something goes wrong during the startup, like if the port is already taken, this can be used to communicate back to the main thread, and display the error accordingly.
2017-04-13 15:49:21 -04:00
Dale Wijnand ec15837f43
Replace unnecessary uses of Command.make with Command.apply 2017-04-13 13:52:30 +01:00
Dale Wijnand 6c07972dd0
Cleanup Command/Help and usage 2017-04-13 13:52:30 +01:00
Dale Wijnand 308abcde9f Merge pull request #3082 from dwijnand/remove-most-deprecated
Remove most @deprecated
2017-04-13 10:32:10 +01:00
Dale Wijnand 881cb4246a Notify about shell less
+ Don't notify ScriptMain users by moving the logic to xMain
+ Only trigger shell if shell is a defined command
+ Use existing Shell/BootCommand strings instead of new ones
2017-04-12 03:24:38 -04:00
Dale Wijnand 3f590d8e13
Drop most remaining deprecations 2017-04-11 16:46:11 +01:00
Eugene Yokota 7ffae0f7df Fix patch error 2017-04-04 19:59:25 -04:00
Dale Wijnand 1a2bfc546b Notify & enable users to stay in the warm shell
Notify & enable users to stay in sbt's shell on the warm JVM by hitting
[ENTER] while sbt is running.

Looks like this; first I run 'sbt about', then I hit [ENTER]:

    $ sbt about
    [info] !!! Executing in batch mode !!! For better performance, hit [ENTER] to remain in the sbt shell

    [info] Loading global plugins from /Users/dnw/.dotfiles/.sbt/0.13/plugins
    [info] Loading project definition from /s/t/project
    [info] Set current project to t (in build file:/s/t/)
    [info] This is sbt 0.13.14-SNAPSHOT
    [info] The current project is {file:/s/t/}t 0.1.0-SNAPSHOT
    [info] The current project is built against Scala 2.12.1
    [info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, sbt.plugins.Giter8TemplatePlugin
    [info] sbt, sbt plugins, and build definitions are using Scala 2.10.6
    >
    >

Fixes #2987
2017-04-04 19:43:28 -04:00
Dale Wijnand c7be291946
Fix StateOps#fail != fail 2017-03-27 14:38:02 +01:00
Eugene Yokota b6d8b565de Codegen change 2017-03-23 14:30:51 -04:00
Eugene Yokota 180bdfd129 Bump underlying modules to latest 2017-03-23 12:41:24 -04:00
Dale Wijnand e67cd6948b
Fix a bunch but not all compile warnings 2017-03-03 01:33:44 +01:00
Dale Wijnand e83564a6b7
Move some server pieces from main-command to main 2017-01-20 17:07:25 +00:00
Josh Soref eefef9d686 spelling: publish 2017-01-20 08:21:56 +00:00
Josh Soref ae22cc2293 spelling: incoming 2017-01-20 08:17:56 +00:00
Josh Soref c81894e45b spelling: command 2017-01-20 08:10:32 +00:00
Josh Soref f66acb8c0e spelling: abstraction 2017-01-20 08:06:55 +00:00
Dale Wijnand c239b553b6
Fix logic in client 2017-01-17 11:49:00 +00:00
Eugene Yokota d91df1f189 Adjust to 1.0.x 2017-01-16 08:44:13 -05:00
Eugene Yokota 1b79cb85b6 Safer template resolver
Fixes #2761

With sbt 0.13.13-RC1 rediscovered that the dependency pulled in from
Giter8 was affecting the plugins. To avoid this, this change splits up
the template resolver implementation to another module called
sbt-giter8-resolver, and it will be downloaded using Ivy into
`~/.sbt/0.13/templates/`, and then launched reflectively using Java as
the interface.
2017-01-16 08:44:13 -05:00
Eugene Yokota 729119a15a Fix parser for new command 2017-01-16 08:43:23 -05:00
Eugene Yokota 73a427c0b8 Adds templateResolvers and `new` command
This adds `new` command, which helps create a new build definition. The
`new` command is extensible via a mechanism called the template
resolver,
which evaluates the arbitrary arguments passed to the command to find
and run a template.

As a reference implementation [Giter8][g8] is provided as follows:

    sbt new eed3si9n/hello.g8

This will run eed3si9n/hello.g8 using Giter8.

  [g8]: http://www.foundweekends.org/giter8/
2017-01-16 08:43:23 -05:00
Eugene Yokota 0365d7cb11 Uncomment publishEvent 2017-01-14 02:30:59 -05:00
Eugene Yokota 8c9dfda089 Split log output per channel
LogManager implementation is modified to use ManagedLogger, which can swap out backing Appenders without re-creating the log instance.

The State was also changed to track `currentCommand: Option[Exec]`. `Exec` knows the origin of the command invocation, and using that we can now send the network-originated events only to the network clients.

Combined together, this implements log splitting between the sbt clients (channels).
2017-01-13 03:00:02 -05:00
Eugene Yokota 66301dbaf1 Adjust from rebasing 2017-01-06 11:35:08 -05:00
Eugene Yokota a2df1a4b53 Formatting fix 2017-01-06 11:27:41 -05:00
Eugene Yokota a0dde10f8a Use NonFatal 2017-01-06 11:27:41 -05:00
Eugene Yokota 892e25d23f Introduce execId that gets sent back
Now the client can put an id on each exec.
This can then be tracked and/or be used to block the user input.
2017-01-06 11:27:41 -05:00
Eugene Yokota 1bf50e10c8 Use Exec in State 2017-01-06 11:27:41 -05:00
Eugene Yokota d96ef58605 Unifying towards using events 2017-01-06 11:27:06 -05:00
Eugene Yokota 46d8f952e4 Refactor to make NetworkChannel per client connection 2017-01-06 11:27:06 -05:00
Eugene Yokota d618f91c6d Replace var with AtomicReference 2017-01-06 11:27:06 -05:00
Eugene Yokota fa7253ece3 Start lightweight client
This is the beginning of a lightweight client, which talks to the
server over Contraband-generated JSON API. Given that the server is
started on port 5173:

```
$ cd /tmp/bogus
$ sbt client localhost:5173
> compile
StatusEvent(Processing, Vector(compile, server))
StatusEvent(Ready, Vector())
StatusEvent(Processing, Vector(, server))
StatusEvent(Ready, Vector())
```
2017-01-06 11:27:06 -05:00
Eugene Yokota 272e733b87 Update to Contraband 2017-01-06 11:27:06 -05:00
Dale Wijnand 7fcfec8b8e
-sbinary/+sjson-new, -datatype/+contraband & upgrades
* start to replace sbinary with sjson-new
* upgrade from sbt/datatype to sbt/contraband
* upgrade and migrate to new sbt modules APIs
2017-01-05 21:59:00 +00:00
Dale Wijnand 43821667bf
Upgrade scalariform version 2016-12-11 12:13:11 +00:00
Eugene Yokota 18233ace05 Using sbt-datatype + sjson-new for JSON serialization 2016-10-27 09:27:41 -04:00
Eugene Yokota e7456b5653 Use the new FullReader 2016-10-27 09:20:06 -04:00
Eugene Yokota a94107e673 Handle closed socket 2016-10-27 02:42:12 -04:00
Eugene Yokota fe1a24cf7c Adjust to 1.0.x 2016-10-27 02:42:12 -04:00
Eugene Yokota a89fcb37ca Exec and CommandExchange refactoring 2016-10-27 02:42:12 -04:00
Eugene Yokota 3359163636 Adds serverPort attribute key 2016-10-27 02:42:12 -04:00
Eugene Yokota ebf4715dd1 Refactor to CommandExchange and CommandChannel 2016-10-27 02:42:12 -04:00
Eugene Yokota 48d3b01e6b Move files around 2016-10-27 02:42:12 -04:00
Eugene Yokota 3381f59ae8 Implement ConsoleListener 2016-10-27 02:42:12 -04:00
Johan Andrén ff211d08f9 Server hooked in as a CommandListener 2016-10-27 02:42:12 -04:00
Eugene Yokota f9dd8b73b7 Refactor to abstract listening for command line 2016-10-27 02:42:12 -04:00
Eugene Yokota 649dc0ce3c This is where we can multiplex commands 2016-10-27 02:42:12 -04:00
Eugene Yokota 9529f0c304 Add `-error` etc for log levels with one hyphen 2016-09-15 02:23:37 -04:00
Eugene Yokota 06724d1c4b Rename early command to `early(command)`
Fixes #2734, Ref #1041
e93c4450a1 added a feature called early
command, which uses `--` as a prefix to denote some commands that runs
ahead of session loading. While the feature might be useful especially
for logging, `--` is too useful just for this purpose.
2016-09-15 01:45:50 -04: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 32760bed55 Remove some fatal exception catching 2016-07-07 18:21:25 +01:00
Dale Wijnand 387674a451 Remove some heads and tails 2016-07-07 18:21:25 +01:00
Dale Wijnand 12d2b5a63b Cleanup commandProj 2016-06-21 08:09:30 +01:00
Eugene Yokota ee272d780e Reorganize directory structure 2016-05-06 16:01:49 -04:00