build.gradle 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import java.util.jar.Manifest
  2. import org.gradle.api.tasks.bundling.GradleManifest
  3. apply id: 'base'
  4. allprojects {
  5. version = '3.0.2.CI-SNAPSHOT'
  6. releaseBuild = version.endsWith('RELEASE')
  7. snapshotBuild = version.endsWith('SNAPSHOT')
  8. group = 'org.springframework.security'
  9. repositories {
  10. mavenRepo name:'Local', urls:'file:///Users/luke/.m2/repository'
  11. mavenCentral()
  12. // mavenRepo name:'SpringSource Milestone Repo', urls:'http://repository.springsource.com/maven/bundles/milestone'
  13. }
  14. }
  15. configure(javaProjects()) {
  16. apply id: 'java'
  17. springVersion = '3.0.0.RELEASE'
  18. springLdapVersion = '1.3.0.RELEASE'
  19. ehcacheVersion = '1.6.2'
  20. aspectjVersion = '1.6.5'
  21. apacheDsVersion = '1.5.5'
  22. jstlVersion = '1.1.2'
  23. configurations {
  24. bundlor
  25. provided
  26. }
  27. dependencies {
  28. compile 'commons-logging:commons-logging:1.1.1'
  29. testCompile 'junit:junit:4.7',
  30. 'org.mockito:mockito-core:1.7',
  31. 'org.jmock:jmock:2.5.1',
  32. 'org.jmock:jmock-junit4:2.5.1',
  33. 'org.hamcrest:hamcrest-core:1.1',
  34. 'org.hamcrest:hamcrest-library:1.1',
  35. "org.springframework:spring-test:$springVersion"
  36. bundlor 'com.springsource.bundlor:com.springsource.bundlor.ant:1.0.0.RC1',
  37. 'com.springsource.bundlor:com.springsource.bundlor:1.0.0.RC1',
  38. 'com.springsource.bundlor:com.springsource.bundlor.blint:1.0.0.RC1'
  39. }
  40. sourceSets {
  41. main {
  42. compileClasspath = compileClasspath + configurations.provided
  43. }
  44. test {
  45. compileClasspath = compileClasspath + configurations.provided
  46. runtimeClasspath = runtimeClasspath + configurations.provided
  47. }
  48. }
  49. test {
  50. options.fork(forkMode: ForkMode.ONCE, jvmArgs: ["-ea", '-Xms128m', '-Xmx500m', '-XX:MaxPermSize=128m', '-XX:+HeapDumpOnOutOfMemoryError'])
  51. }
  52. task bundlor (dependsOn: compileJava) << {
  53. if (!dependsOnTaskDidWork()) {
  54. return
  55. }
  56. ant.taskdef(resource: 'com/springsource/bundlor/ant/antlib.xml', classpath: configurations.bundlor.asPath)
  57. File template = new File(projectDir, 'template.mf')
  58. mkdir(buildDir, 'bundlor')
  59. if (template.exists()) {
  60. ant.bundlor(inputPath: "$buildDir/classes/main", outputPath: "$buildDir/bundlor", manifestTemplatePath: template) {
  61. property(name: 'version', value: "$version")
  62. property(name: 'spring.version', value: "$springVersion")
  63. }
  64. // See GRADLE-395 for support for using an existing manifest
  65. jar.manifest = new GradleManifest(new Manifest(new File("$buildDir/bundlor/META-INF/MANIFEST.MF").newInputStream()))
  66. }
  67. }
  68. jar.dependsOn bundlor
  69. }
  70. configure(javaProjects()) {
  71. apply id: 'maven'
  72. // Create a source jar for uploading
  73. task sourceJar(type: Jar) {
  74. classifier = 'sources'
  75. from sourceSets.main.java
  76. }
  77. configurations {
  78. deployerJars
  79. }
  80. artifacts {
  81. archives sourceJar
  82. }
  83. dependencies {
  84. deployerJars "org.springframework.build.aws:org.springframework.build.aws.maven:2.0.1.BUILD-SNAPSHOT"
  85. }
  86. uploadArchives {
  87. repositories.mavenDeployer {
  88. configuration = configurations.deployerJars
  89. if (releaseBuild) {
  90. // "mavenSyncRepoDir" should be set in properties
  91. repository(url: mavenSyncRepoDir)
  92. } else {
  93. s3credentials = [userName: s3AccessKey, passphrase: s3SecretAccessKey]
  94. repository(url: "s3://maven.springframework.org/milestone") {
  95. authentication(s3credentials)
  96. }
  97. snapshotRepository(url: "s3://maven.springframework.org/snapshot") {
  98. authentication(s3credentials)
  99. }
  100. }
  101. }
  102. }
  103. conf2ScopeMappings.addMapping(1, configurations.provided, "provided")
  104. }
  105. repositories {
  106. // Required for ant s3 task
  107. mavenRepo name: "s2.com release", urls: "http://repository.springsource.com/maven/bundles/release"
  108. }
  109. configurations {
  110. antlibs
  111. }
  112. dependencies {
  113. antlibs "org.springframework.build:org.springframework.build.aws.ant:3.0.3.RELEASE",
  114. "net.java.dev.jets3t:jets3t:0.6.1"
  115. }
  116. def docsDir = new File(project(':manual').buildDir, 'docs')
  117. task apidocs(type: Javadoc) {
  118. destinationDir = new File(buildDir, 'apidocs')
  119. optionsFile = file("$buildDir/tmp/javadoc.options")
  120. source coreModuleProjects().collect { project ->
  121. project.sourceSets.main.allJava
  122. }
  123. classpath = files(coreModuleProjects().collect { project ->
  124. project.sourceSets.main.compileClasspath })
  125. }
  126. task apitar(type: Tar, dependsOn: apidocs) {
  127. compression = Compression.BZIP2
  128. classifier = 'apidocs'
  129. into('apidocs') {
  130. from apidocs.destinationDir
  131. }
  132. }
  133. task doctar(type: Tar, dependsOn: ':manual:doc') {
  134. compression = Compression.BZIP2
  135. classifier = 'doc'
  136. into('reference') {
  137. from docsDir
  138. }
  139. }
  140. def username;
  141. def password;
  142. task login << {
  143. ant.input("Please enter the ssh username for host '$sshHost'", addproperty: "ssh.username")
  144. ant.input("Please enter the ssh password '$sshHost'", addproperty: "ssh.password")
  145. username = ant.properties['ssh.username']
  146. password = ant.properties['ssh.password']
  147. }
  148. task uploadApidocs (dependsOn: login) << {
  149. ant.scp(file: apitar.archivePath, todir: "$username@$sshHost:$remoteDocsDir", password: password)
  150. ant.sshexec(host: sshHost, username: username, password: password, command: "cd $remoteDocsDir && tar -xjf ${apitar.archiveName}")
  151. ant.sshexec(host: sshHost, username: username, password: password, command: "rm $remoteDocsDir/${apitar.archiveName}")
  152. }
  153. task uploadManual (dependsOn: login) << {
  154. ant.scp(file: doctar.archivePath, todir: "$username@$sshHost:$remoteDocsDir", password: password)
  155. ant.sshexec(host: sshHost, username: username, password: password, command: "cd $remoteDocsDir && tar -xjf ${doctar.archiveName}")
  156. ant.sshexec(host: sshHost, username: username, password: password, command: "rm $remoteDocsDir/${doctar.archiveName}")
  157. }
  158. task dist (type: Zip) {
  159. def zipRootDir = "${project.name}-$version"
  160. into (zipRootDir) {
  161. into('docs/apidocs') {
  162. from apidocs.destinationDir
  163. }
  164. into('docs/reference') {
  165. from docsDir
  166. }
  167. into('dist') {
  168. from coreModuleProjects().collect { project -> project.libsDir }
  169. from project(':spring-security-samples-tutorial').libsDir
  170. from project(':spring-security-samples-contacts').libsDir
  171. }
  172. }
  173. }
  174. dist.dependsOn apidocs, ':manual:doc'
  175. dist.dependsOn subprojects.collect { "$it.path:assemble" }
  176. dist.doLast {
  177. ant.checksum(file: archivePath, algorithm: 'SHA1', fileext: '.sha1')
  178. }
  179. task uploadDist << {
  180. def shaFile = file("${dist.archivePath}.sha1")
  181. assert dist.archivePath.isFile()
  182. assert shaFile.isFile()
  183. ant.taskdef(resource: 'org/springframework/build/aws/ant/antlib.xml', classpath: configurations.antlibs.asPath)
  184. ant.s3(accessKey: s3AccessKey, secretKey: s3SecretAccessKey) {
  185. upload(bucketName: 'dist.springframework.org', file: dist.archivePath,
  186. toFile: releaseType() + "/SEC/${dist.archiveName}", publicRead: 'true') {
  187. metadata(name: 'project.name', value: 'Spring Security')
  188. metadata(name: 'release.type', value: releaseType())
  189. metadata(name: 'bundle.version', value: version)
  190. metadata(name: 'package.file.name', value: dist.archiveName)
  191. }
  192. upload(bucketName: 'dist.springframework.org', file: shaFile,
  193. toFile: releaseType() + "/SEC/${dist.archiveName}.sha1", publicRead: 'true')
  194. }
  195. }
  196. def javaProjects() {
  197. subprojects.findAll { project -> project.name != 'faq' && project.name != 'manual' }
  198. }
  199. def sampleProjects() {
  200. subprojects.findAll { project -> project.name.startsWith('spring-security-samples') }
  201. }
  202. def coreModuleProjects() {
  203. javaProjects() - sampleProjects()
  204. }
  205. def releaseType() {
  206. if (releaseBuild) {
  207. 'release'
  208. } else if (snapshotBuild) {
  209. 'snapshot'
  210. } else {
  211. 'milestone'
  212. }
  213. }