Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AntTaskMojo |
|
| 1.5714285714285714;1.571 |
1 | package org.apache.torque.mojo; | |
2 | ||
3 | import org.apache.maven.plugin.MojoExecutionException; | |
4 | import org.apache.tools.ant.Project; | |
5 | import org.apache.tools.ant.Task; | |
6 | import org.apache.torque.util.MojoAntBuildListener; | |
7 | import org.kuali.core.db.torque.FilteredPropertyCopier; | |
8 | ||
9 | /** | |
10 | * A base class for mojos that wrap an Ant Task | |
11 | */ | |
12 | 0 | public class AntTaskMojo extends BaseMojo { |
13 | ||
14 | /** | |
15 | * The ant task to be executed by this mojo. | |
16 | */ | |
17 | private Task antTask; | |
18 | ||
19 | /** | |
20 | * The ant project for the ant task. | |
21 | */ | |
22 | private Project antProject; | |
23 | ||
24 | /** | |
25 | * Configures the Ant task which is wrapped by this mojo. | |
26 | */ | |
27 | protected void configureTask() throws MojoExecutionException { | |
28 | 0 | if (getAntTask() == null) { |
29 | 0 | throw new IllegalArgumentException("Ant task is null"); |
30 | } | |
31 | ||
32 | // Attach our task to a project | |
33 | 0 | setAntProject(getIniatializedAntProject()); |
34 | 0 | getAntTask().setProject(getAntProject()); |
35 | try { | |
36 | // Copy configuration from the mojo to the task | |
37 | 0 | FilteredPropertyCopier copier = new FilteredPropertyCopier(); |
38 | // There is a setProject() method on an Ant Task that expects an Ant Project. This conflicts with | |
39 | // getProject() from the mojo which returns a Maven Project | |
40 | 0 | copier.addExclude("project"); |
41 | 0 | copier.copyProperties(getAntTask(), this); |
42 | 0 | } catch (Exception e) { |
43 | 0 | throw new MojoExecutionException("Error copying properties", e); |
44 | 0 | } |
45 | 0 | } |
46 | ||
47 | /** | |
48 | * Configure the Ant task and then execute it | |
49 | */ | |
50 | public void executeMojo() throws MojoExecutionException { | |
51 | 0 | configureTask(); |
52 | 0 | getAntTask().execute(); |
53 | 0 | } |
54 | ||
55 | /** | |
56 | * Return an Ant project that informs Maven about logging events | |
57 | */ | |
58 | protected Project getIniatializedAntProject() { | |
59 | 0 | getLog().info("Initializing the Ant Project"); |
60 | // Create a new Ant Project | |
61 | 0 | Project antProject = new Project(); |
62 | // initialize it | |
63 | 0 | antProject.init(); |
64 | // Add a listener that gets notified about log messages | |
65 | 0 | antProject.addBuildListener(new MojoAntBuildListener(getLog())); |
66 | // Return the initialized ant project | |
67 | 0 | return antProject; |
68 | } | |
69 | ||
70 | public Project getAntProject() { | |
71 | 0 | return antProject; |
72 | } | |
73 | ||
74 | public void setAntProject(Project antProject) { | |
75 | 0 | this.antProject = antProject; |
76 | 0 | } |
77 | ||
78 | public Task getAntTask() { | |
79 | 0 | return antTask; |
80 | } | |
81 | ||
82 | public void setAntTask(Task antTask) { | |
83 | 0 | this.antTask = antTask; |
84 | 0 | } |
85 | } |