You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2019/08/20 16:01:14 UTC
[royale-compiler] branch develop updated: MXMLRoyalePublisher:
collect inject_html from externs in SWCs
This is an automated email from the ASF dual-hosted git repository.
joshtynjala 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 f653998 MXMLRoyalePublisher: collect inject_html from externs in SWCs
f653998 is described below
commit f6539980d9c9ccb3d60472b17d9d4986904dffd8
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Aug 20 09:01:03 2019 -0700
MXMLRoyalePublisher: collect inject_html from externs in SWCs
---
.../codegen/mxml/royale/MXMLRoyalePublisher.java | 33 ++++++++++++----------
.../internal/projects/RoyaleJSProject.java | 12 +++++++-
2 files changed, 29 insertions(+), 16 deletions(-)
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
index a4f46ef..0159b25 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
@@ -395,42 +395,45 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher
// Iterate over all swc dependencies and add all the externs they contain.
// (Externs are located in a "externs" directory in the root of the SWC)
+ Set<ISWC> swcExterns = project.swcExterns;
List<ISWC> swcs = project.getLibraries();
List<ISWC> allswcs = new ArrayList<ISWC>();
allswcs.addAll(swcs);
allswcs.addAll(themeSWCs);
- if (compilerWrapper != null)
+ for (ISWC swc : allswcs)
{
- for (ISWC swc : allswcs)
+ Map<String, ISWCFileEntry> files = swc.getFiles();
+ for (String key : files.keySet())
{
- Map<String, ISWCFileEntry> files = swc.getFiles();
- for (String key : files.keySet())
+ if (key.startsWith(ROYALE_EXTERNS))
{
- if (key.startsWith(ROYALE_EXTERNS))
+ ISWCFileEntry fileEntry = swc.getFile(key);
+ if (fileEntry != null)
{
- ISWCFileEntry fileEntry = swc.getFile(key);
- if (fileEntry != null)
+ InputStream is = fileEntry.createInputStream();
+ String code = IOUtils.toString(is, "UTF-8");
+ is.close();
+
+ if (compilerWrapper != null)
{
- InputStream is = fileEntry.createInputStream();
- String code = IOUtils.toString(is, "UTF-8");
- is.close();
JarSourceFile externFile = new JarSourceFile(key, code,true);
if (googConfiguration.isVerbose())
{
System.out.println("using extern: " + key);
}
compilerWrapper.addJSExternsFile(externFile);
+ }
- // Write the extern into the filesystem.
- // FIXME: I don't know why we need to do this.
- //FileUtils.write(new File(intermediateDir, key), externFile.getCode());
+ if (swcExterns.contains(swc))
+ {
+ List<String> lines = IOUtils.readLines(new StringReader(code));
+ collectAdditionalHTML(lines, swc.getSWCFile().getAbsolutePath() + ":" + key);
}
}
}
}
}
-
/////////////////////////////////////////////////////////////////////////////////
// Add all files generated by the compiler to the compilation unit.
/////////////////////////////////////////////////////////////////////////////////
@@ -655,7 +658,7 @@ public class MXMLRoyalePublisher extends JSGoogPublisher implements IJSPublisher
collectAdditionalHTML(fileLines, filePath);
}
- private void collectAdditionalHTML(List<String> lines, String filePath)
+ private void collectAdditionalHTML(List<String> lines, String key)
{
boolean inDocComment = false;
boolean inConstructor = false;
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
index 231a4c0..da8cef4 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
@@ -133,7 +133,14 @@ public class RoyaleJSProject extends RoyaleProject
}
}
}
- // IDefinition def = to.getDefinitionPromises().get(0);
+ if (to.getCompilationUnitType() == UnitType.SWC_UNIT)
+ {
+ if (!isGoogProvided(def.getQualifiedName()))
+ {
+ SWCCompilationUnit swcUnit = (SWCCompilationUnit) to;
+ swcExterns.add(swcUnit.getSWC());
+ }
+ }
boolean isInterface = (actualDef instanceof InterfaceDefinition) && (dt == DependencyType.INHERITANCE);
if (!isInterface)
{
@@ -258,6 +265,9 @@ public class RoyaleJSProject extends RoyaleProject
// definitions that had @externs in the source
public ArrayList<String> sourceExterns = new ArrayList<String>();
+
+ // swcs that contain referenced externs
+ public Set<ISWC> swcExterns = new HashSet<ISWC>();
// definitions that should be considered external linkage
public Collection<String> unitTestExterns;
Re: [royale-compiler] branch develop updated: MXMLRoyalePublisher:
collect inject_html from externs in SWCs
Posted by Carlos Rovira <ca...@apache.org>.
Thanks for solving this issue Josh! I think this was an important one for
everyone trying to use external javascript with Royale and hopefully will
make others come to Royale finding less problems :))
El mar., 20 ago. 2019 a las 18:01, <jo...@apache.org> escribió:
> This is an automated email from the ASF dual-hosted git repository.
>
> joshtynjala 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 f653998 MXMLRoyalePublisher: collect inject_html from externs in
> SWCs
> f653998 is described below
>
> commit f6539980d9c9ccb3d60472b17d9d4986904dffd8
> Author: Josh Tynjala <jo...@apache.org>
> AuthorDate: Tue Aug 20 09:01:03 2019 -0700
>
> MXMLRoyalePublisher: collect inject_html from externs in SWCs
> ---
> .../codegen/mxml/royale/MXMLRoyalePublisher.java | 33
> ++++++++++++----------
> .../internal/projects/RoyaleJSProject.java | 12 +++++++-
> 2 files changed, 29 insertions(+), 16 deletions(-)
>
> diff --git
> a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
> b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
> index a4f46ef..0159b25 100644
> ---
> a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
> +++
> b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/royale/MXMLRoyalePublisher.java
> @@ -395,42 +395,45 @@ public class MXMLRoyalePublisher extends
> JSGoogPublisher implements IJSPublisher
>
> // Iterate over all swc dependencies and add all the externs they
> contain.
> // (Externs are located in a "externs" directory in the root of
> the SWC)
> + Set<ISWC> swcExterns = project.swcExterns;
> List<ISWC> swcs = project.getLibraries();
> List<ISWC> allswcs = new ArrayList<ISWC>();
> allswcs.addAll(swcs);
> allswcs.addAll(themeSWCs);
> - if (compilerWrapper != null)
> + for (ISWC swc : allswcs)
> {
> - for (ISWC swc : allswcs)
> + Map<String, ISWCFileEntry> files = swc.getFiles();
> + for (String key : files.keySet())
> {
> - Map<String, ISWCFileEntry> files = swc.getFiles();
> - for (String key : files.keySet())
> + if (key.startsWith(ROYALE_EXTERNS))
> {
> - if (key.startsWith(ROYALE_EXTERNS))
> + ISWCFileEntry fileEntry = swc.getFile(key);
> + if (fileEntry != null)
> {
> - ISWCFileEntry fileEntry = swc.getFile(key);
> - if (fileEntry != null)
> + InputStream is = fileEntry.createInputStream();
> + String code = IOUtils.toString(is, "UTF-8");
> + is.close();
> +
> + if (compilerWrapper != null)
> {
> - InputStream is =
> fileEntry.createInputStream();
> - String code = IOUtils.toString(is, "UTF-8");
> - is.close();
> JarSourceFile externFile = new
> JarSourceFile(key, code,true);
> if (googConfiguration.isVerbose())
> {
> System.out.println("using extern: " +
> key);
> }
> compilerWrapper.addJSExternsFile(externFile);
> + }
>
> - // Write the extern into the filesystem.
> - // FIXME: I don't know why we need to do this.
> - //FileUtils.write(new File(intermediateDir,
> key), externFile.getCode());
> + if (swcExterns.contains(swc))
> + {
> + List<String> lines = IOUtils.readLines(new
> StringReader(code));
> + collectAdditionalHTML(lines,
> swc.getSWCFile().getAbsolutePath() + ":" + key);
> }
> }
> }
> }
> }
>
> -
>
> /////////////////////////////////////////////////////////////////////////////////
> // Add all files generated by the compiler to the compilation
> unit.
>
> /////////////////////////////////////////////////////////////////////////////////
> @@ -655,7 +658,7 @@ public class MXMLRoyalePublisher extends
> JSGoogPublisher implements IJSPublisher
> collectAdditionalHTML(fileLines, filePath);
> }
>
> - private void collectAdditionalHTML(List<String> lines, String
> filePath)
> + private void collectAdditionalHTML(List<String> lines, String key)
> {
> boolean inDocComment = false;
> boolean inConstructor = false;
> diff --git
> a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
> b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
> index 231a4c0..da8cef4 100644
> ---
> a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
> +++
> b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleJSProject.java
> @@ -133,7 +133,14 @@ public class RoyaleJSProject extends RoyaleProject
> }
> }
> }
> - // IDefinition def = to.getDefinitionPromises().get(0);
> + if (to.getCompilationUnitType() == UnitType.SWC_UNIT)
> + {
> + if (!isGoogProvided(def.getQualifiedName()))
> + {
> + SWCCompilationUnit swcUnit = (SWCCompilationUnit) to;
> + swcExterns.add(swcUnit.getSWC());
> + }
> + }
> boolean isInterface = (actualDef instanceof InterfaceDefinition)
> && (dt == DependencyType.INHERITANCE);
> if (!isInterface)
> {
> @@ -258,6 +265,9 @@ public class RoyaleJSProject extends RoyaleProject
>
> // definitions that had @externs in the source
> public ArrayList<String> sourceExterns = new ArrayList<String>();
> +
> + // swcs that contain referenced externs
> + public Set<ISWC> swcExterns = new HashSet<ISWC>();
>
> // definitions that should be considered external linkage
> public Collection<String> unitTestExterns;
>
>
--
Carlos Rovira
http://about.me/carlosrovira