Commit Graph

10242 Commits

Author SHA1 Message Date
Eugene Yokota 73b0c91dfc scala-xml 1.3.0 2020-06-27 01:14:35 -04:00
Ethan Atkins 6796f43ab1 Merge remote-tracking branch 'origin/develop' into wip-sbt-instant-startup 2020-06-26 21:51:58 -07:00
Ethan Atkins 3216848c77 Fix client argument parsing for commands containing `-`
When the user ran a command like `testOnly foo -- bar`, the client was
incorrectly treating the `--` as an sbt argument. The assumption is that
once an argument is found that does not start with a `-`, then
everything following that argument is part of the command arguments.
2020-06-26 20:59:18 -07:00
eugene yokota 638aa5b8e6
Merge pull request #5653 from eed3si9n/wip/bumpgiter8
Giter8 0.13.1
2020-06-26 19:44:41 -04:00
eugene yokota e7c3b675e9
Merge pull request #5645 from eatkins/watch-excludes
Filter all watch settings for unused key check
2020-06-26 17:20:12 -04:00
eugene yokota 836134d0aa
Merge pull request #5642 from eatkins/zinc-real-paths
Use real paths for zinc roots
2020-06-26 17:19:36 -04:00
Eugene Yokota 9437fcf2c0 Giter8 0.13.1 2020-06-26 17:09:33 -04:00
eugene yokota a7bb749db3
Merge pull request #5649 from adpi2/develop
Fix: Trim internal dependency configs in BSP
2020-06-26 14:18:49 -04:00
adpi2 15178b3ef7 trim internal dependency configs in BSP 2020-06-26 10:10:08 +02:00
Ethan Atkins aaee092c96 Revert "Use print + flush instead of println"
This reverts commit b0a859acb5.
2020-06-25 15:16:21 -07:00
Ethan Atkins ba0d97c9ac Use 'FastTrack' instead of 'Maintenance'
FastTrack may better convey the intent.
2020-06-25 15:12:41 -07:00
Ethan Atkins 5238c78dfd Rename Terminal member fields for clarity
Also provide additional source commentary.
2020-06-25 11:46:07 -07:00
Ethan Atkins 4eedaea49e Synchronize ServerConnection.sendString
Without synchronization, it is possible to interlace liens from multiple
messages which causes parsing to fail on the server side.
2020-06-25 10:38:08 -07:00
Ethan Atkins ddc4e850b5 Disable noisy jline log lines
JLine will spam the console with error messages if certain commands get
interrupted. This is very noticeable and annoying in tab completions.

We can stop doing work in background as well since we've silenced the
jline logging.
2020-06-25 10:37:56 -07:00
Ethan Atkins a2047a0b2c Refactor watch
The existing implementation of watch did not work with the thin client.
In sbt 1.3.0, watch was changed to be a blocking command that performed
manual task evaluation. This commit makes the implementation more
similar to < 1.3.0 where watch modifies the state and after running the
user specified command(s), it enters a blocking command. The new
blocking command is very similar to the shell command.

As part of this change, I also reworked some of the internals of watch
so that a number of threads are spawned for reading file and input
events. By using background threads that write to a single event queue,
we are able to block on the file events and terminal input stream rather
than polling. After this change, the cpu utilization as measured by ps
drops from roughly 2% of a cpu to 0.

To integrate with the network client, we introduce a new UITask that is
similar to the AskUserTask but instead of reading lines and adding execs
to the command queue, it reads characters and converts them into watch
commands that we also append to the command queue.

With this new implementation, the watch task that was added in 1.3.0 no
longer works. My guess is that no one was really using it. It wasn't
documented anywhere. The motivation for the task implementation was that
it could be called within another task which would let users define a
task that monitors for file changes before running. Since this had never
been advertised and is only of limited utility anyway, I think it's fine
to break it.

I also had to disable the input-parser and symlinks tests. I'm not 100%
sure why the symlinks test was failing. It would tend to work on my
machine but fail in CI. I gave up on debugging it. The input-parser test
also fails but would be a good candidate to be moved to the client test
in the serverTestProj. At any rate, it was testing a code path that was
only exercised if the user changed the watchInputStream method which is
highly unlikely to have been done in any user builds.

The WatchSpec had become a nuisance and wasn't really preventing from
any regressions so I removed it. The scripted tests are how we test
watch.
2020-06-25 10:05:59 -07:00
Ethan Atkins d5cbc43075 Add tab completion support to thin client
The sbtc client can provide a ux very similar to using the sbt shell
when combined with tab completions. In fact, since some shells have a
better tab completion engine than that provided by jilne2, the
experience can be even better. To make this work, we add another entry
point to the thin client that is capable of generating completions for
an input string. It queries sbt for the completions and prints the
result to stdout, where they are consumed by the shell and fed into its
completion engine.

In addition to providing tab completions, if there is no server running
or if the user is completing `runMain`, `testOnly` or `testQuick`, the
thin client will prompt the user to ask if they would like to start an
sbt server or if they would like to compile to generate the main class
or test names. Neither powershell nor zsh support forwarding input to
the tab completion script. Zsh will print output to stderr so we
opportunistically start the server or complete the test class names.
Powershell does not print completion output at all, so we do not start a
server or fill completions in that case*. For fish and bash, we prompt
the user that they can take these actions so that they can avoid the
expensive operation if desired.

* Powershell users can set the environment variable SBTC_AUTO_COMPLETE
if they want to automatically start a server of compile for run and test
names. No output will be displayed so there can be a long latency
between pressing <tab> and seeing completion results if this variable is
set.
2020-06-24 20:08:14 -07:00
Ethan Atkins ea823f1051 Add server idle timeout
This commit adds the ability for sbt to automatically shut itself down
if it has been idle for some duration of time. The motivation is that
if the user may not realize they have an sbt server running in the
background that is using resources. We don't want to be too aggressive
with the idle timeout because that can reduce the efficacy of the thin
client. A value of one week is chosen so that users can enjoy a long
weekend and when they return to their computer, they won't have to
restart sbt. If they haven't used the server in at least a week, it
seems prudent to just kill it.
2020-06-24 20:04:13 -07:00
Ethan Atkins f8e06def74 Add win32 named pipe security level option
The sbtipcsocket by default restricts win32 named pipes to only allow
connections from the same login session. This makes connecting to a
remote server not work over ssh. We relax the default slightly in sbt to
allow the owner of the pipe to connect over any logon shell. The user
could restore the old behavior with:
```
Global / windowsServerSecurityLevel := Win32SecurityLevel.LOGON_DACL
```
or, if YOLO
```
Global / windowsServerSecurityLevel := Win32SecurityLevel.NO_SECURITY
```
2020-06-24 20:04:13 -07:00
Ethan Atkins 65599f2f84 Add sbt client project
This project is used to create client executables. The implementation is
pure java but we can build graalvm native-images from the java main
class. There are two versions of the client. One of them uses the
ipcsocket jni implementation to connect to the sbt server while the
other uses jna. It is necessary to use jni for the graalvm native-image
tool to work. Otherwise the two approaches should be identical.
2020-06-24 20:04:12 -07:00
Ethan Atkins a7cb186924 Add --close-io-streams flag to sbt
When we start sbt with the thin client, we want to close the server io
streams after it loads so that the client exiting won't crash the
server. When we are running the server as part of the server tests, it
is nice to have the server output. By setting the --close-io-streams
flag when we launch the server in the client, we are able to achieve
both.
2020-06-24 20:03:44 -07:00
Ethan Atkins 18cb839c47 Wrap network commands for reporting
Running multi commands (input commands delimited by semi-colons) did not
work with the thin client. The commands would actually run on the
server, but the thin client would exit immediately without displaying
the output. The reason was that MainLoop would report the exec complete
when all it had done was split the original command into its constituent
parts and prepended them to the state command list. To work around this,
when we detect a network source command, we can remap its exec id to a
different id and only report the original exec id after the commands
complete. We also have to keep track of whether or not the command
succeeded or failed so that the reporting command reports the correct
result.

The way its implemented is with the the following steps:
1. set the terminal to the network terminal
2. stash the current onFailure so that we can properly report failures
3. add the new exec id to a map of the original exec id to the generated
   id
4. actually run the command
5. if the command succeeds, add the original exec id to a result map
6. pop the onFailure
7. restore the terminal to console
8. report the result -- if the original exec id is in the result map we
   report success. Otherwise we report failure.

There is also logic in NetworkChannel for finding the original exec id
if reporting one of the artificially generated exec ids because the
client will not be aware of that id.
2020-06-24 20:03:43 -07:00
Ethan Atkins 43e4fa85e3 Add ctrl+c support thin client
When the user presses ctrl+c, we want to cancel any running tasks that
were initiated by that client. This is a bit tricky because we may not
be sure what is running if the client is in interactive mode. To work
around this, we send a cancellation request with the special id
__CancelAll. When the NetworkChannel receives this request, it cancels
the active task if was initiated by the client that sent the
cancellation request. The result it returns to the client indicates if
there were any tasks to be cancelled. If there were and the client was
in interactive mode, we do not exit. Otherwise we exit.
2020-06-24 19:40:18 -07:00
Ethan Atkins d0842711e4 Rework NetworkClient
This commit integrates the NetworkClient with the server side rendered
ui. Rather than implementing its own shell method, it will now connect
to the server and register itself as a virtual terminal. If there are
command arguments, those will be sent to the server as execs. Otherwise
it will enter a shell mode where it just acts as a relay for io.

In batch mode, it will return the exit code of the last exec sent to the
server. If the server disconnects, the client will exit with an error code.
2020-06-24 19:40:17 -07:00
Ethan Atkins ab362397ba Add remote cancellation support
This commit makes it possible for a remote client to cancel a running
task initiated by a different client by typing `cancel` into the shell.
It can be useful if the remote client has run something blocking like
console.

The console task can't safely be interrupted, so instead we write some
newlines filed by ctrl+d to exit the console.
2020-06-24 19:40:17 -07:00
Ethan Atkins ba345dd797 Add multi-client ui to server
This commit makes it possible for the sbt server to render the same ui
to multiple clients. The network client ui should look nearly identical
to the console ui except for the log messages about the experimental
client.

The way that it works is that it associates a ui thread with each
terminal. Whenever a command starts or completes, callbacks are invoked
on the various channels to update their ui state. For example, if there
are two clients and one of them runs compile, then the prompt is changed
from AskUser to Running for the terminal that initiated the command
while the other client remains in the AskUser state. Whenever the client
changes uses ui states, the existing thread is terminated if it is
running and a new thread is begun.

The UITask formalizes this process. It is based on the AskUser class
from older versions of sbt. In fact, there is an AskUserTask which is
very similar. It uses jline to read input from the terminal (which could
be a network terminal). When it gets a line, it submits it to the
CommandExchange and exits. Once the next command is run (which may or
may not be the command it submitted), the ui state will be reset.

The debug, info, warn and error commands should work with the multi
client ui. When run, they set the log level globally, not just for the
client that set the level.
2020-06-24 19:40:17 -07:00
Ethan Atkins f0815edc7a Improve network client server forking
In the previous version of the NetworkClient, there was no feedback
while the client was starting up. It was also possible that if the
server had exited abruptly and there was a dead active.json portfile
left over, that the client wouldn't be able to start the server.

This commit reworks things so that we launch the server with a java
process and we print out the stdout, stderr streams from the process. We
also forward the client's stdin in case the server couldn't be started
and the user wants to retry or print the stacktrace.
2020-06-24 19:40:17 -07:00
Ethan Atkins 734a1e7641 Add virtual terminal support for network clients
This commit adds support for remote clients to connect to the sbt server
and attach themselves as a virtual terminal. In order to make this work,
each connection must send a json rpc request to attach to the server.
When this is received, the server will periodically query the remote
client to get the terminal properties and capabilities that allow the
remote client to act as a jline terminal proxy. There is also support
for json messages with ids sbt/systemIn and sbt/systemOut that allow io
to be relayed from the remote terminal to the sbt server and back.

Certain commands such as `exit` should be evaluated immediately. To make
this work, we add the concept of a MaintenanceTask. The CommandExchange
has a background thread that reads MaintenanceTasks and evaluates them
on demand. This allows maintenance tasks to be evaluated even when sbt
is evaluating an exec. If it weren't done this way, when the user typed
exit while a different remote connection was running a command, they
wouldn't be able to exit until the command completed.

The ServerIntents in ServerHandler did not handle
JsonRpcResponseMessage because prior to this commit, sbt clients were
primarily making requests to the server. But now the server sends
requests to the client for the terminal properties and terminal
capabilities so it was necessary to add an onResponse handler to
ServerIntent.

I had to move the network channel publishBytes method to run on a
background thread because there were scenarios in which the client
socket would get blocked because the server was trying to write on the
same thread that the read the bytes from the client.

To make the console command work, it is necessary to hijack the
classloader for JLine. In MetaBuildLoader, we put a custom forked JLine
that has a setter for the TerminalFactory singleton. This allows us to
change the terminal that is used by JLine in ConsoleReader. Without this
hack, the scala console would not work for remote clients.
2020-06-24 19:38:42 -07:00
Ethan Atkins e77906445d Refactor network client
Neither The ConsoleAppender class nor the jni based ClientSocket can be
used in a graalvm native image. This commit reworks the NetworkClient so
that we can avoid those limitations. It also adds some additional
command line argument parsing and changes the value of the run method to
return Int rather than Unit for exit code support.
2020-06-24 19:22:57 -07:00
Ethan Atkins 1b03c9b1a9 Make Terminal a trait to support multiple clients
In order to support a multi-client sbt server ux, we need to factor
`Terminal` out into a class instead of a singleton. Each terminal provides
and outputstream and inputstream. In all of the places where we were
previously relying on the `Terminal` singleton we need to update the
code to use `Terminal.get`, which will redirect io to the terminal whose
command is currently running.

This commit does not implement the server side ui for network clients.
It is just preparatory work for the multi-client ui.

The Terminal implementations have thread safe access to the output
stream. For this reason, I had to remove the sychronization on the
ConsoleOut lockObject. There were code paths that led to deadlock when
synchronizing on the lockObject.
2020-06-24 19:22:57 -07:00
Ethan Atkins 120e6eb63d Route TaskProgress through CommandExchange
Rather than going through the console appender logging to make
TaskProgress work, we can instead use the CommandExchange. This will be
useful in future commits where there are multiple terminals that all
need to receive progress. By organizing the TaskProgress this way, we
can store a separate progress state for each terminal and update the
progress for all of the active terminals. We also can set the current
running command in command exchange which will be useful in future
commits to show what command is currently running.

This commit also reworks TaskProgress to always kill its thread when
there are no active tasks. It will start a new thread as soon as there
is another active task.
2020-06-24 19:19:06 -07:00
Ethan Atkins 034b9690c1 Add additional ansi-escape removal functions
This commit adds a number of functions for stripping ansi escape
characters and/or finding the position of the cursor in a line that may
contain colors and moves. The motivation for EscHelpers.cursorPosition
is that when printing progress lines, we need to know the visual
dimensions of the last line printed to the prompt. The
EscHelpers.stripColorsAndMoves can be used to remove all ansi escape
sequences. Finally EscHelpers.stripMoves leaves colors but strips out
all other escape sequences. This is so we can reprint the terminal
prompt during supershell. If we didn't strip out the escape sequences,
we could inadvertently blow away everything below the cursor in cases
where we actually want the lines below the cursor to persist.
2020-06-24 19:19:06 -07:00
Ethan Atkins 13138457cf Don't spam the portfile during TestServer startup
Prior to this change, the server test was repeatedly performing io on
the portfile while the server was starting up. This adds a modest sleep
so that the test is just as responsive without doing needless io.
2020-06-24 19:19:06 -07:00
Ethan Atkins cebf740931 Make TestServer recursive functions tail recursive 2020-06-24 19:19:06 -07:00
Ethan Atkins 26b7c5204c Close previous client socket
This looked like a resource leak. I'm not 100% sure this matters.
2020-06-24 19:19:06 -07:00
Ethan Atkins fcfe4333fe Consolidate and optimize input stream json reading
We had similar code for reading json frames from an input stream in
NetworkChannel and ServerConnection. I reworked and consolidated this
logic into a shared method in ReadJsonFromInputStream.

This commit also removes the ObjectMessage reporting methods that
weren't doing anything.
2020-06-24 19:19:06 -07:00
Ethan Atkins b0a859acb5 Use print + flush instead of println
With println, it is possible for lines to get interleaved because
another thread may call flush before the println appends a newline.
2020-06-24 19:19:06 -07:00
Ethan Atkins a94d6dd77c Rename JLineCompletion parameter name
It was confusing that reader was used as a parameter name in two places.
2020-06-24 19:19:06 -07:00
Ethan Atkins 41d66abb02 Add support for JNI implementation of ClientSocket
The JNI implementation is needed in order for a graalvm native-image to
be build of the NetworkClient.
2020-06-24 19:19:06 -07:00
Ethan Atkins af5afef271 Add option to skip collectAnalysis on network init
The collectAnalysis task an be a bit slow and delays client connections
from running commands. This commit adds an option to skip the analysis
if it isn't needed. The default behavior is left as it was.
2020-06-24 19:19:06 -07:00
Ethan Atkins e53c8f6f01 Add Util.ignoreResult
This adds a convenience macro for appending `()` to an expression if it
is the last expression in a block that is supposed to return Unit.
2020-06-24 19:19:06 -07:00
Ethan Atkins 52d19d8f0c Refactor Signal for graalvm
The graalvm issues warnings about the objects defined in
Signal.register, so I made them top level private classes instead.
2020-06-24 19:19:06 -07:00
Ethan Atkins 7b05ef5918 Disable supershell in server tests
Also make test build files trigger in watch.
2020-06-24 19:19:06 -07:00
Ethan Atkins fe397351df Remove dead external hooks code
These settings were only used by the external hooks implementation that
was removed.
2020-06-24 19:19:06 -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 cc80b6c6ed Bump javafmt plugin version 2020-06-24 11:24:15 -07:00
Ethan Atkins e878660ef3 Update appveyor.yml
Appveyor supports uploading build artifacts that can be downloaded after
the build completes. This can be used to build and distribute graalvm
native images for mac, linux and windows since appveyor supports all
three of these platforms.  Appveyor allows custom builds based on the
git branch. Since building the graalvm native images is slow, the new
config will only build the native image when a branch called
`build-graal` is pushed. Otherwise it will run the normal scripted tests
that it has always run.
2020-06-24 11:24:15 -07:00
eugene yokota 778264a319
Merge pull request #5618 from adpi2/topic/metals-support
Add suggestion about semanticdb when Metals connect to sbt
2020-06-24 14:19:04 -04:00
Ethan Atkins 3c51f01872 Dealias baseDirectory in AppConfiguration
In Load.scala and Defaults.scala, the AppConfiguration.baseDirectory is
dealiased when it is a symlink. This commit dealiases the
AppConfiguration.baseDirectory if it is a symlink so that sbt
`appConfiguration.value.baseDirectory` should be the same as
`baseDirectory.value`.
2020-06-23 16:48:14 -07:00
Ethan Atkins 33d5bce75a Filter all watch settings for unused key check
Rather than enumerate all of the watch keys that may appear unused
though they can be used by the `~` command, rework lintUnused to take a
function `String => Boolean` instead of `Set[String] => Boolean`.
2020-06-23 16:01:08 -07:00
Ethan Atkins 95221ed837 Remove dead external hooks code
These settings were only used by the external hooks implementation that
was removed.
2020-06-23 15:06:53 -07:00