Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise and cleanup #185

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
637 changes: 396 additions & 241 deletions build.gradle

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
implementation 'org.ow2.asm:asm-tree:9.2'
implementation 'net.minecraftforge:srgutils:0.5.3'
implementation 'org.tukaani:xz:1.8' // Extract API, to extract the runtime jars, as Mojang uses lzma
implementation 'de.undercouch:gradle-download-task:4.1.1' // Bulk DownloadLibraries task
implementation 'de.undercouch:gradle-download-task:5.5.0' // Bulk DownloadLibraries task
implementation 'net.minecraftforge:mapping-verifier:2.0.8'
implementation 'net.sf.jopt-simple:jopt-simple:5.0.4' // Needed for verifier
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class CompareJars extends DefaultTask {
throw new GradleException("Comparison failed, see log for details")
}

def loadJar(jar) {
static def loadJar(jar) {
def ret = [:]
new ZipFile(jar).withCloseable{ jin ->
jin.entries().each { entry ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class CreateProjectTemplate extends DefaultTask {

if (bundle != null) {
def zf = new ZipFile(bundle)
zf.entries().findAll{ it.name.equals('META-INF/libraries.list') }.each {
zf.entries().findAll { it.name == 'META-INF/libraries.list' }.each {
zf.getInputStream(it).text.split('\r?\n').each { line ->
libs.add("'" + line.split('\t')[1] + "'")
}
Expand All @@ -84,4 +84,4 @@ public class CreateProjectTemplate extends DefaultTask {

new File(dest, 'build.gradle').withWriter('UTF-8') { it.write(data) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DeduplicateJars extends DefaultTask {
joined: joinedOut
]

def dupes = []
List dupes = []

new ZipOutputStream(duplicates.newOutputStream()).withCloseable{ du ->
inputs.client.each { name, data ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DownloadAssets extends DefaultTask {
Utils.init()

def dl = json.json.assetIndex
def index = new File(dest, 'indexes/' + dl.id + '.json')
File index = new File(dest, 'indexes/' + dl.id + '.json')
if (index.sha1 != dl.sha1)
download(dl.url, index)

Expand All @@ -25,7 +25,7 @@ public class DownloadAssets extends DefaultTask {
}
}

def download(def url, def target) {
def download(String url, File target) {
def ret = new DownloadAction(project, this)
ret.overwrite(false)
ret.useETag('all')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package net.minecraftforge.mcpconfig.tasks

import org.gradle.api.*
import org.gradle.api.file.ProjectLayout
import org.gradle.api.logging.Logger
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.*
import de.undercouch.gradle.tasks.download.DownloadAction

public class DownloadLibraries extends DefaultTask {
import javax.inject.Inject

abstract class DownloadLibraries extends DefaultTask {
@InputFile json
@Input config
@Input dest

@InputDirectory File dest

@Inject
protected abstract ProjectLayout getProjectLayout()

@Inject
protected abstract ObjectFactory getObjectFactory()

@TaskAction
def exec() {
void exec() {
Utils.init()

json.json.libraries.each{ lib ->
Expand All @@ -19,7 +30,7 @@ public class DownloadLibraries extends DefaultTask {
download(art.url, new File(dest, art.path))
}
}
for (def side : ['client', 'server', 'joined']) {
for (String side in ['client', 'server', 'joined']) {
if (config?.libraries?.get(side) != null) {
config.libraries.get(side).each { art ->
download(
Expand All @@ -32,11 +43,13 @@ public class DownloadLibraries extends DefaultTask {
}

def download(def url, def target) {
def ret = new DownloadAction(project, this)
var constructor = DownloadAction.class.getDeclaredConstructor(ProjectLayout, Logger, Object, ObjectFactory, boolean, File)
constructor.setAccessible(true)
var ret = (DownloadAction) constructor.newInstance(projectLayout, this.logger, this, objectFactory, false, projectLayout.buildDirectory.getAsFile().get())
ret.overwrite(false)
ret.useETag('all')
ret.src url
ret.dest target
ret.execute()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package net.minecraftforge.mcpconfig.tasks

import org.gradle.api.*
import org.gradle.api.tasks.*
import de.undercouch.gradle.tasks.download.Download

public class DownloadTool extends Download {
class DownloadTool extends Download {
@Input config

public DownloadTool() {
DownloadTool() {
useETag 'all'
onlyIfModified true
quiet true
}

def config(def cfg, def root) {
def config(def cfg, String root) {
this.config = cfg
src cfg.repo + cfg.path
dest new File(root + cfg.path)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package net.minecraftforge.mcpconfig.tasks
import org.gradle.api.tasks.*
import java.util.zip.*

public class FernflowerTask extends ToolJarExec {
class FernflowerTask extends ToolJarExec {
@InputFile File libraries
@InputFile File input
@OutputFile File log
@OutputFile File dest

@Override
protected void preExec() {
def logStream = log.newOutputStream()
standardOutput logStream
errorOutput logStream
var logStream = log.newOutputStream()
standardOutput = logStream
errorOutput = logStream
setArgs(Utils.fillVariables(args, [
'libraries': libraries,
'input': input,
Expand All @@ -25,17 +25,17 @@ public class FernflowerTask extends ToolJarExec {
protected void postExec() {
if (!dest.exists())
throw new IllegalStateException('Could not find fernflower output: ' + dest)
def failed = []
new ZipFile(dest).withCloseable{ zip ->
zip.entries().findAll{ !it.directory && it.name.endsWith('.java') }.each { e ->
def data = zip.getInputStream(e).text
List<String> failed = []
new ZipFile(dest).withCloseable { zip ->
zip.entries().findAll { !it.directory && it.name.endsWith('.java') }.each { e ->
String data = zip.getInputStream(e).text
if (data.isEmpty() || data.contains("\$FF: Couldn't be decompiled"))
failed.add(e.name)
}
}
if (!failed.isEmpty()) {
logger.lifecycle('Failed to decompile: ')
failed.each{ logger.lifecycle(' ' + it) }
failed.each { logger.lifecycle(' ' + it) }
throw new IllegalStateException('Decompile failed')
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.minecraftforge.mcpconfig.tasks;

import org.gradle.api.*
import org.gradle.api.tasks.*

class MergeJar extends ToolJarExec {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.minecraftforge.mcpconfig.tasks;

import org.gradle.api.*
import org.gradle.api.tasks.*

class RemapJar extends ToolJarExec {
Expand All @@ -12,14 +11,14 @@ class RemapJar extends ToolJarExec {

@Override
protected void preExec() {
def logStream = log == null ? JarExec.NULL_OUTPUT : log.newOutputStream()
standardOutput logStream
errorOutput logStream
var logStream = log === null ? JarExec.NULL_OUTPUT : log.newOutputStream()
standardOutput = logStream
errorOutput = logStream
setArgs(Utils.fillVariables(args, [
'mappings': mappings.absolutePath,
'input': input.absolutePath,
'output': dest.absolutePath,
'libraries': libraries.absolutePath
]))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class RenameMappings extends SingleFileOutput {
@InputFile @Optional official

@TaskAction
def exec() {
void exec() {
Utils.init()
def ret
if (official != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public class RenameSources extends DefaultTask {
def ocls = moff.getClass(scls.original)
if (ocls != null) {
scls.fields.each{ sfld ->
if (sfld.mapped.startsWith('f_') || sfld.mapped.startsWith('field_'))
if (sfld.mapped.startsWithAny('f_', 'field_'))
ret.put(sfld.mapped, ocls.remapField(sfld.original))
}
scls.methods.each{ smtd ->
if (smtd.mapped.startsWith('m_') || smtd.mapped.startsWith('func_'))
if (smtd.mapped.startsWithAny('m_', 'func_'))
ret.put(smtd.mapped, ocls.remapMethod(smtd.original, smtd.descriptor))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import org.gradle.api.tasks.*

//Small helper base task that only outputs one file, this is useful so I can jsut do task.dest instead of task.outputs.files.singleFile
class SingleFileOutput extends DefaultTask {
@OutputFile File dest //dest is used to be consistant with the download plugin's Download task
}
@OutputFile File dest //dest is used to be consistent with the download plugin's Download task
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import net.minecraftforge.srgutils.IMappingFile
public class SplitJar extends DefaultTask {
@InputFile mappings
@InputFile source
@OutputFile slim
@OutputFile extra
@OutputFile File slim
@OutputFile File extra

@TaskAction
def exec() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package net.minecraftforge.mcpconfig.tasks;
package net.minecraftforge.mcpconfig.tasks

import de.undercouch.gradle.tasks.download.Download;
import org.gradle.api.tasks.*
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.jvm.toolchain.JavaToolchainService

import javax.inject.Inject

class ToolJarExec extends JavaExec {
def config(def cfg, def task) {
void config(def cfg, Download task) {
classpath = project.files(task.dest)
args = cfg.args
jvmArgs = cfg.jvmargs
Expand All @@ -34,12 +35,12 @@ class ToolJarExec extends JavaExec {
}

@Override
public final void exec() {
final void exec() {
this.preExec()
super.exec()
this.postExec()
}

protected void preExec(){}
protected void postExec(){}
}
protected void preExec() {}
protected void postExec() {}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package net.minecraftforge.mcpconfig.tasks;
package net.minecraftforge.mcpconfig.tasks

import groovy.transform.CompileStatic;

import java.util.*
import java.util.regex.Matcher
Expand Down Expand Up @@ -60,9 +62,10 @@ class Utils {
}
return allow
}

static def getOsName() {
def name = System.getProperty('os.name').toLowerCase(java.util.Locale.ENGLISH)

@CompileStatic
static String getOsName() {
String name = System.getProperty('os.name').toLowerCase(Locale.ENGLISH)
if (name.contains('windows') || name.contains('win')) return 'windows'
if (name.contains('linux') || name.contains('unix')) return 'linux'
if (name.contains('osx') || name.contains('mac')) return 'osx'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ import java.util.function.Predicate

import net.minecraftforge.mappingverifier.MappingVerifier

public class VerifyMappings extends DefaultTask {
@InputFile mappings
@InputFile joined
@InputFile o2s2idMappings
class VerifyMappings extends DefaultTask {
@InputFile File mappings
@InputFile File joined
@InputFile File o2s2idMappings

@TaskAction
def exec() {
void exec() {
Utils.init()

MappingVerifier mv = new MappingVerifier()
mv.loadMap(mappings)
mv.loadJar(joined)
mv.addDefaultTasks()

def die = false
boolean die = false
if (!mv.verify()) {
for (def t : mv.tasks) {
if (!t.errors.isEmpty()) {
Expand Down Expand Up @@ -118,7 +118,7 @@ public class VerifyMappings extends DefaultTask {
unique.add(id)
}

duplicates.each {s -> error('Id ' + s + ' is a duplicate.')}
duplicates.each { s -> error('Id ' + s + ' is a duplicate.')}

return superProcess && duplicates.isEmpty()
}
Expand Down
Loading