Commit Graph

242 Commits

Author SHA1 Message Date
eugene yokota 48f086059f
Merge pull request #5719 from eatkins/jline3-completions
Set complete flag in completions
2020-08-04 22:18:51 -04:00
Ethan Atkins 775cdd598a Catch IOExceptions in consoleLog
A ClosedChannelException was thrown here during CI.
2020-08-04 11:53:20 -07:00
Ethan Atkins b656d599e1 Allow sbt to force flush of remote output
In eb688c9ecd, we started buffering output
to the remote client to reduce flickering. This was causing problems
with the output for the thin client in batch mode. With the delay, it
was possible for the client to exit before all of its output had been
displayed.

Bonus: only display aggregation error message if terminal has success
enabled (the thin client displays its own timing message so the message
in aggregation ended up being a duplicate).
2020-08-04 10:44:43 -07:00
Ethan Atkins d68e2a6361 Make progress lines blink less
The more we call flush, the more likely progress status is to blink. To
reduce the amount of calls to flush, we can instead batch all of the
bytes that are going to be written and wriite them all at once. This
change made progress noticeably less blinky in the zinc project running
the latest sbt snapshot (which frankly was almost siezure inducing when
running publishLocal)
2020-07-22 14:55:25 -07:00
Ethan Atkins 7b39118214
Merge branch 'develop' into client-system-err 2020-07-22 09:16:10 -07:00
Ethan Atkins 9b332379dd Clear prompt on log messages
Printing a new line was not great ux. You might see something like:

[info] set current project to project (in build file:project)
sbt:project>
[info] new client connected: network-1
sbt:project>

instead of initially

[info] set current project to project (in build file:project)
sbt:project>

and then after the client connects:
[info] set current project to project (in build file:project)
[info] new client connected: network-1
sbt:project>
2020-07-21 13:27:44 -07:00
Ethan Atkins 12112741cb Revert "Unprompt channels during project load"
This reverts commit b1dcf031a5.

I found that b1dcf031a5 had some
unintended consequences that seemed to mess up the prompt state. The
real problem that it was trying to address was that the prompt was being
interleaved with log messages in some scenarios. There was a different
way to fix that in ProgressState that was both simpler and more
reliable.
2020-07-21 13:27:44 -07:00
Ethan Atkins e82c3405b9 Support System.err in thin client
I noticed that when reloading the build, that certain errors are logged
by sbt to System.err. These were not shown to a thin client because we
weren't forwarding System.err. This change remedies that.

System.err is handled more simply than System.out. We do not put
System.err through the progress state because generally System.err is
tends to be unbuffered. I had hesitated to add System.err to the
Terminal interface at all to give users an escape hatch but I couldn't
get project loading to work well with the thin client without it.
2020-07-21 13:27:32 -07:00
Ethan Atkins a19ec581c0 Use jline2 for raw mode
Using the JLine3 implementation of raw mode breaks the scala console for
the console channel.
2020-07-19 12:51:19 -07:00
Ethan Atkins 25e83d8fec Add Terminal.withRawOutput api
In the scala console, it's essential that we not process the bytes that
are written to the terminal by jline.
2020-07-10 13:37:54 -07:00
Ethan Atkins e1c9ed5a55 Buffer terminal lines
It is useful to store a buffer of the lines written to each terminal. We
can use those lines to replay the terminal log lines to a different
client. This is particularly nice when a remote client connects to sbt
while it's booting. We can show the remote client all the lines
displayed by the console prior to the client connecting.
2020-07-10 13:37:54 -07:00
Ethan Atkins 2ecf5967ee Upgrade LineReader to JLine3
This commit upgrades sbt to using jline3. The advantage to jline3 is
that it has a significantly better tab completion engine that is more
similar to what you get from zsh or fish.

The diff is bigger than I'd hoped because there are a number of
behaviors that are different in jline3 vs jline2 in how the library
consumes input streams and implements various features. I also was
unable to remove jline2 because we need it for older versions of the
scala console to work correctly with the thin client. As a result, the
changes are largely additive.

A good amount of this commit was in adding more protocol so that the
remote client can forward its jline3 terminal information to the server.

There were a number of minor changes that I made that either fixed
outstanding ui bugs from #5620 or regressions due to differences between
jline3 and jline2.

The number one thing that caused problems is that the jline3 LineReader
insists on using a NonBlockingInputStream. The implementation ofo
NonBlockingInputStream seems buggy. Moreover, sbt internally uses a
non blocking input stream for system in so jline is adding non blocking
to an already non blocking stream, which is frustrating.

A long term solution might be to consider insourcing LineReader.java
from jline3 and just adapting it to use an sbt terminal rather than
fighting with the jline3 api. This would also have the advantage of not
conflicting with other versions of jline3. Even if we don't, we may want to
shade jline3 if that is possible.
2020-07-10 13:37:53 -07:00
Ethan Atkins ed4d40d3e2 Move ProgressState into its own file
This didn't really belong in ConsoleAppender.scala anymore.
2020-07-10 13:36:32 -07:00
Ethan Atkins b6354656b1 Fix copied scaladoc 2020-07-10 13:36:01 -07:00
Ethan Atkins dea7bdfa89 Don't start an ask user thread for dead console
If there is no system console available, then there is no point in
making an ask user thread. An ask user thread can only be created when
the terminal prompt is in the Prompt.Running or Prompt.Loading state.
The console channel will now set itself to be in the Prompt.NoPrompt
state if it detects that there is no System.console available.

The motivation for this change is that jline was printing a lot of extra
text during scripted and server tests. Whenever a jline3 linereader is
closed, it prints a newline so the logs were filled with unnecessary
newlines.
2020-07-10 13:35:12 -07:00
Ethan Atkins b1dcf031a5 Unprompt channels during project load
In the situation where sbt was started in server mode and a client is
running a `~` command and a project reload is triggered by a change to
a build source, the console terminal looks like

sbt:foo>
[info] received remote command: ~compile
sbt:foo>
[info] welcome to sbt 1.4.0-SNAPSHOT (Azul Systems, Inc. Java 1.8.0_252)
sbt:foo>
[info] loading global plugins from ~/.sbt/1.0/plugins
sbt:foo>
[info] loading settings for project foo-build from metals.sbt ...
sbt:foo>
[info] loading project definition from
~/foo/project
sbt:foo>
[info] loading settings for project root from build.sbt ...
sbt:foo>
[info] loading settings for project macros from build.sbt ...
sbt:foo>
[info] loading settings for project main from build.sbt ...
sbt:foo>
[info] set current project to foo (in build file:~/foo)
sbt:foo>

This change fixes that by unprompting all channels during project
loading and reprompting them when it completes.
2020-07-09 16:54:29 -07:00
Ethan Atkins 6ff4406aa6 Restore println in ConsoleAppender
In a few places, I used this pattern in an attempt to debug some ui
issues. It is incorrect because it doesn't use System.lineSeparator
and is also pointless.
2020-07-01 11:41:04 -07:00
Ethan Atkins b6b2c3096d Only read stdin bytes on demand to fix reboot
When running reboot at the console, the first character that the user
enters after the reboot has completed is lost. This is because it isn't
possible to interrupt System.in and we have a thread that is blocking on
reads to System.in in WriteableInputStream. That thread cannot be
shutdown during normal sbt shutdown while it is reading. When sbt next
starts up (in the same jvm), the previous thread gets the byte but has
nowhere to write it so the byte is lost. This commit fixes that behavior
by ensuring that we only poll from System.in when there is actually a
downstream consumer.

The behavior of reboot is still a little wonky if the user issues a
reboot from a network client and then tries to input commands at the
console. In that case, sbt will have been polling System.in in the ask
user thread prior to the reboot and the ask user thread will be
uninterruptible for the reason described above so the first byte will
again by swallowed by the previous sbt instance. This use case is
sufficiently pathological that it doesn't feel worth the effort to fix.
As annoying as it is, it doesn't break the sbt session. The user will
either submit an invalid command with the missing leading character or
notice the character is missing, possibly think they missed the key,
type backspace a few times and re-type the command.
2020-06-29 16:41:33 -07:00
Ethan Atkins eb66906dad Reset jline on exit
The console input did not work correctly after a reboot because the
console was still reading from System.in.
2020-06-29 16:41:33 -07:00
Ethan Atkins 261084bbb2 Avoid leaking sbt processes
On windows, it is sometimes possible to leak an sbt process if two
processes are started simultaneously by a remote client at the same
time. When this happens, the second process is unable to create a
server because of the first process and it also has no io streams
because the the client detaches its streams. We can detect this
in the shell command and prevent the process from persisting as a
zombie.
2020-06-29 16:41:33 -07:00
Ethan Atkins 267918958d Prevent simultaneous server booting
One issue with the remote client approach is that it is possible for
multiple clients to start multiple servers concurrently. I encountered
this in testing where in one tmux pane I'd start an sbt server and in
another I might run sbtc before the server had finished loading. This
can actually cause java processes to leak because the second process is
unable to start a server but it doesn't necessarily die after the client
that spawned it exits. This commit prevents this scenario by creating a
server socket before it loads the build and closes once the build is
complete. The client can then receive output bytes and forward input to
the booting server.

The socket that is created during boot is always a local socket, either
a UnixDomainServerSocket or a Win32NamedPipeServerSocket. At the moment,
I don't see any reason to support TCP. This socket also has no impact at
all on the normal sbt server that is started up after the project has
loaded.

The socket is hardcoded to be located at the relative path
project/target/$SOCK_NAME or the named pipe $SOCK_NAME where SOCK_NAME
is a farm hash of the absolute path of the project base directory. There
is no portfile json since there is no need since we don't support TCP.

After the socket is created it listens for clients to whom it relays
input to the console's input stream and relays the process output back
to the client. See the javadoc in BootServerSocket.java for further
details.

The process for forking the server is also a bit more complicated after
this change because the client will read the process output and error
streams until the socket is created and thereafter will only read output
from the socket, not the process.
2020-06-29 16:41:33 -07:00
Ethan Atkins 21664be3f7 Set terminal properties during boot
Supershell does not work correctly when the sbt server is started by the
remote client on windows because it incorrectly calculates the terminal
dimensions. To work around this, we can pass in the dimensions from the
remote client as an environment variable. I tried to do this as a system
property but had all kinds of problems with windows stripping delimeters
from the command. It was much easier to get working with an environment
variable and should really only be set by the sbtc client anyway.
2020-06-29 09:45:10 -07:00
Ethan Atkins 611449583a Don't add newline
This was intended to prevent lines from being interlaced but I'm not
sure what if any effect it actually had.
2020-06-29 09:44:48 -07:00
Ethan Atkins a4e1c5aad5 Always print progress lines
It seemed like a good idea to avoid printing the progress lines if they
were the same as last time. Unfortunately there is a scenario where the
user has multiple clients open and while one of the clients is running a
command, the user presses enter in the inactive client. When this
happens the message that warns that the server is running a different
command gets overwritten. Always printing keeps the message visible.
2020-06-29 09:44:24 -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 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 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 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 ae978b9337 Remove TaskProgressFormats autogenerated file
This file somehow got stuck in the repo although it wasn't actually
used. In fact, it fails to compile at all because
sbt.internal.util.TaskProgress is defined in main, not util-logging. I
noticed this because metals wasn't working well because it was failing
to compile util-logging because of this file. I think the file was
checked in by accident in e28e052b5b.
2020-05-05 08:23:56 -07:00
Ethan Atkins 079cf2178c Add ClearScreenAfterCursor
This communicates intent better than clearScreen(0).
2020-05-01 13:02:48 -07:00
Ethan Atkins 58822cc3f5 Add virtual System.out for supershell
In order to make supershell work with println, this commit introduces a
virtual System.out to sbt. While sbt is running, we override the default
java.lang.System.out, java.lang.System.in, scala.Console.out and
scala.Console.in (unless the property `sbt.io.virtual` is set to
something other than true). When using virtual io, we buffer all of the
bytes that are written to System.out and Console.out until flush is
called. When flushing the output, we check if there are any progress
lines. If so, we interleave them with the new lines to print.

The flushing happens on a background thread so it should hopefully not
impede task progress.

This commit also adds logic for handling progress when the cursor is not
all the way to the left. We now track all of the bytes that have been
written since the last new line. Supershell will then calculate the
cursor position from those bytes* and move the cursor back to the
correct position. The motivation for this was to make the run command
work with supershell even when multiple main classes were specified.

* This might not be completely reliable if the string contains ansi
cursor movement characters.
2020-05-01 12:35:43 -07:00
Ethan Atkins 293e83ef9f Add Delete line to terminal prompt 2020-05-01 12:35:43 -07:00
Ethan Atkins 2e3a1e767d Don't poll System.in in ConsoleChannel
The ask user thread is a background thread so it's fine for it to block
on System.in. By blocking rather than polling, the cpu utilization of
sbt drops to 0 on idle. We have to explicitly handle <ctrl+d> if we
block though because the JLine console reader will return null both if
the input stream returns -1
2020-05-01 12:35:43 -07:00
Ethan Atkins 7902ec3b7d Add Terminal abstraction
This commit aims to centralize all of the terminal interactions
throughout sbt. It also seeks to hide the jline implementation details
and only expose the apis that sbt needs for interacting with the
terminal.

In general, we should be able to assume that the terminal is in
canonical (line buffered) mode with echo enabled. To switch to raw mode
or to enable/disable echo, there are apis: Terminal.withRawSystemIn and
Terminal.withEcho that take a thunk as parameter to ensure that the
terminal is reset back to the canonical mode afterwards.
2020-05-01 12:35:43 -07:00
Eugene Yokota 2396b449fe Contraband 0.4.6 2020-04-24 17:44:15 -04:00
Ethan Atkins aecdc44909 Update contraband sources
In 8bfae66b9d I upgraded contraband but
not all of the sources were regenerated because I didn't run clean
before recompiling.
2019-12-12 11:34:53 -08:00
Eugene Yokota 1ef83e9140 Fixes sbt new by restoring the terminal
Fixes https://github.com/sbt/sbt/issues/5063

This fixes "sbt new" on Ubuntu by restoring the terminal state after supershell querying for the terminal width.
2019-12-11 13:05:20 -05:00
Ethan Atkins ad59e71b1a Add util headers
None of the util files had headers.
2019-12-08 10:29:22 -08:00
Ethan Atkins 8bfae66b9d Update build.sbt to handle util projects
As part of re-integrating util into the sbt main project, I had to
update the build.sbt and a few dependencies (like the contraband plugin).
2019-12-08 10:28:31 -08:00
Diego E. Alonso-Blas 3657910063 ConsoleAppender: reuse/recycle StringBuilder storage.
A StringBuilder is a mutable data structure to create a String.
When the String is created, the new String does not share any
storage with the StringBuilder. Thus, we can keep a same
StringBuilder, and reuse its internal storage between different
iterations.
2019-10-22 23:30:09 +02:00
Ethan Atkins 43f25520a0 Don't include DeleteLine in progress length
I incorrectly included the DeleteLine in the progress line length and
this could cause certain progress lines to be incorrectly reported as
multi line when they actually fit on a single terminal line.
2019-10-07 09:30:41 -07:00
Ethan Atkins 9c2dd05b6a Avoid possible divide by zero
On the off chance that in some configurations the terminal width is set
to zero, avoid an exception by returning 0 for terminal lines. It is
likely that supershell will not work well if terminal width is zero, but
that's better than a potential crash (I think the crash would be in the
progress background thread, so I'm not sure how bad it would be, but
still its good to avoid).
2019-09-24 16:35:03 -07:00
Ethan Atkins 5cfab4c9a9 Cleanup implementation of progress report
It was a bit cleaner to consolidate `extra` and
(previousLines|info).length into prevLength and currentLength.
2019-09-24 16:33:42 -07:00
Ethan Atkins 7597cdb19b Take terminal width into account in supershell
Sometimes if the progress lines are wider than the terminal width,
the supershell blank zone can expand indefinitely because be do not move
the cursor far enough up to properly re-fill the blank zone.
2019-09-24 10:59:53 -07:00
eugene yokota 3f20cc1583
Merge pull request #221 from eatkins/lazy-success-event-tag
Load SuccessEventTag lazily
2019-09-18 22:14:28 -04:00
Ethan Atkins b3165b5c8c Load SuccessEventTag lazily
It takes about a second to load scala.reflect.runtime.universe. If we
lazy load here, we can load scala.relect.runtime.universe in the
background to speed up the sbt start up time. See
0ebb7a5662.
2019-09-18 15:33:42 -07:00
Ethan Atkins f20b275045 Fix supershell position bug
The previous implementation of supershell log line interlacing with
regular line interlacing relied on state in a global object. A somewhat
better approach is for each appender to hold a reference to a state
object. Every time tasks run, new appenders are created, so the state
should always reflect the current progress state.
2019-09-03 13:07:51 -07:00
Ethan Atkins 635316902d Allow supershell to work in no color mode
Supershell actually works quite well in no color mode. On the sbt side,
we still want to disable supershell automatically if the output is not a
terminal or no color is set, but this commit allows the user to force
supershell through -Dsbt.supershell or the useSuperShell setting even
when no color is set.
2019-09-02 11:10:42 -07:00
Ethan Atkins a5666e97b6 Manage progress padding
With this commit, I improved the padding management so that padding is
now added above the progress report. Whenever a line is logged at the
info or greater level, we can reduce the padding level by one since that
line has effectively filled in the padding.
2019-09-01 22:26:57 -07:00
Ethan Atkins d9fe5540f5 Interlace log lines with task progress
With the current supershell implementation, the progress display
flickers when there is heavy console logging during task evaluation.
This is because the console appender clears out the task progress and it
isn't restored until the next periodic super shell report (which
runs every 100ms by default). To remove the flickering, I reworked the
implementation to interlace the log lines with progress reports. In
order to ensure that the log lines remained contiguous, I had to apply
padding at the bottom of the supershell region whenever the new report
contained fewer lines than the old report. The report shifts down as new
log lines are appended. This isn't optimal, but I think removing
the flickering while preserving contiguous log lines is worth it.
2019-09-01 21:06:48 -07:00
Eugene Yokota 39fdf70c21 reimplement stacktrace suppression
Ref https://github.com/sbt/sbt/issues/4964
2019-08-20 12:35:13 -04:00
Eugene Yokota 7de45416fa Scala 2.13.0 2019-07-14 12:47:43 -04:00
Eugene Yokota e28e052b5b move super shell rendering to ConsoleAppender
Ref https://github.com/sbt/sbt/issues/4583
This moves the super shell rendering to ConsoleAppender with several improvements.

Instead of scrolling up, supershell is now changed to normal scrolling down, with more traditional cursor position. Before printing out the logs, last known progress reports are wiped out. In addition, there's now 5 lines of blank lines to accomodate for `println(...)` by tasks.
2019-04-21 03:59:19 -04:00
Eugene Yokota 98ec0075f4 apply formatting 2019-04-20 23:23:13 -04:00
Eugene Yokota d496a5dff5 Make showProgress configurable 2019-03-07 16:49:54 -05:00
Eugene Yokota 8215026bc3 Account for log line longer than the terminal width
widthHolder will hold on to the terminal width if supplied by sbt.
This avoids adding dependencies to JLine.
2019-03-07 16:42:10 -05:00
Eugene Yokota 8c85744d67 Use IO.Newline for stack trace 2019-03-07 16:39:47 -05:00
Eugene Yokota 3a6aa57747 log4j 2.11.2 2019-02-23 14:21:07 -05:00
Eugene Yokota 9f202397e4 expose ANSI control sequences 2018-11-16 23:03:25 -08:00
eugene yokota f16997d3a9
Merge pull request #184 from eed3si9n/wip/progress
Adds sbt.color flag and sbt.progress flag
2018-10-02 08:58:38 -04:00
Eugene Yokota efe04c1cde Cleaning up code 2018-10-02 08:51:17 -04:00
Eugene Yokota 9bb244314d implement sbt.progress
This implements a logger that grows upward, instead towards bottom.
2018-10-01 05:50:35 -04:00
Eugene Yokota 53c9b84858 add sbt.color flag
This implements a new sbt.color flag that takes always/auto/never/true/false value as a replacement of current sbt.log.format=true/false flag.

When neither flags are set, the default behavior is to enable color when the terminal supports ANSI and it detects an stdout console (as opposed to redirects).

Fixes https://github.com/sbt/sbt/issues/4284
2018-09-30 21:00:09 -04:00
Eugene Yokota ab674321dc Scala 2.12.7 2018-09-28 02:27:45 -04:00
Eugene Yokota e121d969c4 openjdk11 2018-09-22 00:55:00 -04:00
Eugene Yokota 9f876009c8 Fix 2.10 build
Fixes #179
2018-09-22 00:35:20 -04:00
Eugene Yokota cf0467609d -Xfatal-warnings 2018-09-19 22:46:38 -04:00
eugene yokota 965de89c64
Merge pull request #176 from sbt/1.2.x
Merge 1.2.x
2018-08-29 03:27:16 -04:00
Guillaume Martres 15522a0cbe Add Problem#rendered to customize how problems are shown
Dotty has its own logic for displaying problems with the proper file
path, position, and caret, but if we store this information in
Problem#message we end up with duplicated information in the output
since Zinc will prepend/append similar things (see
sbt.internal.inc.ProblemStringFormats). So far, we worked around this in
Dotty by using an empty position in the sbt bridge reporter, but this
means that crucial semantic information that could be used by a Build
Server Protocol implementation and other tools is lost. This commit
allows us to avoid by adding an optional `rendered` field to `Problem`:
when this field is set, its value controls what the user sees, otherwise
we fallback to the default behavior (the logic to do this will be added to
Zinc after this PR is merged and a new release of sbt-util is made).
2018-08-28 03:58:15 +09:00
Guillaume Martres e905b44a33 Follow-up to the fields added in #173
It turns out that there is more boilerplate to fill that I missed.

Also add deprecation notices.
2018-08-28 02:04:10 +09:00
Eugene Yokota 494f384c49 Formatting 2018-08-16 16:36:41 -04:00
Guillaume Martres 5e3a102606 xsbti.Position: Also add {start,end}{Line,Column}
Positions in the Language Server Protocol and Build Server Protocol are
line/column-based instead of offset-based, so this is more convenient.
Computing the line/column from the offset is possible but requires
reading the source file.
2018-08-14 02:04:55 +09:00
Guillaume Martres 78834527df xsbti.Position: add startOffset and endOffset
A position now has a start, an end, and a point (the existing `offset`),
just like it does in the Scala compiler. This information is especially
useful for displaying squiggly lines in an IDE.

This commit and the next one are required for https://github.com/sbt/zinc/pull/571
2018-08-14 02:04:43 +09:00
Dale Wijnand b1d02bee30
Make checkTypeTag lenient on "scala." type prefix 2018-08-02 07:52:13 +01:00
Eugene Yokota 434e294f28 Fixes the stacktrace trimming
Ref https://github.com/sbt/sbt/issues/4121
Ref https://github.com/sbt/sbt/pull/4232
2018-06-27 06:37:36 -04:00
Eugene Yokota 2b52c7dea0 Merge branch '1.1.x' into wip/merge-1.1.x 2018-06-14 01:11:49 -04:00
Eugene Yokota d2e59fa165 Scala 2.12.6 and other dependencies
sbt 1.1.4
Scala 2.12.6
ScalaCheck 1.14.0
ScalaTest 3.0.5
Contraband 0.4.0
2018-04-28 03:52:33 -04:00
Dale Wijnand 029952895b
Enforce invariant in StringTypeTag optimisation
Or, put differently, "Add a test for sbt/util#153".
2018-04-05 09:43:22 +01:00
Eugene Yokota 0c26b55882 Merge branch '1.1.x' into wip/merge-1.1.x 2018-03-26 22:46:04 -04:00
Jason Zaugg d9b130d519 Optimize ConsoleAppender.appendLog 2018-02-23 14:52:45 +10:00
Johannes Rudolph 0ebb7a5662
In initStringCodecs avoid reflect universe initialization
This showed up in profiling. It's known that TypeTags are expensive. Even
more so if the reflect universe is accessed during startup when the
class loading and JIT compiler are busy enough with other stuff.
2018-02-19 09:19:31 +01:00
Jason Zaugg b68071a488 Cache evidence params for hot method 2018-02-17 14:59:36 +10:00
Seth Tisue ba5b60300d fix typo in AbstractLogger.scala filename 2018-01-30 16:19:09 -08:00
Dale Wijnand 5ed25cbc56
Make EscHelpers.removeEscapeSequences handle partial escape sequences
Fixes #67
2017-12-21 17:09:30 +00:00
Eugene Yokota 1388f4e52c Merge branch '1.0.x' into wip/bump_scala 2017-11-28 23:05:33 -05:00
Leonard Ehrenfried 3cc56ad0ba
Add performance test 2017-11-08 21:36:11 +01:00
Leonard Ehrenfried 48f9cf3be6
Disable calculation of log4j caller location information 2017-11-08 21:36:11 +01:00
Dale Wijnand f4eadfc259 Merge pull request #129 from sbt/1.0.x
Merge 1.0.x
2017-10-02 10:23:02 +01:00
Eugene Yokota ddb6a13feb Provide JValue pass-through 2017-09-24 06:36:18 -04:00
eugene yokota cba6f83447 Merge pull request #122 from tom-walford/1.x
Cleaned up the deprecation messages to point to the correct classes.
2017-08-28 11:43:29 -04:00
tom.walford 83433d40e6 Cleaned up the deprecation messages to point to the correct classes. 2017-08-25 20:47:36 +01:00
Eugene Yokota b2be0f766a Attempt to solve the logger NPE issue
Fixes sbt/util#119

1. perform the string codec registration once.
2. add retries.
2017-08-25 12:01:34 -04:00
Eugene Yokota f74e3e66f1 Trying to reproduce sbt/util#119 2017-08-24 17:51:50 -04:00
Dale Wijnand d31b9c5093
Add, configure & enable Scalafmt 2017-08-10 11:44:24 +01:00
Eugene Yokota 930489eba3 Fix ConsoleAppender to show full stack trace
This is modification of crash log event logging that was added in sbt/util#85.

Instead of using the hardcoded 0 as the default value, this introduces `setTrace(..)` to `ConsoleAppender` like `BasicLogger`. Also the default value is set to `Int.MaxValue` that will display the full stack trace.

Fixes sbt/sbt#3343
2017-07-26 00:03:07 -04:00
Eugene Yokota 5183f7ef81 Use event logging to send success
Fixes sbt/sbt#3213
2017-07-25 16:16:21 -04:00
Eugene Yokota d796084ff4 Filter out color in CosoleAppender only
Fixes sbt/sbt#3348
Ref #101

The new logger, based on log4j separates the concern of the log producer (Logger) and the handlers that takes actions (Appender, e.g for displaying on Console). As such filtering of color should be performed only in the ConsoleAppender.
2017-07-24 23:54:25 -04:00
Eugene Yokota f6370063f4 Deprecate ansiCodesSupported from the logger 2017-07-24 23:20:05 -04:00
Olli Helenius a38d3d6c69 Delegate ansiCodesSupported to ConsoleAppender
Fixes sbt/sbt#3336.
2017-07-18 19:57:57 +03:00
Martin Duhem ddcc909195 Re-fix ConsoleAppender
It turns out that calling `print` on `ConsoleOut` doesn't flush the
output. Remove `writeLine` and let `write` directly use `println`.
2017-07-17 14:36:03 +02:00
Dale Wijnand 81277cbf62 Merge pull request #99 from dwijnand/prereset
Add a RESET at the front of the appendLog line
2017-07-17 10:55:39 +01:00
Dale Wijnand e744985b6b
Add a RESET at the front of the appendLog line 2017-07-17 10:42:39 +01:00
Martin Duhem 28ab7ac79d
Fix logger printing too many newlines 2017-07-17 10:05:58 +02:00
eugene yokota 72f823c80b Merge pull request #91 from Duhemm/wip/cleanup-consoleappender
Cleanup `ConsoleAppender`
2017-07-15 13:17:02 -04:00
Eugene Yokota 8b5210f84d Bump to latest Contraband 2017-07-15 10:36:03 -04:00
eugene yokota 0e6e3a0a2c Merge branch '1.0' into wip/cleanup-consoleappender 2017-07-14 13:07:29 -04:00
jvican 18a73db57d
Remove unnecessary F0, F1 and Maybe
`F0`, `F1` and `Maybe` have become useless since Java 8 introduced
`Supplier`, `Function` and `Optional` in the default Java 8 standard
library.

Therefore, they are not necessary anymore. This change is required to
change some Zinc's and sbt APIs. They are not widely used, so the
changes will be small.
2017-07-14 15:56:34 +02:00
Eugene Yokota 19b3e47972 Fix casting error during initialization
While running scripted, you see

```
ERROR StatusLogger Unable to create custom ContextSelector. Falling back to default.
 java.lang.ClassCastException: Cannot cast org.apache.logging.log4j.core.async.AsyncLoggerContextSelector to org.apache.logging.log4j.core.selector.ContextSelector
	at java.lang.Class.cast(Class.java:3369)
	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:201)
	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOfProperty(LoaderUtil.java:226)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:97)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:58)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at java.lang.Class.newInstance(Class.java:442)
	at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:94)
	at org.apache.logging.log4j.spi.ThreadContextMapFactory.createThreadContextMap(ThreadContextMapFactory.java:73)
	at org.apache.logging.log4j.ThreadContext.init(ThreadContext.java:223)
	at org.apache.logging.log4j.ThreadContext.<clinit>(ThreadContext.java:202)
	at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createDefaultInjector(ContextDataInjectorFactory.java:83)
	at org.apache.logging.log4j.core.impl.ContextDataInjectorFactory.createInjector(ContextDataInjectorFactory.java:67)
	at org.apache.logging.log4j.core.lookup.ContextMapLookup.<init>(ContextMapLookup.java:34)
	at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:117)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:125)
	at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:46)
	at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:650)
	at org.apache.logging.log4j.core.layout.PatternLayout.createDefaultLayout(PatternLayout.java:487)
	at sbt.internal.util.ConsoleAppender.<init>(ConsoleAppender.scala:245)
```

This aims to workaround the casting error during PatternLayout.createDefaultLayout()
that was originally used for ConsoleAppender.
The stacktrace shows it's having issue initializing default DefaultConfiguration.
Since we currently do not use Layout inside ConsoleAppender, the actual pattern is not relevant.
2017-07-14 07:39:05 -04:00
Martin Duhem f55a509fdd
Cleanup `ConsoleAppender` 2017-07-11 16:08:58 +02:00
Dale Wijnand 84180ec402
Move Showlines to logging to drop logging->collection dep 2017-07-03 12:04:45 +01:00
Eugene Yokota 2d777a85ee clean up warnings 2017-07-01 07:47:39 -04:00
Eugene Yokota 4e01a35917 Contraband update 2017-07-01 07:47:19 -04:00
Eugene Yokota 32d6bf38cf send TraceEvent on crash
Fixes sbt/sbt#3234
2017-06-28 02:18:03 -04:00
Eugene Yokota f2cc5ee775 convert log4j async LogEvent to an immutable one
This fixes the buffered log not showing up for tests.

Ref sbt/sbt#3198
2017-05-18 00:36:24 -04:00
Eugene Yokota feeb6291cd Add toString for ObjectEvent 2017-05-18 00:34:41 -04:00
Dale Wijnand d088d16d78
Drop (out-X) from the log output
Fixes sbt/sbt#3056
2017-04-04 14:15:01 +01:00
Eugene Yokota 1dab826ffd Store JValue into ObjectEvent 2017-04-03 03:22:33 -04:00
Eugene Yokota e21c78ebb0 Move JValue format here 2017-04-03 03:22:04 -04:00
Eugene Yokota 94a2e6cb12 Fix directory name 2017-04-03 03:21:14 -04:00
Eugene Yokota a12045ed42 some change for Scala 2.10 2017-02-15 18:52:04 -05:00
Eugene Yokota a9377ce4a6 Implements registerStringCodec
Uses TypeTag to recover the full name of type parameter, which is calculated by StringTypeTag. This is sent along in ObjectEvent.
On the other end, we can lookup typeclass instances using the tag key.
2017-02-08 05:35:49 -05:00
Eugene Yokota 6e2f77f852 ProblemFormats 2017-01-25 23:25:24 -05:00
Eugene Yokota 1320c96953 Rename log events 2017-01-25 23:15:31 -05:00
Eugene Yokota f76e3aa2bb use java.util.Optional in Position 2017-01-25 20:58:37 -05:00
Eugene Yokota 51f9f91038 Adds BufferedAppender 2017-01-24 21:13:38 -05:00
Eugene Yokota 56b51df66b Avoid default params 2017-01-24 20:29:35 -05:00
Eugene Yokota 08e9ce9526 Implement basic event logging 2017-01-23 16:38:14 -05:00
Eugene Yokota ca6a0be602 Handle ReusableObjectMessage
When log4j2 is not using async logging, it sends the ObjectMessage using ReusableObjectMessage.
2017-01-18 06:54:15 -05:00
Eugene Yokota 36eeb4578d Reimplement multi-logger using log4j2
This introduces ManagedLogger, which is a wrapper around Log4j2's async logging.
Log4j2 separates the notion of logger (the code that collects events) and appender (the code that acts on events). The old code is kept around intentionally to minimize breakage during transition.
2017-01-13 02:49:12 -05:00
Dale Wijnand 033adfe4ea
Remove deprecated methods 2016-11-15 17:14:10 +00:00
Dale Wijnand 121e7f5d9e Add -Ywarn-unused & -Ywarn-unused-import, & fix warnings 2016-06-19 11:42:31 +01:00
Eugene Yokota 299484cee6 Remove some warnings 2016-04-01 15:27:37 -04:00
Eugene Yokota 277cbd12ef Adds concrete classes 2015-12-17 00:57:24 -05:00
Eugene Yokota 70b49e9a4b Comment on SI-8450 2015-09-07 01:45:39 -04:00
Eugene Yokota dc0fd2d48b move sbt.internal.util.Logger into sbt.util 2015-09-07 01:31:17 -04:00
Eugene Yokota 0a2d39673c sbt.util.internal -> sbt.internal.util package 2015-09-05 00:51:58 -04:00
Eugene Yokota bc54e035ef Move util into sbt.util.internal package 2015-09-04 12:54:38 -04:00
Martin Duhem 6175d92338 Add recommended compiler flags, fix most of the warnings 2015-08-31 15:25:10 +02:00
Eugene Yokota 871b4f4eef move modules around. 2015-08-20 00:59:57 -04:00