build.gradle 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import org.gradle.api.file.ArchiveOperations
  2. apply plugin: 'elasticsearch.java'
  3. sourceSets {
  4. patcher
  5. }
  6. configurations {
  7. thejar {
  8. canBeResolved = true
  9. }
  10. }
  11. dependencies {
  12. thejar("org.apache.hadoop:hadoop-client-api:${project.parent.versions.hadoop}") {
  13. transitive = false
  14. }
  15. patcherImplementation 'org.ow2.asm:asm:9.7.1'
  16. patcherImplementation 'org.ow2.asm:asm-tree:9.7.1'
  17. }
  18. def outputDir = layout.buildDirectory.dir("patched-classes")
  19. def patchTask = tasks.register("patchClasses", JavaExec) {
  20. inputs.files(configurations.thejar).withPathSensitivity(PathSensitivity.RELATIVE)
  21. inputs.files(sourceSets.patcher.output).withPathSensitivity(PathSensitivity.RELATIVE)
  22. outputs.dir(outputDir)
  23. classpath = sourceSets.patcher.runtimeClasspath
  24. mainClass = 'org.elasticsearch.hdfs.patch.HdfsClassPatcher'
  25. def thejar = configurations.thejar
  26. doFirst {
  27. args(thejar.singleFile, outputDir.get().asFile)
  28. }
  29. }
  30. interface InjectedArchiveOps {
  31. @Inject ArchiveOperations getArchiveOperations()
  32. }
  33. tasks.named('jar').configure {
  34. dependsOn(configurations.thejar)
  35. def injected = project.objects.newInstance(InjectedArchiveOps)
  36. def thejar = configurations.thejar
  37. from(patchTask)
  38. from({ injected.getArchiveOperations().zipTree(thejar.singleFile) }) {
  39. eachFile {
  40. if (outputDir.get().file(it.relativePath.pathString).asFile.exists()) {
  41. it.exclude()
  42. }
  43. }
  44. }
  45. }