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
Show file tree
Hide file tree
Changes from 16 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
21 changes: 21 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@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.code-quality-convention")
id("org.cqfn.diktat.buildutils.publishing-configuration")
alias(libs.plugins.talaiot.base)
java
}

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"
18 changes: 18 additions & 0 deletions diktat-common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@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")
alias(libs.plugins.kotlin.plugin.serialization)
}

dependencies {
implementation(libs.kotlin.stdlib.jdk8)
implementation(libs.kotlinx.serialization.json.jvm)
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.

7 changes: 7 additions & 0 deletions diktat-dev-ksp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
kotlin("jvm")
}

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,71 @@
package org.cqfn.diktat.ruleset.generation

import com.google.devtools.ksp.getClassDeclarationByName
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.KSClassDeclaration

/**
* [SymbolProcessor] to generate a class with contacts for names from provided enum
*/
class EnumNamesSymbolProcessor(
private val sourceEnumName: String,
private val targetPackageName: String,
private val targetClassName: String,
private val codeGenerator: CodeGenerator,
) : SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
val enumDeclaration = requireNotNull(resolver.getClassDeclarationByName(sourceEnumName)) {
"Not found class provided by property <${EnumNamesSymbolProcessorProvider.OPTION_NAME_SOURCE_ENUM_NAME}>"
}
require(enumDeclaration.classKind == ClassKind.ENUM_CLASS) {
"Provided class $sourceEnumName is not enum"
}

resolver.getNewFiles()
.find { it.packageName.asString() == targetPackageName && it.fileName == "$targetClassName.kt" }
?.run {
return emptyList()
}
codeGenerator.createNewFile(
dependencies = Dependencies.ALL_FILES,
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")
}
return emptyList()
}

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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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(
sourceEnumName = environment.options.getValue(OPTION_NAME_SOURCE_ENUM_NAME),
targetPackageName = environment.options.getValue(OPTION_NAME_TARGET_PACKAGE_NAME),
targetClassName = environment.options.getValue(OPTION_NAME_TARGET_CLASS_NAME),
codeGenerator = environment.codeGenerator,
)

companion object {
/**
* Option name to specify `enumName`
*/
const val OPTION_NAME_SOURCE_ENUM_NAME = "sourceEnumName"

/**
* Option name to specify `packageName` for target class
*/
const val OPTION_NAME_TARGET_PACKAGE_NAME = "targetPackageName"

/**
* Option name to specify `className` for target class
*/
const val OPTION_NAME_TARGET_CLASS_NAME = "targetClassName"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.cqfn.diktat.ruleset.generation.EnumNamesSymbolProcessorProvider
46 changes: 14 additions & 32 deletions diktat-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,42 +1,19 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
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("pl.droidsonroids.jacoco.testkit") version "1.0.9"
id("org.gradle.test-retry") version "1.5.2"
}

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")
Expand All @@ -45,15 +22,21 @@ 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)

// FIXME: it should come as transitive dependency from projects.diktatCommon
implementation(libs.kotlinx.serialization.json)
nulls marked this conversation as resolved.
Show resolved Hide resolved
}

val generateVersionsFile by tasks.registering {
nulls marked this conversation as resolved.
Show resolved Hide resolved
val versionsFile = File("$buildDir/generated/src/generated/Versions.kt")
val diktatVersion = project.version.toString()
val ktlintVersion = libs.versions.ktlint.get()

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

outputs.file(versionsFile)

doFirst {
Expand Down Expand Up @@ -100,11 +83,10 @@ 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
}
Expand Down
40 changes: 0 additions & 40 deletions diktat-gradle-plugin/gradle-plugin-marker/pom.xml

This file was deleted.

Loading