Support for test-multi-source in maven
--------------------------------------

         Key: MAVEN-64
         URL: http://jira.andromda.org/browse/MAVEN-64
     Project: Maven Plugins
        Type: New Feature

 Environment: maven 2.0.4, jdk 1.5
    Reporter: Pawel Matras
 Assigned to: Chad Brandon 


Modified version of 
andromda-all/maven/2/multi-source/src/main/java/org/andromda/maven/plugin/MultiSourceMojo.java
 follows (as I can not see an other way of attaching it). It adds to current 
implementation a possibility for additional test source paths. Usage is similar 
to existing one. In addition or instead of the <sourceDirectories> tag you use 
<testSourceDirectories> tag in plugin configuration.
I have tested it with maven 2.0.4 and jdk 1.5.
It would be fine if this or similar patch could be applied on the 3.3-SNAPSHOT 
branch and newer.

----------------------------- MultiSourceMojo.java 
-----------------------------------
package org.andromda.maven.plugin.multisource;

import java.util.Iterator;
import java.util.List;

import org.andromda.core.common.ResourceUtils;
import org.apache.commons.lang.ObjectUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;


/**
 * A Mojo who's sole purpose is to allow multiple source roots
 * to be added to the project (since the Maven Compiler Plugin
 * doesn't allow it), this plugin should be removed if they
 * allow it in the future.
 *
 * @author Chad Brandon
 * @goal add-source
 * @phase generate-sources
 */
public class MultiSourceMojo
    extends AbstractMojo
{
    /**
     * The source directories containing the sources to be compiled.
     *
     * @parameter
     * @required
     */
    private List sourceDirectories;

    /**
     * The test source directories containing the sources to be compiled for 
test.
     *
     * @parameter
     * @required
     */
    private List testSourceDirectories;

    /**
     * The maven project.
     *
     * @parameter expression="${project}"
     * @required
     * @readonly
     * @description "the maven project to use"
     */
    private MavenProject project;

    /**
     * @see org.apache.maven.plugin.Mojo#execute()
     */
    public void execute()
        throws MojoExecutionException, MojoFailureException
    {
        String baseDirectory = 
ResourceUtils.normalizePath(ObjectUtils.toString(project.getBasedir()) + '/');
        addNormalizedPaths( this.sourceDirectories,
            this.project.getCompileSourceRoots(), baseDirectory );
        addNormalizedPaths( this.testSourceDirectories,
            this.project.getTestCompileSourceRoots(), baseDirectory );
    }
  
    private void addNormalizedPaths( List fromPaths, List toPaths, String 
baseDirectory )
    {
        for (final Iterator iterator = fromPaths.iterator(); 
iterator.hasNext();)
        {
            String path = ResourceUtils.normalizePath((String)iterator.next());
            if (!path.startsWith(baseDirectory))
            {
                path = ResourceUtils.normalizePath(baseDirectory + path);
            }
            toPaths.add(path);
        }
    }
}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.andromda.org/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

Reply via email to