royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joshtynj...@apache.org
Subject [royale-compiler] branch develop updated: compiler-jx: refactored IJSWriter writeTo() to accept an OutputStream for the source map so that it can be written to something other than a file, if desired
Date Fri, 02 Nov 2018 18:28:55 GMT
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 e14f37f  compiler-jx: refactored IJSWriter writeTo() to accept an OutputStream for
the source map so that it can be written to something other than a file, if desired
e14f37f is described below

commit e14f37fd63883a79294dc042e2a4cb5ff64aef3a
Author: Josh Tynjala <joshtynjala@apache.org>
AuthorDate: Fri Nov 2 11:28:51 2018 -0700

    compiler-jx: refactored IJSWriter writeTo() to accept an OutputStream for the source map
so that it can be written to something other than a file, if desired
    
    The will eventually allow SWC files to include source maps so that libraries can be debugged
---
 .../apache/royale/compiler/clients/MXMLJSC.java    | 12 ++++++++++--
 .../royale/compiler/clients/MXMLJSCNative.java     | 10 +++++++++-
 .../royale/compiler/clients/MXMLJSCNode.java       | 10 +++++++++-
 .../royale/compiler/clients/MXMLJSCRoyale.java     | 14 +++++++++++---
 .../compiler/clients/MXMLJSCRoyaleCordova.java     | 10 +++++++++-
 .../royale/compiler/codegen/js/IJSWriter.java      |  6 +++---
 .../compiler/internal/codegen/js/JSWriter.java     | 22 +++++++++++-----------
 .../compiler/internal/codegen/mxml/MXMLWriter.java | 16 +++++++++-------
 8 files changed, 71 insertions(+), 29 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
index 5d89c97..8129274 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java
@@ -577,16 +577,24 @@ public class MXMLJSC implements JSCompilerEntryPoint, ProblemQueryProvider,
 	                        BufferedOutputStream out = new BufferedOutputStream(
 	                                new FileOutputStream(outputClassFile));
 	
+                            BufferedOutputStream sourceMapOut = null;
 	                        File outputSourceMapFile = null;
 	                        if (project.config.getSourceMap())
 	                        {
 	                            outputSourceMapFile = getOutputSourceMapFile(
 	                                    cu.getQualifiedNames().get(0), outputFolder);
+                                sourceMapOut = new BufferedOutputStream(
+                                        new FileOutputStream(outputSourceMapFile));
 	                        }
 	                        
-	                        writer.writeTo(out, outputSourceMapFile);
+	                        writer.writeTo(out, sourceMapOut, outputSourceMapFile);
 	                        out.flush();
-	                        out.close();
+                            out.close();
+                            if (sourceMapOut != null)
+                            {
+                                sourceMapOut.flush();
+                                sourceMapOut.close();
+                            }
 	                        writer.close();
 	                    }
 	                }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
index f0f3c3a..6bae88f 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNative.java
@@ -356,16 +356,24 @@ public class MXMLJSCNative implements JSCompilerEntryPoint, ProblemQueryProvider
 	                        BufferedOutputStream out = new BufferedOutputStream(
 	                                new FileOutputStream(outputClassFile));
 	
+                            BufferedOutputStream sourceMapOut = null;
 	                        File outputSourceMapFile = null;
 	                        if (project.config.getSourceMap())
 	                        {
 	                            outputSourceMapFile = getOutputSourceMapFile(
 	                                    cu.getQualifiedNames().get(0), outputFolder);
+                                sourceMapOut = new BufferedOutputStream(
+                                        new FileOutputStream(outputSourceMapFile));
 	                        }
 	                        
-	                        writer.writeTo(out, outputSourceMapFile);
+	                        writer.writeTo(out, sourceMapOut, outputSourceMapFile);
 	                        out.flush();
 	                        out.close();
+                            if (sourceMapOut != null)
+                            {
+                                sourceMapOut.flush();
+                                sourceMapOut.close();
+                            }
 	                        writer.close();
 	                    }
 	                }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
index 463aa35..ed98d56 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCNode.java
@@ -358,16 +358,24 @@ public class MXMLJSCNode implements JSCompilerEntryPoint, ProblemQueryProvider,
 	                        BufferedOutputStream out = new BufferedOutputStream(
 	                                new FileOutputStream(outputClassFile));
 	
+                            BufferedOutputStream sourceMapOut = null;
 	                        File outputSourceMapFile = null;
 	                        if (project.config.getSourceMap())
 	                        {
 	                            outputSourceMapFile = getOutputSourceMapFile(
 	                                    cu.getQualifiedNames().get(0), outputFolder);
+                                sourceMapOut = new BufferedOutputStream(
+                                        new FileOutputStream(outputSourceMapFile));
 	                        }
 	                        
-	                        writer.writeTo(out, outputSourceMapFile);
+	                        writer.writeTo(out, sourceMapOut, outputSourceMapFile);
 	                        out.flush();
 	                        out.close();
+                            if (sourceMapOut != null)
+                            {
+                                sourceMapOut.flush();
+                                sourceMapOut.close();
+                            }
 	                        writer.close();
 	                    }
 	                }
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 475082f..cbcfa28 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
@@ -382,17 +382,25 @@ public class MXMLJSCRoyale implements JSCompilerEntryPoint, ProblemQueryProvider
 	
 	                        BufferedOutputStream out = new BufferedOutputStream(
 	                                new FileOutputStream(outputClassFile));
-	
+
+                            BufferedOutputStream sourceMapOut = null;
 	                        File outputSourceMapFile = null;
 	                        if (project.config.getSourceMap())
 	                        {
 	                            outputSourceMapFile = getOutputSourceMapFile(
-	                                    cu.getQualifiedNames().get(0), outputFolder);
+                                        cu.getQualifiedNames().get(0), outputFolder);
+                                sourceMapOut = new BufferedOutputStream(
+	                                    new FileOutputStream(outputSourceMapFile));
 	                        }
 	                        
-	                        writer.writeTo(out, outputSourceMapFile);
+	                        writer.writeTo(out, sourceMapOut, outputSourceMapFile);
 	                        out.flush();
 	                        out.close();
+                            if (sourceMapOut != null)
+                            {
+                                sourceMapOut.flush();
+                                sourceMapOut.close();
+                            }
 	                        writer.close();
 	                    }
 	                }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
index 503d75f..6e91ea0 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyaleCordova.java
@@ -361,16 +361,24 @@ public class MXMLJSCRoyaleCordova implements JSCompilerEntryPoint, ProblemQueryP
 	                        BufferedOutputStream out = new BufferedOutputStream(
 	                                new FileOutputStream(outputClassFile));
 	
+                            BufferedOutputStream sourceMapOut = null;
 	                        File outputSourceMapFile = null;
 	                        if (project.config.getSourceMap())
 	                        {
 	                            outputSourceMapFile = getOutputSourceMapFile(
 	                                    cu.getQualifiedNames().get(0), outputFolder);
+                                sourceMapOut = new BufferedOutputStream(
+                                        new FileOutputStream(outputSourceMapFile));
 	                        }
 	                        
-	                        writer.writeTo(out, outputSourceMapFile);
+	                        writer.writeTo(out, sourceMapOut, outputSourceMapFile);
 	                        out.flush();
 	                        out.close();
+                            if (sourceMapOut != null)
+                            {
+                                sourceMapOut.flush();
+                                sourceMapOut.close();
+                            }
 	                        writer.close();
 	                    }
 	                }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/IJSWriter.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/IJSWriter.java
index 50ea5cc..09524f2 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/IJSWriter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/codegen/js/IJSWriter.java
@@ -36,8 +36,8 @@ public interface IJSWriter extends IASWriter
      * Write JS file and source map.
      *
      * @param jsOut JS output stream
-     * @param sourceMapOut Source map file
+     * @param sourceMapOut Source map output stream
+     * @param sourceMapFile Source map file
      */
-    void writeTo(OutputStream jsOut, File sourceMapOut);
-
+    void writeTo(OutputStream jsOut, OutputStream sourceMapOut, File sourceMapFile);
 }
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
index d16a3fc..50b0be2 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
@@ -19,9 +19,7 @@
 
 package org.apache.royale.compiler.internal.codegen.js;
 
-import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.List;
@@ -79,7 +77,7 @@ public class JSWriter implements IJSWriter
     @Override
     public void writeTo(OutputStream out)
     {
-        writeTo(out, null);
+        writeTo(out, null, null);
     }
 
     @Override
@@ -88,7 +86,7 @@ public class JSWriter implements IJSWriter
         return 0;
     }
 
-    public void writeTo(OutputStream jsOut, File sourceMapOut)
+    public void writeTo(OutputStream jsOut, OutputStream jsSourceMapOut, File sourceMapFile)
     {
         IJSBackend backend = (IJSBackend) project.getBackend();
         JSFilterWriter writer = (JSFilterWriter) backend.createWriterBuffer(project);
@@ -108,9 +106,14 @@ public class JSWriter implements IJSWriter
             e.printStackTrace();
         }
 
-        if (sourceMapOut != null)
+        if (jsSourceMapOut != null)
         {
-            convertMappingSourcePathsToRelative(emitter, sourceMapOut);
+            String sourceMapFilePath = null;
+            if (sourceMapFile != null)
+            {
+                sourceMapFilePath = sourceMapFile.getAbsolutePath();
+                convertMappingSourcePathsToRelative(emitter, sourceMapFile);
+            }
 
             File compilationUnitFile = new File(compilationUnit.getAbsoluteFilename());
             ISourceMapEmitter sourceMapEmitter = backend.createSourceMapEmitter(emitter);
@@ -118,11 +121,8 @@ public class JSWriter implements IJSWriter
             {
                 String fileName = compilationUnitFile.getName();
                 fileName = fileName.replace(".as", ".js");
-                String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapOut.getAbsolutePath(),
null);
-                BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(sourceMapOut));
-                outStream.write(sourceMap.getBytes());
-                outStream.flush();
-                outStream.close();
+                String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapFilePath,
null);
+                jsSourceMapOut.write(sourceMap.getBytes());
             } catch (Exception e)
             {
                 e.printStackTrace();
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLWriter.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLWriter.java
index 77c8959..6274d53 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLWriter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLWriter.java
@@ -54,7 +54,7 @@ public class MXMLWriter extends JSWriter
     }
 
     @Override
-    public void writeTo(OutputStream out, File sourceMapOut)
+    public void writeTo(OutputStream out, OutputStream sourceMapOut, File sourceMapFile)
     {
         IJSBackend backend = (IJSBackend) project.getBackend();
         JSFilterWriter writer = (JSFilterWriter) backend.createWriterBuffer(project);
@@ -81,7 +81,12 @@ public class MXMLWriter extends JSWriter
 
         if (sourceMapOut != null)
         {
-            convertMappingSourcePathsToRelative((IMappingEmitter) mxmlEmitter, sourceMapOut);
+            String sourceMapFilePath = null;
+            if (sourceMapFile != null)
+            {
+                sourceMapFilePath = sourceMapFile.getAbsolutePath();
+                convertMappingSourcePathsToRelative((IMappingEmitter) mxmlEmitter, sourceMapFile);
+            }
 
             File compilationUnitFile = new File(compilationUnit.getAbsoluteFilename());
             ISourceMapEmitter sourceMapEmitter = backend.createSourceMapEmitter((IMappingEmitter)
mxmlEmitter);
@@ -89,11 +94,8 @@ public class MXMLWriter extends JSWriter
             {
                 String fileName = compilationUnitFile.getName();
                 fileName = fileName.replace(".mxml", ".js");
-                String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapOut.getAbsolutePath(),
null);
-                BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(sourceMapOut));
-                outStream.write(sourceMap.getBytes());
-                outStream.flush();
-                outStream.close();
+                String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapFilePath,
null);
+                sourceMapOut.write(sourceMap.getBytes());
             } catch (Exception e)
             {
                 e.printStackTrace();


Mime
View raw message