You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/12/19 22:44:46 UTC
[royale-compiler] branch develop updated: handle resource bundles
in source path
This is an automated email from the ASF dual-hosted git repository.
aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new 7e9cf64 handle resource bundles in source path
7e9cf64 is described below
commit 7e9cf64e7718c16e5fbc7174f0980a8f242eb799
Author: Alex Harui <ah...@apache.org>
AuthorDate: Wed Dec 19 14:44:34 2018 -0800
handle resource bundles in source path
---
.../royale/compiler/clients/MXMLJSCRoyale.java | 194 ++++++++++++---------
1 file changed, 114 insertions(+), 80 deletions(-)
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
index fa92700..8d9445c 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java
@@ -22,6 +22,7 @@ package org.apache.royale.compiler.clients;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
@@ -678,92 +679,125 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
final ISWC swc = swcManager.get(new File(cu.getAbsoluteFilename()));
if (swc != null)
{
- String bundleName = cu.getBundleNameInColonSyntax();
- String propFileName = "locale/" + cu.getLocale() + "/" + bundleName + ".properties";
- String bundleClassName = cu.getLocale() + "$" + bundleName + "_properties";
- Map<String, ISWCFileEntry> files = swc.getFiles();
- for (String key : files.keySet())
+ if (swc.getSWCFile().getAbsolutePath().endsWith(".swc"))
{
- if (key.equals(propFileName))
- {
- if (!project.compiledResourceBundleNames.contains(bundleName))
- project.compiledResourceBundleNames.add(bundleName);
- project.compiledResourceBundleClasses.add(bundleClassName);
- StringBuilder sb = new StringBuilder();
- ISWCFileEntry fileEntry = swc.getFile(key);
- if (fileEntry != null)
- {
- try {
- InputStream is = fileEntry.createInputStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(is));
- String line;
- while ((line = br.readLine()) != null)
- {
- if (line.contains("="))
- {
- if (sb.length() == 0)
- {
- sb.append("/**\n");
- sb.append(" * Generated by Apache Royale Compiler from " + bundleClassName + ".properties\n");
- sb.append(" * " + bundleClassName + "\n");
- sb.append(" *\n");
- sb.append(" * @fileoverview\n");
- sb.append(" *\n");
- sb.append(" * @suppress {checkTypes|accessControls}\n");
- sb.append(" */\n\n");
- sb.append("goog.provide('" + bundleClassName + "');\n\n");
- sb.append("goog.require('mx.resources.IResourceBundle');\n");
- sb.append("goog.require('mx.resources.ResourceBundle');\n\n\n");
- sb.append("/**\n");
- sb.append(" * @constructor\n");
- sb.append(" * @extends {mx.resources.ResourceBundle}\n");
- sb.append(" * @implements {mx.resources.IResourceBundle}\n");
- sb.append(" */\n");
- sb.append(bundleClassName + " = function() {\n");
- sb.append(" " + bundleClassName + ".base(this, 'constructor');\n");
- sb.append("};\n");
- sb.append("goog.inherits(" + bundleClassName + ", mx.resources.ResourceBundle);\n\n");
- sb.append("/**\n");
- sb.append(" * Prevent renaming of class. Needed for reflection.\n");
- sb.append(" */\n");
- sb.append("goog.exportSymbol('" + bundleClassName + "', " + bundleClassName + ");\n\n");
- sb.append(bundleClassName + ".prototype.getContent = function() { return {\n");
- }
- int c = line.indexOf("=");
- String propName = line.substring(0, c);
- String value = line.substring(c + 1);
- while (value.endsWith("/"))
- {
- value = value.substring(0, value.length() - 1);
- value += br.readLine();
- }
- sb.append(propName + ": \"" + value + "\",\n");
- }
+ String bundleName = cu.getBundleNameInColonSyntax();
+ String propFileName = "locale/" + cu.getLocale() + "/" + bundleName + ".properties";
+ String bundleClassName = cu.getLocale() + "$" + bundleName + "_properties";
+ Map<String, ISWCFileEntry> files = swc.getFiles();
+ for (String key : files.keySet())
+ {
+ if (key.equals(propFileName))
+ {
+ if (!project.compiledResourceBundleNames.contains(bundleName))
+ project.compiledResourceBundleNames.add(bundleName);
+ project.compiledResourceBundleClasses.add(bundleClassName);
+ ISWCFileEntry fileEntry = swc.getFile(key);
+ if (fileEntry != null)
+ {
+ InputStream is;
+ try {
+ is = fileEntry.createInputStream();
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ writeResourceBundle(br, bundleClassName, outputFolder);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
}
- sb.append("__end_of_bundle__: 0\n};};\n");
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- final File outputClassFile = getOutputClassFile(
- bundleClassName, outputFolder);
- System.out.println("Generating resource file: " + outputClassFile);
- FileWriter fw;
- try {
- fw = new FileWriter(outputClassFile, false);
- fw.write(sb.toString());
- fw.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ }
+ }
+ }
+ }
+ else
+ {
+ // it isn't a bundle from a SWC, it is a bundle in the source path
+ String bundleName = cu.getBundleNameInColonSyntax();
+ String propFileName = swc.getSWCFile().getAbsolutePath();
+ String bundleClassName = cu.getLocale() + "$" + bundleName + "_properties";
+ if (!project.compiledResourceBundleNames.contains(bundleName))
+ project.compiledResourceBundleNames.add(bundleName);
+ project.compiledResourceBundleClasses.add(bundleClassName);
+ InputStream is;
+ try {
+ is = new FileInputStream(swc.getSWCFile());
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ writeResourceBundle(br, bundleClassName, outputFolder);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
}
-
}
+ private void writeResourceBundle(BufferedReader br, String bundleClassName, File outputFolder)
+ {
+ StringBuilder sb = new StringBuilder();
+ try {
+ String line;
+ while ((line = br.readLine()) != null)
+ {
+ if (line.contains("="))
+ {
+ if (sb.length() == 0)
+ {
+ sb.append("/**\n");
+ sb.append(" * Generated by Apache Royale Compiler from " + bundleClassName + ".properties\n");
+ sb.append(" * " + bundleClassName + "\n");
+ sb.append(" *\n");
+ sb.append(" * @fileoverview\n");
+ sb.append(" *\n");
+ sb.append(" * @suppress {checkTypes|accessControls}\n");
+ sb.append(" */\n\n");
+ sb.append("goog.provide('" + bundleClassName + "');\n\n");
+ sb.append("goog.require('mx.resources.IResourceBundle');\n");
+ sb.append("goog.require('mx.resources.ResourceBundle');\n\n\n");
+ sb.append("/**\n");
+ sb.append(" * @constructor\n");
+ sb.append(" * @extends {mx.resources.ResourceBundle}\n");
+ sb.append(" * @implements {mx.resources.IResourceBundle}\n");
+ sb.append(" */\n");
+ sb.append(bundleClassName + " = function() {\n");
+ sb.append(" " + bundleClassName + ".base(this, 'constructor');\n");
+ sb.append("};\n");
+ sb.append("goog.inherits(" + bundleClassName + ", mx.resources.ResourceBundle);\n\n");
+ sb.append("/**\n");
+ sb.append(" * Prevent renaming of class. Needed for reflection.\n");
+ sb.append(" */\n");
+ sb.append("goog.exportSymbol('" + bundleClassName + "', " + bundleClassName + ");\n\n");
+ sb.append(bundleClassName + ".prototype.getContent = function() { return {\n");
+ }
+ int c = line.indexOf("=");
+ String propName = line.substring(0, c);
+ String value = line.substring(c + 1);
+ while (value.endsWith("/"))
+ {
+ value = value.substring(0, value.length() - 1);
+ value += br.readLine();
+ }
+ sb.append(propName + ": \"" + value + "\",\n");
+ }
+ }
+ sb.append("__end_of_bundle__: 0\n};};\n");
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ final File outputClassFile = getOutputClassFile(
+ bundleClassName, outputFolder);
+ System.out.println("Generating resource file: " + outputClassFile);
+ FileWriter fw;
+ try {
+ fw = new FileWriter(outputClassFile, false);
+ fw.write(sb.toString());
+ fw.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
/**
* Build target artifact.
*