I tried this while ago I end with the same solution (moving the code to
publisher). There's no way to do this other way since @externs are not
processed from GoogDepsWriter. In fact all code in GoogDepsWriter referring
to externs is never exectuted. Don't know if it worked before, but when I
tried it, setting console prints in the parts of the code that refers to
externs reveal that no code was exectuted since no I never get a single
println in that part outputted in console

El mar., 20 ago. 2019 a las 1:30, Alex Harui (<aha...@adobe.com.invalid>)
escribió:

> I couldn't easily see how this avoids opening and scanning each file
> twice.  That's sort of why the inject_html was in GoogDepsWriter.  It had
> to visit every file already.
>
> HTH,
> -Alex
>
> On 8/19/19, 12:14 PM, "joshtynj...@apache.org" <joshtynj...@apache.org>
> wrote:
>
>     This is an automated email from the ASF dual-hosted git repository.
>
>     joshtynjala pushed a commit to branch develop
>     in repository
> https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitbox.apache.org%2Frepos%2Fasf%2Froyale-compiler.git&amp;data=02%7C01%7Caharui%40adobe.com%7C29436cd97fa94973ad2408d724d96a23%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C1%7C637018388518086696&amp;sdata=eF75V3CAG%2FMVURuYsUe1Wjqwf555o8j5ymln%2F8SQJGs%3D&amp;reserved=0
>
>
>     The following commit(s) were added to refs/heads/develop by this push:
>          new 884afe9  GoogDepsWriter: extracted inject_html detection and
> moved it to the publisher so that inject_html can be detected in externs too
>     884afe9 is described below
>
>     commit 884afe915e7350529baebb487d2985f638daf3d7
>     Author: Josh Tynjala <joshtynj...@apache.org>
>     AuthorDate: Mon Aug 19 11:53:10 2019 -0700
>
>         GoogDepsWriter: extracted inject_html detection and moved it to
> the publisher so that inject_html can be detected in externs too
>     ---
>      .../codegen/mxml/royale/MXMLRoyalePublisher.java   | 123
> ++++++++++++++++++---
>      .../compiler/internal/graph/GoogDepsWriter.java    |  21 ----
>      2 files changed, 105 insertions(+), 39 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 80326a8..a4f46ef 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
>     @@ -18,6 +18,7 @@
>       */
>      package org.apache.royale.compiler.internal.codegen.mxml.royale;
>
>     +import com.google.common.io.Files;
>      import com.google.javascript.jscomp.SourceFile;
>      import org.apache.commons.io.FileUtils;
>      import org.apache.commons.io.FilenameUtils;
>     @@ -52,6 +53,7 @@ import org.apache.royale.swc.ISWCManager;
>      import java.io.*;
>      import java.net.URL;
>      import java.net.URLDecoder;
>     +import java.nio.charset.Charset;
>      import java.util.*;
>
>      public class MXMLRoyalePublisher extends JSGoogPublisher implements
> IJSPublisher
>     @@ -98,6 +100,7 @@ public class MXMLRoyalePublisher extends
> JSGoogPublisher implements IJSPublisher
>          private String outputPathParameter;
>          private String moduleOutput;
>          private boolean useStrictPublishing;
>     +    private List<String> additionalHTML = new ArrayList<String>();
>
>          private GoogDepsWriter getGoogDepsWriter(File intermediateDir,
>
>               String mainClassQName,
>     @@ -441,36 +444,42 @@ public class MXMLRoyalePublisher extends
> JSGoogPublisher implements IJSPublisher
>              if (fileList == null)
>                  return false; // some error occurred
>
>     -        if (compilerWrapper != null)
>     +        for (String sourceExtern : project.sourceExterns)
>              {
>     -            for (String sourceExtern : project.sourceExterns)
>     +            String sourceExternFileName = sourceExtern.replace(".",
> "/") + ".js";
>     +            File sourceExternFile = new File(intermediateDir,
> sourceExternFileName);
>     +            if (sourceExternFile.exists())
>                  {
>     -                String sourceExternFileName =
> sourceExtern.replace(".", "/") + ".js";
>     -                File sourceExternFile = new File(intermediateDir,
> sourceExternFileName);
>     -                if (sourceExternFile.exists())
>     -                {
>     -                    String sourceExternPath =
> sourceExternFile.getAbsolutePath();
>     -                    if (!sourceExternFiles.contains(sourceExternPath))
>     -                        sourceExternFiles.add(sourceExternPath);
>     -                }
>     +                String sourceExternPath =
> sourceExternFile.getAbsolutePath();
>     +                if (!sourceExternFiles.contains(sourceExternPath))
>     +                    sourceExternFiles.add(sourceExternPath);
>                  }
>     -            for (String file : fileList) {
>     +        }
>     +        for (String file : fileList)
>     +        {
>     +            if (compilerWrapper != null)
>     +            {
>                      compilerWrapper.addJSSourceFile(file);
>                      if (googConfiguration.isVerbose())
>                      {
>                          System.out.println("using source file: " + file);
>                      }
>                  }
>     -            for (String file : sourceExternFiles) {
>     +            collectFileAdditionalHTML(file);
>     +        }
>     +        for (String file : sourceExternFiles)
>     +        {
>     +            if (compilerWrapper != null)
>     +            {
>                      compilerWrapper.addJSExternsFile(file);
>                      if (googConfiguration.isVerbose())
>                      {
>                          System.out.println("using extern file: " + file);
>                      }
>                  }
>     +            collectFileAdditionalHTML(file);
>              }
>
>     -
>
>  
> /////////////////////////////////////////////////////////////////////////////////
>              // Generate the index.html for loading the application.
>
>  
> /////////////////////////////////////////////////////////////////////////////////
>     @@ -484,7 +493,7 @@ public class MXMLRoyalePublisher extends
> JSGoogPublisher implements IJSPublisher
>
>              if (project.isModule(mainClassQName))
>              {
>     -            for (String s : gdw.additionalHTML)
>     +            for (String s : additionalHTML)
>                  {
>                      moduleAdditionHTML += "document.head.innerHTML += '"+
> s.trim() + "';";
>                  }
>     @@ -501,17 +510,17 @@ public class MXMLRoyalePublisher extends
> JSGoogPublisher implements IJSPublisher
>                 // Create the index.html for the debug-js version.
>                 if
> (!((JSGoogConfiguration)configuration).getSkipTranspile()) {
>                     if (template != null) {
>     -                   writeTemplate(template, "intermediate",
> projectName, mainClassQName, intermediateDir, depsFileData,
> gdw.additionalHTML);
>     +                   writeTemplate(template, "intermediate",
> projectName, mainClassQName, intermediateDir, depsFileData, additionalHTML);
>                     } else {
>     -                   writeHTML("intermediate", projectName,
> mainClassQName, intermediateDir, depsFileData, gdw.additionalHTML);
>     +                   writeHTML("intermediate", projectName,
> mainClassQName, intermediateDir, depsFileData, additionalHTML);
>                     }
>                 }
>                 // Create the index.html for the release-js version.
>                 if (configuration.release()) {
>                     if (template != null) {
>     -                   writeTemplate(template, "release", projectName,
> mainClassQName, releaseDir, depsFileData, gdw.additionalHTML);
>     +                   writeTemplate(template, "release", projectName,
> mainClassQName, releaseDir, depsFileData, additionalHTML);
>                     } else {
>     -                   writeHTML("release", projectName, mainClassQName,
> releaseDir, null, gdw.additionalHTML);
>     +                   writeHTML("release", projectName, mainClassQName,
> releaseDir, null, additionalHTML);
>                     }
>                 }
>              }
>     @@ -631,6 +640,84 @@ public class MXMLRoyalePublisher extends
> JSGoogPublisher implements IJSPublisher
>              }
>              return list;
>          }
>     +
>     +    private void collectFileAdditionalHTML(String filePath)
>     +    {
>     +        List<String> fileLines;
>     +        try
>     +        {
>     +            fileLines = Files.readLines(new File(filePath),
> Charset.defaultCharset());
>     +        }
>     +        catch(IOException e)
>     +        {
>     +            return;
>     +        }
>     +        collectAdditionalHTML(fileLines, filePath);
>     +    }
>     +
>     +    private void collectAdditionalHTML(List<String> lines, String
> filePath)
>     +    {
>     +        boolean inDocComment = false;
>     +        boolean inConstructor = false;
>     +        boolean inInjectHTML = false;
>     +       for (int i = 0; i < lines.size(); i++)
>     +       {
>     +            String line = lines.get(i);
>     +            if (inDocComment)
>     +            {
>     +                if (inInjectHTML)
>     +                {
>     +                    if (line.indexOf("</inject_html>") > -1)
>     +                    {
>     +                        inInjectHTML = false;
>     +                        continue;
>     +                    }
>     +                    line = line.trim();
>     +                    if (line.startsWith("*"))
>     +                        line = line.substring(1);
>     +                    additionalHTML.add(line);
>     +                    continue;
>     +                }
>     +                int c = line.indexOf("<inject_html>");
>     +                if (c != -1)
>     +                {
>     +                    inInjectHTML = true;
>     +                    continue;
>     +                }
>     +                if (!inConstructor)
>     +                {
>     +                    c = line.indexOf("@constructor");
>     +                    if(c != -1)
>     +                    {
>     +                        inConstructor = true;
>     +                        continue;
>     +                    }
>     +                }
>     +                c = line.indexOf("*/");
>     +                if(c != -1)
>     +                {
>     +                    if(inConstructor)
>     +                    {
>     +                        //we're done
>     +                        break;
>     +                    }
>     +                    inInjectHTML = false;
>     +                    inDocComment = false;
>     +                    inConstructor = false;
>     +                }
>     +
>     +            }
>     +            else
>     +            {
>     +                int c = line.indexOf("/**");
>     +                if(c != -1)
>     +                {
>     +                    inDocComment = true;
>     +                    continue;
>     +                }
>     +            }
>     +        }
>     +    }
>
>          private void sortClosureFile(List<String> deps, String
> entryPoint, List<String> sortedFiles)
>          {
>     diff --git
> a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
> b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
>     index 66ef9a3..cf87fba 100644
>     ---
> a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
>     +++
> b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/graph/GoogDepsWriter.java
>     @@ -325,8 +325,6 @@ public class GoogDepsWriter {
>                 addDeps(mainName);
>                 return true;
>         }
>     -
>     -    public ArrayList<String> additionalHTML = new ArrayList<String>();
>
>          private HashMap<String, GoogDep> visited = new HashMap<String,
> GoogDep>();
>
>     @@ -1091,7 +1089,6 @@ public class GoogDepsWriter {
>             fi.suppressLine = -1;
>             fi.fileoverviewLine = -1;
>             fi.googProvideLine = -1;
>     -           boolean inInjectHTML = false;
>             for (int i = 0; i < n; i++)
>             {
>                 String line = lines.get(i);
>     @@ -1103,24 +1100,6 @@ public class GoogDepsWriter {
>                 }
>                 else
>                 {
>     -                   if (inInjectHTML)
>     -               {
>     -                   if (line.indexOf("</inject_html>") > -1)
>     -                   {
>     -                       inInjectHTML = false;
>     -                       continue;
>     -                   }
>     -                   line = line.trim();
>     -                   if (line.startsWith("*"))
>     -                           line = line.substring(1);
>     -                               additionalHTML.add(line);
>     -                               continue;
>     -               }
>     -                c = line.indexOf("<inject_html>");
>     -                if (c > -1)
>     -                {
>     -                    inInjectHTML = true;
>     -                }
>                         c = line.indexOf("@constructor");
>                         if (c > -1)
>                         {
>
>
>
>

-- 
Carlos Rovira
http://about.me/carlosrovira

Reply via email to