SQL: Ban PrintWriter#println in CLI (elastic/x-pack-elasticsearch#4118)

`PrintWriter#println` doesn't pay attention to the terminal
configuration that we specify so it breaks tests on Windows. If we
instead always use `PrintWriter#print('\n')` then the tests work
properly on windows *and* the CLI actually works properly on Windows.

relates elastic/x-pack-elasticsearch#4109

Original commit: elastic/x-pack-elasticsearch@ac17e691c8
This commit is contained in:
Nik Everett 2018-03-14 16:15:32 -04:00 committed by GitHub
parent b14baf4a6f
commit d1b0067e47
4 changed files with 16 additions and 14 deletions

View File

@ -68,6 +68,14 @@ artifacts {
nodeps nodepsJar nodeps nodepsJar
} }
forbiddenApisMain {
signaturesURLs += file('src/forbidden/cli-signatures.txt').toURI().toURL()
}
forbiddenApisTest {
signaturesURLs += file('src/forbidden/cli-signatures.txt').toURI().toURL()
}
thirdPartyAudit.excludes = [ thirdPartyAudit.excludes = [
// jLine's optional dependencies // jLine's optional dependencies
'org.apache.sshd.client.SshClient', 'org.apache.sshd.client.SshClient',

View File

@ -0,0 +1,3 @@
@defaultMessage println doesn't pay attention to terminal type so it breaks tests on Windows. Just use \n.
java.io.PrintWriter#println()
java.io.PrintWriter#println(java.lang.String)

View File

@ -71,7 +71,8 @@ public class JLineTerminal implements CliTerminal {
@Override @Override
public void println(String text) { public void println(String text) {
terminal.writer().println(text); print(text);
print("\n");
} }
@Override @Override
@ -86,7 +87,7 @@ public class JLineTerminal implements CliTerminal {
@Override @Override
public void println() { public void println() {
terminal.writer().println(); print("\n");
} }
@Override @Override
@ -168,7 +169,7 @@ public class JLineTerminal implements CliTerminal {
} }
public void ln() { public void ln() {
terminal.writer().println(line.toAnsi(terminal)); println(line.toAnsi(terminal));
} }
public void end() { public void end() {

View File

@ -25,19 +25,10 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.PipedInputStream; import java.io.PipedInputStream;
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -46,7 +37,6 @@ import static org.elasticsearch.test.ESTestCase.randomBoolean;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -54,7 +44,7 @@ import static org.junit.Assert.fail;
/** /**
* Wraps a CLI in as "real" a way as it can get without forking the CLI * Wraps a CLI in as "real" a way as it can get without forking the CLI
* subprocess with the goal being integration testing of the CLI without * subprocess with the goal being integration testing of the CLI without
* breaking out security model by forking. We test the script that starts * breaking our security model by forking. We test the script that starts
* the CLI using packaging tests which is super "real" but not super fast * the CLI using packaging tests which is super "real" but not super fast
* and doesn't run super frequently. * and doesn't run super frequently.
*/ */