build.gradle 9.2 KB

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