build.gradle 8.5 KB

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