Coverage Report - com.aurea.maven.plugins.sonic.sdm.AbstractSdmMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSdmMojo
0%
0/21
0%
0/4
2.167
 
 1  
 package com.aurea.maven.plugins.sonic.sdm;
 2  
 
 3  
 import java.io.File;
 4  
 import java.util.Properties;
 5  
 
 6  
 import org.apache.maven.plugin.MojoExecutionException;
 7  
 import org.codehaus.plexus.util.xml.XmlStreamReader;
 8  
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 9  
 import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
 10  
 
 11  
 import com.aurea.maven.plugins.sonic.AbstractSonicMojo;
 12  
 
 13  0
 public abstract class AbstractSdmMojo extends AbstractSonicMojo {
 14  
 
 15  
   /**
 16  
    * @return location of the SDM directory
 17  
    */
 18  
   protected File getTargetSDMDir() {
 19  
   
 20  0
     return new File(getOutputDirectory(), "sonicesb/sdm");
 21  
   }
 22  
 
 23  
   /**
 24  
    * @return the generated tailoring properties file
 25  
    */
 26  
   protected File getGeneratedPropertiesFile() {
 27  
   
 28  0
     return new File(getTargetSDMDir(), "/generated.tailoring.properties");
 29  
   }
 30  
   
 31  
   /**
 32  
    * @return the generated Topology file
 33  
    */
 34  
   protected File getGeneratedTopologyFile() {
 35  
   
 36  0
     return new File(getTargetSDMDir(), "/generated.Topology.xml");
 37  
   }
 38  
 
 39  
   /**
 40  
    * @return the generated Topology file
 41  
    */
 42  
   protected File getMasterTopologyFile() {
 43  
   
 44  0
     return new File(getTargetSDMDir(), "/Topology.xml");
 45  
   }
 46  
   
 47  
 
 48  
   protected Properties buildPropertiesFromTopology(File topoFile) throws MojoExecutionException {
 49  
     try {
 50  0
       Properties generated = new Properties();
 51  0
       XmlStreamReader topoReader = new XmlStreamReader(topoFile);
 52  0
       Xpp3Dom topology = Xpp3DomBuilder.build(topoReader);
 53  
 
 54  0
       Xpp3Dom parameters = topology.getChild("Parameters");
 55  0
       for (Xpp3Dom parameter : parameters.getChildren()) {
 56  0
             String id = getChildElementValue(parameter, "Id");
 57  0
         String value = getChildElementValue(parameter, "Value");
 58  
         
 59  0
                 getLog().debug("Adding Property: " + id + " -- " + value);
 60  0
         generated.put(id, value);
 61  
       }
 62  0
       return generated;
 63  
       
 64  0
     } catch (Exception e) {
 65  0
       throw new MojoExecutionException("Exception while reading topology file: " + topoFile.getName(), e);
 66  
     }
 67  
   }
 68  
   
 69  
   protected String getChildElementValue(Xpp3Dom parent, String name) {
 70  0
           Xpp3Dom childElement = parent.getChild(name);
 71  0
           if(childElement != null)
 72  0
                   return childElement.getValue();
 73  
           
 74  0
           throw new IllegalArgumentException("Child element " + name + " does not exist in element " + parent.getName());
 75  
   }
 76  
 
 77  
 }