Skip to content

Commit 703710e

Browse files
authored
Update to sbt 1.7 and refactor Checkstyle usage (#4)
* Update sbt to 1.7.1 * Update plugin code to sbt 1.0 style * Disable scala 3 syntax * Fix warnings * Fix loading config from classpath * Update test files * wip run directly * Fix scripted tests * Finish switching to calling Checkstyle directly * Remove option from checkstyleSeverityLevel * Remove option from checkstyleXsltTransformations * Tidy remaining settings * Remove debug * Add release plugin * Switch to scapegoat * Add Java 17 to test versions * Update contributing/contributors * Update README
1 parent a0c1f95 commit 703710e

File tree

37 files changed

+339
-451
lines changed

37 files changed

+339
-451
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
java: [8, 11]
15+
java: [8, 11, 17]
1616
steps:
1717
- uses: actions/checkout@v2
1818
- uses: coursier/cache-action@v6
@@ -21,4 +21,4 @@ jobs:
2121
java-version: ${{matrix.java}}
2222
distribution: temurin
2323
- name: Run tests
24-
run: sbt test scripted scalastyle scalafmtCheckAll
24+
run: sbt test scripted scapegoat scalafmtCheckAll

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ target
22
project/target
33
.idea
44
*.iml
5+
.bsp

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
version = 3.5.9
2-
runner.dialect = scala212
2+
runner.dialect = scala212source3
33

44
maxColumn = 120
55

CONTRIBUTING.md

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
1-
# Contribute
2-
These are the basic steps for contributing to sbt-checkstyle-plugin:
3-
4-
1. Fork from [the master branch](https://github.com/etsy/sbt-checkstyle-plugin)
5-
2. Make your changes
6-
3. Document new functionality as appropriate
7-
4. Add new tests if possible
8-
5. Run the test suite with `sbt test scripted`
9-
6. Push your changes to your fork.
10-
7. Send a pull request!
11-
12-
Every pull request will be built with [Travis CI](https://travis-ci.org/etsy/sbt-checkstyle-plugin). The CI build runs both unit tests and Scalastyle.
13-
14-
# Contributors
15-
- Andrew Johnson [ajsquared](https://github.com/ajsquared)
16-
- Hans L'hoëst [lhohan](https://github.com/lhohan)
17-
- sentolacco [sentolacco](https://github.com/sentolacco)
18-
- Joseph Earl [JosephEarl](https://github.com/JosephEarl)
19-
- Alejandro Rivera [AlejandroRivera](https://github.com/AlejandroRivera)
20-
- Michael Stringer [stringbean](https://github.com/stringbean)
1+
# Contributing
2+
3+
When you find a bug in sbt-checkstyle-plugin we want to hear about it. Your bug reports play an important part in making
4+
this plugin more reliable and usable.
5+
6+
Effective bug reports are more likely to be fixed. These guidelines explain how to write such reports and pull requests.
7+
8+
## Before Reporting an Issue
9+
10+
- Make sure that you are running the latest version of SBT (1.x) and the jacoco4sbt plugin.
11+
- Check the open [issues](https://github.com/stringbean/sbt-checkstyle-plugin/issues) and
12+
[pull requests](https://github.com/stringbean/sbt-checkstyle-plugin/pulls) for anything similar. If there is already
13+
an open issue and you have additional information please add it (comments such as +1 aren't helpful).
14+
15+
## How to Report an Issue
16+
17+
It is important when opening a new issue to include as much information as possible including:
18+
19+
- How to reproduce the issue:
20+
- What SBT tasks did you run before `checkstyle`?
21+
- Does it always happen?
22+
- Details of your environment:
23+
- Version of sbt.
24+
- Version of the sbt-checkstyle-plugin plugin.
25+
- Version of Checkstyle.
26+
- A link to a repo containing your project _or_
27+
- A link to a Gist/Pastebin with a test case reproducing the issue.
28+
29+
## How to Submit a Pull Request
30+
31+
We welcome code contributions to sbt-checkstyle-plugin. To make it easier for us to include your contributions please
32+
ensure the following before creating a pull request:
33+
34+
- Your branch is up-to-date with `main`.
35+
- All unit tests and scripted tests pass.
36+
37+
When opening a pull request please including any relevant information - such as _"fixes issue #x"_ or _"adds new
38+
feature y"_.

CONTRIBUTORS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Contributors
2+
3+
- Andrew Johnson [ajsquared](https://github.com/ajsquared)
4+
- Hans L'hoëst [lhohan](https://github.com/lhohan)
5+
- sentolacco [sentolacco](https://github.com/sentolacco)
6+
- Joseph Earl [JosephEarl](https://github.com/JosephEarl)
7+
- Alejandro Rivera [AlejandroRivera](https://github.com/AlejandroRivera)
8+
- Michael Stringer [stringbean](https://github.com/stringbean)

README.md

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# sbt-checkstyle-plugin
22

3+
[![Build Status](https://img.shields.io/github/workflow/status/stringbean/sbt-checkstyle-plugin/ci)](https://github.com/stringbean/sbt-checkstyle-plugin/actions/workflows/ci.yml)
4+
[![Known Vulnerabilities](https://snyk.io/test/github/stringbean/sbt-checkstyle-plugin/badge.svg?targetFile=build.sbt)](https://snyk.io/test/github/stringbean/sbt-checkstyle-plugin?targetFile=build.sbt)
5+
![Maven Central](https://maven-badges.herokuapp.com/maven-central/software.purpledragon/sbt-checkstyle-plugin/badge.svg?style=flat)
6+
![Checkstyle 3.9](https://img.shields.io/badge/Default_Checkstyle-3.9-yellowgreen)
7+
38
This project provides an sbt plugin for running Checkstyle over Java source files. For more information about
49
Checkstyle, see [checkstyle.sourceforge.io](http://checkstyle.sourceforge.io).
510

6-
This plugin uses version 6.15 of Checkstyle by default.
7-
811
This project was forked from [etsy/sbt-checkstyle-plugin](https://github.com/etsy/sbt-checkstyle-plugin) in 2022
912
after it became unmaintained. Some initial code was based on an
1013
[earlier plugin](https://github.com/corux/sbt-code-quality) (dead link).
@@ -17,20 +20,20 @@ Add the following lines to `project/plugins.sbt`:
1720
addSbtPlugin("software.purpledragon" % "sbt-checkstyle-plugin" % "<version>")
1821
```
1922

20-
sbt-checkstyle-plugin is an AutoPlugin, so there is no need to modify the `build.sbt` file to enable it.
23+
Checkstyle will be enabled by default for projects.
2124

2225
## Usage
2326

2427
You can run Checkstyle over your Java source files with the `checkstyle` task. You can run Checkstyle over your Java
25-
tests with the `test:checkstyle` task.
28+
tests with the `Test / checkstyle` task.
2629

27-
The Checkstyle configuration file is `./checkstyle-config.xml` by default. This can be changed by setting the value of
28-
`checkstyleConfigLocation`. By default `test:checkstyle` uses the same configuration file, but this can be changed by
29-
setting the value of `checkstyleConfigLocation in Test`.
30+
The Checkstyle configuration file is `checkstyle-config.xml` by default. This can be changed by setting the value of
31+
`checkstyleConfigLocation`. By default `Test / checkstyle` uses the same configuration file, but this can be changed
32+
by setting the value of `Test / checkstyleConfigLocation`.
3033

3134
The Checkstyle report is output to `target/checkstyle-report.xml` by default. This can be changed by setting the value
32-
of `checkstyleOutputFile`. `test:checkstyle` outputs to `target/checkstyle-test-report.xml`, but this can be changed by
33-
setting the value of `checkstyleOutputFile in Test`.
35+
of `checkstyleOutputFile`. `Test / checkstyle` outputs to `target/checkstyle-test-report.xml`, but this can be changed
36+
by setting the value of `Test / checkstyleOutputFile`.
3437

3538
To change the checkstyle configuration file set `checkstyleConfigLocation` in `build.sbt`:
3639
```scala
@@ -50,36 +53,36 @@ checkstyleConfigLocation := CheckstyleConfigLocation.Classpath("com/etsy/checkst
5053

5154
To run Checkstyle automatically after compilation:
5255
```scala
53-
(checkstyle in Compile) := (checkstyle in Compile).triggeredBy(compile in Compile).value
56+
(Compile / checkstyle) := (Compile / checkstyle).triggeredBy(Compile / compile).value
5457
```
5558

5659
To run Checkstyle automatically after test compilation:
5760
```scala
58-
(checkstyle in Test) := (checkstyle in Test).triggeredBy(compile in Test).value
61+
(Test / checkstyle) := (Test / checkstyle).triggeredBy(Test / compile).value
5962
```
6063

6164
### XSLT transformations
6265

6366
The `checkstyleXsltTransformations` setting allows applying XSLT transformations to the XML report generated by
6467
Checkstyle. For instance, this could be used to generate a more readable HTML report. This setting takes values of
65-
`Option[Set[XSLTSettings]]`, so multiple transformations can be applied.
68+
`Set[XSLTSettings]`, so multiple transformations can be applied.
6669

6770
You can set `checkstyleXsltTransformations` like so in `build.sbt`:
6871
```scala
69-
checkstyleXsltTransformations := {
70-
Some(Set(CheckstyleXSLTSettings(baseDirectory(_ / "checkstyle-noframes.xml").value, target(_ / "checkstyle-report.html").value)))
71-
}
72+
checkstyleXsltTransformations +=
73+
CheckstyleXSLTSettings(baseDirectory.value / "checkstyle-noframes.xml", target.value / "checkstyle-report.html")
7274
```
7375

7476
### Failing the build
7577

7678
You can control what severity of issues should break the build by setting the `checkstyleSeverityLevel` in your
7779
`build.sbt` as follows:
80+
7881
```scala
79-
checkstyleSeverityLevel := Some(CheckstyleSeverityLevel.Error)
82+
checkstyleSeverityLevel := CheckstyleSeverityLevel.Error
8083
```
8184

82-
Possible values are defined by the `CheckstyleSeverityLevel` enumeration. The default is `None`.
85+
Possible values are defined by the `CheckstyleSeverityLevel` enumeration. The default is `Ignore`.
8386

8487
### Integration tests
8588

@@ -89,12 +92,12 @@ lazy val root = (project in file(".")).configs(IntegrationTest)
8992

9093
Defaults.itSettings
9194

92-
checkstyleConfigLocation := CheckstyleConfigLocation.File("my-checkstyle-config.xml"),
93-
checkstyle in IntegrationTest := checkstyleTask(IntegrationTest).value,
94-
checkstyleOutputFile in IntegrationTest := target.value / "checkstyle-integration-test-report.xml"
95+
checkstyleConfigLocation := CheckstyleConfigLocation.File("my-checkstyle-config.xml")
96+
IntegrationTest / checkstyle := checkstyleTask(IntegrationTest).value
97+
IntegrationTest / checkstyleOutputFile := target.value / "checkstyle-integration-test-report.xml"
9598
```
9699

97-
You can then run the tasks `it:checkstyle` and `it:checkstyle-check`.
100+
You can then run the tasks `IntegrationTest / checkstyle` and `IntegrationTest / checkstyle-check`.
98101

99102
### Upgrading Checkstyle version
100103

@@ -104,27 +107,31 @@ Provided the new Checkstyle version is compatible, you can override the version
104107
`project/plugins.sbt`:
105108

106109
```scala
107-
dependencyOverrides += "com.puppycrawl.tools" % "checkstyle" % "6.15"
110+
dependencyOverrides += "com.puppycrawl.tools" % "checkstyle" % "10.3"
108111
```
109112

110113
## Settings
111114

112115
### `checkstyleOutputFile`
113-
* *Description:* The location of the generated checkstyle report.
114-
* *Accepts:* any legal file path
115-
* *Default:* `Some(target.value / "checkstyle-report.xml")`
116+
117+
- **Description:** The location of the generated checkstyle report.
118+
- **Accepts:** `File`
119+
- **Default:** `target.value / "checkstyle-report.xml"`
116120

117121
### `checkstyleConfigLocation`
118-
* *Description:* The location of the checkstyle configuration file.
119-
* *Accepts:* `CheckstyleConfigLocation.{File, URL, Classpath}`
120-
* *Default:* `CheckstyleConfigLocation.File("checkstyle-config.xml")`
122+
123+
- **Description:** The location of the checkstyle configuration file.
124+
- **Accepts:** `CheckstyleConfigLocation` (`.File`, `.URL`, `.Classpath`)
125+
- **Default:** `CheckstyleConfigLocation.File("checkstyle-config.xml")`
121126

122127
### `checkstyleXsltTransformations`
123-
* *Description:* A set of XSLT transformations to be applied to the checkstyle output (optional).
124-
* *Accepts:* `Some(Set[CheckstyleXSLTSettings])`
125-
* *Default:* `None`
128+
129+
- **Description:** A set of XSLT transformations to be applied to the checkstyle output.
130+
- **Accepts:** `Set[CheckstyleXSLTSettings]`
131+
- **Default:** `Set.empty`
126132

127133
### `checkstyleSeverityLevel`
128-
* *Description:* Decide how much effort to put into analysis.
129-
* *Accepts:* `Some(CheckstyleSeverityLevel.{Ignore, Info, Warning, Error})`
130-
* *Default:* `None`
134+
135+
- **Description:** Decide how much effort to put into analysis.
136+
- **Accepts:** `CheckstyleSeverityLevel` (`Ignore`, `Info`, `Warning`, `Error`)
137+
- **Default:** `CheckstyleSeverityLevel.Ignore`

build.sbt

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
name := "sbt-checkstyle-plugin"
22
organization := "software.purpledragon"
33

4-
version := "3.3.1-SNAPSHOT"
5-
6-
sbtPlugin := true
4+
enablePlugins(SbtPlugin)
75

86
libraryDependencies ++= Seq(
9-
"com.puppycrawl.tools" % "checkstyle" % "9.3",
10-
"com.github.sbt" % "junit-interface" % "0.13.3" % Test,
11-
"junit" % "junit" % "4.13.2" % Test,
12-
"com.github.stefanbirkner" % "system-rules" % "1.19.0" % Test
7+
"com.puppycrawl.tools" % "checkstyle" % "9.3"
138
)
149

1510
licenses += ("MIT", url("https://opensource.org/licenses/MIT"))
1611

17-
publishTo := sonatypePublishToBundle.value
18-
1912
developers := List(
2013
Developer(
2114
"stringbean",
@@ -33,5 +26,37 @@ scmInfo := Some(
3326
)
3427
)
3528

36-
scalastyleConfig := file("scalastyle.xml")
37-
scalastyleFailOnError := true
29+
ThisBuild / scapegoatVersion := "1.4.15"
30+
31+
scriptedLaunchOpts := {
32+
scriptedLaunchOpts.value ++
33+
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
34+
}
35+
36+
scalacOptions := Seq(
37+
"-deprecation",
38+
"-feature",
39+
"-unchecked",
40+
"-Xlint:unused"
41+
)
42+
43+
publishTo := sonatypePublishToBundle.value
44+
45+
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._
46+
47+
releaseProcess := Seq[ReleaseStep](
48+
checkSnapshotDependencies,
49+
inquireVersions,
50+
runClean,
51+
runTest,
52+
releaseStepInputTask(scripted),
53+
releaseStepTask(scapegoat),
54+
setReleaseVersion,
55+
commitReleaseVersion,
56+
tagRelease,
57+
publishArtifacts,
58+
releaseStepCommand("sonatypeBundleRelease"),
59+
setNextVersion,
60+
commitNextVersion,
61+
pushChanges
62+
)

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.1.0
1+
sbt.version=1.7.1

project/plugins.sbt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// publishing
22
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1")
33
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
4+
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
45

56
// code style
6-
addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % "1.0.0")
7-
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
7+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
8+
addSbtPlugin("com.sksamuel.scapegoat" %% "sbt-scapegoat" % "1.1.1")

project/scripted.sbt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)