diff --git a/sql/cli/build.gradle b/sql/cli/build.gradle index 1fe00c77b7f..472db245dda 100644 --- a/sql/cli/build.gradle +++ b/sql/cli/build.gradle @@ -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 diff --git a/sql/cli/src/main/java/org/elasticsearch/xpack/sql/cli/Cli.java b/sql/cli/src/main/java/org/elasticsearch/xpack/sql/cli/Cli.java index d3525690061..69e291147e9 100644 --- a/sql/cli/src/main/java/org/elasticsearch/xpack/sql/cli/Cli.java +++ b/sql/cli/src/main/java/org/elasticsearch/xpack/sql/cli/Cli.java @@ -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); diff --git a/sql/cli/src/main/resources/logging.properties b/sql/cli/src/main/resources/logging.properties new file mode 100644 index 00000000000..cfba3c2935f --- /dev/null +++ b/sql/cli/src/main/resources/logging.properties @@ -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 diff --git a/sql/jdbc/build.gradle b/sql/jdbc/build.gradle index 9cc4374ba16..2eff5b1c595 100644 --- a/sql/jdbc/build.gradle +++ b/sql/jdbc/build.gradle @@ -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'