SchemaZipPlugin.groovy 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package io.spring.gradle.convention
  2. import org.gradle.api.plugins.JavaPlugin
  3. import org.gradle.api.tasks.bundling.Zip
  4. import org.gradle.api.Plugin
  5. import org.gradle.api.Project
  6. public class SchemaZipPlugin implements Plugin<Project> {
  7. @Override
  8. public void apply(Project project) {
  9. Zip schemaZip = project.tasks.create('schemaZip', Zip)
  10. schemaZip.group = 'Distribution'
  11. schemaZip.baseName = project.rootProject.name
  12. schemaZip.classifier = 'schema'
  13. schemaZip.description = "Builds -${schemaZip.classifier} archive containing all " +
  14. "XSDs for deployment at static.springframework.org/schema."
  15. project.rootProject.subprojects.each { module ->
  16. module.getPlugins().withType(JavaPlugin.class).all {
  17. def Properties schemas = new Properties();
  18. module.sourceSets.main.resources.find {
  19. it.path.endsWith('META-INF/spring.schemas')
  20. }?.withInputStream { schemas.load(it) }
  21. for (def key : schemas.keySet()) {
  22. def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
  23. assert shortName != key
  24. File xsdFile = module.sourceSets.main.resources.find {
  25. it.path.endsWith(schemas.get(key))
  26. }
  27. assert xsdFile != null
  28. schemaZip.into (shortName) {
  29. duplicatesStrategy 'exclude'
  30. from xsdFile.path
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }