View Javadoc

1   package org.apache.maven.plugin.antrun;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.List;
24  
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.project.MavenProject;
27  import org.apache.tools.ant.Target;
28  
29  /**
30   * Maven AntRun Mojo.
31   *
32   * This plugin provides the capability of calling Ant tasks
33   * from a POM by running the nested ant tasks inside the <tasks/>
34   * parameter. It is encouraged to move the actual tasks to
35   * a separate build.xml file and call that file with an
36   * <ant/> task.
37   *
38   * @author <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
39   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
40   * @version $Id: AntRunMojo.html 816154 2012-05-06 21:49:58Z hboutemy $
41   * @configurator override
42   * @goal run
43   * @requiresDependencyResolution test
44   */
45  public class AntRunMojo
46      extends AbstractAntMojo
47  {
48      /**
49       * The Maven project object
50       *
51       * @parameter expression="${project}"
52       * @required
53       * @readonly
54       */
55      private MavenProject project;
56  
57      /**
58       * The plugin dependencies.
59       *
60       * @parameter expression="${plugin.artifacts}"
61       * @required
62       * @readonly
63       */
64      private List pluginArtifacts;
65  
66      /**
67       * The XML for the Ant task. You can add anything you can add
68       * between &lt;target&gt; and &lt;/target&gt; in a build.xml.
69       *
70       * @parameter expression="${tasks}"
71       */
72      private Target tasks;
73  
74      /**
75       * This folder is added to the list of those folders
76       * containing source to be compiled. Use this if your
77       * ant script generates source code.
78       *
79       * @parameter expression="${sourceRoot}"
80       */
81      private File sourceRoot;
82  
83      /**
84       * This folder is added to the list of those folders
85       * containing source to be compiled for testing. Use this if your
86       * ant script generates test source code.
87       *
88       * @parameter expression="${testSourceRoot}"
89       */
90      private File testSourceRoot;
91  
92      /**
93       * @see org.apache.maven.plugin.Mojo#execute()
94       */
95      public void execute()
96          throws MojoExecutionException
97      {
98          executeTasks( tasks, project, pluginArtifacts );
99  
100         if ( sourceRoot != null )
101         {
102             getLog().info( "Registering compile source root " + sourceRoot );
103             project.addCompileSourceRoot( sourceRoot.toString() );
104         }
105 
106         if ( testSourceRoot != null )
107         {
108             getLog().info( "Registering compile test source root " + testSourceRoot );
109             project.addTestCompileSourceRoot( testSourceRoot.toString() );
110         }
111     }
112 }