Skip to content
This repository was archived by the owner on Sep 26, 2020. It is now read-only.

Commit 8043aa6

Browse files
author
skybrian@google.com
committed
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 Review-Link: https://gwt-review.googlesource.com/#/c/2540/ git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@11597 8db76d5a-ed1c-0410-87a9-c151d255dfc7
1 parent 4f47fa6 commit 8043aa6

File tree

5 files changed

+133
-16
lines changed

5 files changed

+133
-16
lines changed

dev/codeserver/java/com/google/gwt/dev/codeserver/CodeServer.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public static void main(String[] args) throws Exception {
4646
System.exit(1);
4747
}
4848

49+
main(options);
50+
}
51+
52+
/**
53+
* Starts the code server with the given options. Shuts down the JVM if startup fails.
54+
*/
55+
public static void main(Options options) {
4956
if (options.isCompileTest()) {
5057
PrintWriterTreeLogger logger = new PrintWriterTreeLogger();
5158
logger.setMaxDetail(TreeLogger.Type.INFO);
@@ -110,7 +117,8 @@ private static Modules makeModules(Options options, PrintWriterTreeLogger logger
110117
AppSpace appSpace = AppSpace.create(new File(workDir, moduleName));
111118

112119
Recompiler recompiler = new Recompiler(appSpace, moduleName,
113-
options.getSourcePath(), options.getPreferredHost() + ":" + options.getPort(), logger);
120+
options.getSourcePath(), options.getPreferredHost() + ":" + options.getPort(),
121+
options.getRecompileListener(), options.isCompileTest(), logger);
114122
modules.addModuleState(new ModuleState(recompiler, logger, options.getNoPrecompile()));
115123
}
116124
return modules;

dev/codeserver/java/com/google/gwt/dev/codeserver/CompileDir.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,63 @@
2626
* the app, we will create a new, empty CompileDir. This way, a failed compile doesn't
2727
* modify the last good compile.
2828
*
29-
* The CompileDir gets created within the appropriate {@link AppSpace} for the app
29+
* <p>The CompileDir gets created within the appropriate {@link AppSpace} for the app
3030
* being compiled.
3131
*/
32-
class CompileDir {
32+
public class CompileDir {
3333
private final File dir;
3434

3535
/**
3636
* @see #create
3737
*/
38-
private CompileDir(File dir) {
38+
public CompileDir(File dir) {
3939
this.dir = dir;
4040
}
4141

42-
File getWarDir() {
42+
/**
43+
* Top-level directory, containing the others.
44+
*/
45+
public File getRoot() {
46+
return dir;
47+
}
48+
49+
/**
50+
* The directory tree where the compiler saves output files that should be available
51+
* via HTTP. It will be in a subdirectory based on the module name, possibly after
52+
* renaming. Files will be accessible via HTTP until a new compile finishes successfully.
53+
*/
54+
public File getWarDir() {
4355
return new File(dir, "war");
4456
}
4557

4658
File getDeployDir() {
4759
return new File(getWarDir(), "WEB-INF/deploy");
4860
}
4961

50-
File getExtraDir() {
62+
/**
63+
* The directory where the compiler saves auxiliary files that shouldn't be available via HTTP.
64+
*/
65+
public File getExtraDir() {
5166
return new File(dir, "extras");
5267
}
5368

54-
File getGenDir() {
69+
/**
70+
* The directory tree where the compiler saves source code created by GWT generators.
71+
* The source is also accessible via HTTP, for use by browser debuggers.
72+
*/
73+
public File getGenDir() {
5574
return new File(dir, "gen");
5675
}
5776

5877
File getWorkDir() {
5978
return new File(dir, "work");
6079
}
6180

62-
File getLogFile() {
81+
/**
82+
* The file where the GWT compiler writes compile errors and warnings.
83+
* Also accessible via HTTP.
84+
*/
85+
public File getLogFile() {
6386
return new File(dir, "compile.log");
6487
}
6588

dev/codeserver/java/com/google/gwt/dev/codeserver/Options.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class Options {
4545
private String bindAddress = "127.0.0.1";
4646
private String preferredHost = "localhost";
4747
private int port = 9876;
48+
private RecompileListener recompileListener = RecompileListener.NONE;
4849

4950
/**
5051
* Sets each option to the appropriate value, based on command-line arguments.
@@ -70,6 +71,18 @@ public boolean parseArgs(String[] args) {
7071
return true;
7172
}
7273

74+
/**
75+
* A Java application that embeds Super Dev Mode can use this hook to find out
76+
* when compiles start and end.
77+
*/
78+
public void setRecompileListener(RecompileListener recompileListener) {
79+
this.recompileListener = recompileListener;
80+
}
81+
82+
RecompileListener getRecompileListener() {
83+
return recompileListener;
84+
}
85+
7386
/**
7487
* The top level of the directory tree where the code server keeps compiler output.
7588
*/
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.google.gwt.dev.codeserver;
2+
3+
/**
4+
* A callback interface that can be used to find out when Super Dev Mode starts and
5+
* finishes its compiles.
6+
*/
7+
public interface RecompileListener {
8+
9+
/**
10+
* Called when starting a compile.
11+
* @param moduleName The name of the module being compiled, before renaming.
12+
* @param compileId An id for this compile, starting from 1 for the first compile.
13+
* The combination of (moduleName, compileId) is unique within
14+
* a Code Server process. After the CodeServer is restarted, starts again from 1.
15+
* @param compileDir The directory used for this compile. Contains subdirectories for
16+
* working files and compiler output.
17+
*/
18+
void startedCompile(String moduleName, int compileId, CompileDir compileDir);
19+
20+
/**
21+
* Called when a compile finishes.
22+
* @param moduleName The same name passed to startedCompile
23+
* @param compileId The same id passed to startedCompile
24+
* @param success True if the compile succeeded.
25+
*/
26+
void finishedCompile(String moduleName, int compileId, boolean success);
27+
28+
/**
29+
* A listener that does nothing.
30+
*/
31+
RecompileListener NONE = new RecompileListener() {
32+
@Override
33+
public void startedCompile(String moduleName, int compileId, CompileDir compileDir) {
34+
}
35+
36+
@Override
37+
public void finishedCompile(String moduleName, int compileId, boolean success) {
38+
}
39+
};
40+
41+
}

dev/codeserver/java/com/google/gwt/dev/codeserver/Recompiler.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class Recompiler {
5050
private final AppSpace appSpace;
5151
private final String originalModuleName;
5252
private final List<File> sourcePath;
53+
private final RecompileListener listener;
54+
private final boolean failIfListenerFails;
5355
private final TreeLogger logger;
5456
private String serverPrefix;
5557
private int compilesDone = 0;
@@ -62,10 +64,13 @@ class Recompiler {
6264
new AtomicReference<ResourceLoader>();
6365

6466
Recompiler(AppSpace appSpace, String moduleName, List<File> sourcePath,
65-
String serverPrefix, TreeLogger logger) {
67+
String serverPrefix, RecompileListener listener, boolean failIfListenerFails,
68+
TreeLogger logger) {
6669
this.appSpace = appSpace;
6770
this.originalModuleName = moduleName;
6871
this.sourcePath = sourcePath;
72+
this.listener = listener;
73+
this.failIfListenerFails = failIfListenerFails;
6974
this.logger = logger;
7075
this.serverPrefix = serverPrefix;
7176
}
@@ -82,25 +87,52 @@ synchronized CompileDir compile(Map<String, String> bindingProperties)
8287
}
8388

8489
long startTime = System.currentTimeMillis();
85-
CompileDir compileDir = makeCompileDir(++compilesDone);
90+
int compileId = ++compilesDone;
91+
CompileDir compileDir = makeCompileDir(compileId);
8692
TreeLogger compileLogger = makeCompileLogger(compileDir);
8793

88-
ModuleDef module = loadModule(compileLogger, bindingProperties);
89-
String newModuleName = module.getName(); // includes any rename
90-
moduleName.set(newModuleName);
94+
boolean listenerFailed = false;
95+
try {
96+
listener.startedCompile(originalModuleName, compileId, compileDir);
97+
} catch (Exception e) {
98+
compileLogger.log(TreeLogger.Type.WARN, "listener threw exception", e);
99+
listenerFailed = true;
100+
}
91101

102+
boolean success = false;
103+
try {
92104

93-
CompilerOptions options = new CompilerOptionsImpl(compileDir, newModuleName);
105+
ModuleDef module = loadModule(compileLogger, bindingProperties);
106+
String newModuleName = module.getName(); // includes any rename
107+
moduleName.set(newModuleName);
108+
109+
110+
CompilerOptions options = new CompilerOptionsImpl(compileDir, newModuleName);
111+
112+
success = new Compiler(options).run(compileLogger, module);
113+
lastBuild.set(compileDir); // makes compile log available over HTTP
114+
115+
} finally {
116+
try {
117+
listener.finishedCompile(originalModuleName, compileId, success);
118+
} catch (Exception e) {
119+
compileLogger.log(TreeLogger.Type.WARN, "listener threw exception", e);
120+
listenerFailed = true;
121+
}
122+
}
94123

95-
boolean success = new Compiler(options).run(compileLogger, module);
96-
lastBuild.set(compileDir);
97124
if (!success) {
98125
compileLogger.log(TreeLogger.Type.ERROR, "Compiler returned " + success);
99126
throw new UnableToCompleteException();
100127
}
101128

102129
long elapsedTime = System.currentTimeMillis() - startTime;
103130
compileLogger.log(TreeLogger.Type.INFO, "Compile completed in " + elapsedTime + " ms");
131+
132+
if (failIfListenerFails && listenerFailed) {
133+
throw new UnableToCompleteException();
134+
}
135+
104136
return compileDir;
105137
}
106138

0 commit comments

Comments
 (0)