Skip to content

Commit

Permalink
Merge branch 'master' into feature/improve_autofix_in_avoid_null_chec…
Browse files Browse the repository at this point in the history
…ks_rule
  • Loading branch information
sanyavertolet authored Feb 25, 2022
2 parents d7619b4 + c79a36c commit abbe9ea
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 26 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DiKTat is a strict [coding standard ](info/guide/diktat-coding-convention.md) fo
as AST visitors on the top of [KTlint](https://ktlint.github.io/). It can be used for detecting and autofixing code smells in CI/CD process.
The full list of available supported rules and inspections can be found [here](info/available-rules.md).

Now diKTat was already added to the lists of [static analysis tools](https://github.com/analysis-tools-dev/static-analysis), to [kotlin-awesome](https://github.com/KotlinBy/awesome-kotlin) and to [kompar](https://catalog.kompar.tools/Analyzer/diKTat/1.0.2). Thanks to the community for this support!
Now diKTat was already added to the lists of [static analysis tools](https://github.com/analysis-tools-dev/static-analysis), to [kotlin-awesome](https://github.com/KotlinBy/awesome-kotlin) and to [kompar](https://catalog.kompar.tools/Analyzer/diKTat/1.0.3). Thanks to the community for this support!

## See first

Expand Down Expand Up @@ -54,11 +54,11 @@ Main features of diktat are the following:
# another option is "brew install ktlint"
```

2. Load diKTat manually: [here](https://github.com/cqfn/diKTat/releases/download/v1.0.2/diktat-1.0.2.jar)
2. Load diKTat manually: [here](https://github.com/cqfn/diKTat/releases/download/v1.0.3/diktat-1.0.3.jar)

**OR** use curl:
```bash
$ curl -sSLO https://github.com/cqfn/diKTat/releases/download/v1.0.2/diktat-1.0.2.jar
$ curl -sSLO https://github.com/cqfn/diKTat/releases/download/v1.0.3/diktat-1.0.3.jar
```
</details>

Expand Down Expand Up @@ -122,7 +122,7 @@ This plugin is available since version 0.1.5. You can see how the plugin is conf

```kotlin
plugins {
id("org.cqfn.diktat.diktat-gradle-plugin") version "1.0.2"
id("org.cqfn.diktat.diktat-gradle-plugin") version "1.0.3"
}
```

Expand All @@ -133,7 +133,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.cqfn.diktat:diktat-gradle-plugin:1.0.2")
classpath("org.cqfn.diktat:diktat-gradle-plugin:1.0.3")
}
}
Expand Down Expand Up @@ -200,7 +200,7 @@ spotless {
```kotlin
spotless {
kotlin {
diktat("1.0.2").configFile("full/path/to/diktat-analysis.yml")
diktat("1.0.3").configFile("full/path/to/diktat-analysis.yml")
}
}
```
Expand Down Expand Up @@ -231,7 +231,7 @@ Diktat can be run via spotless-maven-plugin since version 2.8.0

```xml
<diktat>
<version>1.0.2</version> <!-- optional -->
<version>1.0.3</version> <!-- optional -->
<configFile>full/path/to/diktat-analysis.yml</configFile> <!-- optional, configuration file path -->
</diktat>
```
Expand Down
2 changes: 1 addition & 1 deletion diktat-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion diktat-gradle-plugin/gradle-plugin-marker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>diktat-gradle-plugin</artifactId>
<groupId>org.cqfn.diktat</groupId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion diktat-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>diktat-parent</artifactId>
<groupId>org.cqfn.diktat</groupId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ class DiktatGradlePlugin : Plugin<Project> {
* Task to run diKTat with fix
*/
const val DIKTAT_FIX_TASK = "diktatFix"

/**
* Version of JVM with more strict module system, which requires `add-opens` for kotlin compiler
*/
const val MIN_JVM_REQUIRES_ADD_OPENS = 16
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package org.cqfn.diktat.plugin.gradle

import org.cqfn.diktat.plugin.gradle.DiktatGradlePlugin.Companion.DIKTAT_CHECK_TASK
import org.cqfn.diktat.plugin.gradle.DiktatGradlePlugin.Companion.DIKTAT_FIX_TASK
import org.cqfn.diktat.plugin.gradle.DiktatGradlePlugin.Companion.MIN_JVM_REQUIRES_ADD_OPENS
import org.cqfn.diktat.ruleset.rules.DIKTAT_CONF_PROPERTY

import generated.DIKTAT_VERSION
import generated.KTLINT_VERSION
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.FileCollection
Expand Down Expand Up @@ -33,7 +35,7 @@ import javax.inject.Inject
* Note: class being `open` is required for gradle to create a task.
*/
open class DiktatJavaExecTaskBase @Inject constructor(
gradleVersionString: String,
private val gradleVersionString: String,
diktatExtension: DiktatExtension,
diktatConfiguration: Configuration,
private val inputs: PatternFilterable,
Expand Down Expand Up @@ -133,6 +135,7 @@ open class DiktatJavaExecTaskBase @Inject constructor(
*/
@TaskAction
override fun exec() {
fixForNewJpms()
if (shouldRun) {
super.exec()
} else {
Expand Down Expand Up @@ -213,6 +216,27 @@ open class DiktatJavaExecTaskBase @Inject constructor(
}
.absolutePath
}

private fun fixForNewJpms() {
val javaVersion = getJavaExecJvmVersion()
project.logger.debug("For diktat execution jvm version $javaVersion will be used")
if (javaVersion.majorVersion.toInt() >= MIN_JVM_REQUIRES_ADD_OPENS) {
// https://github.com/analysis-dev/diktat/issues/1182#issuecomment-1023099713
project.logger.debug("Adding `--add-opens` flag for JVM version >=$MIN_JVM_REQUIRES_ADD_OPENS compatibility")
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
}
}

private fun getJavaExecJvmVersion(): JavaVersion = if (GradleVersion.version(gradleVersionString) >= GradleVersion.version("6.7") &&
javaLauncher.isPresent
) {
// Java Launchers are available since 6.7, but may not always be configured
javaLauncher.map { it.metadata.jvmVersion }.map(JavaVersion::toVersion).get()
} else {
// `javaVersion` property is available since 5.2 and is simply derived from path to JVM executable,
// which may be explicitly set or be the same as current Gradle JVM.
javaVersion
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion diktat-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>diktat-parent</artifactId>
<groupId>org.cqfn.diktat</groupId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion diktat-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</parent>

<properties>
Expand Down
2 changes: 1 addition & 1 deletion diktat-ruleset/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion diktat-test-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
</parent>

<dependencies>
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-groovy-dsl/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "org.cqfn.diktat.diktat-gradle-plugin" version "1.0.2"
id "org.cqfn.diktat.diktat-gradle-plugin" version "1.0.3"
}

repositories {
Expand Down
7 changes: 6 additions & 1 deletion examples/gradle-groovy-dsl/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,9 @@
enabled: true
# Check if boolean expression can be simplified
- name: COMPLEX_BOOLEAN_EXPRESSION
enabled: true
enabled: true
# Check if range can replace with until or `rangeTo` function with range
- name: CONVENTIONAL_RANGE
enabled: true
configuration:
isRangeToIgnore: false
2 changes: 1 addition & 1 deletion examples/gradle-kotlin-dsl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("org.cqfn.diktat.diktat-gradle-plugin") version "1.0.2"
id("org.cqfn.diktat.diktat-gradle-plugin") version "1.0.3"
}

repositories {
Expand Down
7 changes: 6 additions & 1 deletion examples/gradle-kotlin-dsl/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,9 @@
enabled: true
# Check if boolean expression can be simplified
- name: COMPLEX_BOOLEAN_EXPRESSION
enabled: true
enabled: true
# Check if range can replace with until or `rangeTo` function with range
- name: CONVENTIONAL_RANGE
enabled: true
configuration:
isRangeToIgnore: false
7 changes: 6 additions & 1 deletion examples/maven/diktat-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,9 @@
enabled: true
# Check if boolean expression can be simplified
- name: COMPLEX_BOOLEAN_EXPRESSION
enabled: true
enabled: true
# Check if range can replace with until or `rangeTo` function with range
- name: CONVENTIONAL_RANGE
enabled: true
configuration:
isRangeToIgnore: false
4 changes: 2 additions & 2 deletions examples/maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-examples-maven</artifactId>
<packaging>pom</packaging>
<version>1.0.2-SNAPSHOT</version>
<version>1.0.3-SNAPSHOT</version>

<properties>
<diktat.version>1.0.2</diktat.version>
<diktat.version>1.0.3</diktat.version>
</properties>

<build>
Expand Down
2 changes: 1 addition & 1 deletion info/buildSrc/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.3-SNAPSHOT
version=1.0.4-SNAPSHOT
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.cqfn.diktat</groupId>
<artifactId>diktat-parent</artifactId>
<version>1.0.3-SNAPSHOT</version>
<version>1.0.4-SNAPSHOT</version>
<packaging>pom</packaging>

<name>diktat</name>
Expand Down Expand Up @@ -50,7 +50,7 @@
<guava.version>31.0.1-jre</guava.version>
<slf4j.version>1.7.33</slf4j.version>
<commons-cli.version>1.5.0</commons-cli.version>
<diktat-check.version>1.0.2</diktat-check.version>
<diktat-check.version>1.0.3</diktat-check.version>
<kotlinpoet.version>1.10.0</kotlinpoet.version>
<detekt.version>1.19.1</detekt.version>
<dokka.version>1.6.10</dokka.version>
Expand Down Expand Up @@ -196,7 +196,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

0 comments on commit abbe9ea

Please sign in to comment.