commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1554174 - in /commons/proper/compress/branches/compress-2.0: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/commons/ src/main/java/org/apache/commons/compress2/ src/main/java/org/apac...
Date Mon, 30 Dec 2013 09:55:12 GMT
Author: bodewig
Date: Mon Dec 30 09:55:11 2013
New Revision: 1554174

URL: http://svn.apache.org/r1554174
Log:
WIP for defining the ArchiveEntry API - need to think about permissions and non-File POSIX
stuff

Added:
    commons/proper/compress/branches/compress-2.0/findbugs-exclude-filter.xml
      - copied, changed from r1553074, commons/proper/compress/trunk/findbugs-exclude-filter.xml
    commons/proper/compress/branches/compress-2.0/pmd-ruleset.xml
      - copied unchanged from r1553074, commons/proper/compress/trunk/pmd-ruleset.xml
    commons/proper/compress/branches/compress-2.0/pom.xml
      - copied, changed from r1553074, commons/proper/compress/trunk/pom.xml
    commons/proper/compress/branches/compress-2.0/src/
    commons/proper/compress/branches/compress-2.0/src/main/
    commons/proper/compress/branches/compress-2.0/src/main/java/
    commons/proper/compress/branches/compress-2.0/src/main/java/org/
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntry.java
      - copied, changed from r1553074, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveEntry.java
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
  (with props)
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/OwnerInformation.java
  (with props)
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/package.html
      - copied unchanged from r1553074, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/package.html
    commons/proper/compress/branches/compress-2.0/src/test/
    commons/proper/compress/branches/compress-2.0/src/test/java/
    commons/proper/compress/branches/compress-2.0/src/test/java/org/
    commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/
    commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/
    commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/compress2/
    commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/compress2/archivers/
    commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/compress2/archivers/ArchiveEntryParametersTest.java
  (with props)
Modified:
    commons/proper/compress/branches/compress-2.0/   (props changed)

Propchange: commons/proper/compress/branches/compress-2.0/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Dec 30 09:55:11 2013
@@ -0,0 +1 @@
+target

Copied: commons/proper/compress/branches/compress-2.0/findbugs-exclude-filter.xml (from r1553074,
commons/proper/compress/trunk/findbugs-exclude-filter.xml)
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/findbugs-exclude-filter.xml?p2=commons/proper/compress/branches/compress-2.0/findbugs-exclude-filter.xml&p1=commons/proper/compress/trunk/findbugs-exclude-filter.xml&r1=1553074&r2=1554174&rev=1554174&view=diff
==============================================================================
--- commons/proper/compress/trunk/findbugs-exclude-filter.xml (original)
+++ commons/proper/compress/branches/compress-2.0/findbugs-exclude-filter.xml Mon Dec 30 09:55:11
2013
@@ -23,87 +23,5 @@
 -->
 <FindBugsFilter>
 
-  <!-- Reason: References to System.out/err == -->
-  <Match>
-    <Class name="org.apache.commons.compress.archivers.Lister" />
-    <Or>
-      <Method name="main" />
-      <Method name="usage" />
-    </Or>
-    <Bug pattern="NP_ALWAYS_NULL" />
-  </Match>
-  <Match>
-    <Class name="org.apache.commons.compress.archivers.zip.ZipFile" />
-    <Method name="finalize" />
-    <Bug pattern="NP_ALWAYS_NULL" />
-  </Match>
-  <Match>
-    <Class name="org.apache.commons.compress.archivers.dump.DumpArchiveUtil" />
-    <Method name="dumpBlock" />
-    <Bug pattern="NP_ALWAYS_NULL" />
-  </Match>
-
-  <!-- Reason: fallthrough is intended -->
-  <Match>
-    <Class name="org.apache.commons.compress.archivers.zip.ExtraFieldUtils" />
-    <Method name="parse" />
-    <Bug pattern="SF_SWITCH_FALLTHROUGH" />
-  </Match>
-
-  <!-- Reason: fields unused as documented -->
-  <Match>
-    <Class name="org.apache.commons.compress.archivers.jar.JarArchiveEntry" />
-    <Or>
-      <Field name="certificates"/>
-      <Field name="manifestAttributes"/>
-    </Or>
-    <Bug pattern="UWF_NULL_FIELD" />
-  </Match>
-  <Match>
-    <Class name="org.apache.commons.compress.archivers.dump.DumpArchiveEntry" />
-    <Field name="summary"/>
-    <Bug pattern="UWF_NULL_FIELD" />
-  </Match>
-
-  <!-- Reason: exception in close swallowed in order to re-throw original -->
-  <Match>
-    <Class name="org.apache.commons.compress.archivers.zip.ZipFile" />
-    <Method name="&lt;init&gt;" />
-    <Bug pattern="DE_MIGHT_IGNORE" />
-  </Match>
-  <Match>
-    <Class name="org.apache.commons.compress.compressors.pack200.Pack200CompressorOutputStream"
/>
-    <Method name="finish" />
-    <Bug pattern="DE_MIGHT_IGNORE" />
-  </Match>
-
-  <!-- Reason: skip(Long.MAX_VALUE) called to drain stream completely,
-       the class overrides skip to ensure it reads the full amount
-       until EOF is reached -->
-  <Match>
-    <Class name="org.apache.commons.compress.archivers.zip.ZipArchiveInputStream" />
-    <Method name="closeEntry" />
-    <Bug pattern="SR_NOT_CHECKED" />
-  </Match>
-
-  <!-- Reason: trying to delete a temporary file that has deleteOnExit set
-       anyway -->
-  <Match>
-    <Class name="org.apache.commons.compress.compressors.pack200.Pack200Utils" />
-    <Method name="normalize" />
-    <Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
-  </Match>
-  <Match>
-    <Class name="org.apache.commons.compress.compressors.pack200.TempFileCachingStreamBridge$1"
/>
-    <Method name="close" />
-    <Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
-  </Match>
-
-  <!-- Reason: It is the Pack200*Stream that's going to close it. -->
-  <Match>
-    <Class name="org.apache.commons.compress.compressors.pack200.TempFileCachingStreamBridge$1"
/>
-    <Method name="&lt;init&gt;" />
-    <Bug pattern="OBL_UNSATISFIED_OBLIGATION" />
-  </Match>
 
 </FindBugsFilter>

Copied: commons/proper/compress/branches/compress-2.0/pom.xml (from r1553074, commons/proper/compress/trunk/pom.xml)
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/pom.xml?p2=commons/proper/compress/branches/compress-2.0/pom.xml&p1=commons/proper/compress/trunk/pom.xml&r1=1553074&r2=1554174&rev=1554174&view=diff
==============================================================================
--- commons/proper/compress/trunk/pom.xml (original)
+++ commons/proper/compress/branches/compress-2.0/pom.xml Mon Dec 30 09:55:11 2013
@@ -24,8 +24,8 @@
   </parent>
 
   <groupId>org.apache.commons</groupId>
-  <artifactId>commons-compress</artifactId>
-  <version>1.7-SNAPSHOT</version>
+  <artifactId>commons-compress2</artifactId>
+  <version>2.0.0-SNAPSHOT</version>
   <name>Apache Commons Compress</name>
   <url>http://commons.apache.org/proper/commons-compress/</url>
   <!-- The description is not indented to make it look better in the release notes -->
@@ -41,7 +41,7 @@ These include: bzip2, gzip, pack200, lzm
     <commons.jira.id>COMPRESS</commons.jira.id>
     <commons.jira.pid>12310904</commons.jira.pid>
     <!-- configuration bits for cutting a release candidate -->
-    <commons.release.version>1.6</commons.release.version>
+    <commons.release.version>2.0.0</commons.release.version>
     <commons.rc.version>RC1</commons.rc.version>
   </properties>
 
@@ -155,8 +155,8 @@ These include: bzip2, gzip, pack200, lzm
         <configuration>
           <archive>
             <manifestEntries>
-              <Main-Class>org.apache.commons.compress.archivers.Lister</Main-Class>
-              <Extension-Name>org.apache.commons.compress</Extension-Name>
+              <!--Main-Class>org.apache.commons.compress.archivers.Lister</Main-Class-->
+              <Extension-Name>org.apache.commons.compress2</Extension-Name>
             </manifestEntries>
           </archive>
         </configuration>

Copied: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntry.java
(from r1553074, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveEntry.java)
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntry.java?p2=commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntry.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveEntry.java&r1=1553074&r2=1554174&rev=1554174&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveEntry.java
(original)
+++ commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntry.java
Mon Dec 30 09:55:11 2013
@@ -16,44 +16,56 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.commons.compress.archivers;
+package org.apache.commons.compress2.archivers;
 
 import java.util.Date;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * Represents an entry of an archive.
+ * @Immutable
  */
 public interface ArchiveEntry {
 
+    /** Special value indicating that the size is unknown */
+    static final long SIZE_UNKNOWN = -1;
+
     /**
      * Gets the name of the entry in this archive. May refer to a file or directory or other
item.
-     * 
+     *
+     * <p>The name will use '/' as directory separator and end with a '/' if and only
if the entry represents a
+     * directory.</p>
+     *
      * @return The name of this entry in the archive.
      */
-    public String getName();
+    String getName();
 
     /**
-     * Gets the uncompressed size of this entry. May be -1 (SIZE_UNKNOWN) if the size is
unknown
+     * Gets the uncompressed size of this entry. May be -1 ({@link #SIZE_UNKNOWN}) if the
size is unknown.
      * 
      * @return the uncompressed size of this entry.
      */
-    public long getSize();
-
-    /** Special value indicating that the size is unknown */
-    public static final long SIZE_UNKNOWN = -1;
+    long getSize();
 
     /**
      * Returns true if this entry refers to a directory.
      * 
      * @return true if this entry refers to a directory.
      */
-    public boolean isDirectory();
+    boolean isDirectory();
 
     /**
      * Gets the last modified date of this entry.
      * 
      * @return the last modified date of this entry.
-     * @since 1.1
      */
-    public Date getLastModifiedDate();
+    Date getLastModifiedDate();
+
+    /**
+     * Provides information about the owner.
+     *
+     * @return information about the entry's owner or null if the format doesn't support
owner information
+     */
+    OwnerInformation getOwnerInformation();
 }

Added: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java?rev=1554174&view=auto
==============================================================================
--- commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
(added)
+++ commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
Mon Dec 30 09:55:11 2013
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.archivers;
+
+import java.io.File;
+import java.util.Date;
+
+/**
+ * A parameter object useful for creating new ArchiveEntries.
+ * @NotThreadSafe
+ */
+public class ArchiveEntryParameters {
+
+    private static final char SLASH = '/';
+
+    private String name;
+    private long size = ArchiveEntry.SIZE_UNKNOWN;
+    private boolean dirFlag = false;
+    private Date lastModified;
+    private OwnerInformation owner;
+
+    /**
+     * Creates parameters as a copy of an existing entry.
+     * @param otherEntry the other entry.
+     * @return parameters copied from the other entry
+     */
+    public static ArchiveEntryParameters copyOf(ArchiveEntry otherEntry) {
+        return new ArchiveEntryParameters()
+            .withName(otherEntry.getName())
+            .asDirectory(otherEntry.isDirectory())
+            .withSize(otherEntry.getSize())
+            .withLastModifiedDate(otherEntry.getLastModifiedDate())
+            .withOwnerInformation(otherEntry.getOwnerInformation());
+    }
+
+    /**
+     * Populates parameters from a File instance.
+     * @param file the File to read information from
+     * @return parameters populated from the file instance
+     */
+    public static ArchiveEntryParameters fromFile(File file) {
+        return new ArchiveEntryParameters()
+            .withName(file.getName())
+            .asDirectory(file.isDirectory())
+            .withSize(file.exists() ? file.length() : ArchiveEntry.SIZE_UNKNOWN)
+            .withLastModifiedDate(new Date(file.lastModified()));
+    }
+
+    /**
+     * Sets the name.
+     *
+     * <p>The name will be normalized to only contain '/' separators and end with a
'/' if and only if the entry
+     * represents a directory.</p>
+     *
+     * @param name the name of the entry to build
+     * @return the parameters object
+     */
+    public ArchiveEntryParameters withName(String name) {
+        this.name = name;
+        return this;
+    }
+
+    /**
+     * Sets the size of the entry.
+     * @param size the size of the entry to build
+     * @return the parameters object
+     */
+    public ArchiveEntryParameters withSize(long size) {
+        this.size = size;
+        return this;
+    }
+
+    /**
+     * Marks the entry to build as a directory.
+     * @param b whether the entry is supposed to represent a directory
+     * @return the parameters object
+     */
+    public ArchiveEntryParameters asDirectory(boolean b) {
+        this.dirFlag = b;
+        return this;
+    }
+
+    /**
+     * Sets the last modified date of the entry.
+     * @param lastModified the last modified date of the entry to build
+     * @return the parameters object
+     */
+    public ArchiveEntryParameters withLastModifiedDate(Date lastModified) {
+        this.lastModified = clone(lastModified);
+        return this;
+    }
+
+    /**
+     * Sets the owner information of the entry.
+     * @param owner the owner information for the entry to build
+     * @return the parameters object
+     */
+    public ArchiveEntryParameters withOwnerInformation(OwnerInformation owner) {
+        this.owner = owner;
+        return this;
+    }
+
+    /**
+     * Gets the configured name.
+     *
+     * <p>The name will use '/' as directory separator and end with a '/' if and only
if the entry represents a
+     * directory.</p>
+     *
+     * @return the normalized name
+     */
+    public String getName() {
+        return normalize(name, dirFlag);
+    }
+
+    /**
+     * Gets the configured size or {@link #SIZE_UNKNOWN}) if the size is not configured.
+     * 
+     * @return the configured size
+     */
+    public long getSize() {
+        return dirFlag ? 0 : size;
+    }
+
+    /**
+     * Returns true if parameters are configured to represent a directory.
+     * 
+     * @return true if this parameters refer to a directory.
+     */
+    public boolean isDirectory() {
+        return dirFlag;
+    }
+
+    /**
+     * Gets the configured last modified date.
+     * 
+     * @return the configured last modified date or null if no date was configured.
+     */
+    public Date getLastModifiedDate() {
+        return clone(lastModified);
+    }
+
+    /**
+     * Gets the configured information about the owner.
+     *
+     * @return information about the entry's owner or null if no information was configured
+     */
+    public OwnerInformation getOwnerInformation() {
+        return owner;
+    }
+
+    private static String normalize(String name, boolean dirFlag) {
+        if (name != null) {
+            name = name.replace('\\', SLASH);
+            int nameLength = name.length();
+            boolean endsWithSlash = nameLength > 0 && name.charAt(nameLength -
1) == SLASH;
+            if (endsWithSlash != dirFlag) {
+                if (dirFlag) {
+                    name += SLASH;
+                } else {
+                    name = name.substring(0, nameLength - 1);
+                }
+            }
+        }
+        return name;
+    }
+
+    private static Date clone(Date d) {
+        return d == null ? null : (Date) d.clone();
+    }
+}

Propchange: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveEntryParameters.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/OwnerInformation.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/OwnerInformation.java?rev=1554174&view=auto
==============================================================================
--- commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/OwnerInformation.java
(added)
+++ commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/OwnerInformation.java
Mon Dec 30 09:55:11 2013
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.archivers;
+
+/**
+ * Encapsulates owner information of an archive entry.
+ *
+ * <p>Fields that are not supported by the archive format may be null.</p>
+ * @Immutable
+ */
+public class OwnerInformation {
+
+    private final String userName, groupName;
+    private final int userId, groupId;
+
+    /**
+     * Creates an OwnerInformation without names.
+     * @param userId numerical id of the owner
+     * @param groupId numerical id of the group owning the entry
+     */
+    public OwnerInformation(int userId, int groupId) {
+        this(null, null, userId, groupId);
+    }
+
+    /**
+     * Creates an OwnerInformation.
+     * @param userName the name of the owner
+     * @param groupName the name of the group owning the entry
+     * @param userId numerical id of the owner
+     * @param groupId numerical id of the group owning the entry
+     */
+    public OwnerInformation(String userName, String groupName, int userId, int groupId) {
+        this.userName = userName;
+        this.groupName = groupName;
+        this.userId = userId;
+        this.groupId = groupId;
+    }
+
+    /**
+     * Gets the name of the owner.
+     * @return the name of the owner, may be null
+     */
+    public String getUserName() {
+        return userName;
+    }
+
+    /**
+     * Gets the name of the group owning the entry.
+     * @return the name of the group owning the entry, may be null
+     */
+    public String getGroupName() {
+        return groupName;
+    }
+
+    /**
+     * Gets numerical id of the owner.
+     * @return numerical id of the owner
+     */
+    public int getUserId() {
+        return userId;
+    }
+
+    /**
+     * Gets numerical id of the group owning the entry.
+     * @return numerical id of the group owning the entry
+     */
+    public int getGroupId() {
+        return groupId;
+    }
+
+}

Propchange: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/OwnerInformation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/compress2/archivers/ArchiveEntryParametersTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/compress2/archivers/ArchiveEntryParametersTest.java?rev=1554174&view=auto
==============================================================================
--- commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/compress2/archivers/ArchiveEntryParametersTest.java
(added)
+++ commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/compress2/archivers/ArchiveEntryParametersTest.java
Mon Dec 30 09:55:11 2013
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress2.archivers;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import org.junit.Test;
+
+public class ArchiveEntryParametersTest {
+
+    @Test
+    public void defaultValues() {
+        ArchiveEntryParameters p = new ArchiveEntryParameters();
+        assertEquals(null, p.getName());
+        assertEquals(-1, p.getSize());
+        assertEquals(false, p.isDirectory());
+        assertEquals(null, p.getLastModifiedDate());
+        assertEquals(null, p.getOwnerInformation());
+    }
+
+    @Test
+    public void shouldAddTrailingSlashForDirectories() {
+        ArchiveEntryParameters p = new ArchiveEntryParameters()
+            .withName("foo").asDirectory(true);
+        assertEquals("foo/", p.getName());
+        p.withName("foo/");
+        assertEquals("foo/", p.getName());
+        p.withName("");
+        assertEquals("/", p.getName());
+    }
+
+    @Test
+    public void shouldStripTrailingSlashForNonDirectories() {
+        ArchiveEntryParameters p = new ArchiveEntryParameters()
+            .withName("foo").asDirectory(false);
+        assertEquals("foo", p.getName());
+        p.withName("foo/");
+        assertEquals("foo", p.getName());
+        p.withName("");
+        assertEquals("", p.getName());
+    }
+
+    @Test
+    public void sizeShouldBe0ForDirectories() {
+        ArchiveEntryParameters p = new ArchiveEntryParameters()
+            .asDirectory(true);
+        assertEquals(0, p.getSize());
+        p.withSize(42);
+        assertEquals(0, p.getSize());
+    }
+
+    @Test
+    public void copyActuallyCopies() {
+        final Date d = new Date();
+        final OwnerInformation o = new OwnerInformation(17, 4);
+        ArchiveEntryParameters p = ArchiveEntryParameters.copyOf(new ArchiveEntry() {
+                public String getName() {return "baz";}
+                public long getSize() {return 42;}
+                public boolean isDirectory() {return false;}
+                public Date getLastModifiedDate() {return d;}
+                public OwnerInformation getOwnerInformation() {return o;}
+            });
+        assertEquals("baz", p.getName());
+        assertEquals(42, p.getSize());
+        assertEquals(false, p.isDirectory());
+        assertEquals(d, p.getLastModifiedDate());
+        assertEquals(o, p.getOwnerInformation());
+    }
+
+    @Test
+    public void fromExistingFileHasExpectedValues() throws IOException {
+        final Date d = new Date();
+        File f = File.createTempFile("pre", "suf");
+        f.deleteOnExit();
+        f.setLastModified(d.getTime());
+        ArchiveEntryParameters p = ArchiveEntryParameters.fromFile(f);
+        assert p.getName().endsWith("suf");
+        assert p.getName().startsWith("pre");
+        assertEquals(0, p.getSize());
+        assertEquals(false, p.isDirectory());
+        assertWithinTwoSecondsOf(d, p.getLastModifiedDate());
+        assertEquals(null, p.getOwnerInformation());
+    }
+
+    @Test
+    public void fromExistingDirectoryHasExpectedValues() throws IOException {
+        final Date d = new Date();
+        File f = File.createTempFile("pre", "suf");
+        assert f.delete();
+        f.mkdirs();
+        f.deleteOnExit();
+        f.setLastModified(d.getTime());
+        ArchiveEntryParameters p = ArchiveEntryParameters.fromFile(f);
+        assert p.getName().endsWith("suf/");
+        assert p.getName().startsWith("pre");
+        assertEquals(0, p.getSize());
+        assertEquals(true, p.isDirectory());
+        assertWithinTwoSecondsOf(d, p.getLastModifiedDate());
+        assertEquals(null, p.getOwnerInformation());
+    }
+
+    @Test
+    public void fromNonExistingFileHasNoSize() throws IOException {
+        File f = File.createTempFile("pre", "suf");
+        assert f.delete();
+        ArchiveEntryParameters p = ArchiveEntryParameters.fromFile(f);
+        assertEquals(-1, p.getSize());
+    }
+
+    private static void assertWithinTwoSecondsOf(Date expected, Date actual) {
+        assert Math.abs(expected.getTime() - actual.getTime()) < 2000;
+    }
+}

Propchange: commons/proper/compress/branches/compress-2.0/src/test/java/org/apache/commons/compress2/archivers/ArchiveEntryParametersTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message