@@ -22,7 +22,7 @@ plugins {
2222def app = project(' :app' )
2323
2424// Central location for application version
25- project. version = ' 5.7.1 '
25+ project. version = ' 5.8.0 '
2626println " version: ${ project.version} "
2727
2828// Central location for the specific versions of tesseract dependencies
@@ -195,6 +195,12 @@ sourceSets {
195195 }
196196}
197197
198+ test {
199+ // Test classes not meant for Junit
200+ exclude ' **/org/audiveris/omr/jaxb/basic/**'
201+ exclude ' **/org/audiveris/omr/jaxb/facade/**'
202+ }
203+
198204// -------
199205// Tasks
200206// -------
@@ -270,54 +276,79 @@ jar {
270276 }
271277}
272278
273- // Retrieve the full hash for the latest commit from Git
279+ // Retrieve hash of the latest commit from Git
280+ // Output is in 'app.ext.commit' property
274281tasks. register(' getCommit' , Exec ) {
275- description = " Retrieves full hash of git latest commit"
276- outputs . file( " build/ commit.txt " )
277- commandLine = " git rev-parse HEAD " . split(' ' )
282+ description = " Retrieves hash of git latest commit"
283+ // NOTA: We exclude the folder '<root>/flatpak/flathub' from this commit retrieval
284+ commandLine = " git log -n1 --pretty=%H -- :^../flatpak/flathub " . split(' ' )
278285 standardOutput = new ByteArrayOutputStream ()
279286
280287 doLast {
281288 def commit = standardOutput. toString(). replaceAll(' \n ' , ' ' )
282- println " commit: ${ commit} "
289+ println " app. New commit: ${ commit} "
283290 app. ext. commit = commit
284-
285- def commitFile = file(" build/commit.txt" )
286- commitFile. text = commit
287291 }
288292}
289293
290- // Retrieve the short hash for the latest commit from Git
291- tasks. register(' getCommitShort' , Exec ) {
292- description = " Retrieves short hash of git latest commit"
293- outputs. file(" build/commitShort.txt" )
294+ tasks. register(' createBuildFolder' ) {
295+ description = " Make sure the 'build' folder exists"
296+ doLast {
297+ def dir = file(' build' )
298+ if (! dir. exists()) {
299+ dir. mkdirs()
300+ println " app. Directory created: ${ dir} "
301+ } else {
302+ println " app. Directory already exists: ${ dir} "
303+ }
304+ }
305+ }
294306
295- commandLine = " git rev-parse --short HEAD" . split(' ' )
296- standardOutput = new ByteArrayOutputStream ()
307+ // Compare commit with the one used for the generation of ProgramId Java class
308+ tasks. register(' checkCommit' ) {
309+ dependsOn ' getCommit'
310+ dependsOn ' createBuildFolder'
297311
298312 doLast {
299- def commitShort = standardOutput. toString(). replaceAll(' \n ' , ' ' )
300- println " commitShort: ${ commitShort} "
313+ def cache = file(" build/commit.properties" )
314+
315+ if (cache. exists()) {
316+ def props = new Properties ()
317+ cache. withInputStream { props. load(it) }
318+ app. ext. oldCommit = props. getProperty(' commit' )
319+ println " app. Old commit: ${ app.ext.oldCommit} "
320+ if (! app. ext. oldCommit. equals(app. ext. commit)) {
321+ app. ext. commitChanged = ' true'
322+ }
323+ } else {
324+ println " app. No old commit"
325+ app. ext. commitChanged = ' true'
326+ }
327+
328+ if (project. hasProperty(' commitChanged' )) {
329+ // Save the new value
330+ def properties = new Properties ()
331+ properties. setProperty(' commit' , app. ext. commit)
332+
333+ cache. withOutputStream { out ->
334+ properties. store(out, ' Last commit value' )
335+ }
301336
302- def commitShortFile = file( " build/commitShort.txt " )
303- commitShortFile . text = commitShort
337+ println " app. Properties written to disk: ${ cache } "
338+ }
304339 }
305340}
306341
307342// Generate a 'ProgramId.java' source file, based on Git data
308343tasks. register(' generateProgramId' ) {
309344 group = " build"
310345 description = " Generates the ProgramId source"
311- dependsOn ' getCommit'
312- dependsOn ' getCommitShort'
313-
314- inputs. file(" build/commit.txt" )
315- inputs. file(" build/commitShort.txt" )
346+ dependsOn ' checkCommit'
347+ onlyIf { project. hasProperty(' commitChanged' ) }
316348
317349 def outputDir = file(" build/generated-src/org/audiveris/omr" )
318350 def className = " ProgramId"
319351 def gSrc = new File (outputDir, " ${ className} .java" )
320- outputs. file(gSrc)
321352
322353 doLast {
323354 outputDir. exists() || outputDir. mkdirs()
@@ -326,7 +357,7 @@ tasks.register('generateProgramId') {
326357 gSrc. append(" * This code has been automatically generated by Gradle.\n */\n " )
327358 gSrc. append(" public abstract class $className {" )
328359
329- app. ext. programBuild = file( ' build/commitShort.txt ' ) . text . trim()
360+ app. ext. programBuild = app . ext . commit
330361 [" company_name" , " company_id" , " program_name" , " program_id" , " program_version" , " program_build" , " tessdata_tag" ]. each { str ->
331362 def strParts = str. split(" _" )
332363 def propName = strParts[0 ] + strParts[1 ]. capitalize()
@@ -335,6 +366,8 @@ tasks.register('generateProgramId') {
335366 }
336367
337368 gSrc. append(" }\n " )
369+
370+ println " app. Java class ProgramId generated"
338371 }
339372}
340373compileJava. dependsOn(' generateProgramId' )
0 commit comments