View Javadoc
1   package org.andromda.maven.plugin.andromdapp;
2   
3   import java.io.File;
4   
5   import org.apache.maven.plugin.AbstractMojo;
6   import org.apache.maven.plugin.MojoExecutionException;
7   import org.apache.maven.project.MavenProject;
8   import org.apache.commons.lang.StringUtils;
9   
10  
11  /**
12   * An abstract Mojo for app server management.
13   *
14   * @author Chad Brandon
15   */
16  public abstract class AppManagementMojo
17      extends AbstractMojo
18  {
19      /**
20       * The location (i.e. path) to deploy.
21       *
22       * @parameter
23       * @required
24       */
25      protected File deployLocation;
26  
27      /**
28       * @parameter expression="${project}"
29       * @required
30       * @readonly
31       */
32      protected MavenProject project;
33  
34      /**
35       * Attempts to retrieve the packaging of the current project, and if it can't
36       * find it, throws an exception.
37       *
38       * @return the packaging.
39       * @throws MojoExecutionException if no packaging was found.
40       */
41      protected String getPackaging() throws MojoExecutionException
42      {
43          final String packaging = this.project.getPackaging();
44          if (StringUtils.isBlank(packaging))
45          {
46              throw new MojoExecutionException(
47                  "This project must have the packaging defined, when attempting to deploy exploded");
48          }
49          return packaging;
50      }
51  
52      /**
53       * Retrieves the file that will be or is deployed.
54       *
55       * @return the deploy file.
56       * @throws MojoExecutionException
57       */
58      protected File getDeployFile() throws MojoExecutionException
59      {
60          return new File(this.deployLocation, this.project.getBuild().getFinalName() + '.' + this.getPackaging());
61      }
62  }