diff --git a/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/ProductArchiverMojo.java b/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/ProductArchiverMojo.java index b5b5e5af9b..5f4cb07527 100644 --- a/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/ProductArchiverMojo.java +++ b/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/p2/director/ProductArchiverMojo.java @@ -125,6 +125,15 @@ public final class ProductArchiverMojo extends AbstractProductMojo { @Parameter private boolean parallel; + /** + * Controls if for {@code .tar.gz} archives the creation-time is stored as + * {@code LIBARCHIVE.creationtime } attribute in each entry. Currently {@code GNU tar} does not + * support that attributes and emits warnings about the {@code unknown extended header keyword + * 'LIBARCHIVE.creationtime'} when extracting such archive. + */ + @Parameter(defaultValue = "true") + private boolean storeCreationTime; + @Component private MavenProjectHelper helper; @@ -230,6 +239,7 @@ private void materialize(Product product, TargetEnvironment env) throws MojoExec private void createCommonsCompressTarGz(File productArchive, File sourceDir) throws IOException { TarGzArchiver archiver = new TarGzArchiver(); + archiver.setStoreCreationTimeAttribute(storeCreationTime); archiver.setLog(getLog()); archiver.addDirectory(sourceDir); archiver.setDestFile(productArchive); diff --git a/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java b/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java index ab42871b17..7c879ac6ae 100644 --- a/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java +++ b/tycho-p2-director-plugin/src/main/java/org/eclipse/tycho/plugins/tar/TarGzArchiver.java @@ -51,6 +51,7 @@ public class TarGzArchiver { private File destFile; private List sourceDirs = new ArrayList<>(); private Log log = new SystemStreamLog(); + private boolean storeCreationTime; public TarGzArchiver() { } @@ -63,6 +64,10 @@ public void setDestFile(File destFile) { this.destFile = destFile; } + public void setStoreCreationTimeAttribute(boolean storeCreationTime) { + this.storeCreationTime = storeCreationTime; + } + public void addDirectory(File directory) { this.sourceDirs.add(directory); } @@ -70,12 +75,10 @@ public void addDirectory(File directory) { public void createArchive() throws IOException { validate(); log.info("Building tar: " + destFile); - TarArchiveOutputStream tarStream = null; - try { - destFile.getAbsoluteFile().getParentFile().mkdirs(); - GzipCompressorOutputStream gzipStream = new GzipCompressorOutputStream( - new BufferedOutputStream(new FileOutputStream(destFile))); - tarStream = new TarArchiveOutputStream(gzipStream, "UTF-8"); + destFile.getAbsoluteFile().getParentFile().mkdirs(); + try (GzipCompressorOutputStream gzipStream = new GzipCompressorOutputStream( + new BufferedOutputStream(new FileOutputStream(destFile))); + TarArchiveOutputStream tarStream = new TarArchiveOutputStream(gzipStream, "UTF-8");) { // allow "long" file paths (> 100 chars) tarStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX); tarStream.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX); @@ -84,10 +87,6 @@ public void createArchive() throws IOException { addToTarRecursively(sourceDir, child, tarStream); } } - } finally { - if (tarStream != null) { - tarStream.close(); - } } } @@ -133,6 +132,9 @@ private TarArchiveEntry createTarEntry(File tarRootDir, File source) throws IOEx tarEntry.setMode(FilePermissionHelper.toOctalFileMode(attrs.permissions())); } tarEntry.setModTime(source.lastModified()); + if (!storeCreationTime) { // GNU tar cannot handle 'LIBARCHIVE.creationtime' attributes and emits a lot of warnings on it + tarEntry.setCreationTime(null); + } return tarEntry; }