Skip to content

Commit

Permalink
Merge branch 'master' into feature/update-docs-for-#302
Browse files Browse the repository at this point in the history
  • Loading branch information
petertrr authored Nov 27, 2020
2 parents 9d5ceed + 07829e0 commit 33ea95a
Show file tree
Hide file tree
Showing 123 changed files with 3,183 additions and 1,165 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Build and test
on:
pull_request

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

jobs:
test:
name: Unit Test
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/diktat_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: [ master ]

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

jobs:
diktat_snapshot_check:
runs-on: ubuntu-latest
Expand Down
31 changes: 24 additions & 7 deletions .github/workflows/functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ master ]

env:
DIKTAT_VERSION: 0.1.2
DIKTAT_VERSION: 0.1.5
KTLINT_VERSION: 0.39.0
GRADLE_OPTS: -Dorg.gradle.daemon=false # to speed up gradle run

Expand All @@ -21,7 +21,7 @@ jobs:
- name: Setup environment
run: |
cat pom.xml | grep "<diktat-check.version>.*</diktat-check.version>" | head -1 |awk -F'[><]' '{ENVIRON[DIKTAT_VERSION]=$3 ; print ENVIRON[DIKTAT_VERSION]}'
cat pom.xml | grep "<ktlint.version>.*</ktlint.version>" | head -1 |awk -F'[><]' '{ENVIRON[KTLINE_VERSION]=$3 ; print ENVIRON[KTLINE_VERSION]}'
cat pom.xml | grep "<ktlint.version>.*</ktlint.version>" | head -1 |awk -F'[><]' '{ENVIRON[KTLINT_VERSION]=$3 ; print ENVIRON[KTLINT_VERSION]}'
curl -sSLO https://github.com/pinterest/ktlint/releases/download/$KTLINT_VERSION/ktlint && chmod a+x ktlint
curl -sSLO https://github.com/cqfn/diKTat/releases/download/v$DIKTAT_VERSION/diktat-$DIKTAT_VERSION.jar
Expand All @@ -36,28 +36,45 @@ jobs:
- name: Run diKTat from cli
continue-on-error: true
run: |
./ktlint -R diktat-$DIKTAT_VERSION.jar "diktat-rules/src/test/resources/test/funcTest/FunctionalTestFile.kt" &> out
./ktlint -R diktat-$DIKTAT_VERSION.jar "examples/maven/src/main/kotlin/Test.kt" &> out
- name: Check output
id: cli-check
run: |
cat out
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out
- name: Run diKTat from gradle
- name: Run diKTat from gradle kotlin DSL
continue-on-error: true
run: gradle diktatFunctionalTest &> out
working-directory: ./examples/gradle-kotlin-dsl
run: |
gradle diktatCheck &> out
- name: Check gradle from kotlin DSL
working-directory: ./examples/gradle-kotlin-dsl
run: |
cat out
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out
- name: Run diKTat from gradle groovy DSL
continue-on-error: true
working-directory: ./examples/gradle-groovy-dsl
run: |
gradle diktatCheck &> out
- name: Check gradle
- name: Check gradle from groovy DSL
working-directory: ./examples/gradle-groovy-dsl
run: |
cat out
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out
- name: Run diKTat from maven
working-directory: ./examples/maven
continue-on-error: true
run: mvn -B diktat:check@functional-test &> out
run: mvn -B diktat:check &> out

- name: Check maven
working-directory: ./examples/maven
run: |
cat out
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out
6 changes: 5 additions & 1 deletion .github/workflows/metrics_for_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- 'master'

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

jobs:
master_flow:
name: Master branch update
Expand All @@ -25,7 +28,8 @@ jobs:
restore-keys: |
${{ runner.os }}-maven-build-
- name: Run tests
run: mvn -B test -DskipPluginMarker
# we need to run `install` goal here so that gradle will be able to resolve dependencies and run tests on diktat-gradle-plugin
run: mvn -B install -DskipPluginMarker
- name: Generate code coverage report
uses: codecov/codecov-action@v1
with:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,19 @@ jobs:
asset_path: ./diktat-ruleset/target/diktat-${{ env.RELEASE_VERSION }}.jar
asset_name: diktat-${{ env.RELEASE_VERSION }}.jar
asset_content_type: application/zip
- name: Update versions in pom.xml and documentation
- name: Update versions in pom.xml and documentation, update examples
id: update-versions
run: |
mvn -B versions:set -DnextSnapshot=true -DprocessAllModules=true versions:commit
mvn versions:set-property -Dproperty=diktat-check.version -DnewVersion=${{ env.RELEASE_VERSION }}
sed -i "s/$PREVIOUS_VERSION/$RELEASE_VERSION/g" README.md
sed -i "s/$PREVIOUS_VERSION/$RELEASE_VERSION/g" build.gradle.kts
sed -i "s/$PREVIOUS_VERSION/$RELEASE_VERSION/g" .github/workflows/functional_tests.yml
for file in examples/maven/pom.xml examples/gradle-groovy-dsl/build.gradle examples/gradle-kotlin-dsl/build.gradle.kts
do
sed -i "s/$PREVIOUS_VERSION/$RELEASE_VERSION/g" $file
cp diktat-rules/src/main/resources/diktat-analysis.yml $(dirname $file)
done
- name: Create pull request
uses: peter-evans/create-pull-request@v3
with:
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ Add this plugin to your pom.xml:
<input>${project.basedir}/src/test/kotlin</input>
</inputs>
<diktatConfigFile>diktat-analysis.yml</diktatConfigFile>
<excludes>
<exclude>${project.basedir}/src/test/kotlin/excluded</exclude>
</excludes>
</configuration>
</execution>
</executions>
Expand All @@ -103,7 +106,7 @@ To run diktat in **only-check** mode use command `$ mvn diktat:check@diktat`.
To run diktat in **autocorrect** mode use command `$ mvn diktat:fix@diktat`.

## Run with Gradle using diktat-gradle-plugin
This plugin is available since version 0.1.5. You can see how the plugin is configured in our project for self-checks: [build.gradle.kts](build.gradle.kts).
This plugin is available since version 0.1.5. You can see how the plugin is configured in our examples: [build.gradle.kts](examples/gradle-kotlin-dsl/build.gradle.kts).
Add this plugin to your `build.gradle.kts`:
```kotlin
plugins {
Expand All @@ -130,6 +133,7 @@ You can then configure diktat using `diktat` extension:
diktat {
inputs = files("src/**/*.kt") // file collection that will be checked by diktat
debug = true // turn on debug logging
excludes = files("src/test/kotlin/excluded") // these files will not be checked by diktat
}
```

Expand All @@ -153,7 +157,7 @@ For example:
# all rules are enabled by the default. To disable add 'enabled: false' to the config.
enabled: true
configuration:
isCopyrightMandatory: true,
isCopyrightMandatory: true
copyrightText: Copyright (c) Jeff Lebowski, 2012-2020. All rights reserved.
```
Note, that you can specify and put `diktat-analysis.yml` that contains configuration of diktat in the parent directory of your project on the same level where `build.gradle/pom.xml` is stored. \
Expand Down
53 changes: 0 additions & 53 deletions build.gradle.kts

This file was deleted.

8 changes: 8 additions & 0 deletions diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,12 @@
enabled: true
# Checks if extension function with the same signature don't have related classes
- name: EXTENSION_FUNCTION_SAME_SIGNATURE
enabled: true
# Checks if there is empty primary constructor
- name: EMPTY_PRIMARY_CONSTRUCTOR
enabled: true
# In case of not using field keyword in property accessors,
# there should be explicit backing property with the name of real property
# Example: val table get() {if (_table == null) ...} -> table should have _table
- name: NO_CORRESPONDING_PROPERTY
enabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.cqfn.diktat.common.cli

import org.apache.commons.cli.Option

import kotlinx.serialization.*
import kotlinx.serialization.Serializable

/**
* This class is used to serialize/deserialize json representation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import org.junit.jupiter.api.Test
class ConfigReaderTest {
@Test
fun `testing json reading`() {
val rulesConfigList: List<RulesConfig>? = RulesConfigReader(javaClass.classLoader).readResource("src/test/resources/test-rules-config.yml")
val rulesConfigList: List<RulesConfig>? = RulesConfigReader(javaClass.classLoader)
.readResource("src/test/resources/test-rules-config.yml")
require(rulesConfigList != null)
assert(rulesConfigList.any { it.name == "CLASS_NAME_INCORRECT" && it.enabled })
assert(rulesConfigList.find { it.name == "CLASS_NAME_INCORRECT" }?.configuration == mapOf<String, String>())
Expand Down
30 changes: 27 additions & 3 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`java-gradle-plugin`
kotlin("jvm") version "1.4.10"
kotlin("jvm") version "1.4.20"
jacoco
}

repositories {
Expand All @@ -15,8 +16,9 @@ repositories {
}

// default value is needed for correct gradle loading in IDEA; actual value from maven is used during build
val ktlintVersion: String = project.properties.getOrDefault("ktlintVersion", "0.39.0") as String
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "0.1.6-SNAPSHOT"
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.39.0") as String
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "0.1.5"
val junitVersion = project.properties.getOrDefault("junitVersion", "5.7.0") as String
dependencies {
implementation(kotlin("gradle-plugin-api"))

Expand All @@ -25,6 +27,9 @@ dependencies {
}
implementation("com.pinterest.ktlint:ktlint-reporter-plain:$ktlintVersion")
implementation("org.cqfn.diktat:diktat-rules:$diktatVersion")

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

val generateVersionsFile by tasks.registering {
Expand All @@ -51,7 +56,9 @@ tasks.withType<KotlinCompile> {
// fixme: kotlin 1.3 is required for gradle <6.8
languageVersion = "1.3"
apiVersion = "1.3"
jvmTarget = "1.8"
}

dependsOn.add(generateVersionsFile)
}

Expand All @@ -67,3 +74,20 @@ gradlePlugin {
java {
withSourcesJar()
}

// === testing & code coverage, consistent with maven
tasks.withType<Test> {
useJUnitPlatform()
extensions.configure(JacocoTaskExtension::class) {
setDestinationFile(file("target/jacoco.exec"))
}
}

tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
// xml report is used by codecov
xml.isEnabled = true
xml.destination = file("target/site/jacoco/jacoco.xml")
}
}
23 changes: 22 additions & 1 deletion diktat-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,39 @@
<artifactId>exec-maven-plugin</artifactId>
<inherited>false</inherited>
<executions>
<execution>
<id>gradle-test</id>
<phase>test</phase>
<configuration>
<executable>${gradle.executable}</executable>
<arguments>
<argument>clean</argument>
<argument>jacocoTestReport</argument>
<argument>-Pgroup=${project.groupId}</argument>
<argument>-Pversion=${project.version}</argument>
<argument>-Pdescription=${project.description}</argument>
<argument>-PktlintVersion=${ktlint.version}</argument>
<argument>-PjunitVersion=${junit.version}</argument>
<argument>-S</argument>
</arguments>
<skip>${skip.gradle.build}</skip>
</configuration>
<goals>
<goal>exec</goal>
</goals>
</execution>
<execution>
<id>gradle</id>
<phase>prepare-package</phase>
<configuration>
<executable>${gradle.executable}</executable>
<arguments>
<argument>clean</argument>
<argument>${gradle.task}</argument>
<argument>-Pgroup=${project.groupId}</argument>
<argument>-Pversion=${project.version}</argument>
<argument>-Pdescription=${project.description}</argument>
<argument>-PktlintVersion=${ktlint.version}</argument>
<argument>-PjunitVersion=${junit.version}</argument>
<argument>-S</argument>
</arguments>
<skip>${skip.gradle.build}</skip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ open class DiktatExtension {
* Paths that will be scanned for .kt(s) files
*/
lateinit var inputs: FileCollection

/**
* Paths that will be excluded from diktat run
*/
var excludes: FileCollection? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DiktatGradlePlugin : Plugin<Project> {
diktatExtension.inputs = project.fileTree("src").apply {
include("**/*.kt")
}
diktatExtension.excludes = project.files()
diktatExtension.reporter = PlainReporter(System.out)

// only gradle 7+ (or maybe 6.8) will embed kotlin 1.4+, kx.serialization is incompatible with kotlin 1.3, so until then we have to use JavaExec wrapper
Expand Down
Loading

0 comments on commit 33ea95a

Please sign in to comment.