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 org.apache.commons.jelly.JellyTagException;
22 import org.apache.commons.jelly.XMLOutput;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.maven.jelly.MavenJellyContext;
26 import org.apache.maven.jelly.tags.BaseTagSupport;
27 import org.apache.maven.plugin.UnknownPluginException;
28 import org.apache.maven.project.Project;
29
30 /**
31 * A tag to retrieve values from plugins
32 */
33 public class GetTag
34 extends BaseTagSupport
35 {
36 /** LOGGER for debug output */
37 private static final Log LOGGER = LogFactory.getLog( GetTag.class );
38
39 /** the variable to set*/
40 private String var;
41
42 /** the plugin to get the variable from*/
43 private String plugin;
44
45 /** the name of the plugin property to retrieve */
46 private String property;
47
48 /**
49 * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
50 */
51 public void doTag( XMLOutput output )
52 throws JellyTagException
53 {
54 checkAttribute( var, "var" );
55 checkAttribute( plugin, "plugin" );
56 checkAttribute( property, "property" );
57 Project project = getMavenContext().getProject();
58 try
59 {
60 MavenJellyContext context = project.getPluginContext( plugin );
61 if ( context != null )
62 {
63 Object value = context.getVariable( property );
64 getContext().setVariable( var, value );
65 }
66 else
67 {
68 LOGGER.error( "context for plugin '" + plugin + "' in project '" + project + "' is null" );
69 }
70 }
71 catch ( UnknownPluginException e )
72 {
73 LOGGER.error( "Plugin '" + plugin + "' in project '" + project + "' is not available" );
74 }
75 catch ( Exception e )
76 {
77 throw new JellyTagException( "Error loading plugin", e );
78 }
79 }
80
81 /**
82 * @return the plugin to retrieve the property from.
83 */
84 public String getPlugin()
85 {
86 return plugin;
87 }
88
89 /**
90 * @return the name of the property being retrieved
91 */
92 public String getProperty()
93 {
94 return property;
95 }
96
97 /**
98 * @return the variable name to set
99 */
100 public String getVar()
101 {
102 return var;
103 }
104
105 /**
106 * @param pluginId the id of the plugin to retrieve the property from
107 */
108 public void setPlugin( String pluginId )
109 {
110 plugin = pluginId;
111 }
112
113 /**
114 * @param propertyName the name of the property being retrieved
115 */
116 public void setProperty( String propertyName )
117 {
118 property = propertyName;
119 }
120
121 /**
122 * @param variable the variable name to set
123 */
124 public void setVar( String variable )
125 {
126 this.var = variable;
127 }
128
129 }