package org.apache.maven.jelly.tags.maven;
/* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.maven.jelly.MavenJellyContext;
import org.apache.maven.jelly.tags.BaseTagSupport;
import org.apache.maven.plugin.UnknownPluginException;
import org.apache.maven.project.Project;
/**
* A tag to retrieve values from plugins
*/
public class GetTag
extends BaseTagSupport
{
/** LOGGER for debug output */
private static final Log LOGGER = LogFactory.getLog( GetTag.class );
/** the variable to set*/
private String var;
/** the plugin to get the variable from*/
private String plugin;
/** the name of the plugin property to retrieve */
private String property;
/**
* @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
*/
public void doTag( XMLOutput output )
throws JellyTagException
{
checkAttribute( var, "var" );
checkAttribute( plugin, "plugin" );
checkAttribute( property, "property" );
Project project = getMavenContext().getProject();
try
{
MavenJellyContext context = project.getPluginContext( plugin );
if ( context != null )
{
Object value = context.getVariable( property );
getContext().setVariable( var, value );
}
else
{
LOGGER.error( "context for plugin '" + plugin + "' in project '" + project + "' is null" );
}
}
catch ( UnknownPluginException e )
{
LOGGER.error( "Plugin '" + plugin + "' in project '" + project + "' is not available" );
}
catch ( Exception e )
{
throw new JellyTagException( "Error loading plugin", e );
}
}
/**
* @return the plugin to retrieve the property from.
*/
public String getPlugin()
{
return plugin;
}
/**
* @return the name of the property being retrieved
*/
public String getProperty()
{
return property;
}
/**
* @return the variable name to set
*/
public String getVar()
{
return var;
}
/**
* @param pluginId the id of the plugin to retrieve the property from
*/
public void setPlugin( String pluginId )
{
plugin = pluginId;
}
/**
* @param propertyName the name of the property being retrieved
*/
public void setProperty( String propertyName )
{
property = propertyName;
}
/**
* @param variable the variable name to set
*/
public void setVar( String variable )
{
this.var = variable;
}
}