@@ -15,7 +15,6 @@ import org.graalvm.internal.tck.ContributionTask
1515import org.graalvm.internal.tck.DockerTask
1616import org.graalvm.internal.tck.ConfigFilesChecker
1717import org.graalvm.internal.tck.DockerUtils
18- import org.graalvm.internal.tck.PullImagesFromFileTask
1918import org.graalvm.internal.tck.ScaffoldTask
2019import org.graalvm.internal.tck.GrypeTask
2120import org.graalvm.internal.tck.TestedVersionUpdaterTask
@@ -47,19 +46,19 @@ def writeGithubOutput(String key, String value) {
4746String coordinateFilter = Objects . requireNonNullElse(project. findProperty(" coordinates" ), " " )
4847
4948// Support fractional batching coordinates in the form "k/n" (e.g., "1/16")
50- boolean isFractionalBatch (String s ) {
49+ static boolean isFractionalBatch (String s ) {
5150 return s != null && (s ==~ / \d +\/\d +/ )
5251}
5352
54- List<Integer > parseFraction (String s ) {
53+ static List<Integer > parseFraction (String s ) {
5554 def m = s =~ / (\d +)\/ (\d +)/
5655 if (! m. matches()) return null
5756 int k = (m[0 ][1 ] as int )
5857 int n = (m[0 ][2 ] as int )
5958 return [k, n]
6059}
6160
62- List<String > computeBatchedCoordinates (List<String > allCoords , int k , int n ) {
61+ static List<String > computeBatchedCoordinates (List<String > allCoords , int k , int n ) {
6362 if (n <= 0 ) throw new GradleException (" Invalid batches denominator: ${ n} " )
6463 if (k < 1 || k > n) throw new GradleException (" Invalid batch index: ${ k} /${ n} " )
6564 def sorted = new ArrayList<String > (allCoords)
@@ -123,76 +122,8 @@ tasks.named("check").configure {
123122
124123final String METADATA_GROUP = " Metadata"
125124
126- Provider<Task > pullAllowedDockerImagesMatching = tasks. register(" pullAllowedDockerImagesMatching" , DefaultTask ) { task ->
127- task. setDescription(" Pull allowed docker images for all matching coordinates" )
128- task. setGroup(METADATA_GROUP )
129- task. doFirst {
130- if (matchingCoordinates == null || matchingCoordinates. isEmpty()) {
131- throw new GradleException (" No matching coordinates found for property 'coordinates'. Provide -Pcoordinates=<filter> or a fractional batch 'k/n'." )
132- }
133- println " Pulling allowed docker images for ${ matchingCoordinates.size()} coordinate(s):"
134- matchingCoordinates. each { c -> println (" - ${ c} " ) }
135- }
136- }
137125
138- // Collect unique required images across matching coordinates and filter by allowed list
139- tasks. register(" collectRequiredAllowedDockerImagesMatching" , DefaultTask ) { task ->
140- task. setDescription(" Collect unique allowed docker images required by matching coordinates into a file" )
141- task. setGroup(METADATA_GROUP )
142- File out = new File (buildDir, " required-docker-images-union.txt" )
143- // Declare the output so Gradle can track it
144- task. outputs. file(out)
145- task. doFirst {
146- if (matchingCoordinates == null || matchingCoordinates. isEmpty()) {
147- throw new GradleException (" No matching coordinates found for property 'coordinates'. Provide -Pcoordinates=<filter> or a fractional batch 'k/n'." )
148- }
149- Set<String > unionRequired = new LinkedHashSet<> ()
150- matchingCoordinates. each { c ->
151- def parts = c. split(" :" )
152- if (parts. length < 3 ) {
153- logger. warn(" Skipping invalid coordinates: ${ c} " )
154- return
155- }
156- def group = parts[0 ]
157- def artifact = parts[1 ]
158- def version = parts[2 ]
159- File f = project. file(" tests/src/${ group} /${ artifact} /${ version} /required-docker-images.txt" )
160- if (f. exists()) {
161- f. readLines()
162- .collect { it?. trim() }
163- .findAll { it && ! it. startsWith(" #" ) }
164- .each { unionRequired. add(it) }
165- }
166- }
167-
168- Set<String > allowed = DockerUtils . getAllAllowedImages()
169- def notAllowed = unionRequired. findAll { ! allowed. contains(it) }
170- if (! notAllowed. isEmpty()) {
171- throw new GradleException (" The following images are not in the allowed list: ${ notAllowed} . " +
172- " If you need them, add Dockerfiles under tests/tck-build-logic/src/main/resources/allowed-docker-images " +
173- " per CONTRIBUTING.md, or adjust required-docker-images.txt files." )
174- }
175126
176- out. parentFile. mkdirs()
177- def finalList = unionRequired. findAll { allowed. contains(it) }. toList()
178- out. text = finalList. join(System . lineSeparator())
179- println " Collected ${ finalList.size()} required allowed image(s):"
180- finalList. each { println (" - ${ it} " ) }
181- }
182- }
183-
184- // Pull the collected unique images (once)
185- tasks. register(" pullRequiredAllowedDockerImagesMatching" , PullImagesFromFileTask . class) { task ->
186- task. setDescription(" Pull unique allowed docker images required by matching coordinates" )
187- task. setGroup(METADATA_GROUP )
188- task. dependsOn(" collectRequiredAllowedDockerImagesMatching" )
189- task. imagesFile. set(new File (buildDir, " required-docker-images-union.txt" ))
190- }
191-
192- // Rewire the aggregate to depend on the unique pull task
193- pullAllowedDockerImagesMatching. configure {
194- dependsOn(" pullRequiredAllowedDockerImagesMatching" )
195- }
196127
197128// Here we want to configure all test and checkstyle tasks for all filtered subprojects
198129for (String coordinates in matchingCoordinates) {
@@ -422,9 +353,50 @@ tasks.register("checkAllowedDockerImages", GrypeTask.class) { task ->
422353 task. setGroup(METADATA_GROUP )
423354}
424355
425- tasks. register(" pullAllowedDockerImages" , DockerTask . class ) { task ->
426- task. setDescription(" Pull allowed docker images from list. " )
356+ tasks. register(" pullAllowedDockerImages" , DefaultTask ) { task ->
357+ task. setDescription(" Pull allowed docker images required by matching coordinates " )
427358 task. setGroup(METADATA_GROUP )
359+ task. doFirst {
360+ if (matchingCoordinates == null || matchingCoordinates. isEmpty()) {
361+ throw new GradleException (" No matching coordinates found for property 'coordinates'. Provide -Pcoordinates=<filter> or a fractional batch 'k/n'." )
362+ }
363+ Set<String > unionRequired = new LinkedHashSet<> ()
364+ matchingCoordinates. each { c ->
365+ def parts = c. split(" :" )
366+ if (parts. length < 3 ) {
367+ logger. warn(" Skipping invalid coordinates: ${ c} " )
368+ return
369+ }
370+ def group = parts[0 ]
371+ def artifact = parts[1 ]
372+ def version = parts[2 ]
373+ File f = project. file(" tests/src/${ group} /${ artifact} /${ version} /required-docker-images.txt" )
374+ if (f. exists()) {
375+ f. readLines()
376+ .collect { it?. trim() }
377+ .findAll { it && ! it. startsWith(" #" ) }
378+ .each { unionRequired. add(it) }
379+ }
380+ }
381+
382+ Set<String > allowed = DockerUtils . getAllAllowedImages()
383+ def notAllowed = unionRequired. findAll { ! allowed. contains(it) }
384+ if (! notAllowed. isEmpty()) {
385+ throw new GradleException (" The following images are not in the allowed list: ${ notAllowed} . " +
386+ " If you need them, add Dockerfiles under tests/tck-build-logic/src/main/resources/allowed-docker-images " +
387+ " per CONTRIBUTING.md, or adjust required-docker-images.txt files." )
388+ }
389+
390+ def finalList = unionRequired. findAll { allowed. contains(it) }. toList()
391+ println " Pulling ${ finalList.size()} required allowed image(s):"
392+ finalList. each { image ->
393+ println (" - ${ image} " )
394+ project. exec { spec ->
395+ spec. setExecutable(" docker" )
396+ spec. args(" pull" , image)
397+ }
398+ }
399+ }
428400}
429401
430402
0 commit comments