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

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