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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. import org.w3c.dom.Node
  16. import org.w3c.dom.NodeList
  17. import javax.xml.xpath.XPath
  18. import javax.xml.xpath.XPathConstants
  19. import javax.xml.xpath.XPathFactory
  20. buildscript {
  21. repositories {
  22. maven { url 'https://plugins.gradle.org/m2/' }
  23. mavenCentral()
  24. }
  25. }
  26. plugins {
  27. id 'base'
  28. id 'com.dorongold.task-tree' version '2.1.1'
  29. id 'org.nosphere.apache.rat' version '0.8.1'
  30. id 'distribution'
  31. id "com.github.spotbugs" version '5.2.1'
  32. id 'de.thetaphi.forbiddenapis' version '3.6'
  33. id 'org.sonarqube' version '4.0.0.2929'
  34. id 'org.cyclonedx.bom' version '1.8.2'
  35. id 'com.adarshr.test-logger' version '3.2.0'
  36. }
  37. repositories {
  38. mavenCentral()
  39. // maven { url 'https://repository.apache.org/content/repositories/staging' }
  40. }
  41. // Only add the plugin for Sonar if enabled
  42. if (project.hasProperty('enableSonar')) {
  43. println 'Enabling Sonar support'
  44. apply plugin: 'org.sonarqube'
  45. }
  46. boolean isCIBuild = false
  47. String dateSuffix = new Date().format('yyyyMMdd')
  48. // For help converting an Ant build to a Gradle build, see
  49. // https://docs.gradle.org/current/userguide/ant.html
  50. configurations {
  51. antLibs {
  52. attributes {
  53. attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL))
  54. }
  55. }
  56. }
  57. dependencies {
  58. antLibs("org.junit.jupiter:junit-jupiter:5.10.2")
  59. antLibs("org.apache.ant:ant-junitlauncher:1.10.14")
  60. }
  61. ant.taskdef(name: "junit",
  62. classname: "org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.JUnitLauncherTask",
  63. classpath: configurations.antLibs.asPath)
  64. wrapper {
  65. gradleVersion = '8.7'
  66. }
  67. task adjustWrapperPropertiesFile {
  68. doLast {
  69. ant.replaceregexp(match:'^#.*', replace:'', flags:'g', byline:true) {
  70. fileset(dir: project.projectDir, includes: 'gradle/wrapper/gradle-wrapper.properties')
  71. }
  72. new File(project.projectDir, 'gradle/wrapper/gradle-wrapper.properties').with { it.text = it.readLines().findAll { it }.sort().join('\n') }
  73. ant.fixcrlf(file: 'gradle/wrapper/gradle-wrapper.properties', eol: 'lf')
  74. }
  75. }
  76. wrapper.finalizedBy adjustWrapperPropertiesFile
  77. group = 'org.apache.poi'
  78. /**
  79. Define properties for all projects, including this one
  80. */
  81. allprojects {
  82. // apply plugin: 'eclipse'
  83. apply plugin: 'idea'
  84. version = '5.2.6-SNAPSHOT'
  85. }
  86. /**
  87. Define things that are only necessary in sub-projects, but not in the master-project itself
  88. */
  89. subprojects {
  90. //Put instructions for each sub project, but not the master
  91. apply plugin: 'java-library'
  92. apply plugin: 'jacoco'
  93. apply plugin: 'maven-publish'
  94. apply plugin: 'signing'
  95. apply plugin: 'de.thetaphi.forbiddenapis'
  96. apply plugin: 'com.github.spotbugs'
  97. apply plugin: 'org.cyclonedx.bom'
  98. apply plugin: 'com.adarshr.test-logger'
  99. ext {
  100. bouncyCastleVersion = '1.78.1'
  101. commonsCodecVersion = '1.16.1'
  102. commonsCompressVersion = '1.26.1'
  103. commonsIoVersion = '2.16.1'
  104. commonsMathVersion = '3.6.1'
  105. junitVersion = '5.10.2'
  106. log4jVersion = '2.23.1'
  107. mockitoVersion = '4.11.0'
  108. hamcrestVersion = '2.2'
  109. xmlbeansVersion = '5.2.0'
  110. batikVersion = '1.17'
  111. graphics2dVersion = '3.0.1'
  112. pdfboxVersion = '3.0.2'
  113. saxonVersion = '12.4'
  114. xmlSecVersion = '3.0.4'
  115. apiGuardianVersion = '1.1.2'
  116. jdkVersion = (project.properties['jdkVersion'] ?: '8') as int
  117. // see https://github.com/gradle/gradle/blob/master/subprojects/jvm-services/src/main/java/org/gradle/internal/jvm/inspection/JvmVendor.java
  118. jdkVendor = (project.properties['jdkVendor'] ?: '') as String
  119. JAVA9_SRC = 'src/main/java9'
  120. JAVA9_OUT = "${buildDir}/classes/java9/main/"
  121. TEST9_SRC = 'src/test/java9'
  122. TEST9_OUT = "${buildDir}/classes/java9/test/"
  123. VERSIONS9 = 'META-INF/versions/9'
  124. NO_SCRATCHPAD = (findProperty("scratchpad.ignore") == "true")
  125. SAXON_TEST = (findProperty("saxon.test") == "true")
  126. }
  127. configurations {
  128. all {
  129. resolutionStrategy {
  130. force "commons-io:commons-io:${commonsIoVersion}"
  131. force 'org.slf4j:slf4j-api:2.0.13'
  132. force 'com.fasterxml.woodstox:woodstox-core:6.6.2'
  133. }
  134. }
  135. }
  136. tasks.withType(JavaCompile) {
  137. options.encoding = 'UTF-8'
  138. options.compilerArgs += '-Xlint:unchecked'
  139. options.deprecation = true
  140. options.incremental = true
  141. }
  142. tasks.withType(Test) {
  143. systemProperty "file.encoding", "UTF-8"
  144. }
  145. tasks.withType(Javadoc) {
  146. options.encoding = 'UTF-8'
  147. }
  148. tasks.withType(AbstractArchiveTask).configureEach {
  149. preserveFileTimestamps = false
  150. reproducibleFileOrder = true
  151. }
  152. repositories {
  153. mavenCentral()
  154. // maven { url 'https://repository.apache.org/content/repositories/staging' }
  155. }
  156. dependencies {
  157. testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
  158. testImplementation "org.mockito:mockito-core:${mockitoVersion}"
  159. testImplementation "org.hamcrest:hamcrest:${hamcrestVersion}"
  160. testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
  161. if (SAXON_TEST) {
  162. testRuntimeOnly("net.sf.saxon:Saxon-HE:${saxonVersion}") {
  163. exclude group: 'xml-apis', module: 'xml-apis'
  164. }
  165. }
  166. }
  167. java {
  168. toolchain {
  169. languageVersion = JavaLanguageVersion.of(jdkVersion)
  170. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  171. }
  172. withJavadocJar()
  173. withSourcesJar()
  174. }
  175. javadoc {
  176. failOnError = true
  177. maxMemory = "1024M"
  178. javadocTool = javaToolchains.javadocToolFor {
  179. languageVersion = JavaLanguageVersion.of(jdkVersion)
  180. }
  181. doFirst {
  182. options {
  183. if (jdkVersion > 8) addBooleanOption('html5', true)
  184. addBooleanOption('Xdoclint:all,-missing', true)
  185. links 'https://poi.apache.org/apidocs/dev/'
  186. links 'https://docs.oracle.com/javase/8/docs/api/'
  187. links 'https://xmlbeans.apache.org/docs/5.0.0/'
  188. links 'https://commons.apache.org/proper/commons-compress/apidocs/'
  189. use = true
  190. splitIndex = true
  191. source = "1.8"
  192. }
  193. }
  194. }
  195. // helper-target to get a directory with all third-party libraries
  196. // this is used for mass-regression-testing
  197. task getDeps(type: Copy) {
  198. from sourceSets.main.runtimeClasspath
  199. into 'build/runtime/'
  200. }
  201. tasks.withType(Jar) {
  202. duplicatesStrategy = 'fail'
  203. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  204. doLast {
  205. // make sure we do not have distribution jar-files with different versions
  206. // in the build-dir as those lead to strange errors about "duplicate modules"
  207. // when building java9 JPMS class files ("java9")
  208. ant.delete(failOnError: true, verbose: true) {
  209. fileset(dir: "../build/dist/maven/${project.archivesBaseName}", erroronmissingdir: false) {
  210. include(name: '*.jar')
  211. exclude(name: "*${version}.jar")
  212. exclude(name: "*${version}-sources.jar")
  213. include(name: '*.jar.asc')
  214. exclude(name: "*${version}.jar.asc")
  215. exclude(name: "*${version}-sources.jar.asc")
  216. include(name: '*.jar.sha256')
  217. exclude(name: "*${version}.jar.sha256")
  218. exclude(name: "*${version}-sources.jar.sha256")
  219. include(name: '*.jar.sha512')
  220. exclude(name: "*${version}.jar.sha512")
  221. exclude(name: "*${version}-sources.jar.sha512")
  222. include(name: '*.pom')
  223. exclude(name: "*${version}.pom")
  224. include(name: '*.pom.asc')
  225. exclude(name: "*${version}.pom.asc")
  226. }
  227. }
  228. // use failOnError=false for -javadoc and -tests as not all modules create this directory
  229. ant.delete(failOnError: false, verbose: true) {
  230. fileset(dir: "../build/dist/maven/${project.archivesBaseName}-javadoc", erroronmissingdir: false) {
  231. include(name: '*-javadoc.jar')
  232. exclude(name: "*${version}-javadoc.jar")
  233. include(name: '*-javadoc.jar.asc')
  234. exclude(name: "*${version}-javadoc.jar.asc")
  235. include(name: '*-javadoc.jar.sha256')
  236. exclude(name: "*${version}-javadoc.jar.sha256")
  237. include(name: '*-javadoc.jar.sha512')
  238. exclude(name: "*${version}-javadoc.jar.sha512")
  239. }
  240. }
  241. ant.delete(failOnError: false, verbose: true) {
  242. fileset(dir: "../build/dist/maven/${project.archivesBaseName}-tests", erroronmissingdir: false) {
  243. include(name: '*-tests.jar')
  244. exclude(name: "*${version}-tests.jar")
  245. include(name: '*-tests.jar.asc')
  246. exclude(name: "*${version}-tests.jar.asc")
  247. include(name: '*-tests.jar.sha256')
  248. exclude(name: "*${version}-tests.jar.sha256")
  249. include(name: '*-tests.jar.sha512')
  250. exclude(name: "*${version}-tests.jar.sha512")
  251. }
  252. }
  253. ant.checksum(file: it.archivePath, algorithm: 'SHA-256', fileext: '.sha256', format: 'MD5SUM')
  254. ant.checksum(file: it.archivePath, algorithm: 'SHA-512', fileext: '.sha512', format: 'MD5SUM')
  255. }
  256. }
  257. jar {
  258. from("../legal") {
  259. include "NOTICE"
  260. include "LICENSE"
  261. }
  262. rename('^(NOTICE|LICENSE)', 'META-INF/$1')
  263. manifest {
  264. attributes(
  265. 'Specification-Title': 'Apache POI',
  266. 'Specification-Version': project.version,
  267. 'Specification-Vendor': 'The Apache Software Foundation',
  268. 'Implementation-Title': 'Apache POI',
  269. 'Implementation-Version': project.version,
  270. 'Implementation-Vendor': 'org.apache.poi',
  271. 'Implementation-Vendor-Id': 'The Apache Software Foundation'
  272. )
  273. }
  274. }
  275. javadocJar {
  276. // if javadocs and binaries are in the same directory, JPMS complaints about duplicated modules
  277. // in the module-path
  278. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}-javadoc")
  279. }
  280. sourcesJar {
  281. destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")
  282. exclude 'META-INF/services/**'
  283. }
  284. test {
  285. // use US locale for tests
  286. systemProperty "user.language", "en"
  287. systemProperty "user.country", "US"
  288. // make XML test-results available for Jenkins CI
  289. useJUnitPlatform()
  290. reports {
  291. junitXml.required = true
  292. }
  293. javaLauncher = javaToolchains.launcherFor {
  294. languageVersion = JavaLanguageVersion.of(jdkVersion)
  295. if (jdkVendor != '') vendor = JvmVendorSpec.matching(jdkVendor)
  296. }
  297. // Exclude some tests that are not actually tests or do not run cleanly on purpose
  298. exclude '**/BaseTestBorderStyle.class'
  299. exclude '**/BaseTestCellUtil.class'
  300. exclude '**/TestUnfixedBugs.class'
  301. exclude '**/TestOneFile.class'
  302. // Exclude Test Suites
  303. exclude '**/All*Tests.class'
  304. exclude '**/HSSFTests.class'
  305. // set heap size for the test JVM(s)
  306. minHeapSize = "128m"
  307. maxHeapSize = "2g"
  308. // Specifying the local via system properties did not work, so we set them this way
  309. jvmArgs += [
  310. '-Djava.awt.headless=true',
  311. '-Djavax.xml.stream.XMLInputFactory=com.sun.xml.internal.stream.XMLInputFactoryImpl',
  312. "-Dversion.id=${project.version}",
  313. '-ea',
  314. // -Xjit:verbose={compileStart|compileEnd},vlog=build/jit.log${no.jit.sherlock} ... if ${isIBMVM}
  315. ]
  316. // detect if running on Jenkins/CI
  317. isCIBuild |= Boolean.valueOf(System.getenv("CI_BUILD"));
  318. if (isCIBuild) {
  319. System.out.println("Run with reduced parallelism for CI build");
  320. jvmArgs += [
  321. // Strictly serial
  322. '-Djunit.jupiter.execution.parallel.enabled=false',
  323. // OR parallel on 2 threads
  324. //'-Djunit.jupiter.execution.parallel.config.strategy=fixed',
  325. //'-Djunit.jupiter.execution.parallel.config.fixed.parallelism=2'
  326. ]
  327. maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  328. } else {
  329. jvmArgs += [
  330. '-Djunit.jupiter.execution.parallel.enabled=true',
  331. '-Djunit.jupiter.execution.parallel.config.strategy=dynamic',
  332. // this setting breaks the test builds, do not use it!
  333. //'-Djunit.jupiter.execution.parallel.mode.default=concurrent'
  334. ]
  335. // Explicitly defining the maxParallelForks was always slower than not setting it
  336. // So we leave this to Gradle itself, which seems to be very smart
  337. // maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  338. // maxParallelForks = Math.max( Runtime.runtime.availableProcessors() - 1, 1 )
  339. }
  340. // show standard out and standard error of the test JVM(s) on the console
  341. //testLogging.showStandardStreams = true
  342. // http://forums.gradle.org/gradle/topics/jacoco_related_failure_in_multiproject_build
  343. systemProperties['user.dir'] = workingDir
  344. systemProperties['java.io.tmpdir'] = 'build'
  345. systemProperties['POI.testdata.path'] = '../test-data'
  346. // define the locale to not have failing tests when the locale is set differently on the current machine
  347. systemProperties['user.language'] = 'en'
  348. systemProperties['user.country'] = 'US'
  349. // this is necessary for JDK 9+ to keep formatting dates the same way as in previous JDK-versions
  350. systemProperties['java.locale.providers'] = 'JRE,CLDR'
  351. doFirst {
  352. if (jdkVersion > 8) {
  353. // some options were removed in JDK 18
  354. if (jdkVersion < 18) {
  355. jvmArgs += [
  356. '--illegal-access=warn',
  357. ]
  358. }
  359. jvmArgs += [
  360. // see https://github.com/java9-modularity/gradle-modules-plugin/issues/97
  361. // opposed to the recommendation there, it doesn't work to add ... to the dependencies
  362. // testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.10.1'
  363. // gradles gradle-worker.jar is still not a JPMS module and thus runs as unnamed module
  364. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=org.apache.poi.poi',
  365. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.util=ALL-UNNAMED',
  366. '--add-exports','org.junit.platform.commons/org.junit.platform.commons.logging=ALL-UNNAMED',
  367. '-Dsun.reflect.debugModuleAccessChecks=true',
  368. '-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true',
  369. ]
  370. }
  371. }
  372. jacoco {
  373. excludes = [
  374. // this is necessary to make JaCoCo work with JDK 18 for now
  375. 'sun/**',
  376. 'javax/**',
  377. ]
  378. }
  379. }
  380. jacoco {
  381. toolVersion = '0.8.11'
  382. }
  383. jacocoTestReport {
  384. reports {
  385. xml.required = true
  386. }
  387. }
  388. // ensure the build-dir exists
  389. projectDir.mkdirs()
  390. if (project.hasProperty('enableSonar')) {
  391. // See https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/ and
  392. // https://docs.sonarqube.org/display/SONARQUBE52/Analyzing+with+SonarQube+Scanner+for+Gradle
  393. // for documentation of properties.
  394. //
  395. // Some additional properties are currently set in the Jenkins-DSL, see jenkins/create_jobs.groovy
  396. //
  397. sonar {
  398. properties {
  399. // as we currently use build/<module>/ as project-basedir, we need to tell Sonar to use
  400. // the root-folder as "basedir" for the projects
  401. property "sonar.projectBaseDir", "$projectDir"
  402. // currently supported providers on Jenkins: "hg,git": property "sonar.scm.provider", "svn"
  403. // the plugin seems to not detect our non-standard build-layout
  404. property "sonar.junit.reportPaths", "$projectDir/build/test-results/test"
  405. // the Gradle run will report an invalid directory for 'ooxml-schema', but it seems to still work fine
  406. property "sonar.coverage.jacoco.xmlReportPaths", "$projectDir/build/reports/jacoco/test/jacocoTestReport.xml"
  407. // somehow the version was not use properly
  408. property "sonar.projectVersion", version
  409. }
  410. }
  411. }
  412. forbiddenApis {
  413. bundledSignatures = [ 'jdk-unsafe', 'jdk-deprecated', 'jdk-internal', 'jdk-non-portable', 'jdk-reflection' ]
  414. signaturesFiles = files('../src/resources/devtools/forbidden-signatures.txt')
  415. ignoreFailures = false
  416. suppressAnnotations = [ 'org.apache.poi.util.SuppressForbidden' ]
  417. }
  418. forbiddenApisTest {
  419. // forbiddenapis bundled signatures max supported version is 17
  420. // also see https://github.com/policeman-tools/forbidden-apis/issues/191
  421. targetCompatibility = (JavaVersion.VERSION_17.isCompatibleWith(JavaVersion.current()) ? JavaVersion.current() : JavaVersion.VERSION_17)
  422. }
  423. forbiddenApisMain {
  424. signaturesFiles += files('../src/resources/devtools/forbidden-signatures-prod.txt')
  425. targetCompatibility = (JavaVersion.VERSION_17.isCompatibleWith(JavaVersion.current()) ? JavaVersion.current() : JavaVersion.VERSION_17)
  426. }
  427. publishing {
  428. publications {
  429. POI(MavenPublication) {
  430. groupId 'org.apache.poi'
  431. artifactId project.archivesBaseName
  432. from components.java
  433. pom {
  434. packaging = 'jar'
  435. url = 'https://poi.apache.org/'
  436. name = 'Apache POI'
  437. description = 'Apache POI - Java API To Access Microsoft Format Files'
  438. mailingLists {
  439. mailingList {
  440. name = 'POI Users List'
  441. subscribe = 'user-subscribe@poi.apache.org'
  442. unsubscribe = 'user-unsubscribe@poi.apache.org'
  443. archive = 'https://lists.apache.org/list.html?user@poi.apache.org'
  444. }
  445. mailingList {
  446. name = 'POI Developer List'
  447. subscribe = 'dev-subscribe@poi.apache.org'
  448. unsubscribe = 'dev-unsubscribe@poi.apache.org'
  449. archive = 'https://lists.apache.org/list.html?dev@poi.apache.org'
  450. }
  451. }
  452. licenses {
  453. license {
  454. name = 'Apache License, Version 2.0'
  455. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  456. distribution = 'repo'
  457. }
  458. }
  459. organization {
  460. name = 'Apache Software Foundation'
  461. url = 'http://www.apache.org/'
  462. }
  463. issueManagement {
  464. system = 'bugzilla'
  465. url = 'https://bz.apache.org/bugzilla'
  466. }
  467. developers {
  468. developer {
  469. name = 'POI Team'
  470. id = 'poi'
  471. email = 'user@poi.apache.org'
  472. organization = 'Apache POI'
  473. }
  474. }
  475. withXml {
  476. def r = asElement()
  477. def doc = r.getOwnerDocument()
  478. def hdr = new File('../legal/HEADER')
  479. if (!hdr.exists()) hdr = new File('legal/HEADER')
  480. def asl = doc.createComment(hdr.text)
  481. // adding ASF header before root node is ignored
  482. // doc.insertBefore(asl, doc.getDocumentElement())
  483. r.insertBefore(asl, r.getFirstChild())
  484. // Replace ooxml-full with ooxml-lite
  485. XPath xpath = XPathFactory.newInstance().newXPath()
  486. NodeList res = (NodeList)xpath.evaluate("//dependency/artifactId[text() = 'poi-ooxml-full']", doc, XPathConstants.NODESET)
  487. for (int i=res.getLength()-1; i>=0; i--) {
  488. res.item(i).setTextContent('poi-ooxml-lite')
  489. }
  490. // remove duplicate entries
  491. res = (NodeList)xpath.evaluate("//dependency[artifactId = ./preceding-sibling::dependency/artifactId]", doc, XPathConstants.NODESET)
  492. for (int i=res.getLength()-1; i>=0; i--) {
  493. Node n = res.item(i)
  494. n.getParentNode().removeChild(n)
  495. }
  496. }
  497. }
  498. }
  499. }
  500. }
  501. generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"
  502. tasks.withType(GenerateModuleMetadata) {
  503. enabled = false
  504. }
  505. signing {
  506. setRequired {
  507. // signing is only required if this is a release version
  508. // and the artifacts are to be published
  509. gradle.taskGraph.allTasks.any { it instanceof PublishToMavenRepository }
  510. }
  511. sign publishing.publications.POI
  512. }
  513. signPOIPublication.dependsOn('generatePomFileForPOIPublication')
  514. spotbugs {
  515. ignoreFailures = true
  516. showStackTraces = false
  517. maxHeapSize = '2g'
  518. }
  519. build {
  520. if (project.hasProperty('signing.keyId')) {
  521. dependsOn 'signPOIPublication'
  522. }
  523. }
  524. }
  525. // initial try to provide a combined JavaDoc, grouping is still missing here, though!
  526. task allJavaDoc(type: Javadoc) {
  527. var prj = [ project(':poi'), project(':poi-excelant'), project(':poi-ooxml'), project(':poi-scratchpad') ]
  528. source prj.collect { it.sourceSets.main.allJava }
  529. // for possible settings see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.javadoc.Javadoc.html
  530. classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
  531. destinationDir = file("${buildDir}/docs/javadoc")
  532. maxMemory="2048M"
  533. // for possible options see https://docs.gradle.org/current/javadoc/org/gradle/external/javadoc/StandardJavadocDocletOptions.html
  534. options.use = true
  535. options.splitIndex = true
  536. options.addBooleanOption('Xdoclint:all,-missing', true)
  537. title = 'POI API Documentation'
  538. options.bottom = '<![CDATA[<i>Copyright ' + new Date().format('yyyy') + ' The Apache Software Foundation or its licensors, as applicable.</i>]]>'
  539. options.group('DDF - Dreadful Drawing Format', 'org.apache.poi.ddf*')
  540. options.group('HPSF - Horrible Property Set Format', 'org.apache.poi.hpsf*')
  541. options.group('SS - Common Spreadsheet Format', 'org.apache.poi.ss*')
  542. options.group('HSSF - Horrible Spreadsheet Format', 'org.apache.poi.hssf*')
  543. options.group('XSSF - Open Office XML Spreadsheet Format', 'org.apache.poi.xssf*')
  544. options.group('SL - Common Slideshow Format', 'org.apache.poi.sl*')
  545. options.group('HSLF - Horrible Slideshow Format', 'org.apache.poi.hslf*', 'org.apache.poi.hwmf*', 'org.apache.poi.hemf*')
  546. options.group('XSLF - Open Office XML Slideshow Format', 'org.apache.poi.xslf*')
  547. options.group('HWPF - Horrible Word Processor Format', 'org.apache.poi.hwpf*')
  548. options.group('XWPF - Open Office XML Word Processor Format', 'org.apache.poi.xwpf*')
  549. options.group('HDGF - Horrible Diagram Format', 'org.apache.poi.hdgf*')
  550. options.group('XDGF - Open Office XML Diagram Format', 'org.apache.poi.xdgf*')
  551. options.group('HMEF - Transport Neutral Encoding Files (TNEF)', 'org.apache.poi.hmef*')
  552. options.group('HSMF Outlook message file format', 'org.apache.poi.hsmf*')
  553. options.group('HPBF - Publisher Format Files', 'org.apache.poi.hpbf*')
  554. options.group('POIFS - POI File System', 'org.apache.poi.poifs*')
  555. options.group('Utilities', 'org.apache.poi.util*')
  556. options.group('Excelant', 'org.apache.poi.ss.excelant**')
  557. // options.group('Examples', 'org.apache.poi.examples*')
  558. }
  559. clean {
  560. delete "${rootDir}/build/dist"
  561. }
  562. rat {
  563. // Input directory, defaults to '.'
  564. inputDir.set(file("."))
  565. // include all directories which contain files that are included in releases
  566. includes = [
  567. "poi-examples/**",
  568. "poi-excelant/**",
  569. "poi-integration/**",
  570. "legal/**",
  571. "poi/**",
  572. "maven/**",
  573. "poi-ooxml/**",
  574. "poi-ooxml-full/**",
  575. "poi-ooxml-lite/**",
  576. "poi-ooxml-lite-agent/**",
  577. "osgi/**",
  578. "poi-scratchpad/**",
  579. "src/**",
  580. // "sonar/**",
  581. "build.*"
  582. ]
  583. // List of Gradle exclude directives, defaults to ['**/.gradle/**']
  584. //excludes.add("main/java/org/apache/poi/**/*-chart-data.txt")
  585. excludes = [
  586. "build.javacheck.xml",
  587. "**/build/**",
  588. "**/out/**",
  589. "**/*.iml",
  590. "**/*.log",
  591. "**/gradle-wrapper.properties",
  592. "**/main/java/org/apache/poi/**/*-chart-data.txt",
  593. "poi/src/main/resources/org/apache/poi/sl/draw/geom/presetShapeDefinitions.xml",
  594. "poi-ooxml/src/main/resources/org/apache/poi/xslf/usermodel/notesMaster.xml",
  595. "poi-ooxml/src/main/resources/org/apache/poi/xssf/usermodel/presetTableStyles.xml",
  596. "poi-ooxml-full/src/main/xmlschema/org/apache/poi/schemas/*.xsd",
  597. "poi-ooxml-full/src/main/xmlschema/org/apache/poi/xdgf/visio.xsd",
  598. "osgi/README.md",
  599. "src/resources/ooxml-lite-report.*",
  600. // ignore svn conflict artifacts
  601. "**/module-info.*"
  602. ]
  603. /*
  604. <exclude name="documentation/*.txt" />
  605. <exclude name="documentation/content/xdocs/dtd/" />
  606. <exclude name="documentation/content/xdocs/entity/" />
  607. <exclude name="documentation/resources/images/pb-poi.cdr"/>
  608. */
  609. // Prints the list of files with unapproved licences to the console, defaults to false
  610. verbose.set(true)
  611. }
  612. task jenkins(dependsOn: [
  613. 'replaceVersion',
  614. subprojects.build,
  615. subprojects.check,
  616. subprojects.javadoc,
  617. subprojects.jacocoTestReport,
  618. subprojects.getDeps,
  619. 'srcDistZip',
  620. 'srcDistTar',
  621. rat
  622. ]) {}
  623. task jenkinsLite(dependsOn: [
  624. 'replaceVersion',
  625. subprojects.build,
  626. subprojects.test
  627. ]) {}
  628. /*task downloadJarsToLibs() {
  629. def f = new File("$projectDir/../lib/ooxml/xmlbeans-5.0.0.jar")
  630. if (!f.exists()) {
  631. println 'writing file ' + f.getAbsolutePath()
  632. f.getParentFile().mkdirs()
  633. new URL('https://ci-builds.apache.org/job/POI/job/POI-XMLBeans-DSL-1.8/lastSuccessfulBuild/artifact/build/xmlbeans-5.0.0.jar').withInputStream{ i -> f.withOutputStream{ it << i }}
  634. }
  635. }*/
  636. //compileJava.dependsOn 'downloadJarsToLibs'
  637. task replaceVersion() {
  638. outputs.upToDateWhen { false }
  639. var version = subprojects[0].version
  640. var tokens = [
  641. [ 'osgi', 'pom.xml', '(packaging>\\n\\s*<version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}" ],
  642. [ 'osgi', 'pom.xml', '(<poi.version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}" ]
  643. // [ '.', 'build.gradle', ' version = \'[0-9.]+(?:-SNAPSHOT)?\'', " version = '${version}'" ]
  644. ]
  645. doLast {
  646. tokens.forEach {
  647. var dir = it[0], name = it[1], match = it[2], replace = it[3]
  648. ant.replaceregexp(match: match, replace: replace) {
  649. fileset(dir: dir) {
  650. include(name: name)
  651. }
  652. }
  653. }
  654. }
  655. }
  656. task zipJavadocs(type: Zip, dependsOn: allJavaDoc) {
  657. from('build/docs/javadoc/')
  658. destinationDirectory = file('build/dist')
  659. archiveBaseName = 'poi'
  660. archiveVersion = subprojects[0].version
  661. archiveAppendix = 'javadoc'
  662. archiveExtension = 'jar'
  663. }
  664. tasks.withType(Tar) {
  665. compression = Compression.GZIP
  666. archiveExtension = 'tgz'
  667. }
  668. distributions {
  669. src {
  670. contents {
  671. from('.') {
  672. exclude '*/build/**'
  673. exclude 'build/**'
  674. exclude 'dist*/**'
  675. exclude 'lib/**'
  676. exclude 'lib.stored/**'
  677. exclude 'bin/**'
  678. exclude 'out/**'
  679. exclude 'tmp/**'
  680. exclude 'gradle/**'
  681. exclude 'sonar/**/target/**'
  682. exclude 'sonar/*/src/**'
  683. exclude 'compile-lib/**'
  684. exclude 'ooxml-lib/**'
  685. exclude 'ooxml-testlib/**'
  686. exclude 'scripts/**'
  687. exclude '.gradle/**'
  688. exclude '.idea/**'
  689. exclude '.classpath'
  690. exclude '.settings/**'
  691. exclude '.project'
  692. exclude 'TEST*'
  693. exclude 'gradlew'
  694. exclude 'gradlew.bat'
  695. exclude '**/*.iml'
  696. exclude '*.ipr'
  697. exclude '*.iws'
  698. exclude '*.rdf'
  699. exclude '*.png'
  700. exclude '*.gif'
  701. exclude '*.jpg'
  702. exclude '*.jpeg'
  703. exclude '*.swp'
  704. exclude '*.lnk'
  705. exclude '*.log'
  706. exclude '*.launch'
  707. exclude '*.docx'
  708. exclude '*.pptx'
  709. exclude '*.xlsx'
  710. // exclude intermediate files
  711. exclude '**/*-saved.xls'
  712. }
  713. from('legal') { exclude 'HEADER' }
  714. includeEmptyDirs = false
  715. duplicatesStrategy = DuplicatesStrategy.EXCLUDE
  716. }
  717. }
  718. }
  719. task soLinkCheck() {
  720. doLast {
  721. def path = ant.path {
  722. fileset(dir: '.', includes: '**/*.java') {
  723. exclude(name: 'build.gradle')
  724. contains(text: 'stackoverflow.com')
  725. }
  726. }
  727. path.list().each {
  728. println it
  729. }
  730. if (path.size() > 0) {
  731. // #65796 - minimize notifications about non-asf open source
  732. throw new GradleException('License issue found - conceal the link and contradict any findings m(')
  733. }
  734. }
  735. }
  736. var srcDep = [
  737. ':poi:compileJava9',
  738. ':poi:compileTest9',
  739. ':poi-ooxml-full:compileJava9',
  740. ':poi-ooxml-lite-agent:compileJava9',
  741. ':poi-ooxml:compileJava9',
  742. ':poi-ooxml:compileTest9',
  743. ':poi-scratchpad:compileJava9',
  744. ':poi-scratchpad:compileTest9',
  745. ':poi-excelant:compileJava9',
  746. ':poi-excelant:compileTest9',
  747. ':poi-examples:compileJava9',
  748. ':poi-integration:compileTest9',
  749. ':poi-ooxml-lite:compileJava9',
  750. ':poi-ooxml-lite:generateModuleInfo'
  751. ]
  752. srcDistTar.setArchiveFileName("poi-src-${subprojects[0].version}-${dateSuffix}.tgz")
  753. srcDistZip.setArchiveFileName("poi-src-${subprojects[0].version}-${dateSuffix}.zip")
  754. srcDistTar.dependsOn srcDep
  755. srcDistZip.dependsOn srcDep
  756. soLinkCheck.dependsOn srcDep
  757. rat.dependsOn soLinkCheck
  758. task fixDistDir {
  759. doLast {
  760. ant.mkdir(dir: 'build/dist')
  761. ant.move(todir: 'build/dist') {
  762. fileset(dir: 'build/distributions', includes: '*')
  763. }
  764. }
  765. }
  766. srcDistZip.finalizedBy fixDistDir
  767. srcDistTar.finalizedBy fixDistDir