|
|
package org.implab.gradle.containers;
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
|
import org.gradle.api.Project;
|
|
|
import org.gradle.api.file.Directory;
|
|
|
import org.gradle.api.file.DirectoryProperty;
|
|
|
import org.gradle.api.file.ProjectLayout;
|
|
|
import org.gradle.api.file.RegularFile;
|
|
|
import org.gradle.api.file.RegularFileProperty;
|
|
|
import org.gradle.api.model.ObjectFactory;
|
|
|
import org.gradle.api.provider.Property;
|
|
|
import org.gradle.api.provider.Provider;
|
|
|
|
|
|
public class ContainerExtension {
|
|
|
|
|
|
private final Property<String> cliCmd;
|
|
|
|
|
|
private final Property<String> imageAuthority;
|
|
|
|
|
|
private final Property<String> imageGroup;
|
|
|
|
|
|
private final Property<String> imageShortName;
|
|
|
|
|
|
private final Property<String> imageTag;
|
|
|
|
|
|
private final Property<ImageName> imageName;
|
|
|
|
|
|
private final DirectoryProperty contextDir;
|
|
|
|
|
|
private final RegularFileProperty imageIdFile;
|
|
|
|
|
|
public ContainerExtension(ObjectFactory factory, ProjectLayout layout, Project project) {
|
|
|
contextDir = factory.directoryProperty();
|
|
|
contextDir.convention(layout.getBuildDirectory().dir("context"));
|
|
|
|
|
|
imageIdFile = factory.fileProperty();
|
|
|
imageIdFile.convention(layout.getBuildDirectory().file("imageId"));
|
|
|
|
|
|
cliCmd = factory.property(String.class);
|
|
|
cliCmd.set("docker");
|
|
|
|
|
|
imageAuthority = factory.property(String.class);
|
|
|
imageGroup = factory.property(String.class);
|
|
|
imageShortName = factory.property(String.class);
|
|
|
|
|
|
imageShortName.convention(project.getName());
|
|
|
|
|
|
imageTag = factory.property(String.class);
|
|
|
imageTag.set(project
|
|
|
.provider(() -> Optional.ofNullable(project.getVersion()).map(v -> v.toString()).orElse("latest")));
|
|
|
|
|
|
Provider<String> imageRepository = imageGroup.map(g -> g + "/" + imageShortName.get()).orElse(imageShortName);
|
|
|
|
|
|
imageName = factory.property(ImageName.class);
|
|
|
imageName.convention(project.provider(
|
|
|
() -> new ImageName().authority(imageAuthority.get()).name(imageRepository.get()).tag(imageTag.get())));
|
|
|
}
|
|
|
|
|
|
public Property<String> getCliCmd() {
|
|
|
return cliCmd;
|
|
|
}
|
|
|
|
|
|
public void setCliCmd(String cliCmd) {
|
|
|
this.cliCmd.set(cliCmd);
|
|
|
}
|
|
|
|
|
|
public DirectoryProperty getContextDirectory() {
|
|
|
return contextDir;
|
|
|
}
|
|
|
|
|
|
public void setContextDirectory(Directory dir) {
|
|
|
contextDir.set(dir);
|
|
|
}
|
|
|
|
|
|
public void setContextDirectory(Provider<Directory> dir) {
|
|
|
contextDir.set(dir);
|
|
|
}
|
|
|
|
|
|
public RegularFileProperty getImageIdFile() {
|
|
|
return imageIdFile;
|
|
|
}
|
|
|
|
|
|
public void setImageIdFile(RegularFile file) {
|
|
|
imageIdFile.set(file);
|
|
|
}
|
|
|
|
|
|
public void setImageIdFile(Provider<RegularFile> file) {
|
|
|
imageIdFile.set(file);
|
|
|
}
|
|
|
|
|
|
public Property<String> getImageAuthority() {
|
|
|
return imageAuthority;
|
|
|
}
|
|
|
|
|
|
public void setImageAuthority(String value) {
|
|
|
imageAuthority.set(value);
|
|
|
}
|
|
|
|
|
|
public void setImageAuthority(Provider<String> value) {
|
|
|
imageAuthority.set(value);
|
|
|
}
|
|
|
|
|
|
public Property<String> getImageGroup() {
|
|
|
return imageGroup;
|
|
|
}
|
|
|
|
|
|
public void setImageGroup(String value) {
|
|
|
imageGroup.set(value);
|
|
|
}
|
|
|
|
|
|
public void setImageGroup(Provider<String> value) {
|
|
|
imageGroup.set(value);
|
|
|
}
|
|
|
|
|
|
public Property<ImageName> getImageName() {
|
|
|
return imageName;
|
|
|
}
|
|
|
|
|
|
public void setImageName(ImageName name) {
|
|
|
imageName.set(name);
|
|
|
}
|
|
|
|
|
|
public void setImageName(Provider<ImageName> name) {
|
|
|
imageName.set(name);
|
|
|
}
|
|
|
|
|
|
public Property<String> getImageShortName() {
|
|
|
return imageShortName;
|
|
|
}
|
|
|
|
|
|
public void setImageShortName(String name) {
|
|
|
imageShortName.set(name);
|
|
|
}
|
|
|
|
|
|
public void setImageShortName(Provider<String> name) {
|
|
|
imageShortName.set(name);
|
|
|
}
|
|
|
|
|
|
public Property<String> getImageTag() {
|
|
|
return imageTag;
|
|
|
}
|
|
|
|
|
|
public void setImageTag(String tag) {
|
|
|
imageTag.set(tag);
|
|
|
}
|
|
|
|
|
|
public void setImageTag(Provider<String> tag) {
|
|
|
imageTag.set(tag);
|
|
|
}
|
|
|
|
|
|
public ImageName createImageName() {
|
|
|
return new ImageName();
|
|
|
}
|
|
|
|
|
|
}
|