|
43 | 43 | import java.util.List;
|
44 | 44 | import java.util.Objects;
|
45 | 45 | import java.util.Set;
|
| 46 | +import java.util.TimeZone; |
46 | 47 | import java.util.concurrent.Callable;
|
47 | 48 | import java.util.jar.JarEntry;
|
48 | 49 | import java.util.jar.JarFile;
|
|
55 | 56 |
|
56 | 57 | import org.apache.commons.collections4.MultiValuedMap;
|
57 | 58 | import org.apache.commons.collections4.multimap.HashSetValuedHashMap;
|
| 59 | +import org.apache.commons.compress.archivers.zip.ExtraFieldUtils; |
| 60 | +import org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp; |
| 61 | +import org.apache.commons.compress.archivers.zip.ZipExtraField; |
58 | 62 | import org.apache.maven.plugin.MojoExecutionException;
|
59 | 63 | import org.apache.maven.plugins.shade.filter.Filter;
|
60 | 64 | import org.apache.maven.plugins.shade.relocation.Relocator;
|
@@ -89,6 +93,25 @@ public DefaultShader(final Logger logger) {
|
89 | 93 | this.logger = Objects.requireNonNull(logger);
|
90 | 94 | }
|
91 | 95 |
|
| 96 | + // workaround for MSHADE-420 |
| 97 | + private long getTime(ZipEntry entry) { |
| 98 | + if (entry.getExtra() != null) { |
| 99 | + try { |
| 100 | + ZipExtraField[] fields = |
| 101 | + ExtraFieldUtils.parse(entry.getExtra(), true, ExtraFieldUtils.UnparseableExtraField.SKIP); |
| 102 | + for (ZipExtraField field : fields) { |
| 103 | + if (X5455_ExtendedTimestamp.HEADER_ID.equals(field.getHeaderId())) { |
| 104 | + // extended timestamp extra field: need to translate UTC to local time for Reproducible Builds |
| 105 | + return entry.getTime() - TimeZone.getDefault().getRawOffset(); |
| 106 | + } |
| 107 | + } |
| 108 | + } catch (ZipException ze) { |
| 109 | + // ignore |
| 110 | + } |
| 111 | + } |
| 112 | + return entry.getTime(); |
| 113 | + } |
| 114 | + |
92 | 115 | public void shade(ShadeRequest shadeRequest) throws IOException, MojoExecutionException {
|
93 | 116 | Set<String> resources = new HashSet<>();
|
94 | 117 |
|
@@ -332,7 +355,7 @@ public InputStream call() throws Exception {
|
332 | 355 | }
|
333 | 356 | },
|
334 | 357 | name,
|
335 |
| - entry.getTime(), |
| 358 | + getTime(entry), |
336 | 359 | entry.getMethod());
|
337 | 360 | } catch (Exception e) {
|
338 | 361 | throw new IOException(String.format("Problem shading JAR %s entry %s: %s", jar, name, e), e);
|
@@ -423,7 +446,7 @@ private void goThroughAllJarEntriesForManifestTransformer(
|
423 | 446 | resources.add(resource);
|
424 | 447 | try (InputStream inputStream = jarFile.getInputStream(entry)) {
|
425 | 448 | manifestTransformer.processResource(
|
426 |
| - resource, inputStream, shadeRequest.getRelocators(), entry.getTime()); |
| 449 | + resource, inputStream, shadeRequest.getRelocators(), getTime(entry)); |
427 | 450 | }
|
428 | 451 | break;
|
429 | 452 | }
|
|
0 commit comments