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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 (jdkVersion > 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. api files("/Users/pj.fanning/Downloads/xmlbeans-5.1.0.jar")
  35. compileOnly project(':poi-ooxml-full')
  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 = '../src/resources/ooxml-lite-report'
  41. task generateModuleInfo() {
  42. File fileIn = file("${OOXML_LITE_REPORT}.clazz")
  43. File fileOut = file("src/main/java9/module-info.java")
  44. inputs.file fileIn
  45. outputs.file fileOut
  46. doLast {
  47. String header = fileOut.collect().findAll { !(it =~ /exports|}/) }.join('\n')
  48. // generate module-info based on exported classes
  49. String exports = fileIn.
  50. collect { " exports ${it.replaceAll('[/\\\\][^/\\\\]+$', '').replaceAll('[/\\\\]', '.')};" }.
  51. findAll { !(it =~ /\.impl;$/) }.unique().sort().join('\n')
  52. String content = header + '\n' + exports + '\n}'
  53. if (fileOut.text != content) {
  54. fileOut.write content
  55. }
  56. }
  57. }
  58. task compileOoxmlLite(type: Copy) {
  59. dependsOn 'generateModuleInfo', ':poi-ooxml-full:generate_beans'
  60. // This task is currently always executed, because gradle thinks files with two dollar signs
  61. // (as in AlternateContentDocument$AlternateContent$Choice.class) are always stale
  62. // copy re-/sources to modules own directory to pacify IntelliJ, which doesn't like the same source dir in multiple modules
  63. from(project(':poi-ooxml-full').buildDir) {
  64. include 'generated-sources/**'
  65. include 'generated-resources/**'
  66. include 'classes/java/main/**'
  67. }
  68. into(buildDir)
  69. }
  70. java {
  71. toolchain {
  72. languageVersion.set(JavaLanguageVersion.of(jdkVersion))
  73. if (jdkVendor != '') vendor.set(JvmVendorSpec.matching(jdkVendor))
  74. }
  75. }
  76. compileJava {
  77. dependsOn 'compileOoxmlLite'
  78. options.fork = true
  79. options.forkOptions.jvmArgs << '-Xmx2G'
  80. }
  81. processResources.dependsOn 'compileOoxmlLite'
  82. sourcesJar.dependsOn 'compileOoxmlLite'
  83. task compileJava9(type: JavaCompile, dependsOn: 'compileJava') {
  84. javaCompiler = javaToolchains.compilerFor {
  85. languageVersion = JavaLanguageVersion.of(jdkVersion)
  86. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  87. }
  88. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  89. source = file(JAVA9_SRC)
  90. classpath = files()
  91. doFirst {
  92. options.compilerArgs = [
  93. '--patch-module', "${MODULE_NAME}=${project(':poi-ooxml-full').sourceSets.main.output.asPath}",
  94. '--module-path', files(MAIN_MODULE_PATH).asPath
  95. ]
  96. }
  97. onlyIf {
  98. jdkVersion > 8
  99. }
  100. }
  101. task cacheJava9(type: Copy, dependsOn: 'compileJava9') {
  102. from(file(JAVA9_OUT + VERSIONS9))
  103. into(JAVA9_SRC)
  104. }
  105. jar {
  106. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  107. doFirst {
  108. File clazzFile = file("${OOXML_LITE_REPORT}.clazz")
  109. File xsbsFile = file("${OOXML_LITE_REPORT}.xsb")
  110. if (clazzFile.exists() && xsbsFile.exists()) {
  111. List clazz = clazzFile.collect { "${it}.class" }
  112. List clazzInner = clazzFile.collect { "${it}\$*.class" }
  113. List xsbs = xsbsFile.collect { "org/apache/poi/schemas/ooxml/system/ooxml/${it}.xsb" }
  114. File missingXsbsFile = file("missing-xsbs.txt")
  115. List xsbs2 = missingXsbsFile.findAll { !it.empty && !it.startsWith("#") }
  116. .collect { "org/apache/poi/schemas/ooxml/system/ooxml/${it.trim()}.xsb" }
  117. includes = clazz + clazzInner + xsbs + xsbs2 + ['META-INF/versions/**', 'org/apache/poi/schemas/ooxml/element/**']
  118. }
  119. }
  120. if (jdkVersion == 8) {
  121. into('META-INF/versions/9') {
  122. from JAVA9_SRC include '*.class'
  123. }
  124. }
  125. // ignore second module-info.class from poi-ooxml-full
  126. // duplicatesStrategy = 'exclude'
  127. includeEmptyDirs = false
  128. manifest {
  129. attributes('Automatic-Module-Name' : MODULE_NAME, 'Multi-Release': 'true')
  130. }
  131. }
  132. sourcesJar {
  133. metaInf {
  134. from("$projectDir/../legal/LICENSE")
  135. from("$projectDir/../legal/NOTICE")
  136. }
  137. }
  138. spotbugsTest.enabled = false
  139. spotbugsMain.enabled = false
  140. javadoc.enabled = false
  141. javadocJar.enabled = false