001: package org.andromda.maven.plugin;
002:
003: import java.io.File;
004: import java.net.URL;
005:
006: import org.andromda.core.AndroMDA;
007: import org.andromda.core.common.ResourceUtils;
008: import org.andromda.core.configuration.Configuration;
009: import org.andromda.core.configuration.Model;
010: import org.andromda.core.configuration.Repository;
011: import org.apache.maven.plugin.MojoExecutionException;
012:
013: /**
014: * A Maven2 plugin to run AndroMDA.
015: *
016: * @author Chad Brandon
017: * @goal run
018: * @phase generate-sources
019: * @requiresDependencyResolution runtime
020: */
021: public class AndroMDAMojo extends AbstractAndroMDAMojo {
022: /**
023: * Whether or not a last modified check should be performed before running AndroMDA again.
024: *
025: * @parameter expression="${lastModifiedCheck}"
026: */
027: private boolean lastModifiedCheck = false;
028:
029: /**
030: * Whether or not processing should be skipped (this is if you just want to force AndroMDA
031: * not to run on your model).
032: *
033: * @parameter expression="${andromda.run.skip}"
034: */
035: private boolean skipProcessing = false;
036:
037: /**
038: * The directory to which the build source is located (any generated source).
039: *
040: * @parameter expression="${project.build.directory}/src/main/java"
041: */
042: private String buildSourceDirectory;
043:
044: /**
045: * @see org.andromda.maven.plugin.AbstractAndroMDAMojo#execute(org.andromda.core.configuration.Configuration)
046: */
047: public void execute(final Configuration configuration)
048: throws MojoExecutionException {
049: if (!this .skipProcessing) {
050: boolean execute = true;
051: if (this .lastModifiedCheck) {
052: final URL configurationUri = ResourceUtils
053: .toURL(this .configurationUri);
054: final File directory = new File(
055: this .buildSourceDirectory);
056: execute = ResourceUtils.modifiedAfter(ResourceUtils
057: .getLastModifiedTime(configurationUri),
058: directory);
059: if (!execute) {
060: final Repository[] repositories = configuration
061: .getRepositories();
062: int repositoryCount = repositories.length;
063: for (int ctr = 0; ctr < repositoryCount; ctr++) {
064: final Repository repository = repositories[ctr];
065: if (repository != null) {
066: final Model[] models = repository
067: .getModels();
068: final int modelCount = models.length;
069: for (int ctr2 = 0; ctr2 < modelCount; ctr2++) {
070: final Model model = models[ctr2];
071: execute = ResourceUtils.modifiedAfter(
072: model.getLastModified(),
073: directory);
074: if (execute) {
075: break;
076: }
077: }
078: }
079: }
080: }
081: }
082: if (execute) {
083: final AndroMDA andromda = AndroMDA.newInstance();
084: andromda.run(configuration);
085: andromda.shutdown();
086: } else {
087: this
088: .getLog()
089: .info(
090: "Files are up-to-date, skipping AndroMDA execution");
091: }
092: }
093: final File buildSourceDirectory = this .buildSourceDirectory != null ? new File(
094: this.buildSourceDirectory)
095: : null;
096: if (buildSourceDirectory != null) {
097: this.getProject().addCompileSourceRoot(
098: buildSourceDirectory.toString());
099: }
100: }
101: }
|