spring-security-docs.gradle 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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, prerelease) = project.version.split(/(?=-)/, 2)
  39. def antoraYmlText = file('antora.yml').text
  40. layout.buildDirectory.file('.antora.yml').get().asFile.text = antoraYmlText
  41. antoraYmlText = antoraYmlText.lines().collect { l ->
  42. if (l.startsWith('version: ')) {
  43. return prerelease == null ? "version: '${mainVersion}'" : "version: '${mainVersion}'\nprerelease: '${prerelease}'"
  44. }
  45. if (l.startsWith('title: ')) return "title: ${project.parent.description}"
  46. return l == 'ext:' || l.getAt(0) == ' ' ? null : l
  47. }.findAll(Objects::nonNull).join('\n')
  48. outputFile.text = """$antoraYmlText
  49. asciidoc:
  50. attributes:
  51. icondir: icons
  52. gh-old-samples-url: $ghOldSamplesUrl
  53. gh-samples-url: $ghSamplesUrl
  54. gh-url: $ghUrl
  55. security-api-url: $securityApiUrl
  56. security-reference-url: $securityReferenceUrl
  57. spring-framework-api-url: $springFrameworkApiUrl
  58. spring-framework-reference-url: $springFrameworkReferenceUrl
  59. spring-security-version: ${project.version}
  60. ${ymlVersions}
  61. """
  62. }
  63. }
  64. dependencies {
  65. testImplementation platform(project(':spring-security-dependencies'))
  66. testImplementation 'com.unboundid:unboundid-ldapsdk'
  67. testImplementation 'org.apache.directory.server:apacheds-core'
  68. testImplementation 'org.springframework:spring-core'
  69. }
  70. def resolvedVersions(Configuration configuration) {
  71. return {
  72. configuration.resolvedConfiguration
  73. .resolvedArtifacts
  74. .collectEntries { [(it.name + '-version'): it.moduleVersion.id.version] }
  75. }
  76. }
  77. repositories {
  78. mavenCentral()
  79. maven { url 'https://repo.spring.io/release' }
  80. maven { url 'https://repo.spring.io/milestone' }
  81. maven { url 'https://repo.spring.io/snapshot' }
  82. }