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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 TEST9_SRC = 'src/test/java9'
  17. final String TEST9_OUT = "${buildDir}/classes/java9/test/"
  18. final String VERSIONS9 = 'META-INF/versions/9'
  19. configurations {
  20. tests
  21. }
  22. sourceSets {
  23. test {
  24. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  25. output.dir(TEST9_OUT, builtBy: 'cacheTest9')
  26. }
  27. }
  28. }
  29. dependencies {
  30. testImplementation 'org.apache.ant:ant:1.10.9'
  31. testImplementation 'org.apache.commons:commons-collections4:4.4'
  32. testImplementation 'com.google.guava:guava:30.0-jre'
  33. testImplementation project(':poi-ooxml')
  34. testImplementation project(':poi-scratchpad')
  35. testImplementation project(':poi-examples')
  36. testImplementation project(path:':poi-examples', configuration:'archives')
  37. testImplementation project(path:':poi', configuration:'tests')
  38. testImplementation project(path:':poi-ooxml', configuration:'tests')
  39. testImplementation project(path:':poi-scratchpad', configuration:'tests')
  40. testImplementation project(path: ':poi-ooxml-lite-agent', configuration: 'archives')
  41. }
  42. final String MODULE_NAME = 'org.apache.poi.stress'
  43. final Pattern MODULE_NOT_REGEX = ~'((poi|poi-scratchpad|poi-ooxml)[/\\\\][^/\\\\]+$|batik-script)'
  44. final Pattern MODULE_REGEX = ~'\\.jar$'
  45. final List TEST_MODULE_PATH = sourceSets.test.runtimeClasspath.findAll{ it.path =~ MODULE_REGEX && !(it.path =~ MODULE_NOT_REGEX) }.collect{ it.parent }.unique()
  46. final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-ooxml-lite-agent-${project.version}.jar"
  47. final String OOXML_LITE_REPORT = '../build/ooxml-lite-report'
  48. final String OOXML_LITE_JAR = "../build/dist/maven/poi-ooxml-lite/poi-ooxml-lite-${project.version}.jar"
  49. final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"
  50. java {
  51. sourceCompatibility = JavaVersion.VERSION_1_8
  52. targetCompatibility = JavaVersion.VERSION_1_8
  53. }
  54. task compileTest9(type: JavaCompile) {
  55. dependsOn 'compileTestJava', ':poi-ooxml:testJar', ':poi-scratchpad:testJar', ':poi-examples:jar'
  56. sourceCompatibility = 9
  57. targetCompatibility = 9
  58. destinationDirectory = file(TEST9_OUT + VERSIONS9)
  59. source = file(TEST9_SRC)
  60. options.compilerArgs = [
  61. '--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
  62. '--module-path', files(TEST_MODULE_PATH).asPath
  63. ]
  64. classpath = files()
  65. }
  66. task cacheTest9(type: Copy) {
  67. dependsOn 'compileTest9'
  68. from(file(TEST9_OUT + VERSIONS9))
  69. into(TEST9_SRC)
  70. }
  71. jar {
  72. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  73. manifest {
  74. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  75. }
  76. }
  77. // Create a separate jar for test-code to depend on it in other projects
  78. // See http://stackoverflow.com/questions/5144325/gradle-test-dependency
  79. task testJar(type: Jar, dependsOn: testClasses) {
  80. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-tests")
  81. classifier 'tests'
  82. // ignore second module-info.class from main
  83. duplicatesStrategy = 'exclude'
  84. if (JavaVersion.current() == JavaVersion.VERSION_1_8) {
  85. into('META-INF/versions/9') {
  86. from TEST9_SRC include '*.class'
  87. }
  88. }
  89. from sourceSets.test.output + sourceSets.main.output
  90. manifest {
  91. attributes('Automatic-Module-Name': MODULE_NAME, 'Multi-Release': 'true')
  92. }
  93. }
  94. artifacts {
  95. tests testJar
  96. }
  97. test {
  98. // exclude these from the normal test-run
  99. exclude '**/*FileHandler.class'
  100. dependsOn { testJar }
  101. useJUnitPlatform()
  102. doFirst {
  103. jvmArgs = [
  104. '-Djava.io.tmpdir=build',
  105. '-DPOI.testdata.path=../test-data',
  106. '-Djava.awt.headless=true',
  107. '-Djava.locale.providers=JRE,CLDR',
  108. '-Duser.language=en',
  109. '-Duser.country=US',
  110. '-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
  111. "-Dversion.id=${project.version}",
  112. '-ea',
  113. "-javaagent:${OOXML_LITE_AGENT}=${OOXML_LITE_REPORT}|${OOXML_LITE_INCLUDES}",
  114. '-Djunit.jupiter.execution.parallel.enabled=true',
  115. '-Djunit.jupiter.execution.parallel.config.strategy=fixed',
  116. '-Djunit.jupiter.execution.parallel.config.fixed.parallelism=3'
  117. // -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
  118. ]
  119. if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
  120. jvmArgs += [
  121. '-Dsun.reflect.debugModuleAccessChecks=true',
  122. '-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
  123. '--illegal-access=warn',
  124. '--add-modules', MODULE_NAME,
  125. // see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
  126. // opposed to the recommendation there, it doesn't work to add ... to the dependencies
  127. // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.7.1'
  128. // gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
  129. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
  130. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
  131. '--module-path', '../build/dist/maven/poi-integration-tests:' + files(TEST_MODULE_PATH).asPath,
  132. ]
  133. }
  134. }
  135. }
  136. generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"