|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import grails.doc.dropdown.SoftwareVersion |
| 21 | +import grails.doc.git.FetchTagsTask |
| 22 | +import grails.doc.dropdown.CreateReleaseDropDownTask |
| 23 | +import org.asciidoctor.gradle.jvm.AsciidoctorTask |
| 24 | + |
| 25 | +plugins { |
| 26 | + id 'groovy' |
| 27 | +} |
| 28 | + |
| 29 | +apply plugin: 'org.asciidoctor.jvm.convert' |
| 30 | +apply from: rootProject.layout.projectDirectory.file('gradle/reproducible-config.gradle') |
| 31 | + |
| 32 | +// Spring Security + GORM are resolved from the BOM for LDAP doc link generation. |
| 33 | +dependencies { |
| 34 | + implementation platform("org.apache.grails:grails-bom:$grailsVersion") |
| 35 | + implementation 'org.springframework.security:spring-security-core' |
| 36 | + implementation 'org.apache.grails.data:grails-datamapping-core' |
| 37 | + implementation 'org.apache.groovy:groovy' |
| 38 | +} |
| 39 | + |
| 40 | +String getGrailsDocumentationVersion(String version) { |
| 41 | + if (version.endsWith('-SNAPSHOT')) { |
| 42 | + return 'snapshot' |
| 43 | + } |
| 44 | + return version |
| 45 | +} |
| 46 | + |
| 47 | +// NOTE: This resolves dependencies at configuration time, which means any Gradle command |
| 48 | +// at the root level will trigger resolution for this project. Ideally this would be deferred |
| 49 | +// to task execution time, but the Asciidoctor plugin requires attributes at configuration time. |
| 50 | +ext { |
| 51 | + resolvedSpringSecurityVersion = configurations.compileClasspath |
| 52 | + .resolvedConfiguration |
| 53 | + .resolvedArtifacts |
| 54 | + .find { |
| 55 | + it.moduleVersion.id.group == 'org.springframework.security' && |
| 56 | + it.moduleVersion.id.name == 'spring-security-core' |
| 57 | + }.moduleVersion.id.version |
| 58 | + resolvedGormVersion = configurations.compileClasspath |
| 59 | + .resolvedConfiguration |
| 60 | + .resolvedArtifacts |
| 61 | + .find { |
| 62 | + it.moduleVersion.id.group == 'org.apache.grails.data' && |
| 63 | + it.moduleVersion.id.name == 'grails-datamapping-core' |
| 64 | + }.moduleVersion.id.version |
| 65 | +} |
| 66 | +logger.lifecycle('Resolved Spring Security version for Guide links: {}', resolvedSpringSecurityVersion) |
| 67 | +logger.lifecycle('Resolved GORM version for Guide links: {}', resolvedGormVersion) |
| 68 | + |
| 69 | +ext { |
| 70 | + coreDocsDir = rootProject.layout.projectDirectory.dir('plugin-core/docs/src/docs') |
| 71 | + aclDocsDir = rootProject.layout.projectDirectory.dir('plugin-acl/docs/src/docs') |
| 72 | + casDocsDir = rootProject.layout.projectDirectory.dir('plugin-cas/docs/src/docs') |
| 73 | + ldapDocsDir = rootProject.layout.projectDirectory.dir('plugin-ldap/docs/src/docs') |
| 74 | + oauth2DocsDir = rootProject.layout.projectDirectory.dir('plugin-oauth2/docs/src/docs') |
| 75 | + restDocsDir = rootProject.layout.projectDirectory.dir('plugin-rest/docs/src/docs') |
| 76 | + uiDocsDir = rootProject.layout.projectDirectory.dir('plugin-ui/docs/src/docs') |
| 77 | + |
| 78 | + combinedAttributes = [ |
| 79 | + copyright : 'Apache License, Version 2.0', |
| 80 | + docinfo1 : 'true', |
| 81 | + doctype : 'book', |
| 82 | + encoding : 'utf-8', |
| 83 | + icons : 'font', |
| 84 | + id : "grails-spring-security-combined:${projectVersion}", |
| 85 | + idprefix : '', |
| 86 | + idseparator : '-', |
| 87 | + lang : 'en', |
| 88 | + linkattrs : true, |
| 89 | + numbered : '', |
| 90 | + producer : 'Asciidoctor', |
| 91 | + revnumber : projectVersion, |
| 92 | + projectVersion : projectVersion, |
| 93 | + version : projectVersion, |
| 94 | + setanchors : true, |
| 95 | + 'source-highlighter' : 'prettify', |
| 96 | + toc : 'left', |
| 97 | + toc2 : '', |
| 98 | + toclevels : '3', |
| 99 | + 'experimental' : 'true', |
| 100 | + 'compat-mode' : '', |
| 101 | + 'threeZeroXProjectVersion' : '3.0.1', |
| 102 | + // Cross-project include directories |
| 103 | + 'core-docs-dir' : coreDocsDir.asFile.absolutePath, |
| 104 | + 'acl-docs-dir' : aclDocsDir.asFile.absolutePath, |
| 105 | + 'cas-docs-dir' : casDocsDir.asFile.absolutePath, |
| 106 | + 'ldap-docs-dir' : ldapDocsDir.asFile.absolutePath, |
| 107 | + 'oauth2-docs-dir' : oauth2DocsDir.asFile.absolutePath, |
| 108 | + 'rest-docs-dir' : restDocsDir.asFile.absolutePath, |
| 109 | + 'ui-docs-dir' : uiDocsDir.asFile.absolutePath, |
| 110 | + // REST-specific |
| 111 | + 'sourcedir' : "${rootProject.findProject(':spring-security-rest').projectDir}/src/main/groovy", |
| 112 | + 'baseGroovyApiUrl' : "https://apache.github.io/grails-spring-security/${projectVersion}/rest-plugin/groovydoc/", |
| 113 | + // LDAP-specific |
| 114 | + 'customUserDetailsContextMapperPath': "${rootProject.findProject(':ldap-examples-custom-user-details-context-mapper').projectDir}", |
| 115 | + 'functionalTestAppPath' : "${rootProject.findProject(':ldap-examples-functional-test-app').projectDir}", |
| 116 | + 'projectUrl' : 'https://github.com/apache/grails-spring-security', |
| 117 | + 'gormDetailedLink' : "https://gorm.grails.org/${getGrailsDocumentationVersion(resolvedGormVersion)}/hibernate/manual/index.html", |
| 118 | + 'gormSummaryLink' : "https://docs.grails.org/${getGrailsDocumentationVersion(grailsVersion)}/guide/GORM.html", |
| 119 | + 'grailsDocBase' : "https://docs.grails.org/${getGrailsDocumentationVersion(grailsVersion)}", |
| 120 | + 'grailsSpringSecurityCoreVersion' : projectVersion, |
| 121 | + 'grailsSpringSecurityCoreLink' : "https://apache.github.io/grails-spring-security/${getGrailsDocumentationVersion(projectVersion)}/guide/index.html", |
| 122 | + 'springSecurityLdapLink' : "https://docs.spring.io/spring-security/reference/${resolvedSpringSecurityVersion}/servlet/authentication/passwords/ldap.html", |
| 123 | + 'springSecurityLdapApiLink' : "https://docs.spring.io/spring-security/site/docs/${resolvedSpringSecurityVersion}/api", |
| 124 | + // Used by index.adoc header links |
| 125 | + 'springSecurityVersion' : resolvedSpringSecurityVersion, |
| 126 | + 'springFrameworkVersion' : '6.2.x', |
| 127 | + ] |
| 128 | +} |
| 129 | + |
| 130 | +tasks.named('asciidoctor', AsciidoctorTask) { |
| 131 | + sourceDir(layout.projectDirectory.file('src/docs')) |
| 132 | + sources { include('index.adoc') } |
| 133 | + outputDir = layout.buildDirectory.file('docs') |
| 134 | + attributes(combinedAttributes) |
| 135 | + baseDirFollowsSourceDir() |
| 136 | + jvm { |
| 137 | + jvmArgs('--add-opens', 'java.base/sun.nio.ch=ALL-UNNAMED', '--add-opens', 'java.base/java.io=ALL-UNNAMED') |
| 138 | + } |
| 139 | + // Declare inputs for all plugin doc sources so Gradle knows to rebuild when they change |
| 140 | + inputs.dir(coreDocsDir) |
| 141 | + inputs.dir(aclDocsDir) |
| 142 | + inputs.dir(casDocsDir) |
| 143 | + inputs.dir(ldapDocsDir) |
| 144 | + inputs.dir(oauth2DocsDir) |
| 145 | + inputs.dir(restDocsDir) |
| 146 | + inputs.dir(uiDocsDir) |
| 147 | + inputs.dir(sourceDir) |
| 148 | + outputs.dir(outputDir) |
| 149 | +} |
| 150 | + |
| 151 | +def guideDocs = tasks.register('guideDocs', Copy) { |
| 152 | + group = 'documentation' |
| 153 | + dependsOn('asciidoctor') |
| 154 | + duplicatesStrategy = DuplicatesStrategy.INCLUDE |
| 155 | + into(layout.buildDirectory.dir('docs')) |
| 156 | + ['plugin-core', 'plugin-acl', 'plugin-cas', 'plugin-ldap', 'plugin-oauth2', 'plugin-rest', 'plugin-ui'].each { pluginDir -> |
| 157 | + from(rootProject.layout.projectDirectory.dir(pluginDir).dir("docs/src/docs")) { |
| 158 | + include('**/*.png', '**/*.jpg', '**/*.gif', '**/*.svg') |
| 159 | + } |
| 160 | + } |
| 161 | + from(layout.projectDirectory.dir('src/docs')) { |
| 162 | + include('**/*.png', '**/*.jpg', '**/*.gif', '**/*.svg') |
| 163 | + } |
| 164 | +} |
| 165 | + |
| 166 | +def fetchTagsTask = tasks.register('fetchTags', FetchTagsTask) |
| 167 | + |
| 168 | +def createReleaseDropdown = tasks.register('createReleaseDropdown', CreateReleaseDropDownTask) { |
| 169 | + filesToAddDropdowns = layout.buildDirectory.files('docs-modified/index.html') |
| 170 | + sourceDocsDirectory = layout.buildDirectory.dir('docs') |
| 171 | + modifiedPagesDirectory = layout.buildDirectory.dir('docs-modified') |
| 172 | + githubSlug = 'apache/grails-spring-security' |
| 173 | + docBaseUrl = "https://apache.github.io/grails-spring-security" |
| 174 | + versionHtml = '<span id="revnumber">version ' + project.version + '</span>' |
| 175 | + additionalPath = "guide/" |
| 176 | + minimumVersion = SoftwareVersion.build('7.0.0-SNAPSHOT') |
| 177 | + dependsOn(fetchTagsTask) |
| 178 | + dependsOn(guideDocs) |
| 179 | +} |
| 180 | + |
| 181 | +tasks.register('copyGuide', Copy) { |
| 182 | + dependsOn(createReleaseDropdown) |
| 183 | + from(layout.buildDirectory.dir('docs-modified')) |
| 184 | + into(rootProject.layout.buildDirectory.dir('docs/guide')) |
| 185 | +} |
| 186 | + |
| 187 | +tasks.register('copyGhPages', Copy) { |
| 188 | + group = 'documentation' |
| 189 | + description = 'Copy the landing page to the root docs directory' |
| 190 | + from(project.layout.projectDirectory.dir('src/docs')) { |
| 191 | + include 'index.tmpl' |
| 192 | + rename('index.tmpl', 'ghpages.html') |
| 193 | + } |
| 194 | + into(rootProject.layout.buildDirectory.dir('docs')) |
| 195 | +} |
| 196 | + |
| 197 | +tasks.register('aggregateDocs') { |
| 198 | + group = 'documentation' |
| 199 | + description = 'Aggregate all documentation into the root docs directory' |
| 200 | + // Combined guide |
| 201 | + dependsOn('copyGuide') |
| 202 | + // Groovydocs from each plugin's docs subproject |
| 203 | + dependsOn(':core-docs:groovydoc') |
| 204 | + dependsOn(':acl-docs:groovydoc') |
| 205 | + dependsOn(':cas-docs:groovydoc') |
| 206 | + dependsOn(':ldap-docs:groovydoc') |
| 207 | + dependsOn(':oauth2-docs:groovydoc') |
| 208 | + dependsOn(':rest-docs:groovydoc') |
| 209 | + dependsOn(':ui-docs:groovydoc') |
| 210 | + |
| 211 | + // Landing page |
| 212 | + dependsOn('copyGhPages') |
| 213 | +} |
0 commit comments