mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-25 22:36:20 +00:00
Improve CliFixture messages and Win behavior
Original commit: elastic/x-pack-elasticsearch@332d1744a2
This commit is contained in:
parent
fdd98f01ed
commit
de85a2cd2b
@ -22,6 +22,7 @@ import java.nio.file.StandardCopyOption;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import static java.util.Collections.singleton;
|
import static java.util.Collections.singleton;
|
||||||
|
|
||||||
@ -42,12 +43,18 @@ public class CliFixture {
|
|||||||
if (false == Files.isRegularFile(cliJar)) {
|
if (false == Files.isRegularFile(cliJar)) {
|
||||||
throw new IllegalArgumentException(cliJar + " is not a regular file");
|
throw new IllegalArgumentException(cliJar + " is not a regular file");
|
||||||
}
|
}
|
||||||
Path javaExecutable = Paths.get(System.getProperty("java.home"), "bin", "java");
|
String javaExec = "java";
|
||||||
|
boolean isWindows = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win");
|
||||||
|
|
||||||
|
if (isWindows) {
|
||||||
|
javaExec += ".exe";
|
||||||
|
}
|
||||||
|
Path javaExecutable = Paths.get(System.getProperty("java.home"), "bin", javaExec);
|
||||||
if (false == Files.exists(javaExecutable)) {
|
if (false == Files.exists(javaExecutable)) {
|
||||||
throw new IllegalArgumentException(cliJar + " doesn't exist");
|
throw new IllegalArgumentException(javaExec + " doesn't exist");
|
||||||
}
|
}
|
||||||
if (false == Files.isExecutable(javaExecutable)) {
|
if (false == Files.isExecutable(javaExecutable)) {
|
||||||
throw new IllegalArgumentException(cliJar + " isn't executable");
|
throw new IllegalArgumentException(javaExec + " isn't executable");
|
||||||
}
|
}
|
||||||
|
|
||||||
try (ServerSocket server = new ServerSocket()) {
|
try (ServerSocket server = new ServerSocket()) {
|
||||||
@ -63,13 +70,15 @@ public class CliFixture {
|
|||||||
InetSocketAddress bound = (InetSocketAddress) server.getLocalSocketAddress();
|
InetSocketAddress bound = (InetSocketAddress) server.getLocalSocketAddress();
|
||||||
if (bound.getAddress() instanceof Inet6Address) {
|
if (bound.getAddress() instanceof Inet6Address) {
|
||||||
Files.write(tmp, singleton("[" + bound.getHostString() + "]:" + bound.getPort()));
|
Files.write(tmp, singleton("[" + bound.getHostString() + "]:" + bound.getPort()));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Files.write(tmp, singleton(bound.getHostString() + ":" + bound.getPort()));
|
Files.write(tmp, singleton(bound.getHostString() + ":" + bound.getPort()));
|
||||||
}
|
}
|
||||||
Files.move(tmp, dir.resolve("ports"), StandardCopyOption.ATOMIC_MOVE);
|
Files.move(tmp, dir.resolve("ports"), StandardCopyOption.ATOMIC_MOVE);
|
||||||
|
|
||||||
|
boolean run = true;
|
||||||
// Run forever until killed
|
// Run forever until killed
|
||||||
while (true) {
|
while (run) {
|
||||||
try {
|
try {
|
||||||
println("accepting on localhost:" + server.getLocalPort());
|
println("accepting on localhost:" + server.getLocalPort());
|
||||||
Socket s = server.accept();
|
Socket s = server.accept();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user