-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
125 lines (106 loc) · 2.73 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
import java.util.regex.Pattern
import org.apache.commons.io.FileUtils
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "commons-io:commons-io:2.8.0"
}
}
plugins {
id 'de.undercouch.download' version '5.6.0'
id 'java'
id 'maven-publish'
}
def ENV = System.getenv()
def maven_url = ENV.MAVEN_URL
def maven_group = "net.ornithemc"
def maven_group_for_url = "net.ornithemc".replace(".", "/")
def artifact_id = "nests"
def publishedVersions = new HashMap<String, Integer>()
if (maven_url) {
try {
def xml = new URL("${maven_url}/${maven_group_for_url}/${artifact_id}/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
metadata.versioning.versions.version.each {
String[] version = it.text().split(Pattern.quote("+build."))
String mcVersion = version[0]
int build = Integer.parseInt(version[1])
publishedVersions.compute(mcVersion, (key, value) -> value == null || build > value ? build : value)
}
} catch (FileNotFoundException ignored) {
// only happens if no publications exist yet
}
}
def temp = file(".gradle/temp/")
static String version(String mcVersion, int build) {
return "${mcVersion}+build.${build}"
}
file("nests").eachFile {
if (!it.name.endsWith(".nest")) {
return
}
def nests = it
def mcVersion = nests.name.replace(".nest", "")
def prevBuild = publishedVersions.getOrDefault(mcVersion, 0)
def nextBuild = prevBuild + 1
if (prevBuild > 0) {
def prevVersion = version(mcVersion, prevBuild)
def prevJar = new File(temp, "nests.jar")
def prevNests = new File(temp, "mappings.nest")
download.run {
src new URL("${maven_url}/${maven_group_for_url}/${artifact_id}/${prevVersion}/nests-${prevVersion}.jar")
dest prevJar
overwrite true
}
copy {
from({ zipTree(prevJar) }) {
from "nests/mappings.nest"
rename "mappings.nest", "../${prevNests.name}"
}
into prevNests.parentFile
}
if (FileUtils.contentEquals(nests, prevNests)) {
return
}
}
def nextVersion = version(mcVersion, nextBuild)
def makeJar = task("${nextVersion}_makeJar", type: Jar) {
archiveFileName = "nests-${nextVersion}.jar"
from(file(nests)) {
into "nests"
rename nests.name, "mappings.nest"
}
destinationDirectory = file("build/jars")
}
build.dependsOn makeJar
publishing {
publications {
create("${mcVersion.replace(" ", "")}_mavenJava", MavenPublication) {
groupId maven_group
artifactId artifact_id
version nextVersion
artifact(makeJar.archiveFile) {
builtBy makeJar
}
}
}
}
}
publishing {
repositories {
if (maven_url) {
maven {
url maven_url
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
authentication {
basic(BasicAuthentication)
}
}
}
}
}