View Javadoc

1   /*
2    * Copyright (c) 2007, Ounce Labs, Inc.
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *     * Redistributions of source code must retain the above copyright
8    *       notice, this list of conditions and the following disclaimer.
9    *     * Redistributions in binary form must reproduce the above copyright
10   *       notice, this list of conditions and the following disclaimer in the
11   *       documentation and/or other materials provided with the distribution.
12   *     * Neither the name of the <organization> nor the
13   *       names of its contributors may be used to endorse or promote products
14   *       derived from this software without specific prior written permission.
15   *
16   * THIS SOFTWARE IS PROVIDED BY OUNCE LABS, INC. ``AS IS'' AND ANY
17   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19   * DISCLAIMED. IN NO EVENT SHALL OUNCE LABS, INC. BE LIABLE FOR ANY
20   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   */
27  package org.codehaus.mojo.ounce;
28  
29  import java.util.List;
30  
31  import org.apache.maven.project.MavenProject;
32  
33  /**
34   * This mojo generates an Ounce project file. It forks the build and executes the process-sources phase so that any
35   * plugins that may generate sources and attach new source folders to the project will execute and those source folders
36   * will be automatically included in the generated project. This mojo is intended to be executed from the command line.
37   * If you would rather have the project built automatically during your build, use the project-only goal instead.
38   * 
39   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
40   * @requiresDependencyResolution test
41   * @goal project
42   * @execute phase="process-sources"
43   */
44  public class ProjectMojo
45      extends ProjectOnlyMojo
46  {
47  
48      /**
49       * The project executed when forked.
50       * 
51       * @parameter expression="${executedProject}"
52       * @readonly
53       */
54      protected MavenProject executedProject;
55  
56      /**
57       * This method gets the source roots from the forked project (executedProject)
58       * 
59       * @return List of source roots.
60       */
61      protected List getSourceRoots()
62      {
63          List sourceRoots = executedProject.getCompileSourceRoots();
64  
65          if ( this.includeTestSources )
66          {
67              sourceRoots.addAll( executedProject.getTestCompileSourceRoots() );
68          }
69          return sourceRoots;
70      }
71  
72      /**
73       * @return the executedProject
74       */
75      public MavenProject getExecutedProject()
76      {
77          return this.executedProject;
78      }
79  
80      /**
81       * @param theExecutedProject the executedProject to set
82       */
83      public void setExecutedProject( MavenProject theExecutedProject )
84      {
85          this.executedProject = theExecutedProject;
86      }
87  }