MavenBuildOutputTimestamp Class — spring-boot Architecture
Architecture documentation for the MavenBuildOutputTimestamp class in MavenBuildOutputTimestamp.java from the spring-boot codebase.
Entity Profile
Source Code
build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/MavenBuildOutputTimestamp.java lines 41–111
class MavenBuildOutputTimestamp {
private static final Instant DATE_MIN = Instant.parse("1980-01-01T00:00:02Z");
private static final Instant DATE_MAX = Instant.parse("2099-12-31T23:59:59Z");
private final @Nullable String timestamp;
/**
* Creates a new {@link MavenBuildOutputTimestamp}.
* @param timestamp timestamp or {@code null}
*/
MavenBuildOutputTimestamp(@Nullable String timestamp) {
this.timestamp = timestamp;
}
/**
* Returns the parsed timestamp as an {@code FileTime}.
* @return the parsed timestamp as an {@code FileTime}, or {@code null}
* @throws IllegalArgumentException if the outputTimestamp is neither ISO 8601 nor an
* integer, or it's not within the valid range 1980-01-01T00:00:02Z to
* 2099-12-31T23:59:59Z
*/
@Nullable FileTime toFileTime() {
Instant instant = toInstant();
if (instant == null) {
return null;
}
return FileTime.from(instant);
}
/**
* Returns the parsed timestamp as an {@code Instant}.
* @return the parsed timestamp as an {@code Instant}, or {@code null}
* @throws IllegalArgumentException if the outputTimestamp is neither ISO 8601 nor an
* integer, or it's not within the valid range 1980-01-01T00:00:02Z to
* 2099-12-31T23:59:59Z
*/
@Nullable Instant toInstant() {
if (!StringUtils.hasLength(this.timestamp)) {
return null;
}
if (isNumeric(this.timestamp)) {
return Instant.ofEpochSecond(Long.parseLong(this.timestamp));
}
if (this.timestamp.length() < 2) {
return null;
}
try {
Instant instant = OffsetDateTime.parse(this.timestamp).withOffsetSameInstant(ZoneOffset.UTC).toInstant();
if (instant.isBefore(DATE_MIN) || instant.isAfter(DATE_MAX)) {
throw new IllegalArgumentException(
String.format("'%s' is not within the valid range %s to %s", instant, DATE_MIN, DATE_MAX));
}
return instant;
}
catch (DateTimeParseException pe) {
throw new IllegalArgumentException(String.format("Can't parse '%s' to instant", this.timestamp));
}
}
private static boolean isNumeric(String str) {
for (char c : str.toCharArray()) {
if (!Character.isDigit(c)) {
return false;
}
}
return true;
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free