From 14d311be9392c7e69c4af0b428e5bd9085150387 Mon Sep 17 00:00:00 2001 From: Lucwousin Date: Tue, 3 Sep 2019 04:55:37 +0200 Subject: [PATCH] Gradle: Add decompile task to projects (#1273) * Gradle: Add decompile task to projects * add ff as dependency rather than adding ti in buildsrc * smh smh smh smh smh * Add ff version in buildsrc build file This doesn't work in ext as it officially isn't part of the project * Add missing ''s --- build.gradle | 5 +-- buildSrc/build.gradle | 7 ++++ .../src/main/groovy/FernflowerPlugin.groovy | 16 ++++++++++ .../src/main/groovy/FernflowerTask.groovy | 32 +++++++++++++++++++ .../gradle-plugins/fernflower.properties | 1 + injected-client/build.gradle | 3 ++ 6 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 buildSrc/build.gradle create mode 100644 buildSrc/src/main/groovy/FernflowerPlugin.groovy create mode 100644 buildSrc/src/main/groovy/FernflowerTask.groovy create mode 100644 buildSrc/src/main/resources/META-INF/gradle-plugins/fernflower.properties diff --git a/build.gradle b/build.gradle index 6693733d49..543cbe322b 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ ext { asm = '7.1' commonsCli = '1.4' discord = '1.1' - fernflower = '20171017' + fernflower = '07082019' findbugs = '3.0.2' gson = '2.8.5' guava = '28.0-jre' @@ -82,7 +82,7 @@ ext { allprojects { apply plugin: 'maven' - apply plugin: 'checkstyle' + if (this.name != 'rs-client') apply plugin: 'checkstyle' group = 'net.runelite' version = '1.5.33-SNAPSHOT' @@ -105,6 +105,7 @@ subprojects { apply plugin: 'java-library' apply plugin: 'maven' apply plugin: "com.github.ben-manes.versions" + apply plugin: 'fernflower' sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000000..b74b24deb8 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,7 @@ +repositories { + maven { url "https://raw.githubusercontent.com/runelite-extended/maven-repo/master" } +} +dependencies { + compile localGroovy() + implementation group: 'net.runelite', name: 'fernflower', version: '07082019' +} diff --git a/buildSrc/src/main/groovy/FernflowerPlugin.groovy b/buildSrc/src/main/groovy/FernflowerPlugin.groovy new file mode 100644 index 0000000000..062adced78 --- /dev/null +++ b/buildSrc/src/main/groovy/FernflowerPlugin.groovy @@ -0,0 +1,16 @@ +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.tasks.StopExecutionException + +class FernflowerPlugin implements Plugin { + void apply(Project project) { + project.task('decompile', type: FernflowerTask) { + it.dependsOn(project.tasks.jar) + it.doFirst { + if (!project.tasks.jar.didWork) { + throw new StopExecutionException() + } + } + } + } +} diff --git a/buildSrc/src/main/groovy/FernflowerTask.groovy b/buildSrc/src/main/groovy/FernflowerTask.groovy new file mode 100644 index 0000000000..49e46b5639 --- /dev/null +++ b/buildSrc/src/main/groovy/FernflowerTask.groovy @@ -0,0 +1,32 @@ +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler + +class FernflowerTask extends DefaultTask { + List extraArgs + String inputJar + String outputDir + + @InputFile + File getInputJar() { + project.file(inputJar ?: project.buildDir.toString() + '/libs/' + project.getName() + '-' + project.version + '.jar') + } + + @OutputDirectory + File getOutputDir() { + project.file(outputDir ?: project.buildDir.toString() + '/decompiled-sources') + } + + @TaskAction + void decompile() { + getOutputDir().mkdirs() + def args = [getInputJar().toString(), getOutputDir().toString()] + if (extraArgs) { + args.addAll(extraArgs) + } + + ConsoleDecompiler.main(args as String[]) + } +} \ No newline at end of file diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/fernflower.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/fernflower.properties new file mode 100644 index 0000000000..3d922df9d7 --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/fernflower.properties @@ -0,0 +1 @@ +implementation-class=FernflowerPlugin \ No newline at end of file diff --git a/injected-client/build.gradle b/injected-client/build.gradle index 38c22b7dd0..e0810e7bad 100644 --- a/injected-client/build.gradle +++ b/injected-client/build.gradle @@ -44,3 +44,6 @@ classes.doLast() { File f = file("build/classes/java/main/Placeholder.class") f.delete() } + +// tasks.build.dependsOn(tasks.decompile) +// this is just here to show how this could be used \ No newline at end of file