Coverage Report - ch.elca.el4j.maven.plugins.eclipsecs.EclipseCsConfigMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
EclipseCsConfigMojo
0 %
0/21
0 %
0/6
7
 
 1  
 /*
 2  
  * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
 3  
  * the spring framework, http://el4j.sf.net
 4  
  * Copyright (C) 2006 by ELCA Informatique SA, Av. de la Harpe 22-24,
 5  
  * 1000 Lausanne, Switzerland, http://www.elca.ch
 6  
  *
 7  
  * EL4J is published under the GNU Lesser General Public License (LGPL)
 8  
  * Version 2.1. See http://www.gnu.org/licenses/
 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 Lesser General Public License for more details.
 14  
  *
 15  
  * For alternative licensing, please contact info@elca.ch
 16  
  */
 17  
 package ch.elca.el4j.maven.plugins.eclipsecs;
 18  
 
 19  
 import java.io.File;
 20  
 import java.io.FileWriter;
 21  
 import java.io.IOException;
 22  
 import java.io.InputStreamReader;
 23  
 import java.io.Reader;
 24  
 import java.io.Writer;
 25  
 
 26  
 import org.apache.maven.plugin.AbstractMojo;
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.apache.maven.plugin.MojoFailureException;
 29  
 import org.apache.maven.project.MavenProject;
 30  
 import org.apache.velocity.VelocityContext;
 31  
 import org.apache.velocity.app.Velocity;
 32  
 import org.codehaus.plexus.util.IOUtil;
 33  
 import org.springframework.util.StringUtils;
 34  
 
 35  
 /**
 36  
  * Mojo to create .checkstyle file.
 37  
  *
 38  
  * @svnLink $Revision: 3872 $;$Date: 2009-08-04 13:41:09 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/maven/plugins/maven-checkclipse-helper-plugin/src/main/java/ch/elca/el4j/maven/plugins/eclipsecs/EclipseCsConfigMojo.java $
 39  
  *
 40  
  * @author Stefan Wismer (SWI)
 41  
  * @author Martin Zeltner (MZE)
 42  
  *
 43  
  * @goal eclipse-cs-config
 44  
  * @requiresProject true
 45  
  */
 46  0
 public class EclipseCsConfigMojo extends AbstractMojo {
 47  
         // Checkstyle: MemberName off
 48  
         
 49  
         /**
 50  
          * Path to checkstyle file.
 51  
          *
 52  
          * @parameter expression="${checkstyle.checkstyleFilePath}"
 53  
          * @required
 54  
          */
 55  
         protected File checkstyleFile;
 56  
         
 57  
         /**
 58  
          * Path to eclipse-cs config file.
 59  
          *
 60  
          * @parameter expression="${checkstyle.configFilePath}"
 61  
          *            default-value=".checkstyle"
 62  
          * @required
 63  
          */
 64  
         protected File configFilePath;
 65  
         
 66  
         /**
 67  
          * Flag to enable eclipse-cs.
 68  
          *
 69  
          * @parameter expression="${checkstyle.enableEclipseCs}"
 70  
          *            default-value="true"
 71  
          * @required
 72  
          */
 73  
         protected boolean enableEclipseCs;
 74  
         
 75  
         /**
 76  
          * The maven project.
 77  
          *
 78  
          * @parameter expression="${project}"
 79  
          * @required
 80  
          * @readonly
 81  
          */
 82  
         protected MavenProject project;
 83  
         
 84  
         // Checkstyle: MemberName on
 85  
         
 86  
         /**
 87  
          * {@inheritDoc}
 88  
          */
 89  
         public void execute() throws MojoExecutionException, MojoFailureException {
 90  0
                 String projectPackaging = project.getPackaging();
 91  0
                 if (!StringUtils.hasText(projectPackaging)
 92  
                         || projectPackaging.contains("pom")) {
 93  0
                         getLog().info("No eclipse-cs config for pom project.");
 94  0
                         return;
 95  
                 }
 96  
                 
 97  0
                 if (configFilePath.isDirectory()) {
 98  0
                         throw new MojoExecutionException("Given file path "
 99  
                                 + configFilePath.getAbsolutePath()
 100  
                                 + " is a directory!");
 101  
                 }
 102  0
                 getLog().info("Writing file " + configFilePath.getAbsolutePath());
 103  
                 
 104  0
                 VelocityContext context = new VelocityContext();
 105  
                 
 106  0
                 context.put("name", project.getName());
 107  0
                 context.put("enabled", Boolean.toString(enableEclipseCs));
 108  0
                 context.put("location", checkstyleFile.getPath());
 109  
                 
 110  
                 try {
 111  0
                         Writer out = new FileWriter(configFilePath);
 112  0
                         Reader template = new InputStreamReader(getClass().getResourceAsStream("/etc/velocity/eclipse-cs.vm"));
 113  0
                         Velocity.evaluate(context, out, "elcaservice", template);
 114  0
                         IOUtil.close(template);
 115  0
                         IOUtil.close(out);
 116  0
                 } catch (IOException e) {
 117  0
                         getLog().error(e);
 118  0
                 }
 119  
 
 120  0
         }
 121  
 }