001package org.andromda.maven.plugin.andromdapp;
002
003import java.io.File;
004
005import org.apache.maven.plugin.AbstractMojo;
006import org.apache.maven.plugin.MojoExecutionException;
007import org.apache.maven.project.MavenProject;
008import org.apache.commons.lang.StringUtils;
009
010
011/**
012 * An abstract Mojo for app server management.
013 *
014 * @author Chad Brandon
015 */
016public abstract class AppManagementMojo
017    extends AbstractMojo
018{
019    /**
020     * The location (i.e. path) to deploy.
021     *
022     * @parameter
023     * @required
024     */
025    protected File deployLocation;
026
027    /**
028     * @parameter expression="${project}"
029     * @required
030     * @readonly
031     */
032    protected MavenProject project;
033
034    /**
035     * Attempts to retrieve the packaging of the current project, and if it can't
036     * find it, throws an exception.
037     *
038     * @return the packaging.
039     * @throws MojoExecutionException if no packaging was found.
040     */
041    protected String getPackaging() throws MojoExecutionException
042    {
043        final String packaging = this.project.getPackaging();
044        if (StringUtils.isBlank(packaging))
045        {
046            throw new MojoExecutionException(
047                "This project must have the packaging defined, when attempting to deploy exploded");
048        }
049        return packaging;
050    }
051
052    /**
053     * Retrieves the file that will be or is deployed.
054     *
055     * @return the deploy file.
056     * @throws MojoExecutionException
057     */
058    protected File getDeployFile() throws MojoExecutionException
059    {
060        return new File(this.deployLocation, this.project.getBuild().getFinalName() + '.' + this.getPackaging());
061    }
062}