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
This commit is contained in:
Lucwousin
2019-09-03 04:55:37 +02:00
committed by GitHub
parent 0609123f86
commit 14d311be93
6 changed files with 62 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.StopExecutionException
class FernflowerPlugin implements Plugin<Project> {
void apply(Project project) {
project.task('decompile', type: FernflowerTask) {
it.dependsOn(project.tasks.jar)
it.doFirst {
if (!project.tasks.jar.didWork) {
throw new StopExecutionException()
}
}
}
}
}

View File

@@ -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<String> 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[])
}
}

View File

@@ -0,0 +1 @@
implementation-class=FernflowerPlugin