You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by er...@apache.org on 2014/08/01 13:00:54 UTC

[33/33] git commit: [flex-falcon] [refs/heads/develop] - Initial 'shadow project' creation and handling.

Initial 'shadow project' creation and handling.


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

Branch: refs/heads/develop
Commit: 0eecfd1ed06a058a9ac8b59deb1d89f591ecbdfc
Parents: 92caf9b
Author: Erik de Bruin <er...@ixsoftware.nl>
Authored: Wed Jul 30 14:40:22 2014 +0200
Committer: Erik de Bruin <er...@ixsoftware.nl>
Committed: Fri Aug 1 12:59:16 2014 +0200

----------------------------------------------------------------------
 .../apache/flex/compiler/clients/MXMLJSC.java   |  25 +++-
 .../flex/compiler/utils/VF2JSProjectUtils.java  | 118 +++++++++++++++++++
 2 files changed, 141 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0eecfd1e/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
index 947b95a..e97361e 100644
--- a/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
+++ b/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
@@ -73,6 +73,7 @@ import org.apache.flex.compiler.targets.ITarget;
 import org.apache.flex.compiler.targets.ITarget.TargetType;
 import org.apache.flex.compiler.targets.ITargetSettings;
 import org.apache.flex.compiler.units.ICompilationUnit;
+import org.apache.flex.compiler.utils.VF2JSProjectUtils;
 import org.apache.flex.utils.FileUtils;
 import org.apache.flex.utils.FilenameNormalization;
 
@@ -149,12 +150,19 @@ public class MXMLJSC
 
         IBackend backend = new ASBackend();
         String jsOutputTypeString = "";
+        String projectFilePath = "";
         for (String s : args)
         {
+            String[] kvp = s.split("=");
+            
             if (s.contains("-js-output-type"))
             {
-                jsOutputTypeString = s.split("=")[1];
-                break;
+                jsOutputTypeString = kvp[1];
+            }
+            
+            if (kvp.length == 1) // input file path
+            {
+                projectFilePath = kvp[0];
             }
         }
         
@@ -176,6 +184,19 @@ public class MXMLJSC
             backend = new GoogBackend();
             break;
         case VF2JS:
+            String newProjectFilePath = 
+                VF2JSProjectUtils.createTempProject(projectFilePath);
+
+            for (int i = 0; i < args.length; i++)
+            {
+                String[] kvp = args[i].split("=");
+                
+                if (kvp.length == 1) // input file path
+                {
+                    args[i] = newProjectFilePath;
+                }
+            }
+
             backend = new MXMLFlexJSBackend();
             break;
         }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0eecfd1e/compiler.jx/src/org/apache/flex/compiler/utils/VF2JSProjectUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/utils/VF2JSProjectUtils.java b/compiler.jx/src/org/apache/flex/compiler/utils/VF2JSProjectUtils.java
new file mode 100644
index 0000000..4f43328
--- /dev/null
+++ b/compiler.jx/src/org/apache/flex/compiler/utils/VF2JSProjectUtils.java
@@ -0,0 +1,118 @@
+package org.apache.flex.compiler.utils;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+
+import com.google.common.io.Files;
+
+
+public class VF2JSProjectUtils
+{
+
+    private static File tempDir;
+    
+    public static final String createTempProject(String projectFilePath)
+    {
+        tempDir = Files.createTempDir();
+        tempDir.deleteOnExit();
+        
+        String path = projectFilePath.substring(0, projectFilePath.lastIndexOf(File.separator));
+        
+        createTempProjectDir(new File(path).listFiles(), "");
+        
+        String fileName = projectFilePath.substring(projectFilePath.lastIndexOf(File.separator) + 1, projectFilePath.length());
+        
+        return tempDir.getAbsolutePath() + File.separator + fileName;
+    }
+
+    private static void createTempProjectDir(File[] files, String parentPath)
+    {
+        for (File file : files) 
+        {
+            if (file.isDirectory()) 
+            {
+                String path = parentPath + File.separator + file.getName(); 
+                
+                new File(tempDir + File.separator + path).mkdirs();
+
+                createTempProjectDir(file.listFiles(), path);
+            } 
+            else 
+            {
+                String fileName = file.getName();
+
+                if (fileName.contains(".") && fileName.charAt(0) != '.')
+                {
+                    String extension = fileName.substring(fileName.lastIndexOf("."), fileName.length());
+    
+                    if (extension.equals(".mxml") || extension.equals(".as"))
+                    {
+                        File intermediateFile = file;
+                        String tempFileName = fileName.substring(0, fileName.indexOf("."));
+                        File targetDir = new File(tempDir + File.separator + parentPath);
+
+                        System.out.println("NEWLOC " + targetDir.getAbsolutePath());
+                        
+                        File newFile = createTempFileWithVF2JSNamespace(intermediateFile, 
+                                tempFileName, false, targetDir, extension);
+
+                        System.out.println("NEWFILE " + newFile.getAbsolutePath());
+                    }
+                }
+            }
+        }
+    }
+    
+    private static File createTempFileWithVF2JSNamespace(File intermediateFile,
+            String tempFileName, boolean createTempFile, File targetDir,
+            String extension)
+    {
+        File tempFile = null;
+        
+        try 
+        {
+            String content = FileUtils.readFileToString(intermediateFile, "UTF-8");
+
+            // mx (MXML)
+            content = content.replace(
+                    "xmlns:mx=\"library://ns.adobe.com/flex/mx\"", 
+                    "xmlns:vf2js_mx=\"http://flex.apache.org/vf2js_mx/ns\"");
+            content = content.replace("<mx:", "<vf2js_mx:");
+            content = content.replace("</mx:", "</vf2js_mx:");
+
+            // mx (AS)
+            content = content.replace("mx.", "vf2js_mx.");
+
+            // s (MXML)
+            content = content.replace(
+                    "xmlns:s=\"library://ns.adobe.com/flex/spark\"", 
+                    "xmlns:vf2js_s=\"http://flex.apache.org/vf2js_s/ns\"");
+            content = content.replace("<s:", "<vf2js_s:");
+            content = content.replace("</s:", "</vf2js_s:");
+
+            // s (AS)
+            content = content.replace("spark.", "vf2js_s.");
+
+            if (createTempFile)
+            {
+                tempFile = File.createTempFile(tempFileName, extension,
+                        targetDir);
+                tempFile.deleteOnExit();
+            }
+            else
+            {
+                tempFile = new File(targetDir.getAbsolutePath(),
+                        tempFileName + extension);
+            }
+            FileUtils.writeStringToFile(tempFile, content, "UTF-8");
+        } 
+        catch (IOException e) 
+        {
+            throw new RuntimeException("Generating file failed", e);
+        }
+
+        return tempFile;
+    }
+}