`cli`'s `gradle run` works!

Including proper tty support!

Original commit: elastic/x-pack-elasticsearch@a780a99d1b
This commit is contained in:
Nik Everett 2017-07-07 10:32:23 -04:00
parent edcc87e30e
commit f6fad00765
4 changed files with 54 additions and 11 deletions

View File

@ -1,7 +1,8 @@
import org.elasticsearch.gradle.test.RunTask
apply plugin: 'elasticsearch.build'
apply plugin: 'application'
/* We don't use the 'application' plugin because it builds a zip and tgz which
* we don't want. */
description = 'Command line interface to Elasticsearch that speaks SQL'
@ -33,14 +34,18 @@ forbiddenApisMain {
signaturesURLs = [this.class.getResource('/forbidden/jdk-signatures.txt')]
}
// TODO seems like we should use the jars....
jar {
from(zipTree(project(':x-pack-elasticsearch:sql:net-client').jar.archivePath))
from(zipTree(project(':x-pack-elasticsearch:sql:cli-proto').jar.archivePath))
// Bundle all dependencies into the jar.
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
}
// Make the jar "executable" with `java -jar`
manifest {
attributes 'Main-Class': 'org.elasticsearch.xpack.sql.cli.Cli'
}
}
mainClassName = "org.elasticsearch.sql.console.SqlConsole"
// Needed so we can launch graphviz if it is installed
project.compactProfile = 'full'
@ -93,15 +98,39 @@ integTestCluster {
}
task runServer(type: RunTask) {
distribution = 'zip' // NOCOMMIT make double sure we want all the modules
distribution = 'zip'
plugin project(':x-pack-elasticsearch:plugin').path
// Daemonize Elasticsearch so we can run the cli application
daemonize = true
/* Get a "clean" test without the other x-pack features here and check them
* all together later on. */
setting 'xpack.security.enabled', 'false'
setting 'xpack.monitoring.enabled', 'false'
setting 'xpack.ml.enabled', 'false'
setting 'xpack.watcher.enabled', 'false'
run.dependsOn this
}
task run {
/* We can't use JavaExec or Exec because neither support
* ProcessBuilder.Redirect.INHERIT which is required to get full tty-support.
*/
dependsOn jar, runServer
finalizedBy 'runServer#stop'
description = 'Run the CLI and an Elasticsearch instant for it to connect to'
doLast {
List command = [new File(project.javaHome, '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("command: ${command}")
new ProcessBuilder(command)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectInput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor()
}
}
// Allow for com.sun.net.httpserver.* usage for testing

View File

@ -24,6 +24,7 @@ import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Properties;
import java.util.logging.LogManager;
import static org.jline.utils.AttributedStyle.BOLD;
import static org.jline.utils.AttributedStyle.BRIGHT;
@ -33,6 +34,9 @@ import static org.jline.utils.AttributedStyle.YELLOW;
public class Cli {
public static void main(String... args) throws Exception {
/* Initialize the logger from the a properties file we bundle. This makes sure
* we get useful error messages. */
LogManager.getLogManager().readConfiguration(Cli.class.getResourceAsStream("/logging.properties"));
try (Terminal term = TerminalBuilder.builder().build()) {
try {
Cli console = new Cli(new CliConfiguration("localhost:9200/_cli", new Properties()), term);

View File

@ -0,0 +1,6 @@
handlers=java.util.logging.ConsoleHandler
.level = WARNING
# Let jline log information about any failure to setup the terminal properly.
# Without this we have no way of knowing *why* you lose terminal features.
org.jline.level = FINE

View File

@ -43,6 +43,8 @@ task generateGitHash {
dependencies {
compile project(':x-pack-elasticsearch:sql:net-client')
compile project(':x-pack-elasticsearch:sql:jdbc-proto')
/* We want to limit these dependencies so do not add anything to this list
* without serious consideration, and probably shading. */
testCompile project(path: ':client:transport', configuration: 'runtime')
testCompile project(path: ':x-pack-elasticsearch:plugin', configuration: 'testArtifacts')
@ -59,10 +61,12 @@ dependencyLicenses {
ignoreSha 'net-client'
}
// TODO seems like we should use the jars....
jar {
from(zipTree(project(':x-pack-elasticsearch:sql:net-client').jar.archivePath))
from(zipTree(project(':x-pack-elasticsearch:sql:jdbc-proto').jar.archivePath))
// Bundle all dependencies into the jar.
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) }
}
}
apply plugin: 'elasticsearch.rest-test'