|
24 | 24 | import java.nio.charset.StandardCharsets; |
25 | 25 | import java.text.SimpleDateFormat; |
26 | 26 | import java.time.Instant; |
| 27 | +import java.time.format.DateTimeFormatter; |
| 28 | +import java.time.format.DateTimeParseException; |
27 | 29 | import java.util.Collections; |
28 | 30 | import java.util.Date; |
29 | 31 | import java.util.List; |
30 | 32 | import java.util.Map; |
31 | 33 | import java.util.Optional; |
32 | 34 | import java.util.Properties; |
33 | 35 | import java.util.function.Supplier; |
34 | | -import javax.annotation.Nonnull; |
35 | | -import javax.annotation.Nullable; |
36 | 36 | import org.apache.maven.execution.MavenSession; |
37 | 37 | import org.apache.maven.plugin.AbstractMojo; |
38 | 38 | import org.apache.maven.plugin.MojoExecution; |
|
44 | 44 | import org.apache.maven.plugins.annotations.Parameter; |
45 | 45 | import org.apache.maven.project.MavenProject; |
46 | 46 | import org.apache.maven.settings.Settings; |
47 | | -import org.joda.time.DateTime; |
| 47 | +import org.jspecify.annotations.NonNull; |
| 48 | +import org.jspecify.annotations.Nullable; |
48 | 49 | import org.sonatype.plexus.build.incremental.BuildContext; |
49 | 50 | import pl.project13.core.CommitIdGenerationMode; |
50 | 51 | import pl.project13.core.CommitIdPropertiesOutputFormat; |
@@ -1279,25 +1280,25 @@ public Supplier<String> supplyProjectVersion() { |
1279 | 1280 | return () -> project.getVersion(); |
1280 | 1281 | } |
1281 | 1282 |
|
1282 | | - @Nonnull |
| 1283 | + @NonNull |
1283 | 1284 | @Override |
1284 | 1285 | public LogInterface getLogInterface() { |
1285 | 1286 | return log; |
1286 | 1287 | } |
1287 | 1288 |
|
1288 | | - @Nonnull |
| 1289 | + @NonNull |
1289 | 1290 | @Override |
1290 | 1291 | public String getDateFormat() { |
1291 | 1292 | return dateFormat; |
1292 | 1293 | } |
1293 | 1294 |
|
1294 | | - @Nonnull |
| 1295 | + @NonNull |
1295 | 1296 | @Override |
1296 | 1297 | public String getDateFormatTimeZone() { |
1297 | 1298 | return dateFormatTimeZone; |
1298 | 1299 | } |
1299 | 1300 |
|
1300 | | - @Nonnull |
| 1301 | + @NonNull |
1301 | 1302 | @Override |
1302 | 1303 | public String getPrefixDot() { |
1303 | 1304 | String trimmedPrefix = prefix.trim(); |
@@ -1443,8 +1444,8 @@ public boolean isPerModuleVersions() { |
1443 | 1444 | } |
1444 | 1445 |
|
1445 | 1446 | private void publishToAllSystemEnvironments( |
1446 | | - @Nonnull LogInterface log, |
1447 | | - @Nonnull Properties propertiesToPublish, |
| 1447 | + @NonNull LogInterface log, |
| 1448 | + @NonNull Properties propertiesToPublish, |
1448 | 1449 | @Nullable Properties contextProperties) { |
1449 | 1450 | publishPropertiesInto(propertiesToPublish, project.getProperties()); |
1450 | 1451 | // some plugins rely on the user properties (e.g. flatten-maven-plugin) |
@@ -1505,7 +1506,44 @@ protected static Date parseOutputTimestamp(String outputTimestamp) { |
1505 | 1506 | // no timestamp configured |
1506 | 1507 | return null; |
1507 | 1508 | } |
1508 | | - return new DateTime(outputTimestamp).toDate(); |
| 1509 | + // Normalize the timestamp to handle common variations |
| 1510 | + String normalized = outputTimestamp.trim(); |
| 1511 | + |
| 1512 | + // Handle lowercase designators |
| 1513 | + normalized = normalized.replace('t', 'T').replace('z', 'Z'); |
| 1514 | + |
| 1515 | + // Handle hours-only offsets by adding :00 minutes if needed |
| 1516 | + if (normalized.matches(".*[+-]\\d{2}$")) { |
| 1517 | + normalized = normalized.substring(0, normalized.length() - 3) |
| 1518 | + + normalized.substring(normalized.length() - 3) + ":00"; |
| 1519 | + } |
| 1520 | + |
| 1521 | + // Try parsing with different formatters in order of preference |
| 1522 | + DateTimeFormatter[] formatters = { |
| 1523 | + DateTimeFormatter.ISO_INSTANT, // 2022-02-12T15:30:00Z |
| 1524 | + DateTimeFormatter.ISO_OFFSET_DATE_TIME, // 2022-02-12T15:30+00:00 |
| 1525 | + DateTimeFormatter.ISO_LOCAL_DATE_TIME, // 2022-02-12T15:30:00 |
| 1526 | + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mmZ"), // 2019-03-26T10:00-0400 |
| 1527 | + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ"), // 2019-03-26T10:00:00-0400 |
| 1528 | + DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm") // 2022-02-12T15:30 |
| 1529 | + }; |
| 1530 | + |
| 1531 | + for (DateTimeFormatter formatter : formatters) { |
| 1532 | + try { |
| 1533 | + if ( |
| 1534 | + formatter == DateTimeFormatter.ISO_LOCAL_DATE_TIME |
| 1535 | + && |
| 1536 | + (normalized.contains("+") || normalized.contains("-") || normalized.endsWith("Z")) |
| 1537 | + ) { |
| 1538 | + continue; // Skip local formatter for timestamps with timezones |
| 1539 | + } |
| 1540 | + return Date.from(Instant.from(formatter.parse(normalized))); |
| 1541 | + } catch (DateTimeParseException ignore) { |
| 1542 | + // Try next formatter |
| 1543 | + } |
| 1544 | + } |
| 1545 | + |
| 1546 | + throw new IllegalArgumentException("Unable to parse timestamp: " + outputTimestamp); |
1509 | 1547 | } |
1510 | 1548 |
|
1511 | 1549 | private void publishPropertiesInto(Properties propertiesToPublish, Properties propertiesTarget) { |
@@ -1536,7 +1574,7 @@ private void logProperties(LogInterface log, Properties propertiesToPublish) { |
1536 | 1574 | } |
1537 | 1575 | } |
1538 | 1576 |
|
1539 | | - private boolean isPomProject(@Nonnull MavenProject project) { |
| 1577 | + private boolean isPomProject(@NonNull MavenProject project) { |
1540 | 1578 | return project.getPackaging().equalsIgnoreCase("pom"); |
1541 | 1579 | } |
1542 | 1580 | } |
0 commit comments