Coverage Report - com.aurea.maven.plugins.sonic.sdm.VelocityGeneratorMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
VelocityGeneratorMojo
0%
0/23
0%
0/2
6
 
 1  
 package com.aurea.maven.plugins.sonic.sdm;
 2  
 
 3  
 import java.io.File;
 4  
 import java.util.List;
 5  
 
 6  
 import org.apache.maven.plugin.MojoExecutionException;
 7  
 import org.apache.maven.plugin.MojoFailureException;
 8  
 
 9  
 import com.aurea.maven.plugins.sonic.sdm.util.ESBDeploymentModel;
 10  
 import com.aurea.maven.plugins.sonic.sdm.util.ESBDeploymentModelBuilder;
 11  
 import com.aurea.maven.plugins.util.VelocityRunner;
 12  
 
 13  
 /**
 14  
  * This Mojo is a first go of the abstraction we want to achieve in the next iteration of 
 15  
  * the plugin. It relies on Velocity and it's templating languge to generate the content 
 16  
  * of various files needed for deploament. This could be done with the Model.xml, the topology 
 17  
  * files and the new AI feature that's required for customers like BA and Disney. 
 18  
  * 
 19  
  * @goal velocity-generate-model
 20  
  */
 21  
 
 22  0
 public class VelocityGeneratorMojo extends AbstractSdmMojo {
 23  
 
 24  
   /**
 25  
    * @parameter @required
 26  
    */
 27  
   private List<String> templateFiles;
 28  
 
 29  
   /**
 30  
    * @parameter 
 31  
    */
 32  
   private String propFileName;
 33  
   
 34  
   /**
 35  
    * @parameter @default-value="ai" @required
 36  
    */
 37  0
   private String aiOutputDirName = "ai";
 38  
   
 39  
   
 40  
 /* ------------- */ 
 41  
   
 42  
   /**
 43  
    * This method is called from the framework to actually perform the work.
 44  
    * 
 45  
    * @throws MojoExecutionException
 46  
    *           MojoExecutionException
 47  
    * @throws MojoFailureException
 48  
    *           MojoFailureException
 49  
    */
 50  
   protected void doExecute() throws MojoExecutionException, MojoFailureException {
 51  
 
 52  0
     ESBDeploymentModelBuilder builder = new ESBDeploymentModelBuilder(project, getLog());
 53  0
     ESBDeploymentModel model = null;
 54  
     
 55  
     try {
 56  0
       model = builder.getModel();
 57  0
     } catch (Exception e) {
 58  0
       throw new MojoExecutionException("Error building Deployment Model", e);
 59  0
     }
 60  
 
 61  0
     getLog().info("Executing Velocity ....");
 62  
     
 63  0
     VelocityRunner runner = VelocityRunner.getInstance(project);
 64  0
     runner.setOutputDirectory(aiOutputDirName);
 65  0
     runner.addProperty("env", System.getenv());
 66  0
     runner.addProperty("system", System.getProperties());
 67  0
     runner.addProperties("user", propFileName);
 68  0
     runner.addProperty("model", model);
 69  
     
 70  0
     for(String tplFile: templateFiles) {
 71  0
       getLog().debug("Generating Template: " + tplFile);
 72  
       try {
 73  0
         runner.run(tplFile, new File(tplFile).getName());
 74  0
       } catch (Exception e) {
 75  0
         throw new MojoExecutionException("Template generation failed.", e);
 76  0
       }
 77  0
     }
 78  
 
 79  0
   }
 80  
 
 81  
 }