MXMLRoyalePublisher: collect inject_html from externs in SWCs
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 @@
 
         // 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 @@
         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 @@
 		        }
         	}
         }
-        // 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 @@
 
     // 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;