1 package org.apache.maven.jelly.tags.maven;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25
26 import org.apache.commons.jelly.JellyTagException;
27 import org.apache.commons.jelly.MissingAttributeException;
28 import org.apache.commons.jelly.XMLOutput;
29 import org.apache.maven.MavenConstants;
30 import org.apache.maven.MavenUtils;
31 import org.apache.maven.jelly.tags.BaseTagSupport;
32 import org.apache.maven.project.Project;
33
34 /**
35 * A way of running maven as a Jelly tag
36 *
37 * @author <a href="mailto:bob@werken.com">bob mcwhirter</a>
38 * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
39 *
40 * @version $Id: MavenTag.java 517014 2007-03-11 21:15:50Z ltheussl $
41 *
42 * @todo get rid of 'throws Exception'
43 */
44 public class MavenTag
45 extends BaseTagSupport
46 {
47 /** maven project descriptor */
48 private File descriptor;
49
50 /** goals to verify */
51 private String goals;
52
53 /** whether to ignore exceptions */
54 private boolean ignoreFailures;
55
56 /**
57 * Process the tag. Set up a new maven instance with the same maven home
58 * as the one under <code>maven.obj</code> in the context, add the provided
59 * goals and verify.
60 *
61 * @param output for providing xml output
62 * @throws JellyTagException if anything goes wrong.
63 */
64 public void doTag( XMLOutput output )
65 throws MissingAttributeException, JellyTagException
66 {
67 checkAttribute( getDescriptor(), "descriptor" );
68
69 Project project = null;
70 try
71 {
72 project = MavenUtils.getProject( getDescriptor(), getMavenContext().getMavenSession().getRootContext() );
73 project.verifyDependencies();
74 getMavenContext().getMavenSession().getPluginManager().processDependencies( project );
75
76
77 List goalList = new ArrayList();
78 if ( getGoals() != null )
79 {
80 goalList.addAll( MavenUtils.getGoalListFromCsv( getGoals() ) );
81 }
82
83 getMavenContext().getMavenSession().attainGoals( project, goalList );
84 }
85 catch ( Exception e )
86 {
87 if ( isIgnoreFailures() )
88 {
89 getMavenContext().setVariable( MavenConstants.BUILD_FAILURE, "true" );
90 if ( project != null )
91 {
92 Collection c = (Collection) getContext().getVariable( MavenConstants.FAILED_PROJECTS );
93 if ( c == null )
94 {
95 c = new ArrayList();
96 }
97 c.add( project );
98 getContext().setVariable( MavenConstants.FAILED_PROJECTS, c );
99 }
100 return;
101 }
102
103 throw new JellyTagException( e );
104 }
105 }
106
107
108
109
110
111 /**
112 * Setter for the descriptor property
113 *
114 * @param descriptor the maven project descriptor to be read
115 */
116 public void setDescriptor( File descriptor )
117 {
118 this.descriptor = descriptor;
119 }
120
121 /**
122 * Getter for the descriptor property
123 *
124 * @return the maven project descriptor to be read
125 */
126 public File getDescriptor()
127 {
128 return this.descriptor;
129 }
130
131 /**
132 * Setter for the basedir property
133 *
134 * @param basedir the base directory for execution of the project
135 * @deprecated You only need to specify the project descriptor.
136 */
137 public void setBasedir( File basedir )
138 {
139 System.out.println( "\nDEPRECATION WARNING: you no longer need to specify the basedir attribute.\n" );
140 }
141
142 /**
143 * Setter for the goals property
144 *
145 * @param goals a comma separated list of goal names to attain
146 */
147 public void setGoals( String goals )
148 {
149 this.goals = goals;
150 }
151
152 /**
153 * Getter for the goals property
154 *
155 * @return a comma separated list of goal names to attain
156 */
157 public String getGoals()
158 {
159 return this.goals;
160 }
161
162 /**
163 * Set the ignore failures flag.
164 *
165 * @param ignoreFailures The ignore failures flag.
166 */
167 public void setIgnoreFailures( boolean ignoreFailures )
168 {
169 this.ignoreFailures = ignoreFailures;
170 }
171
172 /**
173 * Get the ignore failures flag.
174 *
175 * @return boolean The ignores failure flag.
176 */
177 public boolean isIgnoreFailures()
178 {
179 return ignoreFailures;
180 }
181 }