You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2014/11/02 20:34:57 UTC

git commit: [flex-falcon] [refs/heads/feature/flexmojos-tests] - - Increased the visibility of some of the SWFDump methods - Implemented a maven plugin to dump the ABC data of the classes of a SWF into a directory of "abc"-files.

Repository: flex-falcon
Updated Branches:
  refs/heads/feature/flexmojos-tests 2c4f63117 -> ac95268d2


- Increased the visibility of some of the SWFDump methods
- Implemented a maven plugin to dump the ABC data of the classes of a SWF into a directory of "abc"-files.


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

Branch: refs/heads/feature/flexmojos-tests
Commit: ac95268d2ea430d55deedcbd732932297f21c8b4
Parents: 2c4f631
Author: Christofer Dutz <ch...@codecentric.de>
Authored: Sun Nov 2 20:34:47 2014 +0100
Committer: Christofer Dutz <ch...@codecentric.de>
Committed: Sun Nov 2 20:34:47 2014 +0100

----------------------------------------------------------------------
 flexmojos-tests/bindable-interface/pom.xml      |  26 ++++-
 .../src/main/flex/TestApplication.mxml          |  24 ++++
 .../src/main/flex/TestClass.as                  |  33 ++++++
 flexmojos-tests/bytecode-dumper/pom.xml         |  82 +++++++++++++
 .../flex/swf/io/SWFDumpDirectoryWriter.java     | 114 +++++++++++++++++++
 .../org/apache/flex/swf/io/SWFDumpMojo.java     |  53 +++++++++
 .../src/main/flex/styles.css                    |   2 +
 flexmojos-tests/pom.xml                         |   4 +
 8 files changed, 336 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ac95268d/flexmojos-tests/bindable-interface/pom.xml
----------------------------------------------------------------------
diff --git a/flexmojos-tests/bindable-interface/pom.xml b/flexmojos-tests/bindable-interface/pom.xml
index 1611374..e67fb84 100644
--- a/flexmojos-tests/bindable-interface/pom.xml
+++ b/flexmojos-tests/bindable-interface/pom.xml
@@ -23,7 +23,7 @@
     <groupId>org.apache.flex.compiler.falcon.tests</groupId>
     <artifactId>bindable-interface</artifactId>
     <version>1.0.0-SNAPSHOT</version>
-    <packaging>swc</packaging>
+    <packaging>swf</packaging>
 
 	<build>
         <sourceDirectory>src/main/flex</sourceDirectory>
@@ -33,14 +33,36 @@
                 <artifactId>flexmojos-maven-plugin</artifactId>
                 <version>7.1.0-SNAPSHOT</version>
                 <extensions>true</extensions>
+                <configuration>
+                    <sourceFile>TestApplication.mxml</sourceFile>
+                </configuration>
                 <dependencies>
-                    <dependency>
+                    <!--dependency>
                         <groupId>org.apache.flex.compiler</groupId>
                         <artifactId>falcon-compiler</artifactId>
                         <version>0.0.3-SNAPSHOT</version>
+                    </dependency-->
+                    <dependency>
+                        <groupId>org.apache.flex</groupId>
+                        <artifactId>compiler</artifactId>
+                        <version>4.13.0.20140701</version>
+                        <type>pom</type>
                     </dependency>
                 </dependencies>
             </plugin>
+            <plugin>
+                <groupId>org.apache.flex.compiler.falcon.tests</groupId>
+                <artifactId>bytecode-dumper</artifactId>
+                <version>1.0.0-SNAPSHOT</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>dump</goal>
+                        </goals>
+                        <phase>package</phase>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ac95268d/flexmojos-tests/bindable-interface/src/main/flex/TestApplication.mxml
----------------------------------------------------------------------
diff --git a/flexmojos-tests/bindable-interface/src/main/flex/TestApplication.mxml b/flexmojos-tests/bindable-interface/src/main/flex/TestApplication.mxml
new file mode 100644
index 0000000..388726c
--- /dev/null
+++ b/flexmojos-tests/bindable-interface/src/main/flex/TestApplication.mxml
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+  Created by christoferdutz on 01.11.14.
+-->
+<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
+
+    <fx:Script><![CDATA[
+        import spark.events.TextOperationEvent;
+
+        public var tst:TestClass = new TestClass();
+
+        private function onInputChange(event:TextOperationEvent):void {
+            tst.tst = input.text;
+        }
+
+        ]]></fx:Script>
+
+    <s:VGroup>
+        <s:TextInput id="input" change="label.text = input.text"/>
+
+        <s:Label id="label" text="Lalala: {tst.tst}"/>
+    </s:VGroup>
+
+</s:Application>

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ac95268d/flexmojos-tests/bindable-interface/src/main/flex/TestClass.as
----------------------------------------------------------------------
diff --git a/flexmojos-tests/bindable-interface/src/main/flex/TestClass.as b/flexmojos-tests/bindable-interface/src/main/flex/TestClass.as
new file mode 100644
index 0000000..91e5309
--- /dev/null
+++ b/flexmojos-tests/bindable-interface/src/main/flex/TestClass.as
@@ -0,0 +1,33 @@
+/*
+ *
+ *  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 {
+
+[Bindable]
+public class TestClass implements TestInterface {
+
+    public var tst:String;
+
+    public function TestClass() {
+    }
+
+    public function someFunct():void {
+    }
+
+}
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ac95268d/flexmojos-tests/bytecode-dumper/pom.xml
----------------------------------------------------------------------
diff --git a/flexmojos-tests/bytecode-dumper/pom.xml b/flexmojos-tests/bytecode-dumper/pom.xml
new file mode 100644
index 0000000..561e21a
--- /dev/null
+++ b/flexmojos-tests/bytecode-dumper/pom.xml
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+  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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.flex.compiler.falcon.tests</groupId>
+    <artifactId>bytecode-dumper</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <packaging>maven-plugin</packaging>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-plugin-plugin</artifactId>
+                <version>3.3</version>
+                <configuration>
+                    <!-- see http://jira.codehaus.org/browse/MNG-5346 -->
+                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>mojo-descriptor</id>
+                        <goals>
+                            <goal>descriptor</goal>
+                        </goals>
+                    </execution>
+                    <!-- if you want to generate help goal -->
+                    <execution>
+                        <id>help-goal</id>
+                        <goals>
+                            <goal>helpmojo</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>3.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven.plugin-tools</groupId>
+            <artifactId>maven-plugin-annotations</artifactId>
+            <version>3.3</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-project</artifactId>
+            <version>2.2.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.flex.compiler</groupId>
+            <artifactId>falcon-compiler</artifactId>
+            <version>0.0.3-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ac95268d/flexmojos-tests/bytecode-dumper/src/main/java/org/apache/flex/swf/io/SWFDumpDirectoryWriter.java
----------------------------------------------------------------------
diff --git a/flexmojos-tests/bytecode-dumper/src/main/java/org/apache/flex/swf/io/SWFDumpDirectoryWriter.java b/flexmojos-tests/bytecode-dumper/src/main/java/org/apache/flex/swf/io/SWFDumpDirectoryWriter.java
new file mode 100644
index 0000000..6785764
--- /dev/null
+++ b/flexmojos-tests/bytecode-dumper/src/main/java/org/apache/flex/swf/io/SWFDumpDirectoryWriter.java
@@ -0,0 +1,114 @@
+package org.apache.flex.swf.io;
+
+import org.apache.maven.plugin.logging.Log;
+
+import java.io.*;
+
+/**
+ * Created by christoferdutz on 02.11.14.
+ */
+public class SWFDumpDirectoryWriter {
+
+    private File parentDirectory;
+    private Log log;
+
+    public SWFDumpDirectoryWriter(File file, Log log) {
+        super();
+        this.log = log;
+        this.parentDirectory = new File(file, "abc");
+        if(!parentDirectory.exists()) {
+            if(!parentDirectory.mkdirs()) {
+                throw new RuntimeException("Couldn't create root directory.");
+            }
+        }
+    }
+
+    public void dump(BufferedReader reader) throws IOException {
+        int currentClassId = -1;
+        PrintWriter currentClassPrintWriter = null;
+        String headerBuffer = "";
+
+        String line;
+        while((line = reader.readLine()) != null) {
+            // Start a new class ...
+            if(line.startsWith("// class_id=") && (currentClassId == -1)) {
+                String classId = line.substring(12, line.indexOf(" ", 12));
+                currentClassId = Integer.valueOf(classId);
+            }
+            else if((currentClassId != -1) && (currentClassPrintWriter == null)) {
+                String path = getFileName(line);
+                if(path != null) {
+                    File currentClassFile = new File(parentDirectory, getFileName(line));
+                    File outputDirectory = currentClassFile.getParentFile();
+                    if(!outputDirectory.exists()) {
+                        if(!outputDirectory.mkdirs()) {
+                            throw new RuntimeException("Couldn't create directory for output: " +
+                                    outputDirectory.getAbsolutePath());
+                        }
+                    }
+                    currentClassPrintWriter = new PrintWriter(currentClassFile);
+                    if(!headerBuffer.isEmpty()) {
+                        currentClassPrintWriter.print(headerBuffer);
+                        headerBuffer = "";
+                    }
+                    currentClassPrintWriter.println(line);
+                } else {
+                    headerBuffer += line + "\n";
+                }
+            }
+            // End a class ...
+            else if(line.startsWith("// script ")) {
+                if(currentClassPrintWriter != null) {
+                    currentClassPrintWriter.flush();
+                    currentClassPrintWriter.close();
+                    currentClassId = -1;
+                    currentClassPrintWriter = null;
+                    headerBuffer = "";
+                }
+            }
+            // Dump the content for
+            else {
+                if(currentClassPrintWriter != null) {
+                    currentClassPrintWriter.println(line);
+                }
+                if(!headerBuffer.isEmpty()) {
+                    headerBuffer += line;
+                }
+            }
+
+            log.debug(line);
+        }
+    }
+
+    private String getFileName(String line) {
+        String[] parts = line.split(" ");
+        if(parts.length < 3) {
+            return null;
+        }
+
+        // First segment must be "public", "protected" or "private"
+        if(parts[0].equals("public") || parts[0].equals("protected") || parts[0].equals("protected")) {
+            if("final".equals(parts[1])) {
+                if("class".equals(parts[2])) {
+                    return parts[3].replaceAll("::", ".").replaceAll("\\.", File.separator) + ".abc";
+                } else if("interface".equals(parts[2])) {
+                    return parts[3].replaceAll("::", ".").replaceAll("\\.", File.separator) + ".abc";
+                }
+            } else if("dynamic".equals(parts[1])) {
+                if("class".equals(parts[2])) {
+                    return parts[3].replaceAll("::", ".").replaceAll("\\.", File.separator) + ".abc";
+                } else if("interface".equals(parts[2])) {
+                    return parts[3].replaceAll("::", ".").replaceAll("\\.", File.separator) + ".abc";
+                }
+            } else {
+                if("class".equals(parts[1])) {
+                    return parts[2].replaceAll("::", ".").replaceAll("\\.", File.separator) + ".abc";
+                } else if("interface".equals(parts[1])) {
+                    return parts[2].replaceAll("::", ".").replaceAll("\\.", File.separator) + ".abc";
+                }
+            }
+        }
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ac95268d/flexmojos-tests/bytecode-dumper/src/main/java/org/apache/flex/swf/io/SWFDumpMojo.java
----------------------------------------------------------------------
diff --git a/flexmojos-tests/bytecode-dumper/src/main/java/org/apache/flex/swf/io/SWFDumpMojo.java b/flexmojos-tests/bytecode-dumper/src/main/java/org/apache/flex/swf/io/SWFDumpMojo.java
new file mode 100644
index 0000000..b068285
--- /dev/null
+++ b/flexmojos-tests/bytecode-dumper/src/main/java/org/apache/flex/swf/io/SWFDumpMojo.java
@@ -0,0 +1,53 @@
+package org.apache.flex.swf.io;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.plugins.annotations.Execute;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+
+import java.io.*;
+import java.net.URL;
+
+/**
+ */
+@Mojo(name = "dump")
+@Execute(
+        goal = "dump",
+        phase = LifecyclePhase.PACKAGE)
+public class SWFDumpMojo extends AbstractMojo {
+
+    @Parameter( defaultValue = "${project}", readonly = true )
+    private MavenProject project;
+
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+
+        try {
+            Artifact artifact = project.getArtifact();
+            File artifactFile = artifact.getFile();
+            URL inputUrl = new URL("file://" + artifactFile.getPath());
+
+            // Configure SWFDump to dump abc information
+            SWFDump.abcOption = true;
+
+            // Redirect the output of SWFDump through into a string buffer.
+            StringWriter output = new StringWriter();
+            SWFDump.dumpSwf(new PrintWriter(output), inputUrl, null);
+
+            // Dump the content of the string buffer into separate files.
+            BufferedReader reader = new BufferedReader(new StringReader(output.toString()));
+            Log log = getLog();
+            SWFDumpDirectoryWriter directoryWriter = new SWFDumpDirectoryWriter(artifactFile.getParentFile(), log);
+            directoryWriter.dump(reader);
+        } catch(IOException e) {
+            throw new MojoExecutionException("Failed to dump abc information.", e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ac95268d/flexmojos-tests/css-with-missing-namespace/src/main/flex/styles.css
----------------------------------------------------------------------
diff --git a/flexmojos-tests/css-with-missing-namespace/src/main/flex/styles.css b/flexmojos-tests/css-with-missing-namespace/src/main/flex/styles.css
index 9b52909..c736956 100644
--- a/flexmojos-tests/css-with-missing-namespace/src/main/flex/styles.css
+++ b/flexmojos-tests/css-with-missing-namespace/src/main/flex/styles.css
@@ -17,6 +17,8 @@
  *
  */
 
+@namespace s "library://ns.adobe.com/flex/spark";
+
 Label
 {
 	fontSize: 10px;

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ac95268d/flexmojos-tests/pom.xml
----------------------------------------------------------------------
diff --git a/flexmojos-tests/pom.xml b/flexmojos-tests/pom.xml
index e341e0d..7235c03 100644
--- a/flexmojos-tests/pom.xml
+++ b/flexmojos-tests/pom.xml
@@ -29,6 +29,10 @@
 
     <modules>
         <!--
+            Tool for comparing swfdump output from the default and falcon compiler
+        -->
+        <module>bytecode-dumper</module>
+        <!--
             Problem area: ASDoc doesn't work at all.
         -->