This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 29481dd  Add SevenZOutputFile.createArchiveEntry(Path, String).
29481dd is described below

commit 29481dd09b4b7d0b5ddbcc9ae92db49b9f2fba6a
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Aug 8 16:17:25 2020 -0400

    Add SevenZOutputFile.createArchiveEntry(Path, String).
---
 src/changes/changes.xml                               |  3 +++
 .../commons/compress/archivers/examples/Archiver.java |  2 +-
 .../compress/archivers/sevenz/SevenZOutputFile.java   | 19 +++++++++++++++++++
 .../archivers/sevenz/SevenZOutputFileTest.java        | 11 +++++++++++
 4 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cad70d1..777b9d6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -137,6 +137,9 @@ The <action> type attribute can be add,update,fix,remove.
         Add SevenZOutputFile.write(Path, OpenOption...).
       </action>
       <action type="update" date="2020-08-08" due-to="Gary Gregory" 
dev="ggregory">
+        Add SevenZOutputFile.createArchiveEntry(Path, String).
+      </action>
+      <action type="update" date="2020-08-08" due-to="Gary Gregory" 
dev="ggregory">
         Add Path support to ZipArchiveOutputStream #123.
       </action>
       <action type="update" date="2020-07-23" due-to="Dependabot" 
dev="ggregory">
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java 
b/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
index cf6bfa0..3b10009 100644
--- a/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/Archiver.java
@@ -167,7 +167,7 @@ public class Archiver {
                 Objects.requireNonNull(attrs);
                 final String name = 
directory.relativize(path).toString().replace('\\', '/');
                 if (!name.isEmpty()) {
-                    final ArchiveEntry archiveEntry = 
target.createArchiveEntry(path.toFile(),
+                    final ArchiveEntry archiveEntry = 
target.createArchiveEntry(path,
                         isFile || name.endsWith("/") ? name : name + "/");
                     target.putArchiveEntry(archiveEntry);
                     if (isFile) {
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
 
b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
index fe9db09..3485e1f 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
@@ -163,6 +163,25 @@ public class SevenZOutputFile implements Closeable {
     }
 
     /**
+     * Create an archive entry using the inputPath and entryName provided.
+     *
+     * @param inputPath path to create an entry from
+     * @param entryName the name to use
+     * @return the ArchiveEntry set up with details from the file
+     *
+     * @throws IOException on error
+     * @since 1.21
+     */
+    public SevenZArchiveEntry createArchiveEntry(final Path inputPath,
+            final String entryName) throws IOException {
+        final SevenZArchiveEntry entry = new SevenZArchiveEntry();
+        entry.setDirectory(Files.isDirectory(inputPath));
+        entry.setName(entryName);
+        entry.setLastModifiedDate(new 
Date(Files.getLastModifiedTime(inputPath).toMillis()));
+        return entry;
+    }
+
+    /**
      * Records an archive entry to add.
      *
      * The caller must then write the content to the archive and call
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
index bebc26b..b31ffcb 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFileTest.java
@@ -122,6 +122,11 @@ public class SevenZOutputFileTest extends AbstractTestCase 
{
             outArchive.putArchiveEntry(entry);
             outArchive.closeArchiveEntry();
 
+            entry = outArchive.createArchiveEntry(dir.toPath(), "baz2/");
+            entry.setAntiItem(true);
+            outArchive.putArchiveEntry(entry);
+            outArchive.closeArchiveEntry();
+
             entry = new SevenZArchiveEntry();
             entry.setName("dada");
             entry.setHasWindowsAttributes(true);
@@ -207,6 +212,12 @@ public class SevenZOutputFileTest extends AbstractTestCase 
{
 
             entry = archive.getNextEntry();
             assert (entry != null);
+            assertEquals("baz2/", entry.getName());
+            assertTrue(entry.isDirectory());
+            assertTrue(entry.isAntiItem());
+
+            entry = archive.getNextEntry();
+            assert (entry != null);
             assertEquals("dada", entry.getName());
             assertEquals(2, entry.getSize());
             final byte[] content = new byte[2];

Reply via email to