forked from saveourtool/diktat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
124 lines (108 loc) · 3.83 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import org.jetbrains.kotlin.incremental.createDirectory
import java.nio.file.Files
import java.nio.file.StandardCopyOption
@Suppress("DSL_SCOPE_VIOLATION", "RUN_IN_SCRIPT") // https://github.com/gradle/gradle/issues/22797
plugins {
id("com.saveourtool.diktat.buildutils.versioning-configuration")
id("com.saveourtool.diktat.buildutils.git-hook-configuration")
id("com.saveourtool.diktat.buildutils.code-quality-convention")
id("com.saveourtool.diktat.buildutils.publishing-configuration")
alias(libs.plugins.talaiot.base)
java
`maven-publish`
}
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"
val libsFileName = "libs.versions.toml"
val libsFile = rootProject.file("gradle/$libsFileName")
val libsFileBackup = rootProject.file("gradle/${libsFileName}_backup")
tasks.create("generateLibsForDiktatSnapshot") {
val dir = rootProject.layout
.buildDirectory
.dir("diktat-snapshot")
.get()
.asFile
val dependency = rootProject.project(":diktat-gradle-plugin")
dependsOn(dependency.let { "${it.path}:publishToMavenLocal" })
inputs.file(libsFile)
inputs.files(dependency.pomFile())
inputs.files(dependency.artifactFile())
inputs.property("project-version", version.toString())
outputs.dir(dir)
doFirst {
dir.deleteRecursively()
dir.createDirectory()
}
doLast {
Files.readAllLines(libsFile.toPath())
.map { line ->
when {
line.contains("diktat = ") -> "diktat = \"$version\""
else -> line
}
}
.let {
val libsFileForDiktatSnapshot = dir.resolve(libsFileName)
Files.write(libsFileForDiktatSnapshot.toPath(), it)
Files.move(libsFile.toPath(), libsFileBackup.toPath(), StandardCopyOption.REPLACE_EXISTING)
Files.copy(libsFileForDiktatSnapshot.toPath(), libsFile.toPath())
}
val artifactDir = dir.pathToMavenArtifact(dependency)
.also { it.createDirectory() }
Files.copy(dependency.pomFile().toPath(), artifactDir.resolve(dependency.pomFileName()).toPath())
Files.copy(dependency.artifactFile().toPath(), artifactDir.resolve(dependency.artifactFileName()).toPath())
}
}
tasks.create("rollbackLibsForDiktatSnapshot") {
inputs.file(libsFileBackup)
outputs.file(libsFile)
doLast {
Files.deleteIfExists(libsFile.toPath())
Files.move(libsFileBackup.toPath(), libsFile.toPath())
}
}
/**
* @param project
* @return resolved path to directory according to maven coordinate
*/
fun File.pathToMavenArtifact(project: Project): File = project.group.toString()
.split(".")
.fold(this) { dirToArtifact, newPart -> dirToArtifact.resolve(newPart) }
.resolve(project.name)
.resolve(project.version.toString())
/**
* @return generated pom.xml for project dependency
*/
fun Project.pomFile(): File = layout.buildDirectory
.dir("publications")
.map { publicationsDir ->
publicationsDir.dir("pluginMaven")
.takeIf { it.asFile.exists() }
?: publicationsDir.dir("maven")
}
.map { it.file("pom-default.xml").asFile }
.get()
/**
* @return file name of pom.xml for project
*/
fun Project.pomFileName(): String = "$name-$version.pom"
/**
* @return generated artifact for project dependency
*/
fun Project.artifactFile(): File = layout.buildDirectory
.dir("libs")
.map { it.file(artifactFileName()).asFile }
.get()
/**
* @return file name of artifact for project dependency
*/
fun Project.artifactFileName(): String = "$name-$version.jar"