ImageReference Class — spring-boot Architecture
Architecture documentation for the ImageReference class in ImageReference.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/core/ImageReference.java lines 33–174
public final class ImageReference {
private final ImageName name;
private final @Nullable String tag;
private final @Nullable String digest;
private final String string;
private ImageReference(ImageName name, @Nullable String tag, @Nullable String digest) {
Assert.notNull(name, "'name' must not be null");
this.name = name;
this.tag = tag;
this.digest = digest;
this.string = buildString(name.toString(), tag, digest);
}
/**
* Return the domain for this image name.
* @return the domain
* @see ImageName#getDomain()
*/
public String getDomain() {
return this.name.getDomain();
}
/**
* Return the name of this image.
* @return the image name
* @see ImageName#getName()
*/
public String getName() {
return this.name.getName();
}
/**
* Return the tag from the reference or {@code null}.
* @return the referenced tag
*/
public @Nullable String getTag() {
return this.tag;
}
/**
* Return the digest from the reference or {@code null}.
* @return the referenced digest
*/
public @Nullable String getDigest() {
return this.digest;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
ImageReference other = (ImageReference) obj;
boolean result = true;
result = result && this.name.equals(other.name);
result = result && ObjectUtils.nullSafeEquals(this.tag, other.tag);
result = result && ObjectUtils.nullSafeEquals(this.digest, other.digest);
return result;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + this.name.hashCode();
result = prime * result + ObjectUtils.nullSafeHashCode(this.tag);
result = prime * result + ObjectUtils.nullSafeHashCode(this.digest);
return result;
}
@Override
public String toString() {
return this.string;
}
private String buildString(String name, @Nullable String tag, @Nullable String digest) {
StringBuilder string = new StringBuilder(name);
if (tag != null) {
string.append(":").append(tag);
}
if (digest != null) {
string.append("@").append(digest);
}
return string.toString();
}
/**
* Create a new {@link ImageReference} from the given value. The following value forms
* can be used:
* <ul>
* <li>{@code name} (maps to {@code docker.io/library/name})</li>
* <li>{@code domain/name}</li>
* <li>{@code domain:port/name}</li>
* <li>{@code domain:port/name:tag}</li>
* <li>{@code domain:port/name@digest}</li>
* </ul>
* @param value the value to parse
* @return an {@link ImageReference} instance
*/
public static ImageReference of(String value) {
Assert.hasText(value, "'value' must not be null");
String domain = ImageName.parseDomain(value);
String path = (domain != null) ? value.substring(domain.length() + 1) : value;
String digest = null;
int digestSplit = path.indexOf("@");
if (digestSplit != -1) {
String remainder = path.substring(digestSplit + 1);
Matcher matcher = Regex.DIGEST.matcher(remainder);
if (matcher.find()) {
digest = remainder.substring(0, matcher.end());
remainder = remainder.substring(matcher.end());
path = path.substring(0, digestSplit) + remainder;
}
}
String tag = null;
int tagSplit = path.lastIndexOf(":");
if (tagSplit != -1) {
String remainder = path.substring(tagSplit + 1);
Matcher matcher = Regex.TAG.matcher(remainder);
if (matcher.find()) {
tag = remainder.substring(0, matcher.end());
remainder = remainder.substring(matcher.end());
path = path.substring(0, tagSplit) + remainder;
}
}
Assert.isTrue(Regex.PATH.matcher(path).matches(),
() -> "'value' path must contain an image reference in the form "
+ "'[domainHost:port/][path/]name[:tag][@digest] "
+ "(with 'path' and 'name' containing only [a-z0-9][.][_][-]) [" + value + "]");
ImageName name = new ImageName(domain, path);
return new ImageReference(name, tag, digest);
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free