View Javadoc
1   package org.andromda.maven.plugin.andromdapp;
2   
3   import java.net.URL;
4   import org.andromda.andromdapp.AndroMDApp;
5   import org.andromda.core.common.ResourceUtils;
6   import org.apache.maven.plugin.MojoExecutionException;
7   
8   /**
9    * AndroMDA application generator Mojo.
10   *
11   * @author Chad Brandon
12   * @goal generate
13   * @requiresProject false
14   * @requiresDependencyResolution
15   */
16  public class AndroMDAppMojo
17      extends AbstractAndroMDAppMojo
18  {
19      /**
20       * An AndroMDApp configuration that contains some internal configuration information (like the AndroMDA
21       * version, etc).
22       */
23      private static final String INTERNAL_CONFIGURATION_URI = "META-INF/andromdapp/configuration.xml";
24  
25      /**
26       * @see org.apache.maven.plugin.Mojo#execute()
27       */
28      public void execute()
29          throws MojoExecutionException
30      {
31          if (this.skipProcessing)
32          {
33              getLog().info("andromdapp:generate skipProcessing");
34              return;
35          }
36          try
37          {
38              AndroMDApp andromdapp = new AndroMDApp();
39              final URL internalConfiguration = ResourceUtils.getResource(INTERNAL_CONFIGURATION_URI);
40              if (internalConfiguration == null)
41              {
42                  throw new MojoExecutionException("No configuration could be loaded from --> '" +
43                      INTERNAL_CONFIGURATION_URI + '\'');
44              }
45              andromdapp.addConfigurationUri(internalConfiguration.toString());
46              final String configuration = this.getConfigurationContents();
47              if (configuration != null)
48              {
49                  andromdapp.addConfiguration(this.getConfigurationContents());
50              }
51              andromdapp.run();
52          }
53          catch (final Throwable throwable)
54          {
55              if (throwable instanceof MojoExecutionException)
56              {
57                  throw (MojoExecutionException)throwable;
58              }
59              throw new MojoExecutionException("An error occurred while attempting to generate an application", throwable);
60          }
61      }
62  }