You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import java.util.regex.Pattern
  2. /* ====================================================================
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. ==================================================================== */
  16. final String BEANS_SRC = "${buildDir}/generated-sources"
  17. final String BEANS_RES = "${buildDir}/generated-resources"
  18. sourceSets {
  19. main {
  20. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  21. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  22. }
  23. compileClasspath += files(BEANS_RES)
  24. java {
  25. srcDirs += BEANS_SRC
  26. }
  27. resources {
  28. srcDirs += BEANS_RES
  29. }
  30. }
  31. }
  32. dependencies {
  33. api "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  34. compileOnly project(':poi-ooxml-full')
  35. compileOnly project(path:':poi-integration', configuration:'tests')
  36. }
  37. final MODULE_NAME = 'org.apache.poi.ooxml.schemas'
  38. final Pattern MODULE_REGEX = ~'\\.jar$'
  39. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  40. final String OOXML_LITE_REPORT = '../build/ooxml-lite-report'
  41. task generateModuleInfo() {
  42. dependsOn ':poi-ooxml:build', ':poi-integration:build', ':poi-excelant:build'
  43. File fileIn = file("${OOXML_LITE_REPORT}.clazz")
  44. File fileOut = file("src/main/java9/module-info.java")
  45. inputs.file fileIn
  46. outputs.file fileOut
  47. doLast {
  48. String header = fileOut.collect().findAll { !(it =~ /exports|}/) }.join('\n')
  49. // generate module-info based on exported classes
  50. String exports = fileIn.
  51. collect { " exports ${it.replaceAll('[/\\\\][^/\\\\]+$', '').replaceAll('[/\\\\]', '.')};" }.
  52. findAll { !(it =~ /\.impl;$/) }.unique().sort().join('\n')
  53. String content = header + '\n' + exports + '\n}\n'
  54. if (fileOut.text != content) {
  55. fileOut.write content
  56. }
  57. }
  58. }
  59. task compileOoxmlLite(type: Copy) {
  60. dependsOn 'generateModuleInfo'
  61. // This task is currently always executed, because gradle thinks files with two dollar signs
  62. // (as in AlternateContentDocument$AlternateContent$Choice.class) are always stale
  63. // copy re-/sources to modules own directory to pacify IntelliJ, which doesn't like the same source dir in multiple modules
  64. from(project(':poi-ooxml-full').buildDir) {
  65. include 'generated-sources/**'
  66. include 'generated-resources/**'
  67. include 'classes/java/main/**'
  68. }
  69. into(buildDir)
  70. }
  71. java {
  72. sourceCompatibility = JavaVersion.VERSION_1_8
  73. targetCompatibility = JavaVersion.VERSION_1_8
  74. }
  75. processResources.dependsOn 'compileOoxmlLite'
  76. compileJava.dependsOn 'compileOoxmlLite'
  77. sourcesJar.dependsOn 'compileOoxmlLite'
  78. task compileJava9(type: JavaCompile, dependsOn: 'compileJava') {
  79. sourceCompatibility = 9
  80. targetCompatibility = 9
  81. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  82. source = file(JAVA9_SRC)
  83. classpath = files()
  84. doFirst {
  85. options.compilerArgs = [
  86. '--patch-module', "${MODULE_NAME}=${project(':poi-ooxml-full').sourceSets.main.output.asPath}",
  87. '--module-path', files(MAIN_MODULE_PATH).asPath
  88. ]
  89. }
  90. }
  91. task cacheJava9(type: Copy, dependsOn: 'compileJava9') {
  92. from(file(JAVA9_OUT + VERSIONS9))
  93. into(JAVA9_SRC)
  94. }
  95. jar {
  96. dependsOn ':poi-ooxml:test', ':poi-integration:test'
  97. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  98. doFirst {
  99. File clazzFile = file("${OOXML_LITE_REPORT}.clazz")
  100. File xsbsFile = file("${OOXML_LITE_REPORT}.xsb")
  101. if (clazzFile.exists() && xsbsFile.exists()) {
  102. List clazz = clazzFile.collect { "${it}.class" }
  103. List clazzInner = clazzFile.collect { "${it}\$*.class" }
  104. List xsbs = xsbsFile.collect { "org/apache/poi/schemas/ooxml/system/ooxml/${it}.xsb" }
  105. includes = clazz + clazzInner + xsbs + ['META-INF/versions/**', 'org/apache/poi/schemas/ooxml/element/**']
  106. }
  107. }
  108. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  109. into('META-INF/versions/9') {
  110. from JAVA9_SRC include '*.class'
  111. }
  112. }
  113. // ignore second module-info.class from poi-ooxml-full
  114. // duplicatesStrategy = 'exclude'
  115. includeEmptyDirs = false
  116. manifest {
  117. attributes('Automatic-Module-Name' : MODULE_NAME, 'Multi-Release': 'true')
  118. }
  119. }
  120. spotbugsTest.enabled = false
  121. spotbugsMain.enabled = false
  122. javadoc.enabled = false
  123. javadocJar.enabled = false