This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch release_practice
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/release_practice by this push:
     new d50436b  filter out CRLF when building release artifacts
d50436b is described below

commit d50436b36bd7502e261d1457fca6bfdbfb07c32c
Author: Alex Harui <[email protected]>
AuthorDate: Mon Jun 3 20:55:00 2019 -0700

    filter out CRLF when building release artifacts
---
 .../compiler/filespecs/FileSpecification.java      | 104 ++++++++++++++++++++-
 .../projects/RoyaleProjectConfigurator.java        |   4 +-
 2 files changed, 106 insertions(+), 2 deletions(-)

diff --git 
a/compiler-common/src/main/java/org/apache/royale/compiler/filespecs/FileSpecification.java
 
b/compiler-common/src/main/java/org/apache/royale/compiler/filespecs/FileSpecification.java
index ba553f0..b77a2ff 100644
--- 
a/compiler-common/src/main/java/org/apache/royale/compiler/filespecs/FileSpecification.java
+++ 
b/compiler-common/src/main/java/org/apache/royale/compiler/filespecs/FileSpecification.java
@@ -26,6 +26,7 @@ import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -47,6 +48,8 @@ public class FileSpecification extends BaseFileSpecification 
implements IBinaryF
                super(path);
        }
 
+       public static boolean useCRLFFilter = false;
+       
        @Override
        public int hashCode() {
                final int prime = 31;
@@ -116,9 +119,12 @@ public class FileSpecification extends 
BaseFileSpecification implements IBinaryF
         final BufferedInputStream strm = new BufferedInputStream(new 
FileInputStream(file));
            final BOM bom = getBOM(strm);
         strm.skip(bom.pattern.length);
+        
+        final NoCRLFInputStream input = new NoCRLFInputStream(strm);
 
         final Reader reader = new BufferedReader(
-                new InputStreamReader(strm, bom.charset));
+                new InputStreamReader(useCRLFFilter ? input : strm, 
bom.charset));
+        input.close();
         return reader;
        }
 
@@ -133,4 +139,100 @@ public class FileSpecification extends 
BaseFileSpecification implements IBinaryF
                File fileHandle = getFileHandle();
                fileHandle.setLastModified(fileDate);
        }
+       
+       class NoCRLFInputStream extends FilterInputStream
+       {
+               public NoCRLFInputStream(BufferedInputStream strm)
+               {
+                       super(strm);
+               }
+               
+               /**
+                * if we read a CR, just skip it, assuming it will
+                * be followed by an LF
+                */
+               @Override
+               public int read() throws IOException
+               {
+                       int retval = super.read();
+                       if (retval == '\r')
+                               retval = super.read();
+                       return retval;
+               }
+               
+               /**
+                * if we read a CR, just skip it, assuming it will
+                * be followed by an LF
+                * @throws IOException 
+                */
+               @Override
+               public int read(byte[] b) throws IOException
+               {
+                       int n = b.length;
+                       byte[] temp = new byte[b.length];
+                       int retval = super.read(temp);
+                       if (retval == -1)
+                               return -1;
+                       
+                       int j = 0;
+                       for (int i = 0; i < n; i++)
+                       {
+                               byte c = temp[i];
+                               if (c == '\r')
+                                       continue;
+                               else
+                                       b[j++] = c;
+                       }
+                       while (j < n)
+                       {
+                               int extra = super.read(b, j, 1);
+                               if (extra == -1)
+                                       break;
+                               byte c = b[j];
+                               if (c == '\r')
+                                       continue;
+                               else
+                                   j++;
+                       }
+                       return j;
+               }
+
+               /**
+                * if we read a CR, just skip it, assuming it will
+                * be followed by an LF
+                * @throws IOException 
+                */
+               @Override
+               public int read(byte[] b, int off, int len) throws IOException
+               {
+                       byte[] temp = new byte[len];
+                       int retval = super.read(temp, off, len);
+                       if (retval == -1)
+                               return -1;
+                       if (retval == 0)
+                               return 0;
+                       
+                       int j = 0;
+                       for (int i = off; i < retval; i++)
+                       {
+                               byte c = temp[i];
+                               if (c == '\r')
+                                       continue;
+                               else
+                                       b[off + j++] = c;
+                       }
+//                     System.out.println(new String(b));
+                       while (j < retval)
+                       {
+                               int extra = super.read(b, off + j, 1);
+                               if (extra == -1)
+                                       break;
+                               byte c = b[off + j];
+                               if (c == '\r')
+                                       continue;
+                               j++;
+                       }
+                       return j;
+               }
+       }
 }
diff --git 
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
 
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
index 2ad763a..c68f757 100644
--- 
a/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
+++ 
b/compiler/src/main/java/org/apache/royale/compiler/internal/projects/RoyaleProjectConfigurator.java
@@ -30,6 +30,7 @@ import org.apache.royale.abc.semantics.Namespace;
 import org.apache.royale.abc.semantics.Nsset;
 import org.apache.royale.compiler.config.Configuration;
 import org.apache.royale.compiler.config.Configurator;
+import org.apache.royale.compiler.filespecs.FileSpecification;
 import org.apache.royale.compiler.fxg.flex.FlexFXG2SWFTranscoder;
 import org.apache.royale.compiler.internal.as.codegen.BindableHelper;
 import org.apache.royale.compiler.internal.config.RoyaleTargetSettings;
@@ -267,7 +268,8 @@ public class RoyaleProjectConfigurator extends Configurator
             
project.setAllowAbstractClasses(configuration.getCompilerAllowAbstractClasses());
             
             project.setSwfDebugfileAlias(configuration.getSwfDebugfileAlias());
-            
+            if (configuration.getSwfDebugfileAlias() != null)
+               FileSpecification.useCRLFFilter = true;
             DataTranscoder.embedClassName = 
configuration.getByteArrayEmbedClass();
         }
     }

Reply via email to