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