Brian Slesinsky has uploaded a new change for review.
https://gwt-review.googlesource.com/2540
Change subject: Add callbacks to Super Dev Mode to find out when a compile
starts and finishes, and an alternate main() that can be called after
parsing options.
......................................................................
Add callbacks to Super Dev Mode to find out when a compile starts and
finishes,
and an alternate main() that can be called after parsing options.
Change-Id: I2a27a07d2c8219d496613b1c1c88380c6dc3d032
---
M dev/codeserver/java/com/google/gwt/dev/codeserver/CodeServer.java
M dev/codeserver/java/com/google/gwt/dev/codeserver/CompileDir.java
M dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
A dev/codeserver/java/com/google/gwt/dev/codeserver/RecompileListener.java
M dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java
5 files changed, 133 insertions(+), 16 deletions(-)
diff --git
a/dev/codeserver/java/com/google/gwt/dev/codeserver/CodeServer.java
b/dev/codeserver/java/com/google/gwt/dev/codeserver/CodeServer.java
index 53e78b4..01f3a65 100644
--- a/dev/codeserver/java/com/google/gwt/dev/codeserver/CodeServer.java
+++ b/dev/codeserver/java/com/google/gwt/dev/codeserver/CodeServer.java
@@ -46,6 +46,13 @@
System.exit(1);
}
+ main(options);
+ }
+
+ /**
+ * Starts the code server with the given options. Shuts down the JVM if
startup fails.
+ */
+ public static void main(Options options) {
if (options.isCompileTest()) {
PrintWriterTreeLogger logger = new PrintWriterTreeLogger();
logger.setMaxDetail(TreeLogger.Type.INFO);
@@ -110,7 +117,8 @@
AppSpace appSpace = AppSpace.create(new File(workDir, moduleName));
Recompiler recompiler = new Recompiler(appSpace, moduleName,
- options.getSourcePath(), options.getPreferredHost() + ":" +
options.getPort(), logger);
+ options.getSourcePath(), options.getPreferredHost() + ":" +
options.getPort(),
+ options.getRecompileListener(), options.isCompileTest(), logger);
modules.addModuleState(new ModuleState(recompiler, logger,
options.getNoPrecompile()));
}
return modules;
diff --git
a/dev/codeserver/java/com/google/gwt/dev/codeserver/CompileDir.java
b/dev/codeserver/java/com/google/gwt/dev/codeserver/CompileDir.java
index aedf3e2..a32b7ed 100644
--- a/dev/codeserver/java/com/google/gwt/dev/codeserver/CompileDir.java
+++ b/dev/codeserver/java/com/google/gwt/dev/codeserver/CompileDir.java
@@ -26,20 +26,32 @@
* the app, we will create a new, empty CompileDir. This way, a failed
compile doesn't
* modify the last good compile.
*
- * The CompileDir gets created within the appropriate {@link AppSpace} for
the app
+ * <p>The CompileDir gets created within the appropriate {@link AppSpace}
for the app
* being compiled.
*/
-class CompileDir {
+public class CompileDir {
private final File dir;
/**
* @see #create
*/
- private CompileDir(File dir) {
+ public CompileDir(File dir) {
this.dir = dir;
}
- File getWarDir() {
+ /**
+ * Top-level directory, containing the others.
+ */
+ public File getRoot() {
+ return dir;
+ }
+
+ /**
+ * The directory tree where the compiler saves output files that should
be available
+ * via HTTP. It will be in a subdirectory based on the module name,
possibly after
+ * renaming. Files will be accessible via HTTP until a new compile
finishes successfully.
+ */
+ public File getWarDir() {
return new File(dir, "war");
}
@@ -47,11 +59,18 @@
return new File(getWarDir(), "WEB-INF/deploy");
}
- File getExtraDir() {
+ /**
+ * The directory where the compiler saves auxiliary files that shouldn't
be available via HTTP.
+ */
+ public File getExtraDir() {
return new File(dir, "extras");
}
- File getGenDir() {
+ /**
+ * The directory tree where the compiler saves source code created by
GWT generators.
+ * The source is also accessible via HTTP, for use by browser debuggers.
+ */
+ public File getGenDir() {
return new File(dir, "gen");
}
@@ -59,7 +78,11 @@
return new File(dir, "work");
}
- File getLogFile() {
+ /**
+ * The file where the GWT compiler writes compile errors and warnings.
+ * Also accessible via HTTP.
+ */
+ public File getLogFile() {
return new File(dir, "compile.log");
}
diff --git a/dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
b/dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
index 38a9a94..08380bd 100644
--- a/dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
+++ b/dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java
@@ -45,6 +45,7 @@
private String bindAddress = "127.0.0.1";
private String preferredHost = "localhost";
private int port = 9876;
+ private RecompileListener recompileListener = RecompileListener.NONE;
/**
* Sets each option to the appropriate value, based on command-line
arguments.
@@ -71,6 +72,18 @@
}
/**
+ * A Java application that embeds Super Dev Mode can use this hook to
find out
+ * when compiles start and end.
+ */
+ public void setRecompileListener(RecompileListener recompileListener) {
+ this.recompileListener = recompileListener;
+ }
+
+ RecompileListener getRecompileListener() {
+ return recompileListener;
+ }
+
+ /**
* The top level of the directory tree where the code server keeps
compiler output.
*/
File getWorkDir() {
diff --git
a/dev/codeserver/java/com/google/gwt/dev/codeserver/RecompileListener.java
b/dev/codeserver/java/com/google/gwt/dev/codeserver/RecompileListener.java
new file mode 100644
index 0000000..907f3cb
--- /dev/null
+++
b/dev/codeserver/java/com/google/gwt/dev/codeserver/RecompileListener.java
@@ -0,0 +1,41 @@
+package com.google.gwt.dev.codeserver;
+
+/**
+ * A callback interface that can be used to find out when Super Dev Mode
starts and
+ * finishes its compiles.
+ */
+public interface RecompileListener {
+
+ /**
+ * Called when starting a compile.
+ * @param moduleName The name of the module being compiled, before
renaming.
+ * @param compileId An id for this compile, starting from 1 for the
first compile.
+ * The combination of (moduleName, compileId) is unique
within
+ * a Code Server process. After the CodeServer is
restarted, starts again from 1.
+ * @param compileDir The directory used for this compile. Contains
subdirectories for
+ * working files and compiler output.
+ */
+ void startedCompile(String moduleName, int compileId, CompileDir
compileDir);
+
+ /**
+ * Called when a compile finishes.
+ * @param moduleName The same name passed to startedCompile
+ * @param compileId The same id passed to startedCompile
+ * @param success True if the compile succeeded.
+ */
+ void finishedCompile(String moduleName, int compileId, boolean success);
+
+ /**
+ * A listener that does nothing.
+ */
+ RecompileListener NONE = new RecompileListener() {
+ @Override
+ public void startedCompile(String moduleName, int compileId,
CompileDir compileDir) {
+ }
+
+ @Override
+ public void finishedCompile(String moduleName, int compileId, boolean
success) {
+ }
+ };
+
+}
diff --git
a/dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java
b/dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java
index 2dcfc02..025c2b9 100644
--- a/dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java
+++ b/dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java
@@ -50,6 +50,8 @@
private final AppSpace appSpace;
private final String originalModuleName;
private final List<File> sourcePath;
+ private final RecompileListener listener;
+ private final boolean failIfListenerFails;
private final TreeLogger logger;
private String serverPrefix;
private int compilesDone = 0;
@@ -62,10 +64,13 @@
new AtomicReference<ResourceLoader>();
Recompiler(AppSpace appSpace, String moduleName, List<File> sourcePath,
- String serverPrefix, TreeLogger logger) {
+ String serverPrefix, RecompileListener listener, boolean
failIfListenerFails,
+ TreeLogger logger) {
this.appSpace = appSpace;
this.originalModuleName = moduleName;
this.sourcePath = sourcePath;
+ this.listener = listener;
+ this.failIfListenerFails = failIfListenerFails;
this.logger = logger;
this.serverPrefix = serverPrefix;
}
@@ -82,18 +87,40 @@
}
long startTime = System.currentTimeMillis();
- CompileDir compileDir = makeCompileDir(++compilesDone);
+ int compileId = ++compilesDone;
+ CompileDir compileDir = makeCompileDir(compileId);
TreeLogger compileLogger = makeCompileLogger(compileDir);
- ModuleDef module = loadModule(compileLogger, bindingProperties);
- String newModuleName = module.getName(); // includes any rename
- moduleName.set(newModuleName);
+ boolean listenerFailed = false;
+ try {
+ listener.startedCompile(originalModuleName, compileId, compileDir);
+ } catch (Exception e) {
+ compileLogger.log(TreeLogger.Type.WARN, "listener threw exception",
e);
+ listenerFailed = true;
+ }
+
+ boolean success = false;
+ try {
+
+ ModuleDef module = loadModule(compileLogger, bindingProperties);
+ String newModuleName = module.getName(); // includes any rename
+ moduleName.set(newModuleName);
- CompilerOptions options = new CompilerOptionsImpl(compileDir,
newModuleName);
+ CompilerOptions options = new CompilerOptionsImpl(compileDir,
newModuleName);
- boolean success = new Compiler(options).run(compileLogger, module);
- lastBuild.set(compileDir);
+ success = new Compiler(options).run(compileLogger, module);
+ lastBuild.set(compileDir); // makes compile log available over HTTP
+
+ } finally {
+ try {
+ listener.finishedCompile(originalModuleName, compileId, success);
+ } catch (Exception e) {
+ compileLogger.log(TreeLogger.Type.WARN, "listener threw
exception", e);
+ listenerFailed = true;
+ }
+ }
+
if (!success) {
compileLogger.log(TreeLogger.Type.ERROR, "Compiler returned " +
success);
throw new UnableToCompleteException();
@@ -101,6 +128,11 @@
long elapsedTime = System.currentTimeMillis() - startTime;
compileLogger.log(TreeLogger.Type.INFO, "Compile completed in " +
elapsedTime + " ms");
+
+ if (failIfListenerFails && listenerFailed) {
+ throw new UnableToCompleteException();
+ }
+
return compileDir;
}
--
To view, visit https://gwt-review.googlesource.com/2540
To unsubscribe, visit https://gwt-review.googlesource.com/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a27a07d2c8219d496613b1c1c88380c6dc3d032
Gerrit-PatchSet: 1
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Brian Slesinsky <skybr...@google.com>
--
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "Google Web Toolkit Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.