Skip to content

Commit 2657f6a

Browse files
committed
Only update file header dates when they are modified
Prevents the giant "year" update commits.
1 parent 2306d10 commit 2657f6a

File tree

3 files changed

+60
-20
lines changed

3 files changed

+60
-20
lines changed

buildSrc/src/main/kotlin/mcdev-core.gradle.kts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* https://mcdev.io/
55
*
6-
* Copyright (C) 2025 minecraft-dev
6+
* Copyright (C) 2026 minecraft-dev
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published
@@ -19,6 +19,7 @@
1919
*/
2020

2121
import org.cadixdev.gradle.licenser.header.HeaderStyle
22+
import org.cadixdev.gradle.licenser.tasks.LicenseTask
2223
import org.gradle.accessors.dm.LibrariesForLibs
2324
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode
2425
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
@@ -128,14 +129,58 @@ intellijPlatform {
128129
}
129130

130131
license {
131-
header.set(resources.text.fromFile(rootProject.layout.projectDirectory.file("copyright.txt")))
132+
header.set(resources.text.fromString($$"""
133+
Minecraft Development for IntelliJ
134+
135+
https://mcdev.io/
136+
137+
Copyright (C) ${year} minecraft-dev
138+
139+
This program is free software: you can redistribute it and/or modify
140+
it under the terms of the GNU Lesser General Public License as published
141+
by the Free Software Foundation, version 3.0 only.
142+
143+
This program is distributed in the hope that it will be useful,
144+
but WITHOUT ANY WARRANTY; without even the implied warranty of
145+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
146+
GNU General Public License for more details.
147+
148+
You should have received a copy of the GNU Lesser General Public License
149+
along with this program. If not, see <https://www.gnu.org/licenses/>.
150+
""".trimIndent()))
151+
152+
properties {
153+
set("year", "2026")
154+
}
155+
132156
style["flex"] = HeaderStyle.BLOCK_COMMENT.format
133157
style["bnf"] = HeaderStyle.BLOCK_COMMENT.format
134158

135159
val endings = listOf("java", "kt", "kts", "groovy", "gradle.kts", "xml", "properties", "html", "flex", "bnf")
136160
include(endings.map { "**/*.$it" })
137161
}
138162

163+
tasks.withType(LicenseTask::class).configureEach {
164+
val changedFiles = if (rootProject.ext.has("changedFiles")) {
165+
@Suppress("UNCHECKED_CAST")
166+
rootProject.ext["changedFiles"] as Set<File>
167+
} else {
168+
val unstagedFiles = git("diff", "--name-only").lines()
169+
val stagedFiles = git("diff", "--staged", "--name-only").lines()
170+
var changedFiles = (unstagedFiles + stagedFiles)
171+
.filter { it.isNotBlank() }
172+
.map(project::file)
173+
.toSet()
174+
rootProject.ext["changedFiles"] = changedFiles
175+
changedFiles
176+
}
177+
doFirst {
178+
files = files.filter {
179+
it in changedFiles
180+
}
181+
}
182+
}
183+
139184
idea {
140185
module {
141186
excludeDirs.add(file(intellijPlatform.sandboxContainer.get()))

buildSrc/src/main/kotlin/util.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* https://mcdev.io/
55
*
6-
* Copyright (C) 2025 minecraft-dev
6+
* Copyright (C) 2026 minecraft-dev
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published
@@ -18,6 +18,10 @@
1818
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
*/
2020

21+
import java.io.ByteArrayOutputStream
22+
import java.io.InputStream
23+
import java.io.OutputStream
24+
import java.nio.charset.Charset
2125
import org.gradle.api.Project
2226
import org.gradle.api.tasks.TaskContainer
2327
import org.gradle.api.tasks.util.PatternFilterable
@@ -65,3 +69,11 @@ fun Project.parser(bnf: String, pack: String): TaskDelegate<ParserExec> {
6569
this.grammarKit.setFrom(grammarKit)
6670
}
6771
}
72+
73+
fun Project.git(vararg args: String): String {
74+
val output = providers.exec {
75+
commandLine("git", *args)
76+
isIgnoreExitValue = true
77+
}
78+
return output.standardOutput.asText.get()
79+
}

copyright.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)