28 |
29 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.lift.toml:
--------------------------------------------------------------------------------
1 | build = "mvn"
2 | jdkVersion = "11"
3 |
--------------------------------------------------------------------------------
/.mailmap:
--------------------------------------------------------------------------------
1 | dependabot[bot]
2 | dependabot[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
3 | dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
4 | dependabot[bot]
5 | John Freeman
6 |
--------------------------------------------------------------------------------
/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | --add-opens java.base/java.lang=ALL-UNNAMED
2 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 | wrapperVersion=3.3.2
18 | distributionType=only-script
19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 GantSign Ltd.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ktlint Maven Plugin
2 |
3 | [](https://github.com/gantsign/ktlint-maven-plugin/actions?query=workflow%3ABuild)
4 | [](https://maven-badges.herokuapp.com/maven-central/com.github.gantsign.maven/ktlint-maven-plugin)
5 | [](https://codecov.io/gh/gantsign/ktlint-maven-plugin)
6 | [](https://snyk.io/test/github/gantsign/ktlint-maven-plugin)
7 |
8 | This plugin provides the ability to use
9 | [ktlint](https://github.com/pinterest/ktlint) to format and check your source
10 | code against the ktlint anti-bikeshedding code style.
11 |
12 | ## Using Java 17 and later
13 |
14 | Java 17 is the first LTS release to enforce strong encapsulation. For `ktlint`
15 | to work we need to add `--add-opens java.base/java.lang=ALL-UNNAMED` to the JVM
16 | arguments.
17 |
18 | We recommend that you add a `.mvn/jvm.config` file (relative to the top level
19 | project directory) to all of your projects using this plugin. The file should
20 | have the following contents:
21 |
22 | ```
23 | --add-opens java.base/java.lang=ALL-UNNAMED
24 | ```
25 |
26 | We also recommend adding this to all of your projects using this plugin and
27 | building with Java 11, as it'll suppress an illegal-access warning during the
28 | build.
29 |
30 | For other options see:
31 | [https://maven.apache.org/configure.html](https://maven.apache.org/configure.html)
32 |
33 | ## Goals Overview
34 |
35 | * [ktlint:format](http://gantsign.com/ktlint-maven-plugin/format-mojo.html)
36 | format your Kotlin sources using ktlint.
37 |
38 | * [ktlint:check](http://gantsign.com/ktlint-maven-plugin/check-mojo.html)
39 | check your Kotlin sources for code style violations using ktlint.
40 |
41 | * [ktlint:ktlint](http://gantsign.com/ktlint-maven-plugin/ktlint-mojo.html)
42 | generate project report of code style violations using ktlint.
43 |
44 | ## Usage
45 |
46 | General instructions on how to use the ktlint plugin can be found on the
47 | [usage page](http://gantsign.com/ktlint-maven-plugin/usage.html).
48 |
49 | ## License
50 |
51 | This software is licensed under the terms in the file named "LICENSE" in the
52 | root directory of this project. This project has dependencies that are under
53 | different licenses.
54 |
55 | ## Author Information
56 |
57 | John Freeman
58 |
59 | GantSign Ltd.
60 | Company No. 06109112 (registered in England)
61 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | <# : batch portion
2 | @REM ----------------------------------------------------------------------------
3 | @REM Licensed to the Apache Software Foundation (ASF) under one
4 | @REM or more contributor license agreements. See the NOTICE file
5 | @REM distributed with this work for additional information
6 | @REM regarding copyright ownership. The ASF licenses this file
7 | @REM to you under the Apache License, Version 2.0 (the
8 | @REM "License"); you may not use this file except in compliance
9 | @REM with the License. You may obtain a copy of the License at
10 | @REM
11 | @REM http://www.apache.org/licenses/LICENSE-2.0
12 | @REM
13 | @REM Unless required by applicable law or agreed to in writing,
14 | @REM software distributed under the License is distributed on an
15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | @REM KIND, either express or implied. See the License for the
17 | @REM specific language governing permissions and limitations
18 | @REM under the License.
19 | @REM ----------------------------------------------------------------------------
20 |
21 | @REM ----------------------------------------------------------------------------
22 | @REM Apache Maven Wrapper startup batch script, version 3.3.2
23 | @REM
24 | @REM Optional ENV vars
25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution
26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
28 | @REM ----------------------------------------------------------------------------
29 |
30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
31 | @SET __MVNW_CMD__=
32 | @SET __MVNW_ERROR__=
33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
34 | @SET PSModulePath=
35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
37 | )
38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
39 | @SET __MVNW_PSMODULEP_SAVE=
40 | @SET __MVNW_ARG0_NAME__=
41 | @SET MVNW_USERNAME=
42 | @SET MVNW_PASSWORD=
43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
44 | @echo Cannot start maven from wrapper >&2 && exit /b 1
45 | @GOTO :EOF
46 | : end batch / begin powershell #>
47 |
48 | $ErrorActionPreference = "Stop"
49 | if ($env:MVNW_VERBOSE -eq "true") {
50 | $VerbosePreference = "Continue"
51 | }
52 |
53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
55 | if (!$distributionUrl) {
56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
57 | }
58 |
59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
60 | "maven-mvnd-*" {
61 | $USE_MVND = $true
62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
63 | $MVN_CMD = "mvnd.cmd"
64 | break
65 | }
66 | default {
67 | $USE_MVND = $false
68 | $MVN_CMD = $script -replace '^mvnw','mvn'
69 | break
70 | }
71 | }
72 |
73 | # apply MVNW_REPOURL and calculate MAVEN_HOME
74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
75 | if ($env:MVNW_REPOURL) {
76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
78 | }
79 | $distributionUrlName = $distributionUrl -replace '^.*/',''
80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
82 | if ($env:MAVEN_USER_HOME) {
83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
84 | }
85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
87 |
88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
91 | exit $?
92 | }
93 |
94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
96 | }
97 |
98 | # prepare tmp dir
99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
102 | trap {
103 | if ($TMP_DOWNLOAD_DIR.Exists) {
104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
106 | }
107 | }
108 |
109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
110 |
111 | # Download and Install Apache Maven
112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
113 | Write-Verbose "Downloading from: $distributionUrl"
114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
115 |
116 | $webclient = New-Object System.Net.WebClient
117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
119 | }
120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
122 |
123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
125 | if ($distributionSha256Sum) {
126 | if ($USE_MVND) {
127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
128 | }
129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
132 | }
133 | }
134 |
135 | # unzip and move
136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
138 | try {
139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
140 | } catch {
141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
142 | Write-Error "fail to move MAVEN_HOME"
143 | }
144 | } finally {
145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
147 | }
148 |
149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
150 |
--------------------------------------------------------------------------------
/src/it/check/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | --add-opens java.base/java.lang=ALL-UNNAMED
2 |
--------------------------------------------------------------------------------
/src/it/check/invoker.properties:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | invoker.buildResult=failure
27 |
--------------------------------------------------------------------------------
/src/it/check/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | src/main/kotlin
39 | src/test/kotlin
40 |
41 |
42 | com.github.gantsign.maven
43 | ktlint-maven-plugin
44 | @project.version@
45 |
46 |
47 | check
48 |
49 | check
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/src/it/check/postbuild.groovy:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | String buildLog = new File(basedir, 'build.log').text
27 | assert buildLog.contains('[ERROR] src/main/kotlin/example/Example.kt:29:39: Unnecessary semicolon')
28 | assert buildLog =~ /\Q[ERROR] Failed to execute goal com.github.gantsign.maven:ktlint-maven-plugin:\E[0-9a-z.]+(-SNAPSHOT)?\Q:check (check) on project test-project: Kotlin source failed ktlint check. -> [Help 1]\E/
29 |
--------------------------------------------------------------------------------
/src/it/check/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/check/src/test/kotlin/example/TestExample.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun testExample() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/checkstyle/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | --add-opens java.base/java.lang=ALL-UNNAMED
2 |
--------------------------------------------------------------------------------
/src/it/checkstyle/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | src/main/kotlin
39 | src/test/kotlin
40 |
41 |
42 | com.github.gantsign.maven
43 | ktlint-maven-plugin
44 | @project.version@
45 |
46 |
47 | check
48 |
49 | check
50 |
51 |
52 | false
53 |
54 |
55 | checkstyle
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/src/it/checkstyle/postbuild.groovy:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | String report = new File(new File(basedir, 'target'), 'checkstyle-ktlint.xml').text
27 | assert report.contains('src/main/kotlin/example/Example.kt')
28 | assert report.contains('src/test/kotlin/example/TestExample.kt')
29 |
--------------------------------------------------------------------------------
/src/it/checkstyle/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/checkstyle/src/test/kotlin/example/TestExample.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun testExample() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/format/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | --add-opens java.base/java.lang=ALL-UNNAMED
2 |
--------------------------------------------------------------------------------
/src/it/format/ExpectedExample.txt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon")
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/format/ExpectedTestExample.txt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun testExample() {
29 | println("should remove semicolon")
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/format/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | src/main/kotlin
39 | src/test/kotlin
40 |
41 |
42 | com.github.gantsign.maven
43 | ktlint-maven-plugin
44 | @project.version@
45 |
46 |
47 | format
48 |
49 | format
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/src/it/format/postbuild.groovy:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | String actualExample = new File(basedir, 'src/main/kotlin/example/Example.kt').getText('UTF-8').normalize().trim()
27 | String expectedExample = new File(basedir, 'ExpectedExample.txt').getText('UTF-8').normalize().trim()
28 | assert actualExample == expectedExample
29 |
30 | String actualTestExample = new File(basedir, 'src/test/kotlin/example/TestExample.kt').getText('UTF-8').normalize().trim()
31 | String expectedTestExample = new File(basedir, 'ExpectedTestExample.txt').getText('UTF-8').normalize().trim()
32 | assert actualTestExample == expectedTestExample
33 |
--------------------------------------------------------------------------------
/src/it/format/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/format/src/test/kotlin/example/TestExample.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun testExample() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/report/.mvn/jvm.config:
--------------------------------------------------------------------------------
1 | --add-opens java.base/java.lang=ALL-UNNAMED
2 |
--------------------------------------------------------------------------------
/src/it/report/invoker.properties:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | invoker.goals=clean install site
27 |
--------------------------------------------------------------------------------
/src/it/report/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | src/main/kotlin
39 | src/test/kotlin
40 |
41 |
42 |
43 | org.apache.maven.plugins
44 | maven-site-plugin
45 | 3.7.1
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | com.github.gantsign.maven
55 | ktlint-maven-plugin
56 | @project.version@
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/src/it/report/postbuild.groovy:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | String report = new File(new File(new File(basedir, 'target'), 'site'), 'ktlint.html').text
27 | assert report.contains('src/main/kotlin/example/Example.kt')
28 | assert report.contains('src/test/kotlin/example/TestExample.kt')
29 |
--------------------------------------------------------------------------------
/src/it/report/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/it/report/src/test/kotlin/example/TestExample.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun testExample() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/AbstractBaseMojo.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import java.io.File
29 | import org.apache.maven.plugin.AbstractMojo
30 | import org.apache.maven.plugins.annotations.Parameter
31 |
32 | abstract class AbstractBaseMojo : AbstractMojo() {
33 |
34 | @Parameter(defaultValue = "\${project.basedir}", readonly = true, required = true)
35 | protected lateinit var basedir: File
36 |
37 | @Parameter(defaultValue = "\${project.packaging}", readonly = true, required = true)
38 | protected lateinit var packaging: String
39 |
40 | @Parameter(defaultValue = "\${project.compileSourceRoots}", readonly = true, required = true)
41 | protected lateinit var sourceRoots: List
42 |
43 | @Parameter(
44 | defaultValue = "\${project.testCompileSourceRoots}",
45 | readonly = true,
46 | required = true,
47 | )
48 | protected lateinit var testSourceRoots: List
49 |
50 | /**
51 | * A list of root directories containing Kotlin scripts.
52 | */
53 | @Parameter(property = "ktlint.scriptRoots", defaultValue = "\${project.basedir.path}")
54 | protected lateinit var scriptRoots: List
55 |
56 | /**
57 | * Include the production source roots.
58 | */
59 | @Parameter(property = "ktlint.includeSources", defaultValue = "true", required = true)
60 | protected var includeSources = true
61 |
62 | /**
63 | * Include the test source roots.
64 | */
65 | @Parameter(property = "ktlint.includeTestSources", defaultValue = "true", required = true)
66 | protected var includeTestSources = true
67 |
68 | /**
69 | * Include scripts.
70 | */
71 | @Parameter(property = "ktlint.includeScripts", defaultValue = "true", required = true)
72 | protected var includeScripts = true
73 |
74 | /**
75 | * A list of inclusion filters for the source files to be processed under the source roots.
76 | */
77 | @Parameter(defaultValue = "**/*.kt")
78 | protected var sourcesIncludes: Set? = null
79 |
80 | /**
81 | * A list of exclusion filters for the source files to be processed under the source roots.
82 | */
83 | @Parameter
84 | protected var sourcesExcludes: Set? = null
85 |
86 | /**
87 | * A list of inclusion filters for the source files to be processed under the test source roots.
88 | */
89 | @Parameter(defaultValue = "**/*.kt")
90 | protected var testSourcesIncludes: Set? = null
91 |
92 | /**
93 | * A list of exclusion filters for the source files to be processed under the test source roots.
94 | */
95 | @Parameter
96 | protected var testSourcesExcludes: Set? = null
97 |
98 | /**
99 | * A list of inclusion filters for scripts.
100 | */
101 | @Parameter(defaultValue = "*.kts")
102 | protected var scriptsIncludes: Set? = null
103 |
104 | /**
105 | * A list of exclusion filters for scripts.
106 | */
107 | @Parameter
108 | protected var scriptsExcludes: Set? = null
109 |
110 | /**
111 | * Enable Android Kotlin Style Guide compatibility.
112 | */
113 | @Parameter(property = "ktlint.android", defaultValue = "false", required = true)
114 | protected var android: Boolean = false
115 |
116 | /**
117 | * Enable experimental rules (ktlint-ruleset-experimental).
118 | */
119 | @Parameter(property = "ktlint.experimental", defaultValue = "false", required = true)
120 | protected var experimental: Boolean = false
121 | }
122 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/CheckMojo.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import com.github.gantsign.maven.plugin.ktlint.internal.Check
29 | import com.github.gantsign.maven.plugin.ktlint.internal.Sources
30 | import com.pinterest.ktlint.cli.reporter.plain.Color
31 | import org.apache.maven.plugins.annotations.LifecyclePhase
32 | import org.apache.maven.plugins.annotations.Mojo
33 | import org.apache.maven.plugins.annotations.Parameter
34 |
35 | /**
36 | * Checks for violations of the code style.
37 | */
38 | @Mojo(
39 | name = "check",
40 | defaultPhase = LifecyclePhase.VERIFY,
41 | requiresProject = true,
42 | threadSafe = true,
43 | )
44 | class CheckMojo : AbstractBaseMojo() {
45 |
46 | /**
47 | * A set of reporters to output the results to.
48 | */
49 | @Parameter
50 | private var reporters: Set? = null
51 |
52 | /**
53 | * Whether the KtLint reporter should output in color (doesn't affect the Maven output).
54 | */
55 | @Parameter
56 | private var reporterColor: Boolean = false
57 |
58 | /**
59 | * The color the KtLint reporter should output in (doesn't affect the Maven output).
60 | */
61 | @Parameter
62 | private var reporterColorName: String = Color.DARK_GRAY.name
63 |
64 | /**
65 | * Show error codes.
66 | */
67 | @Parameter(property = "ktlint.verbose", defaultValue = "false", required = true)
68 | private var verbose: Boolean = false
69 |
70 | /**
71 | * Whether to fail the build if the linter finds violations of the code style.
72 | */
73 | @Parameter(property = "ktlint.failOnViolation", defaultValue = "true", required = true)
74 | private var failOnViolation: Boolean = true
75 |
76 | /**
77 | * Skips and code style checks.
78 | */
79 | @Parameter(property = "ktlint.skip", defaultValue = "false", required = true)
80 | private var skip: Boolean = false
81 |
82 | override fun execute() {
83 | if (skip) {
84 | return
85 | }
86 | Check(
87 | log = log,
88 | basedir = basedir,
89 | modulePackaging = packaging,
90 | sources = listOf(
91 | Sources(
92 | isIncluded = includeSources,
93 | sourceRoots = sourceRoots,
94 | includes = sourcesIncludes,
95 | excludes = sourcesExcludes,
96 | ),
97 | Sources(
98 | isIncluded = includeTestSources,
99 | sourceRoots = testSourceRoots,
100 | includes = testSourcesIncludes,
101 | excludes = testSourcesExcludes,
102 | ),
103 | Sources(
104 | isIncluded = includeScripts,
105 | sourceRoots = scriptRoots,
106 | includes = scriptsIncludes,
107 | excludes = scriptsExcludes,
108 | ),
109 | ),
110 | android = android,
111 | reporterConfig = reporters ?: emptySet(),
112 | verbose = verbose,
113 | reporterColor = reporterColor,
114 | reporterColorName = reporterColorName,
115 | enableExperimentalRules = experimental,
116 | failOnViolation = failOnViolation,
117 | )()
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/FormatMojo.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import com.github.gantsign.maven.plugin.ktlint.internal.Format
29 | import com.github.gantsign.maven.plugin.ktlint.internal.Sources
30 | import org.apache.maven.plugins.annotations.LifecyclePhase
31 | import org.apache.maven.plugins.annotations.Mojo
32 | import org.apache.maven.plugins.annotations.Parameter
33 |
34 | /**
35 | * Automatically fixes violations of the code style (when possible).
36 | */
37 | @Mojo(
38 | name = "format",
39 | defaultPhase = LifecyclePhase.PROCESS_SOURCES,
40 | requiresProject = true,
41 | threadSafe = true,
42 | )
43 | class FormatMojo : AbstractBaseMojo() {
44 |
45 | /**
46 | * Skips automatic code style fixes.
47 | */
48 | @Parameter(property = "ktlint.skip", defaultValue = "false", required = true)
49 | private var skip: Boolean = false
50 |
51 | override fun execute() {
52 | if (skip) {
53 | return
54 | }
55 | Format(
56 | log = log,
57 | basedir = basedir,
58 | modulePackaging = packaging,
59 | sources = listOf(
60 | Sources(
61 | isIncluded = includeSources,
62 | sourceRoots = sourceRoots,
63 | includes = sourcesIncludes,
64 | excludes = sourcesExcludes,
65 | ),
66 | Sources(
67 | isIncluded = includeTestSources,
68 | sourceRoots = testSourceRoots,
69 | includes = testSourcesIncludes,
70 | excludes = testSourcesExcludes,
71 | ),
72 | Sources(
73 | isIncluded = includeScripts,
74 | sourceRoots = scriptRoots,
75 | includes = scriptsIncludes,
76 | excludes = scriptsExcludes,
77 | ),
78 | ),
79 | android = android,
80 | enableExperimentalRules = experimental,
81 | )()
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/KtlintReport.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import com.github.gantsign.maven.plugin.ktlint.internal.KtlintReportGenerator
29 | import com.github.gantsign.maven.plugin.ktlint.internal.Report
30 | import com.github.gantsign.maven.plugin.ktlint.internal.Sources
31 | import com.github.gantsign.maven.plugin.ktlint.internal.get
32 | import java.io.File
33 | import java.util.Locale
34 | import java.util.ResourceBundle
35 | import org.apache.maven.plugins.annotations.LifecyclePhase
36 | import org.apache.maven.plugins.annotations.Mojo
37 | import org.apache.maven.plugins.annotations.Parameter
38 | import org.apache.maven.reporting.AbstractMavenReport
39 |
40 | /**
41 | * A reporting task that performs `ktlint` analysis and generates a HTML report on any violations that `ktlint` finds.
42 | */
43 | @Mojo(
44 | name = "ktlint",
45 | defaultPhase = LifecyclePhase.VERIFY,
46 | requiresProject = true,
47 | threadSafe = true,
48 | )
49 | class KtlintReport : AbstractMavenReport() {
50 |
51 | @Parameter(defaultValue = "\${project.basedir}", readonly = true, required = true)
52 | private lateinit var basedir: File
53 |
54 | @Parameter(defaultValue = "\${project.packaging}", readonly = true, required = true)
55 | private lateinit var packaging: String
56 |
57 | @Parameter(defaultValue = "\${project.compileSourceRoots}", readonly = true, required = true)
58 | private lateinit var sourceRoots: List
59 |
60 | @Parameter(
61 | defaultValue = "\${project.testCompileSourceRoots}",
62 | readonly = true,
63 | required = true,
64 | )
65 | private lateinit var testSourceRoots: List
66 |
67 | /**
68 | * A list of root directories containing Kotlin scripts.
69 | */
70 | @Parameter(property = "ktlint.scriptRoots", defaultValue = "\${project.basedir.path}")
71 | private lateinit var scriptRoots: List
72 |
73 | /**
74 | * Include the production source roots.
75 | */
76 | @Parameter(property = "ktlint.includeSources", defaultValue = "true", required = true)
77 | private var includeSources = true
78 |
79 | /**
80 | * Include the test source roots.
81 | */
82 | @Parameter(property = "ktlint.includeTestSources", defaultValue = "true", required = true)
83 | private var includeTestSources = true
84 |
85 | /**
86 | * Include scripts.
87 | */
88 | @Parameter(property = "ktlint.includeScripts", defaultValue = "true", required = true)
89 | private var includeScripts = true
90 |
91 | /**
92 | * File encoding of the Kotlin source files.
93 | */
94 | @Parameter(property = "encoding", defaultValue = "\${project.build.sourceEncoding}")
95 | private val encoding: String? = null
96 |
97 | /**
98 | * A list of inclusion filters for the source files to be processed under the source roots.
99 | */
100 | @Parameter(defaultValue = "**/*.kt")
101 | private var sourcesIncludes: Set? = null
102 |
103 | /**
104 | * A list of exclusion filters for the source files to be processed under the source roots.
105 | */
106 | @Parameter
107 | private var sourcesExcludes: Set? = null
108 |
109 | /**
110 | * A list of inclusion filters for the source files to be processed under the test source roots.
111 | */
112 | @Parameter(defaultValue = "**/*.kt")
113 | private var testSourcesIncludes: Set? = null
114 |
115 | /**
116 | * A list of exclusion filters for the source files to be processed under the test source roots.
117 | */
118 | @Parameter
119 | private var testSourcesExcludes: Set? = null
120 |
121 | /**
122 | * A list of inclusion filters for scripts.
123 | */
124 | @Parameter(defaultValue = "*.kts")
125 | private var scriptsIncludes: Set? = null
126 |
127 | /**
128 | * A list of exclusion filters for scripts.
129 | */
130 | @Parameter
131 | private var scriptsExcludes: Set? = null
132 |
133 | /**
134 | * Enable Android Kotlin Style Guide compatibility.
135 | */
136 | @Parameter(property = "ktlint.android", defaultValue = "false", required = true)
137 | private var android: Boolean = false
138 |
139 | /**
140 | * A set of reporters to output the results to.
141 | */
142 | @Parameter
143 | private var reporters: Set? = null
144 |
145 | /**
146 | * Show error codes.
147 | */
148 | @Parameter(property = "ktlint.verbose", defaultValue = "false", required = true)
149 | private var verbose: Boolean = false
150 |
151 | /**
152 | * Enable experimental rules (ktlint-ruleset-experimental).
153 | */
154 | @Parameter(property = "ktlint.experimental", defaultValue = "false", required = true)
155 | private var experimental: Boolean = false
156 |
157 | /**
158 | * Skips and code style checks.
159 | */
160 | @Parameter(property = "ktlint.skip", defaultValue = "false", required = true)
161 | private var skip: Boolean = false
162 |
163 | private fun getBundle(locale: Locale): ResourceBundle {
164 | return ResourceBundle.getBundle(
165 | "ktlint-report",
166 | locale,
167 | AbstractMavenReport::class.java.classLoader,
168 | )
169 | }
170 |
171 | override fun getName(locale: Locale): String =
172 | getBundle(locale)["report.ktlint.name"]
173 |
174 | override fun getDescription(locale: Locale): String =
175 | getBundle(locale)["report.ktlint.description"]
176 |
177 | override fun getOutputName(): String = "ktlint"
178 |
179 | override fun canGenerateReport(): Boolean =
180 | !skip && sourceRoots.asSequence().map(::File).any { it.isDirectory }
181 |
182 | override fun executeReport(locale: Locale) {
183 | val results = Report(
184 | log = log,
185 | basedir = basedir,
186 | modulePackaging = packaging,
187 | sources = listOf(
188 | Sources(
189 | isIncluded = includeSources,
190 | sourceRoots = sourceRoots,
191 | includes = sourcesIncludes,
192 | excludes = sourcesExcludes,
193 | ),
194 | Sources(
195 | isIncluded = includeTestSources,
196 | sourceRoots = testSourceRoots,
197 | includes = testSourcesIncludes,
198 | excludes = testSourcesExcludes,
199 | ),
200 | Sources(
201 | isIncluded = includeScripts,
202 | sourceRoots = scriptRoots,
203 | includes = scriptsIncludes,
204 | excludes = scriptsExcludes,
205 | ),
206 | ),
207 | android = android,
208 | reporterConfig = reporters ?: emptySet(),
209 | verbose = verbose,
210 | enableExperimentalRules = experimental,
211 | )()
212 | KtlintReportGenerator(sink, getBundle(locale)).generatorReport(results)
213 | }
214 | }
215 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/MavenLogReporter.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import com.pinterest.ktlint.cli.reporter.core.api.KtlintCliError
29 | import com.pinterest.ktlint.cli.reporter.core.api.ReporterV2
30 | import java.io.File
31 | import java.util.concurrent.ConcurrentHashMap
32 | import org.apache.maven.plugin.logging.Log
33 | import org.apache.maven.shared.utils.logging.MessageUtils
34 |
35 | class MavenLogReporter(
36 | val log: Log,
37 | val verbose: Boolean,
38 | val groupByFile: Boolean,
39 | val pad: Boolean,
40 | ) : ReporterV2 {
41 |
42 | private val acc = ConcurrentHashMap>()
43 |
44 | override fun onLintError(file: String, ktlintCliError: KtlintCliError) {
45 | val line = ktlintCliError.line
46 | val col = ktlintCliError.col
47 | val ruleId = ktlintCliError.ruleId
48 | val detail = ktlintCliError.detail
49 |
50 | if (groupByFile) {
51 | acc.getOrPut?>(file, ::ArrayList)!!.add(ktlintCliError)
52 | return
53 | }
54 |
55 | val buf = MessageUtils.buffer()
56 | .a(file.dir())
57 | .strong(file.name())
58 | .a(":")
59 | .strong(line)
60 | .a(":$col:".pad(4))
61 | .a(" ")
62 | .failure(detail)
63 | if (verbose) {
64 | buf.a(" ($ruleId)")
65 | }
66 | log.error(buf.toString())
67 | }
68 |
69 | override fun after(file: String) {
70 | if (!groupByFile) return
71 |
72 | val errList = acc[file] ?: return
73 |
74 | log.error(MessageUtils.buffer().a(file.dir()).strong(file.name()).toString())
75 |
76 | for (err in errList) {
77 | val line = err.line
78 | val col = err.col
79 | val ruleId = err.ruleId
80 | val detail = err.detail
81 | val buf = MessageUtils.buffer()
82 | .a(" ")
83 | .strong(line)
84 | .a(":$col".pad(4))
85 | .a(" ")
86 | .failure(detail)
87 | if (verbose) {
88 | buf.a(" ($ruleId)")
89 | }
90 |
91 | log.error(buf.toString())
92 | }
93 | }
94 |
95 | private fun String.pad(length: Int): String =
96 | if (pad) this.padEnd(length) else this
97 |
98 | private fun String.dir(): String =
99 | substringBeforeLast(File.separator) + File.separator
100 |
101 | private fun String.name(): String =
102 | substringAfterLast(File.separator)
103 |
104 | companion object {
105 | @JvmStatic
106 | val NAME = "maven"
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/MavenLogReporterProvider.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import com.pinterest.ktlint.cli.reporter.core.api.ReporterProviderV2
29 | import java.io.PrintStream
30 | import org.apache.maven.plugin.logging.Log
31 |
32 | class MavenLogReporterProvider : ReporterProviderV2 {
33 |
34 | override val id: String = "maven"
35 |
36 | override fun get(out: PrintStream, opt: Map): MavenLogReporter =
37 | throw UnsupportedOperationException("Use MavenLogReporterProvider.get(Log, Map) instead.")
38 |
39 | fun get(log: Log, opt: Map): MavenLogReporter =
40 | MavenLogReporter(
41 | log = log,
42 | verbose = opt["verbose"].emptyOrTrue(),
43 | groupByFile = opt["group_by_file"].emptyOrTrue(),
44 | pad = opt["pad"].emptyOrTrue(),
45 | )
46 |
47 | private fun String?.emptyOrTrue() = this == "" || this == "true"
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/ReporterConfig.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import java.io.File
29 | import java.util.Properties
30 |
31 | data class ReporterConfig @JvmOverloads constructor(
32 | var name: String? = null,
33 | var output: File? = null,
34 | var properties: Properties? = null,
35 | )
36 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/AbstractLintSupport.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3
29 | import com.pinterest.ktlint.rule.engine.core.api.RuleProvider
30 | import java.io.File
31 | import java.util.ServiceLoader
32 | import org.apache.maven.plugin.logging.Log
33 |
34 | internal abstract class AbstractLintSupport(
35 | protected val log: Log,
36 | protected val basedir: File,
37 | protected val android: Boolean,
38 | protected val enableExperimentalRules: Boolean,
39 | ) {
40 | protected val ruleProviders: Set by lazy {
41 | return@lazy ServiceLoader.load(RuleSetProviderV3::class.java)
42 | .asSequence()
43 | .map { ruleSetProviderV3 -> Pair(ruleSetProviderV3.id, ruleSetProviderV3.getRuleProviders()) }
44 | .distinctBy { (id, _) -> id }
45 | .onEach { (id, _) ->
46 | if (log.isDebugEnabled) {
47 | log.debug("Discovered RuleSetProviderV3 '$id'")
48 | }
49 | }
50 | .flatMap { (_, ruleProviders) -> ruleProviders }
51 | .toSet()
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/AggregatedReporter.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 - 2023 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.pinterest.ktlint.cli.reporter.core.api.KtlintCliError
29 | import com.pinterest.ktlint.cli.reporter.core.api.ReporterV2
30 |
31 | class AggregatedReporter(private val reporters: List) : ReporterV2 {
32 | override fun after(file: String) {
33 | reporters.forEach { it.after(file) }
34 | }
35 |
36 | override fun afterAll() {
37 | reporters.forEach(ReporterV2::afterAll)
38 | }
39 |
40 | override fun before(file: String) {
41 | reporters.forEach { it.before(file) }
42 | }
43 |
44 | override fun beforeAll() {
45 | reporters.forEach(ReporterV2::beforeAll)
46 | }
47 |
48 | override fun onLintError(file: String, ktlintCliError: KtlintCliError) {
49 | reporters.forEach { it.onLintError(file, ktlintCliError) }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/Check.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.github.gantsign.maven.plugin.ktlint.MavenLogReporter
29 | import com.github.gantsign.maven.plugin.ktlint.ReporterConfig
30 | import java.io.File
31 | import org.apache.maven.plugin.MojoFailureException
32 | import org.apache.maven.plugin.logging.Log
33 |
34 | internal class Check(
35 | log: Log,
36 | basedir: File,
37 | modulePackaging: String,
38 | sources: List,
39 | android: Boolean,
40 | reporterConfig: Set,
41 | verbose: Boolean,
42 | reporterColor: Boolean,
43 | reporterColorName: String,
44 | enableExperimentalRules: Boolean,
45 | private val failOnViolation: Boolean,
46 | ) : AbstractCheckSupport(
47 | log,
48 | basedir,
49 | modulePackaging,
50 | sources,
51 | android,
52 | addMavenReporter(reporterConfig),
53 | verbose,
54 | reporterColor,
55 | reporterColorName,
56 | enableExperimentalRules,
57 | ) {
58 | operator fun invoke() {
59 | val reporter = reporter
60 |
61 | val hasErrors = hasErrors(reporter)
62 | if (hasErrors && failOnViolation) {
63 | throw MojoFailureException("Kotlin source failed ktlint check.")
64 | }
65 | }
66 |
67 | companion object {
68 |
69 | @JvmStatic
70 | fun addMavenReporter(reporterConfig: Set): Set {
71 | return if (reporterConfig.any { it.name == MavenLogReporter.NAME }) {
72 | reporterConfig
73 | } else {
74 | reporterConfig + ReporterConfig(MavenLogReporter.NAME)
75 | }
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/CheckResults.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | internal class CheckResults(val fileCount: Int, val errors: List)
29 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/FileLintError.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.pinterest.ktlint.cli.reporter.core.api.KtlintCliError
29 |
30 | internal class FileLintError(
31 | val file: String,
32 | val line: Int,
33 | val col: Int,
34 | val ruleId: String,
35 | val detail: String,
36 | val status: KtlintCliError.Status,
37 | ) {
38 | constructor(file: String, lintError: KtlintCliError) : this(
39 | file,
40 | lintError.line,
41 | lintError.col,
42 | lintError.ruleId,
43 | lintError.detail,
44 | lintError.status,
45 | )
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/Format.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.pinterest.ktlint.rule.engine.api.Code
29 | import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults
30 | import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride
31 | import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride.Companion.plus
32 | import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine
33 | import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CODE_STYLE_PROPERTY
34 | import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleValue
35 | import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EXPERIMENTAL_RULES_EXECUTION_PROPERTY
36 | import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution
37 | import com.pinterest.ktlint.rule.engine.core.api.propertyTypes
38 | import java.io.File
39 | import java.nio.charset.StandardCharsets
40 | import java.util.concurrent.atomic.AtomicInteger
41 | import org.apache.maven.plugin.MojoFailureException
42 | import org.apache.maven.plugin.logging.Log
43 | import org.apache.maven.shared.utils.io.DirectoryScanner
44 | import org.jetbrains.kotlin.utils.addToStdlib.applyIf
45 |
46 | internal class Format(
47 | log: Log,
48 | basedir: File,
49 | private val modulePackaging: String,
50 | private val sources: List,
51 | android: Boolean,
52 | enableExperimentalRules: Boolean,
53 | ) : AbstractLintSupport(log, basedir, android, enableExperimentalRules) {
54 |
55 | private val formattedFileCount = AtomicInteger()
56 |
57 | operator fun invoke() {
58 | val editorConfigOverride =
59 | EditorConfigOverride
60 | .EMPTY_EDITOR_CONFIG_OVERRIDE
61 | .applyIf(enableExperimentalRules) {
62 | log.debug("Add editor config override to allow the experimental rule set")
63 | plus(EXPERIMENTAL_RULES_EXECUTION_PROPERTY to RuleExecution.enabled)
64 | }.applyIf(android) {
65 | log.debug("Add editor config override to set code style to 'android_studio'")
66 | plus(CODE_STYLE_PROPERTY to CodeStyleValue.android_studio)
67 | }
68 |
69 | val editorConfigDefaults = EditorConfigDefaults.load(null, ruleProviders.propertyTypes())
70 |
71 | val ktLintRuleEngine =
72 | KtLintRuleEngine(
73 | ruleProviders = ruleProviders,
74 | editorConfigDefaults = editorConfigDefaults,
75 | editorConfigOverride = editorConfigOverride,
76 | isInvokedFromCli = false,
77 | )
78 |
79 | val checkedFiles = mutableSetOf()
80 | for ((isIncluded, sourceRoots, includes, excludes) in sources) {
81 | if (!isIncluded) {
82 | log.debug("Source roots not included: $sourceRoots")
83 | continue
84 | }
85 | for (sourceRoot in sourceRoots) {
86 | if (!sourceRoot.exists()) {
87 | val msg = "Source root doesn't exist: ${sourceRoot.toRelativeString(basedir)}"
88 | if (modulePackaging == "pom") {
89 | log.debug(msg)
90 | } else {
91 | log.warn(msg)
92 | }
93 | continue
94 | }
95 | if (!sourceRoot.isDirectory) {
96 | throw MojoFailureException(
97 | "Source root is not a directory: ${sourceRoot.toRelativeString(basedir)}",
98 | )
99 | }
100 |
101 | val includesArray =
102 | includes.takeUnless(Set::isEmpty)?.toTypedArray() ?: arrayOf("**/*.kt")
103 | val excludesArray = excludes.toTypedArray()
104 |
105 | val ds = DirectoryScanner().apply {
106 | setIncludes(*includesArray)
107 | setExcludes(*excludesArray)
108 | basedir = sourceRoot
109 | setCaseSensitive(true)
110 | }
111 | ds.scan()
112 |
113 | val sourceFiles = ds.includedFiles.map { File(sourceRoot, it) }
114 |
115 | sourceFiles.forEach { file ->
116 | if (!checkedFiles.add(file.canonicalFile)) {
117 | return@forEach
118 | }
119 |
120 | formatFile(
121 | ktLintRuleEngine = ktLintRuleEngine,
122 | code = Code.fromFile(file),
123 | )
124 | }
125 | }
126 | }
127 | log.info("${formattedFileCount.get()} file(s) formatted.")
128 | }
129 |
130 | private fun formatFile(
131 | ktLintRuleEngine: KtLintRuleEngine,
132 | code: Code,
133 | ) {
134 | val baseRelativePath = code.filePath!!.toFile().toRelativeString(basedir)
135 | log.debug("checking format: $baseRelativePath")
136 | val beforeFileContent = code.content
137 | try {
138 | ktLintRuleEngine
139 | .format(code) { lintError, corrected ->
140 | val errMsg = "$baseRelativePath:${lintError.line}:${lintError.col}: ${lintError.detail}"
141 | log.debug("Format ${if (corrected) "fixed" else "could not fix"} > $errMsg")
142 | }.also { formattedFileContent ->
143 | code
144 | .filePath
145 | ?.toFile()
146 | ?.writeText(formattedFileContent, StandardCharsets.UTF_8)
147 | if (beforeFileContent != formattedFileContent) {
148 | log.debug("Format fixed > $baseRelativePath")
149 | formattedFileCount.incrementAndGet()
150 | }
151 | }
152 | } catch (e: Exception) {
153 | log.error(e.message, e)
154 | }
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/Functions.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | @file:Suppress("ktlint:standard:filename")
27 |
28 | package com.github.gantsign.maven.plugin.ktlint.internal
29 |
30 | import com.pinterest.ktlint.cli.reporter.core.api.KtlintCliError
31 | import com.pinterest.ktlint.rule.engine.api.Code
32 | import com.pinterest.ktlint.rule.engine.api.KtLintParseException
33 | import com.pinterest.ktlint.rule.engine.api.KtLintRuleException
34 | import java.util.Locale
35 | import java.util.ResourceBundle
36 |
37 | internal operator fun ResourceBundle.get(key: String): String =
38 | if (containsKey(key)) getString(key) else key
39 |
40 | internal fun Exception.toKtlintCliError(code: Code): KtlintCliError =
41 | let { e ->
42 | when (e) {
43 | is KtLintParseException ->
44 | KtlintCliError(
45 | line = e.line,
46 | col = e.col,
47 | ruleId = "",
48 | detail = "Not a valid Kotlin file (${e.message?.lowercase(Locale.getDefault())})",
49 | status = KtlintCliError.Status.KOTLIN_PARSE_EXCEPTION,
50 | )
51 |
52 | is KtLintRuleException -> {
53 | KtlintCliError(
54 | line = e.line,
55 | col = e.col,
56 | ruleId = "",
57 | detail =
58 | "Internal Error (rule '${e.ruleId}') in ${code.fileNameOrStdin()} at position '${e.line}:${e.col}" +
59 | ". Please create a ticket at https://github.com/pinterest/ktlint/issues and provide the " +
60 | "source code that triggered an error.\n" +
61 | e.stackTraceToString(),
62 | status = KtlintCliError.Status.KTLINT_RULE_ENGINE_EXCEPTION,
63 | )
64 | }
65 |
66 | else -> throw e
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/KtlintReportGenerator.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.github.gantsign.maven.doxia.sink.kotlin.invoke
29 | import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine
30 | import java.util.ResourceBundle
31 | import org.apache.maven.doxia.sink.Sink
32 |
33 | internal class KtlintReportGenerator(
34 | private val sink: Sink,
35 | private val bundle: ResourceBundle,
36 | ) {
37 |
38 | private val title = bundle["report.ktlint.title"]
39 |
40 | private val ktlintVersion: String? =
41 | KtLintRuleEngine::class.java.`package`?.implementationVersion
42 |
43 | fun generatorReport(results: CheckResults) {
44 | sink {
45 | head {
46 | title {
47 | +title
48 | }
49 | }
50 | body {
51 | section(1) {
52 | title {
53 | +title
54 | }
55 | paragraph {
56 | +"${bundle["report.ktlint.ktlintlink"]} "
57 | link("https://github.com/pinterest/ktlint") {
58 | +"ktlint"
59 | }
60 | if (ktlintVersion != null) {
61 | +" $ktlintVersion"
62 | }
63 | +"."
64 | }
65 | }
66 |
67 | section(1) {
68 | title {
69 | +bundle["report.ktlint.summary"]
70 | }
71 | table {
72 | tableRows {
73 | tableRow {
74 | tableHeaderCell {
75 | +bundle["report.ktlint.files"]
76 | }
77 | tableHeaderCell {
78 | +bundle["report.ktlint.errors"]
79 | }
80 | }
81 | tableRow {
82 | tableCell {
83 | +"${results.fileCount}"
84 | }
85 | tableCell {
86 | +"${results.errors.size}"
87 | }
88 | }
89 | }
90 | }
91 | }
92 |
93 | val errorsByFile =
94 | results.errors.groupBy(FileLintError::file).toSortedMap()
95 |
96 | if (errorsByFile.isNotEmpty()) {
97 | section(1) {
98 | title {
99 | +bundle["report.ktlint.files"]
100 | }
101 | table {
102 | tableRows {
103 | tableRow {
104 | tableHeaderCell {
105 | +bundle["report.ktlint.file"]
106 | }
107 | tableHeaderCell {
108 | +bundle["report.ktlint.errors"]
109 | }
110 | }
111 |
112 | for ((file, errors) in errorsByFile) {
113 | tableRow {
114 | tableCell {
115 | link("#${file.replace('/', '.')}") {
116 | +file
117 | }
118 | }
119 | tableCell {
120 | +"${errors.size}"
121 | }
122 | }
123 | }
124 | }
125 | }
126 | }
127 |
128 | section(1) {
129 | title {
130 | +bundle["report.ktlint.details"]
131 | }
132 | for ((file, errors) in errorsByFile) {
133 | val sortedErrors = errors.sortedWith(
134 | Comparator.comparingInt(FileLintError::line)
135 | .thenComparingInt(FileLintError::col)
136 | .thenComparing(FileLintError::ruleId),
137 | )
138 | section(2, id = file.replace('/', '.')) {
139 | title {
140 | +file
141 | }
142 | }
143 | table {
144 | tableRows {
145 | tableRow {
146 | tableHeaderCell {
147 | +bundle["report.ktlint.detail"]
148 | }
149 | tableHeaderCell {
150 | +bundle["report.ktlint.ruleId"]
151 | }
152 | tableHeaderCell {
153 | +bundle["report.ktlint.line"]
154 | }
155 | }
156 | for (error in sortedErrors) {
157 | tableRow {
158 | tableCell {
159 | +error.detail
160 | }
161 | tableCell {
162 | +error.ruleId
163 | }
164 | tableCell {
165 | +"${error.line}"
166 | }
167 | }
168 | }
169 | }
170 | }
171 | }
172 | }
173 | }
174 | }
175 | }
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/ModelReporter.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.pinterest.ktlint.cli.reporter.core.api.KtlintCliError
29 | import com.pinterest.ktlint.cli.reporter.core.api.ReporterV2
30 | import java.util.concurrent.CopyOnWriteArrayList
31 | import java.util.concurrent.atomic.AtomicInteger
32 |
33 | internal class ModelReporter : ReporterV2 {
34 |
35 | private val _errors = CopyOnWriteArrayList()
36 | private val _fileCount = AtomicInteger()
37 |
38 | val fileCount: Int
39 | get() = _fileCount.get()
40 |
41 | val errors: List
42 | get() = _errors
43 |
44 | override fun onLintError(file: String, ktlintCliError: KtlintCliError) {
45 | _errors.add(FileLintError(file, ktlintCliError))
46 | }
47 |
48 | override fun after(file: String) {
49 | _fileCount.incrementAndGet()
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/Report.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.github.gantsign.maven.plugin.ktlint.ReporterConfig
29 | import com.pinterest.ktlint.cli.reporter.plain.Color
30 | import java.io.File
31 | import org.apache.maven.plugin.logging.Log
32 |
33 | internal class Report(
34 | log: Log,
35 | basedir: File,
36 | modulePackaging: String,
37 | sources: List,
38 | android: Boolean,
39 | reporterConfig: Set,
40 | verbose: Boolean,
41 | enableExperimentalRules: Boolean,
42 | ) : AbstractCheckSupport(
43 | log,
44 | basedir,
45 | modulePackaging,
46 | sources,
47 | android,
48 | reporterConfig,
49 | verbose,
50 | false,
51 | Color.DARK_GRAY.name,
52 | enableExperimentalRules,
53 | ) {
54 | operator fun invoke(): CheckResults {
55 | val modelReporter = ModelReporter()
56 | val reporter = AggregatedReporter(listOf(reporter, modelReporter))
57 |
58 | hasErrors(reporter)
59 |
60 | return CheckResults(modelReporter.fileCount, modelReporter.errors)
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/Sources.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import java.io.File
29 |
30 | data class Sources constructor(
31 | val isIncluded: Boolean,
32 | val sourceRoots: Set,
33 | val includes: Set,
34 | val excludes: Set,
35 | ) {
36 | constructor(
37 | isIncluded: Boolean,
38 | sourceRoots: Collection?,
39 | includes: Collection?,
40 | excludes: Collection?,
41 | ) : this(
42 | isIncluded,
43 | sourceRoots?.asSequence()?.map(::File)?.toSet() ?: emptySet(),
44 | includes?.toSet() ?: emptySet(),
45 | excludes?.toSet() ?: emptySet(),
46 | )
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/services/com.pinterest.ktlint.cli.reporter.core.api.ReporterProviderV2:
--------------------------------------------------------------------------------
1 | com.github.gantsign.maven.plugin.ktlint.MavenLogReporterProvider
2 |
--------------------------------------------------------------------------------
/src/main/resources/ktlint-report.properties:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | report.ktlint.name=Ktlint
27 | report.ktlint.description=Report on coding style conventions.
28 | report.ktlint.title=Ktlint Results
29 | report.ktlint.ktlintlink=The following document contains the results of
30 | report.ktlint.summary=Summary
31 | report.ktlint.files=Files
32 | report.ktlint.errors=Errors
33 | report.ktlint.file=File
34 | report.ktlint.details=Details
35 | report.ktlint.detail=Detail
36 | report.ktlint.ruleId=Rule ID
37 | report.ktlint.line=Line
38 |
--------------------------------------------------------------------------------
/src/site/apt/index.apt.vm:
--------------------------------------------------------------------------------
1 | ------
2 | Introduction
3 | ------
4 | John Freeman
5 | ------
6 | 2018-05-10
7 | ------
8 |
9 | ~~ #%L
10 | ~~ ktlint-maven-plugin
11 | ~~ %%
12 | ~~ Copyright (C) 2018 GantSign Ltd.
13 | ~~ %%
14 | ~~ Permission is hereby granted, free of charge, to any person obtaining a copy
15 | ~~ of this software and associated documentation files (the "Software"), to deal
16 | ~~ in the Software without restriction, including without limitation the rights
17 | ~~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 | ~~ copies of the Software, and to permit persons to whom the Software is
19 | ~~ furnished to do so, subject to the following conditions:
20 | ~~
21 | ~~ The above copyright notice and this permission notice shall be included in
22 | ~~ all copies or substantial portions of the Software.
23 | ~~
24 | ~~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 | ~~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 | ~~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 | ~~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 | ~~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 | ~~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 | ~~ THE SOFTWARE.
31 | ~~ #L%
32 |
33 | ${project.name}
34 |
35 | This plugin provides the ability to use
36 | {{{https://github.com/pinterest/ktlint}ktlint}} to format and check your
37 | source code against the ktlint anti-bikeshedding code style.
38 |
39 | * Goals Overview
40 |
41 | * {{{./format-mojo.html}ktlint:format}} format your Kotlin sources
42 | using ktlint.
43 |
44 | * {{{./check-mojo.html}ktlint:check}} check your Kotlin sources for code style
45 | violations using ktlint.
46 |
47 | * {{{./ktlint-mojo.html}ktlint:ktlint}} generate project report of code style
48 | violations using ktlint.
49 |
50 | []
51 |
52 | * Usage
53 |
54 | General instructions on how to use the ktlint plugin can be found on the
55 | {{{./usage.html}usage page}}.
56 |
57 | * License
58 |
59 | This software is licensed under the terms in the file named "LICENSE" in the
60 | root directory of this project.
61 |
62 | * Author Information
63 |
64 | John Freeman
65 |
66 | GantSign Ltd.
67 | Company No. 06109112 (registered in England)
68 |
--------------------------------------------------------------------------------
/src/site/apt/usage.apt.vm:
--------------------------------------------------------------------------------
1 | ------
2 | Introduction
3 | ------
4 | John Freeman
5 | ------
6 | 2018-05-10
7 | ------
8 |
9 | ~~ #%L
10 | ~~ ktlint-maven-plugin
11 | ~~ %%
12 | ~~ Copyright (C) 2018 GantSign Ltd.
13 | ~~ %%
14 | ~~ Permission is hereby granted, free of charge, to any person obtaining a copy
15 | ~~ of this software and associated documentation files (the "Software"), to deal
16 | ~~ in the Software without restriction, including without limitation the rights
17 | ~~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 | ~~ copies of the Software, and to permit persons to whom the Software is
19 | ~~ furnished to do so, subject to the following conditions:
20 | ~~
21 | ~~ The above copyright notice and this permission notice shall be included in
22 | ~~ all copies or substantial portions of the Software.
23 | ~~
24 | ~~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 | ~~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 | ~~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 | ~~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 | ~~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 | ~~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 | ~~ THE SOFTWARE.
31 | ~~ #L%
32 |
33 | Usage
34 |
35 | Some brief examples on how to use this plugin.
36 |
37 | * Using Java 17 and later
38 |
39 | Java 17 is the first LTS release to enforce strong encapsulation. For
40 | <<>> to work we need to add
41 | <<<--add-opens java.base/java.lang=ALL-UNNAMED>>> to the JVM arguments.
42 |
43 | We recommend that you add a <<<.mvn/jvm.config>>> file (relative to the top
44 | level project directory) to all of your projects using this plugin. The file
45 | should have the following contents:
46 |
47 | +----------+
48 | --add-opens java.base/java.lang=ALL-UNNAMED
49 | +----------+
50 |
51 | We also recommend adding this to all of your projects using this plugin and
52 | building with Java 11, as it'll suppress an illegal-access warning during the
53 | build.
54 |
55 | For other options see: {{https://maven.apache.org/configure.html}}
56 |
57 | * Formatting and checking for violations as part of the build
58 |
59 | Probably the most common use case is to want to both format and check your
60 | code; add the following plugin configuration to your POM.
61 |
62 | +----------+
63 |
64 |
65 | ...
66 |
67 | com.github.gantsign.maven
68 | ktlint-maven-plugin
69 | ${project.version}
70 |
71 |
72 | format-and-check
73 |
74 | format
75 | check
76 |
77 |
78 |
79 |
80 | ...
81 |
82 |
83 | +----------+
84 |
85 | * Formatting as part of the build
86 |
87 | If you just want ktlint to automatically fix what it can, add the following
88 | plugin configuration to your POM.
89 |
90 | +----------+
91 |
92 |
93 | ...
94 |
95 | com.github.gantsign.maven
96 | ktlint-maven-plugin
97 | ${project.version}
98 |
99 |
100 | format
101 |
102 | format
103 |
104 |
105 |
106 |
107 | ...
108 |
109 |
110 | +----------+
111 |
112 | To run this from the command line (without adding the plugin to your POM) you
113 | can run the following from your console:
114 |
115 | +----------+
116 | mvn ${project.groupId}:${project.artifactId}:${project.version}:format
117 | +----------+
118 |
119 | * Checking for violations as part of the build
120 |
121 | If you just want to drill good habits into your developers, add the following
122 | plugin configuration to your POM.
123 |
124 | +----------+
125 |
126 |
127 | ...
128 |
129 | com.github.gantsign.maven
130 | ktlint-maven-plugin
131 | ${project.version}
132 |
133 |
134 | check
135 |
136 | check
137 |
138 |
139 |
140 |
141 | ...
142 |
143 |
144 | +----------+
145 |
146 | To run this from the command line (without adding the plugin to your POM) you
147 | can run the following from your console:
148 |
149 | +----------+
150 | mvn ${project.groupId}:${project.artifactId}:${project.version}:check
151 | +----------+
152 |
153 | * Generate ktlint report as part of the project reports
154 |
155 | To generate the ktlint report as part of the project reports, add the ktlint
156 | plugin in the <<<\>>> section of your POM.
157 |
158 | +----------+
159 |
160 |
161 |
162 | ...
163 |
164 | org.apache.maven.plugins
165 | maven-site-plugin
166 |
167 | 3.7.1
168 |
169 | ...
170 |
171 |
172 |
173 |
174 |
175 |
176 | ...
177 |
178 | com.github.gantsign.maven
179 | ktlint-maven-plugin
180 | ${project.version}
181 |
182 | ...
183 |
184 |
185 | +----------+
186 |
187 | * Using ktlint reporters as part of the build
188 |
189 | As well as Maven project reports that are part of the Maven site (see above)
190 | this plugin also supports ktlint reporters:
191 |
192 | +----------+
193 |
194 |
195 | ...
196 |
197 | com.github.gantsign.maven
198 | ktlint-maven-plugin
199 | ${project.version}
200 |
201 |
202 | reporter
203 |
204 | check
205 |
206 |
207 | false
208 |
209 |
210 | plain
211 |
212 |
213 |
214 | group_by_file
215 | true
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 | ...
225 |
226 |
227 | +----------+
228 |
229 | The built in reporters are <<>>, <<>> and <<>>. You
230 | can also provide a customer reporter (see
231 | {{https://github.com/pinterest/ktlint}} for details); to use a custom reporter
232 | it needs to be added as a Maven dependency to the Maven plugin e.g.:
233 |
234 | +----------+
235 |
236 |
237 | ...
238 |
239 | com.github.gantsign.maven
240 | ktlint-maven-plugin
241 | ${project.version}
242 |
243 |
244 | check
245 |
246 | check
247 |
248 |
249 | false
250 |
251 |
252 | my-custom-reporter
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 | com.example
262 | my-custom-reporter
263 | 1.0
264 |
265 |
266 |
267 | ...
268 |
269 |
270 | +----------+
271 |
--------------------------------------------------------------------------------
/src/site/resources/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gantsign/ktlint-maven-plugin/25404c74d18dfe1c037f487d5eb15bb1b5216cbd/src/site/resources/.nojekyll
--------------------------------------------------------------------------------
/src/site/site.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
32 |
33 |
34 | org.apache.maven.skins
35 | maven-fluido-skin
36 | 1.5
37 |
38 |
39 |
40 |
41 | false
42 | true
43 |
44 |
45 | gantsign/ktlint-maven-plugin
46 | right
47 | black
48 |
49 |
50 |
51 |
52 |
53 | ktlint Maven Plugin
54 | index.html
55 |
56 |
57 |
58 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/src/test/kotlin/com/github/gantsign/maven/plugin/ktlint/FormatMojoTest.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import io.mockk.confirmVerified
29 | import io.mockk.mockk
30 | import io.mockk.verify
31 | import java.io.File
32 | import org.apache.maven.plugin.logging.Log
33 | import org.apache.maven.plugin.testing.MojoRule
34 | import org.assertj.core.api.Assertions.assertThat
35 | import org.junit.Rule
36 | import org.junit.Test
37 |
38 | class FormatMojoTest {
39 |
40 | @Rule
41 | @JvmField
42 | var rule = MojoRule()
43 |
44 | private val source = File("src/main/kotlin/example/Example.kt").path
45 | private val scriptSource = File("src/main/kotlin/example/Example.kts").path
46 | private val mainRoot = File("src/main/kotlin").path
47 | private val testRoot = File("src/test/kotlin").path
48 |
49 | @Test
50 | fun happy() {
51 | val pom = File("target/test-scenarios/format-happy/pom.xml")
52 |
53 | assertThat(pom.isFile).isTrue()
54 |
55 | val project = rule.readMavenProject(pom.parentFile)
56 |
57 | val formatMojo = rule.lookupConfiguredMojo(project, "format") as FormatMojo
58 |
59 | val log = mockk(relaxed = true)
60 | formatMojo.log = log
61 |
62 | assertThat(formatMojo).isNotNull
63 | formatMojo.execute()
64 |
65 | verify(atLeast = 1) { log.isDebugEnabled }
66 | verify { log.debug("checking format: $source") }
67 | verify { log.debug("Format fixed > $source:1:1: Unnecessary semicolon") }
68 | verify {
69 | log.debug(
70 | "Format fixed > $source:29:13: Line is exceeding max line length. Break line before expression",
71 | )
72 | }
73 | verify {
74 | log.debug(
75 | "Format fixed > $source:29:47: Line is exceeding max line length. Break line after '+' " +
76 | "in binary expression",
77 | )
78 | }
79 | verify { log.debug("Format fixed > $source:30:19: Missing newline before \")\"") }
80 | verify { log.debug("Format fixed > $source:30:20: Missing trailing comma before \")\"") }
81 | verify { log.debug("Format fixed > $source") }
82 | verify { log.warn("Source root doesn't exist: $testRoot") }
83 | verify { log.info("1 file(s) formatted.") }
84 | confirmVerified(log)
85 | }
86 |
87 | @Test
88 | fun includeScripts() {
89 | val pom = File("target/test-scenarios/format-include-scripts/pom.xml")
90 |
91 | assertThat(pom.isFile).isTrue()
92 |
93 | val project = rule.readMavenProject(pom.parentFile)
94 |
95 | val formatMojo = rule.lookupConfiguredMojo(project, "format") as FormatMojo
96 |
97 | val log = mockk(relaxed = true)
98 | formatMojo.log = log
99 |
100 | assertThat(formatMojo).isNotNull
101 | formatMojo.execute()
102 |
103 | verify(atLeast = 1) { log.isDebugEnabled }
104 | verify { log.debug("checking format: $scriptSource") }
105 | verify { log.debug("Format fixed > $scriptSource:1:1: Unnecessary semicolon") }
106 | verify {
107 | log.debug(
108 | "Format fixed > $scriptSource:29:13: Line is exceeding max line length. Break line before expression",
109 | )
110 | }
111 | verify {
112 | log.debug(
113 | "Format fixed > $scriptSource:29:47: Line is exceeding max line length. Break line after '+' " +
114 | "in binary expression",
115 | )
116 | }
117 | verify { log.debug("Format fixed > $scriptSource:30:19: Missing newline before \")\"") }
118 | verify { log.debug("Format fixed > $scriptSource") }
119 | verify { log.warn("Source root doesn't exist: $testRoot") }
120 | verify { log.info("1 file(s) formatted.") }
121 | confirmVerified(log)
122 | }
123 |
124 | @Test
125 | fun rootNotFound() {
126 | val pom = File("target/test-scenarios/root-not-found/pom.xml")
127 |
128 | assertThat(pom.isFile).isTrue()
129 |
130 | val project = rule.readMavenProject(pom.parentFile)
131 |
132 | val formatMojo = rule.lookupConfiguredMojo(project, "format") as FormatMojo
133 |
134 | val log = mockk(relaxed = true)
135 | formatMojo.log = log
136 |
137 | assertThat(formatMojo).isNotNull
138 | formatMojo.execute()
139 |
140 | verify(atLeast = 1) { log.isDebugEnabled }
141 | verify { log.warn("Source root doesn't exist: $mainRoot") }
142 | verify { log.warn("Source root doesn't exist: $testRoot") }
143 | verify { log.info("0 file(s) formatted.") }
144 | confirmVerified(log)
145 | }
146 |
147 | @Test
148 | fun skip() {
149 | val pom = File("target/test-scenarios/format-skip/pom.xml")
150 |
151 | assertThat(pom.isFile).isTrue()
152 |
153 | val project = rule.readMavenProject(pom.parentFile)
154 |
155 | val formatMojo = rule.lookupConfiguredMojo(project, "format") as FormatMojo
156 |
157 | val log = mockk()
158 | formatMojo.log = log
159 |
160 | assertThat(formatMojo).isNotNull
161 | formatMojo.execute()
162 |
163 | confirmVerified(log)
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/src/test/kotlin/com/github/gantsign/maven/plugin/ktlint/KtlintReportTest.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint
27 |
28 | import io.mockk.confirmVerified
29 | import io.mockk.every
30 | import io.mockk.mockk
31 | import io.mockk.verify
32 | import java.io.File
33 | import java.util.Locale
34 | import org.apache.maven.plugin.logging.Log
35 | import org.apache.maven.plugin.testing.MojoRule
36 | import org.assertj.core.api.Assertions.assertThat
37 | import org.junit.Rule
38 | import org.junit.Test
39 |
40 | class KtlintReportTest {
41 |
42 | @Rule
43 | @JvmField
44 | var rule = MojoRule()
45 |
46 | @Test
47 | fun hasErrors() {
48 | val pom = File("target/test-scenarios/check-with-errors/pom.xml")
49 |
50 | assertThat(pom.isFile).isTrue()
51 |
52 | val project = rule.readMavenProject(pom.parentFile)
53 |
54 | val ktlintReport = rule.lookupConfiguredMojo(project, "ktlint") as KtlintReport
55 |
56 | val log = mockk(relaxed = true)
57 | ktlintReport.log = log
58 | every { log.isDebugEnabled } returns true
59 |
60 | assertThat(ktlintReport).isNotNull
61 |
62 | ktlintReport.execute()
63 |
64 | verify(atLeast = 1) { log.isDebugEnabled }
65 | verify { log.debug("Discovered RuleSetProviderV3 'RuleSetId(value=standard)'") }
66 | verify { log.debug("Discovered reporter 'maven'") }
67 | verify { log.debug("Discovered reporter 'baseline'") }
68 | verify { log.debug("Discovered reporter 'plain'") }
69 | verify { log.debug("Discovered reporter 'json'") }
70 | verify { log.debug("Discovered reporter 'checkstyle'") }
71 | verify { log.debug("checking: src/main/kotlin/example/Example.kt") }
72 | verify { log.debug("Style error > src/main/kotlin/example/Example.kt:29:39: Unnecessary semicolon") }
73 | verify { log.warn("Source root doesn't exist: src/test/kotlin") }
74 | confirmVerified(log)
75 | }
76 |
77 | @Test
78 | fun rootNotFound() {
79 | val pom = File("target/test-scenarios/root-not-found/pom.xml")
80 |
81 | assertThat(pom.isFile).isTrue()
82 |
83 | val project = rule.readMavenProject(pom.parentFile)
84 |
85 | val ktlintReport = rule.lookupConfiguredMojo(project, "ktlint") as KtlintReport
86 |
87 | val log = mockk()
88 | ktlintReport.log = log
89 |
90 | assertThat(ktlintReport).isNotNull
91 | ktlintReport.execute()
92 |
93 | confirmVerified(log)
94 | }
95 |
96 | @Test
97 | fun skip() {
98 | val pom = File("target/test-scenarios/check-skip/pom.xml")
99 |
100 | assertThat(pom.isFile).isTrue()
101 |
102 | val project = rule.readMavenProject(pom.parentFile)
103 |
104 | val ktlintReport = rule.lookupConfiguredMojo(project, "ktlint") as KtlintReport
105 |
106 | val log = mockk()
107 | ktlintReport.log = log
108 |
109 | assertThat(ktlintReport).isNotNull
110 | ktlintReport.execute()
111 |
112 | confirmVerified(log)
113 | }
114 |
115 | @Test
116 | fun getName() {
117 | val pom = File("target/test-scenarios/check-with-errors/pom.xml")
118 |
119 | assertThat(pom.isFile).isTrue()
120 |
121 | val project = rule.readMavenProject(pom.parentFile)
122 |
123 | val ktlintReport = rule.lookupConfiguredMojo(project, "ktlint") as KtlintReport
124 |
125 | assertThat(ktlintReport.getName(Locale.ENGLISH)).isEqualTo("Ktlint")
126 | }
127 |
128 | @Test
129 | fun getDescription() {
130 | val pom = File("target/test-scenarios/check-with-errors/pom.xml")
131 |
132 | assertThat(pom.isFile).isTrue()
133 |
134 | val project = rule.readMavenProject(pom.parentFile)
135 |
136 | val ktlintReport = rule.lookupConfiguredMojo(project, "ktlint") as KtlintReport
137 |
138 | assertThat(ktlintReport.getDescription(Locale.ENGLISH)).isEqualTo("Report on coding style conventions.")
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/test/kotlin/com/github/gantsign/maven/plugin/ktlint/internal/FunctionsKtTest.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 - 2023 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package com.github.gantsign.maven.plugin.ktlint.internal
27 |
28 | import com.pinterest.ktlint.cli.reporter.core.api.KtlintCliError
29 | import com.pinterest.ktlint.rule.engine.api.Code
30 | import com.pinterest.ktlint.rule.engine.api.KtLintParseException
31 | import com.pinterest.ktlint.rule.engine.api.KtLintRuleException
32 | import io.mockk.every
33 | import io.mockk.mockk
34 | import org.assertj.core.api.Assertions.assertThat
35 | import org.assertj.core.api.Assertions.assertThatThrownBy
36 | import org.junit.Test
37 |
38 | class FunctionsKtTest {
39 |
40 | @Test
41 | fun toKtlintCliError_KtLintParseException() {
42 | val parseException = KtLintParseException(line = 10, col = 15, message = "Test exception")
43 |
44 | val code = mockk()
45 | every { code.fileNameOrStdin() } returns "Test.kt"
46 |
47 | val result = parseException.toKtlintCliError(code)
48 |
49 | assertThat(result.line).isEqualTo(10)
50 | assertThat(result.col).isEqualTo(15)
51 | assertThat(result.ruleId).isEqualTo("")
52 | assertThat(result.detail).isEqualTo("Not a valid Kotlin file (10:15 test exception)")
53 | assertThat(result.status).isEqualTo(KtlintCliError.Status.KOTLIN_PARSE_EXCEPTION)
54 | }
55 |
56 | @Test
57 | fun toKtlintCliError_KtLintRuleException() {
58 | val ruleException = KtLintRuleException(
59 | line = 5,
60 | col = 20,
61 | ruleId = "testRule",
62 | message = "Rule exception",
63 | cause = IllegalArgumentException(),
64 | )
65 |
66 | val code = mockk()
67 | every { code.fileNameOrStdin() } returns "Test.kt"
68 |
69 | val result = ruleException.toKtlintCliError(code)
70 |
71 | assertThat(result.line).isEqualTo(5)
72 | assertThat(result.col).isEqualTo(20)
73 | assertThat(result.ruleId).isEqualTo("")
74 | assertThat(result.detail).startsWith("Internal Error (rule 'testRule') in Test.kt at position '5:20")
75 | assertThat(result.status).isEqualTo(KtlintCliError.Status.KTLINT_RULE_ENGINE_EXCEPTION)
76 | }
77 |
78 | @Test
79 | fun toKtlintCliError_otherException() {
80 | val exception = IllegalArgumentException("Invalid argument")
81 |
82 | val code = mockk()
83 | every { code.fileNameOrStdin() } returns "Test.kt"
84 |
85 | assertThatThrownBy { exception.toKtlintCliError(code) }.isEqualTo(exception)
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-group-by-file/.editorconfig:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | # EditorConfig: http://EditorConfig.org
27 |
28 | # Top-most EditorConfig file
29 | root = true
30 |
31 | # Defaults for all editor files
32 | [*]
33 | insert_final_newline = true
34 | indent_style = space
35 | indent_size = 4
36 | continuation_indent_size = 8
37 | trim_trailing_whitespace = true
38 | max_line_length=120
39 |
40 | # YAML is fussy about indenting and charset
41 | [*.yml]
42 | indent_style = space
43 | indent_size = 2
44 | continuation_indent_size = unset
45 | charset = utf-8
46 |
47 | # YAML is fussy about indenting
48 | [*.md]
49 | indent_style = space
50 | indent_size = 4
51 | trim_trailing_whitespaces = false
52 |
53 | # Follow Kotlin Coding Conventions
54 | [*.{kt,kts}]
55 | indent_size=4
56 | continuation_indent_size=4
57 | charset = utf-8
58 |
59 | # Files with a smaller indent
60 | [*.{java,xml}]
61 | indent_size = 2
62 | continuation_indent_size = 4
63 |
64 | # Java file encoding
65 | [*.java]
66 | charset = utf-8
67 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-group-by-file/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | UTF-8
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | com.github.gantsign.maven
47 | ktlint-maven-plugin
48 |
49 |
50 |
51 | maven
52 |
53 |
54 | group_by_file
55 | true
56 |
57 |
58 | verbose
59 | true
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-group-by-file/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-output-file/.editorconfig:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | # EditorConfig: http://EditorConfig.org
27 |
28 | # Top-most EditorConfig file
29 | root = true
30 |
31 | # Defaults for all editor files
32 | [*]
33 | insert_final_newline = true
34 | indent_style = space
35 | indent_size = 4
36 | continuation_indent_size = 8
37 | trim_trailing_whitespace = true
38 | max_line_length=120
39 |
40 | # YAML is fussy about indenting and charset
41 | [*.yml]
42 | indent_style = space
43 | indent_size = 2
44 | continuation_indent_size = unset
45 | charset = utf-8
46 |
47 | # YAML is fussy about indenting
48 | [*.md]
49 | indent_style = space
50 | indent_size = 4
51 | trim_trailing_whitespaces = false
52 |
53 | # Follow Kotlin Coding Conventions
54 | [*.{kt,kts}]
55 | indent_size=4
56 | continuation_indent_size=4
57 | charset = utf-8
58 |
59 | # Files with a smaller indent
60 | [*.{java,xml}]
61 | indent_size = 2
62 | continuation_indent_size = 4
63 |
64 | # Java file encoding
65 | [*.java]
66 | charset = utf-8
67 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-output-file/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | UTF-8
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | com.github.gantsign.maven
47 | ktlint-maven-plugin
48 |
49 |
50 |
51 | json
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-output-file/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-output-file/src/test/kotlin/example/TestExample.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun testExample() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-proceed-with-errors/.editorconfig:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | # EditorConfig: http://EditorConfig.org
27 |
28 | # Top-most EditorConfig file
29 | root = true
30 |
31 | # Defaults for all editor files
32 | [*]
33 | insert_final_newline = true
34 | indent_style = space
35 | indent_size = 4
36 | continuation_indent_size = 8
37 | trim_trailing_whitespace = true
38 | max_line_length=120
39 |
40 | # YAML is fussy about indenting and charset
41 | [*.yml]
42 | indent_style = space
43 | indent_size = 2
44 | continuation_indent_size = unset
45 | charset = utf-8
46 |
47 | # YAML is fussy about indenting
48 | [*.md]
49 | indent_style = space
50 | indent_size = 4
51 | trim_trailing_whitespaces = false
52 |
53 | # Follow Kotlin Coding Conventions
54 | [*.{kt,kts}]
55 | indent_size=4
56 | continuation_indent_size=4
57 | charset = utf-8
58 |
59 | # Files with a smaller indent
60 | [*.{java,xml}]
61 | indent_size = 2
62 | continuation_indent_size = 4
63 |
64 | # Java file encoding
65 | [*.java]
66 | charset = utf-8
67 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-proceed-with-errors/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | UTF-8
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | com.github.gantsign.maven
47 | ktlint-maven-plugin
48 |
49 | false
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-proceed-with-errors/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-skip/.editorconfig:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | # EditorConfig: http://EditorConfig.org
27 |
28 | # Top-most EditorConfig file
29 | root = true
30 |
31 | # Defaults for all editor files
32 | [*]
33 | insert_final_newline = true
34 | indent_style = space
35 | indent_size = 4
36 | continuation_indent_size = 8
37 | trim_trailing_whitespace = true
38 | max_line_length=120
39 |
40 | # YAML is fussy about indenting and charset
41 | [*.yml]
42 | indent_style = space
43 | indent_size = 2
44 | continuation_indent_size = unset
45 | charset = utf-8
46 |
47 | # YAML is fussy about indenting
48 | [*.md]
49 | indent_style = space
50 | indent_size = 4
51 | trim_trailing_whitespaces = false
52 |
53 | # Follow Kotlin Coding Conventions
54 | [*.{kt,kts}]
55 | indent_size=4
56 | continuation_indent_size=4
57 | charset = utf-8
58 |
59 | # Files with a smaller indent
60 | [*.{java,xml}]
61 | indent_size = 2
62 | continuation_indent_size = 4
63 |
64 | # Java file encoding
65 | [*.java]
66 | charset = utf-8
67 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-skip/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | UTF-8
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | com.github.gantsign.maven
47 | ktlint-maven-plugin
48 |
49 | true
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-skip/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-with-errors/.editorconfig:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | # EditorConfig: http://EditorConfig.org
27 |
28 | # Top-most EditorConfig file
29 | root = true
30 |
31 | # Defaults for all editor files
32 | [*]
33 | insert_final_newline = true
34 | indent_style = space
35 | indent_size = 4
36 | continuation_indent_size = 8
37 | trim_trailing_whitespace = true
38 | max_line_length=120
39 |
40 | # YAML is fussy about indenting and charset
41 | [*.yml]
42 | indent_style = space
43 | indent_size = 2
44 | continuation_indent_size = unset
45 | charset = utf-8
46 |
47 | # YAML is fussy about indenting
48 | [*.md]
49 | indent_style = space
50 | indent_size = 4
51 | trim_trailing_whitespaces = false
52 |
53 | # Follow Kotlin Coding Conventions
54 | [*.{kt,kts}]
55 | indent_size=4
56 | continuation_indent_size=4
57 | charset = utf-8
58 |
59 | # Files with a smaller indent
60 | [*.{java,xml}]
61 | indent_size = 2
62 | continuation_indent_size = 4
63 |
64 | # Java file encoding
65 | [*.java]
66 | charset = utf-8
67 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-with-errors/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | UTF-8
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | com.github.gantsign.maven
47 | ktlint-maven-plugin
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/test/scenarios/check-with-errors/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("should remove semicolon");
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-happy/.editorconfig:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | # EditorConfig: http://EditorConfig.org
27 |
28 | # Top-most EditorConfig file
29 | root = true
30 |
31 | # Defaults for all editor files
32 | [*]
33 | insert_final_newline = true
34 | indent_style = space
35 | indent_size = 4
36 | continuation_indent_size = 8
37 | trim_trailing_whitespace = true
38 | max_line_length=80
39 |
40 | # YAML is fussy about indenting and charset
41 | [*.yml]
42 | indent_style = space
43 | indent_size = 2
44 | continuation_indent_size = unset
45 | charset = utf-8
46 |
47 | # YAML is fussy about indenting
48 | [*.md]
49 | indent_style = space
50 | indent_size = 4
51 | trim_trailing_whitespaces = false
52 |
53 | # Follow Kotlin Coding Conventions
54 | [*.{kt,kts}]
55 | indent_size=4
56 | continuation_indent_size=4
57 | charset = utf-8
58 |
59 | # Files with a smaller indent
60 | [*.{java,xml}]
61 | indent_size = 2
62 | continuation_indent_size = 4
63 |
64 | # Java file encoding
65 | [*.java]
66 | charset = utf-8
67 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-happy/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | UTF-8
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | com.github.gantsign.maven
47 | ktlint-maven-plugin
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-happy/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("this line is too long" + "............................................................")
30 | println("should remove semicolon");
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-include-scripts/.editorconfig:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | # EditorConfig: http://EditorConfig.org
27 |
28 | # Top-most EditorConfig file
29 | root = true
30 |
31 | # Defaults for all editor files
32 | [*]
33 | insert_final_newline = true
34 | indent_style = space
35 | indent_size = 4
36 | continuation_indent_size = 8
37 | trim_trailing_whitespace = true
38 | max_line_length=80
39 |
40 | # YAML is fussy about indenting and charset
41 | [*.yml]
42 | indent_style = space
43 | indent_size = 2
44 | continuation_indent_size = unset
45 | charset = utf-8
46 |
47 | # YAML is fussy about indenting
48 | [*.md]
49 | indent_style = space
50 | indent_size = 4
51 | trim_trailing_whitespaces = false
52 |
53 | # Follow Kotlin Coding Conventions
54 | [*.{kt,kts}]
55 | indent_size=4
56 | continuation_indent_size=4
57 | charset = utf-8
58 | ktlint_standard_trailing-comma-on-call-site = disabled
59 |
60 | # Files with a smaller indent
61 | [*.{java,xml}]
62 | indent_size = 2
63 | continuation_indent_size = 4
64 |
65 | # Java file encoding
66 | [*.java]
67 | charset = utf-8
68 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-include-scripts/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | UTF-8
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | com.github.gantsign.maven
47 | ktlint-maven-plugin
48 |
49 |
50 | **/*.kts
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-include-scripts/src/main/kotlin/example/Example.kts:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("this line is too long" + "............................................................")
30 | println("should remove semicolon");
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-skip/.editorconfig:
--------------------------------------------------------------------------------
1 | ###
2 | # #%L
3 | # ktlint-maven-plugin
4 | # %%
5 | # Copyright (C) 2018 GantSign Ltd.
6 | # %%
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy
8 | # of this software and associated documentation files (the "Software"), to deal
9 | # in the Software without restriction, including without limitation the rights
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | # copies of the Software, and to permit persons to whom the Software is
12 | # furnished to do so, subject to the following conditions:
13 | #
14 | # The above copyright notice and this permission notice shall be included in
15 | # all copies or substantial portions of the Software.
16 | #
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | # THE SOFTWARE.
24 | # #L%
25 | ###
26 | # EditorConfig: http://EditorConfig.org
27 |
28 | # Top-most EditorConfig file
29 | root = true
30 |
31 | # Defaults for all editor files
32 | [*]
33 | insert_final_newline = true
34 | indent_style = space
35 | indent_size = 4
36 | continuation_indent_size = 8
37 | trim_trailing_whitespace = true
38 | max_line_length=120
39 |
40 | # YAML is fussy about indenting and charset
41 | [*.yml]
42 | indent_style = space
43 | indent_size = 2
44 | continuation_indent_size = unset
45 | charset = utf-8
46 |
47 | # YAML is fussy about indenting
48 | [*.md]
49 | indent_style = space
50 | indent_size = 4
51 | trim_trailing_whitespaces = false
52 |
53 | # Follow Kotlin Coding Conventions
54 | [*.{kt,kts}]
55 | indent_size=4
56 | continuation_indent_size=4
57 | charset = utf-8
58 |
59 | # Files with a smaller indent
60 | [*.{java,xml}]
61 | indent_size = 2
62 | continuation_indent_size = 4
63 |
64 | # Java file encoding
65 | [*.java]
66 | charset = utf-8
67 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-skip/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | UTF-8
39 |
40 |
41 |
42 | src/main/kotlin
43 | src/test/kotlin
44 |
45 |
46 | com.github.gantsign.maven
47 | ktlint-maven-plugin
48 |
49 | true
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/test/scenarios/format-skip/src/main/kotlin/example/Example.kt:
--------------------------------------------------------------------------------
1 | /*-
2 | * #%L
3 | * ktlint-maven-plugin
4 | * %%
5 | * Copyright (C) 2018 GantSign Ltd.
6 | * %%
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in
15 | * all copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | * THE SOFTWARE.
24 | * #L%
25 | */
26 | package example
27 |
28 | fun example() {
29 | println("this line is too long" + "............................................................")
30 | println("should remove semicolon");
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/scenarios/root-not-found/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
27 |
28 |
31 | 4.0.0
32 |
33 | com.example
34 | test-project
35 | 0.0.0-SNAPSHOT
36 |
37 |
38 | src/main/kotlin
39 | src/test/kotlin
40 |
41 |
42 | com.github.gantsign.maven
43 | ktlint-maven-plugin
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------