All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javaposse.jobdsl.dsl.helpers.publisher.CoberturaContext.groovy Maven / Gradle / Ivy

There is a newer version: 1.22-rxd-2
Show newest version
package javaposse.jobdsl.dsl.helpers.publisher

import com.google.common.base.Preconditions
import groovy.transform.PackageScope
import javaposse.jobdsl.dsl.helpers.Context

class CoberturaContext implements Context {

    boolean onlyStable = false
    boolean failUnhealthy = false
    boolean failUnstable = false
    boolean autoUpdateHealth = false
    boolean autoUpdateStability = false
    boolean zoomCoverageChart = false
    boolean failNoReports = true

    enum TargetType {
        METHOD, LINE, CONDITIONAL, PACKAGES, FILES, CLASSES
    }
    def targets = [
        "METHOD": new CoberturaTarget(
            targetType: TargetType.METHOD,
            healthyTarget: 8000000,
            unhealthyTarget: 0,
            failingTarget: 0
        ),
        'LINE': new CoberturaTarget(
            targetType: TargetType.LINE,
            healthyTarget: 8000000,
            unhealthyTarget: 0,
            failingTarget: 0
        ),
        'CONDITIONAL': new CoberturaTarget(
            targetType: TargetType.CONDITIONAL,
            healthyTarget: 7000000,
            unhealthyTarget: 0,
            failingTarget: 0
        )
    ]

    String sourceEncoding = 'ASCII'

    /**
     * 
     *  
     *   
     *    false
     *
     * @param onlyStable
     */
    void onlyStable(boolean onlyStable) {
        this.onlyStable = onlyStable
    }

    /**
     * 
     *  
     *   
     *    false
     *
     * @param failUnhealthy
     */
    void failUnhealthy(boolean failUnhealthy) {
        this.failUnhealthy = failUnhealthy
    }

    /**
     * 
     *  
     *   
     *    false
     *
     * @param failUnstable
     */
    void failUnstable(boolean failUnstable) {
        this.failUnstable = failUnstable
    }

    /**
     * 
     *  
     *   
     *    false
     *
     * @param autoUpdateHealth
     */
    void autoUpdateHealth(boolean autoUpdateHealth) {
        this.autoUpdateHealth = autoUpdateHealth
    }

    /**
     * 
     *  
     *   
     *    false
     *
     * @param autoUpdateStability
     */
    void autoUpdateStability(boolean autoUpdateStability) {
        this.autoUpdateStability = autoUpdateStability
    }

    /**
     * 
     *  
     *   
     *    false
     *
     * @param zoomCoverageChart
     */
    void zoomCoverageChart(boolean zoomCoverageChart) {
        this.zoomCoverageChart = zoomCoverageChart
    }

    /**
     * 
     *  
     *   
     *    true
     *
     * @param failNoReports
     */
    void failNoReports(boolean failNoReports) {
        this.failNoReports = failNoReports
    }

    /**
     * @see target('METHOD')
     *
     * @param healthy
     * @param unhealthy
     * @param failing
     */
    void methodTarget(Integer healthy = 8000000, Integer unhealthy = 0, Integer failing = 0) {
        this.target(TargetType.METHOD.name(), healthy, unhealthy, failing)
    }

    /**
     * @see target('LINE')
     *
     * @param healthy
     * @param unhealthy
     * @param failing
     */
    void lineTarget(Integer healthy = 8000000, Integer unhealthy = 0, Integer failing = 0) {
        this.target(TargetType.LINE.name(), healthy, unhealthy, failing)
    }

    /**
     * @see target('CONDITIONAL')
     *
     * @param healthy
     * @param unhealthy
     * @param failing
     */
    void conditionalTarget(Integer healthy = 8000000, Integer unhealthy = 0, Integer failing = 0) {
        this.target(TargetType.CONDITIONAL.name(), healthy, unhealthy, failing)
    }

    /**
     * @see target('FILES')
     *
     * @param healthy
     * @param unhealthy
     * @param failing
     */
    void fileTarget(Integer healthy = 8000000, Integer unhealthy = 0, Integer failing = 0) {
        this.target(TargetType.FILES.name(), healthy, unhealthy, failing)
    }

    /**
     * @see target('CLASSES')
     *
     * @param healthy
     * @param unhealthy
     * @param failing
     */
    void classTarget(Integer healthy = 8000000, Integer unhealthy = 0, Integer failing = 0) {
        this.target(TargetType.CLASSES.name(), healthy, unhealthy, failing)
    }

    /**
     * @see target('PACKAGES')
     *
     * @param healthy
     * @param unhealthy
     * @param failing
     */
    void packageTarget(Integer healthy = 8000000, Integer unhealthy = 0, Integer failing = 0) {
        this.target(TargetType.PACKAGES.name(), healthy, unhealthy, failing)
    }

    /**
     * 
     *  
     *   
     *    
     *     
     *     
     *      METHOD
     *        METHOD
     *      METHOD
     *      8000000
     *     
     *     
     *    
     *    
     *     
     *     
     *      METHOD
     *        LINE
     *      METHOD
     *      8000000
     *     
     *     
     *    
     *    
     *     
     *     
     *      METHOD
     *        CONDITIONAL
     *      METHOD
     *      7000000
     *     
     *     
     *    
     *
     * @param targetType
     * @param healthy
     * @param unhealthy
     * @param failing
     */
    @PackageScope
    void target(String targetType, Integer healthy = 8000000, Integer unhealthy = 0, Integer failing = 0) {
        Preconditions.checkArgument(
            TargetType.values().any { it.toString() == targetType }, "Invalid target type: $targetType " +
            'Available target types: ' + TargetType.values())
        Preconditions.checkArgument((0..100).contains(healthy), 'Invalid healthyTarget treshold, percentage (0-100) expected')
        Preconditions.checkArgument((0..100).contains(unhealthy), 'Invalid unhealthyTarget treshold, percentage (0-100) expected')
        Preconditions.checkArgument((0..100).contains(failing), 'Invalid failingTarget treshold, percentage (0-100) expected')
        this.targets.put(targetType, new CoberturaTarget(
            targetType: targetType,
            healthyTarget: healthy * 100000,
            unhealthyTarget: unhealthy * 100000,
            failingTarget: failing * 100000
        ))
    }

    /**
     * 
     *  
     *   
     *    UTF-8
     *
     * @param sourceEncoding
     */
    void sourceEncoding(String sourceEncoding) {
        Preconditions.checkNotNull(sourceEncoding, 'Source encoding must not be null!')
        this.sourceEncoding = sourceEncoding
    }

    static class CoberturaTarget {
        String targetType
        String healthyTarget
        String unhealthyTarget
        String failingTarget
    }
}






© 2015 - 2024 Weber Informatics LLC | Privacy Policy