try computing the file order ourselves

Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/0b07c7ba
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/0b07c7ba
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/0b07c7ba

Branch: refs/heads/master
Commit: 0b07c7babfd94486262e16b8d96ea7ab321b9a9a
Parents: aee4ae3
Author: Alex Harui <[email protected]>
Authored: Mon Mar 13 10:32:05 2017 -0700
Committer: Alex Harui <[email protected]>
Committed: Mon Mar 13 10:32:14 2017 -0700

----------------------------------------------------------------------
 .../mxml/flexjs/MXMLFlexJSPublisher.java        | 133 +++++++++++++++++++
 .../utils/JSClosureCompilerWrapper.java         |  10 +-
 2 files changed, 140 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0b07c7ba/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
 
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
index 95eea2b..dfcb73d 100644
--- 
a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
+++ 
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
@@ -237,6 +237,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher 
implements IJSPublisher
         }
         // Dump a copy of the closure lib files to the intermediate directory. 
Without this
         // the application will not be able to run.
+        closureSourceFiles = closureFilesInOrder(intermediateDir + 
"/library/closure/", closureSourceFiles, "goog.events.EventTarget");
         for(SourceFile closureSourceFile : closureSourceFiles) {
             FileUtils.write(new File(new File(intermediateDir, 
"library/closure"),
                     closureSourceFile.getName()), closureSourceFile.getCode());
@@ -410,6 +411,138 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher 
implements IJSPublisher
         }
     }
 
+    protected List<SourceFile> closureFilesInOrder(String path, 
List<SourceFile> files, String entryPoint)
+    {
+       ArrayList<String> sortedFiles = new ArrayList<String>();
+       
+       for (SourceFile sourceFile : files)
+       {
+               if (sourceFile.getOriginalPath().endsWith("deps.js"))
+               {
+                       ArrayList<String> deps = new ArrayList<String>();
+               try
+               {
+                   BufferedReader in = new BufferedReader(new 
InputStreamReader(new FileInputStream(path + sourceFile.getOriginalPath()), 
"UTF8"));
+
+                   while (true)
+                   {
+                           String line = in.readLine();
+                           if (line.startsWith("//") || line.trim().length() 
== 0)
+                               continue;
+                           deps.add(line);
+                   }
+               }
+                   catch (Exception e)
+                   {
+                       // nothing to see, move along...
+                   }
+
+                   sortClosureFile(deps, entryPoint, sortedFiles);
+                   
+                   ArrayList<SourceFile> list = new ArrayList<SourceFile>();
+                   ArrayList<String> seen = new ArrayList<String>();
+                   sortedFiles.add("goog/deps.js");
+                   sortedFiles.add("goog/base.js");
+                   int n = sortedFiles.size();
+                   for (int i = n - 1; i >= 0; i--)
+                   {
+                       String fileName = sortedFiles.get(i);
+                       if (seen.contains(fileName)) continue;
+                       seen.add(fileName);
+                       
+                       for (SourceFile file : files)
+                       {
+                               if (file.getOriginalPath().contains(fileName))
+                               {
+                                       list.add(file);
+                                       files.remove(file);
+                                       break;
+                               }
+                       }
+                   }
+                   list.addAll(files);
+                   return list;
+               }
+       }
+       return null;
+    }
+    
+    private void sortClosureFile(List<String> deps, String entryPoint, 
List<String> sortedFiles)
+    {
+       String provided = getProvidedFile(deps, entryPoint);
+        sortedFiles.add(provided);
+        List<String> reqs = getRequires(deps, entryPoint);
+        if (reqs == null) return;
+        for (String req : reqs)
+        {
+               sortClosureFile(deps, req, sortedFiles);
+        }
+    }
+    
+    private String getProvidedFile(List<String> deps, String name)
+    {
+       for (String dep : deps)
+       {
+               int open = dep.indexOf("[");
+               int close = dep.indexOf("]");
+                       String list = dep.substring(open + 1, close);
+                       String[] parts = list.split(",");
+                       ArrayList<String> provideds = new ArrayList<String>();
+                       for (String part : parts)
+                       {
+                               part = part.trim();
+                               if (part.startsWith("'"))
+                                       part = part.substring(1, part.length() 
- 1);
+                               provideds.add(part);                            
        
+                       }
+               if (provideds.contains(name))
+               {
+                       open = dep.indexOf("'");
+                       close = dep.indexOf("'", open + 1);
+                       return dep.substring(open + 1, close);                  
        
+               }
+       }
+       return null;
+    }
+    
+    private List<String> getRequires(List<String> deps, String name)
+    {
+       for (String dep : deps)
+       {
+               int open = dep.indexOf("[");
+               int close = dep.indexOf("]");
+                       String list = dep.substring(open + 1, close);
+                       String[] parts = list.split(",");
+                       ArrayList<String> provideds = new ArrayList<String>();
+                       for (String part : parts)
+                       {
+                               part = part.trim();
+                               if (part.startsWith("'"))
+                                       part = part.substring(1, part.length() 
- 1);
+                               provideds.add(part);                            
        
+                       }
+               if (provideds.contains(name))
+               {
+                       open = dep.indexOf("[", close + 1);
+                       close = dep.indexOf("]", open + 1);
+                       if (open + 1 == close)
+                               return null;
+                       String list2 = dep.substring(open + 1, close);
+                       String[] parts2 = list2.split(",");
+                       ArrayList<String> reqs = new ArrayList<String>();
+                       for (String part : parts2)
+                       {
+                               part = part.trim();
+                               if (part.startsWith("'"))
+                                       part = part.substring(1, part.length() 
- 1);
+                               reqs.add(part);                                 
+                       }
+                       return reqs;
+               }
+       }
+       return null;
+    }    
+
     protected String readCode(File file)
     {
         String code = "";

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0b07c7ba/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
----------------------------------------------------------------------
diff --git 
a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
 
b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
index 1757727..cad59fa 100644
--- 
a/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
+++ 
b/compiler-jx/src/main/java/org/apache/flex/compiler/utils/JSClosureCompilerWrapper.java
@@ -102,6 +102,10 @@ public class JSClosureCompilerWrapper
 
     public void compile()
     {
+       System.out.println("list of source files");
+       for (SourceFile file : jsSourceFiles_)
+               System.out.println(file.getName());
+       System.out.println("end of list of source files");
         compiler_.compile(jsExternsFiles_, jsSourceFiles_, options_);
 
         try
@@ -228,9 +232,9 @@ public class JSClosureCompilerWrapper
             DependencyOptions dopts = new DependencyOptions();
             ArrayList<ModuleIdentifier> entryPoints = new 
ArrayList<ModuleIdentifier>();
             entryPoints.add(ModuleIdentifier.forClosure(projectName));
-            dopts.setDependencyPruning(true)
-                 .setDependencySorting(true)
-                 .setMoocherDropping(true)
+            dopts.setDependencyPruning(false)
+                 .setDependencySorting(false)
+                 .setMoocherDropping(false)
                  .setEntryPoints(entryPoints);
             options_.setDependencyOptions(dopts);
             

Reply via email to