2
0

spring-security-docs.gradle 3.4 KB

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