@@ -20,9 +20,10 @@ dependencies {
2020
2121import com.github.eerohele.DitaOtTask
2222import com.github.eerohele.SaxonXsltTask
23+ import org.gradle.process.ExecOperations
2324
2425def getPropertyOrDefault (String name , def defaultValue ) {
25- hasProperty (name) ? findProperty(name) : defaultValue
26+ providers . gradleProperty (name). getOrElse( defaultValue)
2627}
2728
2829String ditaHome = getPropertyOrDefault(' ditaHome' , projectDir. getParent())
@@ -62,23 +63,25 @@ task extensionPoints(type: SaxonXsltTask) {
6263}
6364
6465task generatePlatformFilter {
65- ant. condition(property : ' platform' , value : ' windows' ) {
66- os(family : ' windows' )
67- }
68-
69- ant. condition(property : ' platform' , value : ' mac' ) {
70- os(family : ' mac' )
71- }
66+ def outputFile = layout. projectDirectory. file(ditavalFile)
67+ outputs. file(outputFile)
7268
73- ant. condition(property : ' platform' , value : ' unix' ) {
74- os(family : ' unix' )
75- }
76-
77- ant. echoxml(file : ditavalFile) {
78- val {
79- prop(action : ' include' , att : ' platform' , val : platform)
80- prop(action : ' exclude' , att : ' platform' )
69+ doLast {
70+ // Use Gradle's built-in OS detection instead of Ant
71+ def platformName = ' unix' // default
72+ if (org.gradle.internal.os.OperatingSystem . current(). isWindows()) {
73+ platformName = ' windows'
74+ } else if (org.gradle.internal.os.OperatingSystem . current(). isMacOsX()) {
75+ platformName = ' mac'
8176 }
77+
78+ // Generate the ditaval file using modern Gradle file operations
79+ outputFile. asFile. text = """ <?xml version="1.0" encoding="UTF-8"?>
80+ <val>
81+ <prop action="include" att="platform" val="${ platformName} "/>
82+ <prop action="exclude" att="platform"/>
83+ </val>
84+ """
8285 }
8386}
8487
@@ -89,7 +92,7 @@ task generatePropertiesTemplate(type: SaxonXsltTask) {
8992}
9093
9194task autoGenerate (dependsOn : [messages, params, extensionPoints, generatePlatformFilter, generatePropertiesTemplate]) {
92- description ' Run tasks that generate content from resource files and the build environment.'
95+ description = ' Run tasks that generate content from resource files and the build environment.'
9396}
9497
9598task pdf (type : DitaOtTask , dependsOn : autoGenerate) {
@@ -141,31 +144,40 @@ task htmlhelp(type: DitaOtTask, dependsOn: autoGenerate) {
141144 }
142145
143146 doLast {
144- ant. move(todir : outputDir, failonerror : ' no' ) {
145- fileset(dir : " ${ outputDir} /htmlhelp" , includes : ' *.chm' )
147+ // Move .chm files using modern Gradle file operations
148+ def htmlhelpDir = file(" ${ outputDir} /htmlhelp" )
149+ if (htmlhelpDir. exists()) {
150+ copy {
151+ from htmlhelpDir
152+ into outputDir
153+ include ' *.chm'
154+ }
155+ // Clean up the htmlhelp directory
156+ delete htmlhelpDir
146157 }
147-
148- ant. delete(dir : " ${ outputDir} /htmlhelp" )
149158 }
150159}
151160
152161task cleanUp {
153162 doLast {
154- ant . delete( dir : outputDir)
163+ delete outputDir
155164 }
156165}
157166
158- def commit = new ByteArrayOutputStream ()
167+ // Create a lazy provider for git commit that resolves at task execution time
168+ def gitCommitProvider = providers. exec {
169+ commandLine(' git' , ' rev-parse' , ' HEAD' )
170+ }. standardOutput. asText. map { it. trim() }
159171
160172task gitMetadata {
161- doLast {
162- exec {
163- workingDir = projectDir
164- commandLine ' git'
165- args = [' rev-parse' , ' HEAD' ]
166- standardOutput = commit
173+ // This task ensures git metadata is available when needed by other tasks
174+ doLast {
175+ // Force provider evaluation to ensure git command runs
176+ logger. info(" Git commit: ${ gitCommitProvider.get()} " )
167177 }
168- }
178+
179+ // Mark outputs to help with up-to-date checking
180+ outputs. upToDateWhen { false } // Always run since git commit changes frequently
169181}
170182
171183task site (type : DitaOtTask ) {
@@ -177,11 +189,15 @@ task site(type: DitaOtTask) {
177189
178190 transtype ' org.dita-ot.html'
179191
192+ // Evaluate the noCommitMeta flag at configuration time
193+ def includeCommitMeta = ! providers. gradleProperty(' noCommitMeta' ). map { Boolean . parseBoolean(it) }. getOrElse(false )
194+
180195 properties {
181196 property(name : ' args.gen.task.lbl' , value : ' YES' )
182197 property(name : ' args.rellinks' , value : ' noparent' )
183- if (! (project. hasProperty(' noCommitMeta' ) && Boolean . parseBoolean(project. property(' noCommitMeta' )))) {
184- property(name : ' commit' , value : commit)
198+ if (includeCommitMeta) {
199+ // Resolve the provider to get actual commit hash value
200+ property(name : ' commit' , value : gitCommitProvider. get())
185201 }
186202 }
187203}
0 commit comments