Work on installer json generation.

This commit is contained in:
LexManos 2018-09-28 20:50:01 -07:00
parent bb9eca96a8
commit b54bd33332
2 changed files with 157 additions and 41 deletions

View file

@ -57,12 +57,6 @@ This software contains a partial repackaging of javaxdelta, a BSD licensed progr
binary differences and applying them, sourced from the subversion at http://sourceforge.net/projects/javaxdelta/ binary differences and applying them, sourced from the subversion at http://sourceforge.net/projects/javaxdelta/
authored by genman, heikok, pivot. authored by genman, heikok, pivot.
The only changes are to replace some Trove collection types with standard Java collections, and repackaged. The only changes are to replace some Trove collection types with standard Java collections, and repackaged.
This software contains potions of Paulscodee IBXM library, a BSD liceensed library for
loading and playing IBXM formated auto. No modifications havee beeen made. The associated
licenses can be found along side this one, or at
https://github.com/MinecraftForge/MinecraftForge/blob/1.12.x/LICENSE-Paulscode%20IBXM%20Library.txt
https://github.com/MinecraftForge/MinecraftForge/blob/1.12.x/LICENSE-Paulscode%20SoundSystem%20CodecIBXM.txt
========================================================================= =========================================================================

View file

@ -14,6 +14,7 @@ import groovy.json.JsonBuilder
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
import java.security.MessageDigest import java.security.MessageDigest
import java.net.URL
import net.minecraftforge.gradle.common.task.SignJar import net.minecraftforge.gradle.common.task.SignJar
import org.apache.tools.ant.filters.ReplaceTokens import org.apache.tools.ant.filters.ReplaceTokens
import de.undercouch.gradle.tasks.download.Download import de.undercouch.gradle.tasks.download.Download
@ -289,32 +290,9 @@ project(':forge') {
'java3d:vecmath' 'java3d:vecmath'
] ]
def mojang = [] def mojang = []
def artifacts = getArtifacts(project, project.configurations.compileClasspath)
project.configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifacts.each { key, lib ->
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
if (forge.contains(key) || mojang.contains(key)){ if (forge.contains(key) || mojang.contains(key)){
def url = forge.contains(key) ? "https://files.minecraftforge.net/maven/" : "https://libraries.minecraft.net/"
def path = "${art.group.replace('.', '/')}/${art.name}/${art.version}/${art.name}-${art.version}"
if (art.classifier != null)
path += "-${art.classifier}"
path += ".${art.extension}"
def lib = [
name: "${art.group}:${art.name}:${art.version}" + (art.classifier == null ? '' : ":${art.classifier}") + (art.extension == 'jar' ? '' : "@${art.extension}"),
downloads: [
path: path,
url: url + path,
sha1: sha1(art.file),
size: art.file.length()
]
]
json.libraries.add(lib) json.libraries.add(lib)
} }
} }
@ -325,21 +303,87 @@ project(':forge') {
task installerJson() { task installerJson() {
ext { ext {
output = file('build/libs/installer.json') output = file('build/libs/install_profile.json')
} }
dependsOn launcherJson dependsOn launcherJson
inputs.file launcherJson.output inputs.file launcherJson.output
outputs.file output outputs.file output
doLast { doLast {
def idx = project.version.indexOf('-')
def json = [ def json = [
install: [ _comment_: launcherJson.comment,
_comment_: launcherJson.comment, profile: project.name,
profileName: project.name, version: project.version.substring(0, idx) + "-${project.name}" + project.version.substring(idx),
version: project.version.split('-')[0] + '-forge-' + project.version.split('-')[1], json: '/version.json',
json: '/version.json', path: "${project.group}:${project.name}:${project.version}",
logo: '/big_logo.png' logo: '/big_logo.png',
minecraft: patcher.mcVersion,
welcome: "Welcome to the simple ${project.name.capitalize()} installer.",
processors: [],
data: [
MAPPINGS: [
client: '/data/joined.tsrg',
server: '/data/joined.tsrg'
],
BINPATCH: [
client: '/data/client.lzma',
server: '/data/server.lzma'
],
MC_SLIM: [
client: "[net.minecraft:client:${patcher.mcVersion}:slim]",
server: "[net.minecraft:server:${patcher.mcVersion}:slim]"
],
MC_DATA: [
client: "[net.minecraft:client:${patcher.mcVersion}:data]",
server: "[net.minecraft:server:${patcher.mcVersion}:data]"
],
MC_EXTRA: [
client: "[net.minecraft:client:${patcher.mcVersion}:extra]",
server: "[net.minecraft:server:${patcher.mcVersion}:extra]"
],
PATCHED: [
client: "[${project.group}:${project.name}:${project.version}:client-patched]",
server: "[${project.group}:${project.name}:${project.version}:server-patched]"
],
REMAPPED: [
client: "[${project.group}:${project.name}:${project.version}:client-srg]",
server: "[${project.group}:${project.name}:${project.version}:server-srg]"
]
] ]
] ]
def libs = [:]
json.processors.add([
jar: 'net.minecraftforge:jarsplitter:1.0.3',
classpath: getClasspath(project, libs, 'net.minecraftforge:jarsplitter:1.0.3'),
args: [
'--input', '{MINECRAFT_JAR}',
'--slim', "{MC_SLIM}",
'--data', "{MC_DATA}",
'--extra', "{MC_EXTRA}",
'--srg', '{MAPPINGS}'
]
])
json.processors.add([
jar: 'net.minecraftforge:binarypatcher:1.0.3',
classpath: getClasspath(project, libs, 'net.minecraftforge:binarypatcher:1.0.3'),
args: [
'--clean', '{MC_SLIM}',
'--output', '{PATCHED}',
'--apply', '{BINPATCH}'
]
])
json.processors.add([
jar: 'net.md-5:SpecialSource:1.8.3',
classpath: getClasspath(project, libs, 'net.md-5:SpecialSource:1.8.3'),
args: [
'--in-jar', '{PATCHED}',
'--out-jar', '{REMAPPED}',
'--srg-in', '{MAPPINGS}'
]
])
json.libraries = libs.values()
output.text = new JsonBuilder(json).toPrettyString() output.text = new JsonBuilder(json).toPrettyString()
} }
} }
@ -556,12 +600,90 @@ def dateToIso8601(date) {
def result = format.format(date) def result = format.format(date)
return result[0..21] + ':' + result[22..-1] return result[0..21] + ':' + result[22..-1]
} }
def sha1(file) { def sha1(file) {
MessageDigest md = MessageDigest.getInstance("SHA-1"); MessageDigest md = MessageDigest.getInstance('SHA-1')
file.eachByte 4096, {bytes, size -> file.eachByte 4096, {bytes, size ->
md.update(bytes, 0, size); md.update(bytes, 0, size)
} }
return md.digest().collect {String.format "%02x", it}.join(); return md.digest().collect {String.format "%02x", it}.join()
}
def artifactTree(project, artifact) {
if (!project.ext.has('tree_resolver'))
project.ext.tree_resolver = 1
def cfg = project.configurations.create('tree_resolver_' + project.ext.tree_resolver++)
def dep = project.dependencies.create(artifact)
cfg.dependencies.add(dep)
def files = cfg.resolve()
return getArtifacts(project, cfg)
}
def getArtifacts(project, config) {
def ret = [:]
config.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 url = "https://libraries.minecraft.net/${path}"
if (!checkExists(url)) {
url = "https://files.minecraftforge.net/maven/${path}"
/*
project.logger.lifecycle("Artifact: ${path}")
def repo = project.file("build/dep_repo/${folder}")
repo.mkdirs()
copy {
from art.file
into folder
rename { filename }
}
project.file("build/dep_repo/${path}.sha1").text = sha1(it.file)
*/
}
ret[key] = [
name: "${art.group}:${art.name}:${art.version}" + (art.classifier == null ? '' : ":${art.classifier}") + (art.extension == 'jar' ? '' : "@${art.extension}"),
downloads: [
artifact: [
path: path,
url: url,
sha1: sha1(art.file),
size: art.file.length()
]
]
]
}
return ret
}
def checkExists(url) {
def code = new URL(url).openConnection().with {
requestMethod = 'HEAD'
connect()
responseCode
}
return code == 200
}
def getClasspath(project, libs, artifact) {
def ret = []
artifactTree(project, artifact).each { key, lib ->
libs[lib.name] = lib
if (lib.name != artifact)
ret.add(lib.name)
}
return ret
} }
//evaluationDependsOnChildren() //evaluationDependsOnChildren()