Introduce Gerrit Inspector: interactive Jython shell
Adds "-s" option to com.google.gerrit.pgm.Daemon to start an interactive Jython shell for inspection and troubleshooting of live data of the Gerrit instance. Gerrit Inspector is an interactive scriptable environment to inspect and modify internal state of the system. This environment is available on the system console after the system starts. Leaving the Inspector will shutdown the Gerrit instance. The environment allows interactive work as well as running of Python scripts for troubleshooting. Accessing Java Virtual Machine objects and calling Java methods is possible. Gerrit Inspect can be started by adding -s option to the command used to launch the daemon: java -jar buck-out/gen/gerrit.war daemon -d ../test_site -s For more information on this facility please see: Documentation/dev-inspector.txt Implementation remark: Jython needs to examine available .jar files on startup. It does so currently by reading contents of the WAR archive unpacked by GerritLauncher in the temporary directory. Jython is able to store this information persistently, but it does not currently work because we unpack WAR file every time on startup. Currently no attempt is made to introspect Guice bindings. Change-Id: I47ffc8383fd50bc6ec12ba31edb6d7d614e97bd5
This commit is contained in:

committed by
Shawn Pearce

parent
aebbe03e4f
commit
ed612fb44a
@@ -300,6 +300,7 @@ public final class GerritLauncher {
|
||||
}
|
||||
|
||||
private volatile static File myArchive;
|
||||
private static File myHome;
|
||||
|
||||
/**
|
||||
* Locate the JAR/WAR file we were launched from.
|
||||
@@ -457,42 +458,26 @@ public final class GerritLauncher {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide path to a working directory
|
||||
*
|
||||
* @return local path of the working directory or null if cannot be determined
|
||||
*/
|
||||
public static File getHomeDirectory() {
|
||||
if (myHome == null) {
|
||||
myHome = locateHomeDirectory();
|
||||
}
|
||||
return myHome;
|
||||
}
|
||||
|
||||
|
||||
private static File tmproot() {
|
||||
File tmp;
|
||||
String gerritTemp = System.getenv("GERRIT_TMP");
|
||||
if (gerritTemp != null && gerritTemp.length() > 0) {
|
||||
tmp = new File(gerritTemp);
|
||||
} else {
|
||||
// Try to find the user's home directory. If we can't find it
|
||||
// return null so the JVM's default temporary directory is used
|
||||
// instead. This is probably /tmp or /var/tmp.
|
||||
//
|
||||
String userHome = System.getProperty("user.home");
|
||||
if (userHome == null || "".equals(userHome)) {
|
||||
userHome = System.getenv("HOME");
|
||||
if (userHome == null || "".equals(userHome)) {
|
||||
System.err.println("warning: cannot determine home directory");
|
||||
System.err.println("warning: using system temporary directory instead");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the home directory exists. If it doesn't, try to make it.
|
||||
//
|
||||
final File home = new File(userHome);
|
||||
if (!home.exists()) {
|
||||
if (home.mkdirs()) {
|
||||
System.err.println("warning: created " + home.getAbsolutePath());
|
||||
} else {
|
||||
System.err.println("warning: " + home.getAbsolutePath() + " not found");
|
||||
System.err.println("warning: using system temporary directory instead");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Use $HOME/.gerritcodereview/tmp for our temporary file area.
|
||||
//
|
||||
tmp = new File(new File(home, ".gerritcodereview"), "tmp");
|
||||
tmp = new File(getHomeDirectory(), "tmp");
|
||||
}
|
||||
if (!tmp.exists() && !tmp.mkdirs()) {
|
||||
System.err.println("warning: cannot create " + tmp.getAbsolutePath());
|
||||
@@ -525,6 +510,49 @@ public final class GerritLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
private static File locateHomeDirectory() {
|
||||
// Try to find the user's home directory. If we can't find it
|
||||
// return null so the JVM's default temporary directory is used
|
||||
// instead. This is probably /tmp or /var/tmp.
|
||||
//
|
||||
String userHome = System.getProperty("user.home");
|
||||
if (userHome == null || "".equals(userHome)) {
|
||||
userHome = System.getenv("HOME");
|
||||
if (userHome == null || "".equals(userHome)) {
|
||||
System.err.println("warning: cannot determine home directory");
|
||||
System.err.println("warning: using system temporary directory instead");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the home directory exists. If it doesn't, try to make it.
|
||||
//
|
||||
final File home = new File(userHome);
|
||||
if (!home.exists()) {
|
||||
if (home.mkdirs()) {
|
||||
System.err.println("warning: created " + home.getAbsolutePath());
|
||||
} else {
|
||||
System.err.println("warning: " + home.getAbsolutePath() + " not found");
|
||||
System.err.println("warning: using system temporary directory instead");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Use $HOME/.gerritcodereview/tmp for our temporary file area.
|
||||
//
|
||||
final File gerrithome = new File(home, ".gerritcodereview");
|
||||
if (!gerrithome.exists() && !gerrithome.mkdirs()) {
|
||||
System.err.println("warning: cannot create " + gerrithome.getAbsolutePath());
|
||||
System.err.println("warning: using system temporary directory instead");
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return gerrithome.getCanonicalFile();
|
||||
} catch (IOException e) {
|
||||
return gerrithome;
|
||||
}
|
||||
}
|
||||
|
||||
private GerritLauncher() {
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user