提交 d61be971 authored 作者: Thomas Mueller's avatar Thomas Mueller

Automated build improvements.

上级 1cba07fa
...@@ -48,6 +48,7 @@ public class SelfDestructor extends Thread { ...@@ -48,6 +48,7 @@ public class SelfDestructor extends Thread {
// ignore // ignore
} }
} }
try {
String time = new Timestamp(System.currentTimeMillis()).toString(); String time = new Timestamp(System.currentTimeMillis()).toString();
System.out.println(time + " Killing the process after " + minutes + " minute(s)"); System.out.println(time + " Killing the process after " + minutes + " minute(s)");
try { try {
...@@ -88,7 +89,13 @@ public class SelfDestructor extends Thread { ...@@ -88,7 +89,13 @@ public class SelfDestructor extends Thread {
// ignore // ignore
} }
System.out.println("Killing the process now"); System.out.println("Killing the process now");
} catch (Throwable t) {
try {
t.printStackTrace(System.out);
} catch (Throwable t2) {
// ignore (out of memory)
}
}
Runtime.getRuntime().halt(1); Runtime.getRuntime().halt(1);
} }
}; };
......
...@@ -112,12 +112,12 @@ public class UploadBuild { ...@@ -112,12 +112,12 @@ public class UploadBuild {
int end = testOutput.indexOf("<br />", idx); int end = testOutput.indexOf("<br />", idx);
if (end >= 0) { if (end >= 0) {
String result = testOutput.substring(idx + "Statements per second: ".length(), end); String result = testOutput.substring(idx + "Statements per second: ".length(), end);
now += " (" + result + " op/s)"; now += " " + result + " op/s";
} }
} }
String sql = "insert into item(title, issued, desc) values('Build " + now + String sql = "insert into item(title, issued, desc) values('Build " + now +
(error ? " (FAILED)" : "") + (error ? " FAILED" : "") +
(coverageFailed ? " (COVERAGE)" : "") + (coverageFailed ? " COVERAGE" : "") +
"', '" + ts + "', '<a href=\"http://www.h2database.com/html/testOutput.html\">Output</a>" + "', '" + ts + "', '<a href=\"http://www.h2database.com/html/testOutput.html\">Output</a>" +
" - <a href=\"http://www.h2database.com/coverage/overview.html\">Coverage</a>" + " - <a href=\"http://www.h2database.com/coverage/overview.html\">Coverage</a>" +
" - <a href=\"http://www.h2database.com/automated/h2-latest.jar\">Jar</a>');\n"; " - <a href=\"http://www.h2database.com/automated/h2-latest.jar\">Jar</a>');\n";
......
/*
* Copyright 2004-2013 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.dev.util;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map.Entry;
import java.util.TreeMap;
/**
* Allows to kill a certain Java process.
*/
public class JavaProcessKiller {
/**
* Kill a certain Java process. The JDK (jps) needs to be in the path.
*
* @param args the Java process name as listed by jps -l. If not set the
* Java processes are listed
*/
public static void main(String... args) {
new JavaProcessKiller().run(args);
}
private void run(String... args) {
TreeMap<Integer, String> map = getProcesses();
System.out.println("Processes:");
System.out.println(map);
if (args.length == 0) {
System.out.println("Kill a Java process");
System.out.println("Usage: java " + getClass().getName() + " <name>");
return;
}
String processName = args[0];
int killCount = 0;
for (Entry<Integer, String> e : map.entrySet()) {
String name = e.getValue();
if (name.equals(processName)) {
int pid = e.getKey();
System.out.println("Killing pid " + pid + "...");
// Windows
try {
exec("taskkill", "/pid", "" + pid, "/f");
} catch (Exception e2) {
// ignore
}
// Unix
try {
exec("kill", "-9", "" + pid);
} catch (Exception e2) {
// ignore
}
System.out.println("done.");
killCount++;
}
}
if (killCount == 0) {
System.out.println("Process " + processName + " not found");
}
map = getProcesses();
System.out.println("Processes now:");
System.out.println(map);
}
private static TreeMap<Integer, String> getProcesses() {
String processList = exec("jps", "-l");
String[] processes = processList.split("\n");
TreeMap<Integer, String> map = new TreeMap<Integer, String>();
for (int i = 0; i < processes.length; i++) {
String p = processes[i].trim();
int idx = p.indexOf(' ');
if (idx > 0) {
int pid = Integer.parseInt(p.substring(0, idx));
String n = p.substring(idx + 1);
map.put(pid, n);
}
}
return map;
}
private static String exec(String... args) {
ByteArrayOutputStream err = new ByteArrayOutputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Process p = Runtime.getRuntime().exec(args);
copyInThread(p.getInputStream(), out);
copyInThread(p.getErrorStream(), err);
p.waitFor();
String e = new String(err.toByteArray(), "UTF-8");
if (e.length() > 0) {
throw new RuntimeException(e);
}
String output = new String(out.toByteArray(), "UTF-8");
return output;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static void copyInThread(final InputStream in, final OutputStream out) {
new Thread("Profiler stream copy") {
@Override
public void run() {
byte[] buffer = new byte[4096];
try {
while (true) {
int len = in.read(buffer, 0, buffer.length);
if (len < 0) {
break;
}
out.write(buffer, 0, len);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}.run();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论