Skip to content

Commit

Permalink
Some changes to the Gradle build
Browse files Browse the repository at this point in the history
Apply IDE suggestions for Gradle build files
Remove obsolete sorting of gradle-wrapper.properties

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923284 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Jan 20, 2025
1 parent 045a37f commit 1dbcea4
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 124 deletions.
77 changes: 33 additions & 44 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,6 @@ wrapper {
gradleVersion = '8.12'
}

task adjustWrapperPropertiesFile {
doLast {
ant.replaceregexp(match:'^#.*', replace:'', flags:'g', byline:true) {
fileset(dir: project.projectDir, includes: 'gradle/wrapper/gradle-wrapper.properties')
}
new File(project.projectDir, 'gradle/wrapper/gradle-wrapper.properties').with { it.text = it.readLines().findAll { it }.sort().join('\n') }
ant.fixcrlf(file: 'gradle/wrapper/gradle-wrapper.properties', eol: 'lf')
}
}
wrapper.finalizedBy adjustWrapperPropertiesFile

group = 'org.apache.poi'

/**
Expand Down Expand Up @@ -150,7 +139,7 @@ subprojects {
}

configurations {
all {
configureEach {
resolutionStrategy {
force "commons-io:commons-io:${commonsIoVersion}"
force 'org.slf4j:slf4j-api:2.0.16'
Expand All @@ -159,16 +148,16 @@ subprojects {
}
}

tasks.withType(JavaCompile) {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.compilerArgs += '-Xlint:unchecked'
options.deprecation = true
options.incremental = true
}
tasks.withType(Test) {
tasks.withType(Test).configureEach {
systemProperty "file.encoding", "UTF-8"
}
tasks.withType(Javadoc) {
tasks.withType(Javadoc).configureEach {
options.encoding = 'UTF-8'
}
tasks.withType(AbstractArchiveTask).configureEach {
Expand Down Expand Up @@ -227,13 +216,13 @@ subprojects {

// helper-target to get a directory with all third-party libraries
// this is used for mass-regression-testing
task getDeps(type: Copy) {
tasks.register('getDeps', Copy) {
from sourceSets.main.runtimeClasspath
into 'build/runtime/'
}

tasks.withType(Jar) {
duplicatesStrategy = 'fail'
tasks.withType(Jar).configureEach {
duplicatesStrategy = DuplicatesStrategy.FAIL
destinationDirectory = file("../build/dist/maven/${project.archivesBaseName}")

doLast {
Expand Down Expand Up @@ -375,10 +364,10 @@ subprojects {
]

// detect if running on Jenkins/CI
isCIBuild |= Boolean.valueOf(System.getenv("CI_BUILD"));
isCIBuild |= Boolean.valueOf(System.getenv("CI_BUILD"))

if (isCIBuild) {
System.out.println("Run with reduced parallelism for CI build");
System.out.println("Run with reduced parallelism for CI build")

jvmArgs += [
// Strictly serial
Expand Down Expand Up @@ -597,7 +586,7 @@ subprojects {

generatePomFileForPOIPublication.destination = "../build/dist/maven/${project.archivesBaseName}/${project.archivesBaseName}-${project.version}.pom"

tasks.withType(GenerateModuleMetadata) {
tasks.withType(GenerateModuleMetadata).configureEach {
enabled = false
}

Expand Down Expand Up @@ -625,14 +614,14 @@ subprojects {
}

// initial try to provide a combined JavaDoc, grouping is still missing here, though!
task allJavaDoc(type: Javadoc) {
var prj = [ project(':poi'), project(':poi-excelant'), project(':poi-ooxml'), project(':poi-scratchpad') ]
tasks.register('allJavaDoc', Javadoc) {
var prj = [project(':poi'), project(':poi-excelant'), project(':poi-ooxml'), project(':poi-scratchpad')]
source prj.collect { it.sourceSets.main.allJava }

// for possible settings see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.javadoc.Javadoc.html
classpath = files(subprojects.collect { it.sourceSets.main.compileClasspath })
destinationDir = file("${buildDir}/docs/javadoc")
maxMemory="2048M"
maxMemory = "2048M"

// for possible options see https://docs.gradle.org/current/javadoc/org/gradle/external/javadoc/StandardJavadocDocletOptions.html
options.use = true
Expand All @@ -647,7 +636,7 @@ task allJavaDoc(type: Javadoc) {
options.group('SS - Common Spreadsheet Format', 'org.apache.poi.ss*')
options.group('HSSF - Horrible Spreadsheet Format', 'org.apache.poi.hssf*')
options.group('XSSF - Open Office XML Spreadsheet Format', 'org.apache.poi.xssf*')
options.group('SL - Common Slideshow Format', 'org.apache.poi.sl*')
options.group('SL - Common Slideshow Format', 'org.apache.poi.sl*')
options.group('HSLF - Horrible Slideshow Format', 'org.apache.poi.hslf*', 'org.apache.poi.hwmf*', 'org.apache.poi.hemf*')
options.group('XSLF - Open Office XML Slideshow Format', 'org.apache.poi.xslf*')
options.group('HWPF - Horrible Word Processor Format', 'org.apache.poi.hwpf*')
Expand Down Expand Up @@ -725,21 +714,21 @@ rat {
}

task jenkins(dependsOn: [
'replaceVersion',
subprojects.build,
subprojects.check,
subprojects.javadoc,
subprojects.jacocoTestReport,
subprojects.getDeps,
'srcDistZip',
'srcDistTar',
rat
'replaceVersion',
subprojects.build,
subprojects.check,
subprojects.javadoc,
subprojects.jacocoTestReport,
subprojects.getDeps,
'srcDistZip',
'srcDistTar',
rat
]) {}

task jenkinsLite(dependsOn: [
'replaceVersion',
subprojects.build,
subprojects.test
'replaceVersion',
subprojects.build,
subprojects.test
]) {}

/*task downloadJarsToLibs() {
Expand All @@ -753,14 +742,14 @@ task jenkinsLite(dependsOn: [

//compileJava.dependsOn 'downloadJarsToLibs'

task replaceVersion() {
tasks.register('replaceVersion') {
outputs.upToDateWhen { false }

var version = subprojects[0].version
var tokens = [
[ 'osgi', 'pom.xml', '(packaging>\\n\\s*<version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}" ],
[ 'osgi', 'pom.xml', '(<poi.version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}" ]
// [ '.', 'build.gradle', ' version = \'[0-9.]+(?:-SNAPSHOT)?\'', " version = '${version}'" ]
['osgi', 'pom.xml', '(packaging>\\n\\s*<version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}"],
['osgi', 'pom.xml', '(<poi.version>)[0-9.]+(?:-SNAPSHOT|-RC\\d+)?', "\\1${version}"]
// [ '.', 'build.gradle', ' version = \'[0-9.]+(?:-SNAPSHOT)?\'', " version = '${version}'" ]
]

doLast {
Expand All @@ -784,7 +773,7 @@ task zipJavadocs(type: Zip, dependsOn: allJavaDoc) {
archiveExtension = 'jar'
}

tasks.withType(Tar) {
tasks.withType(Tar).configureEach {
compression = Compression.GZIP
archiveExtension = 'tgz'
}
Expand Down Expand Up @@ -843,7 +832,7 @@ distributions {
}
}

task soLinkCheck() {
tasks.register('soLinkCheck') {
doLast {
def path = ant.path {
fileset(dir: '.', includes: '**/*.java') {
Expand Down Expand Up @@ -887,7 +876,7 @@ srcDistZip.dependsOn srcDep
soLinkCheck.dependsOn srcDep
rat.dependsOn soLinkCheck

task fixDistDir {
tasks.register('fixDistDir') {
doLast {
ant.mkdir(dir: 'build/dist')
ant.move(todir: 'build/dist') {
Expand Down
6 changes: 3 additions & 3 deletions poi-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final String MODULE_NAME = 'org.apache.poi.examples'
final Pattern MODULE_REGEX = ~'\\.jar$'
final List MODULE_COMPILE_PATH = sourceSets.main.compileClasspath.findAll{ it.path =~ MODULE_REGEX }.collect{ it.parent }.unique()

task compileJava9(type: JavaCompile) {
tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'

javaCompiler = javaToolchains.compilerFor {
Expand All @@ -61,8 +61,8 @@ task compileJava9(type: JavaCompile) {
source = file(JAVA9_SRC)
classpath = files()
options.compilerArgs = [
'--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
'--module-path', files(MODULE_COMPILE_PATH).asPath
'--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
'--module-path', files(MODULE_COMPILE_PATH).asPath
]
}

Expand Down
6 changes: 3 additions & 3 deletions poi-examples/src/main/groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ sourceSets {
}

// Run out read demo by default
tasks.withType(JavaExec) {
classpath = sourceSets.main.runtimeClasspath
tasks.withType(JavaExec).configureEach {
classpath = sourceSets.main.runtimeClasspath
}
task runScript(type: JavaExec) {
tasks.register('runScript', JavaExec) {
mainClass = "SpreadSheetDemo"
args = ["../../../../test-data/spreadsheet/Simple.xls"]
}
Expand Down
14 changes: 7 additions & 7 deletions poi-excelant/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-oo
final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"

task compileJava9(type: JavaCompile) {
tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'

javaCompiler = javaToolchains.compilerFor {
Expand All @@ -69,12 +69,12 @@ task compileJava9(type: JavaCompile) {
source = file(JAVA9_SRC)
classpath = files()
options.compilerArgs = [
'--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
'--module-path', files(MAIN_MODULE_PATH).asPath
'--patch-module', "${MODULE_NAME}=${sourceSets.main.output.classesDirs.asPath}",
'--module-path', files(MAIN_MODULE_PATH).asPath
]
}

task compileTest9(type: JavaCompile) {
tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava', ':poi-ooxml:jar', ':poi-scratchpad:jar'

javaCompiler = javaToolchains.compilerFor {
Expand All @@ -85,8 +85,8 @@ task compileTest9(type: JavaCompile) {
destinationDirectory = file(TEST9_OUT + VERSIONS9)
source = file(TEST9_SRC)
options.compilerArgs = [
'--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
'--module-path', files(TEST_MODULE_PATH).asPath
'--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
'--module-path', files(TEST_MODULE_PATH).asPath
]
classpath = files()
}
Expand Down Expand Up @@ -123,7 +123,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ] ) {

setArchiveClassifier 'tests'
// ignore second module-info.class from main
duplicatesStrategy = 'exclude'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

from sourceSets.test.output + sourceSets.main.output

Expand Down
8 changes: 4 additions & 4 deletions poi-integration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ final String OOXML_LITE_AGENT = "../build/dist/maven/poi-ooxml-lite-agent/poi-oo
final String OOXML_LITE_REPORT = '../src/resources/ooxml-lite-report'
final String OOXML_LITE_INCLUDES = "^(com/microsoft/schemas|org/(etsi|openxmlformats|w3/)|org/apache/poi/schemas)"

task compileTest9(type: JavaCompile) {
tasks.register('compileTest9', JavaCompile) {
dependsOn 'compileTestJava', ':poi-ooxml:testJar', ':poi-scratchpad:testJar', ':poi-examples:jar'

javaCompiler = javaToolchains.compilerFor {
Expand All @@ -101,8 +101,8 @@ task compileTest9(type: JavaCompile) {
destinationDirectory = file(TEST9_OUT + VERSIONS9)
source = file(TEST9_SRC)
options.compilerArgs = [
'--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
'--module-path', files(MODULE_COMPILE_PATH).asPath
'--patch-module', "${MODULE_NAME}=${(sourceSets.main.output.classesDirs + sourceSets.test.output.classesDirs).asPath}",
'--module-path', files(MODULE_COMPILE_PATH).asPath
]
classpath = files()
}
Expand All @@ -123,7 +123,7 @@ task testJar(type: Jar, dependsOn: [ testClasses, compileTest9 ] ) {

setArchiveClassifier 'tests'
// ignore second module-info.class from main
duplicatesStrategy = 'exclude'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

from sourceSets.test.output + sourceSets.main.output

Expand Down
50 changes: 25 additions & 25 deletions poi-ooxml-full/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ compileJava {
options.forkOptions.jvmArgs += '-Xmx2G'
}

task compileJava9(type: JavaCompile) {
tasks.register('compileJava9', JavaCompile) {
dependsOn 'compileJava'

javaCompiler = javaToolchains.compilerFor {
Expand All @@ -66,24 +66,24 @@ task compileJava9(type: JavaCompile) {
source = file(JAVA9_SRC)
classpath = files()
options.compilerArgs = [
'--patch-module', "${MODULE_NAME}=${sourceSets.main.output.asPath}",
'--module-path', files(MAIN_MODULE_PATH).asPath
'--patch-module', "${MODULE_NAME}=${sourceSets.main.output.asPath}",
'--module-path', files(MAIN_MODULE_PATH).asPath
]
}

task copy_xsds(type: Copy) {
from ('src/main/xmlschema/org/apache/poi/xdgf')
from ('src/main/xmlschema/org/apache/poi/schemas') {
tasks.register('copy_xsds', Copy) {
from('src/main/xmlschema/org/apache/poi/xdgf')
from('src/main/xmlschema/org/apache/poi/schemas') {
include 'XAdES*.xsd', '*.xsdconfig', 'xmldsig*.xsd', 'ooxmlSchemas.xsdconfig', 'markup-compatibility.xsd',
'vmlDrawing.xsd', 'word10.xsd', 'word12.xsd', 'xlThreaded*.xsd', 'dml-drawing.xsd', 'drawing-chart2012.xsd',
'chartEx.xsd'
exclude '*.zip'
}
from ('src/main/xmlschema/org/apache/poi/poifs/crypt') {
from('src/main/xmlschema/org/apache/poi/poifs/crypt') {
include 'signatureInfo.xsd'
}
from (zipTree('src/main/xmlschema/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip'))
from (zipTree('src/main/xmlschema/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip')) {
from(zipTree('src/main/xmlschema/org/apache/poi/schemas/OfficeOpenXML-XMLSchema-Transitional.zip'))
from(zipTree('src/main/xmlschema/org/apache/poi/schemas/OpenPackagingConventions-XMLSchema.zip')) {
include 'opc-digSig.xsd', 'opc-relationships.xsd'
}
into 'build/xsds'
Expand All @@ -95,38 +95,38 @@ task generate_beans(dependsOn: copy_xsds) {

doLast {
ant.uptodate(
property: 'xmlbeans_uptodate',
targetfile: 'build/generated-resources/org/apache/poi/schemas/ooxml/system/ooxml/TypeSystemHolder.class'
property: 'xmlbeans_uptodate',
targetfile: 'build/generated-resources/org/apache/poi/schemas/ooxml/system/ooxml/TypeSystemHolder.class'
) {
srcFiles(dir: 'build/xsds', includes: '*.xsd')
}

ant.taskdef(
name: 'xmlbean',
classname: 'org.apache.xmlbeans.impl.tool.XMLBean',
classpath: sourceSets.main.runtimeClasspath.asPath
name: 'xmlbean',
classname: 'org.apache.xmlbeans.impl.tool.XMLBean',
classpath: sourceSets.main.runtimeClasspath.asPath
)

if (!ant.properties.xmlbeans_uptodate) {
ant.xmlbean(
schema: 'build/xsds',
srcgendir: BEANS_SRC,
classgendir: BEANS_RES,
destfile: 'build/xsds.jar',
srconly: true,
failonerror: true,
fork: true,
memoryMaximumSize: '1536m',
typesystemname: 'ooxml',
repackage: 'org.apache.xmlbeans.metadata:org.apache.poi.schemas.ooxml'
schema: 'build/xsds',
srcgendir: BEANS_SRC,
classgendir: BEANS_RES,
destfile: 'build/xsds.jar',
srconly: true,
failonerror: true,
fork: true,
memoryMaximumSize: '1536m',
typesystemname: 'ooxml',
repackage: 'org.apache.xmlbeans.metadata:org.apache.poi.schemas.ooxml'
) {
classpath = sourceSets.main.runtimeClasspath.asPath
}
}
}
}

task sourceJar(type: Jar) {
tasks.register('sourceJar', Jar) {
setArchiveClassifier 'sources'
from sourceSets.main.allJava
}
Expand Down
Loading

0 comments on commit 1dbcea4

Please sign in to comment.