forked from MinecraftForge/ForgeGradle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
420 lines (366 loc) · 15.3 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.gradle.publish:plugin-publish-plugin:0.9.1"
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'
classpath 'org.ow2.asm:asm:6.2.1'
classpath 'org.ow2.asm:asm-tree:6.2.1'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven'
apply plugin: "com.gradle.plugin-publish"
apply plugin: 'license'
group = 'net.minecraftforge.gradle'
version = '2.3-SNAPSHOT'
//version = '2.2.1'
archivesBaseName = 'ForgeGradle'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
repositories {
mavenLocal()
maven {
name = "forge"
url = "https://maven.minecraftforge.net/"
}
maven {
// because Srg2Source needs an eclipse dependency.
name = "eclipse"
url = "https://repo.eclipse.org/content/groups/eclipse/"
}
jcenter() // get as many deps from here as possible
mavenCentral()
// because SS and its snapshot
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
// because of the GradleStart stuff
maven {
name = "mojang"
url = "https://libraries.minecraft.net/"
}
}
configurations {
deployerJars
shade
compileOnly.extendsFrom shade
all {
resolutionStrategy {
force 'org.ow2.asm:asm-commons:6.0'
force 'org.ow2.asm:asm-tree:6.0'
force 'org.ow2.asm:asm:6.0'
}
}
}
dependencies {
compile gradleApi()
// moved to the beginning to be the overrider
//compile 'org.ow2.asm:asm-debug-all:6.0'
compile 'com.google.guava:guava:18.0'
compile 'net.sf.opencsv:opencsv:2.3' // reading CSVs.. also used by SpecialSource
compile 'com.cloudbees:diff4j:1.1' // for difing and patching
compile 'com.github.abrarsyed.jastyle:jAstyle:1.3' // formatting
compile 'net.sf.trove4j:trove4j:2.1.0' // because its awesome.
compile 'com.github.jponge:lzma-java:1.3' // replaces the LZMA binary
compile 'com.nothome:javaxdelta:2.0.1' // GDIFF implementation for BinPatches
compile 'com.google.code.gson:gson:2.2.4' // Used instead of Argo for buuilding changelog.
compile 'com.github.tony19:named-regexp:0.2.3' // 1.7 Named regexp features
compile 'net.minecraftforge:forgeflower:1.0.342-SNAPSHOT' // Fernflower Forge edition
shade 'net.md-5:SpecialSource:1.8.2' // deobf and reobf
// because curse
compile 'org.apache.httpcomponents:httpclient:4.3.3'
compile 'org.apache.httpcomponents:httpmime:4.3.3'
// mcp stuff
shade 'de.oceanlabs.mcp:RetroGuard:3.6.6'
shade('de.oceanlabs.mcp:mcinjector:3.4-SNAPSHOT'){
exclude group: 'org.ow2.asm'
}
shade('net.minecraftforge:Srg2Source:5.0.+'){
exclude group: 'org.ow2.asm'
exclude group: 'org.eclipse.equinox', module: 'org.eclipse.equinox.common'
exclude group: 'cpw.mods', module: 'modlauncher'
}
//Stuff used in the GradleStart classes
compileOnly 'com.mojang:authlib:1.5.16'
compileOnly('net.minecraft:launchwrapper:1.11'){
exclude group: 'org.ow2.asm'
}
compileOnly 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.3-2'
testCompile 'junit:junit:4.12'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.14'
}
sourceSets {
main.compileClasspath += configurations.shade;
main.runtimeClasspath += configurations.shade;
test.compileClasspath += configurations.shade;
test.runtimeClasspath += configurations.shade;
}
compileJava {
options.deprecation = true
//options.compilerArgs += ["-Werror"]
//options.compilerArgs += ["-Werror", "-Xlint:unchecked"]
}
processResources {
from(sourceSets.main.resources.srcDirs) {
include 'forgegradle.version.txt'
expand 'version': project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'forgegradle.version.txt'
}
}
import java.util.zip.*
import org.objectweb.asm.*
import org.objectweb.asm.tree.*
//TODO: Eclipse complains about unused messages. Find a way to make it shut up.
class PatchJDTClasses extends DefaultTask {
static def COMPILATION_UNIT_RESOLVER = 'org/eclipse/jdt/core/dom/CompilationUnitResolver'
static def RANGE_EXTRACTOR = 'net/minecraftforge/srg2source/ast/RangeExtractor'
def RESOLVE_METHOD = 'resolve([Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;Lorg/eclipse/jdt/core/dom/FileASTRequestor;ILjava/util/Map;I)V'
def GET_CONTENTS = 'org/eclipse/jdt/internal/compiler/util/Util.getFileCharContent(Ljava/io/File;Ljava/lang/String;)[C'
def HOOK_DESC_RESOLVE = '(Ljava/lang/String;Ljava/lang/String;)[C'
@Input def targets = [] as Set
@Input def libraries = [] as Set
@OutputFile File output
void target(String value) {
targets.add(value)
}
void library(File value) {
libraries.add(value)
}
@TaskAction
void patchClass() {
def toProcess = targets.collect()
new ZipOutputStream(new FileOutputStream(output)).withCloseable{ zout ->
libraries.stream().filter{ !it.isDirectory() }.each { lib ->
new ZipFile(lib).withCloseable { zin ->
def remove = []
toProcess.each{ target ->
def entry = zin.getEntry(target+'.class')
if (entry == null)
return
def node = new ClassNode()
def reader = new ClassReader(zin.getInputStream(entry))
reader.accept(node, 0)
//CompilationUnitResolver allows batch compiling, the problem is it is hardcoded to read the contents from a File.
//So we patch this call to redirect to us, so we can get the contents from our InputSupplier
if (COMPILATION_UNIT_RESOLVER.equals(target)) {
logger.lifecycle('Transforming: ' + target + ' From: ' + lib)
def resolve = node.methods.find{ RESOLVE_METHOD.equals(it.name + it.desc) }
if (resolve == null)
throw new RuntimeException('Failed to patch ' + target + ': Could not find method ' + RESOLVE_METHOD)
for (int x = 0; x < resolve.instructions.size(); x++) {
def insn = resolve.instructions.get(x)
if (insn.type == AbstractInsnNode.METHOD_INSN) {
if (GET_CONTENTS.equals(insn.owner + '.' + insn.name + insn.desc)) {
if (
resolve.instructions.get(x - 5).opcode == Opcodes.NEW &&
resolve.instructions.get(x - 4).opcode == Opcodes.DUP &&
resolve.instructions.get(x - 3).opcode == Opcodes.ALOAD &&
resolve.instructions.get(x - 2).opcode == Opcodes.INVOKESPECIAL &&
resolve.instructions.get(x - 1).opcode == Opcodes.ALOAD
) {
resolve.instructions.set(resolve.instructions.get(x - 5), new InsnNode(Opcodes.NOP)); // NEW File
resolve.instructions.set(resolve.instructions.get(x - 4), new InsnNode(Opcodes.NOP)); // DUP
resolve.instructions.set(resolve.instructions.get(x - 2), new InsnNode(Opcodes.NOP)); // INVOKESTATIC <init>
insn.owner = RANGE_EXTRACTOR
insn.desc = HOOK_DESC_RESOLVE
logger.lifecycle('Patched ' + node.name)
} else {
throw new IllegalStateException('Found Util.getFileCharContents call, with unexpected context')
}
}
}
}
} else if (RANGE_EXTRACTOR.equals(target)) {
logger.lifecycle('Tansforming: ' + target + ' From: ' + lib)
def marker = node.methods.find{ 'hasBeenASMPatched()Z'.equals(it.name + it.desc) }
if (marker == null)
throw new RuntimeException('Failed to patch ' + target + ': Could not find method hasBeenASMPatched()Z')
marker.instructions.clear()
marker.instructions.add(new InsnNode(Opcodes.ICONST_1))
marker.instructions.add(new InsnNode(Opcodes.IRETURN))
logger.lifecycle('Patched: ' + node.name)
}
def writer = new ClassWriter(0)
node.accept(writer)
remove.add(target)
def nentry = new ZipEntry(entry.name)
nentry.time = 0
zout.putNextEntry(nentry)
zout.write(writer.toByteArray())
zout.closeEntry()
}
toProcess.removeAll(remove)
}
}
if (!toProcess.isEmpty())
throw new IllegalStateException('Patching class failed: ' + toProcess)
}
}
}
task patchJDT(type: PatchJDTClasses) {
target PatchJDTClasses.COMPILATION_UNIT_RESOLVER
target PatchJDTClasses.RANGE_EXTRACTOR
configurations.shade.resolvedConfiguration.resolvedArtifacts.stream().filter { dep ->
dep.name.equals('org.eclipse.jdt.core') || dep.name.equals('Srg2Source')
}
.forEach { dep -> library dep.file }
output file('build/patchJDT/patch_jdt.jar')
}
jar {
dependsOn('patchJDT')
configurations.shade.each { dep ->
/* I can use this again to find where dupes come from, so.. gunna just keep it here.
logger.lifecycle(dep.toString())
project.zipTree(dep).visit {
element ->
def path = element.relativePath.toString()
if (path.contains('org/eclipse/core') && path.endsWith('.class'))
println " $element.relativePath"
}
*/
from(project.zipTree(dep)){
exclude 'META-INF', 'META-INF/**', '.api_description', '.options', 'about.html', 'module-info.class', 'plugin.properties', 'plugin.xml', 'about_files/**'
duplicatesStrategy 'warn'
}
}
from(zipTree(patchJDT.output)){
duplicatesStrategy 'include'
}
manifest {
attributes 'version':project.version
attributes 'javaCompliance': project.targetCompatibility
attributes 'group':project.group
attributes 'Implementation-Version': project.version + getGitHash()
}
}
javadoc {
classpath += configurations.compileOnly
// linked javadoc urls.. why not...
options.addStringOption 'link', 'https://gradle.org/docs/current/javadoc/'
options.addStringOption 'link', 'http://docs.guava-libraries.googlecode.com/git-history/v18.0/javadoc'
options.addStringOption 'link', 'http://asm.ow2.org/asm50/javadoc/user/'
}
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc
classifier = "javadoc"
}
artifacts {
archives jar
//archives javadocJar
}
test {
if (project.hasProperty("filesmaven")) // disable this test when on the forge jenkins
exclude "**/ExtensionMcpMappingTest*"
}
license {
ext {
description = 'A Gradle plugin for the creation of Minecraft mods and MinecraftForge plugins.'
year = '2013-' + Calendar.getInstance().get(Calendar.YEAR)
fullname = 'Minecraft Forge'
}
header rootProject.file('HEADER')
include '**net/minecraftforge/gradle/**/*.java'
excludes ([
'**net/minecraftforge/gradle/util/ZipFileTree.java',
'**net/minecraftforge/gradle/util/json/version/*',
'**net/minecraftforge/gradle/util/patching/Base64.java',
'**net/minecraftforge/gradle/util/patching/ContextualPatch.java'
])
ignoreFailures false
strictCheck true
mapping {
java = 'SLASHSTAR_STYLE'
}
}
pluginBundle {
website = 'http://www.gradle.org/'
vcsUrl = 'https://github.com/MinecraftForge/ForgeGradle'
description = 'Gradle plugin for all Minecraft mod development needs'
tags = ['forge', 'minecraft', 'minecraftforge', 'sponge', 'mcp']
plugins {
patcher {
id = 'net.minecraftforge.gradle.patcher'
displayName = 'Minicraft Patcher Plugin'
}
tweakerClient {
id = 'net.minecraftforge.gradle.tweaker-client'
displayName = 'Mincraft Client Tweaker Plugin'
}
tweakerServer {
id = 'net.minecraftforge.gradle.tweaker-server'
displayName = 'Mincraft Server Tweaker Plugin'
}
forge {
id = 'net.minecraftforge.gradle.forge'
displayName = 'MincraftForge Mod Development Plugin'
}
launch4j {
id = 'net.minecraftforge.gradle.launch4j'
displayName = 'Specialized Launch4J Gradle Plugin'
}
}
}
uploadArchives {
repositories.mavenDeployer {
dependsOn 'build'
repository(url: project.repositories.mavenLocal().getUrl())
pom {
groupId = project.group
version = project.version
artifactId = project.archivesBaseName
project {
name project.archivesBaseName
packaging 'jar'
description 'GTCE Gradle plugin fork for Forge'
url 'https://github.com/GregTechCE/ForgeGradle'
scm {
url 'https://github.com/GregTechCE/ForgeGradle'
connection 'scm:git:git://github.com/GregTechCE/ForgeGradle.git'
developerConnection 'scm:git:[email protected]:GregTechCE/ForgeGradle.git'
}
issueManagement {
system 'github'
url 'https://github.com/GregTechCE/ForgeGradle/issues'
}
licenses {
license {
name 'Lesser GNU Public License, Version 2.1'
url 'https://www.gnu.org/licenses/lgpl-2.1.html'
distribution 'repo'
}
}
developers {
developer {
id 'AbrarSyed'
name 'Abrar Syed'
roles { role 'developer' }
}
developer {
id 'LexManos'
name 'Lex Manos'
roles { role 'developer' }
}
}
}
}
}
}
// write out version so its convenient for doc deployment
file('build').mkdirs()
file('build/version.txt').text = version;
def getGitHash() {
def process = 'git rev-parse --short HEAD'.execute()
process.waitFor()
return '-' + (process.exitValue() ? 'unknown' : process.text.trim())
}