spring-security-docs.gradle 3.6 KB

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