@@ -8,79 +8,86 @@ import org.gradle.api.provider.Provider
88import java.net.URLEncoder
99import java.nio.charset.StandardCharsets
1010
11- public abstract class ContainerTaskExtension (private val task : Task ) {
12- public fun inputLocalImage (imageReference : String ) {
13- val trackingFile = task.getLocalImageTrackingFile(imageReference)
14- task.inputs.file(trackingFile.map { regularFile ->
15- writeLocalImageId(imageReference, regularFile)
16- regularFile
17- })
18- }
11+ public abstract class ContainerTaskExtension (task : Task ) {
12+ public val inputs: Inputs = Inputs (task)
13+ public val outputs: Outputs = Outputs (task)
1914
20- public fun outputLocalImage ( imageReference : String ) {
21- val trackingFile = task.getLocalImageTrackingFile (imageReference)
22- task.outputs.file(trackingFile.map { regularFile ->
23- writeLocalImageId(imageReference, regularFile)
24- regularFile
25- })
26- task.doLast { writeLocalImageId(imageReference, trackingFile.get()) }
27- }
15+ public class Inputs internal constructor( private val task : Task ) {
16+ public fun localImage (imageReference : String ) {
17+ val trackingFile = task.getLocalImageTrackingFile(imageReference)
18+ task.inputs.file(trackingFile.map { regularFile ->
19+ writeLocalImageId(imageReference, regularFile)
20+ regularFile
21+ })
22+ }
2823
29- public fun inputRegistryImage (imageReference : String , autoRefresh : Boolean = false) {
30- val trackingFile = task.getRegistryImageTrackingFile(imageReference)
31- task.inputs.file(trackingFile.map { regularFile ->
32- if (autoRefresh || ! regularFile.asFile.exists()) {
33- writeRegistryImageDigest(imageReference, regularFile)
34- }
35- regularFile
36- })
24+ public fun registryImage (imageReference : String , autoRefresh : Boolean = false) {
25+ val trackingFile = task.getRegistryImageTrackingFile(imageReference)
26+ task.inputs.file(trackingFile.map { regularFile ->
27+ if (autoRefresh || ! regularFile.asFile.exists()) {
28+ writeRegistryImageDigest(imageReference, regularFile)
29+ }
30+ regularFile
31+ })
32+ }
3733 }
3834
39- public fun outputRegistryImage (imageReference : String , autoRefresh : Boolean = false) {
40- val trackingFile = task.getLocalImageTrackingFile(imageReference)
41- task.outputs.file(trackingFile.map { regularFile ->
42- if (autoRefresh || ! regularFile.asFile.exists()) {
43- writeRegistryImageDigest(imageReference, regularFile)
44- }
45- regularFile
46- })
47- task.doLast {
48- val regularFile = trackingFile.get()
49- if (autoRefresh || ! regularFile.asFile.exists()) {
50- writeRegistryImageDigest(imageReference, regularFile)
35+ public class Outputs internal constructor(private val task : Task ) {
36+ public fun localImage (imageReference : String ) {
37+ val trackingFile = task.getLocalImageTrackingFile(imageReference)
38+ task.outputs.file(trackingFile.map { regularFile ->
39+ writeLocalImageId(imageReference, regularFile)
40+ regularFile
41+ })
42+ task.doLast { writeLocalImageId(imageReference, trackingFile.get()) }
43+ }
44+
45+ public fun registryImage (imageReference : String , autoRefresh : Boolean = false) {
46+ val trackingFile = task.getLocalImageTrackingFile(imageReference)
47+ task.outputs.file(trackingFile.map { regularFile ->
48+ if (autoRefresh || ! regularFile.asFile.exists()) {
49+ writeRegistryImageDigest(imageReference, regularFile)
50+ }
51+ regularFile
52+ })
53+ task.doLast {
54+ val regularFile = trackingFile.get()
55+ if (autoRefresh || ! regularFile.asFile.exists()) {
56+ writeRegistryImageDigest(imageReference, regularFile)
57+ }
5158 }
5259 }
5360 }
61+ }
5462
55- private fun Task.getLocalImageTrackingFile (
56- imageReference : String ,
57- ): Provider <RegularFile > {
58- val fileName = URLEncoder .encode(imageReference, StandardCharsets .UTF_8 )
59- return project.layout.buildDirectory.file(" images/local/$fileName " )
60- }
63+ private fun Task.getLocalImageTrackingFile (
64+ imageReference : String ,
65+ ): Provider <RegularFile > {
66+ val fileName = URLEncoder .encode(imageReference, StandardCharsets .UTF_8 )
67+ return project.layout.buildDirectory.file(" images/local/$fileName " )
68+ }
6169
62- private fun Task.getRegistryImageTrackingFile (
63- imageReference : String ,
64- ): Provider <RegularFile > {
65- val fileName = URLEncoder .encode(imageReference, StandardCharsets .UTF_8 )
66- return project.layout.buildDirectory.file(" images/registry/$fileName " )
67- }
70+ private fun Task.getRegistryImageTrackingFile (
71+ imageReference : String ,
72+ ): Provider <RegularFile > {
73+ val fileName = URLEncoder .encode(imageReference, StandardCharsets .UTF_8 )
74+ return project.layout.buildDirectory.file(" images/registry/$fileName " )
75+ }
6876
69- private fun writeLocalImageId (imageReference : String , regularFile : RegularFile ) {
70- val file = regularFile.asFile
71- if (! file.parentFile.exists()) {
72- file.parentFile.mkdirs()
73- }
74- val imageId = Local .getImageId(imageReference)
75- file.writeText(imageId ? : " " )
77+ private fun writeLocalImageId (imageReference : String , regularFile : RegularFile ) {
78+ val file = regularFile.asFile
79+ if (! file.parentFile.exists()) {
80+ file.parentFile.mkdirs()
7681 }
82+ val imageId = Local .getImageId(imageReference)
83+ file.writeText(imageId ? : " " )
84+ }
7785
78- private fun writeRegistryImageDigest (imageReference : String , regularFile : RegularFile ) {
79- val file = regularFile.asFile
80- if (! file.parentFile.exists()) {
81- file.parentFile.mkdirs()
82- }
83- val imageDigest = Registry .getImageDigest(imageReference)
84- file.writeText(imageDigest ? : " " )
86+ private fun writeRegistryImageDigest (imageReference : String , regularFile : RegularFile ) {
87+ val file = regularFile.asFile
88+ if (! file.parentFile.exists()) {
89+ file.parentFile.mkdirs()
8590 }
91+ val imageDigest = Registry .getImageDigest(imageReference)
92+ file.writeText(imageDigest ? : " " )
8693}
0 commit comments