Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to Gradle #1625

Merged
merged 59 commits into from
Mar 23, 2023
Merged
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
27897f0
Use gradle for project build
petertrr Dec 28, 2020
c22b18b
Use gradle for project build
petertrr Jan 13, 2021
55d6d6f
Use gradle for project build
petertrr Jan 13, 2021
ff83821
Merge remote-tracking branch 'origin/master' into feature/migrate-to-…
petertrr Jan 13, 2021
c975f81
Move project build to gradle
petertrr Jan 13, 2021
33c8d9d
Move project build to gradle
petertrr Jan 13, 2021
b6f703b
Migration to Gradle
nulls Mar 14, 2023
3536bf7
finished a basic migration to gradle
nulls Mar 15, 2023
c176b27
Merge branch 'master' into feature/migrate-to-gradle-2
nulls Mar 15, 2023
b114680
downgrade gradle
nulls Mar 15, 2023
c5401f6
added ksp to generate enum names
nulls Mar 15, 2023
45ca514
reverted unused changes
nulls Mar 15, 2023
9b519f9
reverted unused changes with WarningNames
nulls Mar 15, 2023
d5bb2e4
moved updating copyright year to gradle
nulls Mar 15, 2023
a37789f
migrated maven plugin
nulls Mar 15, 2023
e7cb0ca
disabled explicit setting a goal prefix
nulls Mar 15, 2023
4440904
upgraded ksp
nulls Mar 15, 2023
a7e9fdc
removed pom.xml and fixed PublishingConfiguration
nulls Mar 15, 2023
a80649f
fixed review notes
nulls Mar 16, 2023
269e10d
upgraded itf version
nulls Mar 16, 2023
c95cc12
formatting
nulls Mar 16, 2023
e2e2ba0
fixed package name for gradle/plugins
nulls Mar 16, 2023
87bee78
Merge branch 'master' into feature/migrate-to-gradle-2
nulls Mar 16, 2023
5b81349
Merge remote-tracking branch 'origin/feature/migrate-to-gradle' into …
nulls Mar 16, 2023
deecffa
fixed github action
nulls Mar 16, 2023
bf95ef0
fixed github action
nulls Mar 16, 2023
4674e27
make github executable
nulls Mar 16, 2023
31ede40
downgraded java version
nulls Mar 16, 2023
857e7f2
cleanup VersioningConfiguration.kt
nulls Mar 16, 2023
ca60c8e
fixed detekt to use gradle
nulls Mar 16, 2023
23c3707
fixed diktat-dev-ksp
nulls Mar 16, 2023
8d2df4c
disabled spotless
nulls Mar 16, 2023
509973d
added annotation for ksp
nulls Mar 16, 2023
0429267
Merge branch 'master' into feature/migrate-to-gradle-2
nulls Mar 16, 2023
493825b
fixed a path to fat jar
nulls Mar 16, 2023
7325d3c
Merge remote-tracking branch 'origin/feature/migrate-to-gradle-2' int…
nulls Mar 16, 2023
6d333d5
extracted githook installation
nulls Mar 16, 2023
e2e2012
disabled spotless plugin
nulls Mar 16, 2023
0e0b3b4
added shadow plugin
nulls Mar 16, 2023
f156684
removed spotlessKotlin
nulls Mar 16, 2023
f8c0307
disabled tests for maven
nulls Mar 16, 2023
dbb2b83
WIP
nulls Mar 17, 2023
d564f37
Merge remote-tracking branch 'origin/feature/migrate-to-gradle-2' int…
nulls Mar 17, 2023
f6561f7
removed spotless
nulls Mar 20, 2023
e1b3fd5
Merge remote-tracking branch 'origin/master' into feature/migrate-to-…
nulls Mar 20, 2023
c564f4c
updated .gitignore
nulls Mar 20, 2023
77a8599
WIP
nulls Mar 20, 2023
03641f6
WIP
nulls Mar 22, 2023
a5161cd
fixed shadowJar
nulls Mar 23, 2023
7ad9757
updated detekt.yml, diktat.yml and codeql-analysis.yml
nulls Mar 23, 2023
08620fb
update diktat_snapshot.yml
nulls Mar 23, 2023
69f3f0d
added codecov to common build
nulls Mar 23, 2023
043ed6b
upgraded diktat and fixed detekt issues
nulls Mar 23, 2023
2437a7f
setup snapshot diktat check
nulls Mar 23, 2023
3f9294e
diktatFix
nulls Mar 23, 2023
f260fe3
diktatFix
nulls Mar 23, 2023
327f07b
fixed a path to artifact of diktat-*.jar
nulls Mar 23, 2023
06c35d2
Merge remote-tracking branch 'origin/master' into feature/migrate-to-…
nulls Mar 23, 2023
289ed17
supported changes after merge
nulls Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@ ij_smart_tabs = false
ij_visual_guides = 80,120,180
ij_wrap_on_typing = false

[{*.yaml,*.yml}]
indent_size = 2

[{*.kt,*.kts}]
ij_kotlin_align_in_columns_case_branch = false
ij_kotlin_align_multiline_binary_operation = false
139 changes: 87 additions & 52 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
@@ -7,47 +7,67 @@ on:
branches:
- 'master'

concurrency:
# https://docs.github.com/en/actions/using-jobs/using-concurrency
# The latest queued workflow is preferred; the ones already in progress get cancelled
# Workflows on master branch shouldn't be cancelled, that's why they are identified by commit SHA
group: ${{ github.ref == 'refs/heads/master' && format('{0}-{1}', github.workflow, github.sha) || format('{0}-{1}', github.workflow, github.ref) }}
cancel-in-progress: true

jobs:
build_and_test_with_code_coverage:
name: Build, test and upload code coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
# required for correct codecov upload
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
- name: Cache local Maven repository
distribution: temurin
- name: Retrieve Kotlin version
run: |
kv=$(cat gradle/libs.versions.toml | grep '^kotlin =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KOTLIN_VERSION=$kv >> $GITHUB_ENV
shell: bash
- name: Cache konan
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: maven-build-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-build-
- name: Maven Install
run: mvn -B -Dstyle.color=always clean install
- name: Code coverage report
uses: codecov/codecov-action@v3
path: ~/.konan
key: ${{ runner.os }}-gradle-konan-${{ env.KOTLIN_VERSION }}
- name: Build all
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
arguments: |
build
-x detekt
--scan
--build-cache
- name: Upload gradle reports
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
files: '**/target/site/jacoco*/jacoco.xml,**/reports/jacoco/**/*.xml'
flags: unittests
fail_ci_if_error: true # optional (default = false)
name: gradle-reports
path: '**/build/reports/'
retention-days: 1
- name: Upload diktat jar
uses: actions/upload-artifact@v3
with:
name: diktat-ruleset
path: diktat-ruleset/target/diktat-*.jar
path: diktat-ruleset/build/libs/diktat-*.jar
# no need to store artifact longer, it is used only by dependant jobs
retention-days: 1
- name: Upload gradle reports
if: ${{ failure() }}
uses: actions/upload-artifact@v3
- name: Code coverage report
uses: codecov/codecov-action@v3
with:
name: gradle-test-report-${{ runner.os }}
path: 'diktat-gradle-plugin/build/reports/'
retention-days: 1
fail_ci_if_error: false

run_diktat_from_CLI:
name: Run diktat via CLI
@@ -60,10 +80,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup environment variables

- name: Retrieve Ktlint version
run: |
cat pom.xml | grep "<version>.*</version>" | head -1 | awk -F'[><]' '{ printf "DIKTAT_VERSION=%s\n",$3 }' >> $GITHUB_ENV
cat pom.xml | grep "<ktlint.version>.*</ktlint.version>" | head -1 | awk -F'[><]' '{ printf "KTLINT_VERSION=%s\n",$3 }' >> $GITHUB_ENV
ktlint_version=$(cat gradle/libs.versions.toml | grep '^ktlint =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KTLINT_VERSION=$ktlint_version >> $GITHUB_ENV
shell: bash

- name: Setup environment
@@ -77,10 +98,16 @@ jobs:
with:
name: diktat-ruleset

- name: Retrieve diktat jar file name
run: |
filename=$(ls diktat-*.jar)
echo DIKTAT_JAR=$filename >> $GITHUB_ENV
shell: bash

- name: Run diKTat from cli
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard 'examples/maven/src/main/kotlin/Test.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard 'examples/maven/src/main/kotlin/Test.kt' &>out.txt
shell: bash

- name: Check output
@@ -94,14 +121,14 @@ jobs:
continue-on-error: true
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard "$PWD/examples/maven/src/main/kotlin/Test.kt" &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard "$PWD/examples/maven/src/main/kotlin/Test.kt" &>out.txt
shell: bash

- name: Run diKTat from cli on windows (absolute paths)
continue-on-error: true
if: runner.os == 'Windows'
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard "%cd%/examples/maven/src/main/kotlin/Test.kt" > out.txt 2>&1
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard "%cd%/examples/maven/src/main/kotlin/Test.kt" > out.txt 2>&1
shell: cmd

- name: Check output (absolute paths)
@@ -114,7 +141,7 @@ jobs:
- name: Run diKTat from cli (glob paths, 1 of 4)
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard 'examples/maven/src/main/kotlin/*.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard 'examples/maven/src/main/kotlin/*.kt' &>out.txt
shell: bash

- name: Check output (glob paths, 1 of 4)
@@ -127,7 +154,7 @@ jobs:
- name: Run diKTat from cli (glob paths, 2 of 4)
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard 'examples/**/main/kotlin/*.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard 'examples/**/main/kotlin/*.kt' &>out.txt
shell: bash

- name: Check output (glob paths, 2 of 4)
@@ -140,7 +167,7 @@ jobs:
- name: Run diKTat from cli (glob paths, 3 of 4)
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard 'examples/**/*.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard 'examples/**/*.kt' &>out.txt
shell: bash

- name: Check output (glob paths, 3 of 4)
@@ -153,7 +180,7 @@ jobs:
- name: Run diKTat from cli (glob paths, 4 of 4)
continue-on-error: true
run: |
java -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar --disabled_rules=standard '**/*.kt' &>out.txt
java -jar ktlint -R ${{ env.DIKTAT_JAR }} --disabled_rules=standard '**/*.kt' &>out.txt
shell: bash

- name: Check output (glob paths, 4 of 4)
@@ -171,7 +198,7 @@ jobs:
# test failures may be OS-specific (or the tests themselves flaky).
fail-fast: false
matrix:
os: [ windows-latest, macos-latest ]
os: [ ubuntu-latest, windows-latest, macos-latest ]

# A possible workaround for <https://github.com/dorny/test-reporter/issues/168>.
permissions:
@@ -182,30 +209,35 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
# required for correct codecov upload
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: maven-build-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-build-
- name: Maven Install
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
distribution: temurin
- name: Retrieve Kotlin version
run: |
mvn -B -Dstyle.color=always -T1C clean install
kv=$(cat gradle/libs.versions.toml | grep '^kotlin =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KOTLIN_VERSION=$kv >> $GITHUB_ENV
shell: bash
- name: Cache konan
uses: actions/cache@v3
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-konan-${{ env.KOTLIN_VERSION }}

- name: Maven Install on windows
if: runner.os == 'Windows'
run: |
mvn -B -Dstyle.color=always -T1C clean install
shell: cmd
- name: Build all
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
arguments: |
build
-x detekt
--scan
--build-cache
# This step needs a Git repository, so it's impossible to extract it
# into a separate job (or, otherwise, we'd need to upload the content
@@ -216,7 +248,7 @@ jobs:
with:
name: JUnit Tests (${{ runner.os }}, dorny/test-reporter@v1)
# Comma-separated values.
path: "**/target/*-reports/TEST-*.xml, **/build/test-results/*/TEST-*.xml"
path: "**/build/test-results/*/TEST-*.xml"
reporter: java-junit
# Ignore the "Resource not accessible by integration" error when a PR
# originates from a non-collaborator. This is
@@ -230,17 +262,20 @@ jobs:
with:
name: xml-test-reports-${{ runner.os }}
path: |
**/target/*-reports/TEST-*.xml
**/build/test-results/*/TEST-*.xml
retention-days: 1

- name: Upload gradle reports
if: ${{ failure() }}
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: gradle-test-report-${{ matrix.os }}
path: 'diktat-gradle-plugin/build/reports/'
path: '**/build/reports/'
retention-days: 1
- name: Code coverage report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false

report:
name: Publish JUnit test results
22 changes: 19 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ jobs:
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['java']
language: ['kotlin']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

@@ -58,8 +58,24 @@ jobs:
# and modify them (or add more) to build your code if your project
# uses a compiled language

- run: |
mvn clean install
- uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
# The `--continue` flag is necessary so that Gradle keeps going after the 1st test failure.
# By default, when test for all MPP targets are executed, Kotlin Gradle Plugin generates a single aggregated HTML report.
# Property `kotlin.tests.individualTaskReports` enables individual Junit-style XML reports.
# See org.jetbrains.kotlin.gradle.testing.internal.KotlinTestReport.
arguments: |
build
--continue
-x detekt
-Pkotlin.tests.individualTaskReports=true
-Porg.gradle.caching=true
-Pdetekt.multiplatform.disabled=true
-PdisableRedundantTargets=true
-PenabledExecutables=debug
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
39 changes: 26 additions & 13 deletions .github/workflows/detekt.yml
Original file line number Diff line number Diff line change
@@ -6,24 +6,37 @@ on:
pull_request:

jobs:
test:
name: Running detekt
runs-on: ubuntu-18.04
detekt_check:
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
- name: Cache local Maven repository
uses: actions/cache@v3
distribution: temurin
- uses: gradle/gradle-build-action@v2
with:
path: ~/.m2/repository
key: maven-detekt-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-detekt-
# when running detekt with type resolution, we need to have all project modules compiled too
- name: running deteKT
run: mvn -B compile dependency:build-classpath@detekt detekt:check@detekt -DskipPluginMarker
gradle-version: wrapper
arguments: |
detektAll
--build-cache
--continue
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
- name: Upload SARIF report to Github
uses: github/codeql-action/upload-sarif@v2
if: ${{ always() }}
with:
sarif_file: build/detekt-sarif-reports/detekt-merged.sarif
- name: Upload SARIF artifacts
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: sarif-reports
path: "**/build/detekt-sarif-reports/"
retention-days: 1
48 changes: 28 additions & 20 deletions .github/workflows/diktat.yml
Original file line number Diff line number Diff line change
@@ -8,31 +8,39 @@ on:

jobs:
diktat_check:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write

steps:
- uses: actions/checkout@v3
with:
# set this to 0 to fetch all tags too and be able to use them later
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
- name: Cache local Maven repository
uses: actions/cache@v3
distribution: temurin
- uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
diktatCheck
mergeDiktatReports
-Pdiktat.githubActions=true
-Pdetekt.multiplatform.disabled=true
--build-cache
--continue
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
- name: Upload SARIF report to Github
uses: github/codeql-action/upload-sarif@v2
if: ${{ always() }}
with:
sarif_file: build/reports/diktat/diktat-merged.sarif
- name: Upload SARIF artifacts
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
path: ~/.m2/repository
key: maven-diktat-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-diktat-
- name: Substitute diktat config with the one from the latest release
# fixme: can be done from the fetched repo without additional network request
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags --abbrev=0)
DIKTAT_CONFIG=diktat-analysis.yml
wget -O $DIKTAT_CONFIG https://raw.githubusercontent.com/saveourtool/diKTat/$LATEST_TAG/$DIKTAT_CONFIG
- name: Run diktat via maven plugin
run: mvn -B -Dstyle.color=always diktat:check@diktat -DskipPluginMarker
name: sarif-reports
path: "**/build/reports/diktat"
retention-days: 1
96 changes: 65 additions & 31 deletions .github/workflows/diktat_snapshot.yml
Original file line number Diff line number Diff line change
@@ -6,49 +6,83 @@ on:
pull_request:
branches: [ master ]

env:
GRADLE_OPTS: -Dorg.gradle.daemon=false

jobs:
diktat_snapshot_check:
runs-on: ubuntu-20.04
name: 'Check the project using diktat snapshot plugin'
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write

steps:
- uses: actions/checkout@v3
with:
# Fetch Git tags, so that semantic version can be calculated.
# Alternatively, run `git fetch --prune --unshallow --tags` as the
# next step, see
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
fetch-depth: 0

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
- name: Cache local Maven repository (shared with regular CI build)
distribution: temurin

- name: 'Cache ~/.konan'
id: cache-konan
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: maven-build-${{ hashFiles('**/pom.xml') }}
path: |
~/.konan
key: ${{ runner.os }}-konan-${{ hashFiles('**/*.gradle.kts', '**/gradle-wrapper.properties') }}-build-java${{ matrix.java-version }}
restore-keys: |
maven-build
- name: Set version
# Set project version which will then be used to run diktat from local maven repo.
# Base version is stored in env variable for later usage.
# Note: maven-help-plugin requires non-interactive mode (do not add -B flag).
run: |
snapshot_version=$(printf 'VERSION=${project.version}\n0\n' | mvn help:evaluate 2>/dev/null | grep '^VERSION' | cut -d= -f2)
base_version=${snapshot_version%-SNAPSHOT}
echo "BASE_VERSION=$base_version" >> $GITHUB_ENV
mvn -B versions:set -DnewVersion=$base_version-pre
- name: Build and install
# install diktat with version 'base_version-pre' to local maven repo
run: mvn -B -Dstyle.color=always clean install -DskipTests=true --projects diktat-maven-plugin --also-make
- name: Revert project version and set proper version for diktat check
# revert project version to avoid cycle dependency
# set diktat version in plugin dependencies to the version which was built in the previous step
run: |
mvn -B versions:set -DnewVersion=${{ env.BASE_VERSION }}-SNAPSHOT
mvn -B versions:set-property -Dproperty=diktat-check.version -DnewVersion=${{ env.BASE_VERSION }}-pre
- name: Run diktat snapshot via maven plugin
${{ runner.os }}-konan-${{ hashFiles('**/*.gradle.kts', '**/gradle-wrapper.properties') }}-
${{ runner.os }}-konan-
- name: 'Publish a snapshot version to local repo'
id: generateLibsForDiktatSnapshot
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
:diktat-common:publishToMavenLocal
:diktat-rules:publishToMavenLocal
:diktat-gradle-plugin:publishToMavenLocal
:generateLibsForDiktatSnapshot
-x detekt
-x diktatCheck
-x test
- name: 'Override <gradle/libs.versions.toml>'
run: |
mvn -B -X -Dstyle.color=always diktat:check@diktat -Ddiktat.debug=true -Ddiktat.githubActions=true
- name: Upload SARIF to Github using the upload-sarif action
mv gradle/libs.versions.toml gradle/libs.versions.toml_current
mv build/diktat-snapshot/libs.versions.toml_snapshot gradle/libs.versions.toml
# copied from .github/workflows/diktat.yml
- uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
diktatCheck
mergeDiktatReports
-Pdiktat.githubActions=true
-Pdetekt.multiplatform.disabled=true
--build-cache
--continue
-PgprUser=${{ github.actor }}
-PgprKey=${{ secrets.GITHUB_TOKEN }}
- name: Upload SARIF report to Github
uses: github/codeql-action/upload-sarif@v2
if: ${{ always() }}
with:
sarif_file: ${{ github.workspace }}
sarif_file: build/reports/diktat/diktat-merged.sarif
# override category to have a different with release version
category: diktat (snapshot)
- name: Upload SARIF artifacts
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: sarif-reports
path: "**/build/reports/diktat"
retention-days: 1
39 changes: 0 additions & 39 deletions .github/workflows/metrics_for_master.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -11,3 +11,6 @@ out/
*.swp

*.sarif

# a generated file for github action
/gradle/libs.versions.toml_snapshot
108 changes: 108 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import org.cqfn.diktat.buildutils.configureSigning
import org.jetbrains.kotlin.incremental.createDirectory
import java.nio.file.Files

@Suppress("DSL_SCOPE_VIOLATION", "RUN_IN_SCRIPT") // https://github.com/gradle/gradle/issues/22797
plugins {
id("org.cqfn.diktat.buildutils.versioning-configuration")
id("org.cqfn.diktat.buildutils.git-hook-configuration")
id("org.cqfn.diktat.buildutils.code-quality-convention")
id("org.cqfn.diktat.buildutils.publishing-configuration")
alias(libs.plugins.talaiot.base)
java
`maven-publish`
}

talaiot {
metrics {
// disabling due to problems with OSHI on some platforms
performanceMetrics = false
environmentMetrics = false
}
publishers {
timelinePublisher = true
}
}

project.description = "diKTat kotlin formatter and fixer"

configureSigning()

tasks.create("generateLibsForDiktatSnapshot") {
val dir = rootProject.buildDir.resolve("diktat-snapshot")

val dependencies = setOf(
projects.diktatCommon,
projects.diktatRules,
projects.diktatGradlePlugin,
)
mustRunAfter(dependencies.map { ":${it.name}:publishToMavenLocal" })
val libsFile = rootProject.file("gradle/libs.versions.toml")

inputs.file(libsFile)
inputs.files(dependencies.map { it.pomFile() })
inputs.files(dependencies.map { it.artifactFile() })
inputs.property("project-version", version.toString())
outputs.dir(dir)

doFirst {
dir.deleteRecursively()
dir.createDirectory()
}
doLast {
Files.readAllLines(libsFile.toPath())
.map { line ->
when {
line.contains("diktat = ") -> "diktat = \"$version\""
else -> line
}
}
.let {
val libsFileForDiktatSnapshot = dir.resolve("libs.versions.toml_snapshot")
Files.write(libsFileForDiktatSnapshot.toPath(), it)
}

dependencies.forEach { dependency ->
val artifactDir = dir.pathToMavenArtifact(dependency)
.also { it.createDirectory() }
Files.copy(dependency.pomFile().toPath(), artifactDir.resolve(dependency.pomFileName()).toPath())
Files.copy(dependency.artifactFile().toPath(), artifactDir.resolve(dependency.artifactFileName()).toPath())
}
}
}

/**
Fixed Show fixed Hide fixed
* @param projectDependency
* @return resolved path to directory according to maven coordinate
*/
fun File.pathToMavenArtifact(projectDependency: ProjectDependency): File = projectDependency.group.toString()
.split(".")
.fold(this) { dirToArtifact, newPart -> dirToArtifact.resolve(newPart) }
.resolve(projectDependency.name)
.resolve(projectDependency.version.toString())

/**
* @return generated pom.xml for project dependency
*/
fun ProjectDependency.pomFile(): File = rootProject.file("$name/build/publications/")
.let { publicationsDir ->
publicationsDir.resolve("pluginMaven")
.takeIf { it.exists() }
?: publicationsDir.resolve("maven")
}
.resolve("pom-default.xml")

/**
* @return file name of pom.xml for project dependency
*/
fun ProjectDependency.pomFileName(): String = "$name-$version.pom"

/**
* @return generated artifact for project dependency
*/
fun ProjectDependency.artifactFile(): File = rootProject.file("$name/build/libs/$name-$version.jar")

/**
* @return file name of artifact for project dependency
*/
fun ProjectDependency.artifactFileName(): String = "$name-$version.jar"
19 changes: 19 additions & 0 deletions diktat-common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@Suppress("DSL_SCOPE_VIOLATION", "RUN_IN_SCRIPT") // https://github.com/gradle/gradle/issues/22797
plugins {
id("org.cqfn.diktat.buildutils.kotlin-jvm-configuration")
id("org.cqfn.diktat.buildutils.code-quality-convention")
id("org.cqfn.diktat.buildutils.publishing-signing-default-configuration")
alias(libs.plugins.kotlin.plugin.serialization)
}

dependencies {
implementation(libs.kotlin.stdlib.jdk8)
api(libs.kotlinx.serialization.json)
api(libs.kaml)
implementation(libs.apache.commons.cli)
implementation(libs.kotlin.logging)
// ktlint-core is needed only for `initKtLintKLogger` method
implementation(libs.ktlint.core)
testImplementation(libs.junit.jupiter)
testImplementation(libs.assertj.core)
}
98 changes: 0 additions & 98 deletions diktat-common/pom.xml

This file was deleted.

8 changes: 8 additions & 0 deletions diktat-dev-ksp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id("org.cqfn.diktat.buildutils.kotlin-jvm-configuration")
id("org.cqfn.diktat.buildutils.code-quality-convention")
}

dependencies {
implementation("com.google.devtools.ksp:symbol-processing-api:1.8.10-1.0.9")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.cqfn.diktat.ruleset.generation

/**
* Annotation that marks to generate an object with names from Enum
*
* @property generatedPackageName
* @property generatedClassName
*/
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class EnumNames(
val generatedPackageName: String,
val generatedClassName: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package org.cqfn.diktat.ruleset.generation

import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.symbol.ClassKind
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSAnnotation
import com.google.devtools.ksp.symbol.KSClassDeclaration

/**
* [SymbolProcessor] to generate a class with contacts for names from provided enum
*/
class EnumNamesSymbolProcessor(
private val codeGenerator: CodeGenerator,
) : SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
resolver.getEnumDeclarations().forEach { doProcess(resolver, it) }
return emptyList()
}

private fun doProcess(resolver: Resolver, enumDeclaration: KSClassDeclaration) {
val annotation = enumDeclaration.annotations
.single {
it.shortName.asString() == EnumNames::class.simpleName
}
val targetPackageName = annotation.getArgumentValue("generatedPackageName")
val targetClassName = annotation.getArgumentValue("generatedClassName")
if (resolver.isAlreadyGenerated(targetPackageName, targetClassName)) {
return
}
codeGenerator.createNewFile(
dependencies = Dependencies(false),
packageName = targetPackageName,
fileName = targetClassName,
).bufferedWriter()
.use { writer ->
writer.write(autoGenerationComment)
writer.newLine()
writer.write("package $targetPackageName\n")
writer.newLine()
writer.write("import kotlin.String\n")
writer.newLine()
writer.write("object $targetClassName {\n")
enumDeclaration.declarations
.filterIsInstance<KSClassDeclaration>()
.filter { it.classKind == ClassKind.ENUM_ENTRY }
.map { it.simpleName.asString() }
.forEach { enumEntryName ->
writer.write(" const val $enumEntryName: String = \"$enumEntryName\"\n")
}
writer.write("}\n")
}
}

companion object {
/**
* The comment that will be added to the generated sources file.
*/
private val autoGenerationComment =
"""
|/**
| * This document was auto generated, please don't modify it.
| * This document contains all enum properties from Warnings.kt as Strings.
| */
""".trimMargin()
private val annotationName: String = requireNotNull(EnumNames::class.qualifiedName) {
"Failed to retrieve a qualified name from ${EnumNames::class}"
}

private fun Resolver.getEnumDeclarations(): Sequence<KSClassDeclaration> = getSymbolsWithAnnotation(annotationName)
.filterIsInstance<KSClassDeclaration>()
.onEach { candidate ->
require(candidate.classKind == ClassKind.ENUM_CLASS) {
"Annotated class ${candidate.qualifiedName} is not enum"
}
}

private fun KSAnnotation.getArgumentValue(argumentName: String): String = arguments
.singleOrNull { it.name?.asString() == argumentName }
.let {
requireNotNull(it) {
"Not found $argumentName in $this"
}
}
.value
?.let { it as? String }
.let {
requireNotNull(it) {
"Not found a value for $argumentName in $this"
}
}

private fun Resolver.isAlreadyGenerated(
packageName: String,
className: String,
): Boolean = getNewFiles()
.find { it.packageName.asString() == packageName && it.fileName == "$className.kt" }
?.let { true }
?: false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.cqfn.diktat.ruleset.generation

import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.processing.SymbolProcessorProvider

/**
* [SymbolProcessorProvider] for [EnumNamesSymbolProcessor]
*/
class EnumNamesSymbolProcessorProvider : SymbolProcessorProvider {
override fun create(
environment: SymbolProcessorEnvironment,
): SymbolProcessor = EnumNamesSymbolProcessor(
codeGenerator = environment.codeGenerator,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.cqfn.diktat.ruleset.generation.EnumNamesSymbolProcessorProvider
83 changes: 20 additions & 63 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.cqfn.diktat.buildutils.configureSigning
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.getCurrentOperatingSystem
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`java-gradle-plugin`
kotlin("jvm") version "1.8.10"
jacoco
id("org.cqfn.diktat.buildutils.kotlin-jvm-configuration")
id("org.cqfn.diktat.buildutils.code-quality-convention")
id("org.cqfn.diktat.buildutils.diktat-version-file-configuration")
id("pl.droidsonroids.jacoco.testkit") version "1.0.9"
id("org.gradle.test-retry") version "1.5.2"
id("com.gradle.plugin-publish") version "1.1.0"
}

repositories {
flatDir {
// to use snapshot diktat without necessary installing
dirs("../diktat-common/target")
content {
includeGroup("org.cqfn.diktat")
}
}
mavenCentral()
mavenLocal {
// to use snapshot diktat
content {
includeGroup("org.cqfn.diktat")
}
}
}

// default value is needed for correct gradle loading in IDEA; actual value from maven is used during build
// To debug gradle plugin, please set `diktatVersion` manually to the current maven project version.
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.46.1") as String
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "1.2.3"
val junitVersion = project.properties.getOrDefault("junitVersion", "5.8.1") as String
val jacocoVersion = project.properties.getOrDefault("jacocoVersion", "0.8.7") as String
dependencies {
implementation(kotlin("gradle-plugin-api"))
implementation("io.github.detekt.sarif4k:sarif4k:0.3.0")
implementation(libs.sarif4k.jvm)
nulls marked this conversation as resolved.
Show resolved Hide resolved

implementation("org.cqfn.diktat:diktat-common:$diktatVersion") {
api(projects.diktatCommon) {
exclude("org.jetbrains.kotlin", "kotlin-compiler-embeddable")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk7")
@@ -45,41 +24,18 @@ dependencies {
exclude("org.slf4j", "slf4j-log4j12")
}

testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
}

val generateVersionsFile by tasks.registering {
val versionsFile = File("$buildDir/generated/src/generated/Versions.kt")

inputs.property("diktat version", diktatVersion)
inputs.property("ktlint version", ktlintVersion)
outputs.file(versionsFile)

doFirst {
versionsFile.parentFile.mkdirs()
versionsFile.writeText(
"""
package generated
internal const val DIKTAT_VERSION = "$diktatVersion"
internal const val KTLINT_VERSION = "$ktlintVersion"
""".trimIndent()
)
}
}
kotlin.sourceSets["main"].kotlin.srcDir("$buildDir/generated/src")

tasks.withType<KotlinCompile> {
kotlinOptions {
// fixme: kotlin 1.3 is required for gradle <6.8
languageVersion = "1.3"
apiVersion = "1.3"
jvmTarget = "1.8"
freeCompilerArgs = freeCompilerArgs - "-Werror"
}

dependsOn.add(generateVersionsFile)
}

gradlePlugin {
@@ -91,24 +47,21 @@ gradlePlugin {
}
}

java {
withSourcesJar()
}

// === testing & code coverage, jacoco is run independent from maven
val functionalTestTask by tasks.register<Test>("functionalTest")
tasks.withType<Test> {
useJUnitPlatform()
}
jacoco.toolVersion = jacocoVersion

// === integration testing
// fixme: should probably use KotlinSourceSet instead
val functionalTest = sourceSets.create("functionalTest") {
val functionalTest: SourceSet = sourceSets.create("functionalTest") {
nulls marked this conversation as resolved.
Show resolved Hide resolved
compileClasspath += sourceSets.main.get().output + configurations.testRuntimeClasspath.get()
runtimeClasspath += output + compileClasspath
}
tasks.getByName<Test>("functionalTest") {

@Suppress("GENERIC_VARIABLE_WRONG_DECLARATION", "MAGIC_NUMBER")
val functionalTestProvider: TaskProvider<Test> = tasks.named<Test>("functionalTest") {
Fixed Show fixed Hide fixed
shouldRunAfter("test")
testClassesDirs = functionalTest.output.classesDirs
classpath = functionalTest.runtimeClasspath
@@ -129,8 +82,10 @@ tasks.getByName<Test>("functionalTest") {
finalizedBy(tasks.jacocoTestReport)
}
tasks.check { dependsOn(tasks.jacocoTestReport) }

jacocoTestKit {
applyTo("functionalTestRuntimeOnly", tasks.named("functionalTest"))
@Suppress("UNCHECKED_CAST")
applyTo("functionalTestRuntimeOnly", functionalTestProvider as TaskProvider<Task>)
}
tasks.jacocoTestReport {
shouldRunAfter(tasks.withType<Test>())
@@ -144,3 +99,5 @@ tasks.jacocoTestReport {
xml.required.set(true)
}
}

configureSigning()
40 changes: 0 additions & 40 deletions diktat-gradle-plugin/gradle-plugin-marker/pom.xml

This file was deleted.

208 changes: 0 additions & 208 deletions diktat-gradle-plugin/pom.xml

This file was deleted.

6 changes: 0 additions & 6 deletions diktat-gradle-plugin/settings.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -18,20 +18,18 @@ internal fun createExampleProject(testProjectDir: TemporaryFolder,
exampleProject.copyRecursively(testProjectDir.root)
val buildFileName = buildInitDsl.fileNameFor("build")
File(testProjectDir.root, buildFileName).delete()
testProjectDir.newFile(buildFileName).apply {
writeText(
"""
plugins {
id("org.cqfn.diktat.diktat-gradle-plugin")
}
testProjectDir.newFile(buildFileName).writeText(
"""
plugins {
id("org.cqfn.diktat.diktat-gradle-plugin")
}
repositories {
mavenLocal()
mavenCentral()
}
""".trimIndent()
)
}
repositories {
mavenLocal()
mavenCentral()
}
""".trimIndent()
)
}

/**
@@ -57,7 +55,12 @@ internal fun runDiktat(testProjectDir: TemporaryFolder,
"Running gradle returned exception $ex, cause: ${ex?.cause}"
}
}
.getOrNull()!!
.getOrNull()
.let {
requireNotNull(it) {
"Failed to get build result from running diktat"
}
}

/**
* This is support for jacoco reports in tests run with gradle TestKit
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ open class DiktatJavaExecTaskBase @Inject constructor(
// `main` is deprecated and replaced with `mainClass` since gradle 6.4
mainClass.set("com.pinterest.ktlint.Main")
} else {
@Suppress("Deprecation")
main = "com.pinterest.ktlint.Main"
}

53 changes: 53 additions & 0 deletions diktat-maven-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import de.benediktritter.maven.plugin.development.task.GenerateHelpMojoSourcesTask
import de.benediktritter.maven.plugin.development.task.GenerateMavenPluginDescriptorTask

plugins {
id("org.cqfn.diktat.buildutils.kotlin-jvm-configuration")
id("org.cqfn.diktat.buildutils.code-quality-convention")
id("org.cqfn.diktat.buildutils.publishing-configuration")
id("de.benediktritter.maven-plugin-development") version "0.4.1"
`maven-publish`
}

dependencies {
implementation(libs.maven.plugin.api)
compileOnly(libs.maven.plugin.annotations)
compileOnly(libs.maven.core)

implementation(libs.kotlin.stdlib.jdk8)
implementation(projects.diktatRules)
implementation(libs.ktlint.core)
implementation(libs.ktlint.reporter.plain)
implementation(libs.ktlint.reporter.sarif)
implementation(libs.ktlint.reporter.json)
implementation(libs.ktlint.reporter.html)
implementation(libs.ktlint.reporter.baseline)
testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.vintage.engine)
testImplementation(libs.junit.jupiter.extension.itf)
testImplementation(libs.maven.plugin.testing.harness)
// to use org.apache.maven.repository.RepositorySystem in newer maven versions and maybe other classes
testImplementation(libs.maven.compat)
testImplementation(libs.assertj.core)
testImplementation(libs.plexus.cipher)
}

tasks.withType<GenerateMavenPluginDescriptorTask> {
notCompatibleWithConfigurationCache("https://github.com/britter/maven-plugin-development/issues/8")
nulls marked this conversation as resolved.
Show resolved Hide resolved
}

tasks.withType<GenerateHelpMojoSourcesTask> {
notCompatibleWithConfigurationCache("https://github.com/britter/maven-plugin-development/issues/8")
}

mavenPlugin {
goalPrefix.set("diktat")
}

publishing {
publications {
create<MavenPublication>("mavenPlugin") {
from(components["java"])
}
}
}
347 changes: 0 additions & 347 deletions diktat-maven-plugin/pom.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import org.apache.maven.project.ProjectBuilder
import org.apache.maven.project.ProjectBuildingRequest
import org.eclipse.aether.DefaultRepositorySystemSession
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.jupiter.api.Assertions
@@ -20,6 +21,7 @@ import kotlin.io.path.div
*/
@OptIn(ExperimentalPathApi::class)
@Suppress("LongMethod", "TOO_LONG_FUNCTION")
@Ignore
class DiktatBaseMojoTest {
@get:Rule val mojoRule = MojoRule()
private lateinit var buildingRequest: ProjectBuildingRequest
@@ -46,11 +48,11 @@ class DiktatBaseMojoTest {
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
@@ -87,11 +89,11 @@ class DiktatBaseMojoTest {
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
45 changes: 45 additions & 0 deletions diktat-rules/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
id("org.cqfn.diktat.buildutils.kotlin-jvm-configuration")
id("org.cqfn.diktat.buildutils.code-quality-convention")
id("org.cqfn.diktat.buildutils.publishing-signing-default-configuration")
id("com.google.devtools.ksp") version "1.8.10-1.0.9"
idea
}

project.description = "The main diktat ruleset"

dependencies {
api(projects.diktatCommon)
testImplementation(projects.diktatTestFramework)
api(libs.ktlint.core)
implementation(libs.kotlin.stdlib.jdk8)
// guava is used for string case utils
implementation(libs.guava)
implementation(libs.kotlin.logging)
testImplementation(libs.junit.jupiter)
testImplementation(libs.junit.platform.suite)
testImplementation(libs.assertj.core)
testImplementation(libs.mockito)
// is used for simplifying boolean expressions
implementation(libs.jbool.expressions)

// generating
compileOnly(projects.diktatDevKsp)
ksp(projects.diktatDevKsp)
testImplementation(libs.kotlin.reflect)
}

kotlin {
sourceSets.main {
kotlin.srcDir("build/generated/ksp/main/kotlin")
}
}

idea {
module {
// Not using += due to https://github.com/gradle/gradle/issues/8749
sourceDirs = sourceDirs + file("build/generated/ksp/main/kotlin") // or tasks["kspKotlin"].destination
testSourceDirs = testSourceDirs + file("build/generated/ksp/test/kotlin")
generatedSourceDirs = generatedSourceDirs + file("build/generated/ksp/main/kotlin") + file("build/generated/ksp/test/kotlin")
}
}
152 changes: 0 additions & 152 deletions diktat-rules/pom.xml

This file was deleted.

279 changes: 0 additions & 279 deletions diktat-rules/src/main/kotlin/generated/WarningNames.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package org.cqfn.diktat.ruleset.constants
import org.cqfn.diktat.common.config.rules.Rule
import org.cqfn.diktat.common.config.rules.RulesConfig
import org.cqfn.diktat.common.config.rules.isRuleEnabled
import org.cqfn.diktat.ruleset.generation.EnumNames
import org.cqfn.diktat.ruleset.utils.isSuppressed
import org.jetbrains.kotlin.com.intellij.lang.ASTNode

@@ -27,6 +28,10 @@ typealias ListOfPairs = MutableList<Pair<ASTNode, String>>
"MaxLineLength",
"WRONG_NEWLINES"
)
@EnumNames(
generatedPackageName = "generated",
generatedClassName = "WarningNames",
)
enum class Warnings(
@Suppress("PRIVATE_MEMBER") val canBeAutoCorrected: Boolean,
val ruleId: String,

This file was deleted.

61 changes: 61 additions & 0 deletions diktat-ruleset/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("org.cqfn.diktat.buildutils.kotlin-jvm-configuration")
id("org.cqfn.diktat.buildutils.code-quality-convention")
id("org.cqfn.diktat.buildutils.publishing-configuration")
id("com.github.johnrengelman.shadow") version "7.1.2"
`maven-publish`
}

project.description = "This module builds jar that can be used to run diktat using ktlint -R via command line"

dependencies {
api(projects.diktatRules) {
// Kotlin runtime & libraries will be provided by ktlint executable
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
nulls marked this conversation as resolved.
Show resolved Hide resolved
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
exclude("org.jetbrains.kotlin", "kotlin-compiler-embeddable")
}
testImplementation(projects.diktatTestFramework)
testImplementation(libs.kotlin.stdlib.common)
testImplementation(libs.kotlin.stdlib.jdk7)
testImplementation(libs.kotlin.stdlib.jdk8)
testImplementation(libs.kotlin.stdlib)
testImplementation(libs.kotlin.compiler.embeddable)
testImplementation(libs.junit.jupiter)
testImplementation(libs.junit.platform.suite)
testImplementation(libs.assertj.core)
testImplementation(libs.mockito)
}

tasks.named<ShadowJar>("shadowJar") {
archiveBaseName.set("diktat")
archiveClassifier.set("")
}

// disable default jar
tasks.named("jar") {
enabled = false
}

// it triggers shadowJar with default build
tasks {
build {
dependsOn(shadowJar)
}
}

// it creates a publication for shadowJar
publishing {
publications {
create<MavenPublication>("shadow") {
// https://github.com/johnrengelman/shadow/issues/417#issuecomment-830668442
project.extensions.configure<ShadowExtension> {
component(this@create)
}
}
}
}
229 changes: 0 additions & 229 deletions diktat-ruleset/pom.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ import kotlin.io.path.createDirectories
import kotlin.io.path.div
import kotlin.io.path.exists
import kotlin.io.path.listDirectoryEntries
import kotlin.io.path.name
import kotlin.io.path.outputStream
import kotlin.io.path.readText
import kotlin.io.path.relativeTo
@@ -136,7 +137,7 @@ class DiktatSaveSmokeTest : DiktatSmokeTestBase() {
@Suppress("EMPTY_BLOCK_STRUCTURE_ERROR")
private val logger = KotlinLogging.loggerWithKtlintConfig { }
private const val BASE_DIRECTORY = "src/test/resources/test/smoke"
private const val BUILD_DIRECTORY = "target"
private const val BUILD_DIRECTORY = "build/libs"
private const val FAT_JAR_GLOB = "diktat-*.jar"
private const val KTLINT_VERSION = "0.46.1"
private const val SAVE_VERSION: String = "0.3.4"
Original file line number Diff line number Diff line change
@@ -383,7 +383,7 @@ abstract class DiktatSmokeTestBase {
@Suppress("AVOID_NULL_CHECKS")
internal fun createTmpFiles() {
listOf(
"$RESOURCE_FILE_PATH/../../../build.gradle_.kts" to "build.gradle.kts",
"$RESOURCE_FILE_PATH/../../../build.gradle.kts_" to "build.gradle.kts",
"$RESOURCE_FILE_PATH/Example1Test.kt" to "Example1-2Test.kt",
)
.map { (resource, targetFileName) ->
17 changes: 17 additions & 0 deletions diktat-test-framework/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id("org.cqfn.diktat.buildutils.kotlin-jvm-configuration")
id("org.cqfn.diktat.buildutils.code-quality-convention")
}

project.description = "Test framework for diktat"

dependencies {
api(projects.diktatCommon)
implementation(libs.kotlin.stdlib.jdk8)
implementation(libs.apache.commons.cli)
implementation(libs.apache.commons.io)
implementation(libs.kotlin.logging)
implementation(libs.kotlin.multiplatform.diff)
testImplementation(libs.junit.jupiter)
testImplementation(libs.assertj.core)
}
123 changes: 0 additions & 123 deletions diktat-test-framework/pom.xml

This file was deleted.

13 changes: 13 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
group=org.cqfn.diktat

# gradle performance
org.gradle.jvmargs=-Xmx3g -XX:MaxMetaspaceSize=512m
org.gradle.parallel=true
org.gradle.vfs.watch=true

# See <https://docs.gradle.com/enterprise/gradle-plugin/>
#
# If this is enabled, the Gradle Enterprise plug-in will be conflicting with
# the Test Retry plug-in (org.gradle.test-retry,
# <https://github.com/gradle/test-retry-gradle-plugin>).
systemProp.gradle.enterprise.testretry.enabled=false
157 changes: 157 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
[versions]
kotlin = "1.8.10"
serialization = "1.5.0"
ktlint = "0.46.1"
junit = "5.9.1"
junit-platfrom = "1.9.1"
guava = "31.1-jre"
commons-cli = "1.5.0"
commons-io = "2.11.0"
kotlinpoet = "1.12.0"
detekt = "1.22.0"
dokka = "1.7.20"
jacoco = "0.8.8"
# maven
maven-api = "3.8.6"
maven-plugin-tools = "3.7.0"
maven-plugin-testing-harness = "3.3.0"
plexus = "2.0"

jbool = "1.24"
# downgraded to be compliance with ktlint
mu-logging = "2.1.23"
kaml = "0.47.0"
kotlin-multiplatform-diff = "0.4.0"
sarif4k = "0.3.0"
jupiter-itf-extension = "0.12.0"
# FIXME: need to migrate to mockito
mockito-all = "1.10.19"


# copied from save-cloud
jetbrains-annotations = "24.0.1"
save-cli = "0.3.9"
ktor = "2.2.4"
okio = "3.3.0"
kotlinx-datetime = "0.4.0"
kotlinx-coroutines = "1.6.4"
assertj = "3.24.2"
diktat = "1.2.5"
jgit = "6.5.0.202303070854-r"
mockito = "5.2.0"
mockito-kotlin = "4.1.0"
# only in save-cli
log4j = "2.20.0"
testcontainers = "1.17.6"
okhttp3 = "4.10.0"
reckon = "0.16.1"
commons-compress = "1.22"
zip4j = "2.11.5"
ktoml = "0.4.1"
springdoc = "1.6.15"
kotlinx-cli = "0.3.5"
spotless = "6.17.0"
arrow-kt = "1.1.5"
publish = "1.3.0"
download = "5.3.1"

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-js = { id = "org.jetbrains.kotlin.js", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-plugin-jpa = { id = "org.jetbrains.kotlin.plugin.jpa", version.ref = "kotlin" }
kotlin-plugin-allopen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }
talaiot-base = { id = "io.github.cdsap.talaiot.plugin.base", version = "1.5.3" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
spotless = { id = "com.diffplug.gradle.spotless", version.ref = "spotless" }
download = { id = "de.undercouch.download", version.ref = "download" }

[libraries]
save-common = { module = "com.saveourtool.save:save-common", version.ref = "save-cli" }
save-common-jvm = { module = "com.saveourtool.save:save-common-jvm", version.ref = "save-cli" }
save-core = { module = "com.saveourtool.save:save-core", version.ref = "save-cli" }
save-core-jvm = { module = "com.saveourtool.save:save-core-jvm", version.ref = "save-cli" }
save-plugins-fix = { module = "com.saveourtool.save:fix-plugin", version.ref = "save-cli" }
save-plugins-fix-jvm = { module = "com.saveourtool.save:fix-plugin-jvm", version.ref = "save-cli" }
save-plugins-warn-jvm = { module = "com.saveourtool.save:warn-plugin-jvm", version.ref = "save-cli" }
save-plugins-fixAndWarn-jvm = { module = "com.saveourtool.save:fix-and-warn-plugin-jvm", version.ref = "save-cli" }
save-reporters = { module = "com.saveourtool.save:save-reporters", version.ref = "save-cli" }
publish-gradle-plugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "publish"}
download-plugin = { module = "de.undercouch:gradle-download-task", version.ref = "download" }

# kotlin
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
kotlin-stdlib-common = { module = "org.jetbrains.kotlin:kotlin-stdlib-common", version.ref = "kotlin" }
kotlin-stdlib-jdk7 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk7", version.ref = "kotlin" }
kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }


# kotlinx serialization
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "serialization" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
kotlinx-serialization-json-jvm = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-jvm", version.ref = "serialization" }
# another serialization
kaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kaml" }

#kotlin libs
kotlin-multiplatform-diff = { module = "io.github.petertrr:kotlin-multiplatform-diff", version.ref = "kotlin-multiplatform-diff" }

# ktlint & detekt
ktlint-core = { module = "com.pinterest.ktlint:ktlint-core", version.ref = "ktlint" }
ktlint-reporter-plain = { module = "com.pinterest.ktlint:ktlint-reporter-plain", version.ref = "ktlint" }
ktlint-reporter-sarif = { module = "com.pinterest.ktlint:ktlint-reporter-sarif", version.ref = "ktlint" }
ktlint-reporter-json = { module = "com.pinterest.ktlint:ktlint-reporter-json", version.ref = "ktlint" }
ktlint-reporter-html = { module = "com.pinterest.ktlint:ktlint-reporter-html", version.ref = "ktlint" }
ktlint-reporter-baseline = { module = "com.pinterest.ktlint:ktlint-reporter-baseline", version.ref = "ktlint" }
sarif4k = { module = "io.github.detekt.sarif4k:sarif4k", version.ref = "sarif4k" }
sarif4k-jvm = { module = "io.github.detekt.sarif4k:sarif4k-jvm", version.ref = "sarif4k" }

# apache
apache-commons-cli = { module = "commons-cli:commons-cli", version.ref = "commons-cli" }
apache-commons-io = { module = "commons-io:commons-io", version.ref = "commons-io" }

# others
guava = { module = "com.google.guava:guava", version.ref = "guava" }
jbool-expressions = { module = "com.bpodgursky:jbool_expressions", version.ref = "jbool" }

# logging
kotlin-logging = { module = "io.github.microutils:kotlin-logging", version.ref = "mu-logging" }

# testing
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-vintage-engine = { module = "org.junit.vintage:junit-vintage-engine", version.ref = "junit" }
junit-jupiter-extension-itf = { module = "com.soebes.itf.jupiter.extension:itf-jupiter-extension", version.ref = "jupiter-itf-extension" }
assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj" }
junit-platform-suite = { module = "org.junit.platform:junit-platform-suite-engine", version.ref = "junit-platfrom" }
mockito = { module = "org.mockito:mockito-all", version.ref = "mockito-all" }

# maven
maven-core = { module = "org.apache.maven:maven-core", version.ref = "maven-api" }
maven-embedder = { module = "org.apache.maven:maven-embedder", version.ref = "maven-api" }
maven-compat = { module = "org.apache.maven:maven-compat", version.ref = "maven-api" }
maven-plugin-api = { module = "org.apache.maven:maven-plugin-api", version.ref = "maven-api" }
maven-plugin-annotations = { module = "org.apache.maven.plugin-tools:maven-plugin-annotations", version.ref = "maven-plugin-tools" }
maven-plugin-testing-harness = { module = "org.apache.maven.plugin-testing:maven-plugin-testing-harness", version.ref = "maven-plugin-testing-harness" }
plexus-cipher = { module = "org.codehaus.plexus:plexus-cipher", version.ref = "plexus" }

######### copied from save-cloud
kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-plugin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin" }


jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" }

# java core libraries
validation-api = { module = "jakarta.validation:jakarta.validation-api"}
annotation-api = { module = "jakarta.annotation:jakarta.annotation-api"}

# code quality
diktat-gradle-plugin = { module = "org.cqfn.diktat:diktat-gradle-plugin", version.ref = "diktat" }
detekt-gradle-plugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" }
gradle-plugin-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
reckon-gradle-plugin = { module = "org.ajoberstar.reckon:reckon-gradle", version.ref = "reckon" }
45 changes: 45 additions & 0 deletions gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

repositories {
file("$rootDir/../../build/diktat-snapshot")
.takeIf { it.exists() }
?.run {
maven {
url = this@run.toURI()
}
}
mavenCentral()
gradlePluginPortal()
}

dependencies {
// workaround https://github.com/gradle/gradle/issues/15383
implementation(files(project.libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(libs.kotlin.gradle.plugin)
implementation(libs.reckon.gradle.plugin)
implementation(libs.detekt.gradle.plugin) {
exclude("io.github.detekt.sarif4k", "sarif4k")
}
implementation(libs.diktat.gradle.plugin) {
exclude("io.github.detekt.sarif4k", "sarif4k")
}
implementation(libs.sarif4k)
implementation(libs.gradle.plugin.spotless)
implementation(libs.publish.gradle.plugin)
// extra dependencies
implementation(libs.kotlin.stdlib)
implementation(libs.kotlin.stdlib.common)
implementation(libs.kotlin.stdlib.jdk7)
implementation(libs.kotlin.stdlib.jdk8)
implementation(libs.jetbrains.annotations)
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
}
}
9 changes: 9 additions & 0 deletions gradle/plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootProject.name = "buildutils"

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../libs.versions.toml"))
}
}
}
8 changes: 8 additions & 0 deletions gradle/plugins/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@file:Suppress("CONSTANT_UPPERCASE", "PACKAGE_NAME_MISSING")

object Versions {
/**
* JDK version which is used for building and running the project.
*/
const val jdk = "8"
nulls marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Configuration for code coverage calculation via Jacoco
*/

package org.cqfn.diktat.buildutils

import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.the
import org.gradle.testing.jacoco.plugins.JacocoPlugin
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.testing.jacoco.tasks.JacocoReport

/**
* Configure jacoco for [this] project
*/
fun Project.configureJacoco() {
apply<JacocoPlugin>()

configure<JacocoPluginExtension> {
toolVersion = the<LibrariesForLibs>()
.versions
.jacoco
.get()
}

tasks.named<Test>("test") {
finalizedBy("jacocoTestReport")
}
tasks.named<JacocoReport>("jacocoTestReport") {
dependsOn(tasks.named<Test>("test"))
reports {
xml.required.set(true)
html.required.set(true)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/**
* Publishing configuration file.
*/

@file:Suppress(
"MISSING_KDOC_TOP_LEVEL",
"MISSING_KDOC_ON_FUNCTION",
)

package org.cqfn.diktat.buildutils

import io.github.gradlenexus.publishplugin.NexusPublishExtension
import org.gradle.api.Named
import org.gradle.api.Project
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.internal.logging.text.StyledTextOutput
import org.gradle.internal.logging.text.StyledTextOutput.Style.Failure
import org.gradle.internal.logging.text.StyledTextOutput.Style.Success
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.SigningExtension

/**
* Enables signing of the artifacts if the `signingKey` project property is set.
*
* Should be explicitly called after each custom `publishing {}` section.
*/
fun Project.configureSigning() {
if (hasProperty("signingKey")) {
/*
* GitHub Actions.
*/
configureSigningCommon {
useInMemoryPgpKeys(property("signingKey") as String?, findProperty("signingPassword") as String?)
}
} else if (
hasProperties(
"signing.keyId",
"signing.password",
"signing.secretKeyRingFile",
)
) {
/*-
* Pure-Java signing mechanism via `org.bouncycastle.bcpg`.
*
* Requires an 8-digit (short form) PGP key id and a present `~/.gnupg/secring.gpg`
* (for gpg 2.1, run
* `gpg --keyring secring.gpg --export-secret-keys >~/.gnupg/secring.gpg`
* to generate one).
*/
configureSigningCommon()
} else if (hasProperty("signing.gnupg.keyName")) {
/*-
* Use an external `gpg` executable.
*
* On Windows, you may need to additionally specify the path to `gpg` via
* `signing.gnupg.executable`.
*/
configureSigningCommon {
useGpgCmd()
}
}
}

@Suppress("TOO_LONG_FUNCTION")
internal fun Project.configurePublications() {
val dokkaJar: Jar = tasks.create<Jar>("dokkaJar") {
group = "documentation"
archiveClassifier.set("javadoc")
from(tasks.findByName("dokkaHtml"))
}
configure<PublishingExtension> {
repositories {
mavenLocal()
}
publications.withType<MavenPublication>().configureEach {
/*
* The content of this section will get executed only if
* a particular module has a `publishing {}` section.
*/
this.artifact(dokkaJar)
this.pom {
name.set(project.name)
description.set(project.description ?: project.name)
url.set("https://www.cqfn.org/diKTat/")
licenses {
license {
name.set("MIT License")
url.set("http://www.opensource.org/licenses/mit-license.php")
}
}
developers {
developer {
id.set("akuleshov7")
name.set("Andrey Kuleshov")
email.set("andrewkuleshov7@gmail.com")
url.set("https://github.com/akuleshov7")
}
developer {
id.set("petertrr")
name.set("Peter Trifanov")
email.set("peter.trifanov@gmail.com")
url.set("https://github.com/petertrr")
}
}
scm {
connection.set("scm:git:git://github.com/saveourtool/diktat.git")
developerConnection.set("scm:git:ssh://github.com:saveourtool/diktat.git")
url.set("http://github.com/saveourtool/diktat/tree/master")
}
}
}
}
}

internal fun Project.configureNexusPublishing() {
configure<NexusPublishExtension> {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(property("sonatypeUsername") as String)
password.set(property("sonatypePassword") as String)
}
}
}
}

/**
* @param useKeys the block which configures the PGP keys. Use either
* [SigningExtension.useInMemoryPgpKeys], [SigningExtension.useGpgCmd], or an
* empty lambda.
* @see SigningExtension.useInMemoryPgpKeys
* @see SigningExtension.useGpgCmd
*/
private fun Project.configureSigningCommon(useKeys: SigningExtension.() -> Unit = {}) {
configure<SigningExtension> {
useKeys()
val publications = extensions.getByType<PublishingExtension>().publications
val publicationCount = publications.size
val message = "The following $publicationCount publication(s) are getting signed: ${publications.map(Named::getName)}"
val style = when (publicationCount) {
0 -> Failure
else -> Success
}
styledOut(logCategory = "signing").style(style).println(message)
sign(*publications.toTypedArray())
}
}

private fun Project.styledOut(logCategory: String): StyledTextOutput =
serviceOf<StyledTextOutputFactory>().create(logCategory)

/**
* Determines if this project has all the given properties.
*
* @param propertyNames the names of the properties to locate.
* @return `true` if this project has all the given properties, `false` otherwise.
* @see Project.hasProperty
*/
private fun Project.hasProperties(vararg propertyNames: String): Boolean =
propertyNames.asSequence().all(this::hasProperty)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
Fixed Show fixed Hide fixed
* Configuration for project versioning
*/

package org.cqfn.diktat.buildutils

import org.ajoberstar.grgit.gradle.GrgitServiceExtension
import org.ajoberstar.grgit.gradle.GrgitServicePlugin
import org.ajoberstar.reckon.gradle.ReckonExtension
import org.ajoberstar.reckon.gradle.ReckonPlugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType

/**
* Configures reckon plugin for [this] project, should be applied for root project only
*/
fun Project.configureVersioning() {
apply<ReckonPlugin>()
apply<GrgitServicePlugin>()

// should be provided in the gradle.properties
configure<ReckonExtension> {
snapshots()
setScopeCalc(calcScopeFromProp())
setStageCalc(calcStageFromProp())
}

val status = project.extensions.getByType<GrgitServiceExtension>()
.service
.map { it.grgit.repository.jgit.status().call() }
.get()
if (!status.isClean) {
logger.warn("git tree is not clean; " +
"Untracked files: ${status.untracked}, uncommitted changes: ${status.uncommittedChanges}"
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.cqfn.diktat.buildutils

plugins {
id("org.cqfn.diktat.buildutils.detekt-convention-configuration")
id("org.cqfn.diktat.buildutils.diktat-convention-configuration")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.cqfn.diktat.buildutils

import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.report.ReportMergeTask

plugins {
id("io.gitlab.arturbosch.detekt")
}

detekt {
config = rootProject.files("detekt-config.yml")
basePath = rootDir.canonicalPath
buildUponDefaultConfig = true
}

@Suppress("RUN_IN_SCRIPT")
if (path == rootProject.path) {
tasks.register("detektAll") {
allprojects {
this@register.dependsOn(tasks.withType<Detekt>())
}
}

tasks.register("mergeDetektReports", ReportMergeTask::class) {
output.set(buildDir.resolve("detekt-sarif-reports/detekt-merged.sarif"))
}
}

@Suppress("GENERIC_VARIABLE_WRONG_DECLARATION")
val reportMerge: TaskProvider<ReportMergeTask> = rootProject.tasks.named<ReportMergeTask>("mergeDetektReports") {
input.from(
tasks.withType<Detekt>().map { it.sarifReportFile }
)
shouldRunAfter(tasks.withType<Detekt>())
}
tasks.withType<Detekt>().configureEach {
reports.sarif.required.set(true)
finalizedBy(reportMerge)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.cqfn.diktat.buildutils

import org.cqfn.diktat.plugin.gradle.DiktatJavaExecTaskBase

plugins {
id("org.cqfn.diktat.diktat-gradle-plugin")
}

diktat {
diktatConfigFile = rootProject.file("diktat-analysis.yml")
githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false
inputs {
// using `Project#path` here, because it must be unique in gradle's project hierarchy
if (path == rootProject.path) {
include("gradle/plugins/src/**/*.kt", "*.kts", "gradle/plugins/**/*.kts")
exclude("gradle/plugins/build/**")
} else {
include("src/**/*.kt", "**/*.kts")
exclude(
"src/test/**/*.kt",
"src/test/**/*.kts",
"src/*Test/**/*.kt",
"build/**/*.kts",
)
}
}
}

tasks.withType<DiktatJavaExecTaskBase>().configureEach {
javaLauncher.set(project.extensions.getByType<JavaToolchainService>().launcherFor {
// a temporary workaround -- diktat-gradle-plugin doesn't detect java version of `javaLauncher`
languageVersion.set(JavaLanguageVersion.of(11))
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.cqfn.diktat.buildutils

import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.registering
import org.gradle.kotlin.dsl.the
import java.io.File

plugins {
kotlin("jvm")
}

val ktlintVersion: String = the<LibrariesForLibs>()
.versions
.ktlint
.get()

val generateVersionsFile by tasks.registering {
val outputDir = File("$buildDir/generated/src")
val versionsFile = outputDir.resolve("generated/Versions.kt")

val diktatVersion = version.toString()

inputs.property("diktat version", diktatVersion)
inputs.property("ktlint version", ktlintVersion)
outputs.dir(outputDir)

doFirst {
versionsFile.parentFile.mkdirs()
versionsFile.writeText(
"""
package generated
internal const val DIKTAT_VERSION = "$diktatVersion"
internal const val KTLINT_VERSION = "$ktlintVersion"
""".trimIndent()
)
}
}

kotlin.sourceSets.getByName("main") {
kotlin.srcDir(
generateVersionsFile.map {
it.outputs.files.singleFile
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.cqfn.diktat.buildutils

/**
* Task of type [Copy] that install git hooks from directory in repo to .git directory
*/
val installGitHooksTask = tasks.register("installGitHooks", Copy::class) {
from(file("$rootDir/.git-hooks"))
into(file("$rootDir/.git/hooks"))
}

// add git hooks installation to build by adding it as a dependency for some common task
run {
tasks.findByName("build")?.dependsOn(installGitHooksTask)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.cqfn.diktat.buildutils

import org.gradle.api.tasks.testing.Test
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs +
"-opt-in=kotlin.RequiresOptIn" + "-Werror"
}
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(Versions.jdk))
}
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(Versions.jdk))
}
}

configureJacoco()
tasks.withType<Test> {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.cqfn.diktat.buildutils

import io.github.gradlenexus.publishplugin.NexusPublishPlugin
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.extra

plugins {
`maven-publish`
signing
}

run {
// If present, set properties from env variables. If any are absent, release will fail.
System.getenv("OSSRH_USERNAME")?.let {
extra.set("sonatypeUsername", it)
}
System.getenv("OSSRH_PASSWORD")?.let {
extra.set("sonatypePassword", it)
}
System.getenv("GPG_SEC")?.let {
extra.set("signingKey", it)
}
System.getenv("GPG_PASSWORD")?.let {
extra.set("signingPassword", it)
}

if (project.path == rootProject.path) {
apply<NexusPublishPlugin>()
if (hasProperty("sonatypeUsername")) {
configureNexusPublishing()
}
}
}

run {
configurePublications()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.cqfn.diktat.buildutils

import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.get

plugins {
id("org.cqfn.diktat.buildutils.publishing-configuration")
}

run {
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
}
}
}

configureSigning()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.cqfn.diktat.buildutils

configureVersioning()
Binary file not shown.
File renamed without changes.
4 changes: 2 additions & 2 deletions diktat-gradle-plugin/gradlew → gradlew
Original file line number Diff line number Diff line change
@@ -144,15 +144,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
File renamed without changes.
625 changes: 0 additions & 625 deletions pom.xml

This file was deleted.

54 changes: 54 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
rootProject.name = "diktat"

dependencyResolutionManagement {
repositories {
file("$rootDir/build/diktat-snapshot")
.takeIf { it.exists() }
?.run {
maven {
url = this@run.toURI()
}
}
mavenCentral()
}
}

pluginManagement {
repositories {
file("$rootDir/build/diktat-snapshot")
.takeIf { it.exists() }
?.run {
maven {
url = this@run.toURI()
}
}
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id("com.gradle.enterprise") version "3.12.4"
}

includeBuild("gradle/plugins")
include("diktat-common")
include("diktat-gradle-plugin")
include("diktat-maven-plugin")
include("diktat-rules")
include("diktat-ruleset")
include("diktat-test-framework")
include("diktat-dev-ksp")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

gradleEnterprise {
@Suppress("AVOID_NULL_CHECKS")
if (System.getenv("CI") != null) {
buildScan {
publishAlways()
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
}
}