-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
file_publisher.gradle
96 lines (90 loc) · 3.13 KB
/
file_publisher.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
import java.security.MessageDigest
import java.net.URL
repositories {
mavenLocal()
mavenCentral()
maven { url = 'https://files.minecraftforge.net/maven/' }
maven { url = 'https://libraries.minecraft.net/' }
}
def sha1(file) {
MessageDigest md = MessageDigest.getInstance('SHA-1')
file.eachByte 4096, {bytes, size ->
md.update(bytes, 0, size)
}
return md.digest().collect {String.format "%02x", it}.join()
}
def md5(file) {
MessageDigest md = MessageDigest.getInstance('MD5')
file.eachByte 4096, {bytes, size ->
md.update(bytes, 0, size)
}
return md.digest().collect {String.format "%02x", it}.join()
}
def artifactTree(repo, artifact, transitive) {
if (!project.ext.has('tree_resolver'))
project.ext.tree_resolver = 1
def cfg = project.configurations.create('tree_resolver_' + project.ext.tree_resolver++)
cfg.transitive = transitive
def dep = project.dependencies.create(artifact)
cfg.dependencies.add(dep)
def files = cfg.resolve()
cfg.resolvedConfiguration.resolvedArtifacts.each {
def art = [
group: it.moduleVersion.id.group,
name: it.moduleVersion.id.name,
version: it.moduleVersion.id.version,
classifier: it.classifier,
extension: it.extension,
file: it.file
]
def key = art.group + ':' + art.name
def folder = "${art.group.replace('.', '/')}/${art.name}/${art.version}/"
def filename = "${art.name}-${art.version}"
if (art.classifier != null)
filename += "-${art.classifier}"
filename += ".${art.extension}"
def path = "${folder}${filename}"
def desc = "${art.group}:${art.name}:${art.version}"
if (art.classifier != null)
desc += ":${art.classifier}"
if (art.extension != 'jar')
desc += "@${art.extension}"
def url = "https://libraries.minecraft.net/${path}"
if (checkExists(url)) {
println("Mojang Artifact: ${desc}")
} else {
url = "https://files.minecraftforge.net/maven/${path}"
if (checkExists(url)) {
println("Forge Artifact: ${desc}")
} else {
println("Pending Artifact: ${desc}")
def target = project.file("${repo}/${folder}")
target.mkdirs()
copy {
from art.file
into target
rename { filename }
}
project.file("${target}/${filename}.sha1").text = sha1(it.file)
project.file("${target}/${filename}.md5").text = md5(it.file)
}
}
}
}
def checkExists(url) {
def code = new URL(url).openConnection().with {
requestMethod = 'HEAD'
connect()
responseCode
}
return code == 200
}
//TODO: Make Forge's build explode if a file is missing from our repo
task artifacts() {
doLast {
file('dep_repo').deleteDir()
[
'com.google.code.findbugs:jsr305:3.0.1'
].forEach{art -> artifactTree('dep_repo', art, false)}
}
}