@@ -22,7 +22,7 @@ import com.github.eerohele.DitaOtTask
2222import com.github.eerohele.SaxonXsltTask
2323
2424def getPropertyOrDefault (String name , def defaultValue ) {
25- hasProperty (name) ? findProperty(name) : defaultValue
25+ providers . gradleProperty (name). getOrElse( defaultValue)
2626}
2727
2828String ditaHome = getPropertyOrDefault(' ditaHome' , projectDir. getParent())
@@ -62,23 +62,25 @@ task extensionPoints(type: SaxonXsltTask) {
6262}
6363
6464task 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- }
65+ def outputFile = layout. projectDirectory. file(ditavalFile)
66+ outputs. file(outputFile)
7267
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' )
68+ doLast {
69+ // Use Gradle's built-in OS detection instead of Ant
70+ def platformName = ' unix' // default
71+ if (org.gradle.internal.os.OperatingSystem . current(). isWindows()) {
72+ platformName = ' windows'
73+ } else if (org.gradle.internal.os.OperatingSystem . current(). isMacOsX()) {
74+ platformName = ' mac'
8175 }
76+
77+ // Generate the ditaval file using modern Gradle file operations
78+ outputFile. asFile. text = """ <?xml version="1.0" encoding="UTF-8"?>
79+ <val>
80+ <prop action="include" att="platform" val="${ platformName} "/>
81+ <prop action="exclude" att="platform"/>
82+ </val>
83+ """
8284 }
8385}
8486
@@ -89,7 +91,7 @@ task generatePropertiesTemplate(type: SaxonXsltTask) {
8991}
9092
9193task autoGenerate (dependsOn : [messages, params, extensionPoints, generatePlatformFilter, generatePropertiesTemplate]) {
92- description ' Run tasks that generate content from resource files and the build environment.'
94+ description = ' Run tasks that generate content from resource files and the build environment.'
9395}
9496
9597task pdf (type : DitaOtTask , dependsOn : autoGenerate) {
@@ -141,31 +143,39 @@ task htmlhelp(type: DitaOtTask, dependsOn: autoGenerate) {
141143 }
142144
143145 doLast {
144- ant. move(todir : outputDir, failonerror : ' no' ) {
145- fileset(dir : " ${ outputDir} /htmlhelp" , includes : ' *.chm' )
146+ // Move .chm files using modern Gradle file operations
147+ def htmlhelpDir = file(" ${ outputDir} /htmlhelp" )
148+ if (htmlhelpDir. exists()) {
149+ copy {
150+ from htmlhelpDir
151+ into outputDir
152+ include ' *.chm'
153+ }
154+ // Clean up the htmlhelp directory
155+ delete htmlhelpDir
146156 }
147-
148- ant. delete(dir : " ${ outputDir} /htmlhelp" )
149157 }
150158}
151159
152160task cleanUp {
153161 doLast {
154- ant . delete( dir : outputDir)
162+ delete outputDir
155163 }
156164}
157165
158- def commit = new ByteArrayOutputStream ()
166+ // Create a configuration-cache compatible provider for git commit
167+ def gitCommitProvider = providers. exec {
168+ commandLine(' git' , ' rev-parse' , ' HEAD' )
169+ }. standardOutput. asText. map { it. trim() }
159170
160171task gitMetadata {
161- doLast {
162- exec {
163- workingDir = projectDir
164- commandLine ' git'
165- args = [' rev-parse' , ' HEAD' ]
166- standardOutput = commit
172+ // This task is kept for compatibility but git commit is now handled via provider
173+ doLast {
174+ logger. info(" Git commit: ${ gitCommitProvider.get()} " )
167175 }
168- }
176+
177+ // Mark outputs to help with up-to-date checking
178+ outputs. upToDateWhen { false } // Always run since git commit changes frequently
169179}
170180
171181task site (type : DitaOtTask ) {
@@ -177,11 +187,14 @@ task site(type: DitaOtTask) {
177187
178188 transtype ' org.dita-ot.html'
179189
190+ // Evaluate the noCommitMeta flag at configuration time
191+ def includeCommitMeta = ! providers. gradleProperty(' noCommitMeta' ). map { Boolean . parseBoolean(it) }. getOrElse(false )
192+
180193 properties {
181194 property(name : ' args.gen.task.lbl' , value : ' YES' )
182195 property(name : ' args.rellinks' , value : ' noparent' )
183- if (! (project . hasProperty( ' noCommitMeta ' ) && Boolean . parseBoolean(project . property( ' noCommitMeta ' ))) ) {
184- property(name : ' commit' , value : commit )
196+ if (includeCommitMeta ) {
197+ property(name : ' commit' , value : gitCommitProvider )
185198 }
186199 }
187200}
0 commit comments