Coverage Report - org.boretti.drools.integration.drools5.DroolsCompile
 
Classes in this File Line Coverage Branch Coverage Complexity
DroolsCompile
0 %
0/47
0 %
0/16
2
 
 1  
 /*
 2  
     Drools5 Integration Helper
 3  
     Copyright (C) 2009  Mathieu Boretti mathieu.boretti@gmail.com
 4  
 
 5  
     This program is free software: you can redistribute it and/or modify
 6  
     it under the terms of the GNU General Public License as published by
 7  
     the Free Software Foundation, either version 3 of the License, or
 8  
     (at your option) any later version.
 9  
 
 10  
     This program is distributed in the hope that it will be useful,
 11  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
     GNU General Public License for more details.
 14  
 
 15  
     You should have received a copy of the GNU General Public License
 16  
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 17  
 
 18  
  */
 19  
 package org.boretti.drools.integration.drools5;
 20  
 
 21  
 import java.io.File;
 22  
 
 23  
 import org.apache.maven.execution.MavenSession;
 24  
 import org.apache.maven.plugin.AbstractMojo;
 25  
 import org.apache.maven.plugin.MojoExecutionException;
 26  
 import org.apache.maven.plugin.MojoFailureException;
 27  
 import org.apache.maven.project.MavenProject;
 28  
 import org.apache.maven.shared.filtering.MavenResourcesFiltering;
 29  
 import org.codehaus.plexus.util.DirectoryScanner;
 30  
 
 31  
 
 32  
 /**
 33  
  * This goal compile drools
 34  
  * @author mbo
 35  
  * @goal drools-compile
 36  
  * @phase compile
 37  
  * @requiresDependencyResolution runtime
 38  
  */
 39  0
 public class DroolsCompile extends AbstractMojo {
 40  
 
 41  
         @Override
 42  
         public void execute() throws MojoExecutionException, MojoFailureException {
 43  0
                 if (getLog().isDebugEnabled()) getLog().debug("starting drools compilation");
 44  0
                 DirectoryScanner scanner = new DirectoryScanner();
 45  0
                 if (!getInputDirectory().exists()) {
 46  0
                         getLog().warn("Skipping not existing directory "+getInputDirectory());
 47  0
                         return;
 48  
                 }
 49  0
                 scanner.setBasedir(getInputDirectory());
 50  0
                 scanner.setIncludes(new String[] { "**/*"+getExtension(),"*"+getExtension() });
 51  0
                 scanner.scan();
 52  0
                 boolean ok=true;
 53  0
                 getOutputDirectory().mkdirs();
 54  0
                 for (String file : scanner.getIncludedFiles()) {
 55  0
                         File sfile = new File(getInputDirectory(), file);
 56  0
                         File dfile = new File(getOutputDirectory(),file.replaceFirst(getExtension()+"$", getCompiledExtension()));
 57  0
                         dfile.getParentFile().mkdirs();
 58  0
                         if (!DroolsHelper.compileSourceFile(getLog(), project, sfile,dfile,false)) ok=false;
 59  
                 }
 60  0
                 scanner = new DirectoryScanner();
 61  0
                 if (!getInputDirectory().exists()) {
 62  0
                         getLog().warn("Skipping not existing directory "+getInputDirectory());
 63  0
                         return;
 64  
                 }
 65  0
                 scanner.setBasedir(getInputDirectory());
 66  0
                 scanner.setIncludes(new String[] { "**/*"+getXmlExtension(),"*"+getXmlExtension() });
 67  0
                 scanner.scan();
 68  0
                 getOutputDirectory().mkdirs();
 69  0
                 for (String file : scanner.getIncludedFiles()) {
 70  0
                         File sfile = new File(getInputDirectory(), file);
 71  0
                         File dfile = new File(getOutputDirectory(),file.replaceFirst(getXmlExtension()+"$", getCompiledExtension()));
 72  0
                         dfile.getParentFile().mkdirs();
 73  0
                         if (!DroolsHelper.compileSourceFile(getLog(), project, sfile,dfile,true)) ok=false;
 74  
                 }
 75  0
                 if (!ok) {
 76  0
                         throw new MojoExecutionException("Validation error of the drools");
 77  
                 }
 78  0
         }
 79  
 
 80  
         /**
 81  
          * @parameter expression="${session}"
 82  
          * 
 83  
          * @readonly
 84  
          * @required
 85  
          */
 86  
         protected MavenSession session;
 87  
         
 88  
         /**
 89  
      * @parameter expression="${project}"
 90  
      * @required
 91  
      * @readonly
 92  
      */
 93  
     protected MavenProject project;
 94  
     
 95  
     /**
 96  
      * The output directory into which to copy the rules.
 97  
      *
 98  
      * @parameter expression="${project.basedir}/target/classes"
 99  
      * @required
 100  
      */
 101  
     private File outputDirectory;
 102  
     
 103  
     /**
 104  
      * The input directory from where to copy the rules.
 105  
      * 
 106  
      * @parameter expression="${project.basedir}/src/main/drools"
 107  
      * @required
 108  
      */
 109  
     private File inputDirectory;
 110  
     
 111  
     /**
 112  
      * The default extension for drools file
 113  
      * 
 114  
      * @parameter expression=".drl"
 115  
      * @required
 116  
      */
 117  
     private String extension;
 118  
     
 119  
     /**
 120  
      * The default extension for xml drools file
 121  
      * 
 122  
      * @parameter expression=".xml"
 123  
      * @required
 124  
      */
 125  
     private String xmlExtension;
 126  
     
 127  
     /**
 128  
      * The default extension for compiled drools file
 129  
      * 
 130  
      * @parameter expression=".cdrl"
 131  
      * @required
 132  
      */
 133  
     private String compiledExtension;
 134  
     
 135  
     /**
 136  
      * 
 137  
      * @component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" role-hint="default"
 138  
      * @required
 139  
      */    
 140  
     protected MavenResourcesFiltering mavenResourcesFiltering;
 141  
 
 142  
         public File getOutputDirectory() {
 143  0
                 return outputDirectory;
 144  
         }
 145  
 
 146  
         public void setOutputDirectory(File outputDirectory) {
 147  0
                 this.outputDirectory = outputDirectory;
 148  0
         }
 149  
 
 150  
         public File getInputDirectory() {
 151  0
                 return inputDirectory;
 152  
         }
 153  
 
 154  
         public void setInputDirectory(File inputDirectory) {
 155  0
                 this.inputDirectory = inputDirectory;
 156  0
         }
 157  
 
 158  
         public String getExtension() {
 159  0
                 return extension;
 160  
         }
 161  
 
 162  
         public void setExtension(String extension) {
 163  0
                 this.extension = extension;
 164  0
         }
 165  
 
 166  
         public String getCompiledExtension() {
 167  0
                 return compiledExtension;
 168  
         }
 169  
 
 170  
         public void setCompiledExtension(String compiledExtension) {
 171  0
                 this.compiledExtension = compiledExtension;
 172  0
         }
 173  
 
 174  
         /**
 175  
          * @return the xmlExtension
 176  
          */
 177  
         public String getXmlExtension() {
 178  0
                 return xmlExtension;
 179  
         }
 180  
 
 181  
         /**
 182  
          * @param xmlExtension the xmlExtension to set
 183  
          */
 184  
         public void setXmlExtension(String xmlExtension) {
 185  0
                 this.xmlExtension = xmlExtension;
 186  0
         } 
 187  
 
 188  
 }