/**
* Invokes GWTCompile on the apps specified in the configuration file.
*/
protected void doGWTCompile() throws EnunciateException, IOException {
if (this.gwtHome == null) {
throw new EnunciateException("To compile a GWT app you must specify the GWT home directory, either in configuration, by setting the GWT_HOME environment variable, or setting the 'gwt.home' system property.");
}
File gwtHomeDir = new File(this.gwtHome);
if (!gwtHomeDir.exists()) {
throw new EnunciateException("GWT home not found ('" + gwtHomeDir.getAbsolutePath() + "').");
}
File gwtUserJar = new File(gwtHomeDir, "gwt-user.jar");
if (!gwtUserJar.exists()) {
warn("Unable to find %s. You may be GWT compile errors.", gwtUserJar.getAbsolutePath());
}
//now we have to find gwt-dev.jar.
//start by assuming linux...
File gwtDevJar = new File(gwtHomeDir, "gwt-dev.jar");
if (!gwtDevJar.exists()) {
File linuxDevJar = new File(gwtHomeDir, "gwt-dev-linux.jar");
gwtDevJar = linuxDevJar;
if (!gwtDevJar.exists()) {
//linux not found. try mac...
File macDevJar = new File(gwtHomeDir, "gwt-dev-mac.jar");
gwtDevJar = macDevJar;
if (!gwtDevJar.exists()) {
//okay, we'll try windows if we have to...
File windowsDevJar = new File(gwtHomeDir, "gwt-dev-windows.jar");
gwtDevJar = windowsDevJar;
if (!gwtDevJar.exists()) {
throw new EnunciateException(String.format("Unable to find GWT dev jar. Looked for %s, %s, and %s.", linuxDevJar.getAbsolutePath(), macDevJar.getAbsolutePath(), windowsDevJar.getAbsolutePath()));
}
}
}
}
boolean windows = false;
File javaBinDir = new File(System.getProperty("java.home"), "bin");
File javaExecutable = new File(javaBinDir, "java");
if (!javaExecutable.exists()) {
//append the "exe" for windows users.
javaExecutable = new File(javaBinDir, "java.exe");
windows = true;
}
String javaCommand = javaExecutable.getAbsolutePath();
if (!javaExecutable.exists()) {
warn("No java executable found in %s. We'll just hope the environment is set up to execute 'java'...", javaBinDir.getAbsolutePath());
javaCommand = "java";
}
StringBuilder classpath = new StringBuilder(enunciate.getEnunciateRuntimeClasspath());
//append the client-side gwt directory.
classpath.append(File.pathSeparatorChar).append(getClientSideGenerateDir().getAbsolutePath());
//append the gwt-user jar.
classpath.append(File.pathSeparatorChar).append(gwtUserJar.getAbsolutePath());
//append the gwt-dev jar.
classpath.append(File.pathSeparatorChar).append(gwtDevJar.getAbsolutePath());
//so here's the GWT compile command:
//java [extra jvm args] -cp [classpath] [compilerClass] -gen [gwt-gen-dir] -style [style] -out [out] [moduleName]
List<String> jvmargs = getGwtCompileJVMArgs();
List<String> compilerArgs = getGwtCompilerArgs();
List<String> gwtcCommand = new ArrayList<String>(jvmargs.size() + compilerArgs.size() + 11);
int argIndex = 0;
gwtcCommand.add(argIndex++, javaCommand);
for (String arg : jvmargs) {
gwtcCommand.add(argIndex++, arg);
}
gwtcCommand.add(argIndex++, "-cp");
int classpathArgIndex = argIndex; //app-specific arg.
gwtcCommand.add(argIndex++, null);
int compileClassIndex = argIndex;
gwtcCommand.add(argIndex++, getGwtCompilerClass());
gwtcCommand.add(argIndex++, "-gen");
gwtcCommand.add(argIndex++, getGwtGenDir().getAbsolutePath());
gwtcCommand.add(argIndex++, "-style");
int styleArgIndex = argIndex;
gwtcCommand.add(argIndex++, null); //app-specific arg.
gwtcCommand.add(argIndex++, gwtVersionGreaterThan(1, 5) ? "-war" : "-out");
int outArgIndex = argIndex;
gwtcCommand.add(argIndex++, null); //app-specific arg.
for (String arg : compilerArgs) {
gwtcCommand.add(argIndex++, arg);
}
int moduleNameIndex = argIndex;
gwtcCommand.add(argIndex, null); //module-specific arg.
for (GWTApp gwtApp : gwtApps) {
String appName = gwtApp.getName();
File appSource = enunciate.resolvePath(gwtApp.getSrcDir());
String style = gwtApp.getJavascriptStyle().toString();
File appDir = getAppGenerateDir(appName);
gwtcCommand.set(classpathArgIndex, classpath.toString() + File.pathSeparatorChar + appSource.getAbsolutePath());
gwtcCommand.set(styleArgIndex, style);
gwtcCommand.set(outArgIndex, appDir.getAbsolutePath());
boolean upToDate = enunciate.isUpToDate(getClientSideGenerateDir(), appDir) && enunciate.isUpToDate(appSource, appDir);
if (!upToDate) {
for (GWTAppModule appModule : gwtApp.getModules()) {
String moduleName = appModule.getName();
gwtcCommand.set(moduleNameIndex, moduleName);
debug("Executing GWTCompile for module '%s'...", moduleName);
if (enunciate.isDebug()) {
StringBuilder command = new StringBuilder();
for (String commandPiece : gwtcCommand) {
command.append(' ').append(commandPiece);
}
debug("Executing GWTCompile for module %s with the command: %s", moduleName, command);
}
ProcessBuilder processBuilder = new ProcessBuilder(gwtcCommand);
processBuilder.directory(getGenerateDir());
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
BufferedReader procReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = procReader.readLine();
while (line != null) {
line = URLDecoder.decode(line, "utf-8").replaceAll("%", "%%").trim(); //GWT URL-encodes spaces and other weird Windows characters.
info(line);
line = procReader.readLine();
}
int procCode;
try {
procCode = process.waitFor();
}
catch (InterruptedException e1) {
throw new EnunciateException("Unexpected inturruption of the GWT compile process.");
}
if (procCode != 0) {
throw new EnunciateException("GWT compile failed for module " + moduleName);
}
if (!gwtVersionGreaterThan(1, 5)) {
File moduleOutputDir = appDir;
String outputPath = appModule.getOutputPath();