-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
128 lines (107 loc) · 3.58 KB
/
build.gradle
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
125
126
127
128
import net.fabricmc.mappingio.*
import net.fabricmc.mappingio.adapter.MappingNsCompleter
import net.fabricmc.mappingio.format.*
import net.fabricmc.mappingio.tree.*
buildscript {
repositories {
maven {
name "Fabric Repository"
url 'https://maven.fabricmc.net'
}
}
dependencies {
classpath 'net.fabricmc:mapping-io:0.3.0'
}
}
plugins {
id 'maven-publish'
}
static List<String> getPublishedVersions() {
String xml
try {
xml = new URL("https://maven.glass-launcher.net/babric/babric/intermediary/maven-metadata.xml").text
} catch (FileNotFoundException ignored) {
return []
}
def metadata = new XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text();
return versions
}
def publishedVersions = getPublishedVersions()
def ENV = System.getenv()
def published = false
def localMappingsPath = "$buildDir/v2Mappings"
new File(localMappingsPath).mkdirs()
file('mappings').eachFile {
if (!it.name.endsWith(".tiny")) return
def mcVer = it.name.replace(".tiny", "")
if (publishedVersions.contains(mcVer) && !(ENV.FORCE_PUBLISH == mcVer)) {
project.logger.lifecycle("Skipping ${mcVer} as it has already been released")
return
} else {
project.logger.lifecycle("Building ${mcVer}")
}
published = true
File v1MappingFile = it
File v2MappingFile = new File("$localMappingsPath/${it.name}")
def conversionTask = "convert${it.name}ToV2"
tasks.register(conversionTask) {
group = "V2 Conversion"
inputs.file(v1MappingFile)
outputs.file(v2MappingFile)
doLast {
def memoryMappingTree = new MemoryMappingTree()
MappingNsCompleter nsCompleter = new MappingNsCompleter(memoryMappingTree, Map.of("glue", "intermediary", "server", "intermediary", "client", "intermediary"));
MappingReader.read(v1MappingFile.toPath(), nsCompleter)
try (MappingWriter mappingWriter = MappingWriter.create(v2MappingFile.toPath(), MappingFormat.TINY_2)) {
memoryMappingTree.accept(mappingWriter)
}
}
}
Jar makeV1Jar = makeJar(mcVer, v1MappingFile, false)
Jar makeV2Jar = makeJar(mcVer, v2MappingFile, true)
makeV2Jar.dependsOn conversionTask
publishing {
publications {
create("${mcVer.replace(" ", "")}_mavenJava", MavenPublication) {
groupId "babric"
artifactId "intermediary"
version mcVer
artifact(makeV1Jar.archiveFile) {
builtBy makeV1Jar
}
artifact(makeV2Jar.archiveFile) {
builtBy makeV2Jar
classifier = "v2"
}
}
}
}
}
if (!published) {
throw new RuntimeException("Nothing to publish, override with the FORCE_PUBLISH env")
}
def makeJar(String mcVersion, File mappings, boolean v2) {
def jarFilename = "intermediary-" + mcVersion + (v2 ? "-v2" : "")
return task("${mcVersion}_makeJar" + (v2 ? "v2" : ""), type: Jar) {
baseName jarFilename
from(file(mappings)) {
into "mappings"
rename mappings.name, "mappings.tiny"
}
destinationDirectory = file("build/jars")
}
}
publishing {
repositories {
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
}