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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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', ':poi-ooxml-full:compileJava'
  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. compileJava {
  68. dependsOn 'compileOoxmlLite'
  69. options.fork = true
  70. options.forkOptions.jvmArgs += '-Xmx2G'
  71. }
  72. processResources.dependsOn 'compileOoxmlLite'
  73. sourcesJar.dependsOn 'compileOoxmlLite'
  74. task compileJava9(type: JavaCompile, dependsOn: 'compileJava') {
  75. javaCompiler = javaToolchains.compilerFor {
  76. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  77. }
  78. sourceCompatibility = 1.9
  79. targetCompatibility = 1.9
  80. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  81. source = file(JAVA9_SRC)
  82. classpath = files()
  83. doFirst {
  84. options.compilerArgs = [
  85. '--patch-module', "${MODULE_NAME}=${project(':poi-ooxml-full').sourceSets.main.output.asPath}",
  86. '--module-path', files(MAIN_MODULE_PATH).asPath
  87. ]
  88. }
  89. }
  90. jar {
  91. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  92. doFirst {
  93. File clazzFile = file("${OOXML_LITE_REPORT}.clazz")
  94. File xsbsFile = file("${OOXML_LITE_REPORT}.xsb")
  95. if (clazzFile.exists() && xsbsFile.exists()) {
  96. List clazz = clazzFile.collect { "${it}.class" }
  97. List clazzInner = clazzFile.collect { "${it}\$*.class" }
  98. List xsbs = xsbsFile.collect { "org/apache/poi/schemas/ooxml/system/ooxml/${it}.xsb" }
  99. File missingXsbsFile = file("missing-xsbs.txt")
  100. List xsbs2 = missingXsbsFile.findAll { !it.empty && !it.startsWith("#") }
  101. .collect { "org/apache/poi/schemas/ooxml/system/ooxml/${it.trim()}.xsb" }
  102. includes = clazz + clazzInner + xsbs + xsbs2 + ['META-INF/versions/**', 'org/apache/poi/schemas/ooxml/element/**']
  103. }
  104. }
  105. // ignore second module-info.class from poi-ooxml-full
  106. // duplicatesStrategy = 'exclude'
  107. includeEmptyDirs = false
  108. manifest {
  109. attributes('Automatic-Module-Name' : MODULE_NAME, 'Multi-Release': 'true')
  110. }
  111. }
  112. sourcesJar {
  113. metaInf {
  114. from("$projectDir/../legal/LICENSE")
  115. from("$projectDir/../legal/NOTICE")
  116. }
  117. }
  118. spotbugsTest.enabled = false
  119. spotbugsMain.enabled = false
  120. javadoc.enabled = false
  121. javadocJar.enabled = false
  122. cyclonedxBom {
  123. // includeConfigs is the list of configuration names to include when generating the BOM (leave empty to include every configuration)
  124. includeConfigs = ["runtimeClasspath"]
  125. // skipConfigs is a list of configuration names to exclude when generating the BOM
  126. //skipConfigs = ["compileClasspath", "testCompileClasspath"]
  127. // Specified the type of project being built. Defaults to 'library'
  128. projectType = "library"
  129. // Specified the version of the CycloneDX specification to use. Defaults to 1.4.
  130. schemaVersion = "1.4"
  131. // Boms destination directory (defaults to build/reports)
  132. destination = file("build/reports")
  133. // The file name for the generated BOMs (before the file format suffix). Defaults to 'bom'
  134. outputName = "poi-ooxml-lite-${project.version}.bom"
  135. // The file format generated, can be xml, json or all for generating both
  136. outputFormat = "all"
  137. // Exclude BOM Serial Number
  138. includeBomSerialNumber = true
  139. }