mirror of https://github.com/apache/maven.git
don't throw a runtime exception
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219862 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6e87ae8941
commit
cfb51d7036
|
@ -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 <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
||||
* @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 );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue