Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/class-cast-exception-kdoc(#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
aktsay6 authored Nov 23, 2020
2 parents 02941fe + 4d17fe0 commit e5c375b
Show file tree
Hide file tree
Showing 37 changed files with 942 additions and 299 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
3 changes: 3 additions & 0 deletions .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 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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 Down Expand Up @@ -153,7 +153,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.

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
34 changes: 29 additions & 5 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`java-gradle-plugin`
kotlin("jvm") version "1.4.10"
jacoco
}

repositories {
Expand All @@ -14,20 +15,24 @@ repositories {
jcenter()
}

val ktlintVersion: String by project
val diktatVersion = project.version
val ktlintVersion = project.properties.getOrDefault("ktlintVersion", "0.39.0") as String
val diktatVersion = project.version.takeIf { it.toString() != Project.DEFAULT_VERSION } ?: "0.1.6-SNAPSHOT"
val junitVersion = project.properties.getOrDefault("junitVersion", "5.7.0") as String
dependencies {
implementation(kotlin("gradle-plugin-api"))

implementation("com.pinterest.ktlint:ktlint-core:$ktlintVersion") {
exclude("com.pinterest.ktlint", "ktlint-ruleset-standard")
}
implementation("com.pinterest.ktlint:ktlint-reporter-plain:$ktlintVersion")
implementation("org.cqfn.diktat:diktat-rules:$version")
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 {
val versionsFile = File("$buildDir/generated/src/main/generated/Versions.kt")
val versionsFile = File("$buildDir/generated/src/generated/Versions.kt")

outputs.file(versionsFile)

Expand All @@ -43,14 +48,16 @@ val generateVersionsFile by tasks.registering {
)
}
}
sourceSets.main.get().java.srcDir("$buildDir/generated/src/main")
sourceSets.main.get().java.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"
}

dependsOn.add(generateVersionsFile)
}

Expand All @@ -66,3 +73,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
@@ -0,0 +1,31 @@
package org.cqfn.diktat.plugin.gradle

import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

class DiktatGradlePluginTest {
private val projectBuilder = ProjectBuilder.builder()
private lateinit var project: Project

@BeforeEach
fun setUp() {
project = projectBuilder.build()
project.pluginManager.apply(DiktatGradlePlugin::class.java)
}

@Test
fun `check that tasks are registered`() {
Assertions.assertTrue(project.tasks.findByName("diktatCheck") != null)
Assertions.assertTrue(project.tasks.findByName("diktatFix") != null)
}

@Test
fun `check default extension properties`() {
val diktatExtension = project.extensions.getByName("diktat") as DiktatExtension
Assertions.assertFalse(diktatExtension.debug)
Assertions.assertIterableEquals(project.fileTree("src").files, diktatExtension.inputs.files)
}
}
Loading

0 comments on commit e5c375b

Please sign in to comment.