-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.gradle
155 lines (137 loc) · 5.57 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import java.nio.file.Files
import java.security.MessageDigest
plugins {
id 'java-base'
id 'com.diffplug.eclipse.apt' version '3.44.0' apply false
}
group 'com.fox2code'
version project['foxloader.version']
tasks.register('publishToMavenLocal', Task)
subprojects {
apply plugin: 'java-library'
apply plugin: 'com.diffplug.eclipse.apt'
repositories {
mavenCentral()
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
maven {
url 'https://repo.spongepowered.org/maven'
content {
includeGroup "org.spongepowered"
}
}
maven {
name = 'Fabric'
url 'https://maven.fabricmc.net/'
content {
includeGroup "net.fabricmc"
}
}
maven {
url 'https://cdn.fox2code.com/maven'
}
maven {
url 'https://jitpack.io/'
}
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
withSourcesJar()
withJavadocJar()
}
// Support "@reason" javadoc Mixin tag mandated by Minecraft-Dev Intellij plugin
javadoc.options.tags = [ "reason" ]
test {
useJUnitPlatform()
}
afterEvaluate {
tasks.withType(JavaCompile.class).configureEach {
options.compilerArgs += '-g'
options.encoding = 'UTF-8'
}
final String reindevVersion = project['reindev.version'] as String
final String reindevVersionAllowFrom = project['reindev.version.allowFrom'] as String
if (project.pluginManager.hasPlugin("maven-publish")) {
rootProject.tasks.publishToMavenLocal.dependsOn(publishToMavenLocal)
publishing {
publications {
release(MavenPublication) {
from components.java
groupId = "com.github.Fox2Code.FoxLoader"
artifactId = project.name
version = '1.0' // JitPack only work with "1.0" as version
pom {
url = 'https://github.com/Fox2Code/FoxLoader'
if (reindevVersion == reindevVersionAllowFrom) {
properties = [
"foxloader.version": project['foxloader.version'] as String,
"reindev.version" : reindevVersion,
]
} else {
properties = [
"foxloader.version" : project['foxloader.version'] as String,
"reindev.version" : reindevVersion,
"reindev.version.allowFrom": reindevVersionAllowFrom,
]
}
}
}
}
}
}
}
}
// We need to download client and server to be able to compile the project.
// Let's do that there really quick.
static void downloadIfNeeded(URL url, File file, String hash) {
file.getParentFile().mkdirs()
if (file.exists()) {
byte[] localData = Files.readAllBytes(file.toPath())
byte[] localHash = MessageDigest.getInstance("SHA-256").digest(localData)
String hashString = new BigInteger(1, localHash).toString(16)
if (hashString == hash) return
if (!file.delete()) {
throw new IOException("Failed to delete corrupted file: " + file.getName())
}
}
println("Downloading " + url)
HttpURLConnection connection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY)
String javaVendor = System.getProperty("java.vendor")
String javaVersion = System.getProperty("java.version")
String javaVendorVersion = System.getProperty("java.vm.version")
String osName = System.getProperty("os.name")
String osVersion = System.getProperty("os.version")
String osArch = System.getProperty("os.arch")
connection.setConnectTimeout(5000)
connection.setRequestProperty("Connection", "keep-alive")
connection.setRequestProperty("User-Agent", String.format("Gradle/7.5.1 (%s;%s;%s) (%s;%s;%s)",
osName, osVersion, osArch, javaVendor, javaVersion, javaVendorVersion))
file.withOutputStream { fileOut ->
fileOut << connection.getInputStream()
}
byte[] fileData = Files.readAllBytes(file.toPath())
byte[] fileHash = MessageDigest.getInstance("SHA-256").digest(fileData)
String hashString = new BigInteger(1, fileHash).toString(16)
if (hash != hashString) {
throw new IOException("Excpeted HASH: " + hash + " got " + hashString)
}
}
File clientFile = new File(project.rootDir, "client" + File.separator +
"libs" + File.separator + project['reindev.clientJar'])
File serverFile = new File(project.rootDir, "server" + File.separator +
"libs" + File.separator + project['reindev.serverJar'])
downloadIfNeeded(new URL(project['reindev.clientUrl'] as String), clientFile,
project['reindev.clientSHA256Sum'] as String)
downloadIfNeeded(new URL(project['reindev.serverUrl'] as String), serverFile,
project['reindev.serverSHA256Sum'] as String)