find_link

Maven Plugins

Support for test-multi-source in maven

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Not an issue
  • Affects Version/s: None
  • Fix Version/s: 3.4-SNAPSHOT
  • Component/s: None
  • Description:
    Hide
    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);
            }
        }
    }
    Show
    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);         }     } }
  • Environment:
    maven 2.0.4, jdk 1.5

Activity

Hide
Pawel Matras added a comment - 11/Jun/07 12:11 PM
Here is more robust version of the multi-source plugin (it will not fail on empty directories in pom.xml). Test source generation is made optional too.


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
     */
    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 );
        if (this.testSourceDirectories != null)
{
            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 != null)
{
               if (!path.startsWith(baseDirectory))
               {
               path = ResourceUtils.normalizePath(baseDirectory + path);
               }
               toPaths.add(path);
            }
        }
    }
}
Show
Pawel Matras added a comment - 11/Jun/07 12:11 PM Here is more robust version of the multi-source plugin (it will not fail on empty directories in pom.xml). Test source generation is made optional too. 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      */     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 );         if (this.testSourceDirectories != null) {             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 != null) {                if (!path.startsWith(baseDirectory))                {                path = ResourceUtils.normalizePath(baseDirectory + path);                }                toPaths.add(path);             }         }     } }
Hide
Plushnikov Michail added a comment - 27/Dec/09 5:24 PM
We don't provide our implementation of multi-source-plugin anymore.
You can use codehaus plugin instead:

<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>

http://mojo.codehaus.org/build-helper-maven-plugin/usage.html
Show
Plushnikov Michail added a comment - 27/Dec/09 5:24 PM We don't provide our implementation of multi-source-plugin anymore. You can use codehaus plugin instead: <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> http://mojo.codehaus.org/build-helper-maven-plugin/usage.html

People

Dates

  • Created:
    01/Jun/07 3:11 PM
    Updated:
    27/Dec/09 5:24 PM
    Resolved:
    27/Dec/09 5:24 PM