You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by sh...@apache.org on 2005/12/25 18:10:37 UTC
svn commit: r358988 - in /excalibur/trunk/fortress/plugin: ./ src/ src/java/
src/java/org/ src/java/org/apache/ src/java/org/apache/avalon/
src/java/org/apache/avalon/fortress/
src/java/org/apache/avalon/fortress/tools/ src/site/ src/site/apt/
Author: shash
Date: Sun Dec 25 09:10:33 2005
New Revision: 358988
URL: http://svn.apache.org/viewcvs?rev=358988&view=rev
Log:
Fix for FORTRESS-21.
Converted ComponentMetaInfoCollector into a non-Ant-specific generic class.
Created new classes for Ant and Maven-2 plugins
Added:
excalibur/trunk/fortress/plugin/pom.xml
excalibur/trunk/fortress/plugin/src/
excalibur/trunk/fortress/plugin/src/java/
excalibur/trunk/fortress/plugin/src/java/org/
excalibur/trunk/fortress/plugin/src/java/org/apache/
excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/
excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/
excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/
excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/AbstractQDoxMojo.java
excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/ComponentMetaMavenMojo.java
excalibur/trunk/fortress/plugin/src/site/
excalibur/trunk/fortress/plugin/src/site/apt/
excalibur/trunk/fortress/plugin/src/site/apt/howto.apt
excalibur/trunk/fortress/plugin/src/site/apt/introduction.apt
excalibur/trunk/fortress/plugin/src/site/site.xml
Added: excalibur/trunk/fortress/plugin/pom.xml
URL: http://svn.apache.org/viewcvs/excalibur/trunk/fortress/plugin/pom.xml?rev=358988&view=auto
==============================================================================
--- excalibur/trunk/fortress/plugin/pom.xml (added)
+++ excalibur/trunk/fortress/plugin/pom.xml Sun Dec 25 09:10:33 2005
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Copyright 2003-2004 The Apache Software Foundation
+ 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.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.excalibur.fortress.meta</groupId>
+ <artifactId>maven-fortress-plugin</artifactId>
+ <version>0.0.1</version>
+ <name>Maven Fortress Plugin</name>
+ <description>Maven Fortress Plugin</description>
+ <packaging>maven-plugin</packaging>
+ <build>
+ <sourceDirectory>src/java</sourceDirectory>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.excalibur.fortress.meta</groupId>
+ <artifactId>excalibur-fortress-meta</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>qdox</groupId>
+ <artifactId>qdox</artifactId>
+ <version>1.5</version>
+ </dependency>
+ </dependencies>
+ <scm>
+ <connection>
+ scm:svn:http://svn.apache.org/repos/asf/excalibur/trunk/fortress/plugin
+ </connection>
+ <url>
+ http://svn.apache.org/viewcvs.cgi/excalibur/trunk/fortress/plugin
+ </url>
+ </scm>
+</project>
Added: excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/AbstractQDoxMojo.java
URL: http://svn.apache.org/viewcvs/excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/AbstractQDoxMojo.java?rev=358988&view=auto
==============================================================================
--- excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/AbstractQDoxMojo.java (added)
+++ excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/AbstractQDoxMojo.java Sun Dec 25 09:10:33 2005
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2003-2004 The Apache Software Foundation
+ * 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.avalon.fortress.tools;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.model.FileSet;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.plexus.util.DirectoryScanner;
+
+import com.thoughtworks.qdox.JavaDocBuilder;
+import com.thoughtworks.qdox.model.DefaultDocletTagFactory;
+import com.thoughtworks.qdox.model.DocletTagFactory;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaSource;
+
+/**
+ * An abstract class that provides the common logic of getting directory and
+ * file-set configuration information from Maven before creating the list of classes
+ * and source files that will be parsed by QDox.
+ *
+ * Classes extending this class must call the <code>execute()</code> method, after which
+ * the <code>allSources</code> and <code>allClasses</code> fields are filled in.
+ *
+ * @author <a href="mailto:dev@excalibur.apache.org">The Excalibur Team</a>
+ * @version CVS $Revision: 1.1 $ $Date: 2005/12/25 08:29:44 $
+ */
+public class AbstractQDoxMojo extends AbstractMojo
+{
+
+ /**
+ * The directory where the generated directories and files are placed
+ * @parameter expression="${project.build.outputDirectory}"
+ */
+ private File destDir;
+
+ /**
+ * Define the set of directory and file name inclusion/exclusion patterns. If ommitted,
+ * a default fileset is constructed using the baseDir and defaultIncludes configuration
+ * @parameter
+ */
+ private FileSet[] filesets;
+
+ /**
+ * If filesets are not defined, a default one is created using this directory
+ * @parameter expression="${basedir}"
+ */
+ private String baseDir;
+
+ /**
+ * If filesets are not defined, a default one is created using this inclusion pattern
+ * @parameter expression="**\/*.java"
+ */
+ private String defaultIncludes;
+
+ protected HashMap fileMap = new HashMap();
+
+ protected ArrayList allSources = new ArrayList();
+
+ protected ArrayList allClasses = new ArrayList();
+
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+ validateAttributes();
+ buildFileMap();
+ JavaDocBuilder builder = new JavaDocBuilder( createDocletTagFactory() );
+
+ // Add a classloader that has the taskdef's classpath.
+ builder.getClassLibrary().addClassLoader( getClass().getClassLoader() );
+ mergeBuilderSources( builder );
+ JavaSource[] sources = builder.getSources();
+ processSources( sources );
+ }
+
+ protected void buildFileMap()
+ {
+ for ( int i = 0; i < filesets.length; i++ )
+ {
+ FileSet fs = filesets[ i ];
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setBasedir( fs.getDirectory() );
+ if ( fs.getIncludes().size() > 0 )
+ {
+ ds.setIncludes( (String[]) fs.getIncludes().toArray( new String[0] ) );
+ }
+ if ( fs.getExcludes().size() > 0 )
+ {
+ ds.setExcludes( (String[]) fs.getExcludes().toArray( new String[0] ) );
+ }
+ ds.scan();
+ String[] srcFiles = ds.getIncludedFiles();
+ buildFileMap( new File( fs.getDirectory() ), srcFiles );
+ }
+ }
+
+ protected void buildFileMap( File directory, String[] sourceFiles )
+ {
+ for ( int i = 0; i < sourceFiles.length; i++ )
+ {
+ File src = new File( directory, sourceFiles[ i ] );
+ fileMap.put( src.getAbsolutePath(), src );
+ }
+ }
+
+ protected DocletTagFactory createDocletTagFactory()
+ {
+ return new DefaultDocletTagFactory();
+ }
+
+ private void mergeBuilderSources( JavaDocBuilder builder )
+ {
+ for ( Iterator iterator = fileMap.keySet().iterator(); iterator.hasNext(); )
+ {
+ String sourceFile = (String) iterator.next();
+ builder.addSourceTree( (File) fileMap.get( sourceFile ) );
+
+ }
+ }
+
+ protected void processSources( JavaSource[] sources )
+ {
+ for ( int i = 0; i < sources.length; i++ )
+ {
+ JavaSource source = sources[ i ];
+ allSources.add( source );
+ JavaClass[] classes = source.getClasses();
+ processClasses( classes );
+ }
+ }
+
+ protected void processClasses( JavaClass[] classes )
+ {
+ for ( int j = 0; j < classes.length; j++ )
+ {
+ JavaClass clazz = classes[ j ];
+ allClasses.add( clazz );
+ }
+ }
+
+ protected void validateAttributes() throws MojoExecutionException
+ {
+ if ( filesets == null || filesets.length == 0 )
+ {
+ filesets = createDefaultFileset();
+ }
+ }
+
+ protected FileSet[] createDefaultFileset()
+ {
+ FileSet[] defaultFileSet = new FileSet[] {new FileSet()};
+ List defaultPatternList = new ArrayList();
+
+ defaultPatternList.add(defaultIncludes);
+ defaultFileSet[0].setIncludes(defaultPatternList);
+ defaultFileSet[0].setDirectory(baseDir);
+
+ return defaultFileSet;
+ }
+
+ public File getDestDir()
+ {
+ return destDir;
+ }
+}
Added: excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/ComponentMetaMavenMojo.java
URL: http://svn.apache.org/viewcvs/excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/ComponentMetaMavenMojo.java?rev=358988&view=auto
==============================================================================
--- excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/ComponentMetaMavenMojo.java (added)
+++ excalibur/trunk/fortress/plugin/src/java/org/apache/avalon/fortress/tools/ComponentMetaMavenMojo.java Sun Dec 25 09:10:33 2005
@@ -0,0 +1,94 @@
+package org.apache.avalon.fortress.tools;
+
+import java.util.ArrayList;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+
+/**
+ * The Maven-2 plugin to extract Fortress meta-data from Java sources.
+ *
+ * @author <a href="mailto:dev@excalibur.apache.org">The Excalibur Team</a>
+ * @version CVS $Revision: 1.1 $ $Date: 2005/12/25 08:29:44 $
+ *
+ *
+ * @author The Excalibur Team
+ * @version $Id$
+ * @goal collect-metainfo
+ * @description Extracts Fortress Meta-information from annotations in .java files
+ * @phase compile
+ */
+ public class ComponentMetaMavenMojo extends AbstractQDoxMojo
+{
+
+ /**
+ * Wrap Maven plugin logger
+ */
+ private class MavenBuildLogger implements BuildLogger
+ {
+ private Log m_logger;
+
+ private MavenBuildLogger()
+ {
+ //Disallow use, must use construcor below that supplies Maven logger
+ }
+
+ public MavenBuildLogger( Log logger )
+ {
+ m_logger = logger;
+ }
+
+ public void debug( String message )
+ {
+ m_logger.debug( message );
+ }
+
+ public void error( String message )
+ {
+ m_logger.error( message );
+ }
+
+ public void info( String message )
+ {
+ m_logger.info( message );
+ }
+
+ public void warn( String message )
+ {
+ m_logger.warn( message );
+ }
+ }
+
+ public void execute() throws MojoExecutionException, MojoFailureException
+ {
+
+ validate();
+
+ getLog().info( "Writing Info descriptors as property files (.meta)." );
+
+ super.execute();
+
+ ComponentMetaInfoCollector collector = new ComponentMetaInfoCollector( new MavenBuildLogger( getLog() ) );
+ collector.setAllClasses( getAllClasses() );
+ collector.setDestDir( getDestDir() );
+ try
+ {
+ collector.execute();
+ }
+ catch ( Exception e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ }
+
+ private ArrayList getAllClasses()
+ {
+ return allClasses;
+ }
+
+ private void validate()
+ {
+ }
+
+}
Added: excalibur/trunk/fortress/plugin/src/site/apt/howto.apt
URL: http://svn.apache.org/viewcvs/excalibur/trunk/fortress/plugin/src/site/apt/howto.apt?rev=358988&view=auto
==============================================================================
--- excalibur/trunk/fortress/plugin/src/site/apt/howto.apt (added)
+++ excalibur/trunk/fortress/plugin/src/site/apt/howto.apt Sun Dec 25 09:10:33 2005
@@ -0,0 +1,54 @@
+ ------
+ Maven 2 Fortress Plugin: configuration examples
+ ------
+ The Excalibur Team
+ <de...@excalibur.apache.org>
+ ------
+ December 25, 2005
+
+ Introduction
+
+ The Fortress plugin allows extraction of Avalon/Fortress service meta-data from Java source files.
+
+ * collect-metadata (default): generates the war artifact
+
+ * The configuration in the pom.xml is as follows:
+-------------------
+ <build>
+ ...
+ <plugins>
+ ...
+ <plugin>
+ <groupId>org.apache.excalibur.fortress.meta</groupId>
+ <artifactId>maven-fortress-plugin</artifactId>
+ <version>0.0.1</version>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <goals>
+ <goal>collect-metainfo</goal>
+ </goals>
+ <configuration>
+ <destdir>
+ ${pom.build.outputDirectory}
+ </destdir>
+ <filesets>
+ <fileset>
+ <directory>
+ ${pom.build.sourceDirectory}
+ </directory>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </fileset>
+ </filesets>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ ...
+ </plugins>
+ ...
+ </build>
+-------------------
+
\ No newline at end of file
Added: excalibur/trunk/fortress/plugin/src/site/apt/introduction.apt
URL: http://svn.apache.org/viewcvs/excalibur/trunk/fortress/plugin/src/site/apt/introduction.apt?rev=358988&view=auto
==============================================================================
--- excalibur/trunk/fortress/plugin/src/site/apt/introduction.apt (added)
+++ excalibur/trunk/fortress/plugin/src/site/apt/introduction.apt Sun Dec 25 09:10:33 2005
@@ -0,0 +1,13 @@
+ ------
+ Maven 2 Fortress Plugin: configuration examples
+ ------
+ The Excalibur Team
+ <de...@excalibur.apache.org>
+ ------
+ December 25, 2005
+
+ Introduction
+
+ The Fortress plugin allows extraction of Avalon/Fortress service meta-data from Java source files.
+
+ The full description of goals is available {{{index.html}here}}.
Added: excalibur/trunk/fortress/plugin/src/site/site.xml
URL: http://svn.apache.org/viewcvs/excalibur/trunk/fortress/plugin/src/site/site.xml?rev=358988&view=auto
==============================================================================
--- excalibur/trunk/fortress/plugin/src/site/site.xml (added)
+++ excalibur/trunk/fortress/plugin/src/site/site.xml Sun Dec 25 09:10:33 2005
@@ -0,0 +1,28 @@
+<project name="Maven Fortress Plugin">
+
+ <bannerLeft>
+ <name>Maven Fortress Plugin</name>
+ <src>
+ http://maven.apache.org/images/apache-maven-project.png
+ </src>
+ <href>http://maven.apache.org/</href>
+ </bannerLeft>
+
+ <bannerRight>
+ <src>http://maven.apache.org/images/maven-small.gif</src>
+ </bannerRight>
+
+ <body>
+ <links>
+ <item name="Maven 2" href="http://maven.apache.org/maven2/"/>
+ </links>
+
+ <menu name="Overview">
+ <item name="Introduction" href="introduction.html"/>
+ <item name="How to Use" href="howto.html"/>
+ </menu>
+
+ ${reports}
+ </body>
+
+</project>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org