|
1 | 1 | import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask |
2 | 2 | import java.net.HttpURLConnection |
3 | | -import java.net.URL |
| 3 | +import java.net.URI |
4 | 4 | import java.nio.file.Files |
5 | 5 | import java.nio.file.StandardOpenOption |
| 6 | +import kotlin.io.path.absolutePathString |
| 7 | +import kotlin.io.path.createDirectories |
| 8 | +import kotlin.io.path.div |
6 | 9 |
|
7 | 10 | plugins { |
8 | | - `java-library` |
9 | | - alias(libs.plugins.kotlin.jvm) |
10 | | - alias(libs.plugins.kotlinx.serialization) |
11 | | - alias(libs.plugins.dokka) |
12 | | - alias(libs.plugins.ktlint) |
13 | | - alias(libs.plugins.versions) |
14 | | - `maven-publish` |
| 11 | + `java-library` |
| 12 | + alias(libs.plugins.kotlin.jvm) |
| 13 | + alias(libs.plugins.kotlinx.serialization) |
| 14 | + alias(libs.plugins.dokka) |
| 15 | + alias(libs.plugins.spotless) |
| 16 | + alias(libs.plugins.versions) |
| 17 | + `maven-publish` |
15 | 18 | } |
16 | 19 |
|
17 | 20 | println("Kotlin v${KotlinVersion.CURRENT}") |
| 21 | + |
18 | 22 | println("Java v${System.getProperty("java.version")}") |
| 23 | + |
19 | 24 | println("Arch: ${System.getProperty("os.arch")}") |
20 | 25 |
|
21 | 26 | group = "github.buriedincode" |
22 | | -version = "0.3.1" |
| 27 | + |
| 28 | +version = "0.4.0" |
23 | 29 |
|
24 | 30 | repositories { |
25 | | - mavenCentral() |
26 | | - mavenLocal() |
| 31 | + mavenCentral() |
| 32 | + mavenLocal() |
27 | 33 | } |
28 | 34 |
|
29 | 35 | dependencies { |
30 | | - implementation(libs.bundles.kotlinx.serialization) |
31 | | - implementation(libs.kotlin.logging) |
32 | | - runtimeOnly(libs.sqlite.jdbc) |
33 | | - testImplementation(libs.junit.jupiter) |
34 | | - testRuntimeOnly(libs.junit.platform.launcher) |
35 | | - testRuntimeOnly(libs.kotlin.reflect) |
36 | | - testRuntimeOnly(libs.log4j2.slf4j2.impl) |
37 | | -} |
| 36 | + implementation(libs.bundles.kotlinx.serialization) |
| 37 | + implementation(libs.kotlin.logging) |
38 | 38 |
|
39 | | -java { |
40 | | - toolchain { |
41 | | - languageVersion = JavaLanguageVersion.of(17) |
42 | | - } |
43 | | -} |
| 39 | + runtimeOnly(libs.sqlite.jdbc) |
| 40 | + |
| 41 | + testImplementation(libs.junit.jupiter) |
44 | 42 |
|
45 | | -kotlin { |
46 | | - jvmToolchain(17) |
| 43 | + testRuntimeOnly(libs.junit.platform.launcher) |
| 44 | + testRuntimeOnly(libs.log4j2.slf4j2) |
47 | 45 | } |
48 | 46 |
|
49 | | -configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> { |
50 | | - version = "1.5.0" |
| 47 | +java { toolchain { languageVersion = JavaLanguageVersion.of(21) } } |
| 48 | + |
| 49 | +kotlin { jvmToolchain(21) } |
| 50 | + |
| 51 | +spotless { |
| 52 | + kotlin { |
| 53 | + ktfmt().kotlinlangStyle().configure { |
| 54 | + it.setMaxWidth(120) |
| 55 | + it.setBlockIndent(2) |
| 56 | + it.setContinuationIndent(2) |
| 57 | + it.setRemoveUnusedImports(true) |
| 58 | + it.setManageTrailingCommas(true) |
| 59 | + } |
| 60 | + } |
| 61 | + kotlinGradle { |
| 62 | + ktfmt().kotlinlangStyle().configure { |
| 63 | + it.setMaxWidth(120) |
| 64 | + it.setBlockIndent(2) |
| 65 | + it.setContinuationIndent(2) |
| 66 | + it.setRemoveUnusedImports(true) |
| 67 | + it.setManageTrailingCommas(true) |
| 68 | + } |
| 69 | + } |
51 | 70 | } |
52 | 71 |
|
53 | 72 | tasks.test { |
54 | | - environment("METRON__USERNAME", System.getenv("METRON__USERNAME")) |
55 | | - environment("METRON__PASSWORD", System.getenv("METRON__PASSWORD")) |
56 | | - useJUnitPlatform() |
57 | | - testLogging { |
58 | | - events("passed", "skipped", "failed") |
59 | | - } |
| 73 | + environment("METRON__USERNAME", System.getenv("METRON__USERNAME")) |
| 74 | + environment("METRON__PASSWORD", System.getenv("METRON__PASSWORD")) |
| 75 | + useJUnitPlatform() |
| 76 | + testLogging { events("passed", "skipped", "failed") } |
60 | 77 | } |
61 | 78 |
|
62 | 79 | fun isNonStable(version: String): Boolean { |
63 | | - val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) } |
64 | | - val regex = "^[0-9,.v-]+(-r)?$".toRegex() |
65 | | - val isStable = stableKeyword || regex.matches(version) |
66 | | - return isStable.not() |
| 80 | + val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) } |
| 81 | + val regex = "^[0-9,.v-]+(-r)?$".toRegex() |
| 82 | + val isStable = stableKeyword || regex.matches(version) |
| 83 | + return isStable.not() |
67 | 84 | } |
68 | 85 |
|
69 | 86 | tasks.withType<DependencyUpdatesTask> { |
70 | | - gradleReleaseChannel = "current" |
71 | | - resolutionStrategy { |
72 | | - componentSelection { |
73 | | - all { |
74 | | - if (isNonStable(candidate.version) && !isNonStable(currentVersion)) { |
75 | | - reject("Release candidate") |
76 | | - } |
77 | | - } |
| 87 | + gradleReleaseChannel = "current" |
| 88 | + checkForGradleUpdate = true |
| 89 | + checkConstraints = false |
| 90 | + checkBuildEnvironmentConstraints = false |
| 91 | + resolutionStrategy { |
| 92 | + componentSelection { |
| 93 | + all { |
| 94 | + if (isNonStable(candidate.version) && !isNonStable(currentVersion)) { |
| 95 | + reject("Release candidate") |
78 | 96 | } |
| 97 | + } |
79 | 98 | } |
| 99 | + } |
80 | 100 | } |
81 | 101 |
|
82 | | -publishing { |
83 | | - publications { |
84 | | - create<MavenPublication>("kraken") { |
85 | | - from(components["java"]) |
86 | | - } |
87 | | - } |
88 | | -} |
| 102 | +publishing { publications { create<MavenPublication>("kraken") { from(components["java"]) } } } |
89 | 103 |
|
90 | 104 | tasks.register("processReadme") { |
91 | | - group = "documentation" |
92 | | - description = "Processes the README.md file to inline SVG badges." |
| 105 | + group = "documentation" |
| 106 | + description = "Processes the README.md file to inline SVG badges." |
93 | 107 |
|
94 | | - doLast { |
95 | | - val linkedBadgePattern = """\[\!\[(.*?)\]\((.*?)\)\]\((.*?)\)""".toRegex() // [](link) |
96 | | - val badgePattern = """\!\[(.*?)\]\((.*?)\)""".toRegex() //  |
| 108 | + doLast { |
| 109 | + val linkedBadgePattern = """\[\!\[(.*?)\]\((.*?)\)\]\((.*?)\)""".toRegex() // [](link) |
| 110 | + val badgePattern = """\!\[(.*?)\]\((.*?)\)""".toRegex() //  |
97 | 111 |
|
98 | | - val inputPath = project.rootDir.toPath().resolve("README.md") |
99 | | - val outputPath = project.buildDir.toPath().resolve("Processed-README.md") |
| 112 | + val inputPath = project.rootDir.toPath() / "README.md" |
| 113 | + val outputPath = project.layout.buildDirectory.get().asFile.toPath() / "Processed-README.md" |
100 | 114 |
|
101 | | - if (!Files.exists(inputPath)) { |
102 | | - throw IllegalStateException("${inputPath.toAbsolutePath()} not found.") |
103 | | - } |
| 115 | + if (!Files.exists(inputPath)) { |
| 116 | + throw IllegalStateException("${inputPath.absolutePathString()} not found.") |
| 117 | + } |
104 | 118 |
|
105 | | - var content = Files.readAllLines(inputPath).joinToString("\n") |
106 | | - content = content.replaceFirst("# Kraken", "# Module Kraken") |
107 | | - |
108 | | - fun fetchSvg(url: String): String? { |
109 | | - return try { |
110 | | - val connection = URL(url).openConnection() as HttpURLConnection |
111 | | - connection.requestMethod = "GET" |
112 | | - connection.connect() |
113 | | - |
114 | | - if (connection.responseCode == 200 && connection.contentType.contains("image/svg+xml")) { |
115 | | - connection.inputStream.bufferedReader().use { it.readText() } |
116 | | - } else { |
117 | | - println("Warning: $url is not an SVG badge") |
118 | | - null |
119 | | - } |
120 | | - } catch (e: Exception) { |
121 | | - println("Error fetching $url: ${e.message}") |
122 | | - null |
123 | | - } |
124 | | - } |
| 119 | + var content = Files.readAllLines(inputPath).joinToString("\n") |
| 120 | + content = content.replaceFirst("# Kraken", "# Module Kraken") |
125 | 121 |
|
126 | | - fun processContent(pattern: Regex, replaceFunction: (MatchResult) -> String): String { |
127 | | - return pattern.replace(content) { match -> |
128 | | - replaceFunction(match) |
129 | | - } |
130 | | - } |
| 122 | + fun fetchSvg(url: String): String? { |
| 123 | + return try { |
| 124 | + val connection = URI.create(url).toURL().openConnection() as HttpURLConnection |
| 125 | + connection.requestMethod = "GET" |
| 126 | + connection.connect() |
131 | 127 |
|
132 | | - content = processContent(linkedBadgePattern) { match -> |
133 | | - val altText = match.groupValues[1] |
134 | | - val badgeUrl = match.groupValues[2] |
135 | | - val linkUrl = match.groupValues[3] |
136 | | - val svgContent = fetchSvg(badgeUrl) |
137 | | - if (svgContent != null) { |
138 | | - """<a href="$linkUrl" target="_blank">$svgContent</a>""" |
139 | | - } else { |
140 | | - """<a href="$linkUrl" target="_blank"><img alt="$altText" src="$badgeUrl" /></a>""" |
141 | | - } |
142 | | - } |
143 | | - |
144 | | - content = processContent(badgePattern) { match -> |
145 | | - val altText = match.groupValues[1] |
146 | | - val badgeUrl = match.groupValues[2] |
147 | | - val svgContent = fetchSvg(badgeUrl) |
148 | | - svgContent ?: """<img alt="$altText" src="$badgeUrl" />""" |
| 128 | + if (connection.responseCode == 200 && connection.contentType.contains("image/svg+xml")) { |
| 129 | + connection.inputStream.bufferedReader().use { it.readText() } |
| 130 | + } else { |
| 131 | + println("Warning: $url is not an SVG badge") |
| 132 | + null |
149 | 133 | } |
| 134 | + } catch (e: Exception) { |
| 135 | + println("Error fetching $url: ${e.message}") |
| 136 | + null |
| 137 | + } |
| 138 | + } |
150 | 139 |
|
151 | | - Files.createDirectories(outputPath.parent) |
152 | | - Files.writeString(outputPath, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING) |
153 | | - println("Processing complete. Output written to ${outputPath.toAbsolutePath()}") |
| 140 | + fun processContent(pattern: Regex, replaceFunction: (MatchResult) -> String): String { |
| 141 | + return pattern.replace(content) { match -> replaceFunction(match) } |
154 | 142 | } |
| 143 | + |
| 144 | + content = |
| 145 | + processContent(linkedBadgePattern) { match -> |
| 146 | + val altText = match.groupValues[1] |
| 147 | + val badgeUrl = match.groupValues[2] |
| 148 | + val linkUrl = match.groupValues[3] |
| 149 | + val svgContent = fetchSvg(badgeUrl) |
| 150 | + if (svgContent != null) { |
| 151 | + """<a href="$linkUrl" target="_blank">$svgContent</a>""" |
| 152 | + } else { |
| 153 | + """<a href="$linkUrl" target="_blank"><img alt="$altText" src="$badgeUrl" /></a>""" |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + content = |
| 158 | + processContent(badgePattern) { match -> |
| 159 | + val altText = match.groupValues[1] |
| 160 | + val badgeUrl = match.groupValues[2] |
| 161 | + val svgContent = fetchSvg(badgeUrl) |
| 162 | + svgContent ?: """<img alt="$altText" src="$badgeUrl" />""" |
| 163 | + } |
| 164 | + |
| 165 | + outputPath.parent.createDirectories() |
| 166 | + Files.writeString(outputPath, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING) |
| 167 | + println("Processing complete. Output written to ${outputPath.absolutePathString()}") |
| 168 | + } |
155 | 169 | } |
156 | 170 |
|
157 | 171 | tasks.dokkaHtml { |
158 | | - dependsOn("processReadme") |
159 | | - dokkaSourceSets { |
160 | | - configureEach { |
161 | | - includes.from(project.buildDir.toPath().resolve("Processed-README.md")) |
162 | | - } |
163 | | - } |
| 172 | + dependsOn("processReadme") |
| 173 | + dokkaSourceSets { |
| 174 | + configureEach { includes.from(project.layout.buildDirectory.get().asFile.toPath() / "Processed-README.md") } |
| 175 | + } |
164 | 176 | } |
0 commit comments