01: package org.andromda.maven.plugin.multisource;
02:
03: import java.util.Iterator;
04: import java.util.List;
05:
06: import org.andromda.core.common.ResourceUtils;
07: import org.apache.commons.lang.ObjectUtils;
08: import org.apache.maven.plugin.AbstractMojo;
09: import org.apache.maven.plugin.MojoExecutionException;
10: import org.apache.maven.plugin.MojoFailureException;
11: import org.apache.maven.project.MavenProject;
12:
13: /**
14: * A Mojo who's sole purpose is to allow multiple source roots
15: * to be added to the project (since the Maven Compiler Plugin
16: * doesn't allow it), this plugin should be removed if they
17: * allow it in the future.
18: *
19: * @author Chad Brandon
20: * @goal add-source
21: * @phase generate-sources
22: */
23: public class MultiSourceMojo extends AbstractMojo {
24: /**
25: * The source directories containing the sources to be compiled.
26: *
27: * @parameter
28: * @required
29: */
30: private List sourceDirectories;
31:
32: /**
33: * The maven project.
34: *
35: * @parameter expression="${project}"
36: * @required
37: * @readonly
38: * @description "the maven project to use"
39: */
40: private MavenProject project;
41:
42: /**
43: * @see org.apache.maven.plugin.Mojo#execute()
44: */
45: public void execute() throws MojoExecutionException,
46: MojoFailureException {
47: final String baseDirectory = ResourceUtils
48: .normalizePath(ObjectUtils.toString(project
49: .getBasedir()) + '/');
50: for (final Iterator iterator = this .sourceDirectories
51: .iterator(); iterator.hasNext();) {
52: String path = ResourceUtils.normalizePath((String) iterator
53: .next());
54: if (!path.startsWith(baseDirectory)) {
55: path = ResourceUtils
56: .normalizePath(baseDirectory + path);
57: }
58: this.project.getCompileSourceRoots().add(path);
59: }
60: }
61: }
|