{"id":13665240,"url":"https://github.com/orrsella/sbt-stats","last_synced_at":"2025-04-30T14:31:33.433Z","repository":{"id":6438796,"uuid":"7677700","full_name":"orrsella/sbt-stats","owner":"orrsella","description":"An sbt plugin for source code statistics","archived":false,"fork":false,"pushed_at":"2019-05-23T18:30:14.000Z","size":46,"stargazers_count":80,"open_issues_count":6,"forks_count":9,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-08-03T06:01:54.054Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orrsella.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-18T01:01:22.000Z","updated_at":"2024-06-13T07:43:40.000Z","dependencies_parsed_at":"2022-08-26T04:01:24.047Z","dependency_job_id":null,"html_url":"https://github.com/orrsella/sbt-stats","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orrsella%2Fsbt-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orrsella%2Fsbt-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orrsella%2Fsbt-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orrsella%2Fsbt-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orrsella","download_url":"https://codeload.github.com/orrsella/sbt-stats/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224031926,"owners_count":17244361,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T06:00:30.531Z","updated_at":"2024-11-11T00:30:34.726Z","avatar_url":"https://github.com/orrsella.png","language":"Scala","funding_links":[],"categories":["Analysis","SOURCE"],"sub_categories":[],"readme":"# sbt-stats\n\nAn [sbt](http://www.scala-sbt.org/) (Simple Build Tool) plugin that easily provides source code statistics and analytics in the sbt console. It's purpose is to provide a Bird's-eye View of your project in terms of raw numbers and percentages. Can provide statistics for an entire multi-project build, or on a per-project basis. See [this post](http://orrsella.com/2013/01/20/introducing-sbt-stats-an-sbt-plugin-for-source-code-statistics/) for some more background.\n\n## Add Plugin\n\nTo add sbt-stats functionality to your project add the following to your `project/plugins.sbt` file:\n\n```scala\naddSbtPlugin(\"com.orrsella\" % \"sbt-stats\" % \"1.0.7\")\n```\n\nIf you want to use it for more than one project, you can add it to your global plugins file, usually found at: `~/.sbt/plugins/plugins.sbt` and then have it available for all sbt projects. See [Using Plugins](http://www.scala-sbt.org/release/docs/Getting-Started/Using-Plugins.html) for additional information on sbt plugins.\n\n### Troubleshooting\n\nIf you added the plugin globally but still don't have the `stats` command available, try:\n\n```\n$ sbt\n\u003e reload plugins\n\u003e clean\n\u003e reload return\n```\n\nEssentially, this enters the `project` project, cleans it, and returns back to your main project (remember that [sbt is recursive](http://www.scala-sbt.org/release/docs/Getting-Started/Full-Def.html#sbt-is-recursive) – each `project/` folder is an sbt project in itself!).\n\n### Requirements\n\n* sbt 1.0+, Scala 2.12.x\n* sbt 0.13.5+ (requires `AutoPlugin`), Scala 2.10.x\n\n\n## Usage\n\nTo use sbt-stats, simply enter the `stats` command in the sbt console. It will provide basic statistics about the source files in your single-project build, or all projects aggregated if you have a multi-project setup. Here's an example for the [akka](https://github.com/akka/akka) project:\n\n```\nakka \u003e stats\n[info] Code Statistics for project:\n[info]\n[info] Files\n[info] - Total:      267 files\n[info] - Scala:      214 files (80.1%)\n[info] - Java:       53 files (19.9%)\n[info] - Total size: 2,101,408 Bytes\n[info] - Avg size:   164,258 Bytes\n[info] - Avg length: 4,545 lines\n[info]\n[info] Lines\n[info] - Total:      57,443 lines\n[info] - Code:       34,388 lines (59.9%)\n[info] - Comment:    15,864 lines (27.6%)\n[info] - Blank:      7,191 lines (12.5%)\n[info] - Bracket:    5,760 lines (10.0%)\n[info]\n[info] Characters\n[info] - Total:      1,821,830 chars\n[info] - Code:       1,272,314 chars (69.8%)\n[info] - Comment:    549,516 chars (30.2%)\n```\n\nThe default output provides File, Line and Character statistics (the analysis can be [easily extended](https://github.com/orrsella/sbt-stats#extending) with custom logic). These stats are aggregated across all 30 projects in the akka build.\n\nTo get statistics for a single project, select it using `project PROJECT_NAME` and run `stats-project`. This will only run the task on the selected project, and won't aggregate any subprojects. For example:\n\n```\nakka \u003e project akka-actor\n[info] Set current project to akka-actor (in build file:/Users/orr/Development/Scala/Projects/akka/)\nakka-actor \u003e stats-project\n[info]\n[info] Code Statistics for project 'akka-actor':\n[info]\n[info] Files\n[info] - Total:      91 files\n[info] - Scala:      78 files (85.7%)\n[info] - Java:       13 files (14.3%)\n[info] - Total size: 765,238 Bytes\n[info] - Avg size:   8,409 Bytes\n[info] - Avg length: 229 lines\n[info]\n[info] Lines\n[info] - Total:      20,894 lines\n[info] - Code:       10,161 lines (48.6%)\n[info] - Comment:    8,078 lines (38.7%)\n[info] - Blank:      2,655 lines (12.7%)\n[info] - Bracket:    1,583 lines (7.6%)\n[info]\n[info] Characters\n[info] - Total:      680,139 chars\n[info] - Code:       405,894 chars (59.7%)\n[info] - Comment:    274,245 chars (40.3%)\n```\n\n### Output\n\nHere is how line types are defined for the `Lines` output:\n\n* Code – any line that's not a comment or a blank line\n* Comment – any line starting with `//`, `/*` or `*`\n  * In-line comments (```val x = 5 // my comment```) are *not* counted as comment lines.\n  * Multi-line comment blocks (`/* ... \\n ... \\n ... */`) of `n` lines are counted as *only* 1 comment line and n-1 code lines (if you want more advanced comment parsing you can [easily extend](https://github.com/orrsella/sbt-stats#extending) an `Analyzer` yourself).\n* Blank – any empty line or spaces-only\n* Bracket – a line consisting of *only* an opening *or* closing curly brace\n* Since bracket lines are obviously code: code % + comment % + blank % = 100%\n\n## Configuration\n\nThe plugin uses `Analyzer` classes to produce it's statistics. The default analyzers include `FilesAnalyzer`, `LinesAnalyzer` and `CharsAnalyzer` which are automatically used (their output displayed above). You can manually configure which analyzers will be used by setting the `statsAnalyzers` sbt [setting](http://www.scala-sbt.org/release/docs/Getting-Started/Basic-Def.html). For example, add the following to your `build.sbt` file to only use the FilesAnalyzer:\n\n```scala\nimport com.orrsella.sbtstats._\n\nstatsAnalyzers := Seq(new FilesAnalyzer())\n```\n\nThe default analyzers intentionally have simple and basic implementations, calculating all their stats by simple string reads and comparisons. No reflection or advanced analysis methods are used. If you want more advanced output, see the next section.\n\n## Extending\n\nIf you're interested in more statistics (like counting the number of classes, traits, objects, methods, etc.) or implementing the existing analyzers differently, you can easily do it. For example, to create a new `MyAnalyzer` place the following code in the `project` directory (for example in `project/MyAnalyzer.scala`):\n\n```scala\nimport com.orrsella.sbtstats._\nimport java.io.File\n\nclass MyAnalyzer extends Analyzer {\n  // sources: source files as retrieved from sbt's `sources` setting\n  // packageBin: the output jar file as retrieved from sbt's `packageBin` task\n  def analyze(sources: Seq[File], packageBin: File) = {\n    val metric1 = sources.filter(_.getName.endsWith(\"foo\")).length // completely useless metric 1\n    val metric2 = packageBin.length^2                              // completely useless metric 2\n    ...\n    new MyAnalyzerResult(metric1, metric2, ...)\n  }\n}\n\n// result object for MyAnalyzer\nclass MyAnalyzerResult(metric1: Int, metric2: Double, ...) extends AnalyzerResult {\n  val title = \"My Analysis\"\n  val metrics =\n    Seq(\n      new AnalyzerMetric(\"Metric 1:\", metric1, \"files\"),\n      new AnalyzerMetric(\"Metric 2:\", metric2, 3500, \"Bytes\"))\n}\n```\n\nAs you can see, all that you need to do is override the `analyze(sources: Seq[File], packageBin: File)` method of the [Analyzer](https://github.com/orrsella/sbt-stats/blob/master/src/main/scala/com/orrsella/sbtstats/Analyzer.scala) class and use the `sources` sequence (of source files) *and/or* `packageBin` file (the output jar) to calculate the metrics you're interested in. The `AnalyzerResult` object is also pretty straight-forward – the `title` is the string that'll be displayed at the top of the analyzer block in the sbt console, and the `AnalyzerMetric` objects are the body of the block. Each [metric](https://github.com/orrsella/sbt-stats/blob/master/src/main/scala/com/orrsella/sbtstats/AnalyzerMetric.scala) has a mandatory `title` and `value`. Optional are `total` (used to calculate percentage) and `units` for that metric.\n\nNow to tell sbt-stats to use your new analyzer, add it as explained in [configuration](https://github.com/orrsella/sbt-stats#configuration). To add the new analyzer *in addition* to the default analyzers, add the following to `build.sbt`:\n\n```scala\nimport com.orrsella.sbtstats._\n\nstatsAnalyzers += new MyAnalyzer()\n```\n\nTo have the new analyzer the sole analyzer, without using the default analyzers, add:\n\n```scala\nstatsAnalyzers := Seq(new MyAnalyzer())\n```\n\nFinally, here's what the output of the new `MyAnalyzer` will look like in the sbt console:\n\n```\n[info] ...\n[info]\n[info] My Analysis\n[info] - Metric 1: 5 files\n[info] - Metric 2: 100 Bytes (60.0%)\n```\n\nFor a full Analyzer class you can see [FilesAnalyzer](https://github.com/orrsella/sbt-stats/blob/master/src/main/scala/com/orrsella/sbtstats/FilesAnalyzer.scala) for example.\n\n## Feedback\n\nAny comments/suggestions? Let me know what you think – I'd love to hear from you. Send pull requests, issues or contact me: [@orrsella](http://twitter.com/orrsella) and [orrsella.com](http://orrsella.com)\n\n## License\n\nThis software is licensed under the Apache 2 license, quoted below.\n\nCopyright (c) 2013 Orr Sella\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forrsella%2Fsbt-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forrsella%2Fsbt-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forrsella%2Fsbt-stats/lists"}