[israfil-mojo commit] r585 - in trunk/maven-flex2-plugin/src: it/maven-flex2-actionscript2-test main/java/net/israfil/m...

4 views
Skip to first unread message

codesite...@google.com

unread,
Jan 7, 2008, 2:17:58 PM1/7/08
to israfil-...@googlegroups.com
Author: christianedwardgruber
Date: Mon Jan 7 11:16:56 2008
New Revision: 585

Modified:
trunk/maven-flex2-plugin/src/it/maven-flex2-actionscript2-test/pom.xml
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/ASDocMojo.java
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/AbstractFlexCompilerMojo.java
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/AbstractFlexMojo.java
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/CompCompilerMojo.java
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/MXMLCompilerMojo.java
trunk/maven-flex2-plugin/src/main/resources/META-INF/plexus/components.xml

Log:
initial implementation of asdoc support. Not very configurable yet,
and it dumps into target/asdoc, and no report generation during site
build yet, but it's a step.

Modified: trunk/maven-flex2-plugin/src/it/maven-flex2-actionscript2-test/pom.xml
==============================================================================
---
trunk/maven-flex2-plugin/src/it/maven-flex2-actionscript2-test/pom.xml (original)
+++
trunk/maven-flex2-plugin/src/it/maven-flex2-actionscript2-test/pom.xml
Mon Jan 7 11:16:56 2008
@@ -21,6 +21,12 @@
<javaOpt>-Xmx512m</javaOpt>
</javaOpts>
</configuration>
+ <executions>
+ <execution>
+ <goals><goal>asdoc</goal></goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
</plugin>
</plugins>
</build>

Modified: trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/ASDocMojo.java
==============================================================================
---
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/ASDocMojo.java (original)
+++
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/ASDocMojo.java
Mon Jan 7 11:16:56 2008
@@ -34,44 +34,36 @@
package net.israfil.mojo.flex2;

import java.io.File;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
+import java.io.IOException;
import java.util.List;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import javax.xml.parsers.SAXParser;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.logging.Log;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;


/**
- * Compilation action for Flex2 actionscript 3 classes.
+ * API Document generator for Actionscript 3 code.
*
* @author <a href="cgr...@israfil.net">Christian Edward Gruber</a>
* @version $Id: CompCompilerMojo.java 573 2007-12-20 03:12:19Z
christianedwardgruber $
*
* @goal asdoc
* @requiresDependencyResolution
- * @phase apidoc
* @requiresProject
*/
public class ASDocMojo extends AbstractFlexMojo {

+ /**
+ * The location of the asdoc templates to be used in generating documentation
+ *
+ * @parameter expression="${asdoc.templates}" default-value="${flex.home}/asdoc/templates"
+ * @required
+ */
+ protected File asdocTemplates;

protected String getCompilerClass() { return "flex2.tools.ASDoc"; }

- protected void finalizeParameters(List parameterList)
- throws MojoExecutionException, MojoFailureException {
- // TODO Auto-generated method stub
-
- }
+ protected String getExecutableJar() { return "asdoc.jar"; }

protected File getOutputFile() {
return getFile(outputDirectory, finalName, "asdoc");
@@ -82,12 +74,43 @@
// TODO Auto-generated method stub
return null;
}
+

protected List prepareParameters() throws MojoFailureException,
MojoExecutionException {
List parameters = super.prepareParameters();

-
+ parameters.add( "-doc-sources" );
+
+ try {
+ parameters.add( source.getCanonicalPath());
+ } catch (IOException e) {
+ throw new MojoExecutionException("Source path doesn't exist.", e);
+ }
+
+ parameters.add( "-templates-path" );
+
+ try {
+ parameters.add( asdocTemplates.getCanonicalPath());
+ } catch (IOException e) {
+ throw new MojoExecutionException("Templates path doesn't exist.", e);
+ }
+
+ // define output folder.
+ parameters.add("-output");
+ File asdocOutput = new File(outputDirectory,"asdoc");
+ try {
+ parameters.add(asdocOutput.getCanonicalPath());
+ } catch (IOException e) {
+ throw new MojoExecutionException("Exception attempting to set
output file: " + asdocOutput.getPath(), e);
+ }
+
return parameters;
+ }
+
+ protected void postProcess() {
+
+
+
}

/*

Modified: trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/AbstractFlexCompilerMojo.java
==============================================================================
---
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/AbstractFlexCompilerMojo.java (original)
+++
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/AbstractFlexCompilerMojo.java
Mon Jan 7 11:16:56 2008
@@ -35,10 +35,6 @@

import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -47,12 +43,6 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectHelper;
-import org.codehaus.plexus.util.cli.CommandLineException;
-import org.codehaus.plexus.util.cli.CommandLineUtils;
-import org.codehaus.plexus.util.cli.Commandline;
-import org.codehaus.plexus.util.cli.StreamConsumer;


/**
@@ -74,16 +64,6 @@
*/
protected boolean resolveExtraSwcsFromFlexFrameworksLibs = false;

- /**
- * The location of the flex configuration file. Uses the installed
- * default flex-config.xml file if none supplied.
- *
- * @parameter expression="${flex.config}" default-value="${flex.home}/frameworks/flex-config.xml"
- * @required
- *
- */
- protected File flexConfig;
-
/**
* The current locale.
*
@@ -164,31 +144,20 @@
}


- protected void addSourcePathToParameters(List parameterList) {
- Iterator i = compileSourceRoots.iterator();
- if (i.hasNext());
- parameterList.add( "-source-path" );
- while (i.hasNext()) {
- String path = (String)i.next();
- if (new File(path).exists()) {
- getLog().debug("Adding source path: " + path);
- parameterList.add( path );
- } else {
- getLog().debug("Ignoring missing source path: " + path);
- }
- }
- }
+

protected List prepareParameters() throws MojoFailureException,
MojoExecutionException {
List parameters = super.prepareParameters();
-
- parameters.add("-load-config");
+
+ // define output file.
+ File outFile = getOutputFile();
+ parameters.add("-output");
try {
- parameters.add(flexConfig.getCanonicalFile().getAbsolutePath());
+ parameters.add(outFile.getCanonicalFile().getAbsolutePath());
} catch (IOException e) {
- throw new MojoExecutionException("Config file does not exist.", e);
- }
-
+ throw new MojoExecutionException("Exception attempting to set
output file: " + outFile, e);
+ }
+
// add in locale
parameters.add("-compiler.locale");
parameters.add(locale);

Modified: trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/AbstractFlexMojo.java
==============================================================================
---
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/AbstractFlexMojo.java (original)
+++
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/AbstractFlexMojo.java
Mon Jan 7 11:16:56 2008
@@ -36,13 +36,10 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
@@ -73,15 +70,15 @@
*/
protected File flexHome;

- /**
- * The source directories containing the sources to be compiled.
- *
- * @parameter expression="${project.compileSourceRoots}"
- * @required
- * @readonly
- */
- protected List compileSourceRoots;
-
+ /**
+ * The location of the flex configuration file. Uses the installed
+ * default flex-config.xml file if none supplied.
+ *
+ * @parameter expression="${flex.config}" default-value="${flex.home}/frameworks/flex-config.xml"
+ * @required
+ *
+ */
+ protected File flexConfig;

/**
* Location of the flex sources.
@@ -162,7 +159,7 @@
if ( classifier.trim().length() > 0
&& !classifier.startsWith( "-" )){
classifier = "-" + classifier;
}
- return new File( basedir, finalName + "-" + classifier
+ ".jar" );
+ return new File( basedir, finalName + classifier + ".jar" );
} else {
return new File( basedir, finalName + "." +
getFileExtension() );
}
@@ -177,25 +174,28 @@
protected List prepareParameters() throws MojoFailureException,
MojoExecutionException {
List parameters = new ArrayList();

- // define output file.
- File outFile = getOutputFile();
- parameters.add("-output");
try {
- parameters.add(outFile.getCanonicalFile().getAbsolutePath());
+ parameters.add("+flexlib=" + new
File(flexHome,"frameworks").getCanonicalPath());
} catch (IOException e) {
- throw new MojoExecutionException("Exception attempting to set
output file: " + outFile, e);
+ throw new MojoExecutionException("Config file does not exist.", e);
+ }
+
+ parameters.add("-load-config");
+ try {
+ parameters.add(flexConfig.getCanonicalFile().getAbsolutePath());
+ } catch (IOException e) {
+ throw new MojoExecutionException("Config file does not exist.", e);
}


+ parameters.add( "-source-path" );

-
-
-
-
-
-
- // hack in the source, since we're not using a proper plexus
compiler yet.
- compileSourceRoots.add(new File(project.getBasedir(),"src/main/flex").getPath());
+ try {
+ parameters.add( source.getCanonicalPath());
+ } catch (IOException e) {
+ throw new MojoExecutionException("Source path doesn't exist.", e);
+ }
+

return parameters;
}
@@ -217,6 +217,30 @@
}
}
}
+
+
+ protected abstract String getExecutableJar();
+
+ protected String getCommandClassPath() throws
MojoExecutionException, MojoFailureException {
+ StringBuffer compilerClasspath = new StringBuffer();
+ try {
+ addClasspathEntry(compilerClasspath,new File(new File(flexHome,"lib"),getExecutableJar()).getCanonicalPath());
+
+ // get support jar.
+ for (Iterator i = pluginArtifacts.iterator(); i.hasNext() ;) {
+ Artifact artifact = (Artifact)i.next();
+ getLog().debug("Trying artifact to add to classpath: " + artifact);
+ if (artifact.getGroupId().equals("net.israfil.mojo") &&
artifact.getArtifactId().equals("maven-flex2-plugin-support")) {
+ addClasspathEntry(compilerClasspath, artifact.getFile().getCanonicalFile().getAbsolutePath());
+ break;
+ }
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException("Could not generate a canonical
path for library.",e);
+ }
+
+ return compilerClasspath.toString();
+ }

public void execute() throws MojoExecutionException,
MojoFailureException {

@@ -238,55 +262,23 @@
//
List commandLineArgs = new ArrayList();

- if( javaOpts != null )
- for( int i = 0; i < javaOpts.length; i++ )
- commandLineArgs.add( javaOpts[i] );
+ //Add java opts, checking for two opts which are set in the
+ //basic flex shell scripts, and setting them if they're not
+ //overridden.
+ //TODO: Test this.
+ boolean maxMemIsSet = false;
+ boolean sunIoCachesIsSet = false;
+ for( int i = 0; i < javaOpts.length; i++ ) {
+ commandLineArgs.add( javaOpts[i] );
+ if (javaOpts[i].startsWith("-Xmx")) maxMemIsSet = true;
+ else if
(javaOpts[i].startsWith("-Dsun.io.useCanonCaches")) sunIoCachesIsSet = true;
+ }
+ if (!maxMemIsSet) commandLineArgs.add("-Xmx384m");
+ if (!sunIoCachesIsSet) commandLineArgs.add("-Dsun.io.useCanonCaches=false");
+
commandLineArgs.add("-classpath");
- StringBuffer compilerClasspath = new StringBuffer();
- try {
- File flexJars = new File(flexHome,"lib");
- if (!flexJars.exists())
- throw new MojoExecutionException("Flex lib not found.");
- File[] libs = flexJars.listFiles();
- // assume libs is not null and get all .jars in the lib folder;
- for (int i = 0 ; i < libs.length ; i++) {
- File lib = libs[i];
- if (lib.exists()) {
- String path = lib.getCanonicalFile().getAbsolutePath();
- if (path.endsWith(".jar")) {
- addClasspathEntry(compilerClasspath, path);
- }
- } else getLog().debug("Ignoring non-existant lib: " + lib);
- }
-
- // find this plugin's artifact and add the .jar to the classpath.
-
- for (Iterator i = pluginArtifacts.iterator(); i.hasNext() ;) {
- Artifact artifact = (Artifact)i.next();
- getLog().debug("Trying artifact to add to classpath: " + artifact);
- if (artifact.getGroupId().equals("net.israfil.mojo") &&
artifact.getArtifactId().equals("maven-flex2-plugin-support")) {
- addClasspathEntry(compilerClasspath, artifact.getFile().getCanonicalFile().getAbsolutePath());
- break;
- }
- }
-
- //MojoDescriptor mojoDescriptor = (MojoDescriptor)pluginMojos.get(0);
- //PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
- //Artifact thisPlugin = (Artifact)pluginDescriptor.getArtifactMap().get("net.israfil.mojo:maven-flex2-plugin");
- // add this plugin to the classpath to allow the wrapper to be present.
- //Artifact thisPlugin = (Artifact)project.getPluginArtifactMap().get("net.israfil.mojo:maven-flex2-plugin");
-
-
- if (getLog().isDebugEnabled())
- getLog().debug("Using classpath: " + compilerClasspath.toString());
-
- } catch (MalformedURLException e) {
- throw new MojoExecutionException("Could not generate a URL for library.",e);
- } catch (IOException e) {
- throw new MojoExecutionException("Could not generate a canonical
path for library.",e);
- }
- commandLineArgs.add(compilerClasspath.toString());
-
+ commandLineArgs.add(getCommandClassPath());
+
//
// Setup the Java parameters.
//
@@ -308,7 +300,15 @@
} catch ( CommandLineException e ) {
throw new MojoExecutionException( "Command execution
failed.", e );
}
+
+ postProcess();

+ }
+
+ /**
+ * Executed near the end of execute().
+ */
+ protected void postProcess() {
// Point Maven2 at the outbound file.
File outFile = getOutputFile();
if (classifier != null) {
@@ -316,7 +316,7 @@
} else {
project.getArtifact().setFile(outFile);
}
- }
+ };

protected void addClasspathEntry(StringBuffer compilerClasspath,
String path) {
getLog().debug("Adding " + path + " to path.");

Modified: trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/CompCompilerMojo.java
==============================================================================
---
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/CompCompilerMojo.java (original)
+++
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/CompCompilerMojo.java
Mon Jan 7 11:16:56 2008
@@ -34,6 +34,8 @@
package net.israfil.mojo.flex2;

import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
@@ -43,6 +45,7 @@

import javax.xml.parsers.SAXParser;

+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
@@ -115,19 +118,25 @@

protected String getCompilerClass() { return "flex2.tools.Compc"; }

+ protected String getExecutableJar() { return "compc.jar"; }
+
protected String getFileExtension() { return "swc"; }

protected List prepareParameters() throws MojoFailureException,
MojoExecutionException {
List parameters = super.prepareParameters();
-
+
parameters.add("-compiler.debug=" + debug);
-
- addSourcePathToParameters(parameters);
-
+
if (flexLibPropertiesFile == null) {
getLog().debug("No flex lib properties specified - checking for
included resources or classes.");
if (includedClasses == null) {
- includeSourceRoots(parameters);
+ if (source.exists()) {
+ getLog().debug("Adding source path: " + source.getPath());
+ parameters.add( "-include-sources" );
+ parameters.add( source.getPath() );
+ } else {
+ getLog().debug("Ignoring missing source path: " + source.getPath());
+ }
}
if (includedResources == null) {
includeAllResources();
@@ -163,7 +172,8 @@

if (includedResources != null && !includedResources.isEmpty()) {
for (Iterator i = includedResources.iterator() ; i.hasNext();) {
- List resourceRoots = new ArrayList(compileSourceRoots);
+ List resourceRoots = new ArrayList();
+ resourceRoots.add(source.getPath());
resourceRoots.add("src/main/resources/");
ComponentResource cr = (ComponentResource)i.next();
parameters.add( "-include-file" );
@@ -182,20 +192,57 @@
return parameters;
}

- private void includeSourceRoots(List parameterList) {
- for (Iterator i = compileSourceRoots.iterator();i.hasNext();) {
- String path = (String)i.next();
- if (new File(path).exists()) {
- getLog().debug("Adding source path: " + path);
- parameterList.add( "-include-sources" );
- parameterList.add( path );
- } else {
- getLog().debug("Ignoring missing source path: " + path);
+ protected String getCommandClassPath() throws
MojoExecutionException, MojoFailureException {
+ StringBuffer compilerClasspath = new StringBuffer();
+ try {
+ File flexJars = new File(flexHome,"lib");
+ if (!flexJars.exists())
+ throw new MojoExecutionException("Flex lib not found.");
+ File[] libs = flexJars.listFiles();
+ // assume libs is not null and get all .jars in the lib folder;
+ for (int i = 0 ; i < libs.length ; i++) {
+ File lib = libs[i];
+ if (lib.exists()) {
+ String path = lib.getCanonicalFile().getAbsolutePath();
+ if (path.endsWith(".jar")) {
+ addClasspathEntry(compilerClasspath, path);
+ }
+ } else getLog().debug("Ignoring non-existant lib: " + lib);
}
+
+ // find this plugin's artifact and add the .jar to the classpath.
+
+ for (Iterator i = pluginArtifacts.iterator(); i.hasNext() ;) {
+ Artifact artifact = (Artifact)i.next();
+ getLog().debug("Trying artifact to add to classpath: " + artifact);
+ if (artifact.getGroupId().equals("net.israfil.mojo") &&
artifact.getArtifactId().equals("maven-flex2-plugin-support")) {
+ addClasspathEntry(compilerClasspath, artifact.getFile().getCanonicalFile().getAbsolutePath());
+ break;
+ }
+ }
+
+ //MojoDescriptor mojoDescriptor = (MojoDescriptor)pluginMojos.get(0);
+ //PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
+ //Artifact thisPlugin = (Artifact)pluginDescriptor.getArtifactMap().get("net.israfil.mojo:maven-flex2-plugin");
+ // add this plugin to the classpath to allow the wrapper to be present.
+ //Artifact thisPlugin = (Artifact)project.getPluginArtifactMap().get("net.israfil.mojo:maven-flex2-plugin");
+
+
+ if (getLog().isDebugEnabled())
+ getLog().debug("Using classpath: " + compilerClasspath.toString());
+
+ } catch (MalformedURLException e) {
+ throw new MojoExecutionException("Could not generate a URL for library.",e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Could not generate a canonical
path for library.",e);
}
- }
+ return compilerClasspath.toString();
+
+ }
+
private void includeAllResources() {
- List resourcesRootPaths = new ArrayList(compileSourceRoots);
+ List resourcesRootPaths = new ArrayList();
+ resourcesRootPaths.add(source.getPath());
resourcesRootPaths.add("src/main/resources/");
for (int i = 0; i < resourcesRootPaths.size(); i++) {
File resourcesRoot = new File((String)resourcesRootPaths.get(i));

Modified: trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/MXMLCompilerMojo.java
==============================================================================
---
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/MXMLCompilerMojo.java (original)
+++
trunk/maven-flex2-plugin/src/main/java/net/israfil/mojo/flex2/MXMLCompilerMojo.java
Mon Jan 7 11:16:56 2008
@@ -73,16 +73,16 @@

protected String getCompilerClass() { return "flex2.tools.Compiler"; }

- protected String getFileExtension() { return "swf"; }
+ protected String getExecutableJar() { return "mxmlc.jar"; }
+
+ protected String getFileExtension() { return "swf"; }


protected List prepareParameters() throws MojoFailureException,
MojoExecutionException {
List parameters = super.prepareParameters();
+
+ parameters.add("-compiler.debug=" + debug);

- parameters.add("-compiler.debug=" + debug);
-
- addSourcePathToParameters(parameters);
-
parameters.add("--");

// Add in main mxml file.

Modified: trunk/maven-flex2-plugin/src/main/resources/META-INF/plexus/components.xml
==============================================================================
---
trunk/maven-flex2-plugin/src/main/resources/META-INF/plexus/components.xml (original)
+++
trunk/maven-flex2-plugin/src/main/resources/META-INF/plexus/components.xml
Mon Jan 7 11:16:56 2008
@@ -19,7 +19,7 @@
<!--
<test-compile>net.israfil.mojo:maven-flex2-plugin:test-compile-swc</test-compile>
<test>org.apache.maven.plugins:maven-swc-plugin:test-compile</test>
- -->
+ -->
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
@@ -33,7 +33,7 @@
</implementation>
<configuration>
<phases>
- <compile>net.israfil.mojo:maven-flex2-plugin:compile-swf</compile>
+ <compile>net.israfil.mojo:maven-flex2-plugin:compile-swf</compile>
<!--
<test-compile>net.israfil.mojo:maven-flex2-plugin:test-compile-swf</test-compile>
<test>org.apache.maven.plugins:maven-swc-plugin:test-compile-swf</test>

Reply all
Reply to author
Forward
0 new messages