From ac96f271360907c264e9333b0392443df28207ab Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Thu, 21 Apr 2011 11:57:18 +0100 Subject: [PATCH] Gradle refactoring. Create separate S3 upload task and extract ide customization into a separate file. --- build.gradle | 93 +++++-------------- buildSrc/build.gradle | 1 + .../src/main/groovy/S3DistroUpload.groovy | 92 ++++++++++++++++++ gradle/dist.gradle | 86 ----------------- gradle/ide-integration.gradle | 81 ++++++++++++++++ 5 files changed, 195 insertions(+), 158 deletions(-) create mode 100644 buildSrc/src/main/groovy/S3DistroUpload.groovy delete mode 100644 gradle/dist.gradle create mode 100644 gradle/ide-integration.gradle diff --git a/build.gradle b/build.gradle index aa0c660422..e1807c58d9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,7 @@ apply plugin: 'base' +description = 'Spring Security' + allprojects { version = '3.1.0.CI-SNAPSHOT' releaseBuild = version.endsWith('RELEASE') @@ -41,89 +43,36 @@ configure (aspectjProjects) { apply plugin: 'aspectj' } -apply from: "$rootDir/gradle/dist.gradle" +// Task for creating the distro zip -apply plugin: 'idea' +task dist(type: Zip) { + dependsOn subprojects*.tasks*.matching { task -> task.name == 'assemble' } -configure(javaProjects) { - apply plugin: 'idea' - apply plugin: 'eclipse' + evaluationDependsOn(':docs') - ideaModule { - downloadJavadoc=false - excludeDirs.add(buildDir) - gradleCacheVariable = 'GRADLE_CACHE' - outputDir = "$rootProject.projectDir/intellij/out" as File - testOutputDir = "$rootProject.projectDir/intellij/testOut" as File - whenConfigured { module -> - def allClasses = module.dependencies.findAll() { dep -> - if (dep instanceof org.gradle.plugins.idea.model.ModuleLibrary - && dep.classes.find { path -> - path.url.matches('.*jcl-over-slf4j.*') || - path.url.matches('.*servlet-api.*') || - path.url.matches('.*jsp-api.*') - }) { - dep.scope = 'COMPILE' - dep.exported = false - } - } + def zipRootDir = "${project.name}-$version" + into(zipRootDir) { + from(rootDir) { + include '*.txt' } - } - // GRADLE-1116 - eclipseClasspath.whenConfigured { classpath -> - classpath.entries.removeAll { entry -> entry.path.endsWith('/build/classes/test') } - } - eclipseClasspath.doFirst { - eclipseClasspath.whenConfigured { classpath -> - def includeDeps = project.configurations.getByName('runtime')?.collect { f-> f.absolutePath } as Set - classpath.entries.each { cp -> - if(cp instanceof org.gradle.plugins.eclipse.model.Library) { - def include = includeDeps.contains(cp.path) - def attr = 'org.eclipse.jst.component.dependency' - if(include && project.hasProperty('war')) { - // GRADLE-1426 (part a) - cp.entryAttributes.put(attr,'/WEB-INF/lib') - } else if(!include) { - // GRADLE-1422 - cp.entryAttributes.remove(attr) - } - } - } + into('docs') { + with(project(':docs').apiSpec) + with(project(':docs:manual').spec) } - } - // GRADLE-1426 (part b) - project.plugins.withType(org.gradle.api.plugins.WarPlugin.class).all { - eclipseWtpComponent.whenConfigured { wtpComp -> - wtpComp.wbModuleEntries.findAll { it instanceof org.gradle.plugins.eclipse.model.WbDependentModule }.each { e -> - if(!e.handle.startsWith('module:/resource/')) { - wtpComp.wbModuleEntries.remove(e) - } - } - } - } - tasks.withType(org.gradle.plugins.eclipse.EclipseWtpComponent) { - whenConfigured { wtpComponent -> - wtpComponent.contextPath = project.tasks.findByName('jettyRun')?.contextPath?.replaceFirst('/','') + into('dist') { + from coreModuleProjects.collect {project -> project.libsDir } + from project(':spring-security-samples-tutorial').libsDir + from project(':spring-security-samples-contacts').libsDir } } } -ideaModule { - excludeDirs += file('.gradle') - excludeDirs += file('buildSrc/build') - excludeDirs += file('buildSrc/.gradle') +task uploadDist(type: S3DistroUpload) { + archiveFile = dist.archivePath + projectKey = 'SEC' } -ideaProject { - javaVersion = '1.6' - subprojects = [rootProject] + javaProjects - withXml { provider -> - // Use git - def node = provider.asNode() - def vcsConfig = node.component.find { it.'@name' == 'VcsDirectoryMappings' } - vcsConfig.mapping[0].'@vcs' = 'Git' - } -} +apply from: "$rootDir/gradle/ide-integration.gradle" task wrapper(type: Wrapper) { gradleVersion = '1.0-milestone-1' diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index b642c7cc51..8cf7636879 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -22,6 +22,7 @@ dependencies { 'xml-resolver:xml-resolver:1.2', 'xerces:xercesImpl:2.9.1', 'saxon:saxon:6.5.3', + 'net.java.dev.jets3t:jets3t:0.6.1', fopDeps runtime 'net.sf.xslthl:xslthl:2.0.1', diff --git a/buildSrc/src/main/groovy/S3DistroUpload.groovy b/buildSrc/src/main/groovy/S3DistroUpload.groovy new file mode 100644 index 0000000000..e4342e72dc --- /dev/null +++ b/buildSrc/src/main/groovy/S3DistroUpload.groovy @@ -0,0 +1,92 @@ + +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.TaskAction +import org.jets3t.service.security.AWSCredentials +import org.jets3t.service.impl.rest.httpclient.RestS3Service +import org.jets3t.service.S3Service +import org.jets3t.service.model.S3Bucket +import org.jets3t.service.model.S3Object +import org.jets3t.service.acl.AccessControlList + +/** + * @author Luke Taylor + */ +class S3DistroUpload extends DefaultTask { + @InputFile + File archiveFile + + @Input + String bucketName = 'dist.springframework.org' + + // 'Spring Security' + @Input + String projectName = project.description + + // e.g 'SEC' + @Input + String projectKey + + @TaskAction + def upload() { + def accessKey = project.s3AccessKey + def secretKey = project.s3SecretAccessKey + def version = project.version.toString() + + assert version.length() > 0 + assert accessKey.length() > 0 + assert secretKey.length() > 0 + assert projectName.length() > 0 + + assert archiveFile.exists() + + String archiveName = archiveFile.getName() + + logger.info("Creating SHA checksum file...") + project.ant.checksum(file: archiveFile, algorithm: 'SHA1', fileext: '.sha1', forceoverwrite: 'true') + File shaFile = "${archiveFile}.sha1" as File + + assert shaFile.exists() + + AWSCredentials creds = new AWSCredentials(accessKey, secretKey); + S3Service s3 = new RestS3Service(creds) + S3Bucket bucket = new S3Bucket(bucketName) + + String releaseType = releaseType(version) + + String key = releaseType + '/' + projectKey + '/' + archiveName + + S3Object archiveDest = new S3Object(bucket, key) + archiveDest.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ) + archiveDest.setDataInputFile(archiveFile) + archiveDest.setContentLength(archiveFile.length()) + archiveDest.addMetadata('project.name', projectName) + archiveDest.addMetadata('bundle.version', version) + archiveDest.addMetadata('release.type', releaseType) + archiveDest.addMetadata('package.file.name', archiveName) + + logger.info("Uploading archive " + archiveFile.getName() + " to " + archiveDest + "...") + s3.putObject(bucket, archiveDest) + logger.info("Done") + + S3Object shaDest = new S3Object(bucket, key + '.sha1') + shaDest.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ) + shaDest.setDataInputFile(shaFile) + shaDest.setContentLength(shaFile.length()) + + logger.info("Uploading SHA checksum " + shaFile.getName() + " to " + key + '.sha1' + "...") + s3.putObject(bucket, shaDest); + logger.info("Done") + } + + def releaseType(String version) { + if (version.endsWith('RELEASE')) { + 'release' + } else if (version.endsWith('SNAPSHOT')) { + 'snapshot' + } else { + 'milestone' + } + } +} diff --git a/gradle/dist.gradle b/gradle/dist.gradle deleted file mode 100644 index e1efdb91c3..0000000000 --- a/gradle/dist.gradle +++ /dev/null @@ -1,86 +0,0 @@ - -// Task for creating the distro zip - -configurations { - antaws -} - -dependencies { - antaws "org.springframework.build:org.springframework.build.aws.ant:3.0.3.RELEASE", - "net.java.dev.jets3t:jets3t:0.6.1" -} - -task dist(type: Zip) { - dependsOn 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 -} - -class UploadDist extends DefaultTask { - @InputFile - File shaFile - - @InputFile - File archiveFile - - @Input - String archiveName - - @TaskAction - def upload() { - def accessKey = project.s3AccessKey - def secretKey = project.s3SecretAccessKey - def version = project.version - def classpath = project.configurations.antaws - - 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/gradle/ide-integration.gradle b/gradle/ide-integration.gradle new file mode 100644 index 0000000000..13636bd373 --- /dev/null +++ b/gradle/ide-integration.gradle @@ -0,0 +1,81 @@ +apply plugin: 'idea' + +configure(javaProjects) { + apply plugin: 'idea' + apply plugin: 'eclipse' + + ideaModule { + downloadJavadoc=false + excludeDirs.add(buildDir) + gradleCacheVariable = 'GRADLE_CACHE' + outputDir = "$rootProject.projectDir/intellij/out" as File + testOutputDir = "$rootProject.projectDir/intellij/testOut" as File + whenConfigured { module -> + def allClasses = module.dependencies.findAll() { dep -> + if (dep instanceof org.gradle.plugins.idea.model.ModuleLibrary + && dep.classes.find { path -> + path.url.matches('.*jcl-over-slf4j.*') || + path.url.matches('.*servlet-api.*') || + path.url.matches('.*jsp-api.*') + }) { + dep.scope = 'COMPILE' + dep.exported = false + } + } + } + } + // GRADLE-1116 + eclipseClasspath.whenConfigured { classpath -> + classpath.entries.removeAll { entry -> entry.path.endsWith('/build/classes/test') } + } + eclipseClasspath.doFirst { + eclipseClasspath.whenConfigured { classpath -> + def includeDeps = project.configurations.getByName('runtime')?.collect { f-> f.absolutePath } as Set + classpath.entries.each { cp -> + if(cp instanceof org.gradle.plugins.eclipse.model.Library) { + def include = includeDeps.contains(cp.path) + def attr = 'org.eclipse.jst.component.dependency' + if(include && project.hasProperty('war')) { + // GRADLE-1426 (part a) + cp.entryAttributes.put(attr,'/WEB-INF/lib') + } else if(!include) { + // GRADLE-1422 + cp.entryAttributes.remove(attr) + } + } + } + } + } + // GRADLE-1426 (part b) + project.plugins.withType(org.gradle.api.plugins.WarPlugin.class).all { + eclipseWtpComponent.whenConfigured { wtpComp -> + wtpComp.wbModuleEntries.findAll { it instanceof org.gradle.plugins.eclipse.model.WbDependentModule }.each { e -> + if(!e.handle.startsWith('module:/resource/')) { + wtpComp.wbModuleEntries.remove(e) + } + } + } + } + tasks.withType(org.gradle.plugins.eclipse.EclipseWtpComponent) { + whenConfigured { wtpComponent -> + wtpComponent.contextPath = project.tasks.findByName('jettyRun')?.contextPath?.replaceFirst('/','') + } + } +} + +ideaModule { + excludeDirs += file('.gradle') + excludeDirs += file('buildSrc/build') + excludeDirs += file('buildSrc/.gradle') +} + +ideaProject { + javaVersion = '1.6' + subprojects = [rootProject] + javaProjects + withXml { provider -> + // Use git + def node = provider.asNode() + def vcsConfig = node.component.find { it.'@name' == 'VcsDirectoryMappings' } + vcsConfig.mapping[0].'@vcs' = 'Git' + } +}