Skip to content

Commit

Permalink
Diktat command (#1649)
Browse files Browse the repository at this point in the history
  • Loading branch information
nulls committed Mar 30, 2023
1 parent 08f3e2a commit 6b4ecd1
Show file tree
Hide file tree
Showing 33 changed files with 973 additions and 521 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/diktat_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
arguments: |
:diktat-common:publishToMavenLocal
:diktat-rules:publishToMavenLocal
:diktat-runner:diktat-runner-api:publishToMavenLocal
:diktat-runner:diktat-runner-ktlint-engine:publishToMavenLocal
:diktat-gradle-plugin:publishToMavenLocal
:generateLibsForDiktatSnapshot
-x detekt
Expand Down
28 changes: 15 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ tasks.create("generateLibsForDiktatSnapshot") {
val dir = rootProject.buildDir.resolve("diktat-snapshot")

val dependencies = setOf(
projects.diktatCommon,
projects.diktatRules,
projects.diktatGradlePlugin,
rootProject.project(":diktat-common"),
rootProject.project(":diktat-rules"),
rootProject.project(":diktat-runner:diktat-runner-api"),
rootProject.project(":diktat-runner:diktat-runner-ktlint-engine"),
rootProject.project(":diktat-gradle-plugin"),
)
mustRunAfter(dependencies.map { ":${it.name}:publishToMavenLocal" })
mustRunAfter(dependencies.map { "${it.path}:publishToMavenLocal" })
val libsFile = rootProject.file("gradle/libs.versions.toml")

inputs.file(libsFile)
Expand Down Expand Up @@ -72,19 +74,19 @@ tasks.create("generateLibsForDiktatSnapshot") {
}

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

/**
* @return generated pom.xml for project dependency
*/
fun ProjectDependency.pomFile(): File = rootProject.file("$name/build/publications/")
fun Project.pomFile(): File = buildDir.resolve("publications")
.let { publicationsDir ->
publicationsDir.resolve("pluginMaven")
.takeIf { it.exists() }
Expand All @@ -93,16 +95,16 @@ fun ProjectDependency.pomFile(): File = rootProject.file("$name/build/publicatio
.resolve("pom-default.xml")

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

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

/**
* @return file name of artifact for project dependency
*/
fun ProjectDependency.artifactFileName(): String = "$name-$version.jar"
fun Project.artifactFileName(): String = "$name-$version.jar"

This file was deleted.

19 changes: 9 additions & 10 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ plugins {

dependencies {
implementation(kotlin("gradle-plugin-api"))
implementation(projects.diktatRunner.diktatRunnerKtlintEngine)
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)
// merge sarif reports
implementation(libs.sarif4k.jvm)

api(projects.diktatCommon) {
exclude("org.jetbrains.kotlin", "kotlin-compiler-embeddable")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk8")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-jdk7")
exclude("org.jetbrains.kotlin", "kotlin-stdlib")
exclude("org.jetbrains.kotlin", "kotlin-stdlib-common")
exclude("org.slf4j", "slf4j-log4j12")
}

implementation(libs.kotlinx.serialization.json)
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.cqfn.diktat.plugin.gradle

import org.cqfn.diktat.plugin.gradle.tasks.DiktatCheckTask.Companion.registerDiktatCheckTask
import org.cqfn.diktat.plugin.gradle.tasks.DiktatFixTask.Companion.registerDiktatFixTask
import org.cqfn.diktat.plugin.gradle.tasks.configureMergeReportsTask
import generated.DIKTAT_VERSION
import generated.KTLINT_VERSION
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.attributes.Bundling
import org.gradle.api.tasks.util.PatternSet

/**
Expand All @@ -28,38 +26,8 @@ class DiktatGradlePlugin : Plugin<Project> {
diktatConfigFile = project.rootProject.file("diktat-analysis.yml")
}

// Configuration that will be used as classpath for JavaExec task.
val diktatConfiguration = project.configurations.create(DIKTAT_CONFIGURATION) { configuration ->
configuration.isVisible = false
configuration.dependencies.add(project.dependencies.create("com.pinterest:ktlint:$KTLINT_VERSION", closureOf<ExternalModuleDependency> {
/*
* Prevent the discovery of standard rules by excluding them as
* dependencies.
*/
val ktlintRuleSets = sequenceOf(
"standard",
"experimental",
"test",
"template"
)
ktlintRuleSets.forEach { ktlintRuleSet ->
exclude(
mutableMapOf(
"group" to "com.pinterest.ktlint",
"module" to "ktlint-ruleset-$ktlintRuleSet"
)
)
}

attributes {
it.attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling::class.java, Bundling.EXTERNAL))
}
}))
configuration.dependencies.add(project.dependencies.create("org.cqfn.diktat:diktat-rules:$DIKTAT_VERSION"))
}

project.registerDiktatCheckTask(diktatExtension, diktatConfiguration, patternSet)
project.registerDiktatFixTask(diktatExtension, diktatConfiguration, patternSet)
project.registerDiktatCheckTask(diktatExtension, patternSet)
project.registerDiktatFixTask(diktatExtension, patternSet)
project.configureMergeReportsTask(diktatExtension)
}

Expand Down
Loading

0 comments on commit 6b4ecd1

Please sign in to comment.