-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstonecutter.gradle
More file actions
123 lines (112 loc) · 5.53 KB
/
Copy pathstonecutter.gradle
File metadata and controls
123 lines (112 loc) · 5.53 KB
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
plugins {
id "dev.kikugie.stonecutter"
}
// Currently used version
// Switch with `gradlew "Set active project to <version>"`,
// go back with `gradlew "Reset active project"`.
stonecutter.active "26.3" /* [SC] DO NOT EDIT */
// ------ Versioning ------------------------------------------
def versionPropsFile = rootProject.file("version.properties")
if (!versionPropsFile.exists()) {
throw new GradleException("Missing ${versionPropsFile}")
}
Properties versionProps = new Properties()
versionPropsFile.withInputStream { versionProps.load(it) }
def versionPart = { String key, boolean required = true ->
def value = versionProps[key]?.toString()?.trim()
if (required && (value == null || value.isEmpty())) {
throw new GradleException("version.properties is missing '${key}'")
}
return value ?: ""
}
def isAlpha = versionPart("version.alpha").toBoolean()
def stage = versionPart("version.stage", false)
def major = versionPart("version.major").toInteger()
def minor = versionPart("version.minor").toInteger()
def patch = versionPart("version.patch").toInteger()
def build = versionPart("version.build").toInteger()
ext.mod_version = (isAlpha
? "${major}.${minor}.${patch}${stage}-alpha.${build}"
: "${major}.${minor}.${patch}${stage}").toString()
logger.lifecycle("Versioning: ${mod_version} (${isAlpha ? 'ALPHA' : 'RELEASE'})")
// ------ Generated build tasks ------------------------------------
def tasksByVersion = new TreeMap()
stonecutter.tree.getBranches().each { branch ->
def branchName = branch.getId()
def task = branchName - "essentials-" == "core" ? "check" : "buildAndCollect"
branch.getNodes().each { node ->
def mcVersion = node.getMetadata().getVersion()
tasksByVersion.computeIfAbsent(mcVersion) { [] } << ":${branchName}:${mcVersion}:${task}"
}
}
tasksByVersion.each { mcVersion, paths ->
tasks.register("build-${mcVersion}") {
group = "build version"
description = "Builds every loader for Minecraft ${mcVersion} into <root>/build/libs"
dependsOn paths
}
}
tasks.register("buildAll") {
group = "build version"
description = "Builds every loader for every Minecraft version into <root>/build/libs"
dependsOn tasksByVersion.values().flatten()
}
// ------ mcversion range files (essentials-core mixins) --------------------
project(":essentials-core") {
apply plugin: "idea"
idea.module.excludeDirs += file("mcversion")
}
def switchTaskType = dev.kikugie.stonecutter.controller.task.StonecutterSwitchTask
def mcversionLayout = {
def core = stonecutter.tree.getBranches().find { it.getId() == "essentials-core" }
new org.vmstudio.build.McVersionLayout(rootProject.file("essentials-core"), core.getVersions()*.getVersion())
}
def mcversionForm = {
new org.vmstudio.build.McVersionForm(rootDir, stonecutter.tree.getBranches()
.collectEntries { [(it.getId()): it.getVersions()*.getVersion()] })
}
def mcversionMove = tasks.register("mcversionMove") {
group = "stonecutter"
description = "Moves the range files covering the version switched to into essentials-core/src and parks the others"
outputs.dirs(file("essentials-core/src/main/java"), file("essentials-core/mcversion"))
outputs.upToDateWhen { false }
doLast {
def versions = gradle.taskGraph.allTasks.findAll { switchTaskType.isInstance(it) }.collect { it.version.get() }.unique()
if (versions.size() != 1) {
throw new GradleException("mcversionMove needs exactly one Stonecutter switch, found ${versions}")
}
mcversionLayout().moveTo(versions[0]).each { logger.lifecycle("mcversion: ${it}") }
}
}
def mcversionSwitch = tasks.register("mcversionSwitch") {
group = "stonecutter"
description = "Resyncs the range files with the active version, keeps the parked ones in the form of their range and every commented branch in its own names"
outputs.dirs(file("essentials-core/src/main/java"), file("essentials-core/mcversion"))
outputs.upToDateWhen { false }
onlyIf { gradle.taskGraph.allTasks.every { !switchTaskType.isInstance(it) || it.state.failure == null } }
doLast {
def active = org.vmstudio.build.McVersionLayout.activeVersion(rootDir)
mcversionLayout().switchTo(active).each { logger.lifecycle("mcversion: ${it}") }
mcversionForm().normalize(active).each { logger.lifecycle("mcversion: ${it}") }
}
}
tasks.withType(switchTaskType).configureEach { finalizedBy mcversionSwitch }
gradle.projectsEvaluated {
def requested = gradle.startParameter.taskNames
.findAll { it ==~ /:?(stonecutterSwitchTo.+|(Set|Reset|Refresh) active project.*)/ }
.collect { tasks.findByName(it.startsWith(":") ? it.substring(1) : it) }.findAll()
(requested + requested.collectMany { it.taskDependencies.getDependencies(it) as List })
.findAll { switchTaskType.isInstance(it) }
.collect { it.version.get() }.unique()
.each { version -> project(":essentials-core:${version}").tasks.named("stonecutterPrepare") { dependsOn mcversionMove } }
}
// ------ StoneCutter parameters --------------------------------------
stonecutter.parameters {
swaps.put("mod_version", "\"${mod_version}\";")
// Pure renames and package moves (ResourceLocation -> Identifier, ...): see McVersionRenames
org.vmstudio.build.McVersionRenames.forVersion(current.version).each { rule ->
replacements.regex(rule.forward(current.version)) {
replace(rule.oldPattern, rule.newText, rule.newPattern, rule.oldText)
}
}
}