2018-01-18 08:39:02 -05:00
|
|
|
/*
|
2018-01-18 11:15:02 -05:00
|
|
|
* This project is named sql-cli because it is in the "org.elasticsearch.plugin"
|
2018-01-18 08:39:02 -05:00
|
|
|
* group and it'd be super confusing for it to just be called "cli" there.
|
|
|
|
* Also, the jar we ultimately want to ship is sql-cli-VERSION.jar which is
|
|
|
|
* exactly what gradle makes by default when the project is named sql-cli.
|
|
|
|
*/
|
|
|
|
|
2017-12-13 10:19:31 -05:00
|
|
|
apply plugin: 'elasticsearch.build'
|
|
|
|
/* We don't use the 'application' plugin because it builds a zip and tgz which
|
|
|
|
* we don't want. */
|
|
|
|
|
2018-04-11 11:29:57 -04:00
|
|
|
archivesBaseName = 'elasticsearch-sql-cli'
|
|
|
|
|
2017-12-13 10:19:31 -05:00
|
|
|
description = 'Command line interface to Elasticsearch that speaks SQL'
|
|
|
|
|
|
|
|
dependencies {
|
2018-11-06 11:42:57 -05:00
|
|
|
compile "org.jline:jline:3.8.2"
|
2018-06-28 08:56:16 -04:00
|
|
|
compile xpackProject('plugin:sql:sql-client')
|
|
|
|
compile xpackProject('plugin:sql:sql-action')
|
2018-01-18 11:15:02 -05:00
|
|
|
compile "org.elasticsearch:elasticsearch-cli:${version}"
|
2017-12-13 10:19:31 -05:00
|
|
|
|
2018-01-18 11:15:02 -05:00
|
|
|
runtime "org.fusesource.jansi:jansi:1.16"
|
|
|
|
runtime "org.elasticsearch:jna:${versions.jna}"
|
2018-01-18 08:39:02 -05:00
|
|
|
|
2018-01-18 11:15:02 -05:00
|
|
|
testCompile "org.elasticsearch.test:framework:${version}"
|
2017-12-13 10:19:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
dependencyLicenses {
|
2018-01-18 11:15:02 -05:00
|
|
|
mapping from: /elasticsearch-cli.*/, to: 'elasticsearch'
|
|
|
|
mapping from: /elasticsearch-core.*/, to: 'elasticsearch'
|
|
|
|
mapping from: /jackson-.*/, to: 'jackson'
|
|
|
|
mapping from: /lucene-.*/, to: 'lucene'
|
2018-06-28 08:56:16 -04:00
|
|
|
mapping from: /sql-action.*/, to: 'elasticsearch'
|
|
|
|
mapping from: /sql-client.*/, to: 'elasticsearch'
|
2018-01-18 11:15:02 -05:00
|
|
|
ignoreSha 'elasticsearch-cli'
|
|
|
|
ignoreSha 'elasticsearch-core'
|
|
|
|
ignoreSha 'elasticsearch'
|
2018-06-28 08:56:16 -04:00
|
|
|
ignoreSha 'sql-action'
|
|
|
|
ignoreSha 'sql-client'
|
2017-12-13 10:19:31 -05:00
|
|
|
}
|
|
|
|
|
SQL: Replace the cli fixture with in-process testing (elastic/x-pack-elasticsearch#3889)
I'm really really sad to be removing the cli-fixture but I've had
trouble with it leaking recently it is pretty slow. Beyond that, we'd
prefer that our test fixture only fixture things that are external
depndencies.
So, yeah, I'm removing it. So we get faster tests and no chance of
leaking processes. We lose some "realness" in the tests. Instead of
interacting with the CLI like a real user we embed it in the test
process. That means we don't test the forking, we don't test the
executable jar, and we don't test the jLine console detection stuff. On
the other hand we were kind of forcing the jLine console detection stuff
in a funky way with the fixture anyway. And we test the executable jar
in the packaging tests. And that'll have to do.
I haven't renamed `RemoteCli` because it'd bloat this commit with
mechanical changes that'd make it hard to review. I'll rename it in a
followup commit.
This also updates jLine so we can disable blinking to matching
parentheses during testing. I have no clue why, but this wasn't
happening when we used the fixture. The trouble with the blinking is
that it is based on *time* so it slows things down. Worse, it works
inconsistently! Sometimes it spits out sensible ascii codes and
sometimes it, well, spits out weird garbage. When you use it in person
it works fine though. So we keep it on when not testing.
Cleans up some redundancy in when testing CLI errors. Less copy and
paste good.
I was tempted to disable the xterm emulation entirely while working on
this because upgrading jLine changed a few things and it was a real pain
to update. But If we turned that off then we'd have *nothing* testing
the colors and such. That'd be a shame because we use color in the
output to commicate stuff. I like it so I don't want to break it.
While I was there, I replaces the cli connector's `PrintWriter` with a
`BufferedWriter`. The `PrintWriter` was kind of a trap because `println`
would fail to work properly on windows because we force the terminal
into xterm mode and it doesn't know what to do with windows line
endings. Windows.....
Additionally I fixed a race condition between disabling echo when
reading passwords and fast writers. We were disabling the echo shortly
after sending the prompt. A fast enough writer could send us text before
the echo disable kicked in. Now I delegate to `LineReader#readLine`
with a special echo mask that disables echo. This is both easier to test
and doesn't seem to have the race condition. This race condition was
failing the tests because they are so much faster now. Yay!
Original commit: elastic/x-pack-elasticsearch@d0ec0273964630a3a113ab27009fdff6a182ecb2
2018-02-27 12:24:16 -05:00
|
|
|
/*
|
|
|
|
* Bundle all dependencies into the main jar and mark it as executable it
|
|
|
|
* can be easilly shipped around and used.
|
|
|
|
*/
|
2017-12-13 10:19:31 -05:00
|
|
|
jar {
|
2018-04-25 09:38:31 -04:00
|
|
|
from({
|
2018-01-18 11:15:02 -05:00
|
|
|
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
|
|
|
|
configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
|
2018-04-25 09:38:31 -04:00
|
|
|
}) {
|
|
|
|
// We don't need the META-INF from the things we bundle. For now.
|
|
|
|
exclude 'META-INF/*'
|
2018-01-18 11:15:02 -05:00
|
|
|
}
|
|
|
|
manifest {
|
|
|
|
attributes 'Main-Class': 'org.elasticsearch.xpack.sql.cli.Cli'
|
|
|
|
}
|
2017-12-13 10:19:31 -05:00
|
|
|
}
|
|
|
|
|
SQL: Replace the cli fixture with in-process testing (elastic/x-pack-elasticsearch#3889)
I'm really really sad to be removing the cli-fixture but I've had
trouble with it leaking recently it is pretty slow. Beyond that, we'd
prefer that our test fixture only fixture things that are external
depndencies.
So, yeah, I'm removing it. So we get faster tests and no chance of
leaking processes. We lose some "realness" in the tests. Instead of
interacting with the CLI like a real user we embed it in the test
process. That means we don't test the forking, we don't test the
executable jar, and we don't test the jLine console detection stuff. On
the other hand we were kind of forcing the jLine console detection stuff
in a funky way with the fixture anyway. And we test the executable jar
in the packaging tests. And that'll have to do.
I haven't renamed `RemoteCli` because it'd bloat this commit with
mechanical changes that'd make it hard to review. I'll rename it in a
followup commit.
This also updates jLine so we can disable blinking to matching
parentheses during testing. I have no clue why, but this wasn't
happening when we used the fixture. The trouble with the blinking is
that it is based on *time* so it slows things down. Worse, it works
inconsistently! Sometimes it spits out sensible ascii codes and
sometimes it, well, spits out weird garbage. When you use it in person
it works fine though. So we keep it on when not testing.
Cleans up some redundancy in when testing CLI errors. Less copy and
paste good.
I was tempted to disable the xterm emulation entirely while working on
this because upgrading jLine changed a few things and it was a real pain
to update. But If we turned that off then we'd have *nothing* testing
the colors and such. That'd be a shame because we use color in the
output to commicate stuff. I like it so I don't want to break it.
While I was there, I replaces the cli connector's `PrintWriter` with a
`BufferedWriter`. The `PrintWriter` was kind of a trap because `println`
would fail to work properly on windows because we force the terminal
into xterm mode and it doesn't know what to do with windows line
endings. Windows.....
Additionally I fixed a race condition between disabling echo when
reading passwords and fast writers. We were disabling the echo shortly
after sending the prompt. A fast enough writer could send us text before
the echo disable kicked in. Now I delegate to `LineReader#readLine`
with a special echo mask that disables echo. This is both easier to test
and doesn't seem to have the race condition. This race condition was
failing the tests because they are so much faster now. Yay!
Original commit: elastic/x-pack-elasticsearch@d0ec0273964630a3a113ab27009fdff6a182ecb2
2018-02-27 12:24:16 -05:00
|
|
|
/*
|
|
|
|
* Build a jar that doesn't include the dependencies bundled that we can
|
|
|
|
* include with QA tests along side Elasticsearch without breaking
|
|
|
|
* jarhell.
|
|
|
|
*/
|
|
|
|
configurations {
|
|
|
|
nodeps
|
|
|
|
}
|
|
|
|
task nodepsJar(type: Jar) {
|
|
|
|
appendix 'nodeps'
|
|
|
|
from sourceSets.main.output
|
|
|
|
}
|
|
|
|
artifacts {
|
|
|
|
nodeps nodepsJar
|
|
|
|
}
|
|
|
|
|
2018-12-18 17:48:30 -05:00
|
|
|
forbiddenApisMain {
|
|
|
|
//sql does not depend on server, so only jdk signatures should be checked
|
|
|
|
replaceSignatureFiles 'jdk-signatures'
|
2018-08-22 02:05:22 -04:00
|
|
|
signaturesFiles += files('src/forbidden/cli-signatures.txt')
|
2018-03-14 16:15:32 -04:00
|
|
|
}
|
|
|
|
|
2019-01-07 10:24:19 -05:00
|
|
|
thirdPartyAudit.ignoreMissingClasses (
|
SQL: Replace the cli fixture with in-process testing (elastic/x-pack-elasticsearch#3889)
I'm really really sad to be removing the cli-fixture but I've had
trouble with it leaking recently it is pretty slow. Beyond that, we'd
prefer that our test fixture only fixture things that are external
depndencies.
So, yeah, I'm removing it. So we get faster tests and no chance of
leaking processes. We lose some "realness" in the tests. Instead of
interacting with the CLI like a real user we embed it in the test
process. That means we don't test the forking, we don't test the
executable jar, and we don't test the jLine console detection stuff. On
the other hand we were kind of forcing the jLine console detection stuff
in a funky way with the fixture anyway. And we test the executable jar
in the packaging tests. And that'll have to do.
I haven't renamed `RemoteCli` because it'd bloat this commit with
mechanical changes that'd make it hard to review. I'll rename it in a
followup commit.
This also updates jLine so we can disable blinking to matching
parentheses during testing. I have no clue why, but this wasn't
happening when we used the fixture. The trouble with the blinking is
that it is based on *time* so it slows things down. Worse, it works
inconsistently! Sometimes it spits out sensible ascii codes and
sometimes it, well, spits out weird garbage. When you use it in person
it works fine though. So we keep it on when not testing.
Cleans up some redundancy in when testing CLI errors. Less copy and
paste good.
I was tempted to disable the xterm emulation entirely while working on
this because upgrading jLine changed a few things and it was a real pain
to update. But If we turned that off then we'd have *nothing* testing
the colors and such. That'd be a shame because we use color in the
output to commicate stuff. I like it so I don't want to break it.
While I was there, I replaces the cli connector's `PrintWriter` with a
`BufferedWriter`. The `PrintWriter` was kind of a trap because `println`
would fail to work properly on windows because we force the terminal
into xterm mode and it doesn't know what to do with windows line
endings. Windows.....
Additionally I fixed a race condition between disabling echo when
reading passwords and fast writers. We were disabling the echo shortly
after sending the prompt. A fast enough writer could send us text before
the echo disable kicked in. Now I delegate to `LineReader#readLine`
with a special echo mask that disables echo. This is both easier to test
and doesn't seem to have the race condition. This race condition was
failing the tests because they are so much faster now. Yay!
Original commit: elastic/x-pack-elasticsearch@d0ec0273964630a3a113ab27009fdff6a182ecb2
2018-02-27 12:24:16 -05:00
|
|
|
// jLine's optional dependencies
|
2018-01-18 11:15:02 -05:00
|
|
|
'org.apache.sshd.client.SshClient',
|
|
|
|
'org.apache.sshd.client.auth.keyboard.UserInteraction',
|
|
|
|
'org.apache.sshd.client.channel.ChannelShell',
|
|
|
|
'org.apache.sshd.client.channel.ClientChannel',
|
|
|
|
'org.apache.sshd.client.channel.ClientChannelEvent',
|
|
|
|
'org.apache.sshd.client.future.AuthFuture',
|
|
|
|
'org.apache.sshd.client.future.ConnectFuture',
|
|
|
|
'org.apache.sshd.client.future.OpenFuture',
|
|
|
|
'org.apache.sshd.client.session.ClientSession',
|
|
|
|
'org.apache.sshd.common.Factory',
|
|
|
|
'org.apache.sshd.common.channel.PtyMode',
|
|
|
|
'org.apache.sshd.common.config.keys.FilePasswordProvider',
|
|
|
|
'org.apache.sshd.common.util.io.NoCloseInputStream',
|
|
|
|
'org.apache.sshd.common.util.io.NoCloseOutputStream',
|
|
|
|
'org.apache.sshd.server.Command',
|
|
|
|
'org.apache.sshd.server.Environment',
|
|
|
|
'org.apache.sshd.server.ExitCallback',
|
|
|
|
'org.apache.sshd.server.SessionAware',
|
|
|
|
'org.apache.sshd.server.Signal',
|
|
|
|
'org.apache.sshd.server.SshServer',
|
|
|
|
'org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider',
|
|
|
|
'org.apache.sshd.server.scp.ScpCommandFactory$Builder',
|
|
|
|
'org.apache.sshd.server.session.ServerSession',
|
|
|
|
'org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory$Builder',
|
SQL: Replace the cli fixture with in-process testing (elastic/x-pack-elasticsearch#3889)
I'm really really sad to be removing the cli-fixture but I've had
trouble with it leaking recently it is pretty slow. Beyond that, we'd
prefer that our test fixture only fixture things that are external
depndencies.
So, yeah, I'm removing it. So we get faster tests and no chance of
leaking processes. We lose some "realness" in the tests. Instead of
interacting with the CLI like a real user we embed it in the test
process. That means we don't test the forking, we don't test the
executable jar, and we don't test the jLine console detection stuff. On
the other hand we were kind of forcing the jLine console detection stuff
in a funky way with the fixture anyway. And we test the executable jar
in the packaging tests. And that'll have to do.
I haven't renamed `RemoteCli` because it'd bloat this commit with
mechanical changes that'd make it hard to review. I'll rename it in a
followup commit.
This also updates jLine so we can disable blinking to matching
parentheses during testing. I have no clue why, but this wasn't
happening when we used the fixture. The trouble with the blinking is
that it is based on *time* so it slows things down. Worse, it works
inconsistently! Sometimes it spits out sensible ascii codes and
sometimes it, well, spits out weird garbage. When you use it in person
it works fine though. So we keep it on when not testing.
Cleans up some redundancy in when testing CLI errors. Less copy and
paste good.
I was tempted to disable the xterm emulation entirely while working on
this because upgrading jLine changed a few things and it was a real pain
to update. But If we turned that off then we'd have *nothing* testing
the colors and such. That'd be a shame because we use color in the
output to commicate stuff. I like it so I don't want to break it.
While I was there, I replaces the cli connector's `PrintWriter` with a
`BufferedWriter`. The `PrintWriter` was kind of a trap because `println`
would fail to work properly on windows because we force the terminal
into xterm mode and it doesn't know what to do with windows line
endings. Windows.....
Additionally I fixed a race condition between disabling echo when
reading passwords and fast writers. We were disabling the echo shortly
after sending the prompt. A fast enough writer could send us text before
the echo disable kicked in. Now I delegate to `LineReader#readLine`
with a special echo mask that disables echo. This is both easier to test
and doesn't seem to have the race condition. This race condition was
failing the tests because they are so much faster now. Yay!
Original commit: elastic/x-pack-elasticsearch@d0ec0273964630a3a113ab27009fdff6a182ecb2
2018-02-27 12:24:16 -05:00
|
|
|
'org.mozilla.universalchardet.UniversalDetector',
|
|
|
|
'org.fusesource.jansi.internal.Kernel32$FOCUS_EVENT_RECORD',
|
|
|
|
'org.fusesource.jansi.internal.Kernel32$MOUSE_EVENT_RECORD',
|
2019-01-07 10:24:19 -05:00
|
|
|
)
|
2017-12-13 10:19:31 -05:00
|
|
|
|
2017-12-15 10:42:18 -05:00
|
|
|
task runcli {
|
2018-01-18 11:15:02 -05:00
|
|
|
description = 'Run the CLI and connect to elasticsearch running on 9200'
|
|
|
|
dependsOn 'assemble'
|
|
|
|
doLast {
|
|
|
|
List command = [new File(project.runtimeJavaHome, 'bin/java').absolutePath]
|
|
|
|
if ('true'.equals(System.getProperty('debug', 'false'))) {
|
|
|
|
command += '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000'
|
|
|
|
}
|
|
|
|
command += ['-jar', jar.archivePath.absolutePath]
|
|
|
|
logger.info("running the cli with: ${command}")
|
2017-12-13 10:19:31 -05:00
|
|
|
|
2018-01-18 11:15:02 -05:00
|
|
|
new ProcessBuilder(command)
|
|
|
|
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
|
|
|
|
.redirectInput(ProcessBuilder.Redirect.INHERIT)
|
|
|
|
.redirectError(ProcessBuilder.Redirect.INHERIT)
|
|
|
|
.start()
|
|
|
|
.waitFor()
|
|
|
|
}
|
2017-12-13 10:19:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Use the jar for testing so we can get the proper version information
|
2018-12-19 01:25:20 -05:00
|
|
|
unitTest {
|
2018-01-18 11:15:02 -05:00
|
|
|
classpath -= compileJava.outputs.files
|
|
|
|
classpath -= configurations.compile
|
|
|
|
classpath -= configurations.runtime
|
|
|
|
classpath += jar.outputs.files
|
|
|
|
dependsOn jar
|
2017-12-15 10:42:18 -05:00
|
|
|
}
|