Running it all

You may have already asked yourself: How does all this fit together? Where is the central point where AndroMDA is started and configured? Why does it execute some particular workflow script?

The answer is quite easy: Let's have a look at samples/chain/pom.xml, the place where A4 is invoked on a test model called "chain":

    <plugin>
        <groupId>org.andromda.integration</groupId>
        <artifactId>andromda-runner-maven2</artifactId>
        <dependencies>
            <dependency>
                <groupId>org.andromda.metamodeling</groupId>
                <artifactId>andromda-metamodeling-metamodels-emf-uml2</artifactId>
                <version>4.0-M1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.andromda.metamodeling</groupId>
                <artifactId>andromda-metamodeling-metamodels-oop</artifactId>
                <version>4.0-M1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.andromda.cartridges</groupId>
                <artifactId>andromda-enterpriseapp-cartridge</artifactId>
                <version>4.0-M1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.andromda.cartridges</groupId>
                <artifactId>andromda-spring-cartridge</artifactId>
                <version>4.0-M1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.andromda.cartridges</groupId>
                <artifactId>andromda-java-cartridge</artifactId>
                <version>4.0-M1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.andromda.transformers</groupId>
                <artifactId>andromda-transformers-atl</artifactId>
                <version>4.0-M1-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>org.andromda.transformers</groupId>
                <artifactId>andromda-transformers-mofscript</artifactId>
                <version>4.0-M1-SNAPSHOT</version>
            </dependency>
        </dependencies>
        <executions>
            <execution>
                <goals>
                    <goal>run</goal>
                </goals>
                <configuration>
                    <configurationURL>
                      file:${basedir}/src/main/config/AndroMDAConfiguration.groovy
                    </configurationURL>
                    <workflowDefinitionURL>
                      file:${basedir}/src/main/config/CodeGenWorkflow.groovy
                    </workflowDefinitionURL>
                </configuration>
            </execution>
        </executions>
        <version>${pom.version}</version>
    </plugin>

What do you see here? A Maven plugin is invoked in this build script. The Maven plugin is called andromda-runner-maven2, from its name you can deduce that it starts AndroMDA. First of all, it lists all kinds of dependency tags to have the necessary metamodels, cartridges and transformer plugins on the classpath so that A4 will find their extensions when it starts up. Next, the execution tag tells AndroMDA what to do: the goal is to run AndroMDA with a configuration and a workflow. The configuration is found inside AndroMDAConfiguration.groovy:

  // define some output directories for the generated files (not serious, yet!)
  String coreGeneratedDir   = "$env.projectBuildDirectory/tmp/core/target/src"
  String coreManualDir      = "$env.projectBuildDirectory/tmp/core/src"
  String commonGeneratedDir = "$env.projectBuildDirectory/tmp/common/target/src"

  // define a new namespace for the Spring/Hibernate-Cartridge
  def spring = namespaces.createNamespace("SpringHibernate")

  // define the outlets of the SpringHibernate cartridge
  spring.daos                = coreGeneratedDir
  spring.daoImpls            = coreManualDir

  spring.springConfiguration = coreGeneratedDir

  spring.serviceInterfaces   = commonGeneratedDir
  spring.services            = coreGeneratedDir
  spring.serviceImpls        = coreManualDir

  spring.criteria            = commonGeneratedDir
  spring.valueObjects        = commonGeneratedDir

This Groovy script creates a set of namespace objects (actually, only one that is called "SpringHibernate"). It dynamically adds all kinds of properties to this namespace (the property names are not declared inside the Namespace class but Groovy calls a setProperty() method on the namespace). Groovy insiders call this an Expando object.

When the script has been executed, A4 converts the namespaces and properties to a configuration model (instance of a special custom metamodel called "Configuration").

Then, it starts CodeGenWorkflow.groovy because this has also been configured inside the execution tag in pom.xml above. This workflow has already been described in the workflow page.