Skip to content

Commit 6019e17

Browse files
committed
Merge remote-tracking branch 'upstream/mc1.20.1/dev' into mc1.21.1/dev
2 parents c0a1e02 + e431324 commit 6019e17

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ plugins {
1111
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.8" // https://github.com/JetBrains/gradle-idea-ext-plugin
1212
}
1313

14-
apply from: './gradle/java.gradle'
14+
apply from: "./gradle/java.gradle"
15+
apply from: "gradle/property_loader.gradle"
1516

1617
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equals('false')
1718
ext.buildNumber = System.getenv('BUILD_NUMBER')

gradle/property_loader.gradle

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
This module can inject build properties from a JSON file. Each property in the
3+
JSON file will be mapped to a build property using the key of that property.
4+
Property keys ending with _comment will be skipped.
5+
6+
If a secretFile property exists and points to a valid JSON file that file will
7+
be automatically loaded. You can manually load a file using the loadProperties
8+
method.
9+
*/
10+
import groovy.json.JsonSlurper
11+
12+
// Auto detects a secret file and injects it.
13+
if (project.rootProject.hasProperty("secretFile")) {
14+
project.logger.lifecycle("Automatically loading properties from the secretFile")
15+
final def secretsFile = project.rootProject.file(project.rootProject.getProperty("secretFile"))
16+
17+
if (secretsFile.exists() && secretsFile.name.endsWith(".json")) {
18+
loadProperties(secretsFile)
19+
}
20+
}
21+
22+
// Loads properties using a specified json file.
23+
def loadProperties(propertyFile) {
24+
if (propertyFile.exists()) {
25+
propertyFile.withReader {
26+
Map propMap = new JsonSlurper().parse it
27+
28+
for (entry in propMap) {
29+
30+
// Filter entries that use _comment in the key.
31+
if (!entry.key.endsWith("_comment")) {
32+
33+
project.ext.set(entry.key, entry.value)
34+
}
35+
}
36+
37+
project.logger.lifecycle("Successfully loaded " + propMap.size() + " properties")
38+
propMap.clear()
39+
}
40+
} else {
41+
project.logger.warn("The property file " + propertyFile.getName() + " could not be loaded. It does not exist.")
42+
}
43+
}
44+
45+
// Allows other scripts to use these methods.
46+
ext {
47+
loadProperties = this.&loadProperties
48+
}

0 commit comments

Comments
 (0)