Skip to content
This repository has been archived by the owner on Nov 8, 2020. It is now read-only.

aalmiray/stats-gradle-plugin

Repository files navigation

Stats Gradle Plugin

Build Status Coverage Status Apache License 2 download donations Patreon orange

Stats Gradle Plugin

A Gradle plugin for counting lines of code in the same fashion as the Grails stats command.

Requirements

  • Gradle 2.x and JDK7.

Usage

The plugin is available from Bintray’s JCenter. The latest release is 0.2.2. You can use it as follows

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.kordamp.gradle:stats-gradle-plugin:0.2.2'
    }
}

apply plugin: 'org.kordamp.gradle.stats'

The plugin adds a new task named stats. This task is responsible for computing lines of code. The default configuration is good enough to work with standard Java or Groovy projects without additional setup. Invoking this task in a plain Java project yields something like the following output

$ gradle stats
:stats

    +----------------------+-------+-------+
    | Name                 | Files |   LOC |
    +----------------------+-------+-------+
    | Java Sources         |     1 |     5 |
    +----------------------+-------+-------+
    | Totals               |     1 |     5 |
    +----------------------+-------+-------+

It’s possible to generate an aggregate report when multiple projects are configured. Simply add the following to the root project

task aggregateStatsReport(type: org.kordamp.gradle.stats.AggregateStatsReportTask) {}

You may define a value for the projects property (a collection of project names) if you want desire to limit the number of projects to be queried for stats. The default setting is to query all subprojects. Note that the stats task must have been called before the aggregate task, such as

$ gradle stats aggregateStatsReport

Configuration

The following properties can be configured for the stats task

formats

List of output formats. Valid values are xml, html and txt.

reportDir

Directory where output reports should be placed. default value is project.file("${project.buildDir}/reports/stats")

counters

a Map of additional org.kordamp.gradle.stats.Counter implementations, keyed by extension.

paths

Maps of additional source paths that contain sources to be counted.

The following configuration may be used in a Griffon project for example

stats {
    formats = ['xml', 'html', 'txt']
    paths = [
        model:      [name: 'Models',      path: 'griffon-app/models'],
        view:       [name: 'Views',       path: 'griffon-app/views'],
        controller: [name: 'Controllers', path: 'griffon-app/controllers'],
        service:    [name: 'Services',    path: 'griffon-app/services'],
        config:     [name: 'Config',      path: 'griffon-app/conf'],
        lifecycle:  [name: 'Lifecycle',   path: 'griffon-app/lifecycle']
    ]
}

Which may make the stats task output something similar to

    +----------------------+-------+-------+
    | Name                 | Files |   LOC |
    +----------------------+-------+-------+
    | Groovy Sources       |     4 |    28 |
    | Java Sources         |     1 |     2 |
    | Groovy Test Sources  |     1 |    16 |
    | Models               |     1 |     8 |
    | Views                |     1 |    24 |
    | Controllers          |     1 |    10 |
    | Config               |     1 |    12 |
    | Lifecycle            |     1 |    16 |
    +----------------------+-------+-------+
    | Totals               |    11 |   116 |
    +----------------------+-------+-------+

You may restrict a path to match an specific file type, such as java or any other supported file extension, for example

stats {
    formats = ['xml', 'html', 'txt']
    paths = [
        foo: [name: 'Foos', path: 'src/foo', extension: 'foo']
    ]
}

Supported Extensions

  • java

  • groovy

  • scala

  • kt (Kotlin)

  • js

  • css

  • scss (SASS)

  • xml

  • html

  • fxml (JavaFX FXML)

  • properties

  • sql

  • yaml

Supported Paths

All project SourceSets will be queried when calculating stats, however the following paths have special treatment for reporting their names:

  • src/test

  • src/integration-test

  • src/functional-test

About

A Gradle plugin for counting lines of code in the same fashion as the griffon stats command.

Resources

License

Stars

Watchers

Forks

Packages

No packages published