From f755499edf11b54270fec6834ff8a99f113b2abe Mon Sep 17 00:00:00 2001 From: glowredman <35727266+glowredman@users.noreply.github.com> Date: Thu, 27 Jan 2022 08:27:39 +0100 Subject: [PATCH] Update deobf method to save BON2 and deobfuscated jars in the gradle directory (#12) --- .gitignore | 1 - build.gradle | 49 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 92daf92..75c41f6 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,3 @@ src/main/resources/mixins.*.json *.bat *.DS_Store !gradlew.bat -/deobf/ diff --git a/build.gradle b/build.gradle index fd2582f..5a2270d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1642964305 +//version: 1643020202 /* DO NOT CHANGE THIS FILE! @@ -598,11 +598,43 @@ configure(updateBuildScript) { // Deobfuscation -def deobf(String sourceURL, String fileName) { - def bon2File = "$projectDir/deobf/BON2-2.5.0.jar" - def cacheFile = "$projectDir/deobf/out/" + fileName + ".jar" - def deobfFile = "$projectDir/deobf/out/" + fileName + "-deobf.jar" +def deobf(String sourceURL) { + try { + URL url = new URL(sourceURL) + String fileName = url.getFile() + //get rid of directories: + int lastSlash = fileName.lastIndexOf("/") + if(lastSlash > 0) { + fileName = fileName.substring(lastSlash + 1) + } + //get rid of extension: + if(fileName.endsWith(".jar")) { + fileName = fileName.substring(0, fileName.lastIndexOf(".")) + } + + String hostName = url.getHost() + if(hostName.startsWith("www.")) { + hostName = hostName.substring(4) + } + List parts = Arrays.asList(hostName.split("\\.")) + Collections.reverse(parts) + hostName = String.join(".", parts) + + return deobf(sourceURL, hostName + "/" + fileName) + } catch(Exception e) { + return deobf(sourceURL, "deobf/" + String.valueOf(sourceURL.hashCode())) + } +} + +// The method above is to be prefered. Use this method if the filename is not at the end of the URL. +def deobf(String sourceURL, String fileName) { + String cacheDir = System.getProperty("user.home") + "/.gradle/caches/" + String bon2Dir = cacheDir + "forge_gradle/deobf" + String bon2File = bon2Dir + "/BON2-2.5.0.jar" + String obfFile = cacheDir + "modules-2/files-2.1/" + fileName + ".jar" + String deobfFile = cacheDir + "modules-2/files-2.1/" + fileName + "-deobf.jar" + if(file(deobfFile).exists()) { return files(deobfFile) } @@ -616,18 +648,17 @@ def deobf(String sourceURL, String fileName) { download { src sourceURL - dest cacheFile + dest obfFile quiet true overwrite false } exec { - commandLine 'java', '-jar', bon2File, '--inputJar', cacheFile, '--outputJar', deobfFile, '--mcVer', '1.7.10', '--mappingsVer', 'stable_12', '--notch' - workingDir "$projectDir/deobf" + commandLine 'java', '-jar', bon2File, '--inputJar', obfFile, '--outputJar', deobfFile, '--mcVer', '1.7.10', '--mappingsVer', 'stable_12', '--notch' + workingDir bon2Dir standardOutput = new ByteArrayOutputStream() } - delete(cacheFile) return files(deobfFile) }