Repository: flex-falcon Updated Branches: refs/heads/develop 818397220 -> 704d6324b
- Refactored the compiler mojos (as and js) to utilize the FlexToolGroups (ASJS being the default) - Enforced the FlexToolGroup "Falcon" for all externs - Added the TweenJS lib to the build Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/704d6324 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/704d6324 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/704d6324 Branch: refs/heads/develop Commit: 704d6324b53acc2a003779dbb8c38abc16606752 Parents: 8183972 Author: Christofer Dutz <[email protected]> Authored: Tue Apr 26 16:54:14 2016 +0200 Committer: Christofer Dutz <[email protected]> Committed: Tue Apr 26 16:54:14 2016 +0200 ---------------------------------------------------------------------- externs/GCL/pom.xml | 3 + externs/cordova/pom.xml | 3 + externs/createjs/pom.xml | 55 +++--- .../src/main/config/compile-as-config.xml | 12 +- .../createjs/src/main/config/externc-config.xml | 82 ++++---- externs/google_maps/pom.xml | 3 + externs/jasmine/pom.xml | 3 + externs/jquery/pom.xml | 3 + externs/js/pom.xml | 3 + externs/node/pom.xml | 3 + .../flex/maven/flexjs/BaseCompileMojo.java | 189 +++++++++++++++++++ .../apache/flex/maven/flexjs/CompileASMojo.java | 182 ++---------------- .../apache/flex/maven/flexjs/CompileJSMojo.java | 68 ++----- 13 files changed, 329 insertions(+), 280 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/GCL/pom.xml ---------------------------------------------------------------------- diff --git a/externs/GCL/pom.xml b/externs/GCL/pom.xml index fcddaa4..0854ced 100644 --- a/externs/GCL/pom.xml +++ b/externs/GCL/pom.xml @@ -40,6 +40,9 @@ <artifactId>flexjs-maven-plugin</artifactId> <version>0.6.0-SNAPSHOT</version> <extensions>true</extensions> + <configuration> + <toolGroupName>Falcon</toolGroupName> + </configuration> <dependencies> <dependency> <groupId>org.apache.flex.flexjs.compiler</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/cordova/pom.xml ---------------------------------------------------------------------- diff --git a/externs/cordova/pom.xml b/externs/cordova/pom.xml index 9a35622..225eddd 100644 --- a/externs/cordova/pom.xml +++ b/externs/cordova/pom.xml @@ -44,6 +44,9 @@ <artifactId>flexjs-maven-plugin</artifactId> <version>0.6.0-SNAPSHOT</version> <extensions>true</extensions> + <configuration> + <toolGroupName>Falcon</toolGroupName> + </configuration> <dependencies> <dependency> <groupId>org.apache.flex.flexjs.compiler</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/createjs/pom.xml ---------------------------------------------------------------------- diff --git a/externs/createjs/pom.xml b/externs/createjs/pom.xml index 05642f8..8f2251c 100644 --- a/externs/createjs/pom.xml +++ b/externs/createjs/pom.xml @@ -35,16 +35,17 @@ <properties> <createjs.version>0.8.0</createjs.version> + <tweenjs.version>0.6.2</tweenjs.version> </properties> <build> <plugins> - <!-- Download easejs/createjs form GitHub and unpack it into the target directory --> <plugin> <groupId>com.googlecode.maven-download-plugin</groupId> <artifactId>download-maven-plugin</artifactId> <version>1.2.1</version> <executions> + <!-- Download easejs/createjs form GitHub and unpack it into the target directory --> <execution> <id>get-createjs</id> <phase>validate</phase> @@ -55,11 +56,26 @@ <url>https://github.com/CreateJS/EaselJS/archive/${createjs.version}.zip</url> <unpack>true</unpack> <outputFileName>createjs-${createjs.version}.zip</outputFileName> - <outputDirectory>${project.build.directory}</outputDirectory> + <outputDirectory>${project.build.directory}/downloads</outputDirectory> + </configuration> + </execution> + <!-- Download TweenJS form GitHub and unpack it into the target directory --> + <execution> + <id>get-tweenjs</id> + <phase>validate</phase> + <goals> + <goal>wget</goal> + </goals> + <configuration> + <url>https://github.com/CreateJS/TweenJS/archive/${tweenjs.version}.zip</url> + <unpack>true</unpack> + <outputFileName>tweenjs-${tweenjs.version}.zip</outputFileName> + <outputDirectory>${project.build.directory}/downloads</outputDirectory> </configuration> </execution> </executions> </plugin> + <plugin> <groupId>org.apache.flex.flexjs.compiler</groupId> <artifactId>compiler-build-tools</artifactId> @@ -102,6 +118,11 @@ <replace-regexp-operation><match>createjs.MovieClip.prototype.labels;</match><replace/></replace-regexp-operation> <!-- Remove the closing brackets at the end --> <replace-regexp-operation><match>\}(\)\(|\(\))\);</match><replace/></replace-regexp-operation> + <!-- Fixes needed by tweenjs --> + <replace-regexp-operation><match>@param data</match><replace>@param \{Object\} data</replace></replace-regexp-operation> + <replace-regexp-operation><match>@param ratio</match><replace>@param \{Number\} ratio</replace></replace-regexp-operation> + <replace-regexp-operation><match>@param target</match><replace>@param \{Object\} target</replace></replace-regexp-operation> + <replace-regexp-operation><match>\{any\}</match><replace>\{Object\}</replace></replace-regexp-operation> </operations> </configuration> </execution> @@ -113,7 +134,7 @@ </goals> <configuration> <includes> - <include>createjs/utils/Ticker.js</include> + <include>EaselJS-${createjs.version}/src/createjs/utils/Ticker.js</include> </includes> <operations> <cut-operation> @@ -132,7 +153,7 @@ </goals> <configuration> <includes> - <include>easeljs/display/Graphics.js</include> + <include>EaselJS-${createjs.version}/src/easeljs/display/Graphics.js</include> </includes> <operations> <cut-operation> @@ -142,29 +163,14 @@ </operations> </configuration> </execution> - <!-- It seems that excluding the files doesn't work, so we have to delete them --> - <!--execution> - <id>pre-process-delete-unused</id> - <phase>validate</phase> - <goals> - <goal>pre-process-sources</goal> - </goals> - <configuration> - <includes> - <include>easeljs/version.js</include> - <include>easeljs/version_movieclip.js</include> - </includes> - <operations> - <delete-file-operation/> - </operations> - </configuration> - </execution--> </executions> <configuration> <!-- Take the JavaScript from the previously downloaded and unpacked distribution --> - <downloadesSourceDirectory>${project.build.directory}/EaselJS-${createjs.version}/src</downloadesSourceDirectory> + <downloadesSourceDirectory>${project.build.directory}/downloads</downloadesSourceDirectory> <includes> - <include>**/*.js</include> + <include>EaselJS-${createjs.version}/src/createjs/**/*.js</include> + <include>EaselJS-${createjs.version}/src/easeljs/**/*.js</include> + <include>TweenJS-${tweenjs.version}/src/tweenjs/**/*.js</include> </includes> </configuration> </plugin> @@ -173,6 +179,9 @@ <artifactId>flexjs-maven-plugin</artifactId> <version>0.6.0-SNAPSHOT</version> <extensions>true</extensions> + <configuration> + <toolGroupName>Falcon</toolGroupName> + </configuration> <dependencies> <dependency> <groupId>org.apache.flex.flexjs.compiler</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/createjs/src/main/config/compile-as-config.xml ---------------------------------------------------------------------- diff --git a/externs/createjs/src/main/config/compile-as-config.xml b/externs/createjs/src/main/config/compile-as-config.xml index 1f946ac..3abbb9a 100644 --- a/externs/createjs/src/main/config/compile-as-config.xml +++ b/externs/createjs/src/main/config/compile-as-config.xml @@ -81,8 +81,16 @@ <path>../src/main/javascript/missing.js</path> </include-file> <include-file> - <name>externs/*</name> - <path>EaselJS-0.8.0/src</path> + <name>externs/createjs/*</name> + <path>downloads/EaselJS-0.8.0/src/createjs</path> + </include-file> + <include-file> + <name>externs/easeljs/*</name> + <path>downloads/EaselJS-0.8.0/src/easeljs</path> + </include-file> + <include-file> + <name>externs/tweenjs/*</name> + <path>downloads/TweenJS-0.6.2/src/tweenjs</path> </include-file> <!-- <include-file> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/createjs/src/main/config/externc-config.xml ---------------------------------------------------------------------- diff --git a/externs/createjs/src/main/config/externc-config.xml b/externs/createjs/src/main/config/externc-config.xml index 78b21aa..bcc9f05 100644 --- a/externs/createjs/src/main/config/externc-config.xml +++ b/externs/createjs/src/main/config/externc-config.xml @@ -60,47 +60,47 @@ </compiler> <external> - <path-element>../../../target/EaselJS-0.8.0/src/createjs/events/Event.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/createjs/events/EventDispatcher.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/createjs/utils/extend.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/createjs/utils/indexof.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/createjs/utils/promote.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/createjs/utils/Ticker.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/Bitmap.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/BitmapText.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/Container.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/DisplayObject.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/DOMElement.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/Graphics.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/MovieClip.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/Shadow.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/Shape.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/Sprite.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/SpriteContainer.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/SpriteSheet.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/SpriteStage.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/Stage.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/display/Text.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/events/MouseEvent.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/filters/AlphaMapFilter.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/filters/AlphaMaskFilter.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/filters/BlurFilter.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/filters/ColorFilter.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/filters/ColorMatrix.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/filters/ColorMatrixFilter.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/filters/Filter.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/geom/DisplayProps.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/geom/Matrix2D.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/geom/Point.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/geom/Rectangle.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/ui/ButtonHelper.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/ui/Touch.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/utils/SpriteSheetBuilder.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/utils/SpriteSheetUtils.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/easeljs/utils/UID.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/tweenjs/Ease.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/tweenjs/Timeline.js</path-element> - <path-element>../../../target/EaselJS-0.8.0/src/tweenjs/Tween.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/createjs/events/Event.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/createjs/events/EventDispatcher.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/createjs/utils/extend.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/createjs/utils/indexof.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/createjs/utils/promote.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/createjs/utils/Ticker.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/Bitmap.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/BitmapText.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/Container.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/DisplayObject.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/DOMElement.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/Graphics.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/MovieClip.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/Shadow.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/Shape.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/Sprite.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/SpriteContainer.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/SpriteSheet.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/SpriteStage.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/Stage.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/display/Text.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/events/MouseEvent.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/filters/AlphaMapFilter.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/filters/AlphaMaskFilter.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/filters/BlurFilter.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/filters/ColorFilter.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/filters/ColorMatrix.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/filters/ColorMatrixFilter.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/filters/Filter.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/geom/DisplayProps.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/geom/Matrix2D.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/geom/Point.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/geom/Rectangle.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/ui/ButtonHelper.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/ui/Touch.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/utils/SpriteSheetBuilder.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/utils/SpriteSheetUtils.js</path-element> + <path-element>../../../target/downloads/EaselJS-0.8.0/src/easeljs/utils/UID.js</path-element> + <path-element>../../../target/downloads/TweenJS-0.6.2/src/tweenjs/Ease.js</path-element> + <path-element>../../../target/downloads/TweenJS-0.6.2/src/tweenjs/Timeline.js</path-element> + <path-element>../../../target/downloads/TweenJS-0.6.2/src/tweenjs/Tween.js</path-element> </external> <as-root>../../../target/generated-sources/externc</as-root> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/google_maps/pom.xml ---------------------------------------------------------------------- diff --git a/externs/google_maps/pom.xml b/externs/google_maps/pom.xml index a3e4147..43b8c7a 100644 --- a/externs/google_maps/pom.xml +++ b/externs/google_maps/pom.xml @@ -92,6 +92,9 @@ google.maps = {};]]></replace></replace-regexp-operation> <artifactId>flexjs-maven-plugin</artifactId> <version>0.6.0-SNAPSHOT</version> <extensions>true</extensions> + <configuration> + <toolGroupName>Falcon</toolGroupName> + </configuration> <dependencies> <dependency> <groupId>org.apache.flex.flexjs.compiler</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/jasmine/pom.xml ---------------------------------------------------------------------- diff --git a/externs/jasmine/pom.xml b/externs/jasmine/pom.xml index c85f7e3..9a028f1 100644 --- a/externs/jasmine/pom.xml +++ b/externs/jasmine/pom.xml @@ -64,6 +64,9 @@ <artifactId>flexjs-maven-plugin</artifactId> <version>0.6.0-SNAPSHOT</version> <extensions>true</extensions> + <configuration> + <toolGroupName>Falcon</toolGroupName> + </configuration> <dependencies> <dependency> <groupId>org.apache.flex.flexjs.compiler</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/jquery/pom.xml ---------------------------------------------------------------------- diff --git a/externs/jquery/pom.xml b/externs/jquery/pom.xml index c37b94b..b71dd18 100644 --- a/externs/jquery/pom.xml +++ b/externs/jquery/pom.xml @@ -86,6 +86,9 @@ <artifactId>flexjs-maven-plugin</artifactId> <version>0.6.0-SNAPSHOT</version> <extensions>true</extensions> + <configuration> + <toolGroupName>Falcon</toolGroupName> + </configuration> <dependencies> <dependency> <groupId>org.apache.flex.flexjs.compiler</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/js/pom.xml ---------------------------------------------------------------------- diff --git a/externs/js/pom.xml b/externs/js/pom.xml index bd3dd0f..964b875 100644 --- a/externs/js/pom.xml +++ b/externs/js/pom.xml @@ -123,6 +123,9 @@ <artifactId>flexjs-maven-plugin</artifactId> <version>0.6.0-SNAPSHOT</version> <extensions>true</extensions> + <configuration> + <toolGroupName>Falcon</toolGroupName> + </configuration> <dependencies> <dependency> <groupId>org.apache.flex.flexjs.compiler</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/externs/node/pom.xml ---------------------------------------------------------------------- diff --git a/externs/node/pom.xml b/externs/node/pom.xml index 7233c7a..39dd3c7 100644 --- a/externs/node/pom.xml +++ b/externs/node/pom.xml @@ -66,6 +66,9 @@ <artifactId>flexjs-maven-plugin</artifactId> <version>0.6.0-SNAPSHOT</version> <extensions>true</extensions> + <configuration> + <toolGroupName>Falcon</toolGroupName> + </configuration> <dependencies> <dependency> <groupId>org.apache.flex.flexjs.compiler</groupId> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseCompileMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseCompileMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseCompileMojo.java new file mode 100644 index 0000000..92e548f --- /dev/null +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseCompileMojo.java @@ -0,0 +1,189 @@ +package org.apache.flex.maven.flexjs; + +import org.apache.flex.maven.flexjs.types.FlexScope; +import org.apache.flex.tools.FlexTool; +import org.apache.flex.tools.FlexToolGroup; +import org.apache.flex.tools.FlexToolRegistry; +import org.apache.maven.RepositoryUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.*; +import org.eclipse.aether.RepositorySystemSession; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Created by christoferdutz on 22.04.16. + */ +public abstract class BaseCompileMojo + extends AbstractMojo +{ + + @Parameter(defaultValue = "${project}", readonly = true) + protected MavenProject project; + + @Parameter(defaultValue="${project.build.directory}") + protected File outputDirectory; + + @Parameter(defaultValue = "FlexJS") + protected String toolGroupName; + + @Parameter(readonly = true, defaultValue = "${repositorySystemSession}") + private RepositorySystemSession repositorySystemSession; + + @Component + private ProjectDependenciesResolver projectDependenciesResolver; + + protected abstract File getConfigFile(); + + protected abstract String[] getCompilerArgs(File configFile); + + public void execute() + throws MojoExecutionException + { + File configFile = getConfigFile(); + if(!configFile.exists()) { + getLog().info(" - compilation config file '" + configFile.getPath() + + "' not found, skipping compilation"); + return; + } + + // Prepare the config file. + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + try { + // Resolve all the dependencies. + Set<Artifact> resolvedDependencies = resolveDependencies(); + + // Parse the input document. + DocumentBuilder builder = factory.newDocumentBuilder(); + Document configuration = builder.parse(new FileInputStream(configFile)); + + // Append the path-elements for the compile scope. + Set<Artifact> compileDependencies = getDependenciesForScope(resolvedDependencies, FlexScope.COMPILE); + outputLibraryPath(configuration, "flex-config/compiler/library-path", compileDependencies); + + // Append the path-elements for the external scope. + Set<Artifact> externalDependencies = getDependenciesForScope(resolvedDependencies, FlexScope.EXTERNAL); + outputLibraryPath(configuration, "flex-config/compiler/external-library-path", externalDependencies); + + // Write the modified config-file to the output directory. + File configFileOutput = new File(outputDirectory, configFile.getName()); + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Transformer transformer = transformerFactory.newTransformer(); + DOMSource source = new DOMSource(configuration); + StreamResult result = new StreamResult(configFileOutput); + transformer.transform(source, result); + + // Get the falcon tool group. + FlexToolRegistry toolRegistry = new FlexToolRegistry(); + FlexToolGroup toolGroup = toolRegistry.getToolGroup(toolGroupName); + if(toolGroup == null) { + throw new MojoExecutionException("Could not find tool group: Falcon"); + } + + // Get an instance of the compiler and run the build. + FlexTool compc = toolGroup.getFlexTool(FlexTool.FLEX_TOOL_COMPC); + compc.execute(getCompilerArgs(configFileOutput)); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (TransformerConfigurationException e) { + e.printStackTrace(); + } catch (TransformerException e) { + e.printStackTrace(); + } + } + + private Set<Artifact> resolveDependencies() throws MojoExecutionException { + DefaultDependencyResolutionRequest dependencyResolutionRequest = + new DefaultDependencyResolutionRequest(project, repositorySystemSession); + DependencyResolutionResult dependencyResolutionResult; + + try { + dependencyResolutionResult = projectDependenciesResolver.resolve(dependencyResolutionRequest); + } catch (DependencyResolutionException ex) { + throw new MojoExecutionException(ex.getMessage(), ex); + } + + Set<Artifact> artifacts = new LinkedHashSet<Artifact>(); + if (dependencyResolutionResult.getDependencyGraph() != null + && !dependencyResolutionResult.getDependencyGraph().getChildren().isEmpty()) { + RepositoryUtils.toArtifacts(artifacts, dependencyResolutionResult.getDependencyGraph().getChildren(), + Collections.singletonList(project.getArtifact().getId()), null); + } + return artifacts; + } + + private Set<Artifact> getDependenciesForScope(Set<Artifact> dependencies, FlexScope scope) { + Set<Artifact> artifacts = new LinkedHashSet<Artifact>(); + for(Artifact dependency : dependencies) { + FlexScope dependencyScope = FlexScope.COMPILE; + if(dependency.getScope() != null) { + dependencyScope = FlexScope.valueOf(dependency.getScope().toUpperCase()); + } + if(dependencyScope == scope) { + artifacts.add(dependency); + } + } + return artifacts; + } + + private void outputLibraryPath(Document configDocument, String baseXPath, Set<Artifact> artifacts) { + if(!artifacts.isEmpty()) { + XPathFactory xPathfactory = XPathFactory.newInstance(); + XPath xpath = xPathfactory.newXPath(); + try { + XPathExpression expr = xpath.compile(baseXPath); + Element externalLibraryPath = (Element) expr.evaluate(configDocument, XPathConstants.NODE); + if(externalLibraryPath != null) { + // Remove any existing path-elements (They are leftovers from the ant build). + Node child = externalLibraryPath.getFirstChild(); + while(child != null) { + externalLibraryPath.removeChild(child); + child = externalLibraryPath.getFirstChild(); + } + + // Add the new path-elements. + for (Artifact artifact : artifacts) { + Element newPathElement = configDocument.createElement("path-element"); + newPathElement.setTextContent(artifact.getFile().getAbsolutePath()); + externalLibraryPath.appendChild(newPathElement); + } + } else { + throw new RuntimeException("Could not find root element " + baseXPath); + } + } catch (XPathExpressionException e) { + throw new RuntimeException("Error adding path-element", e); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java index fa63c49..ad18d5b 100644 --- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASMojo.java @@ -16,198 +16,48 @@ package org.apache.flex.maven.flexjs; -import org.apache.flex.maven.flexjs.types.FlexScope; -import org.apache.flex.tools.FlexTool; -import org.apache.flex.tools.FlexToolGroup; -import org.apache.flex.tools.FlexToolRegistry; -import org.apache.maven.RepositoryUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; 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.*; -import org.eclipse.aether.RepositorySystemSession; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import javax.xml.xpath.*; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; /** * goal which compiles a project into a flexjs swc library. */ @Mojo(name="compile-as",defaultPhase = LifecyclePhase.PROCESS_SOURCES) public class CompileASMojo - extends AbstractMojo + extends BaseCompileMojo { - @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; - @Parameter(defaultValue="${basedir}/src/main/config/compile-as-config.xml") private File compileAsConfigFile; - @Parameter(defaultValue="${project.build.directory}") - private File outputDirectory; - @Parameter(defaultValue = "${project.artifactId}-${project.version}.swc") private String outputFileName; - @Parameter(readonly = true, defaultValue = "${repositorySystemSession}") - private RepositorySystemSession repositorySystemSession; - - @Component - private ProjectDependenciesResolver projectDependenciesResolver; - - public void execute() - throws MojoExecutionException - { - if(!compileAsConfigFile.exists()) { - getLog().info(" - compilation config file '" + compileAsConfigFile.getPath() + - "' not found, skipping compilation"); - return; - } - - // Prepare the config file. - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - try { - // Resolve all the dependencies. - Set<Artifact> resolvedDependencies = resolveDependencies(); - - // Parse the input document. - DocumentBuilder builder = factory.newDocumentBuilder(); - Document configuration = builder.parse(new FileInputStream(compileAsConfigFile)); - - // Append the path-elements for the compile scope. - Set<Artifact> compileDependencies = getDependenciesForScope(resolvedDependencies, FlexScope.COMPILE); - outputLibraryPath(configuration, "flex-config/compiler/library-path", compileDependencies); - - // Append the path-elements for the external scope. - Set<Artifact> externalDependencies = getDependenciesForScope(resolvedDependencies, FlexScope.EXTERNAL); - outputLibraryPath(configuration, "flex-config/compiler/external-library-path", externalDependencies); - - // Write the modified config-file to the output directory. - File configFileOutput = new File(outputDirectory, "compile-as-config.xml"); - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - DOMSource source = new DOMSource(configuration); - StreamResult result = new StreamResult(configFileOutput); - transformer.transform(source, result); - - // Get the falcon tool group. - FlexToolRegistry toolRegistry = new FlexToolRegistry(); - FlexToolGroup toolGroup = toolRegistry.getToolGroup("Falcon"); - if(toolGroup == null) { - throw new MojoExecutionException("Could not find tool group: Falcon"); - } - - // Get an instance of the compiler and run the build. - FlexTool compc = toolGroup.getFlexTool(FlexTool.FLEX_TOOL_COMPC); - File outputFile = new File(outputDirectory, outputFileName); - String[] args = {"-debug", "-load-config=" + configFileOutput.getPath(), - "-output=" + outputFile.getPath(), "-define=COMPILE::AS3,true", "-define=COMPILE::JS,false"}; - compc.execute(args); - - // Attach the file created by the compiler as artifact file to maven. - project.getArtifact().setFile(outputFile); - - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (TransformerConfigurationException e) { - e.printStackTrace(); - } catch (TransformerException e) { - e.printStackTrace(); - } + @Override + protected File getConfigFile() { + return compileAsConfigFile; } - private Set<Artifact> resolveDependencies() throws MojoExecutionException { - DefaultDependencyResolutionRequest dependencyResolutionRequest = - new DefaultDependencyResolutionRequest(project, repositorySystemSession); - DependencyResolutionResult dependencyResolutionResult; - - try { - dependencyResolutionResult = projectDependenciesResolver.resolve(dependencyResolutionRequest); - } catch (DependencyResolutionException ex) { - throw new MojoExecutionException(ex.getMessage(), ex); - } - - Set<Artifact> artifacts = new LinkedHashSet<Artifact>(); - if (dependencyResolutionResult.getDependencyGraph() != null - && !dependencyResolutionResult.getDependencyGraph().getChildren().isEmpty()) { - RepositoryUtils.toArtifacts(artifacts, dependencyResolutionResult.getDependencyGraph().getChildren(), - Collections.singletonList(project.getArtifact().getId()), null); - } - return artifacts; + private File getOutputFile() { + return new File(outputDirectory, outputFileName); } - private Set<Artifact> getDependenciesForScope(Set<Artifact> dependencies, FlexScope scope) { - Set<Artifact> artifacts = new LinkedHashSet<Artifact>(); - for(Artifact dependency : dependencies) { - FlexScope dependencyScope = FlexScope.COMPILE; - if(dependency.getScope() != null) { - dependencyScope = FlexScope.valueOf(dependency.getScope().toUpperCase()); - } - if(dependencyScope == scope) { - artifacts.add(dependency); - } - } - return artifacts; + @Override + protected String[] getCompilerArgs(File configFile) { + return new String[]{"-debug", "-load-config=" + configFile.getPath(), + "-output=" + getOutputFile().getPath(), "-define=COMPILE::AS3,true", "-define=COMPILE::JS,false"}; } - private void outputLibraryPath(Document configDocument, String baseXPath, Set<Artifact> artifacts) { - if(!artifacts.isEmpty()) { - XPathFactory xPathfactory = XPathFactory.newInstance(); - XPath xpath = xPathfactory.newXPath(); - try { - XPathExpression expr = xpath.compile(baseXPath); - Element externalLibraryPath = (Element) expr.evaluate(configDocument, XPathConstants.NODE); - if(externalLibraryPath != null) { - // Remove any existing path-elements (They are leftovers from the ant build). - Node child = externalLibraryPath.getFirstChild(); - while(child != null) { - externalLibraryPath.removeChild(child); - child = externalLibraryPath.getFirstChild(); - } - - // Add the new path-elements. - for (Artifact artifact : artifacts) { - Element newPathElement = configDocument.createElement("path-element"); - newPathElement.setTextContent(artifact.getFile().getAbsolutePath()); - externalLibraryPath.appendChild(newPathElement); - } - } else { - throw new RuntimeException("Could not find root element " + baseXPath); - } - } catch (XPathExpressionException e) { - throw new RuntimeException("Error adding path-element", e); - } + @Override + public void execute() throws MojoExecutionException { + super.execute(); + if(getOutputFile().exists()) { + // Attach the file created by the compiler as artifact file to maven. + project.getArtifact().setFile(getOutputFile()); } } - } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/704d6324/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java index 6ad19dc..620a4ea 100644 --- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileJSMojo.java @@ -16,18 +16,10 @@ package org.apache.flex.maven.flexjs; -import org.apache.flex.tools.FlexTool; -import org.apache.flex.tools.FlexToolGroup; -import org.apache.flex.tools.FlexToolRegistry; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; 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 org.apache.maven.project.ProjectDependenciesResolver; -import org.eclipse.aether.RepositorySystemSession; import java.io.File; @@ -36,29 +28,33 @@ import java.io.File; */ @Mojo(name="compile-js",defaultPhase = LifecyclePhase.PROCESS_SOURCES) public class CompileJSMojo - extends AbstractMojo + extends BaseCompileMojo { - @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; - @Parameter(defaultValue="${basedir}/src/main/config/compile-js-config.xml") private File compileJsConfigFile; - @Parameter(defaultValue="${project.build.directory}") - private File outputDirectory; - @Parameter(defaultValue = "${project.artifactId}-${project.version}.swc") private String outputFileName; - @Parameter(readonly = true, defaultValue = "${repositorySystemSession}") - private RepositorySystemSession repositorySystemSession; + @Override + protected File getConfigFile() { + return compileJsConfigFile; + } + + private File getOutputDirectory() { + return new File(outputDirectory, "generated-sources/flexjs"); + } - @Component - private ProjectDependenciesResolver projectDependenciesResolver; + @Override + protected String[] getCompilerArgs(File configFile) { + return new String[] {"-js-output-type=FLEXJS", "-keep-asdoc", "-load-config=" + configFile.getPath(), + "-output=" + new File(outputDirectory.getPath(), "generated-sources/flexjs").getPath(), + "-define=COMPILE::AS3,false", "-define=COMPILE::JS,true"}; + } - public void execute() - throws MojoExecutionException + @Override + public void execute() throws MojoExecutionException { if(!compileJsConfigFile.exists()) { getLog().info(" - compilation config file '" + compileJsConfigFile.getPath() + @@ -66,40 +62,16 @@ public class CompileJSMojo return; } - File generatedSourcesOutputDir = new File(outputDirectory, "generated-sources/flexjs"); + File generatedSourcesOutputDir = getOutputDirectory(); if(!generatedSourcesOutputDir.exists()) { if(!generatedSourcesOutputDir.mkdirs()) { throw new MojoExecutionException("Could not create directory " + generatedSourcesOutputDir.getPath()); } } - // Get the falcon tool group. - FlexToolRegistry toolRegistry = new FlexToolRegistry(); - FlexToolGroup toolGroup = toolRegistry.getToolGroup("FlexJS"); - if(toolGroup == null) { - throw new MojoExecutionException("Could not find tool group: Falcon"); - } - - // Get an instance of the compiler and run the build. - FlexTool compc = toolGroup.getFlexTool(FlexTool.FLEX_TOOL_COMPC); - File outputFile = new File(outputDirectory, outputFileName); - -/* <!--arg value="+flexlib=${FLEX_HOME}/frameworks" /> - <arg value="+playerglobal.version=${playerglobal.version}" /> - <arg value="+env.PLAYERGLOBAL_HOME=${env.PLAYERGLOBAL_HOME}" /> - <arg value="+env.AIR_HOME=${env.AIR_HOME}" /> - <arg value="-external-library-path+=${JS.SWC}" /> - <!-- this is not on external-library path otherwise goog.requires are not generated --> - <arg value="-library-path+=${GCL.SWC}" />*/ - - String[] args = {"-js-output-type=FLEXJS", "-keep-asdoc", "-load-config=" + compileJsConfigFile.getPath(), - "-output=" + new File(outputDirectory.getPath(), "generated-sources/flexjs").getPath(), - "-define=COMPILE::AS3,false", "-define=COMPILE::JS,true"}; - compc.execute(args); - - // Attach the file created by the compiler as artifact file to maven. - project.getArtifact().setFile(outputFile); + super.execute(); + // TODO: Add Source directory } }
