@Override
public boolean compilePage(Webapp webapp, Page page) throws IOException {
String sdkType = page.getFrameworkType();
boolean isExt = sdkType.equals(JavaScriptFramework.EXTJS);
JavaScriptFramework framework = isExt ? webapp.getExt() : webapp.getSenchaTouch();
String sdkPath = isExt ? webapp.getExt().getFullPath() : webapp.getSenchaTouch().getFullPath();
String dependencyFile = isExt ? "ExtDependencies.js" : "SenchaTouchDependencies.js";
String webappSrcAbsolutePath = webapp.getFullPath() + "/src/main/webapp";
String pageAbsolutePath = webappSrcAbsolutePath + "/" + page.getPath();
/*
* Create ghosts
*/
try {
if (!createGhosts(webapp, webappSrcAbsolutePath, pageAbsolutePath, sdkType, sdkPath)) return false;
} catch (Exception e) {
throw new RuntimeException(e);
}
/*
* Compile Page
*/
String compileOutput = null;
framework.cleanCmdBugs();
try {
String[] cmdString = {
environmentService.getEnvironment().getCmdPath() + "/sencha",
"-d",
"-sdk=" + sdkPath,
"compile",
"-classpath=" +
webappSrcAbsolutePath + "/adaptrex/ghosts.js," +
pageAbsolutePath + "/app/app.js," +
pageAbsolutePath + "/app," +
webappSrcAbsolutePath + "/" + webapp.getGlobalFolder() + "," +
webapp.getAdaptrex().getFullPath() + "/" + sdkType + "/src," +
sdkPath + "/src",
"exclude","-all",
"and","include","-r","-f", pageAbsolutePath + "/app/app.js",
"and","exclude","-f", sdkPath + "/src",
"and","exclude","-f", webappSrcAbsolutePath + "/adaptrex/ghosts.js",
"and","concat", pageAbsolutePath + "/build/app-all-debug.js",
"and","concat", "-compress",pageAbsolutePath + "/build/app-all.js",
"and","save", "appset",
"and","exclude","-all",
"and","include","-r","-f", pageAbsolutePath + "/app/app.js",
"and","include","-na", "Adaptrex.override",
"and","include","-r","-f", dependencyFile,
"and","exclude","-s", "appset",
"and","exclude","-f", dependencyFile,
"and","concat", pageAbsolutePath + "/build/app-" + sdkType + "-debug.js",
"and","concat", "-compress",pageAbsolutePath + "/build/app-" + sdkType + ".js"
};
ProcessBuilder processBuilder = new ProcessBuilder(cmdString);
processBuilder.redirectErrorStream();
Process cmd = processBuilder.start();
Tools.StreamGobbler gobbler = new Tools.StreamGobbler(cmd.getInputStream());
gobbler.start();
cmd.waitFor();
compileOutput = gobbler.getGobblerOutput();
if (compileOutput.contains("[ERR]")) {
logService.log(Log.ERROR, "Error compiling page: " + page.getPath(), compileOutput);
return false;
}
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
framework.restoreCmdBugs();
}
logService.log(Log.SUCCESS, "Successfully compiled page: " + page.getPath());
return true;
}