Package org.apache.maven.jelly.tags.werkz

Source Code of org.apache.maven.jelly.tags.werkz.MavenGoalTag

package org.apache.maven.jelly.tags.werkz;

/* ====================================================================
*   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.maven.MavenConstants;
import org.apache.maven.jelly.MavenJellyContext;
import org.apache.maven.plugin.JellyScriptHousing;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.werkz.Action;
import org.apache.maven.werkz.Goal;
import org.apache.maven.werkz.Session;
import org.apache.maven.werkz.WerkzProject;
import org.apache.maven.werkz.jelly.GoalTag;

/**
* Replacement for werkz's <code>GoalTag</code> which does not allow a goal
* to be redefined once defined.
* For Jelly scripts that are run which contain this tag it is assumed that
* they are being run in the order whereby the first definition wins.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id: MavenGoalTag.java 517014 2007-03-11 21:15:50Z ltheussl $
*/
public class MavenGoalTag
    extends GoalTag
{
    // ------------------------------------------------------------
    // C O N S T R U C T O R S
    // ------------------------------------------------------------

    /**
     * Construct.
     */
    public MavenGoalTag()
    {
        // intentionally left blank.
    }

    /**
     * Define a goal.
     *
     * @param output The output sink.
     * @throws JellyTagException If an error occurs while executing the tag.
     */
    public void doTag( XMLOutput output )
        throws JellyTagException
    {
        Goal goal = getProject().getGoal( getName() );

        if ( ( goal == null ) || ( goal.getAction() == null ) )
        {
            super.doTag( output );
            goal = getProject().getGoal( getName() );
            JellyScriptHousing currentHousing = (JellyScriptHousing) getContext()
                .getVariable( PluginManager.PLUGIN_HOUSING );
            goal.setAction( new MavenGoalAction( currentHousing ) );
        }
    }

    void runBodyTag( Session session )
        throws JellyTagException
    {
        MavenJellyContext context = (MavenJellyContext) getContext();

        getBody().run( context, context.getXMLOutput() );
    }

    /**
     * @todo refactor into a separate class that gets the necessary variables delegated to it.
     */
    public class MavenGoalAction
        implements Action
    {
        private final JellyScriptHousing housing;

        public MavenGoalAction( JellyScriptHousing housing )
        {
            super();
            this.housing = housing;
            if ( housing == null )
            {
                throw new NullPointerException( "Plugin Housing can not be null" );
            }
        }

        public void performAction( Session session )
            throws Exception
        {
            MavenJellyContext oldContext = (MavenJellyContext) getContext();

            //GoalToJellyScriptHousingMapper mapper = ( GoalToJellyScriptHousingMapper ) session.getAttribute(
            //PluginManager.GOAL_MAPPER );
            //JellyScriptHousing housing = mapper.getPluginHousing( getName() );
            MavenJellyContext context = housing.getProject().getContext();

            setContext( context );

            runBodyTag( session );

            setContext( oldContext );
        }

        public boolean requiresAction()
        {
            return true;
        }
    }

    public WerkzProject getProject()
    {
        return (WerkzProject) getContext().getVariable( MavenConstants.WERKZ_PROJECT );
    }
}
TOP

Related Classes of org.apache.maven.jelly.tags.werkz.MavenGoalTag

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.