@@ -3,6 +3,7 @@ buildscript {
33 dependencies {
44 // used at configuration-time for version info
55 classpath ' org.eclipse.jgit:org.eclipse.jgit:5.7.+'
6+ classpath " javax.inject:javax.inject:1"
67 }
78}
89
@@ -20,9 +21,6 @@ plugins {
2021
2122
2223import de.undercouch.gradle.tasks.download.Download
23- import org.eclipse.jgit.api.Git
24- import org.eclipse.jgit.lib.Constants
25- import org.eclipse.jgit.lib.ObjectId
2624
2725import java.util.regex.Pattern
2826
@@ -42,16 +40,18 @@ jacoco {
4240 toolVersion = " 0.8.13"
4341}
4442
45- jacocoTestReport {
46- dependsOn test
43+ tasks. named(" jacocoTestReport" , JacocoReport ) {
44+ dependsOn(tasks. named(" test" ))
45+
4746 reports { xml. required. set(true ) }
48- afterEvaluate {
49- classDirectories. setFrom(files(classDirectories. files. collect {
50- fileTree(dir : it, exclude : [
51- ' **/ast/**' , ' **/jassAst/**' , ' **/jassIm/**' , ' **/luaAst/**' , ' **/antlr/**'
52- ])
53- }))
54- }
47+
48+ def excluded = [' **/ast/**' , ' **/jassAst/**' , ' **/jassIm/**' , ' **/luaAst/**' , ' **/antlr/**' ]
49+
50+ classDirectories. setFrom(
51+ files(classDirectories. files. collect { dir ->
52+ fileTree(dir : dir, exclude : excluded)
53+ })
54+ )
5555}
5656
5757def genDir = " $projectDir /src-gen"
@@ -120,68 +120,93 @@ def parseqFiles = fileTree(dir: 'parserspec', include: '*.parseq')
120120
121121def pkgPattern = Pattern . compile(/ package\s +(\S +)\s *;/ )
122122
123- tasks . register( ' genAst ' ) {
124- // make it incremental/cacheable
125- inputs . files(parseqFiles)
126- outputs . dir(genDir)
123+ // resolve once at configuration time
124+ def genDirFile = file(genDir)
125+ def astgenCp = configurations . astgen
126+ def pkgPatternLocal = pkgPattern
127127
128- doLast {
129- // fetch ExecOperations from Gradle services (no @Inject needed)
130- ExecOperations execOps = project. services. get(ExecOperations )
128+ def perFileTasks = []
131129
132- parseqFiles. files. each { File f ->
133- String contents = f. getText(' UTF-8' )
134- def m = pkgPattern. matcher(contents)
135- String pkg = m. find() ? m. group(1 ) : " "
136- File targetDir = file(" $genDir /${ pkg.replace('.', '/')} " )
130+ parseqFiles. files. each { File f ->
131+ // determine package at configuration time (same logic you had)
132+ String contents = f. getText(' UTF-8' )
133+ def m = pkgPatternLocal. matcher(contents)
134+ String pkg = m. find() ? m. group(1 ) : " "
135+ File targetDir = new File (genDirFile, pkg. replace(' .' , ' /' ))
137136
138- targetDir. mkdirs()
137+ def t = tasks. register(" genAst_${ f.name.replaceAll(/[^A-Za-z0-9_]/, '_')} " , JavaExec ) {
138+ // incremental + cache correctness for the generator
139+ inputs. file(f)
140+ inputs. files(astgenCp). withPropertyName(" astgenClasspath" )
141+ outputs. dir(targetDir)
139142
140- // run: asg.Main <file> <targetDir> using isolated classpath
141- execOps. javaexec {
142- classpath = configurations. astgen
143- mainClass. set(' asg.Main' )
144- args(f. absolutePath, targetDir. absolutePath)
145- }
146- }
143+ classpath = astgenCp
144+ mainClass. set(" asg.Main" )
145+ args(f. absolutePath, targetDir. absolutePath)
146+
147+ // optional: ensure target dir exists
148+ doFirst { targetDir. mkdirs() }
147149 }
150+
151+ perFileTasks << t
152+ }
153+
154+ tasks. register(" genAst" ) {
155+ inputs. files(parseqFiles)
156+ outputs. dir(genDirFile)
157+ dependsOn(perFileTasks)
148158}
149159
160+
161+
150162/* * -------- Version info file generation -------- */
151163
152164tasks. register(' versionInfoFile' ) {
153165 description " Generates a file CompileTimeInfo.java with version number etc."
154166
155- // resolve git info at configuration time
156- Git git = Git . open(new File (rootProject. projectDir, ' ..' ))
157- ObjectId head = git. getRepository(). resolve(Constants . HEAD )
158- String gitRevision = head. abbreviate(8 ). name()
159- String gitRevisionlong = head. getName()
160- String tag = git. describe(). setTarget(head). setAlways(true ). setTags(true ). call()
161- String wurstVersion = " ${ version} -${ tag} "
162-
163- inputs. property(" wurstVersion" , wurstVersion)
167+ def repoDir = new File (rootProject. projectDir, ' ..' )
164168
165169 def dir = new File (" $genDir /de/peeeq/wurstscript/" )
166170 def out = new File (dir, ' CompileTimeInfo.java' )
167171 outputs. file(out)
168172
173+ // capture at configuration time (no Task.project usage later)
174+ def versionString = project. version. toString()
175+
176+ // Inputs so the task reruns when metadata changes:
177+ // - project version changes
178+ inputs. property(" projectVersion" , versionString)
179+ // - HEAD changes (branch updates)
180+ inputs. file(new File (repoDir, " .git/HEAD" )). withPropertyName(" gitHeadRef" )
181+ // - branch ref changes (only for branch-based HEAD; harmless if missing)
182+ inputs. files(fileTree(new File (repoDir, " .git/refs" ))). withPropertyName(" gitRefs" )
183+ // - tags move / new tags (for git describe --tags)
184+ inputs. files(fileTree(new File (repoDir, " .git/refs/tags" ))). withPropertyName(" gitTags" )
185+ // - working tree dirtiness affects "--dirty"
186+ inputs. file(new File (repoDir, " .git/index" )). optional(). withPropertyName(" gitIndex" )
187+
169188 doLast {
189+ def rev8 = [" git" , " rev-parse" , " --short=8" , " HEAD" ]. execute(null , repoDir). text. trim()
190+ def revLong = [" git" , " rev-parse" , " HEAD" ]. execute(null , repoDir). text. trim()
191+ def tag = [" git" , " describe" , " --tags" , " --always" , " --dirty" ]. execute(null , repoDir). text. trim()
192+
193+ def wurstVersion = " ${ versionString} -${ tag} "
194+
170195 dir. mkdirs()
171- String currentTime = new Date (). format(" yyyy/MM/dd KK:mm:ss" )
172196 out. text = """
173- package de.peeeq.wurstscript;
197+ package de.peeeq.wurstscript;
174198
175- public class CompileTimeInfo {
176- public static final String time="${ currentTime} ";
177- public static final String revision="${ gitRevision} ";
178- public static final String revisionLong="${ gitRevisionlong} ";
179- public static final String version="${ wurstVersion} ";
180- }
181- """
199+ public class CompileTimeInfo {
200+ public static final String revision="${ rev8} ";
201+ public static final String revisionLong="${ revLong} ";
202+ public static final String version="${ wurstVersion} ";
203+ }
204+ """
182205 }
183206}
184207
208+
209+
185210/* * -------- Aggregate generation + wiring into compile -------- */
186211
187212tasks. register(' gen' ) {
@@ -308,5 +333,9 @@ tasks.register('generate_hotdoc') {
308333 }
309334}
310335
336+ tasks. named(" coveralls" ) {
337+ notCompatibleWithConfigurationCache(" coveralls plugin task uses Project at execution time" )
338+ }
339+
311340/* * -------- Apply deployment settings -------- */
312341apply from : ' deploy.gradle'
0 commit comments