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 set plugin values
32 */
33 public class SetTag
34 extends BaseTagSupport
35 {
36 /** LOGGER for debug output */
37 private static final Log LOGGER = LogFactory.getLog( SetTag.class );
38
39 /** the value to set */
40 private Object value;
41
42 /** the plugin in which the variable will be set */
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( value, "value" );
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 context.setVariable( property, value );
64 }
65 else
66 {
67 LOGGER.error( "context for plugin '" + plugin + "' in project '" + project + "' is null" );
68 }
69 }
70 catch ( UnknownPluginException e )
71 {
72 LOGGER.error( "Plugin '" + plugin + "' in project '" + project + "' is not available" );
73 }
74 catch ( Exception e )
75 {
76 throw new JellyTagException( "Error loading plugin", e );
77 }
78 }
79
80 /**
81 * @return the plugin to retrieve the property from.
82 */
83 public String getPlugin()
84 {
85 return plugin;
86 }
87
88 /**
89 * @return the name of the property being retrieved
90 */
91 public String getProperty()
92 {
93 return property;
94 }
95
96 /**
97 * @return the value to set
98 */
99 public Object getValue()
100 {
101 return value;
102 }
103
104 /**
105 * @param pluginId the id of the plugin in which the property will be set
106 */
107 public void setPlugin( String pluginId )
108 {
109 plugin = pluginId;
110 }
111
112 /**
113 * @param propertyName the name of the property being set
114 */
115 public void setProperty( String propertyName )
116 {
117 property = propertyName;
118 }
119
120 /**
121 * @param value the value to set
122 */
123 public void setValue( Object value )
124 {
125 this.value = value;
126 }
127
128 }