SchemaDeployPlugin.groovy 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 SchemaDeployPlugin implements Plugin<Project> {
  7. @Override
  8. public void apply(Project project) {
  9. project.getPluginManager().apply('org.hidetake.ssh')
  10. project.ssh.settings {
  11. knownHosts = allowAnyHosts
  12. }
  13. project.remotes {
  14. docs {
  15. role 'docs'
  16. if (project.hasProperty('deployDocsHost')) {
  17. host = project.findProperty('deployDocsHost')
  18. } else {
  19. host = 'docs.af.pivotal.io'
  20. }
  21. retryCount = 5 // retry 5 times (default is 0)
  22. retryWaitSec = 10 // wait 10 seconds between retries (default is 0)
  23. user = project.findProperty('deployDocsSshUsername')
  24. if(project.hasProperty('deployDocsSshKeyPath')) {
  25. identity = project.file(project.findProperty('deployDocsSshKeyPath'))
  26. } else if (project.hasProperty('deployDocsSshKey')) {
  27. identity = project.findProperty('deployDocsSshKey')
  28. }
  29. if(project.hasProperty('deployDocsSshPassphrase')) {
  30. passphrase = project.findProperty('deployDocsSshPassphrase')
  31. }
  32. }
  33. }
  34. project.task('deploySchema') {
  35. dependsOn 'schemaZip'
  36. doFirst {
  37. project.ssh.run {
  38. session(project.remotes.docs) {
  39. def now = System.currentTimeMillis()
  40. def name = project.rootProject.name
  41. def version = project.rootProject.version
  42. def tempPath = "/tmp/${name}-${now}-schema/".replaceAll(' ', '_')
  43. execute "mkdir -p $tempPath"
  44. project.tasks.schemaZip.outputs.each { o ->
  45. println "Putting $o.files"
  46. put from: o.files, into: tempPath
  47. }
  48. execute "unzip $tempPath*.zip -d $tempPath"
  49. def extractPath = "/var/www/domains/spring.io/docs/htdocs/autorepo/schema/${name}/${version}/"
  50. execute "rm -rf $extractPath"
  51. execute "mkdir -p $extractPath"
  52. execute "rm -f $tempPath*.zip"
  53. execute "rm -rf $extractPath*"
  54. execute "mv $tempPath/* $extractPath"
  55. /*
  56. * Copy spring-security-oauth schemas so that legacy projects using the "http" scheme can
  57. * resolve the following schema locations:
  58. *
  59. * - http://www.springframework.org/schema/security/spring-security-oauth-1.0.xsd
  60. * - http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
  61. * - http://www.springframework.org/schema/security/spring-security-oauth2-2.0.xsd
  62. *
  63. * Note: The directory:
  64. * https://www.springframework.org/schema/security/
  65. *
  66. * is a symbolic link pointing to:
  67. * https://docs.spring.io/autorepo/schema/spring-security/current/security/
  68. *
  69. * which in turn points to the latest:
  70. * https://docs.spring.io/autorepo/schema/spring-security/$version/security/
  71. *
  72. * with the help of the autoln command which is run regularly via a cron job.
  73. *
  74. * See https://github.com/spring-io/autoln for more info.
  75. */
  76. if (name == "spring-security") {
  77. def springSecurityOauthPath = "/var/www/domains/spring.io/docs/htdocs/autorepo/schema/spring-security-oauth/current/security"
  78. execute "cp $springSecurityOauthPath/* ${extractPath}security"
  79. }
  80. execute "chmod -R g+w $extractPath"
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }