Package org.andromda.maven.plugin

Source Code of org.andromda.maven.plugin.AndroMDAMojo

package org.andromda.maven.plugin;

import java.io.File;
import java.net.URL;

import org.andromda.core.AndroMDA;
import org.andromda.core.common.ResourceUtils;
import org.andromda.core.configuration.Configuration;
import org.andromda.core.configuration.Model;
import org.andromda.core.configuration.Repository;
import org.apache.maven.plugin.MojoExecutionException;


/**
* A Maven2 plugin to run AndroMDA.
*
* @author Chad Brandon
* @goal run
* @phase generate-sources
* @requiresDependencyResolution runtime
*/
public class AndroMDAMojo
    extends AbstractAndroMDAMojo
{
    /**
     * Whether or not a last modified check should be performed before running AndroMDA again.
     *
     * @parameter expression="${lastModifiedCheck}"
     */
    private boolean lastModifiedCheck = false;
   
    /**
     * Whether or not processing should be skipped (this is if you just want to force AndroMDA
     * not to run on your model).
     *
     * @parameter expression="${andromda.run.skip}"
     */
    private boolean skipProcessing = false;

    /**
     * The directory to which the build source is located (any generated source).
     *
     * @parameter expression="${project.build.directory}/src/main/java"
     */
    private String buildSourceDirectory;

    /**
     * @see org.andromda.maven.plugin.AbstractAndroMDAMojo#execute(org.andromda.core.configuration.Configuration)
     */
    public void execute(final Configuration configuration)
        throws MojoExecutionException
    {
        if (!this.skipProcessing)
        {
            boolean execute = true;
            if (this.lastModifiedCheck)
            {
                final URL configurationUri = ResourceUtils.toURL(this.configurationUri);
                final File directory = new File(this.buildSourceDirectory);
                execute = ResourceUtils.modifiedAfter(
                        ResourceUtils.getLastModifiedTime(configurationUri),
                        directory);
                if (!execute)
                {
                    final Repository[] repositories = configuration.getRepositories();
                    int repositoryCount = repositories.length;
                    for (int ctr = 0; ctr < repositoryCount; ctr++)
                    {
                        final Repository repository = repositories[ctr];
                        if (repository != null)
                        {
                            final Model[] models = repository.getModels();
                            final int modelCount = models.length;
                            for (int ctr2 = 0; ctr2 < modelCount; ctr2++)
                            {
                                final Model model = models[ctr2];
                                execute = ResourceUtils.modifiedAfter(
                                        model.getLastModified(),
                                        directory);
                                if (execute)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            if (execute)
            {
                final AndroMDA andromda = AndroMDA.newInstance();
                andromda.run(configuration);
                andromda.shutdown();
            }
            else
            {
                this.getLog().info("Files are up-to-date, skipping AndroMDA execution");
            }
        }
        final File buildSourceDirectory =
            this.buildSourceDirectory != null ? new File(this.buildSourceDirectory) : null;
        if (buildSourceDirectory != null)
        {
            this.getProject().addCompileSourceRoot(buildSourceDirectory.toString());
        }
    }
}
TOP

Related Classes of org.andromda.maven.plugin.AndroMDAMojo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.