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.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
76
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 }