diff --git a/maven-plugins/maven-clover/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java b/maven-plugins/maven-clover/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java index 4ab448c870..0879c14939 100644 --- a/maven-plugins/maven-clover/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java +++ b/maven-plugins/maven-clover/maven-clover-plugin/src/main/java/org/apache/maven/plugin/clover/CloverCheckMojo.java @@ -1,5 +1,7 @@ +package org.apache.maven.plugin.clover; + /* - * Copyright 2005 The Apache Software Foundation. + * Copyright 2001-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,32 +15,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.maven.plugin.clover; - -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.tools.ant.Project; -import org.apache.tools.ant.taskdefs.Taskdef; import com.cenqua.clover.cfg.Percentage; import com.cenqua.clover.tasks.CloverPassTask; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.Taskdef; /** - * @goal check - * @phase verify - * @execute phase="test" lifecycle="clover" - * @description Verify test percentage coverage and fail the build if it is below the defined threshold + * Verify test percentage coverage and fail the build if it is below the defined threshold. * * @author Vincent Massol * @version $Id$ + * @goal check + * @phase verify + * @execute phase="test" lifecycle="clover" + * * */ -public class CloverCheckMojo extends AbstractCloverMojo +public class CloverCheckMojo + extends AbstractCloverMojo { /** * @parameter expression="${project.build.directory}/clover/clover.db" * @required */ - protected String cloverDatabase; + protected String cloverDatabase; /** * @parameter expression="70" @@ -46,31 +48,41 @@ public class CloverCheckMojo extends AbstractCloverMojo */ protected float targetPercentage; - public void execute() throws MojoExecutionException + public void execute() + throws MojoExecutionException { registerLicenseFile(); checkCoverage(); } - private void registerCloverAntTasks(Project antProject) + private void registerCloverAntTasks( Project antProject ) { - Taskdef taskdef = (Taskdef) antProject.createTask("taskdef"); - taskdef.setResource("clovertasks"); + Taskdef taskdef = (Taskdef) antProject.createTask( "taskdef" ); + taskdef.setResource( "clovertasks" ); taskdef.execute(); } - + private void checkCoverage() + throws MojoExecutionException { Project antProject = new Project(); antProject.init(); - - registerCloverAntTasks(antProject); - CloverPassTask cloverPassTask = (CloverPassTask) antProject.createTask("clover-check"); - cloverPassTask.setInitString(this.cloverDatabase); - cloverPassTask.setHaltOnFailure(true); - cloverPassTask.setTarget(new Percentage(this.targetPercentage)); - cloverPassTask.execute(); + registerCloverAntTasks( antProject ); + + CloverPassTask cloverPassTask = (CloverPassTask) antProject.createTask( "clover-check" ); + cloverPassTask.setInitString( this.cloverDatabase ); + cloverPassTask.setHaltOnFailure( true ); + cloverPassTask.setTarget( new Percentage( this.targetPercentage ) ); + try + { + cloverPassTask.execute(); + } + catch ( BuildException e ) + { + // TODO: change to a failure, hopefully get a decent Java API out of them so we can get a better exception + throw new MojoExecutionException( e.getMessage(), e ); + } } }