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
23 import org.apache.commons.jelly.JellyTagException;
24 import org.apache.commons.jelly.MissingAttributeException;
25 import org.apache.commons.jelly.XMLOutput;
26 import org.apache.maven.MavenUtils;
27 import org.apache.maven.jelly.tags.BaseTagSupport;
28
29 /**
30 * MavenSession Jelly tag that creates a POM instance.
31 * By default, the inheritance in the POM isn't used.
32 * You must use the attribute useInheritance to activate it.
33 *
34 * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
35 * @version $Id: PomTag.java 517014 2007-03-11 21:15:50Z ltheussl $
36 */
37 public class PomTag
38 extends BaseTagSupport
39 {
40 /** MavenSession project descriptor. */
41 private File projectDescriptor;
42
43 /** Name of var to give the project object. */
44 private String var;
45
46 /** Define if the pom must use the inheritance. */
47 private boolean useInheritance;
48
49 /**
50 * Set MavenSession project descriptor.
51 *
52 * @param projectDescriptor the file name of the maven project descriptor
53 */
54 public void setProjectDescriptor( File projectDescriptor )
55 {
56 this.projectDescriptor = projectDescriptor;
57 }
58
59 /**
60 * Set var name for the POM.
61 *
62 * @param var Variable name for the pom.
63 */
64 public void setVar( String var )
65 {
66 this.var = var;
67 }
68
69 /**
70 * Define if the pom must use the inheritance.
71 * Setted to false by default to keep a backward compatibility.
72 * @param useInheritance true if the pom object must use the inheritance.
73 */
74 public void setUseInheritance( boolean useInheritance )
75 {
76 this.useInheritance = useInheritance;
77 }
78
79 /**
80 * Perform functionality provided by the tag
81 * @param output the place to write output
82 * @throws JellyTagException when the projectDescriptor attribute is missing, or
83 * another error occurs
84 */
85 public void doTag( XMLOutput output )
86 throws MissingAttributeException, JellyTagException
87 {
88
89
90 checkAttribute( projectDescriptor, "projectDescriptor" );
91 checkAttribute( var, "var" );
92
93 try
94 {
95 context.setVariable( var, MavenUtils.getProject( projectDescriptor, getMavenContext(), useInheritance ) );
96 }
97 catch ( Exception e )
98 {
99 throw new JellyTagException( "error getting project", e );
100 }
101 }
102 }