2
0

spring-security-docs.gradle 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. plugins {
  2. id 'org.antora' version '1.0.0-alpha.7'
  3. }
  4. apply plugin: 'io.spring.convention.docs'
  5. apply plugin: 'java'
  6. antora {
  7. playbook = 'cached-antora-playbook.yml'
  8. playbookProvider {
  9. repository = 'spring-projects/spring-security'
  10. branch = 'docs-build'
  11. path = 'lib/antora/templates/per-branch-antora-playbook.yml'
  12. checkLocalBranch = true
  13. }
  14. options = [clean: true, stacktrace: true]
  15. }
  16. tasks.register('generateAntora') {
  17. group = 'Documentation'
  18. description = 'Generates the antora.yml for dynamic properties'
  19. doLast {
  20. def docsTag = snapshotBuild ? 'current' : project.version
  21. def ghTag = snapshotBuild ? 'main' : project.version
  22. def ghUrl = "https://github.com/spring-projects/spring-security/tree/$ghTag"
  23. def ghOldSamplesUrl = 'https://github.com/spring-projects/spring-security/tree/5.4.x/samples'
  24. def ghSamplesUrl = "https://github.com/spring-projects/spring-security-samples/tree/$samplesBranch"
  25. def securityDocsUrl = "https://docs.spring.io/spring-security/site/docs/$docsTag"
  26. def securityApiUrl = "$securityDocsUrl/api/"
  27. def securityReferenceUrl = "$securityDocsUrl/reference/html5/"
  28. def springFrameworkApiUrl = "https://docs.spring.io/spring-framework/docs/$springFrameworkVersion/javadoc-api/"
  29. def springFrameworkReferenceUrl = "https://docs.spring.io/spring-framework/docs/$springFrameworkVersion/reference/html/"
  30. def ymlVersions = resolvedVersions(project.configurations.testRuntimeClasspath).call()
  31. .collect(v -> " ${v.getKey()}: ${v.getValue()}")
  32. .join('\n')
  33. def outputFile = layout.buildDirectory.file('generateAntora/antora.yml').get().asFile
  34. mkdir(outputFile.getParentFile())
  35. def mainVersion = project.version
  36. def prerelease = null
  37. def versionComponents = mainVersion.split(/(?=-)/)
  38. if (versionComponents.length > 1) {
  39. if (versionComponents[1] == '-SNAPSHOT') {
  40. mainVersion = versionComponents[0]
  41. prerelease = "'-SNAPSHOT'"
  42. } else {
  43. prerelease = 'true'
  44. }
  45. }
  46. def antoraYmlText = file('antora.yml').text
  47. layout.buildDirectory.file('.antora.yml').get().asFile.text = antoraYmlText
  48. antoraYmlText = antoraYmlText.lines().collect { l ->
  49. if (l.startsWith('version: ')) {
  50. return prerelease == null ? "version: '${mainVersion}'" : "version: '${mainVersion}'\nprerelease: ${prerelease}"
  51. }
  52. if (l.startsWith('title: ')) return "title: ${project.parent.description}"
  53. return l == 'ext:' || l.getAt(0) == ' ' ? null : l
  54. }.findAll(Objects::nonNull).join('\n')
  55. outputFile.text = """$antoraYmlText
  56. asciidoc:
  57. attributes:
  58. icondir: icons
  59. gh-old-samples-url: $ghOldSamplesUrl
  60. gh-samples-url: $ghSamplesUrl
  61. gh-url: $ghUrl
  62. security-api-url: $securityApiUrl
  63. security-reference-url: $securityReferenceUrl
  64. spring-framework-api-url: $springFrameworkApiUrl
  65. spring-framework-reference-url: $springFrameworkReferenceUrl
  66. spring-security-version: ${project.version}
  67. ${ymlVersions}
  68. """
  69. }
  70. }
  71. dependencies {
  72. testImplementation platform(project(':spring-security-dependencies'))
  73. testImplementation 'com.unboundid:unboundid-ldapsdk'
  74. testImplementation 'org.apache.directory.server:apacheds-core'
  75. testImplementation 'org.springframework:spring-core'
  76. }
  77. def resolvedVersions(Configuration configuration) {
  78. return {
  79. configuration.resolvedConfiguration
  80. .resolvedArtifacts
  81. .collectEntries { [(it.name + '-version'): it.moduleVersion.id.version] }
  82. }
  83. }
  84. repositories {
  85. mavenCentral()
  86. maven { url 'https://repo.spring.io/release' }
  87. maven { url 'https://repo.spring.io/milestone' }
  88. maven { url 'https://repo.spring.io/snapshot' }
  89. }