flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - initial support for modules
Date Tue, 15 Aug 2017 17:23:46 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 7edc0343e -> f8b724e46


initial support for modules


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

Branch: refs/heads/develop
Commit: f8b724e46af9a8d7916bdb95a44369eab7273121
Parents: 7edc034
Author: Alex Harui <aharui@apache.org>
Authored: Tue Aug 15 10:20:53 2017 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Aug 15 10:23:24 2017 -0700

----------------------------------------------------------------------
 .../javascript/jscomp/CompilerMapFetcher.java   |  53 +++++
 .../mxml/flexjs/MXMLFlexJSPublisher.java        |  91 +++++++--
 .../utils/JSClosureCompilerWrapper.java         | 204 ++++++++++++++++++-
 3 files changed, 329 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f8b724e4/compiler-jx/src/main/java/com/google/javascript/jscomp/CompilerMapFetcher.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/com/google/javascript/jscomp/CompilerMapFetcher.java
b/compiler-jx/src/main/java/com/google/javascript/jscomp/CompilerMapFetcher.java
new file mode 100644
index 0000000..5fbb7ae
--- /dev/null
+++ b/compiler-jx/src/main/java/com/google/javascript/jscomp/CompilerMapFetcher.java
@@ -0,0 +1,53 @@
+/*
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package com.google.javascript.jscomp;
+
+public class CompilerMapFetcher
+{
+
+    private static final long serialVersionUID = 2021530437904249081L;
+
+    public CompilerMapFetcher()
+    {
+        super();
+    }
+    
+    public static VariableMap getVariableMap(Compiler compiler)
+    {
+    	return compiler.getVariableMap();
+    }
+    
+    public static VariableMap getPropertyMap(Compiler compiler)
+    {
+    	return compiler.getPropertyMap();
+    }
+
+    public static void setVariableMap(CompilerOptions options, VariableMap input)
+    {
+    	options.inputVariableMap = input;
+    }
+    
+    public static void setPropertyMap(CompilerOptions options, VariableMap input)
+    {
+    	options.inputPropertyMap = input;
+    }
+    
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f8b724e4/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 a46c9ba..0683573 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
@@ -323,24 +323,35 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements
IJSPublisher
         // is generated here so it can be used for outputting the html templates.
         String depsFileData = gdw.generateDeps(project, problems);
 
-        File template = ((JSGoogConfiguration)configuration).getHtmlTemplate();
-        // Create the index.html for the debug-js version.
-        if (!((JSGoogConfiguration)configuration).getSkipTranspile()) {
-            if (template != null) {
-                writeTemplate(template, "intermediate", projectName, intermediateDir, depsFileData,
gdw.additionalHTML);
-            } else {
-                writeHTML("intermediate", projectName, intermediateDir, depsFileData, gdw.additionalHTML);
-            }
-        }
-        // Create the index.html for the release-js version.
-        if (configuration.release()) {
-            if (template != null) {
-                writeTemplate(template, "release", projectName, releaseDir, depsFileData,
gdw.additionalHTML);
-            } else {
-                writeHTML("release", projectName, releaseDir, null, gdw.additionalHTML);
-            }
+        if (depsFileData.contains("UIModule.js"))
+        {
+        	// need better test someday
+        	depsFileData += "\ngoog.require('" + projectName + "');\n";
+            writeFile(new File(intermediateDir, projectName + "__deps.js"), depsFileData,
false);
+            Set<String> provideds = computeProvideds(depsFileData);
+            compilerWrapper.setProvideds(provideds);
+            gdw.needCSS = true;
         }
-
+        else
+        {
+	        File template = ((JSGoogConfiguration)configuration).getHtmlTemplate();
+	        // Create the index.html for the debug-js version.
+	        if (!((JSGoogConfiguration)configuration).getSkipTranspile()) {
+	            if (template != null) {
+	                writeTemplate(template, "intermediate", projectName, intermediateDir, depsFileData,
gdw.additionalHTML);
+	            } else {
+	                writeHTML("intermediate", projectName, intermediateDir, depsFileData, gdw.additionalHTML);
+	            }
+	        }
+	        // Create the index.html for the release-js version.
+	        if (configuration.release()) {
+	            if (template != null) {
+	                writeTemplate(template, "release", projectName, releaseDir, depsFileData,
gdw.additionalHTML);
+	            } else {
+	                writeHTML("release", projectName, releaseDir, null, gdw.additionalHTML);
+	            }
+	        }
+        }        
 
         /////////////////////////////////////////////////////////////////////////////////
         // Generate or copy the main CSS resources.
@@ -378,6 +389,23 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
         return true;
     }
 
+    private Set<String> computeProvideds(String data)
+    {
+    	HashSet<String> set = new HashSet<String>();
+    	String[] lines = data.split("\n");
+    	for (String line : lines)
+    	{
+    		int c = line.indexOf("['");
+    		if (c != -1)
+    		{
+	    		int c2 = line.indexOf("'", c + 2);
+	    		String name = line.substring(c + 2, c2);
+	    		set.add(name);
+    		}
+    	}
+    	return set;
+    }
+    
     protected List<SourceFile> closureFilesInOrder(String path, List<SourceFile>
files, String entryPoint)
     {
     	ArrayList<String> sortedFiles = new ArrayList<String>();
@@ -768,6 +796,11 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
         return true;
     }
     
+    private String[] reservedFunctions = {
+    		"org['apache']['flex']['core']['UIBase'] = function(){};",
+    		"org['apache']['flex']['html']['Label'] = function(){};",
+    };
+    
     private void writeExportedNames(JSClosureCompilerWrapper compilerWrapper)
     {
     	if (!googConfiguration.getExportPublicSymbols())
@@ -801,6 +834,30 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements IJSPublisher
 	        	compilerWrapper.addJSExternsFile(exportsFile.getAbsolutePath());
 	        }
     	}
+    	else
+    	{
+        	StringBuilder sb = new StringBuilder();
+        	sb.append("/**\n");
+        	sb.append(" * generated by Apache FlexJS compiler\n");
+        	sb.append(" * @externs\n");
+        	sb.append(" */\n");
+        	for (String name : reservedFunctions)
+        	{
+        		sb.append("\n\n");
+	        	sb.append("/**\n");
+	        	sb.append(" */\n");
+	        	sb.append(name + "\n");
+        	}
+        	File exportsFile = new File(outputFolder, "dontrename.js");
+        	try {
+				writeFile(exportsFile, sb.toString(), false);
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+        	//compilerWrapper.addJSExternsFile(exportsFile.getAbsolutePath());
+    		
+    	}
     }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/f8b724e4/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 42ad2b3..05c791b 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
@@ -19,18 +19,26 @@
 
 package org.apache.flex.compiler.utils;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.logging.Level;
 
 import com.google.javascript.jscomp.CheckLevel;
 import com.google.javascript.jscomp.CommandLineRunner;
 import com.google.javascript.jscomp.CompilationLevel;
 import com.google.javascript.jscomp.Compiler;
+import com.google.javascript.jscomp.CompilerMapFetcher;
 import com.google.javascript.jscomp.CompilerOptions;
 import com.google.javascript.jscomp.CompilerOptions.LanguageMode;
 import com.google.javascript.jscomp.DependencyOptions;
@@ -39,6 +47,7 @@ import com.google.javascript.jscomp.FlexJSDiagnosticGroups;
 import com.google.javascript.jscomp.ModuleIdentifier;
 import com.google.javascript.jscomp.SourceFile;
 import com.google.javascript.jscomp.SourceMap;
+import com.google.javascript.jscomp.VariableMap;
 import com.google.javascript.jscomp.WarningLevel;
 
 public class JSClosureCompilerWrapper
@@ -49,7 +58,8 @@ public class JSClosureCompilerWrapper
         Compiler.setLoggingLevel(Level.INFO);
 
         compiler_ = new Compiler();
-
+        filterOptions(args);
+        
         ArrayList<String> splitArgs = new ArrayList<String>();
         for (String s : args)
         {
@@ -77,6 +87,11 @@ public class JSClosureCompilerWrapper
     private CompilerOptions options_;
     private List<SourceFile> jsExternsFiles_;
     private List<SourceFile> jsSourceFiles_;
+    private String variableMapOutputPath;
+    private String propertyMapOutputPath;
+    private String variableMapInputPath;
+    private String propertyMapInputPath;
+    private Set<String> provideds;
     
     public String targetFilePath;
     
@@ -100,12 +115,45 @@ public class JSClosureCompilerWrapper
         jsSourceFiles_.add(file);
     }
 
+    public void setProvideds(Set<String> set)
+    {
+    	provideds = set;
+    }
+    
     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");
+    	File outputFolder = new File(targetFilePath).getParentFile();
+        if (variableMapInputPath != null)
+        {
+        	File inputFile = new File(outputFolder, variableMapInputPath);
+        	try {
+            	VariableMap map = VariableMap.load(inputFile.getAbsolutePath());
+				CompilerMapFetcher.setVariableMap(options_, map);
+				Set<String> usedVars = getUsedVars(inputFile);
+				compiler_.addExportedNames(usedVars);
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+        }
+        
+        if (propertyMapInputPath != null)
+        {
+        	File inputFile = new File(outputFolder, propertyMapInputPath);
+        	try {
+            	VariableMap map = VariableMap.load(inputFile.getAbsolutePath());
+				CompilerMapFetcher.setPropertyMap(options_, map);
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+        }
+
+
         compiler_.compile(jsExternsFiles_, jsSourceFiles_, options_);
 
         try
@@ -123,6 +171,30 @@ public class JSClosureCompilerWrapper
             System.out.println(error);
         }
         
+        if (variableMapOutputPath != null)
+        {
+        	File outputFile = new File(outputFolder, variableMapOutputPath);
+        	VariableMap map = CompilerMapFetcher.getVariableMap(compiler_);
+        	try {
+				map.save(outputFile.getAbsolutePath());
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+        }
+        
+        if (propertyMapOutputPath != null)
+        {
+        	File outputFile = new File(outputFolder, propertyMapOutputPath);
+        	VariableMap map = CompilerMapFetcher.getPropertyMap(compiler_);
+        	try {
+				map.save(outputFile.getAbsolutePath());
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+        }
+        
         /*
         for (JSError message : compiler_.getWarnings())
         {
@@ -136,6 +208,64 @@ public class JSClosureCompilerWrapper
         */
     }
     
+    private Set<String> getUsedVars(File file)
+    {
+    	HashMap<String, String> vars = new HashMap<String, String>();
+    	
+        try
+        {
+            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),
"UTF8"));
+
+            String line = in.readLine();
+
+            while (line != null)
+            {
+                int c = line.indexOf(":");
+                if (c != -1)
+                {
+                	String name = line.substring(0, c);
+                	
+                	String var = line.substring(c + 1).trim();
+                	vars.put(name, var);
+                }
+                line = in.readLine();
+            }
+            
+            // remove all vars that are used by this module
+            // that way they will re-use the names in the
+            // loader
+            for (String name : provideds)
+            {
+            	name = name.replace('.', '$');
+            	Set<String> keys = vars.keySet();
+            	ArrayList<String> remKeys = new ArrayList<String>();
+            	for (String key : keys)
+            	{
+            		if (key.contains(name))
+            		{
+            			remKeys.add(key);
+            		}
+            	}
+            	for (String key : remKeys)
+            	{
+            		vars.remove(key);
+            	}
+            }
+            in.close();
+        }
+        catch (Exception e)
+        {
+            // nothing to see, move along...
+        }
+        HashSet<String> usedVars = new HashSet<String>();
+    	Set<String> keys = vars.keySet();
+    	for (String key : keys)
+    	{
+    		usedVars.add(vars.get(key));
+    	}
+        return usedVars;
+    }
+    
     @SuppressWarnings( "deprecation" )
     private void initExterns()
     {
@@ -153,10 +283,62 @@ public class JSClosureCompilerWrapper
         }
     }
     
+    private void filterOptions(List<String> args)
+    {
+		final String PROPERTY_MAP = "--property_map_output_file ";
+		final String VARIABLE_MAP = "--variable_map_output_file ";
+		final String PROPERTY_INPUT_MAP = "--property_map_input_file ";
+		final String VARIABLE_INPUT_MAP = "--variable_map_input_file ";
+		String propEntry = null;
+		String varEntry = null;
+		String propInputEntry = null;
+		String varInputEntry = null;
+
+    	for (String s : args)
+    	{
+    		if (s.startsWith(PROPERTY_MAP))
+    		{
+    			propEntry = s;
+    			propertyMapOutputPath = s.substring(PROPERTY_MAP.length());
+    		}
+    		
+    		if (s.startsWith(PROPERTY_INPUT_MAP))
+    		{
+    			propInputEntry = s;
+    			propertyMapInputPath = s.substring(PROPERTY_INPUT_MAP.length());
+    		}
+    		
+    		if (s.startsWith(VARIABLE_MAP))
+    		{
+    			varEntry = s;
+    			variableMapOutputPath = s.substring(VARIABLE_MAP.length());
+    		}
+    			
+    		if (s.startsWith(VARIABLE_INPUT_MAP))
+    		{
+    			varInputEntry = s;
+    			variableMapInputPath = s.substring(VARIABLE_INPUT_MAP.length());
+    		}
+    	}
+    	if (varEntry != null)
+    		args.remove(varEntry);
+    	if (propEntry != null)
+    		args.remove(propEntry);
+    	if (varInputEntry != null)
+    		args.remove(varInputEntry);
+    	if (propInputEntry != null)
+    		args.remove(propInputEntry);
+    		
+    }
+    
     private void initOptions(List<String> args)
     {
     	final String JS_FLAG = "--js ";
-    	
+		final String PROPERTY_MAP = "--property_map_output_file ";
+		final String VARIABLE_MAP = "--variable_map_output_file ";
+		String propEntry = null;
+		String varEntry = null;
+
     	boolean hasCompilationLevel = false;
     	boolean hasWarningLevel = false;
     	for (String s : args)
@@ -171,7 +353,25 @@ public class JSClosureCompilerWrapper
     		if (s.startsWith("--warning_level ") ||
     			s.startsWith("-W "))
     			hasWarningLevel = true;
+    		
+    		if (s.startsWith(PROPERTY_MAP))
+    		{
+    			propEntry = s;
+    			propertyMapOutputPath = s.substring(PROPERTY_MAP.length());
+    		}
+    		
+    		if (s.startsWith(VARIABLE_MAP))
+    		{
+    			varEntry = s;
+    			variableMapOutputPath = s.substring(VARIABLE_MAP.length());
+    		}
+    			
     	}
+    	if (varEntry != null)
+    		args.remove(varEntry);
+    	if (propEntry != null)
+    		args.remove(propEntry);
+    		
     	if (!hasCompilationLevel)
     		CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(
                 options_);


Mime
View raw message