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  import java.io.IOException;
23  
24  import org.apache.commons.jelly.JellyTagException;
25  import org.apache.commons.jelly.MissingAttributeException;
26  import org.apache.commons.jelly.XMLOutput;
27  import org.apache.maven.MavenUtils;
28  import org.apache.maven.jelly.tags.BaseTagSupport;
29  
30  /**
31   * Jelly tag to convert a relative path into an absolute path by prepending the basedir if it
32   * is relative.
33   *
34   * @author Brett Porter <a href="mailto:brett@apache.org">brett@apache.org</a>
35   */
36  public class MakeAbsolutePathTag
37      extends BaseTagSupport
38  {
39      /** The base dir. */
40      private File basedir;
41  
42      /** The path to convert. */
43      private String path;
44  
45      /** The jelly variable to store the result into. */
46      private String var;
47  
48      /**
49       * Set the base directory.
50       * @param basedir the base directory.
51       */
52      public void setBasedir( File basedir )
53      {
54          this.basedir = basedir;
55      }
56  
57      /**
58       * Set the path.
59       * @param path the path.
60       */
61      public void setPath( String path )
62      {
63          this.path = path;
64      }
65  
66      /**
67       * Set the result variable.
68       * @param var the result variable name.
69       */
70      public void setVar( String var )
71      {
72          this.var = var;
73      }
74  
75      /* (non-Javadoc)
76       * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
77       */
78      public void doTag( XMLOutput output )
79          throws MissingAttributeException, JellyTagException
80      {
81          checkAttribute( basedir, "basedir" );
82          checkAttribute( path, "path" );
83          checkAttribute( var, "var" );
84  
85          try
86          {
87              getContext().setVariable( var, MavenUtils.makeAbsolutePath( basedir, path ) );
88          }
89          catch ( IOException e )
90          {
91              throw new JellyTagException( "Unable to resolve directory", e );
92          }
93      }
94  }