Coverage Report - org.boretti.drools.integration.drools4.DroolsCopyAndValidateTest
 
Classes in this File Line Coverage Branch Coverage Complexity
DroolsCopyAndValidateTest
0 %
0/33
0 %
0/10
2.286
 
 1  
 /*
 2  
     Drools4 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.drools4;
 20  
 
 21  
 import java.io.File;
 22  
 import java.io.IOException;
 23  
 
 24  
 import org.apache.maven.execution.MavenSession;
 25  
 import org.apache.maven.plugin.AbstractMojo;
 26  
 import org.apache.maven.plugin.MojoExecutionException;
 27  
 import org.apache.maven.plugin.MojoFailureException;
 28  
 import org.apache.maven.project.MavenProject;
 29  
 import org.apache.maven.shared.filtering.MavenResourcesFiltering;
 30  
 import org.codehaus.plexus.util.DirectoryScanner;
 31  
 
 32  
 
 33  
 /**
 34  
  * This goal copy drools file and validate them for test
 35  
  * @author mbo
 36  
  * @goal drools-copy-validate-test
 37  
  * @phase test-compile
 38  
  * @requiresDependencyResolution test
 39  
  */
 40  0
 public class DroolsCopyAndValidateTest extends AbstractMojo {
 41  
 
 42  
         @Override
 43  
         public void execute() throws MojoExecutionException, MojoFailureException {
 44  0
                 if (getLog().isDebugEnabled()) getLog().debug("starting drools copy and validation");
 45  0
                 DirectoryScanner scanner = new DirectoryScanner();
 46  0
                 if (!getInputDirectory().exists()) {
 47  0
                         getLog().warn("Skipping not existing directory "+getInputDirectory());
 48  0
                         return;
 49  
                 }
 50  0
                 scanner.setBasedir(getInputDirectory());
 51  0
                 scanner.setIncludes(new String[] { "**/*"+getExtension(),"*"+getExtension() });
 52  0
                 scanner.scan();
 53  0
                 boolean ok=true;
 54  0
                 getOutputDirectory().mkdirs();
 55  0
                 for (String file : scanner.getIncludedFiles()) {
 56  0
                         File sfile = new File(getInputDirectory(), file);
 57  0
                         File dfile = new File(getOutputDirectory(),file);
 58  0
                         dfile.getParentFile().mkdirs();
 59  0
                         if (!DroolsHelper.validateSourceFile(getLog(), project, sfile)) ok=false;
 60  
                         try {
 61  0
                                 FileHelper.copyFile(sfile, dfile);
 62  0
                         } catch (IOException e) {
 63  0
                                 getLog().error("Unable to copy file :"+e.getMessage(),e);
 64  0
                                 throw new MojoExecutionException("Unable to coyp file :"+e.getMessage(),e);
 65  0
                         }
 66  
                 }
 67  0
                 if (!ok) {
 68  0
                         throw new MojoExecutionException("Validation error of the drools");
 69  
                 }
 70  0
         }
 71  
 
 72  
         /**
 73  
          * @parameter expression="${session}"
 74  
          * 
 75  
          * @readonly
 76  
          * @required
 77  
          */
 78  
         protected MavenSession session;
 79  
         
 80  
         /**
 81  
      * @parameter expression="${project}"
 82  
      * @required
 83  
      * @readonly
 84  
      */
 85  
     protected MavenProject project;
 86  
     
 87  
     /**
 88  
      * The output directory into which to copy the rules.
 89  
      *
 90  
      * @parameter expression="${project.basedir}/target/test-classes"
 91  
      * @required
 92  
      */
 93  
     private File outputDirectory;
 94  
     
 95  
     /**
 96  
      * The input directory from where to copy the rules.
 97  
      * 
 98  
      * @parameter expression="${project.basedir}/src/test/drools"
 99  
      * @required
 100  
      */
 101  
     private File inputDirectory;
 102  
     
 103  
     /**
 104  
      * The default extension for drools file
 105  
      * 
 106  
      * @parameter expression=".drl"
 107  
      * @required
 108  
      */
 109  
     private String extension;
 110  
     
 111  
     /**
 112  
      * 
 113  
      * @component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" role-hint="default"
 114  
      * @required
 115  
      */    
 116  
     protected MavenResourcesFiltering mavenResourcesFiltering;
 117  
 
 118  
         public File getOutputDirectory() {
 119  0
                 return outputDirectory;
 120  
         }
 121  
 
 122  
         public void setOutputDirectory(File outputDirectory) {
 123  0
                 this.outputDirectory = outputDirectory;
 124  0
         }
 125  
 
 126  
         public File getInputDirectory() {
 127  0
                 return inputDirectory;
 128  
         }
 129  
 
 130  
         public void setInputDirectory(File inputDirectory) {
 131  0
                 this.inputDirectory = inputDirectory;
 132  0
         }
 133  
 
 134  
         public String getExtension() {
 135  0
                 return extension;
 136  
         }
 137  
 
 138  
         public void setExtension(String extension) {
 139  0
                 this.extension = extension;
 140  0
         } 
 141  
 
 142  
 }