001package org.andromda.maven.plugin.andromdapp;
002
003import java.net.URL;
004import org.andromda.andromdapp.AndroMDApp;
005import org.andromda.core.common.ResourceUtils;
006import org.apache.maven.plugin.MojoExecutionException;
007
008/**
009 * AndroMDA application generator Mojo.
010 *
011 * @author Chad Brandon
012 * @goal generate
013 * @requiresProject false
014 * @requiresDependencyResolution
015 */
016public class AndroMDAppMojo
017    extends AbstractAndroMDAppMojo
018{
019    /**
020     * An AndroMDApp configuration that contains some internal configuration information (like the AndroMDA
021     * version, etc).
022     */
023    private static final String INTERNAL_CONFIGURATION_URI = "META-INF/andromdapp/configuration.xml";
024
025    /**
026     * @see org.apache.maven.plugin.Mojo#execute()
027     */
028    public void execute()
029        throws MojoExecutionException
030    {
031        if (this.skipProcessing)
032        {
033            getLog().info("andromdapp:generate skipProcessing");
034            return;
035        }
036        try
037        {
038            AndroMDApp andromdapp = new AndroMDApp();
039            final URL internalConfiguration = ResourceUtils.getResource(INTERNAL_CONFIGURATION_URI);
040            if (internalConfiguration == null)
041            {
042                throw new MojoExecutionException("No configuration could be loaded from --> '" +
043                    INTERNAL_CONFIGURATION_URI + '\'');
044            }
045            andromdapp.addConfigurationUri(internalConfiguration.toString());
046            final String configuration = this.getConfigurationContents();
047            if (configuration != null)
048            {
049                andromdapp.addConfiguration(this.getConfigurationContents());
050            }
051            andromdapp.run();
052        }
053        catch (final Throwable throwable)
054        {
055            if (throwable instanceof MojoExecutionException)
056            {
057                throw (MojoExecutionException)throwable;
058            }
059            throw new MojoExecutionException("An error occurred while attempting to generate an application", throwable);
060        }
061    }
062}