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:
16
buildSrc/src/main/groovy/FernflowerPlugin.groovy
Normal file
16
buildSrc/src/main/groovy/FernflowerPlugin.groovy
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
buildSrc/src/main/groovy/FernflowerTask.groovy
Normal file
32
buildSrc/src/main/groovy/FernflowerTask.groovy
Normal 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[])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
implementation-class=FernflowerPlugin
|
||||
Reference in New Issue
Block a user