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 java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.XMLOutput;
import org.apache.maven.MavenConstants;
import org.apache.maven.MavenUtils;
import org.apache.maven.jelly.tags.BaseTagSupport;
import org.apache.maven.project.Project;
/**
* A way of running maven as a Jelly tag
*
* @author <a href="mailto:bob@werken.com">bob mcwhirter</a>
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
*
* @version $Id: MavenTag.java 517014 2007-03-11 21:15:50Z ltheussl $
*
* @todo get rid of 'throws Exception'
*/
public class MavenTag
extends BaseTagSupport
{
/** maven project descriptor */
private File descriptor;
/** goals to verify */
private String goals;
/** whether to ignore exceptions */
private boolean ignoreFailures;
/**
* Process the tag. Set up a new maven instance with the same maven home
* as the one under <code>maven.obj</code> in the context, add the provided
* goals and verify.
*
* @param output for providing xml output
* @throws JellyTagException if anything goes wrong.
*/
public void doTag( XMLOutput output )
throws MissingAttributeException, JellyTagException
{
checkAttribute( getDescriptor(), "descriptor" );
Project project = null;
try
{
project = MavenUtils.getProject( getDescriptor(), getMavenContext().getMavenSession().getRootContext() );
project.verifyDependencies();
getMavenContext().getMavenSession().getPluginManager().processDependencies( project );
// Set the project goals if they have been specified.
List goalList = new ArrayList();
if ( getGoals() != null )
{
goalList.addAll( MavenUtils.getGoalListFromCsv( getGoals() ) );
}
getMavenContext().getMavenSession().attainGoals( project, goalList );
}
catch ( Exception e )
{
if ( isIgnoreFailures() )
{
getMavenContext().setVariable( MavenConstants.BUILD_FAILURE, "true" );
if ( project != null )
{
Collection c = (Collection) getContext().getVariable( MavenConstants.FAILED_PROJECTS );
if ( c == null )
{
c = new ArrayList();
}
c.add( project );
getContext().setVariable( MavenConstants.FAILED_PROJECTS, c );
}
return;
}
throw new JellyTagException( e );
}
}
// ------------------------------------------------------------
// A C C E S S O R S
// ------------------------------------------------------------
/**
* Setter for the descriptor property
*
* @param descriptor the maven project descriptor to be read
*/
public void setDescriptor( File descriptor )
{
this.descriptor = descriptor;
}
/**
* Getter for the descriptor property
*
* @return the maven project descriptor to be read
*/
public File getDescriptor()
{
return this.descriptor;
}
/**
* Setter for the basedir property
*
* @param basedir the base directory for execution of the project
* @deprecated You only need to specify the project descriptor.
*/
public void setBasedir( File basedir )
{
System.out.println( "\nDEPRECATION WARNING: you no longer need to specify the basedir attribute.\n" );
}
/**
* Setter for the goals property
*
* @param goals a comma separated list of goal names to attain
*/
public void setGoals( String goals )
{
this.goals = goals;
}
/**
* Getter for the goals property
*
* @return a comma separated list of goal names to attain
*/
public String getGoals()
{
return this.goals;
}
/**
* Set the ignore failures flag.
*
* @param ignoreFailures The ignore failures flag.
*/
public void setIgnoreFailures( boolean ignoreFailures )
{
this.ignoreFailures = ignoreFailures;
}
/**
* Get the ignore failures flag.
*
* @return boolean The ignores failure flag.
*/
public boolean isIgnoreFailures()
{
return ignoreFailures;
}
}