gnodet commented on code in PR #599:
URL: https://github.com/apache/maven-jar-plugin/pull/599#discussion_r4085883671
##########
src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java:
##########
@@ -270,11 +288,28 @@ protected String getOutputTimestamp() {
for (int i = time.length(); --i >= 0; ) {
char c = time.charAt(i);
if ((c < '0' || c > '9') && (i != 0 || c != '-')) {
+ // Not a plain integer — treat as ISO 8601 and pass through
as-is.
return time;
}
}
+ // Plain integer: convert from seconds to ISO 8601, clamping to
EPOCH_MIN if needed.
try {
- return Instant.ofEpochSecond(Long.parseLong(time)).toString();
+ long seconds = Long.parseLong(time);
+ if (seconds < EPOCH_MIN) {
+ Instant instant = Instant.ofEpochSecond(seconds);
+ log.warn("Output timestamp \""
Review Comment:
Fixed in 416b3b0.
##########
src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java:
##########
@@ -270,11 +288,28 @@ protected String getOutputTimestamp() {
for (int i = time.length(); --i >= 0; ) {
char c = time.charAt(i);
if ((c < '0' || c > '9') && (i != 0 || c != '-')) {
+ // Not a plain integer — treat as ISO 8601 and pass through
as-is.
return time;
}
}
+ // Plain integer: convert from seconds to ISO 8601, clamping to
EPOCH_MIN if needed.
try {
- return Instant.ofEpochSecond(Long.parseLong(time)).toString();
+ long seconds = Long.parseLong(time);
+ if (seconds < EPOCH_MIN) {
+ Instant instant = Instant.ofEpochSecond(seconds);
+ log.warn("Output timestamp \""
+ + time
+ + "\" (resolved to "
+ + instant
+ + ") is before the minimum value accepted by the jar
tool ("
+ + Instant.ofEpochSecond(EPOCH_MIN)
Review Comment:
Fixed in 416b3b0.
##########
src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java:
##########
@@ -270,11 +288,28 @@ protected String getOutputTimestamp() {
for (int i = time.length(); --i >= 0; ) {
char c = time.charAt(i);
if ((c < '0' || c > '9') && (i != 0 || c != '-')) {
+ // Not a plain integer — treat as ISO 8601 and pass through
as-is.
return time;
}
}
+ // Plain integer: convert from seconds to ISO 8601, clamping to
EPOCH_MIN if needed.
try {
- return Instant.ofEpochSecond(Long.parseLong(time)).toString();
+ long seconds = Long.parseLong(time);
+ if (seconds < EPOCH_MIN) {
+ Instant instant = Instant.ofEpochSecond(seconds);
+ log.warn("Output timestamp \""
+ + time
+ + "\" (resolved to "
+ + instant
+ + ") is before the minimum value accepted by the jar
tool ("
+ + Instant.ofEpochSecond(EPOCH_MIN)
+ + "). Clamping to minimum. "
+ + "If you use SOURCE_DATE_EPOCH=0, set it to at least "
+ + EPOCH_MIN
+ + " (1980-01-01T00:00:02Z).");
Review Comment:
Fixed in 416b3b0.
##########
src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java:
##########
@@ -270,11 +288,28 @@ protected String getOutputTimestamp() {
for (int i = time.length(); --i >= 0; ) {
char c = time.charAt(i);
if ((c < '0' || c > '9') && (i != 0 || c != '-')) {
+ // Not a plain integer — treat as ISO 8601 and pass through
as-is.
return time;
}
}
+ // Plain integer: convert from seconds to ISO 8601, clamping to
EPOCH_MIN if needed.
try {
- return Instant.ofEpochSecond(Long.parseLong(time)).toString();
+ long seconds = Long.parseLong(time);
+ if (seconds < EPOCH_MIN) {
+ Instant instant = Instant.ofEpochSecond(seconds);
+ log.warn("Output timestamp \""
+ + time
+ + "\" (resolved to "
+ + instant
+ + ") is before the minimum value accepted by the jar
tool ("
+ + Instant.ofEpochSecond(EPOCH_MIN)
+ + "). Clamping to minimum. "
+ + "If you use SOURCE_DATE_EPOCH=0, set it to at least "
+ + EPOCH_MIN
+ + " (1980-01-01T00:00:02Z).");
+ return Instant.ofEpochSecond(EPOCH_MIN).toString();
Review Comment:
Fixed in 416b3b0.
##########
src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java:
##########
@@ -270,11 +288,28 @@ protected String getOutputTimestamp() {
for (int i = time.length(); --i >= 0; ) {
char c = time.charAt(i);
if ((c < '0' || c > '9') && (i != 0 || c != '-')) {
+ // Not a plain integer — treat as ISO 8601 and pass through
as-is.
return time;
}
}
+ // Plain integer: convert from seconds to ISO 8601, clamping to
EPOCH_MIN if needed.
try {
- return Instant.ofEpochSecond(Long.parseLong(time)).toString();
+ long seconds = Long.parseLong(time);
+ if (seconds < EPOCH_MIN) {
+ Instant instant = Instant.ofEpochSecond(seconds);
+ log.warn("Output timestamp \""
+ + time
+ + "\" (resolved to "
+ + instant
+ + ") is before the minimum value accepted by the jar
tool ("
+ + Instant.ofEpochSecond(EPOCH_MIN)
+ + "). Clamping to minimum. "
+ + "If you use SOURCE_DATE_EPOCH=0, set it to at least "
+ + EPOCH_MIN
+ + " (1980-01-01T00:00:02Z).");
+ return Instant.ofEpochSecond(EPOCH_MIN).toString();
+ }
+ return Instant.ofEpochSecond(seconds).toString();
} catch (NumberFormatException | DateTimeException e) {
throw new MojoException("Timestamp \"" + time + "\" is not a
number of seconds.", e);
Review Comment:
Fixed in 416b3b0.
##########
src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java:
##########
@@ -270,11 +288,28 @@ protected String getOutputTimestamp() {
for (int i = time.length(); --i >= 0; ) {
char c = time.charAt(i);
if ((c < '0' || c > '9') && (i != 0 || c != '-')) {
+ // Not a plain integer — treat as ISO 8601 and pass through
as-is.
return time;
}
}
+ // Plain integer: convert from seconds to ISO 8601, clamping to
EPOCH_MIN if needed.
try {
- return Instant.ofEpochSecond(Long.parseLong(time)).toString();
+ long seconds = Long.parseLong(time);
+ if (seconds < EPOCH_MIN) {
+ Instant instant = Instant.ofEpochSecond(seconds);
Review Comment:
Fixed in 416b3b0.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]