| @@ -1,2 +1,2 | |||||
| 1 | group=org.implab.gradle | 
             | 
        1 | group=org.implab.gradle | |
| 2 | version=1.1 No newline at end of file | 
             | 
        2 | version=1.1.1 No newline at end of file | |
| @@ -1,94 +1,156 | |||||
| 1 | package org.implab.gradle.containers; | 
             | 
        1 | package org.implab.gradle.containers; | |
| 2 | 
             | 
        2 | |||
| 3 | import java.util.Optional; | 
             | 
        3 | import java.util.Optional; | |
| 4 | 
             | 
        4 | |||
| 5 | import org.gradle.api.Project; | 
             | 
        5 | import org.gradle.api.Project; | |
| 
             | 
        6 | import org.gradle.api.file.Directory; | |||
| 6 | import org.gradle.api.file.DirectoryProperty; | 
             | 
        7 | import org.gradle.api.file.DirectoryProperty; | |
| 7 | import org.gradle.api.file.ProjectLayout; | 
             | 
        8 | import org.gradle.api.file.ProjectLayout; | |
| 
             | 
        9 | import org.gradle.api.file.RegularFile; | |||
| 8 | import org.gradle.api.file.RegularFileProperty; | 
             | 
        10 | import org.gradle.api.file.RegularFileProperty; | |
| 9 | import org.gradle.api.model.ObjectFactory; | 
             | 
        11 | import org.gradle.api.model.ObjectFactory; | |
| 10 | import org.gradle.api.provider.Property; | 
             | 
        12 | import org.gradle.api.provider.Property; | |
| 11 | import org.gradle.api.provider.Provider; | 
             | 
        13 | import org.gradle.api.provider.Provider; | |
| 12 | 
             | 
        14 | |||
| 13 | public class ContainerExtension { | 
             | 
        15 | public class ContainerExtension { | |
| 14 | 
             | 
        16 | |||
| 15 | private final Property<String> cliCmd; | 
             | 
        17 | private final Property<String> cliCmd; | |
| 16 | 
             | 
        18 | |||
| 17 | private final Property<String> imageAuthority; | 
             | 
        19 | private final Property<String> imageAuthority; | |
| 18 | 
             | 
        20 | |||
| 19 | private final Property<String> imageGroup; | 
             | 
        21 | private final Property<String> imageGroup; | |
| 20 | 
             | 
        22 | |||
| 21 | private final Property<String> imageShortName; | 
             | 
        23 | private final Property<String> imageShortName; | |
| 22 | 
             | 
        24 | |||
| 23 | private final Property<String> imageTag; | 
             | 
        25 | private final Property<String> imageTag; | |
| 24 | 
             | 
        26 | |||
| 25 | private final Property<ImageName> imageName; | 
             | 
        27 | private final Property<ImageName> imageName; | |
| 26 | 
             | 
        28 | |||
| 27 | private final DirectoryProperty contextDir; | 
             | 
        29 | private final DirectoryProperty contextDir; | |
| 28 | 
             | 
        30 | |||
| 29 | private final RegularFileProperty imageIdFile; | 
             | 
        31 | private final RegularFileProperty imageIdFile; | |
| 30 | 
             | 
        32 | |||
| 31 | public ContainerExtension(ObjectFactory factory, ProjectLayout layout, Project project) { | 
             | 
        33 | public ContainerExtension(ObjectFactory factory, ProjectLayout layout, Project project) { | |
| 32 | contextDir = factory.directoryProperty(); | 
             | 
        34 | contextDir = factory.directoryProperty(); | |
| 33 | contextDir.convention(layout.getBuildDirectory().dir("context")); | 
             | 
        35 | contextDir.convention(layout.getBuildDirectory().dir("context")); | |
| 34 | 
             | 
        36 | |||
| 35 | imageIdFile = factory.fileProperty(); | 
             | 
        37 | imageIdFile = factory.fileProperty(); | |
| 36 | imageIdFile.convention(layout.getBuildDirectory().file("imageId")); | 
             | 
        38 | imageIdFile.convention(layout.getBuildDirectory().file("imageId")); | |
| 37 | 
             | 
        39 | |||
| 38 | cliCmd = factory.property(String.class); | 
             | 
        40 | cliCmd = factory.property(String.class); | |
| 39 | cliCmd.set("docker"); | 
             | 
        41 | cliCmd.set("docker"); | |
| 40 | 
             | 
        42 | |||
| 41 | imageAuthority = factory.property(String.class); | 
             | 
        43 | imageAuthority = factory.property(String.class); | |
| 42 | imageGroup = factory.property(String.class); | 
             | 
        44 | imageGroup = factory.property(String.class); | |
| 43 | imageShortName = factory.property(String.class); | 
             | 
        45 | imageShortName = factory.property(String.class); | |
| 44 | 
             | 
        46 | |||
| 45 | imageShortName.convention(project.getName()); | 
             | 
        47 | imageShortName.convention(project.getName()); | |
| 46 | 
             | 
        48 | |||
| 47 | imageTag = factory.property(String.class); | 
             | 
        49 | imageTag = factory.property(String.class); | |
| 48 | imageTag.set(project | 
             | 
        50 | imageTag.set(project | |
| 49 | .provider(() -> Optional.ofNullable(project.getVersion()).map(v -> v.toString()).orElse("latest"))); | 
             | 
        51 | .provider(() -> Optional.ofNullable(project.getVersion()).map(v -> v.toString()).orElse("latest"))); | |
| 50 | 
             | 
        52 | |||
| 51 | Provider<String> imageRepository = imageGroup.map(g -> g + "/" + imageShortName.get()).orElse(imageShortName); | 
             | 
        53 | Provider<String> imageRepository = imageGroup.map(g -> g + "/" + imageShortName.get()).orElse(imageShortName); | |
| 52 | 
             | 
        54 | |||
| 53 | imageName = factory.property(ImageName.class); | 
             | 
        55 | imageName = factory.property(ImageName.class); | |
| 54 | imageName.convention(project.provider( | 
             | 
        56 | imageName.convention(project.provider( | |
| 55 | () -> new ImageName().authority(imageAuthority.get()).name(imageRepository.get()).tag(imageTag.get()))); | 
             | 
        57 | () -> new ImageName().authority(imageAuthority.get()).name(imageRepository.get()).tag(imageTag.get()))); | |
| 56 | } | 
             | 
        58 | } | |
| 57 | 
             | 
        59 | |||
| 58 | public Property<String> getCliCmd() { | 
             | 
        60 | public Property<String> getCliCmd() { | |
| 59 | return cliCmd; | 
             | 
        61 | return cliCmd; | |
| 60 | } | 
             | 
        62 | } | |
| 61 | 
             | 
        63 | |||
| 62 | public void setCliCmd(String cliCmd) { | 
             | 
        64 | public void setCliCmd(String cliCmd) { | |
| 63 | this.cliCmd.set(cliCmd); | 
             | 
        65 | this.cliCmd.set(cliCmd); | |
| 64 | } | 
             | 
        66 | } | |
| 65 | 
             | 
        67 | |||
| 66 | public DirectoryProperty getContextDirectory() { | 
             | 
        68 | public DirectoryProperty getContextDirectory() { | |
| 67 | return contextDir; | 
             | 
        69 | return contextDir; | |
| 68 | } | 
             | 
        70 | } | |
| 69 | 
             | 
        71 | |||
| 
             | 
        72 | public void setContextDirectory(Directory dir) { | |||
| 
             | 
        73 | contextDir.set(dir); | |||
| 
             | 
        74 | } | |||
| 
             | 
        75 | ||||
| 
             | 
        76 | public void setContextDirectory(Provider<Directory> dir) { | |||
| 
             | 
        77 | contextDir.set(dir); | |||
| 
             | 
        78 | } | |||
| 
             | 
        79 | ||||
| 70 | public RegularFileProperty getImageIdFile() { | 
             | 
        80 | public RegularFileProperty getImageIdFile() { | |
| 71 | return imageIdFile; | 
             | 
        81 | return imageIdFile; | |
| 72 | } | 
             | 
        82 | } | |
| 73 | 
             | 
        83 | |||
| 
             | 
        84 | public void setImageIdFile(RegularFile file) { | |||
| 
             | 
        85 | imageIdFile.set(file); | |||
| 
             | 
        86 | } | |||
| 
             | 
        87 | ||||
| 
             | 
        88 | public void setImageIdFile(Provider<RegularFile> file) { | |||
| 
             | 
        89 | imageIdFile.set(file); | |||
| 
             | 
        90 | } | |||
| 
             | 
        91 | ||||
| 74 | public Property<String> getImageAuthority() { | 
             | 
        92 | public Property<String> getImageAuthority() { | |
| 75 | return imageAuthority; | 
             | 
        93 | return imageAuthority; | |
| 76 | } | 
             | 
        94 | } | |
| 77 | 
             | 
        95 | |||
| 
             | 
        96 | public void setImageAuthority(String value) { | |||
| 
             | 
        97 | imageAuthority.set(value); | |||
| 
             | 
        98 | } | |||
| 
             | 
        99 | ||||
| 
             | 
        100 | public void setImageAuthority(Provider<String> value) { | |||
| 
             | 
        101 | imageAuthority.set(value); | |||
| 
             | 
        102 | } | |||
| 
             | 
        103 | ||||
| 78 | public Property<String> getImageGroup() { | 
             | 
        104 | public Property<String> getImageGroup() { | |
| 79 | return imageGroup; | 
             | 
        105 | return imageGroup; | |
| 80 | } | 
             | 
        106 | } | |
| 81 | 
             | 
        107 | |||
| 
             | 
        108 | public void setImageGroup(String value) { | |||
| 
             | 
        109 | imageGroup.set(value); | |||
| 
             | 
        110 | } | |||
| 
             | 
        111 | ||||
| 
             | 
        112 | public void setImageGroup(Provider<String> value) { | |||
| 
             | 
        113 | imageGroup.set(value); | |||
| 
             | 
        114 | } | |||
| 
             | 
        115 | ||||
| 82 | public Property<ImageName> getImageName() { | 
             | 
        116 | public Property<ImageName> getImageName() { | |
| 83 | return imageName; | 
             | 
        117 | return imageName; | |
| 84 | } | 
             | 
        118 | } | |
| 85 | 
             | 
        119 | |||
| 
             | 
        120 | public void setImageName(ImageName name) { | |||
| 
             | 
        121 | imageName.set(name); | |||
| 
             | 
        122 | } | |||
| 
             | 
        123 | ||||
| 
             | 
        124 | public void setImageName(Provider<ImageName> name) { | |||
| 
             | 
        125 | imageName.set(name); | |||
| 
             | 
        126 | } | |||
| 
             | 
        127 | ||||
| 86 | public Property<String> getImageShortName() { | 
             | 
        128 | public Property<String> getImageShortName() { | |
| 87 | return imageShortName; | 
             | 
        129 | return imageShortName; | |
| 88 | } | 
             | 
        130 | } | |
| 89 | 
             | 
        131 | |||
| 
             | 
        132 | public void setImageShortName(String name) { | |||
| 
             | 
        133 | imageShortName.set(name); | |||
| 
             | 
        134 | } | |||
| 
             | 
        135 | ||||
| 
             | 
        136 | public void setImageShortName(Provider<String> name) { | |||
| 
             | 
        137 | imageShortName.set(name); | |||
| 
             | 
        138 | } | |||
| 
             | 
        139 | ||||
| 
             | 
        140 | public Property<String> getImageTag() { | |||
| 
             | 
        141 | return imageTag; | |||
| 
             | 
        142 | } | |||
| 
             | 
        143 | ||||
| 
             | 
        144 | public void setImageTag(String tag) { | |||
| 
             | 
        145 | imageTag.set(tag); | |||
| 
             | 
        146 | } | |||
| 
             | 
        147 | ||||
| 
             | 
        148 | public void setImageTag(Provider<String> tag) { | |||
| 
             | 
        149 | imageTag.set(tag); | |||
| 
             | 
        150 | } | |||
| 
             | 
        151 | ||||
| 90 | public ImageName createImageName() { | 
             | 
        152 | public ImageName createImageName() { | |
| 91 | return new ImageName(); | 
             | 
        153 | return new ImageName(); | |
| 92 | } | 
             | 
        154 | } | |
| 93 | 
             | 
        155 | |||
| 94 | } No newline at end of file | 
             | 
        156 | } | |
        
        General Comments 0
    
    
  
  
                      You need to be logged in to leave comments.
                      Login now
                    
                