All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.modello.maven.ModelloGenerateMojo Maven / Gradle / Ivy

The newest version!
package org.codehaus.modello.maven;

/*
 * Copyright (c) 2007, Codehaus.org
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

import java.util.Map;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.modello.plugin.ModelloGenerator;

/**
 * 

* A dynamic way to use generators and Modello plugins. *

* *

* Example Usage: *

*
 *   <plugin>
 *     <groupId>org.codehaus.modello</groupId>
 *     <artifactId>modello-maven-plugin</artifactId>
 *     <version>1.3</version>
 *     <dependencies>
 *       <dependency>
 *         <groupId>org.codehaus.modello</groupId>
 *         <artifactId>modello-plugin-jpa</artifactId>
 *         <version>1.0.0-SNAPSHOT</version>
 *       </dependency>
 *     </dependencies>
 *     <configuration>
 *       <version>1.0.0</version>
 *       <packageWithVersion>false</packageWithVersion>
 *       <models>
 *         <model>src/main/mdo/project-model.xml</model>
 *       </models>
 *     </configuration>
 *     <executions>
 *       <execution>
 *         <id>java</id>
 *         <goals>
 *           <goal>generate</goal>
 *         </goals>
 *         <configuration>
 *           <generatorId>java</generatorId>
 *         </configuration>
 *       </execution>
 *       <execution>
 *         <id>jpa</id>
 *         <goals>
 *           <goal>generate</goal>
 *         </goals>
 *         <configuration>
 *           <generatorId>jpa-mapping</generatorId>
 *         </configuration>
 *       </execution>
 *     </executions>
 *   </plugin>
 * 
* * @author Joakim Erdfelt */ @Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true) public class ModelloGenerateMojo extends AbstractModelloSourceGeneratorMojo { @Component(role = ModelloGenerator.class) private Map generatorMap; @Parameter(property = "modello.generator.id", defaultValue = "java") private String generatorId; protected String getGeneratorType() { return generatorId; } public void execute() throws MojoExecutionException { if (!generatorMap.containsKey(generatorId)) { throw new MojoExecutionException("Unable to execute modello, generator id [" + generatorId + "] not found. (Available generator ids : " + generatorMap.keySet() + ")"); } getLog().info("[modello:generate {generator: " + generatorId + "}]"); super.execute(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy