Coverage Report - org.boretti.drools.integration.drools4.DroolsClassProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
DroolsClassProcessor
0 %
0/22
0 %
0/4
4.5
 
 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.FileInputStream;
 23  
 import java.io.FileNotFoundException;
 24  
 import java.io.FileOutputStream;
 25  
 import java.io.IOException;
 26  
 
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.apache.maven.plugin.logging.Log;
 29  
 import org.objectweb.asm.ClassReader;
 30  
 import org.objectweb.asm.ClassWriter;
 31  
 
 32  
 /**
 33  
  * @author mbo
 34  
  * @since 1.1.0
 35  
  *
 36  
  */
 37  
 class DroolsClassProcessor {
 38  0
         private DroolsClassProcessor() {}
 39  
         
 40  
         public static void ClassProcessor(Log logger,File src)
 41  
         throws MojoExecutionException {
 42  0
                 if (src==null) return;
 43  
                 try {
 44  0
                         FileInputStream fis = new FileInputStream(src);
 45  0
                         ClassReader cr = new ClassReader(fis);
 46  0
                         ClassWriter cw = new ClassWriter(cr,0); // 0 ???
 47  0
                         DroolsClassVisitor dcv = new DroolsClassVisitor(logger,cw);
 48  0
                         cr.accept(dcv, 0); // 0 ???
 49  0
                         byte clazz[] = cw.toByteArray();
 50  0
                         fis.close();
 51  0
                         if (dcv.isNeedChange()) {
 52  0
                                 logger.info("File "+src+" must be rewritten.");
 53  0
                                 fis.close();
 54  0
                                 FileOutputStream fos = new FileOutputStream(src);
 55  0
                                 fos.write(clazz);
 56  
                         }
 57  0
                 } catch (FileNotFoundException e) {
 58  0
                         logger.error(""+e.getMessage(),e);
 59  0
                         throw new MojoExecutionException(""+e.getMessage(),e);
 60  0
                 } catch (IOException e) {
 61  0
                         logger.error(""+e.getMessage(),e);
 62  0
                         throw new MojoExecutionException(""+e.getMessage(),e);
 63  0
                 }
 64  0
         }
 65  
 }