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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 MODULE_NAME = 'org.apache.poi.ooxml.schemas'
  17. final String BEANS_SRC = "${buildDir}/generated-sources"
  18. final String BEANS_RES = "${buildDir}/generated-resources"
  19. sourceSets {
  20. main {
  21. // TypeSystemHolder.class is in the resources
  22. output.dir(BEANS_RES, builtBy: 'generate_beans')
  23. compileClasspath += files(BEANS_RES)
  24. if (jdkVersion > 8) {
  25. output.dir(JAVA9_OUT, builtBy: 'cacheJava9')
  26. }
  27. java {
  28. srcDirs = [BEANS_SRC]
  29. }
  30. }
  31. }
  32. dependencies {
  33. api "org.apache.xmlbeans:xmlbeans:${xmlbeansVersion}"
  34. }
  35. idea {
  36. module {
  37. // Marks the already(!) added srcDir as "generated"
  38. generatedSourceDirs += file(BEANS_SRC)
  39. resourceDirs += file(BEANS_RES)
  40. }
  41. }
  42. final Pattern MODULE_REGEX = ~'\\.jar$'
  43. final List MAIN_MODULE_PATH = sourceSets.main.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()
  44. compileJava {
  45. dependsOn 'generate_beans'
  46. options.fork = true
  47. options.forkOptions.jvmArgs << '-Xmx2G'
  48. }
  49. task compileJava9(type: JavaCompile) {
  50. dependsOn 'compileJava'
  51. javaCompiler = javaToolchains.compilerFor {
  52. languageVersion = JavaLanguageVersion.of(Math.max(11, jdkVersion))
  53. }
  54. sourceCompatibility = 1.9
  55. targetCompatibility = 1.9
  56. destinationDirectory = file(JAVA9_OUT + VERSIONS9)
  57. source = file(JAVA9_SRC)
  58. classpath = files()
  59. options.compilerArgs = [
  60. '--patch-module', "${MODULE_NAME}=${sourceSets.main.output.asPath}",
  61. '--module-path', files(MAIN_MODULE_PATH).asPath
  62. ]
  63. }
  64. task cacheJava9(type: Copy) {
  65. dependsOn 'compileJava9'
  66. from(file(JAVA9_OUT + VERSIONS9))
  67. into(JAVA9_SRC)
  68. }
  69. task copy_xsds(type: Copy) {
  70. from ('src/main/xmlschema/org/apache/poi/xdgf')
  71. from ('src/main/xmlschema/org/apache/poi/schemas') {
  72. include 'XAdES*.xsd', '*.xsdconfig', 'xmldsig*.xsd', 'ooxmlSchemas.xsdconfig', 'markup-compatibility.xsd',
  73. 'vmlDrawing.xsd', 'word12.xsd', 'xlThreaded*.xsd', 'dml-drawing.xsd'
  74. exclude '*.zip'
  75. }
  76. from ('src/main/xmlschema/org/apache/poi/poifs/crypt') {
  77. include 'signatureInfo.xsd'
  78. }
  79. from (zipTree('src/main/xmlschema/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip'))
  80. from (zipTree('src/main/xmlschema/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip')) {
  81. include 'opc-digSig.xsd', 'opc-relationships.xsd'
  82. }
  83. into 'build/xsds'
  84. }
  85. task generate_beans(dependsOn: copy_xsds) {
  86. inputs.dir 'build/xsds'
  87. outputs.dir 'build/generated-resources'
  88. doLast {
  89. ant.uptodate(
  90. property: 'xmlbeans_uptodate',
  91. targetfile: 'build/generated-resources/org/apache/poi/schemas/ooxml/system/ooxml/TypeSystemHolder.class'
  92. ) {
  93. srcFiles(dir: 'build/xsds', includes: '*.xsd')
  94. }
  95. ant.taskdef(
  96. name: 'xmlbean',
  97. classname: 'org.apache.xmlbeans.impl.tool.XMLBean',
  98. classpath: sourceSets.main.runtimeClasspath.asPath
  99. )
  100. if (!ant.properties.xmlbeans_uptodate) {
  101. ant.xmlbean(
  102. schema: 'build/xsds',
  103. srcgendir: BEANS_SRC,
  104. classgendir: BEANS_RES,
  105. destfile: 'build/xsds.jar',
  106. srconly: true,
  107. failonerror: true,
  108. fork: true,
  109. memoryMaximumSize: '1536m',
  110. typesystemname: 'ooxml',
  111. repackage: 'org.apache.xmlbeans.metadata:org.apache.poi.schemas.ooxml'
  112. ) {
  113. classpath = sourceSets.main.runtimeClasspath.asPath
  114. }
  115. }
  116. }
  117. }
  118. task sourceJar(type: Jar) {
  119. classifier 'sources'
  120. from sourceSets.main.allJava
  121. }
  122. jar {
  123. dependsOn 'sourceJar'
  124. if (jdkVersion == 8) {
  125. into('META-INF/versions/9') {
  126. from JAVA9_SRC include '*.class'
  127. }
  128. }
  129. manifest {
  130. attributes ('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  131. }
  132. }
  133. sourcesJar {
  134. metaInf {
  135. from("$projectDir/../legal/LICENSE")
  136. from("$projectDir/../legal/NOTICE")
  137. }
  138. }
  139. publishing {
  140. publications {
  141. POI(MavenPublication) {
  142. pom {
  143. name = 'Apache POI - OOXML schemas (full)'
  144. description =
  145. 'XmlBeans generated from the Ecma supplied xsds (since POI 5.0.0, the 5th edition is used):\n' +
  146. ' https://www.ecma-international.org/publications/standards/Ecma-376.htm'
  147. }
  148. }
  149. }
  150. }
  151. spotbugsTest.enabled = false
  152. spotbugsMain.enabled = false
  153. javadoc.enabled = false
  154. javadocJar.enabled = false
  155. cyclonedxBom {
  156. // includeConfigs is the list of configuration names to include when generating the BOM (leave empty to include every configuration)
  157. includeConfigs = ["runtimeClasspath"]
  158. // skipConfigs is a list of configuration names to exclude when generating the BOM
  159. //skipConfigs = ["compileClasspath", "testCompileClasspath"]
  160. // Specified the type of project being built. Defaults to 'library'
  161. projectType = "library"
  162. // Specified the version of the CycloneDX specification to use. Defaults to 1.4.
  163. schemaVersion = "1.4"
  164. // Boms destination directory (defaults to build/reports)
  165. destination = file("build/reports")
  166. // The file name for the generated BOMs (before the file format suffix). Defaults to 'bom'
  167. outputName = "poi-ooxml-full-${project.version}.bom"
  168. // The file format generated, can be xml, json or all for generating both
  169. outputFormat = "all"
  170. // Exclude BOM Serial Number
  171. includeBomSerialNumber = true
  172. }