View Javadoc

1   package org.apache.maven.jelly.tags.maven;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
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          // Check to make sure that we have a valid POM
89          // before processing.
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 }