Repository: flex-falcon Updated Branches: refs/heads/develop 7405eca0b -> e880f34d5
add -html-template option so FalconJX will fill in a template instead of generating an index.html file and add a -html-output-filename option so the output file doesn't have to be called index.html Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/3afe7741 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/3afe7741 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/3afe7741 Branch: refs/heads/develop Commit: 3afe7741f559ac214de4ef0beb14ca456cfe9010 Parents: 796b5e8 Author: Alex Harui <[email protected]> Authored: Tue Sep 27 12:06:51 2016 -0700 Committer: Alex Harui <[email protected]> Committed: Tue Sep 27 12:06:51 2016 -0700 ---------------------------------------------------------------------- .../mxml/flexjs/MXMLFlexJSPublisher.java | 77 +++++++++++++++++++- .../driver/js/goog/JSGoogConfiguration.java | 46 ++++++++++++ .../internal/projects/FlexJSProject.java | 24 ++++++ 3 files changed, 144 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3afe7741/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java index 64b3c86..e8287b3 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java @@ -18,6 +18,7 @@ */ package org.apache.flex.compiler.internal.codegen.mxml.flexjs; +import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -53,6 +54,10 @@ import org.apache.flex.compiler.internal.driver.js.flexjs.JSCSSCompilationSessio import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration; import org.apache.flex.compiler.internal.graph.GoogDepsWriter; import org.apache.flex.compiler.internal.projects.FlexJSProject; +import org.apache.flex.compiler.internal.targets.ITargetAttributes; +import org.apache.flex.compiler.targets.ISWFTarget; +import org.apache.flex.compiler.targets.ITargetReport; +import org.apache.flex.compiler.targets.ITargetSettings; import org.apache.flex.compiler.utils.JSClosureCompilerWrapper; import org.apache.flex.swc.ISWC; import org.apache.flex.swc.ISWCFileEntry; @@ -419,10 +424,21 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher // File srcDeps = new File(depsSrcFilePath); + File template = ((JSGoogConfiguration)configuration).getHtmlTemplate(); if (!((JSGoogConfiguration)configuration).getSkipTranspile()) - writeHTML("intermediate", projectName, intermediateDirPath, depsFileData.toString(), gdw.additionalHTML); + { + if (template != null) + writeTemplate(template, "intermediate", projectName, intermediateDirPath, depsFileData.toString(), gdw.additionalHTML); + else + writeHTML("intermediate", projectName, intermediateDirPath, depsFileData.toString(), gdw.additionalHTML); + } if (!configuration.debug()) - writeHTML("release", projectName, releaseDirPath, null, gdw.additionalHTML); + { + if (template != null) + writeTemplate(template, "release", projectName, intermediateDirPath, depsFileData.toString(), gdw.additionalHTML); + else + writeHTML("release", projectName, releaseDirPath, null, gdw.additionalHTML); + } if (project.needCSS || ((JSGoogConfiguration)configuration).getSkipTranspile()) { if (!((JSGoogConfiguration)configuration).getSkipTranspile()) @@ -564,6 +580,61 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher return code; } + protected void writeTemplate(File template, String type, String projectName, String dirPath, String deps, List<String> additionalHTML) + throws IOException + { + String input = readCode(template); + ITargetAttributes ta = project.computeTargetAttributes(); + Float width = ta.getWidth(); + Float height = ta.getHeight(); + String result = input.replaceAll("\\$\\{application\\}", projectName); + result = result.replaceAll("\\$\\{bgcolor\\}", ta.getBackgroundColor()); + //result = result.replaceAll("\\$\\{expressInstallSwf\\}", expressInstallSwf); + if (height != null) + result = result.replaceAll("\\$\\{height\\}", height.toString()); + result = result.replaceAll("\\$\\{title\\}", ta.getPageTitle()); + //result = result.replaceAll("\\$\\{version_major\\}", versionMajor); + //result = result.replaceAll("\\$\\{version_minor\\}", versionMinor); + //result = result.replaceAll("\\$\\{version_revision\\}", versionRevision); + if (width != null) + result = result.replaceAll("\\$\\{width\\}", width.toString()); + //result = result.replaceAll("\\$\\{useBrowserHistory\\}", useBrowserHistory); + + StringBuilder addHTML = new StringBuilder(); + for (String s : additionalHTML) + addHTML.append(s).append("\n"); + + if ("intermediate".equals(type)) + { + addHTML.append("\t<script type=\"text/javascript\" src=\"./library/closure/goog/base.js\"></script>\n"); + addHTML.append("\t<script type=\"text/javascript\">\n"); + addHTML.append(deps); + addHTML.append("\t\tgoog.require(\""); + addHTML.append(projectName); + addHTML.append("\");\n"); + addHTML.append("\t</script>\n"); + } + else + { + addHTML.append("\t<script type=\"text/javascript\" src=\"./"); + addHTML.append(projectName); + addHTML.append(".js\"></script>\n"); + } + result = result.replaceAll("\\$\\{head\\}", addHTML.toString()); + + StringBuilder htmlFile = new StringBuilder(); + htmlFile.append("\t<script type=\"text/javascript\">\n"); + htmlFile.append("\t\tnew "); + htmlFile.append(projectName); + htmlFile.append("()"); + htmlFile.append(".start();\n"); + htmlFile.append("\t</script>\n"); + + result = result.replaceAll("\\$\\{body\\}", htmlFile.toString()); + + writeFile(dirPath + File.separator + ((JSGoogConfiguration) configuration).getHtmlOutputFileName(), result, false); + } + protected void writeHTML(String type, String projectName, String dirPath, String deps, List<String> additionalHTML) throws IOException { @@ -606,7 +677,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher htmlFile.append("</body>\n"); htmlFile.append("</html>"); - writeFile(dirPath + File.separator + "index.html", htmlFile.toString(), false); + writeFile(dirPath + File.separator + ((JSGoogConfiguration) configuration).getHtmlOutputFileName(), htmlFile.toString(), false); } private void writeCSS(String projectName, String dirPath) throws IOException http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3afe7741/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java index 6eb1037..40bdcfc 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/driver/js/goog/JSGoogConfiguration.java @@ -29,6 +29,7 @@ import org.apache.flex.compiler.clients.JSConfiguration; import org.apache.flex.compiler.clients.MXMLJSC; import org.apache.flex.compiler.config.ConfigurationValue; import org.apache.flex.compiler.exceptions.ConfigurationException; +import org.apache.flex.compiler.internal.config.annotations.Arguments; import org.apache.flex.compiler.internal.config.annotations.Config; import org.apache.flex.compiler.internal.config.annotations.FlexOnly; import org.apache.flex.compiler.internal.config.annotations.InfiniteArguments; @@ -328,4 +329,49 @@ public class JSGoogConfiguration extends JSConfiguration { jsOutputOptimizations.addAll(value); } + + // 'html-template' option + // + + private String htmlTemplateFileName = null; + + public File getHtmlTemplate() + { + return htmlTemplateFileName != null ? new File(htmlTemplateFileName) : null; + } + + /** + * Specify an HTML template with tokens to replace with application-specific values. + * If not specified a standard template is generated. + */ + @Config(advanced = true) + @Mapping("html-template") + @Arguments("filename") + public void setHtmlTemplate(ConfigurationValue cv, String filename) + { + this.htmlTemplateFileName = getOutputPath(cv, filename); + } + + // 'html-output-filename' option + // + + private String htmlOutputFileName = "index.html"; + + public String getHtmlOutputFileName() + { + return htmlOutputFileName; + } + + /** + * Specify the name of the HTML file that goes in the output folder. Default is index.html. + */ + @Config(advanced = true) + @Mapping("html-output-filename") + @Arguments("filename") + public void setHtmlOutputFileName(ConfigurationValue cv, String filename) + { + this.htmlOutputFileName = filename; + } + + } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3afe7741/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java index 3f4ef14..b63ceb0 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/projects/FlexJSProject.java @@ -36,11 +36,16 @@ import org.apache.flex.compiler.internal.definitions.InterfaceDefinition; import org.apache.flex.compiler.internal.driver.js.flexjs.JSCSSCompilationSession; import org.apache.flex.compiler.internal.driver.js.goog.JSGoogConfiguration; import org.apache.flex.compiler.internal.scopes.ASProjectScope.DefinitionPromise; +import org.apache.flex.compiler.internal.targets.ITargetAttributes; import org.apache.flex.compiler.internal.targets.LinkageChecker; +import org.apache.flex.compiler.internal.tree.as.FileNode; +import org.apache.flex.compiler.internal.tree.mxml.MXMLDocumentNode; +import org.apache.flex.compiler.internal.tree.mxml.MXMLFileNode; import org.apache.flex.compiler.internal.units.SWCCompilationUnit; import org.apache.flex.compiler.internal.workspaces.Workspace; import org.apache.flex.compiler.targets.ITargetSettings; import org.apache.flex.compiler.tree.as.IASNode; +import org.apache.flex.compiler.tree.as.IDefinitionNode; import org.apache.flex.compiler.units.ICompilationUnit; /** @@ -330,4 +335,23 @@ public class FlexJSProject extends FlexProject return MXMLFlexJSEmitterTokens.ID_PREFIX.getToken(); } + public ITargetAttributes computeTargetAttributes() + { + List<String> names; + try { + names = mainCU.getQualifiedNames(); + IDefinition def = this.resolveQNameToDefinition(names.get(0)); + IDefinitionNode node = def.getNode(); + if (node instanceof MXMLDocumentNode) + { + MXMLDocumentNode mxmlDoc = (MXMLDocumentNode)node; + MXMLFileNode mxmlFile = (MXMLFileNode)mxmlDoc.getParent(); + return mxmlFile.getTargetAttributes(this); + } + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } }
