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

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