FLEX-35229 - [FlexJS] extend the flexjs-maven-plugin to be able to generate static asdoc html - Implemented a first version that outputs DITA xml for a SWF and a JS compilation using the DITA xml backend - Still not finished ...
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/319cb536 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/319cb536 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/319cb536 Branch: refs/heads/develop Commit: 319cb536ece52bcbfa3b48e6cc98eb6a35ac2089 Parents: 22ea48e Author: Christofer Dutz <christofer.d...@codecentric.de> Authored: Sun Dec 25 16:57:41 2016 +0100 Committer: Christofer Dutz <christofer.d...@codecentric.de> Committed: Sun Dec 25 16:57:41 2016 +0100 ---------------------------------------------------------------------- .../org/apache/flex/maven/flexjs/BaseMojo.java | 8 +- .../flex/maven/flexjs/CompileASDocMojo.java | 156 +++++++++++++++++++ .../apache/flex/maven/flexjs/CompileASMojo.java | 6 +- .../flex/maven/flexjs/CompileAppMojo.java | 6 +- .../apache/flex/maven/flexjs/CompileJSMojo.java | 6 +- .../flex/maven/flexjs/CompileTypedefsMojo.java | 6 +- .../flex/maven/flexjs/GenerateExterncMojo.java | 6 +- .../config/compile-asdoc-js-config.xml | 112 +++++++++++++ .../config/compile-asdoc-swf-config.xml | 127 +++++++++++++++ 9 files changed, 414 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java index 7c56482..f294d2f 100644 --- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/BaseMojo.java @@ -104,9 +104,9 @@ public abstract class BaseMojo return false; } - protected abstract String getConfigFileName(); + protected abstract String getConfigFileName() throws MojoExecutionException; - protected abstract File getOutput(); + protected abstract File getOutput() throws MojoExecutionException; protected VelocityContext getVelocityContext() throws MojoExecutionException { VelocityContext context = new VelocityContext(); @@ -278,7 +278,7 @@ public abstract class BaseMojo protected void handleExitCode(int exitCode) throws MojoExecutionException { // Allow normal execution and execution with warnings. if(!((exitCode == 0) || (!failOnCompilerWarnings && (exitCode == 2)))) { - throw new MojoExecutionException("There were errors during the build."); + throw new MojoExecutionException("There were errors during the build. Got return code " + exitCode); } } @@ -345,7 +345,7 @@ public abstract class BaseMojo return libraries; } - protected List<Define> getDefines() { + protected List<Define> getDefines() throws MojoExecutionException { List<Define> defines = new LinkedList<Define>(); if(this.defines != null) { for(Define define : this.defines) { http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASDocMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASDocMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASDocMojo.java new file mode 100644 index 0000000..e8fd8ac --- /dev/null +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileASDocMojo.java @@ -0,0 +1,156 @@ +/* + * Licensed 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 org.apache.flex.maven.flexjs; + +import org.apache.flex.tools.FlexTool; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; + +import java.io.File; +import java.util.List; + +/** + * goal which compiles the asdoc documentation for the project. + */ +@Mojo(name="compile-asdoc",defaultPhase = LifecyclePhase.SITE) +public class CompileASDocMojo + extends BaseMojo +{ + + @Parameter(defaultValue = "asdoc") + private String asdocDirectoryName; + + @Parameter(defaultValue = "false") + private boolean skipASDoc; + + private ThreadLocal<Type> type = new ThreadLocal<Type>(); + + @Override + protected String getToolGroupName() { + return "FlexJS"; + } + + @Override + protected String getFlexTool() { + return FlexTool.FLEX_TOOL_ASDOC; + } + + @Override + protected String getConfigFileName() throws MojoExecutionException { + if(type.get() == null) { + throw new MojoExecutionException("type not set"); + } + switch (type.get()) { + case SWF: + return "compile-asdoc-swf-config.xml"; + case JS: + return "compile-asdoc-js-config.xml"; + } + return null; + } + + @Override + protected File getOutput() throws MojoExecutionException { + if(type.get() == null) { + throw new MojoExecutionException("type not set"); + } + switch (type.get()) { + case SWF: + return new File(new File(outputDirectory, asdocDirectoryName), "swf"); + case JS: + return new File(new File(outputDirectory, asdocDirectoryName), "js"); + } + return null; + } + + @Override + protected boolean skip() { + return skipASDoc; + } + + @Override + public void execute() throws MojoExecutionException { + // We are using a ThreadLocal in this case in order to control the + // mode the two methods getOutput and getDefines are in in a threadsafe + // manner. Currently it wouldn't be necessary, but we never know how the + // compiler will be instantiated in the future. This method is safe in + // any way it could be used (Multiple executions in parallel with Maven). + try { + // Execute the ASDoc generation for SWF + getLog().info("Generating SWF apidocs"); + type.set(Type.SWF); + File outputDirectory = getOutput(); + if (!outputDirectory.exists()) { + if (!outputDirectory.mkdirs()) { + throw new MojoExecutionException("Could not create output directory for apidocs " + outputDirectory.getPath()); + } + } + super.execute(); + getLog().info("Finished"); + + // Execute the ASDoc generation for JavaScript + getLog().info("Generating JS apidocs"); + type.set(Type.JS); + outputDirectory = getOutput(); + if (!outputDirectory.exists()) { + if (!outputDirectory.mkdirs()) { + throw new MojoExecutionException("Could not create output directory for apidocs " + outputDirectory.getPath()); + } + } + super.execute(); + getLog().info("Finished"); + } finally { + type.remove(); + } + + // TODO: Merge both outputs in order to create one XML per class containing which elements are available for SWF and which ones for JS in one file + // TODO: Send each merged XML through an XSLT that produces XHTML + + } + + @Override + protected List<String> getCompilerArgs(File configFile) throws MojoExecutionException { + List<String> args = super.getCompilerArgs(configFile); + args.add("-js-output-type=flexjs_dita"); + return args; + } + + @Override + protected List<Define> getDefines() throws MojoExecutionException { + List<Define> defines = super.getDefines(); + if(type.get() == null) { + throw new MojoExecutionException("type not set"); + } + switch (type.get()) { + case SWF: + defines.add(new Define("COMPILE::JS", "false")); + defines.add(new Define("COMPILE::SWF", "true")); + break; + case JS: + defines.add(new Define("COMPILE::JS", "true")); + defines.add(new Define("COMPILE::SWF", "false")); + break; + } + return defines; + } + + private enum Type { + SWF, + JS + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/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 f705cb6..a32200b 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 @@ -53,12 +53,12 @@ public class CompileASMojo } @Override - protected String getConfigFileName() { + protected String getConfigFileName() throws MojoExecutionException { return "compile-as-config.xml"; } @Override - protected File getOutput() { + protected File getOutput() throws MojoExecutionException { return new File(outputDirectory, outputFileName); } @@ -89,7 +89,7 @@ public class CompileASMojo } @Override - protected List<Define> getDefines() { + protected List<Define> getDefines() throws MojoExecutionException { List<Define> defines = super.getDefines(); defines.add(new Define("COMPILE::JS", "false")); defines.add(new Define("COMPILE::SWF", "true")); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java index 8a4da76..c7e9dbe 100644 --- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileAppMojo.java @@ -77,7 +77,7 @@ public class CompileAppMojo } @Override - protected String getConfigFileName() { + protected String getConfigFileName() throws MojoExecutionException { if(outputJavaScript) { return "compile-app-javascript-config.xml"; } @@ -93,7 +93,7 @@ public class CompileAppMojo } @Override - protected File getOutput() { + protected File getOutput() throws MojoExecutionException { if(outputJavaScript) { return new File(outputDirectory, "javascript"); } @@ -175,7 +175,7 @@ public class CompileAppMojo }*/ @Override - protected List<Define> getDefines() { + protected List<Define> getDefines() throws MojoExecutionException { List<Define> defines = super.getDefines(); defines.add(new Define("COMPILE::JS", "false")); defines.add(new Define("COMPILE::SWF", "true")); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/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 0878bea..03a0f63 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 @@ -53,12 +53,12 @@ public class CompileJSMojo } @Override - protected String getConfigFileName() { + protected String getConfigFileName() throws MojoExecutionException { return "compile-js-config.xml"; } @Override - protected File getOutput() { + protected File getOutput() throws MojoExecutionException { return new File(outputDirectory, outputFileName); } @@ -105,7 +105,7 @@ public class CompileJSMojo } @Override - protected List<Define> getDefines() { + protected List<Define> getDefines() throws MojoExecutionException { List<Define> defines = super.getDefines(); defines.add(new Define("COMPILE::JS", "true")); defines.add(new Define("COMPILE::SWF", "false")); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileTypedefsMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileTypedefsMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileTypedefsMojo.java index 013c778..b1c4686 100644 --- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileTypedefsMojo.java +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/CompileTypedefsMojo.java @@ -55,11 +55,11 @@ public class CompileTypedefsMojo } @Override - protected String getConfigFileName() { + protected String getConfigFileName() throws MojoExecutionException { return "compile-extern-config.xml"; } - protected File getOutput() { + protected File getOutput() throws MojoExecutionException { return new File(outputDirectory, outputFileName); } @@ -91,7 +91,7 @@ public class CompileTypedefsMojo } @Override - protected List<Define> getDefines() { + protected List<Define> getDefines() throws MojoExecutionException { List<Define> defines = super.getDefines(); defines.add(new Define("COMPILE::JS", "true")); defines.add(new Define("COMPILE::SWF", "false")); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateExterncMojo.java ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateExterncMojo.java b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateExterncMojo.java index b893d4b..9a94856 100644 --- a/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateExterncMojo.java +++ b/flexjs-maven-plugin/src/main/java/org/apache/flex/maven/flexjs/GenerateExterncMojo.java @@ -56,7 +56,7 @@ public class GenerateExterncMojo } @Override - protected String getConfigFileName() { + protected String getConfigFileName() throws MojoExecutionException { return "generate-externc-config.xml"; } @@ -66,7 +66,7 @@ public class GenerateExterncMojo } @Override - protected File getOutput() { + protected File getOutput() throws MojoExecutionException { return new File(outputDirectory, outputDirectoryName); } @@ -117,7 +117,7 @@ public class GenerateExterncMojo } @Override - protected List<Define> getDefines() { + protected List<Define> getDefines() throws MojoExecutionException { List<Define> defines = super.getDefines(); defines.add(new Define("COMPILE::JS", "true")); defines.add(new Define("COMPILE::SWF", "false")); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/flexjs-maven-plugin/src/main/resources/config/compile-asdoc-js-config.xml ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/resources/config/compile-asdoc-js-config.xml b/flexjs-maven-plugin/src/main/resources/config/compile-asdoc-js-config.xml new file mode 100644 index 0000000..034246b --- /dev/null +++ b/flexjs-maven-plugin/src/main/resources/config/compile-asdoc-js-config.xml @@ -0,0 +1,112 @@ +<!-- + + 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. + +--> +<flex-config> + + <compiler> + + <accessible>false</accessible> + <debug>$debug</debug> + + <library-path> + #foreach($artifact in $libraries) <path-element>$artifact.file</path-element> + #end + </library-path> + + <external-library-path> + #foreach($artifact in $externalLibraries) <path-element>$artifact.file</path-element> + #end + </external-library-path> + + <source-path> + #foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element> + #end + </source-path> + + <namespaces> + #foreach($namespace in $namespaces) <namespace> + <uri>$namespace.uri</uri> + <manifest>$namespace.manifest</manifest> + </namespace> + #end + </namespaces> + + <warn-no-constructor>false</warn-no-constructor> + + <keep-as3-metadata> + #foreach($metadata in $keepAs3Metadata) <name>$metadata</name> + #end + </keep-as3-metadata> + + <allow-subclass-overrides>$allowSubclassOverrides</allow-subclass-overrides> + + <mxml> + <children-as-data>true</children-as-data> + </mxml> + + <binding-value-change-event>org.apache.flex.events.ValueChangeEvent</binding-value-change-event> + <binding-value-change-event-kind>org.apache.flex.events.ValueChangeEvent</binding-value-change-event-kind> + <binding-value-change-event-type>valueChange</binding-value-change-event-type> + + <show-deprecation-warnings>false</show-deprecation-warnings> + + #foreach($define in $defines) <define> + <name>$define.name</name> + <value>$define.value</value> + </define> + #end + </compiler> + + #if($includeSources) + <include-sources> + #foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element> + #end + </include-sources> + #end + + #if($includeClasses) + <include-classes> + #foreach($includeClass in $includeClasses) <class>$includeClass</class> + #end + </include-classes> + #end + + #if($namespaceUris) + <include-namespaces> + #foreach($namespaceUri in $namespaceUris) <uri>$namespaceUri</uri> + #end + </include-namespaces> + #end + + <js-output-type>FLEXJS</js-output-type> + + <keep-asdoc>true</keep-asdoc> + + <output>${output}</output> + + <doc-namespaces> +#foreach($namespace in $namespaces) <uri>$namespace.uri</uri> +#end + </doc-namespaces> + + <doc-sources> +#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element> +#end + </doc-sources> + +</flex-config> http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/319cb536/flexjs-maven-plugin/src/main/resources/config/compile-asdoc-swf-config.xml ---------------------------------------------------------------------- diff --git a/flexjs-maven-plugin/src/main/resources/config/compile-asdoc-swf-config.xml b/flexjs-maven-plugin/src/main/resources/config/compile-asdoc-swf-config.xml new file mode 100644 index 0000000..eb3b84d --- /dev/null +++ b/flexjs-maven-plugin/src/main/resources/config/compile-asdoc-swf-config.xml @@ -0,0 +1,127 @@ +<!-- + + 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. + +--> +<flex-config> + + <compiler> + + <accessible>true</accessible> + <debug>$debug</debug> + + <library-path> +#foreach($artifact in $libraries) <path-element>$artifact.file</path-element> +#end + </library-path> + + <external-library-path> +#foreach($artifact in $externalLibraries) <path-element>$artifact.file</path-element> +#end + </external-library-path> + + <theme> +#foreach($artifact in $themeLibraries) <filename>$artifact.file</filename> +#end + </theme> + + <source-path> +#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element> +#end + </source-path> + + <namespaces> +#foreach($namespace in $namespaces) <namespace> + <uri>$namespace.uri</uri> + <manifest>$namespace.manifest</manifest> + </namespace> +#end + </namespaces> + + <keep-as3-metadata> +#foreach($metadata in $keepAs3Metadata) <name>$metadata</name> +#end + </keep-as3-metadata> + + <allow-subclass-overrides>$allowSubclassOverrides</allow-subclass-overrides> + + <mxml> + <children-as-data>true</children-as-data> + </mxml> + + <binding-value-change-event>org.apache.flex.events.ValueChangeEvent</binding-value-change-event> + <binding-value-change-event-kind>org.apache.flex.events.ValueChangeEvent</binding-value-change-event-kind> + <binding-value-change-event-type>valueChange</binding-value-change-event-type> + + <locale> + </locale> + + <warn-no-constructor>false</warn-no-constructor> + <show-deprecation-warnings>false</show-deprecation-warnings> + +#foreach($define in $defines) <define> + <name>$define.name</name> + <value>$define.value</value> + </define> +#end + </compiler> + +#if($includeSources) + <include-sources> +#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element> +#end + </include-sources> +#end + +#if($includeClasses) + <include-classes> +#foreach($includeClass in $includeClasses) <class>$includeClass</class> +#end + </include-classes> +#end + +#if($namespaceUris) + <include-namespaces> +#foreach($namespaceUri in $namespaceUris) <uri>$namespaceUri</uri> +#end + </include-namespaces> +#end + +#foreach($includeFile in $includeFiles) <include-file> + <name>$includeFile.name</name> + <path>$includeFile.path</path> + </include-file> +#end + +#if($includeLookupOnly) + <include-lookup-only>$includeLookupOnly</include-lookup-only> +#end + + <target-player>${targetPlayer}</target-player> + + <output>${output}</output> + + <doc-namespaces> +#foreach($namespace in $namespaces) <uri>$namespace.uri</uri> +#end + </doc-namespaces> + + <doc-sources> +#foreach($sourcePath in $sourcePaths) <path-element>$sourcePath</path-element> +#end + </doc-sources> + +</flex-config>