Object object = getPluginContext().get(TEST_CONTAINER_RUNNER_KEY + mojoExecution.getExecutionId());
if (object == null) {
throw new MojoExecutionException(
"No Pax Exam container found. Did you run the start-container goal?");
}
DefaultJavaRunner javaRunner = (DefaultJavaRunner) object;
object = getPluginContext().get(TEST_CONTAINER_PORT_KEY + mojoExecution.getExecutionId());
if (object == null) {
throw new MojoExecutionException(
"No Pax Exam container port found. Did you run the start-container goal?");
}
Integer port = (Integer) object;
try {
getLog().debug("stopping test container");
Socket socket = new Socket((String) null, port);
OutputStream os = socket.getOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
PrintWriter pw = new PrintWriter(writer, true);
InputStreamReader isr = new InputStreamReader(socket.getInputStream(), "UTF-8");
BufferedReader reader = new BufferedReader(isr);
pw.println("stop");
getLog().debug("quitting test container");
reader.readLine();
pw.println("quit");
reader.close();
pw.close();
socket.close();
}
catch (IOException exc) {
getLog().info("exception communicating with background process, terminating process");
getLog().info(exc);
}
javaRunner.shutdown();
}