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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. output.dir(JAVA9_OUT, builtBy: 'compileJava9')
  21. compileClasspath += files(BEANS_RES)
  22. java {
  23. srcDirs += BEANS_SRC
  24. }
  25. resources {
  26. srcDirs += BEANS_RES
  27. }
  28. }
  29. }
  30. dependencies {
  31. api "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  32. compileOnly project(':poi-ooxml-full')
  33. }
  34. final MODULE_NAME = 'org.apache.poi.ooxml.schemas'
  35. final Pattern MODULE_REGEX = ~'\\.jar$'
  36. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  37. final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
  38. task generateModuleInfo() {
  39. File fileIn = file("${OOXML_LITE_REPORT}.clazz")
  40. File fileOut = file("src/main/java9/module-info.java")
  41. inputs.file fileIn
  42. outputs.file fileOut
  43. doLast {
  44. String header = fileOut.collect().findAll { !(it =~ /exports|}/) }.join('\n')
  45. // generate module-info based on exported classes
  46. String exports = fileIn.
  47. collect { " exports ${it.replaceAll('[/\\\\][^/\\\\]+$', '').replaceAll('[/\\\\]', '.')};" }.
  48. findAll { !(it =~ /\.impl;$/) }.unique().sort().join('\n')
  49. String content = header + '\n' + exports + '\n}'
  50. if (fileOut.text != content) {
  51. fileOut.write content
  52. }
  53. }
  54. }
  55. task compileOoxmlLite(type: Copy) {
  56. dependsOn 'generateModuleInfo', ':poi-ooxml-full:generate_beans'
  57. // This task is currently always executed, because gradle thinks files with two dollar signs
  58. // (as in AlternateContentDocument$AlternateContent$Choice.class) are always stale
  59. // copy re-/sources to modules own directory to pacify IntelliJ, which doesn't like the same source dir in multiple modules
  60. from(project(':poi-ooxml-full').buildDir) {
  61. include 'generated-sources/**'
  62. include 'generated-resources/**'
  63. include 'classes/java/main/**'
  64. }
  65. into(buildDir)
  66. }
  67. java {
  68. toolchain {
  69. languageVersion.set(JavaLanguageVersion.of(jdkVersion))
  70. if (jdkVendor != '') vendor.set(JvmVendorSpec.matching(jdkVendor))
  71. }
  72. }
  73. compileJava {
  74. dependsOn 'compileOoxmlLite'
  75. options.fork = true
  76. options.forkOptions.jvmArgs << '-Xmx2G'
  77. }
  78. processResources.dependsOn 'compileOoxmlLite'
  79. sourcesJar.dependsOn 'compileOoxmlLite'
  80. task compileJava9(type: JavaCompile, dependsOn: 'compileJava') {
  81. javaCompiler = javaToolchains.compilerFor {
  82. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  83. }
  84. sourceCompatibility = 1.9
  85. targetCompatibility = 1.9
  86. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  87. source = file(JAVA9_SRC)
  88. classpath = files()
  89. doFirst {
  90. options.compilerArgs = [
  91. '--patch-module', "${MODULE_NAME}=${project(':poi-ooxml-full').sourceSets.main.output.asPath}",
  92. '--module-path', files(MAIN_MODULE_PATH).asPath
  93. ]
  94. }
  95. }
  96. jar {
  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. File missingXsbsFile = file("missing-xsbs.txt")
  106. List xsbs2 = missingXsbsFile.findAll { !it.empty && !it.startsWith("#") }
  107. .collect { "org/apache/poi/schemas/ooxml/system/ooxml/${it.trim()}.xsb" }
  108. includes = clazz + clazzInner + xsbs + xsbs2 + ['META-INF/versions/**', 'org/apache/poi/schemas/ooxml/element/**']
  109. }
  110. }
  111. // ignore second module-info.class from poi-ooxml-full
  112. // duplicatesStrategy = 'exclude'
  113. includeEmptyDirs = false
  114. manifest {
  115. attributes('Automatic-Module-Name' : MODULE_NAME, 'Multi-Release': 'true')
  116. }
  117. }
  118. sourcesJar {
  119. metaInf {
  120. from("$projectDir/../legal/LICENSE")
  121. from("$projectDir/../legal/NOTICE")
  122. }
  123. }
  124. spotbugsTest.enabled = false
  125. spotbugsMain.enabled = false
  126. javadoc.enabled = false
  127. javadocJar.enabled = false
  128. cyclonedxBom {
  129. // includeConfigs is the list of configuration names to include when generating the BOM (leave empty to include every configuration)
  130. includeConfigs = ["runtimeClasspath"]
  131. // skipConfigs is a list of configuration names to exclude when generating the BOM
  132. //skipConfigs = ["compileClasspath", "testCompileClasspath"]
  133. // Specified the type of project being built. Defaults to 'library'
  134. projectType = "library"
  135. // Specified the version of the CycloneDX specification to use. Defaults to 1.4.
  136. schemaVersion = "1.4"
  137. // Boms destination directory (defaults to build/reports)
  138. destination = file("build/reports")
  139. // The file name for the generated BOMs (before the file format suffix). Defaults to 'bom'
  140. outputName = "poi-ooxml-lite-${project.version}.bom"
  141. // The file format generated, can be xml, json or all for generating both
  142. outputFormat = "all"
  143. // Exclude BOM Serial Number
  144. includeBomSerialNumber = true
  145. }