From 74b66591e9f36c66766989c34d708fb89331a55d Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Wed, 4 Aug 2010 02:04:40 +0100 Subject: [PATCH] Build refactoring. --- build.gradle | 235 +++--------------- .../main/groovy/docbook/DocbookPlugin.groovy | 3 + docs/docs.gradle | 107 ++++++++ docs/faq/faq.gradle | 17 -- docs/manual/manual.gradle | 19 -- gradle/dist.gradle | 80 ++++++ settings.gradle | 14 +- 7 files changed, 228 insertions(+), 247 deletions(-) create mode 100644 docs/docs.gradle delete mode 100644 docs/faq/faq.gradle delete mode 100644 docs/manual/manual.gradle create mode 100644 gradle/dist.gradle diff --git a/build.gradle b/build.gradle index f326aac803..b387e67a3b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,5 @@ apply plugin: 'base' -buildscript { - repositories { - mavenRepo urls: 'http://gradle.artifactoryonline.com/gradle/plugins' - } - dependencies { - classpath "org.gradle.plugins:gradle-idea-plugin:0.3" - } -} - allprojects { version = '3.1.0.CI-SNAPSHOT' releaseBuild = version.endsWith('RELEASE') @@ -27,7 +18,41 @@ allprojects { } } -allprojects { +javaProjects = subprojects.findAll { project -> project.name != 'docs' && project.name != 'faq' && project.name != 'manual' } +sampleProjects = subprojects.findAll { project -> project.name.startsWith('spring-security-samples') } +itestProjects = subprojects.findAll { project -> project.name.startsWith('itest') } +coreModuleProjects = javaProjects - sampleProjects - itestProjects +aspectjProjects = [project(':spring-security-aspects'), project(':spring-security-samples-aspectj')] +releaseProjects = coreModuleProjects + project(':spring-security-aspects') + +configure(javaProjects) { + apply from: "$rootDir/gradle/javaprojects.gradle" +} + +configure(coreModuleProjects) { + apply from: "$rootDir/gradle/bundlor.gradle" + apply from: "$rootDir/gradle/maven.gradle" + // Gives better names in structure101 jar diagram + sourceSets.main.classesDir = new File(buildDir, "classes/" + project.name.substring("spring-security".length() + 1)) +} + +configure (aspectjProjects) { + apply from: "$rootDir/gradle/aspectj.gradle" +} + +configurations { + antlibs +} + +dependencies { + antlibs "org.springframework.build:org.springframework.build.aws.ant:3.0.3.RELEASE", + "net.java.dev.jets3t:jets3t:0.6.1" +} + +apply from: "$rootDir/gradle/dist.gradle" +apply plugin: 'idea' + +configure(javaProjects) { apply plugin: 'idea' ideaModule { downloadJavadoc=false @@ -71,194 +96,4 @@ ideaWorkspace { } } */ -configure(javaProjects) { - apply from: "$rootDir/gradle/javaprojects.gradle" -} - -configure(coreModuleProjects) { - apply from: "$rootDir/gradle/bundlor.gradle" - apply from: "$rootDir/gradle/maven.gradle" - // Gives better names in structure101 jar diagram - sourceSets.main.classesDir = new File(buildDir, "classes/" + project.name.substring("spring-security".length() + 1)) -} - -configure (aspectjProjects) { - apply from: "$rootDir/gradle/aspectj.gradle" -} - -configurations { - antlibs -} - -dependencies { - antlibs "org.springframework.build:org.springframework.build.aws.ant:3.0.3.RELEASE", - "net.java.dev.jets3t:jets3t:0.6.1" -} - -task apidocs(type: Javadoc) { - destinationDir = new File(buildDir, 'apidocs') - title = "Spring Security $version API" - optionsFile = file("$buildDir/tmp/javadoc.options") - - source coreModuleProjects.collect {project -> - project.sourceSets.main.allJava - } - - classpath = files(coreModuleProjects.collect {project -> - project.sourceSets.main.compileClasspath - }) -} - -task docSiteLogin(type: Login) { - if (project.hasProperty('sshHost')) { - host = project.property('sshHost') - } -} - -// Define remoteSiteDir and sshHost in gradle.properties -def remoteDocsDir = null - -if (hasProperty('remoteSiteDir')) { - remoteDocsDir="$remoteSiteDir/docs/3.1.x" -} - -task uploadApidocs(type: TarUpload) { - dependsOn apidocs - classifier = 'apidocs' - remoteDir = remoteDocsDir - login = docSiteLogin - - into('apidocs') { - from apidocs.destinationDir - } -} - -def docsDir = new File(project(':manual').buildDir, 'docs') - -task uploadDoc(type: TarUpload) { - dependsOn ':manual:doc' - classifier = 'doc' - remoteDir = remoteDocsDir - login = docSiteLogin - - into('reference') { - from docsDir - } -} - -task uploadFaq(type: TarUpload) { - dependsOn ':faq:docbookHtmlSingle' - classifier = 'faq' - if (project.hasProperty('remoteSiteDir')) { - remoteDir = project.property('remoteSiteDir') - } - login = docSiteLogin - - def faqDir = new File(project(':faq').buildDir, 'docs') - - into('faq') { - from faqDir - } -} - -task dist(type: Zip) { - def zipRootDir = "${project.name}-$version" - into(zipRootDir) { - into('docs/apidocs') { - from apidocs.destinationDir - } - into('docs/reference') { - from docsDir - } - into('dist') { - from coreModuleProjects.collect {project -> project.libsDir } - from project(':spring-security-samples-tutorial').libsDir - from project(':spring-security-samples-contacts').libsDir - } - } -} - -dist { - dependsOn apidocs, ':manual:doc', subprojects.collect { "$it.path:assemble" } - doLast { - ant.checksum(file: archivePath, algorithm: 'SHA1', fileext: '.sha1') - } -} - -task uploadDist(type: UploadDist) { - archiveFile = dist.archivePath - shaFile = "${dist.archivePath}.sha1" as File - archiveName = dist.archiveName - classpath = configurations.antlibs -} - -def getJavaProjects() { - subprojects.findAll {project -> project.name != 'faq' && project.name != 'manual' } -} - -def getSampleProjects() { - subprojects.findAll {project -> project.name.startsWith('spring-security-samples') } -} - -def getItestProjects() { - subprojects.findAll {project -> project.name.startsWith('itest') } -} - -def getCoreModuleProjects() { - javaProjects - sampleProjects - itestProjects -} - -def getAspectjProjects() { - [project(':spring-security-aspects'), project(':spring-security-samples-aspectj')] -} - -def getReleaseProjects() { - coreModuleProjects +project(':spring-security-aspects') -} - -class UploadDist extends DefaultTask { - @InputFile - File shaFile - - @InputFile - File archiveFile - - @Input - String archiveName - - @InputFiles - def classpath - - @TaskAction - def upload() { - def accessKey = project.s3AccessKey - def secretKey = project.s3SecretAccessKey - def version = project.version - - project.ant { - taskdef(resource: 'org/springframework/build/aws/ant/antlib.xml', classpath: classpath.asPath) - s3(accessKey: accessKey, secretKey: secretKey) { - upload(bucketName: 'dist.springframework.org', file: archiveFile, - toFile: releaseType() + "/SEC/${archiveName}", publicRead: 'true') { - metadata(name: 'project.name', value: 'Spring Security') - metadata(name: 'release.type', value: releaseType()) - metadata(name: 'bundle.version', value: version) - metadata(name: 'package.file.name', value: archiveName) - } - upload(bucketName: 'dist.springframework.org', file: shaFile, - toFile: releaseType() + "/SEC/${archiveName}.sha1", publicRead: 'true') - } - } - } - - def releaseType() { - if (project.releaseBuild) { - 'release' - } else if (project.snapshotBuild) { - 'snapshot' - } else { - 'milestone' - } - } -} diff --git a/buildSrc/src/main/groovy/docbook/DocbookPlugin.groovy b/buildSrc/src/main/groovy/docbook/DocbookPlugin.groovy index 24e84de9ad..3ee2ed6efd 100644 --- a/buildSrc/src/main/groovy/docbook/DocbookPlugin.groovy +++ b/buildSrc/src/main/groovy/docbook/DocbookPlugin.groovy @@ -48,6 +48,9 @@ class DocbookPlugin implements Plugin { Task docbookFoPdf = project.tasks.add("docbookFoPdf", DocbookFoPdf.class); docbookFoPdf.setDescription('Generates PDF output'); docbookFoPdf.extension = 'fo' + + Task docbook = project.tasks.add("docbook", DefaultTask.class); + docbook.dependsOn (docbookHtml, docbookHtmlSingle, docbookFoPdf) } } diff --git a/docs/docs.gradle b/docs/docs.gradle new file mode 100644 index 0000000000..2c007650c7 --- /dev/null +++ b/docs/docs.gradle @@ -0,0 +1,107 @@ +// Docbook and Javadoc building and uploading tasks + +subprojects { + apply plugin: 'base' + apply plugin: 'docbook' + + docbookHtmlSingle.stylesheet = new File(projectDir, 'src/xsl/html-single-custom.xsl') +} + +project('faq') { + defaultTasks 'docbookHtmlSingle' + [docbookHtml, docbookFoPdf, docbookHtmlSingle]*.sourceFileName = 'faq.xml' + docbookHtmlSingle.suffix = '' + + spec = copySpec { + into ('faq') { + from("$buildDir/docs") + from("$projectDir/src/resources") + } + } +} + +project('manual') { + defaultTasks 'docbookHtml', 'docbookHtmlSingle', 'docbookFoPdf' + [docbookHtml, docbookFoPdf, docbookHtmlSingle]*.sourceFileName = 'springsecurity.xml' + + docbookHtml.stylesheet = new File(projectDir, 'src/xsl/html-custom.xsl') + docbookHtmlSingle.stylesheet = new File(projectDir, 'src/xsl/html-single-custom.xsl') + docbookFoPdf.stylesheet = new File(projectDir, 'src/xsl/pdf-custom.xsl') + def imagesDir = new File(projectDir, 'src/docbook/images'); + docbookFoPdf.admonGraphicsPath = "${imagesDir}/" + + spec = copySpec { + into ('reference') { + from("$buildDir/docs") + from("$projectDir/src/resources") + } + into ('reference/images') { + from (imagesDir) + } + } +} + +task apidocs(type: Javadoc) { + destinationDir = new File(buildDir, 'apidocs') + title = "Spring Security $version API" + optionsFile = file("$buildDir/tmp/javadoc.options") + + source coreModuleProjects.collect { project -> + project.sourceSets.main.allJava + } + + classpath = files(coreModuleProjects.collect { project -> + project.sourceSets.main.compileClasspath + }) +} + +apiSpec = copySpec { + into('apidocs') { + from(apidocs.destinationDir) + } +} + +task docSiteLogin(type: Login) { + if (project.hasProperty('sshHost')) { + host = project.property('sshHost') + } +} + +// Define remoteSiteDir and sshHost in gradle.properties +def remoteDocsDir = null + +if (hasProperty('remoteSiteDir')) { + remoteDocsDir="$remoteSiteDir/docs/3.1.x" +} + +task uploadApidocs(type: TarUpload) { + dependsOn apidocs + baseName = "${rootProject.name}" + appendix = 'apidocs' + remoteDir = remoteDocsDir + login = docSiteLogin + + with(apiSpec) +} + +task uploadManual(type: TarUpload) { + dependsOn 'manual:docbook' + baseName = "${rootProject.name}" + appendix = 'doc' + remoteDir = remoteDocsDir + login = docSiteLogin + + with(project('manual').spec) +} + +task uploadFaq(type: TarUpload) { + dependsOn 'faq:docbookHtmlSingle' + baseName = "${rootProject.name}" + appendix = 'faq' + if (project.hasProperty('remoteSiteDir')) { + remoteDir = project.property('remoteSiteDir') + } + login = docSiteLogin + + with(project('faq').spec) +} \ No newline at end of file diff --git a/docs/faq/faq.gradle b/docs/faq/faq.gradle deleted file mode 100644 index 2680a455e3..0000000000 --- a/docs/faq/faq.gradle +++ /dev/null @@ -1,17 +0,0 @@ -apply plugin: 'base' -apply plugin: 'docbook' - -defaultTasks 'docbookHtmlSingle' - -[docbookHtml, docbookFoPdf, docbookHtmlSingle]*.sourceFileName = 'faq.xml' - -docbookHtmlSingle.stylesheet = new File(projectDir, 'src/xsl/html-single-custom.xsl') -docbookHtmlSingle.suffix = '' - -docbookHtmlSingle.doLast { - resourcesDir = new File(projectDir, 'src/resources') - ant { - docsDir = new File(buildDir, 'docs') - copy(toDir: docsDir) {fileset(dir: resourcesDir)} - } -} diff --git a/docs/manual/manual.gradle b/docs/manual/manual.gradle deleted file mode 100644 index a1f7b6f28a..0000000000 --- a/docs/manual/manual.gradle +++ /dev/null @@ -1,19 +0,0 @@ -apply plugin: 'base' -apply plugin: 'docbook' - -[docbookHtml, docbookFoPdf, docbookHtmlSingle]*.sourceFileName = 'springsecurity.xml'; - -docbookHtml.stylesheet = new File(projectDir, 'src/xsl/html-custom.xsl') -docbookHtmlSingle.stylesheet = new File(projectDir, 'src/xsl/html-single-custom.xsl') -docbookFoPdf.stylesheet = new File(projectDir, 'src/xsl/pdf-custom.xsl') -def imagesDir = new File(projectDir, 'src/docbook/images'); -docbookFoPdf.admonGraphicsPath = "${imagesDir}/" - -task doc (dependsOn: [docbookHtml, docbookHtmlSingle, docbookFoPdf]) << { - resourcesDir = new File(projectDir, 'src/resources') - ant { - docsDir = new File(buildDir, 'docs') - copy(toDir: docsDir) {fileset(dir: resourcesDir)} - copy(toDir: new File(docsDir, 'images')) {fileset(dir: imagesDir)} - } -} diff --git a/gradle/dist.gradle b/gradle/dist.gradle new file mode 100644 index 0000000000..b7032a85fa --- /dev/null +++ b/gradle/dist.gradle @@ -0,0 +1,80 @@ + +// Task for creating the distro zip + +task dist(type: Zip) { + dependsOn ':docs:apidocs', ':docs:manual:docbook', subprojects*.tasks*.matching { task -> task.name == 'assemble' } + + evaluationDependsOn(':docs') + + def zipRootDir = "${project.name}-$version" + into(zipRootDir) { + from(rootDir) { + include '*.txt' + } + into('docs') { + with(project(':docs').apiSpec) + with(project(':docs:manual').spec) + } + into('dist') { + from coreModuleProjects.collect {project -> project.libsDir } + from project(':spring-security-samples-tutorial').libsDir + from project(':spring-security-samples-contacts').libsDir + } + } + doLast { + ant.checksum(file: archivePath, algorithm: 'SHA1', fileext: '.sha1') + } +} + +task uploadDist(type: UploadDist) { + archiveFile = dist.archivePath + shaFile = "${dist.archivePath}.sha1" as File + archiveName = dist.archiveName + classpath = configurations.antlibs +} + +class UploadDist extends DefaultTask { + @InputFile + File shaFile + + @InputFile + File archiveFile + + @Input + String archiveName + + @InputFiles + def classpath + + @TaskAction + def upload() { + def accessKey = project.s3AccessKey + def secretKey = project.s3SecretAccessKey + def version = project.version + + project.ant { + taskdef(resource: 'org/springframework/build/aws/ant/antlib.xml', classpath: classpath.asPath) + s3(accessKey: accessKey, secretKey: secretKey) { + upload(bucketName: 'dist.springframework.org', file: archiveFile, + toFile: releaseType() + "/SEC/${archiveName}", publicRead: 'true') { + metadata(name: 'project.name', value: 'Spring Security') + metadata(name: 'release.type', value: releaseType()) + metadata(name: 'bundle.version', value: version) + metadata(name: 'package.file.name', value: archiveName) + } + upload(bucketName: 'dist.springframework.org', file: shaFile, + toFile: releaseType() + "/SEC/${archiveName}.sha1", publicRead: 'true') + } + } + } + + def releaseType() { + if (project.releaseBuild) { + 'release' + } else if (project.snapshotBuild) { + 'snapshot' + } else { + 'milestone' + } + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 88c45c3dc3..c6cc6aa60d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,11 +22,6 @@ def String[] samples = [ 'ldap' ] -def String[] docs = [ - 'faq', - 'manual' -] - def String[] itest = [ 'web', 'context' @@ -58,13 +53,10 @@ itest.each { name -> p.projectDir = new File(settingsDir, "itest/${name}"); } -include docs +include 'docs', 'docs:faq', 'docs:manual' -docs.each { name -> - p = findProject(":${name}") - p.buildFileName = "${name}.gradle" - p.projectDir = new File(settingsDir, "docs/${name}"); -} +docs = findProject(':docs') +docs.buildFileName = 'docs.gradle' rootProject.children.each {project -> assert project.projectDir.isDirectory()