flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject svn commit: r1433931 - /flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
Date Wed, 16 Jan 2013 13:31:46 GMT
Author: erikdebruin
Date: Wed Jan 16 13:31:45 2013
New Revision: 1433931

URL: http://svn.apache.org/viewvc?rev=1433931&view=rev
Log:
- I've been tinkering with the 'compile' method to get it to output an entire project to JS
when run in Eclipse with the arguments listed below, please verify for any silly n00b mistakes...

--> arguments: -load-config="[path with spaces]" +env.PLAYERGLOBAL_HOME=[path] +playerglobal.version=11.1
-output=[full path (with JS file name)] [full path (with AS file name)]

Modified:
    flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java

Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java?rev=1433931&r1=1433930&r2=1433931&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
(original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/clients/MXMLJSC.java
Wed Jan 16 13:31:45 2013
@@ -46,7 +46,7 @@ import org.apache.flex.compiler.exceptio
 import org.apache.flex.compiler.exceptions.ConfigurationException.MustSpecifyTarget;
 import org.apache.flex.compiler.exceptions.ConfigurationException.OnlyOneSource;
 import org.apache.flex.compiler.internal.js.codegen.JSSharedData;
-import org.apache.flex.compiler.internal.js.driver.JSBackend;
+import org.apache.flex.compiler.internal.js.driver.goog.GoogBackend;
 import org.apache.flex.compiler.internal.projects.CompilerProject;
 import org.apache.flex.compiler.internal.projects.FlexProject;
 import org.apache.flex.compiler.internal.projects.ISourceFileHandler;
@@ -105,7 +105,8 @@ public class MXMLJSC
     {
         long startTime = System.nanoTime();
 
-        final IBackend backend = new JSBackend();
+        //final IBackend backend = new JSBackend();
+        final IBackend backend = new GoogBackend();
         final MXMLJSC mxmlc = new MXMLJSC(backend);
         final Set<ICompilerProblem> problems = new HashSet<ICompilerProblem>();
         final int exitCode = mxmlc.mainNoExit(args, problems, true);
@@ -265,39 +266,40 @@ public class MXMLJSC
                 }
 
                 final File outputFile = new File(getOutputFilePath());
-
                 final File outputFolder = new File(outputFile.getParent());
+                
                 List<ICompilationUnit> reachableCompilationUnits = project
                         .getReachableCompilationUnitsInSWFOrder(ImmutableSet
                                 .of(mainCU));
                 for (final ICompilationUnit cu : reachableCompilationUnits)
                 {
                     if (cu.getCompilationUnitType() == ICompilationUnit.UnitType.AS_UNIT
-                            && cu != mainCU)
+                            /* && cu != mainCU */)
                     {
-                        final File outputClassFile = new File(
-                                outputFolder.getAbsolutePath() + File.separator
-                                        + cu.getShortNames().get(0) + ".js");
-                        System.out.println(outputClassFile.getAbsolutePath());
-
-                        for (ICompilationUnit unit : reachableCompilationUnits)
-                        {
+                        final File outputClassFile = 
+                        		getOutputClassFile(cu.getQualifiedNames().get(0), 
+                        				outputFolder);
+
+                        //for (ICompilationUnit unit : reachableCompilationUnits)
+                        //{
+                        	ICompilationUnit unit = cu;
                             IASWriter jswriter = JSSharedData.backend
                                     .createWriter(project,
                                             (List<ICompilerProblem>) errors,
                                             unit, false);
 
-                            if (unit.getCompilationUnitType() != ICompilationUnit.UnitType.AS_UNIT)
-                                continue;
+                            //if (unit.getCompilationUnitType() != ICompilationUnit.UnitType.AS_UNIT)
+                                //continue;
 
                             // XXX hack what is CountingOutputStream?
-                            BufferedOutputStream out = new BufferedOutputStream(
-                                    new FileOutputStream(outputClassFile));
+                            BufferedOutputStream out = 
+                            		new BufferedOutputStream(
+                            				new FileOutputStream(outputClassFile));
                             jswriter.writeTo(out);
                             out.flush();
                             out.close();
                             jswriter.close();
-                        }
+                        //}
                     }
                 }
                 compilationSuccess = true;
@@ -392,6 +394,40 @@ public class MXMLJSC
     }
 
     /**
+     * @author Erik de Bruin
+     * 
+     * Get the output class file. This includes the (sub)directory in which the
+     * original class file lives. If the directory structure doesn't exist, it
+     * is created.
+     * 
+     * @param qname
+     * @param outputFolder
+     * @return output class file path
+     */
+    private File getOutputClassFile(String qname, File outputFolder)
+    {
+    	String[] cname = qname.split("\\.");
+    	String sdirPath = outputFolder.getAbsolutePath() + File.separator;
+        if (cname.length > 0)
+        {
+        	for (int i = 0, n = cname.length - 1; i < n; i++)
+        	{
+        		sdirPath += cname[i] + File.separator;
+        	}
+        	
+        	//System.out.println(sdirPath);
+        	
+        	File sdir = new File(sdirPath);
+        	if (!sdir.exists())
+        		sdir.mkdirs();
+        	
+        	qname = cname[cname.length - 1];
+        }
+        
+        return new File(sdirPath + qname + "." + JSSharedData.OUTPUT_EXTENSION);
+    }
+
+    /**
      * Mxmlc uses target file as the main compilation unit and derive the output
      * SWF file name from this file.
      * 



Mime
View raw message