2017-10-04 19:01:06 +02:00
|
|
|
/*
|
|
|
|
|
* sbt
|
2023-06-20 13:42:07 +02:00
|
|
|
* Copyright 2023, Scala center
|
|
|
|
|
* Copyright 2011 - 2022, Lightbend, Inc.
|
2017-10-04 19:01:06 +02:00
|
|
|
* Copyright 2008 - 2010, Mark Harrah
|
2018-09-14 09:40:39 +02:00
|
|
|
* Licensed under Apache License 2.0 (see LICENSE)
|
2017-10-04 19:01:06 +02:00
|
|
|
*/
|
2014-06-25 21:19:17 +02:00
|
|
|
package sbt
|
|
|
|
|
|
|
|
|
|
import java.io._
|
|
|
|
|
|
2016-05-07 01:21:13 +02:00
|
|
|
import sbt.internal._
|
2022-09-20 09:49:26 +02:00
|
|
|
import sbt.internal.inc.MappedFileConverter
|
2017-04-21 09:14:31 +02:00
|
|
|
import sbt.internal.util.{
|
|
|
|
|
AttributeEntry,
|
|
|
|
|
AttributeMap,
|
|
|
|
|
ConsoleOut,
|
|
|
|
|
GlobalLogging,
|
|
|
|
|
MainAppender,
|
2024-03-25 15:47:40 +01:00
|
|
|
Terminal,
|
2017-04-21 09:14:31 +02:00
|
|
|
}
|
2024-03-25 15:47:40 +01:00
|
|
|
import sbt.internal.inc.PlainVirtualFileConverter
|
2015-09-11 11:00:34 +02:00
|
|
|
|
2016-07-08 04:23:20 +02:00
|
|
|
object PluginCommandTestPlugin0 extends AutoPlugin { override def requires = empty }
|
2014-06-25 21:19:17 +02:00
|
|
|
|
|
|
|
|
package subpackage {
|
2016-07-08 04:23:20 +02:00
|
|
|
object PluginCommandTestPlugin1 extends AutoPlugin { override def requires = empty }
|
2014-06-25 21:19:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-01-16 06:47:53 +01:00
|
|
|
object PluginCommandTest extends verify.BasicTestSuite {
|
2014-06-25 21:19:17 +02:00
|
|
|
import subpackage._
|
|
|
|
|
import FakeState._
|
|
|
|
|
|
2021-01-16 06:47:53 +01:00
|
|
|
test("`plugin` command should work for plugins within nested in one package") {
|
|
|
|
|
val output = processCommand(
|
|
|
|
|
"plugin sbt.PluginCommandTestPlugin0",
|
|
|
|
|
PluginCommandTestPlugin0,
|
|
|
|
|
PluginCommandTestPlugin1
|
|
|
|
|
)
|
|
|
|
|
assert(output.contains("sbt.PluginCommandTestPlugin0 is activated."))
|
|
|
|
|
}
|
2014-06-25 21:19:17 +02:00
|
|
|
|
2021-01-16 06:47:53 +01:00
|
|
|
test("it should work for plugins nested more than one package") {
|
|
|
|
|
val output = processCommand(
|
|
|
|
|
"plugin sbt.subpackage.PluginCommandTestPlugin1",
|
|
|
|
|
PluginCommandTestPlugin0,
|
|
|
|
|
PluginCommandTestPlugin1
|
|
|
|
|
)
|
|
|
|
|
assert(output.contains("sbt.subpackage.PluginCommandTestPlugin1 is activated."))
|
|
|
|
|
}
|
2014-06-25 21:19:17 +02:00
|
|
|
|
2021-01-16 06:47:53 +01:00
|
|
|
test("it should suggest a plugin when given an incorrect plugin with a similar name") {
|
2014-06-25 21:19:17 +02:00
|
|
|
|
2021-01-16 06:47:53 +01:00
|
|
|
val output = processCommand(
|
|
|
|
|
"plugin PluginCommandTestPlugin0",
|
|
|
|
|
PluginCommandTestPlugin0,
|
|
|
|
|
PluginCommandTestPlugin1
|
|
|
|
|
)
|
|
|
|
|
assert(
|
|
|
|
|
output.contains(
|
2014-06-25 21:19:17 +02:00
|
|
|
"Not a valid plugin: PluginCommandTestPlugin0 (similar: sbt.PluginCommandTestPlugin0, sbt.subpackage.PluginCommandTestPlugin1)"
|
|
|
|
|
)
|
2021-01-16 06:47:53 +01:00
|
|
|
)
|
2014-06-25 21:19:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object FakeState {
|
|
|
|
|
|
|
|
|
|
def processCommand(input: String, enabledPlugins: AutoPlugin*): String = {
|
|
|
|
|
val outBuffer = new ByteArrayOutputStream
|
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.
2019-12-18 19:24:32 +01:00
|
|
|
val logFile = File.createTempFile("sbt", ".log")
|
2014-06-25 21:19:17 +02:00
|
|
|
try {
|
2024-10-28 04:55:30 +01:00
|
|
|
val state = FakeState(logFile, enabledPlugins*)
|
2024-03-25 15:47:40 +01:00
|
|
|
Terminal.withOut(new PrintStream(outBuffer, true)) {
|
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.
2019-12-18 19:24:32 +01:00
|
|
|
MainLoop.processCommand(Exec(input, None), state)
|
|
|
|
|
}
|
2014-06-25 21:19:17 +02:00
|
|
|
new String(outBuffer.toByteArray)
|
|
|
|
|
} finally {
|
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.
2019-12-18 19:24:32 +01:00
|
|
|
logFile.delete()
|
|
|
|
|
()
|
2014-06-25 21:19:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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.
2019-12-18 19:24:32 +01:00
|
|
|
def apply(logFile: File, plugins: AutoPlugin*) = {
|
2014-06-25 21:19:17 +02:00
|
|
|
|
|
|
|
|
val base = new File("").getAbsoluteFile
|
|
|
|
|
val testProject = Project("test-project", base).setAutoPlugins(plugins)
|
|
|
|
|
|
2024-10-28 04:55:30 +01:00
|
|
|
val settings: Seq[Def.Setting[?]] = Nil
|
2014-06-25 21:19:17 +02:00
|
|
|
|
|
|
|
|
val currentProject = Map(testProject.base.toURI -> testProject.id)
|
2022-09-20 09:49:26 +02:00
|
|
|
val currentEval: () => Eval = () => Load.mkEval(Nil, base, Nil)
|
2017-04-21 09:14:31 +02:00
|
|
|
val sessionSettings =
|
|
|
|
|
SessionSettings(base.toURI, currentProject, Nil, Map.empty, Nil, currentEval)
|
2014-06-25 21:19:17 +02:00
|
|
|
|
|
|
|
|
val delegates: (Scope) => Seq[Scope] = _ => Nil
|
|
|
|
|
val scopeLocal: Def.ScopeLocal = _ => Nil
|
|
|
|
|
|
2024-11-11 13:49:14 +01:00
|
|
|
val (cMap, data: Def.Settings) =
|
2022-09-20 09:49:26 +02:00
|
|
|
Def.makeWithCompiledMap(settings)(using delegates, scopeLocal, Def.showFullKey)
|
2024-10-28 04:55:30 +01:00
|
|
|
val extra: KeyIndex => BuildUtil[?] = (keyIndex) =>
|
2017-04-21 09:14:31 +02:00
|
|
|
BuildUtil(base.toURI, Map.empty, keyIndex, data)
|
2018-06-04 12:14:38 +02:00
|
|
|
val structureIndex: StructureIndex =
|
2018-08-06 05:18:13 +02:00
|
|
|
Load.structureIndex(data, settings, extra, Map.empty)
|
2014-06-25 21:19:17 +02:00
|
|
|
val streams: (State) => BuildStreams.Streams = null
|
|
|
|
|
|
|
|
|
|
val loadedDefinitions: LoadedDefinitions = new LoadedDefinitions(
|
2017-04-21 09:14:31 +02:00
|
|
|
base,
|
|
|
|
|
Nil,
|
|
|
|
|
ClassLoader.getSystemClassLoader,
|
|
|
|
|
Nil,
|
|
|
|
|
Seq(testProject),
|
|
|
|
|
Nil
|
2014-06-25 21:19:17 +02:00
|
|
|
)
|
|
|
|
|
|
2024-03-25 15:47:40 +01:00
|
|
|
val converter = PlainVirtualFileConverter.converter
|
|
|
|
|
val pluginData = PluginData(Nil, converter)
|
2016-03-29 19:11:42 +02:00
|
|
|
val builds: DetectedModules[BuildDef] = new DetectedModules[BuildDef](Nil)
|
2014-06-25 21:19:17 +02:00
|
|
|
|
2017-04-21 09:14:31 +02:00
|
|
|
val detectedAutoPlugins: Seq[DetectedAutoPlugin] =
|
|
|
|
|
plugins.map(p => DetectedAutoPlugin(p.label, p, hasAutoImport = false))
|
2016-06-19 22:37:10 +02:00
|
|
|
val detectedPlugins = new DetectedPlugins(detectedAutoPlugins, builds)
|
2017-04-21 09:14:31 +02:00
|
|
|
val loadedPlugins =
|
|
|
|
|
new LoadedPlugins(base, pluginData, ClassLoader.getSystemClassLoader, detectedPlugins)
|
2024-03-25 15:47:40 +01:00
|
|
|
val buildUnit = new BuildUnit(base.toURI, base, loadedDefinitions, loadedPlugins, converter)
|
2014-06-25 21:19:17 +02:00
|
|
|
|
|
|
|
|
val (partBuildUnit: PartBuildUnit, _) = Load.loaded(buildUnit)
|
|
|
|
|
val loadedBuildUnit = Load.resolveProjects(base.toURI, partBuildUnit, _ => testProject.id)
|
|
|
|
|
|
|
|
|
|
val units = Map(base.toURI -> loadedBuildUnit)
|
2018-04-24 17:12:10 +02:00
|
|
|
val buildStructure = new BuildStructure(
|
|
|
|
|
units,
|
|
|
|
|
base.toURI,
|
|
|
|
|
settings,
|
|
|
|
|
data,
|
|
|
|
|
structureIndex,
|
|
|
|
|
streams,
|
|
|
|
|
delegates,
|
2020-07-03 20:33:04 +02:00
|
|
|
scopeLocal,
|
|
|
|
|
cMap,
|
2022-09-20 09:49:26 +02:00
|
|
|
MappedFileConverter.empty,
|
2018-04-24 17:12:10 +02:00
|
|
|
)
|
2014-06-25 21:19:17 +02:00
|
|
|
|
|
|
|
|
val attributes = AttributeMap.empty ++ AttributeMap(
|
|
|
|
|
AttributeEntry(Keys.sessionSettings, sessionSettings),
|
|
|
|
|
AttributeEntry(Keys.stateBuildStructure, buildStructure)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
State(
|
|
|
|
|
null,
|
|
|
|
|
Seq(BuiltinCommands.plugin),
|
|
|
|
|
Set.empty,
|
|
|
|
|
None,
|
2016-12-07 19:22:34 +01:00
|
|
|
List(),
|
2014-06-25 21:19:17 +02:00
|
|
|
State.newHistory,
|
|
|
|
|
attributes,
|
2018-04-24 17:12:10 +02:00
|
|
|
GlobalLogging.initial(
|
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.
2019-12-18 19:24:32 +01:00
|
|
|
MainAppender.globalDefault(ConsoleOut.globalProxy),
|
|
|
|
|
logFile,
|
|
|
|
|
ConsoleOut.globalProxy
|
2018-04-24 17:12:10 +02:00
|
|
|
),
|
2016-12-07 19:22:34 +01:00
|
|
|
None,
|
2014-06-25 21:19:17 +02:00
|
|
|
State.Continue
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|