From 0e7251b44571f8edc4642c10a96c3a85a04a3763 Mon Sep 17 00:00:00 2001 From: reger24 Date: Wed, 26 Jan 2022 14:54:18 +0100 Subject: [PATCH] Changed Gradle build regarding prepYaCyProperties to be more reliable The properties contain info from the local git (the last commitDate and the number of commints since last distribution-label +9000) currently Gradle build script must execute external jar (libbuild/GitComInf-All.jar) which creates a property file. other build targets relay on the properties - so here is a currently a timing problem. 1. nice would be we could get rid of the whole gitbuildnumber thing on work with current date etc. Changed it now to create the property file at the end - after a build so during init no external jar execution is required but just reading the prop file. At least a bit more stable. in addition I include it in the repository so that a fresh pime build has it available (even some measure included to use some fake if file is missing) --- build.gradle | 62 +++++++++++++++++++++++++-------------- gitbuildnumber.properties | 7 +++++ 2 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 gitbuildnumber.properties diff --git a/build.gradle b/build.gradle index 22111dda8..0294d2197 100644 --- a/build.gradle +++ b/build.gradle @@ -149,40 +149,39 @@ jar { shadowJar.zip64 = true // saw build error: Execution failed for task ':shadowJar'. shadow.org.apache.tools.zip.Zip64RequiredException: archive contains more than 65535 entries. - -// runs the support tool which creates gitbuildnumber.properties from info of local git repository -task runGitComInf(type: JavaExec) { - classpath = files('libbuild/GitComInf-all.jar') - args = [project.projectDir.getPath(), project.projectDir.getPath() + "/build/tmp/gitbuildnumber.properties"] - mainClass = 'GitComInf' -} - // prepare yacyBuildProperties.java from template (needed after commits or new versions) // read values from property file generated by GitComInf tool import org.apache.tools.ant.filters.ReplaceTokens -task prepYaCyProperties (type: Copy, dependsOn : ['runGitComInf']) { - mustRunAfter runGitComInf +task prepYaCyProperties (type: Copy) { - def propfile = "build/tmp/gitbuildnumber.properties"; + def propfile = "gitbuildnumber.properties"; if (project.file(propfile).exists()) { // must check otherwise any action may stop after clean on this error - file("build/tmp/gitbuildnumber.properties").withReader { + file("gitbuildnumber.properties").withReader { Properties props = new Properties() props.load(it) project.ext.filterTokens.putAll(props) } - } else + } else { // on missing properties file use generic data logger.error("prepYaCyProperties: file " + propfile + " is missing, you should re-run runGitComInf") + Properties props = new Properties() + String Dstr = new Date().format("yyyyMMDD") + String Tstr = new Date().format("yyyyMMDD-HHmmss") + props.put("branch","-dev") + props.put ("DSTAMP",Dstr ) + props.put ("REPL_DATE",Dstr) + props.put ("REPL_REVISION_NR",Tstr) + props.put ("releaseNr",Tstr) + project.ext.filterTokens.putAll(props) + } String fdirname = sourceSets.main.java.srcDirs[0].name + '/net/yacy/peers/operation' - copy { - from fdirname - include('yacyBuildProperties.java.template') - rename 'yacyBuildProperties.java.template', 'yacyBuildProperties.java' - into (fdirname) - - filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: project.ext.filterTokens) - filter(ReplaceTokens, tokens: [REPL_VERSION: version, REPL_PKGMANAGER:"false", REPL_RESTARTCMD: "/etc/init.d/yacy restart"]) // gradle.project.version + some defaults from ant - } + from fdirname + include('yacyBuildProperties.java.template') + rename 'yacyBuildProperties.java.template', 'yacyBuildProperties.java' + filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: project.ext.filterTokens) + filter(ReplaceTokens, tokens: [REPL_VERSION: version, REPL_PKGMANAGER:"false", REPL_RESTARTCMD: "/etc/init.d/yacy restart"]) // gradle.project.version + some defaults from ant + into (fdirname) + } compileJava.dependsOn(prepYaCyProperties) // must be executed before compile (due to source template filtering) @@ -448,3 +447,22 @@ task distWinInstaller (dependsOn:['copyFilesToDistDir','copyDependenciesForDistr tasks.findByName('createInstaller').mustRunAfter 'prepNsis' } +// runs the support tool which creates gitbuildnumber.properties from info of local git repository +task storeGitComInf(type: JavaExec) { + mustRunAfter(build) + classpath = files('libbuild/GitComInf-all.jar') + args = [project.projectDir.getPath(), project.projectDir.getPath() + "/gitbuildnumber.properties"] + mainClass = 'GitComInf' +} + +//--- build aliases : define a synonym here if you want a shortcut to run multiple targets +// workaround to run storeGitComInf after a build without adding arbitray dependencies +// this makes sure gitbuildnumber.properties is availabel and up-to-date +def buildAliases = [ + 'build' : ['build','storeGitComInf'] + ] +def expandedTaskList = [] +gradle.startParameter.taskNames.each { + expandedTaskList << (buildAliases[it] ? buildAliases[it] : it) +} +gradle.startParameter.taskNames = expandedTaskList.flatten() \ No newline at end of file diff --git a/gitbuildnumber.properties b/gitbuildnumber.properties new file mode 100644 index 000000000..05ee0c4c8 --- /dev/null +++ b/gitbuildnumber.properties @@ -0,0 +1,7 @@ +# +#Wed Jan 26 14:44:44 CET 2022 +DSTAMP=20220126 +branch= +REPL_REVISION_NR=10210 +releaseNr=10210 +REPL_DATE=20220126