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] - try revisiting main class to inject Language require if needed. The flag may be set after the mainCU gets written
Date Sun, 14 Jun 2015 06:14:50 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 1f72b5451 -> 53ed68ef7


try revisiting main class to inject Language require if needed.  The flag may be set after
the mainCU gets written


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

Branch: refs/heads/develop
Commit: 53ed68ef76b7289a8cd024c24497f59e15b99f24
Parents: 1f72b54
Author: Alex Harui <aharui@apache.org>
Authored: Sat Jun 13 23:13:47 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Sat Jun 13 23:14:33 2015 -0700

----------------------------------------------------------------------
 .../flex/compiler/internal/test/TestBase.java   | 87 ++++++++++++++++++++
 .../mxml/flexjs/MXMLFlexJSPublisher.java        | 33 +++++++-
 2 files changed, 119 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/53ed68ef/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/TestBase.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/TestBase.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/TestBase.java
index 2a2e90b..cd69242 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/TestBase.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/test/TestBase.java
@@ -41,7 +41,10 @@ import org.apache.flex.compiler.codegen.as.IASEmitter;
 import org.apache.flex.compiler.codegen.mxml.IMXMLEmitter;
 import org.apache.flex.compiler.config.Configurator;
 import org.apache.flex.compiler.driver.IBackend;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.as.ASFilterWriter;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.projects.FlexProject;
 import org.apache.flex.compiler.internal.projects.FlexProjectConfigurator;
@@ -277,9 +280,93 @@ public class TestBase implements ITestBase
             }
         }
 
+        File outputRootDir = new File(
+                FilenameNormalization.normalize(tempDir
+                        + File.separator + inputDirName));
+        String qname;
+		try {
+			qname = mainCU.getQualifiedNames().get(0);
+	        final File outputClassFile = getOutputClassFile(qname
+	                + "_output", outputRootDir);
+	        appendLanguage(outputClassFile.getAbsolutePath(), qname);
+		} catch (InterruptedException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
         return compiledFileNames;
     }
 
+    protected void writeFile(String path, String content, boolean append)
+    throws IOException
+	{
+		File tgtFile = new File(path);
+		
+		if (!tgtFile.exists())
+		    tgtFile.createNewFile();
+		
+		FileWriter fw = new FileWriter(tgtFile, append);
+		fw.write(content);
+		fw.close();
+	}
+    
+    private void appendLanguage(String path, String projectName)
+	throws IOException
+	{
+		StringBuilder appendString = new StringBuilder();
+		appendString.append(JSGoogEmitterTokens.GOOG_REQUIRE.getToken());
+		appendString.append(ASEmitterTokens.PAREN_OPEN.getToken());
+		appendString.append(ASEmitterTokens.SINGLE_QUOTE.getToken());
+		appendString.append(JSFlexJSEmitterTokens.LANGUAGE_QNAME.getToken());
+		appendString.append(ASEmitterTokens.SINGLE_QUOTE.getToken());
+		appendString.append(ASEmitterTokens.PAREN_CLOSE.getToken());
+		appendString.append(ASEmitterTokens.SEMICOLON.getToken());
+		
+	    String fileData = readCode(new File(path));
+	    int reqidx = fileData.indexOf(appendString.toString());
+
+	    if (reqidx == -1 && project instanceof FlexJSProject && ((FlexJSProject)project).needLanguage)
+	    {
+	    	reqidx = fileData.lastIndexOf(JSGoogEmitterTokens.GOOG_REQUIRE.getToken());
+	    	if (reqidx == -1)
+	    		reqidx = fileData.lastIndexOf(JSGoogEmitterTokens.GOOG_PROVIDE.getToken());
+	    	reqidx = fileData.indexOf(";", reqidx);
+		    String after = fileData.substring(reqidx + 1);
+		    String before = fileData.substring(0, reqidx + 1);
+		    String s = before + "\n" + appendString.toString() + after;
+		    writeFile(path, s, false);
+	    }
+	}
+	
+	protected String readCode(File file)
+	{
+	    String code = "";
+	    try
+	    {
+	        BufferedReader in = new BufferedReader(new InputStreamReader(
+	                new FileInputStream(file), "UTF8"));
+	
+	        String line = in.readLine();
+	
+	        while (line != null)
+	        {
+	            code += line + "\n";
+	            line = in.readLine();
+	        }
+	        code = code.substring(0, code.length() - 1);
+	
+	        in.close();
+	    }
+	    catch (Exception e)
+	    {
+	        // nothing to see, move along...
+	    }
+	
+	    return code;
+	}
+
     protected File getOutputClassFile(String qname, File outputFolder)
     {
         String[] cname = qname.split("\\.");

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/53ed68ef/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
index 53a6181..4292534 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSPublisher.java
@@ -39,7 +39,9 @@ import org.apache.commons.io.filefilter.RegexFileFilter;
 import org.apache.flex.compiler.clients.problems.ProblemQuery;
 import org.apache.flex.compiler.codegen.js.IJSPublisher;
 import org.apache.flex.compiler.config.Configuration;
+import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSharedData;
+import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogPublisher;
 import org.apache.flex.compiler.internal.driver.js.flexjs.JSCSSCompilationSession;
@@ -255,6 +257,7 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements
 
         appendExportSymbol(projectIntermediateJSFilePath, projectName);
         appendEncodedCSS(projectIntermediateJSFilePath, projectName);
+        appendLanguage(projectIntermediateJSFilePath, projectName);
 
         //if (!subsetGoog)
         //{
@@ -522,7 +525,35 @@ public class MXMLFlexJSPublisher extends JSGoogPublisher implements
             writeFile(path, appendString.toString(), true);
         }
     }
-        
+     
+    private void appendLanguage(String path, String projectName)
+    	throws IOException
+	{
+		StringBuilder appendString = new StringBuilder();
+		appendString.append(JSGoogEmitterTokens.GOOG_REQUIRE.getToken());
+		appendString.append(ASEmitterTokens.PAREN_OPEN.getToken());
+		appendString.append(ASEmitterTokens.SINGLE_QUOTE.getToken());
+		appendString.append(JSFlexJSEmitterTokens.LANGUAGE_QNAME.getToken());
+		appendString.append(ASEmitterTokens.SINGLE_QUOTE.getToken());
+		appendString.append(ASEmitterTokens.PAREN_CLOSE.getToken());
+		appendString.append(ASEmitterTokens.SEMICOLON.getToken());
+		appendString.append(File.separator);
+		
+	    String fileData = readCode(new File(path));
+	    int reqidx = fileData.indexOf(appendString.toString());
+	    if (reqidx == -1 && project.needLanguage)
+	    {
+	    	reqidx = fileData.lastIndexOf(JSGoogEmitterTokens.GOOG_REQUIRE.getToken());
+	    	if (reqidx == -1)
+	    		reqidx = fileData.lastIndexOf(JSGoogEmitterTokens.GOOG_PROVIDE.getToken());
+	    	reqidx = fileData.indexOf(";", reqidx);
+		    String after = fileData.substring(reqidx + 1);
+		    String before = fileData.substring(0, reqidx + 1);
+		    String s = before + "\n" + appendString.toString() + after;
+		    writeFile(path, s, false);
+	    }
+	}
+
     protected String readCode(File file)
     {
         String code = "";


Mime
View raw message