Hi,
I just started an very basic implementation of this. Here is a patch file.
For now, it converts mxml, as and html documents to syntax highlighted html
pages and just copies other types of sources files to the "source view"
directory. I dropped Java2html for JHighlight because it can highlight xml
files too.
I will complete it with a navigation generated with Velocity, in a frameset
I guess.
Stop me if this is not what you had in mind ;)
Julien
2010/3/12 Marvin Froeder <[email protected]>
> I neve finished implementing that one.
>
> Sent from DROID
>
> Em 12/03/2010 07:20, "Julien Nicoulaud" <[email protected]
> >escreveu:
>
>
> Hi, i''m unsuccessfully trying to use the "source-view" goal. Is it
> experimental for now ? It is not documented, are there parameters I should
> know ?
>
> I tried calling it on several artifacts of type swf, and most of the time,
> it just does nothing, and only for one of them, it outputs some generated
> html in the build log and then crashes the build (no "build error").
>
> VELO, would you have some example of this in your magical test set ? :)
>
> --
> You received this message because you are subscribed to the Google
> Groups "Flex Mojos" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<flex-mojos%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/flex-mojos?hl=en?hl=en
>
> http://flexmojos.sonatype.org/
>
> --
> You received this message because you are subscribed to the Google
> Groups "Flex Mojos" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<flex-mojos%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/flex-mojos?hl=en?hl=en
>
> http://flexmojos.sonatype.org/
>
--
You received this message because you are subscribed to the Google
Groups "Flex Mojos" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/flex-mojos?hl=en?hl=en
http://flexmojos.sonatype.org/
Index: flexmojos-parent/pom.xml
===================================================================
--- flexmojos-parent/pom.xml (revision 1621)
+++ flexmojos-parent/pom.xml (working copy)
@@ -436,9 +436,9 @@
<type>maven-plugin</type>
</dependency>
<dependency>
- <groupId>de.java2html</groupId>
- <artifactId>java2html</artifactId>
- <version>5.0</version>
+ <groupId>com.uwyn</groupId>
+ <artifactId>jhighlight</artifactId>
+ <version>1.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
Index: flexmojos-maven-plugin/pom.xml
===================================================================
--- flexmojos-maven-plugin/pom.xml (revision 1621)
+++ flexmojos-maven-plugin/pom.xml (working copy)
@@ -224,8 +224,8 @@
<type>maven-plugin</type>
</dependency>
<dependency>
- <groupId>de.java2html</groupId>
- <artifactId>java2html</artifactId>
+ <groupId>com.uwyn</groupId>
+ <artifactId>jhighlight</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
Index: flexmojos-maven-plugin/src/main/java/org/sonatype/flexmojos/source/SourceViewMojo.java
===================================================================
--- flexmojos-maven-plugin/src/main/java/org/sonatype/flexmojos/source/SourceViewMojo.java (revision 1621)
+++ flexmojos-maven-plugin/src/main/java/org/sonatype/flexmojos/source/SourceViewMojo.java (working copy)
@@ -8,29 +8,36 @@
package org.sonatype.flexmojos.source;
import java.io.File;
-import java.io.FileReader;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
-import java.util.Collection;
+import java.io.InputStream;
+import java.io.OutputStream;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.sonatype.flexmojos.AbstractIrvinMojo;
-import de.java2html.Java2Html;
+import com.uwyn.jhighlight.renderer.XhtmlRendererFactory;
/**
+ * Generate the "Source view" documentation from the sources, like Flex/Flash
+ * Builder does for the release builds. Users can they right click the
+ * application and view the sources.
+ *
+ * <p>
+ * This goal produces a syntax highlighted version of the as, mxml and html
+ * documents in the sources, and just copies other types of files.
+ * </p>
+ *
* @goal source-view
- * @phase package
+ * @phase prepare-package
*/
-public class SourceViewMojo
- extends AbstractMojo
+public class SourceViewMojo extends AbstractIrvinMojo
{
-
/**
- * The maven project.
+ * The Maven project.
*
* @parameter expression="${project}"
* @required
@@ -38,28 +45,180 @@
*/
protected MavenProject project;
- @SuppressWarnings( "unchecked" )
- public void execute()
- throws MojoExecutionException, MojoFailureException
+ /**
+ * The name of the directory containing the "View source" documentation.
+ *
+ * <p>
+ * It must be the same as the one declared in the Flex application:
+ * <pre>
+ * <mx:Application [...] viewSourceURL="srcview">
+ * [...]
+ * </mx:Application>
+ * </pre>
+ * </p>
+ *
+ * @parameter default-value="srcview"
+ */
+ protected String sourceViewDirectoryName;
+
+ /**
+ * {...@inheritdoc}
+ */
+ @Override
+ protected void setUp() throws MojoExecutionException, MojoFailureException
+ {
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ @Override
+ protected void run() throws MojoExecutionException, MojoFailureException
+ {
+ // Create the "Source view" directory
+ File sourceViewDirectory = new File(project.getBuild().getDirectory() + File.separator + sourceViewDirectoryName);
+ sourceViewDirectory.mkdirs();
+
+ // Start processing the main source directory
+ processDirectory(new File(project.getBuild().getSourceDirectory()), sourceViewDirectory);
+ }
+
+ /**
+ * {...@inheritdoc}
+ */
+ @Override
+ protected void tearDown() throws MojoExecutionException, MojoFailureException
+ {
+ }
+
+ /**
+ * Loop through source files in the directory and syntax highlight and/or
+ * copy them to the target directory.
+ *
+ * @param directory
+ * The source directory to process.
+ * @param targetDirectory
+ * The directory where to store the output.
+ */
+ private void processDirectory(File directory, File targetDirectory)
+ {
+ getLog().debug("Processing directory " + directory.getName());
+
+ // Loop through files in the directory
+ File[] files = directory.listFiles();
+ for (File file : files)
+ {
+ // Skip hidden files
+ if (!file.isHidden() && !file.getName().startsWith("."))
+ {
+ if (file.isDirectory())
+ {
+ File newTargetDirectory = new File(targetDirectory, file.getName());
+ newTargetDirectory.mkdir();
+ processDirectory(file, newTargetDirectory);
+ }
+ else
+ {
+ try
+ {
+ processFile(file, targetDirectory);
+ }
+ catch (IOException e)
+ {
+ getLog().warn("Error while processing " + file.getName(), e);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Syntax highlight and/or copy the source file to the target directory.
+ *
+ * @param file
+ * The file to process.
+ * @param targetDirectory
+ * The directory where to store the output.
+ * @throws IOException
+ * If there was a file read/write exception.
+ */
+ private void processFile(File file, File targetDirectory) throws IOException
+ {
+ getLog().debug("Processing file " + file.getName());
+
+ // Prepare to copy the file
+ String destinationFilePath = targetDirectory.getCanonicalPath() + File.separator + file.getName();
+
+ // Check if the file can be syntax highlighted
+ String extension = file.getName().substring(file.getName().lastIndexOf('.') + 1);
+ String highlightFilter = getHighlightFilter(extension);
+
+ if (highlightFilter != null)
+ {
+ destinationFilePath += ".html";
+ XhtmlRendererFactory.getRenderer(highlightFilter).highlight(file.getName(),
+ new FileInputStream(file),
+ new FileOutputStream(destinationFilePath),
+ "UTF-8",
+ false);
+ getLog().debug(file.getName() + " converted to HTML.");
+ }
+ else
+ {
+ copyFile(file, destinationFilePath);
+ getLog().debug(file.getName() + " copied.");
+ }
+ }
+
+ /**
+ * Copy the file to the destination.
+ *
+ * @param file
+ * The file to copy.
+ * @param destinationFilePath
+ * The canonical path of the destination file.
+ * @throws IOException
+ * If there was a file read/write exception.
+ */
+ private void copyFile(File file, String destinationFilePath) throws IOException
{
- File srcDir = new File( project.getBuild().getSourceDirectory() );
- Collection<File> testFiles = FileUtils.listFiles( srcDir, new String[] { "as" }, true );
- for ( File file : testFiles )
+ InputStream in = new FileInputStream(file);
+ OutputStream out = new FileOutputStream(destinationFilePath);
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0)
{
- String fileContent;
- try
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+
+ /**
+ * Get the syntax highlighting filter to use for a file extension.
+ *
+ * @param fileExtension
+ * the file extension to test.
+ * @return null if no filter available for this file type.
+ * @see {...@link XhtmlRendererFactory#getSupportedTypes()}
+ */
+ private String getHighlightFilter(String fileExtension)
+ {
+ if (fileExtension != null)
+ {
+ if ("as".equals(fileExtension))
{
- fileContent = IOUtils.toString( new FileReader( file ) );
+ return XhtmlRendererFactory.JAVA;
}
- catch ( IOException e )
+ else if ("xml".equals(fileExtension) || "mxml".equals(fileExtension))
{
- throw new MojoExecutionException( e.getMessage(), e );
+ return XhtmlRendererFactory.XML;
}
- System.out.println( fileContent );
- fileContent = Java2Html.convertToHtmlPage( fileContent );
- System.out.println( fileContent );
- System.exit( 0 );
+ else if ("htm".equals(fileExtension) || "html".equals(fileExtension))
+ {
+ return XhtmlRendererFactory.XHTML;
+ }
}
+ return null;
}
-
}