Stats Gradle Plugin

November 30, 2017 ยท View on GitHub

:linkattrs: :project-name: stats-gradle-plugin :plugin-version: 0.2.2

image:http://img.shields.io/travis/aalmiray/{project-name}/master.svg["Build Status", link="https://travis-ci.org/aalmiray/{project-name}"] image:http://img.shields.io/coveralls/aalmiray/{project-name}/master.svg["Coverage Status", link="https://coveralls.io/r/aalmiray/{project-name}"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"] image:https://api.bintray.com/packages/aalmiray/kordamp/{project-name}/images/download.svg[link="https://bintray.com/aalmiray/kordamp/{project-name}/_latestVersion"] image:https://img.shields.io/badge/donations-Patreon-orange.svg[link="https://www.patreon.com/user?u=6609318"]

== Stats Gradle Plugin

A Gradle plugin for counting lines of code in the same fashion as the http://grails.org[Grails] stats command.

== Requirements

  • Gradle 2.x and JDK7.

== Usage

The plugin is available from https://bintray.com[Bintray's JCenter]. The latest release is {plugin-version}. You can use it as follows

[source,groovy] [subs="attributes"]

buildscript { repositories { jcenter() } dependencies { classpath 'org.kordamp.gradle:{project-name}:{plugin-version}' } }

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

[source]

$ 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

[source, groovy]

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

[source]

$ 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

[source,groovy]

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

[source,groovy]

+----------------------+-------+-------+
| 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

[source,groovy]

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