ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r804624 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/ main/org/apache/ant/compress/taskdefs/ tests/antunit/
Date Sun, 16 Aug 2009 05:34:02 GMT
Author: bodewig
Date: Sun Aug 16 05:34:02 2009
New Revision: 804624

URL: http://svn.apache.org/viewvc?rev=804624&view=rev
Log:
tiny refactoring plus ar task

Added:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java 
 (contents, props changed)
      - copied, changed from r804622, ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml?rev=804624&r1=804623&r2=804624&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml Sun Aug
16 05:34:02 2009
@@ -33,6 +33,10 @@
     classname="org.apache.ant.compress.taskdefs.Unzip"
     />
   <taskdef
+    name="ar"
+    classname="org.apache.ant.compress.taskdefs.Ar"
+    />
+  <taskdef
     name="tar"
     classname="org.apache.ant.compress.taskdefs.Tar"
     />

Copied: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
(from r804622, ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java)
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java?p2=ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java&p1=ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java&r1=804622&r2=804624&rev=804624&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java Sun
Aug 16 05:34:02 2009
@@ -18,63 +18,59 @@
 
 package org.apache.ant.compress.taskdefs;
 
-import org.apache.ant.compress.util.TarStreamFactory;
+import org.apache.ant.compress.util.ArStreamFactory;
 import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
-import org.apache.commons.compress.archivers.tar.TarConstants;
+import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
+import org.apache.tools.ant.BuildException;
 
 /**
  * Creates tar archives.
  */
-public class Tar extends ArchiveBase {
-    public Tar() {
-        super(new TarStreamFactory(),
+public class Ar extends ArchiveBase {
+    /** stolen from ArEntry */
+    private static final int DEFAULT_MODE = 33188;
+
+    public Ar() {
+        super(new ArStreamFactory(),
               new ArchiveBase.EntryBuilder() {
-                public ArchiveEntry buildEntry(String name,
-                                               ArchiveBase.ResourceWithFlags r) {
+                public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
                     boolean isDir = r.getResource().isDirectory();
-                    TarArchiveEntry ent =
-                        new TarArchiveEntry(name,
-                                            isDir ? TarConstants.LF_DIR
-                                            : TarConstants.LF_NORMAL);
-                    ent.setModTime(r.getResource().getLastModified());
-                    ent.setSize(isDir ? 0 : r.getResource().getSize());
+                    if (isDir) {
+                        // REVISIT
+                        throw new BuildException("ar archives cannot store"
+                                                 + " directory entries");
+                    }
 
+                    int mode = DEFAULT_MODE;
                     if (r.getResourceFlags().hasModeBeenSet()) {
-                        ent.setMode(r.getResourceFlags().getMode());
+                        mode = r.getResourceFlags().getMode();
                     } else if (!isDir
                                && r.getCollectionFlags().hasModeBeenSet()) {
-                        ent.setMode(r.getCollectionFlags().getMode());
+                        mode = r.getCollectionFlags().getMode();
                     } else if (isDir
                                && r.getCollectionFlags().hasDirModeBeenSet()) {
-                        ent.setMode(r.getCollectionFlags().getDirMode());
+                        mode = r.getCollectionFlags().getDirMode();
                     }
 
+                    int uid = 0;
                     if (r.getResourceFlags().hasUserIdBeenSet()) {
-                        ent.setUserId(r.getResourceFlags().getUserId());
+                        uid = r.getResourceFlags().getUserId();
                     } else if (r.getCollectionFlags().hasUserIdBeenSet()) {
-                        ent.setUserId(r.getCollectionFlags().getUserId());
+                        uid = r.getCollectionFlags().getUserId();
                     }
 
+                    int gid = 0;
                     if (r.getResourceFlags().hasGroupIdBeenSet()) {
-                        ent.setGroupId(r.getResourceFlags().getGroupId());
+                        gid = r.getResourceFlags().getGroupId();
                     } else if (r.getCollectionFlags().hasGroupIdBeenSet()) {
-                        ent.setGroupId(r.getCollectionFlags().getGroupId());
-                    }
- 
-                    if (r.getResourceFlags().hasUserNameBeenSet()) {
-                        ent.setUserName(r.getResourceFlags().getUserName());
-                    } else if (r.getCollectionFlags().hasUserNameBeenSet()) {
-                        ent.setUserName(r.getCollectionFlags().getUserName());
+                        gid = r.getCollectionFlags().getGroupId();
                     }
 
-                    if (r.getResourceFlags().hasGroupNameBeenSet()) {
-                        ent.setGroupName(r.getResourceFlags().getGroupName());
-                    } else if (r.getCollectionFlags().hasGroupNameBeenSet()) {
-                        ent.setGroupName(r.getCollectionFlags().getGroupName());
-                    }
- 
-                    return ent;
+                    return new ArArchiveEntry(r.getName(),
+                                              r.getResource().getSize(),
+                                              uid, gid, mode,
+                                              r.getResource().getLastModified()
+                                              / 1000);
                 }
             });
     }

Propchange: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java?rev=804624&r1=804623&r2=804624&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
Sun Aug 16 05:34:02 2009
@@ -127,7 +127,7 @@
             log("No sources, nothing to do", Project.MSG_WARN);
         } else {
             try {
-                writeArchive(dest, toAdd);
+                writeArchive(toAdd);
             } catch (IOException ioex) {
                 throw new BuildException("Failed to write archive", ioex);
             }
@@ -163,7 +163,10 @@
         return (ResourceWithFlags[]) l.toArray(new ResourceWithFlags[l.size()]);
     }
 
-    protected void writeArchive(Resource dest, ResourceWithFlags[] src)
+    /**
+     * Creates the archive archiving the given resources.
+     */
+    protected void writeArchive(ResourceWithFlags[] src)
         throws IOException {
         FileUtils fu = FileUtils.getFileUtils();
         ArchiveOutputStream out = null;
@@ -174,18 +177,8 @@
                                          Expand.NATIVE_ENCODING.equals(encoding)
                                          ? null : encoding);
             for (int i = 0; i < src.length; i++) {
-                String name = src[i].getResource().getName();
-                if (src[i].getCollectionFlags().hasFullpath()) {
-                    name = src[i].getCollectionFlags().getFullpath();
-                } else if (src[i].getCollectionFlags().hasPrefix()) {
-                    String prefix = src[i].getCollectionFlags().getPrefix();
-                    if (!prefix.endsWith("/")) {
-                        prefix = prefix + "/";
-                    }
-                    name = prefix + name;
-                }
 
-                ArchiveEntry ent = builder.buildEntry(name, src[i]);
+                ArchiveEntry ent = builder.buildEntry(src[i]);
                 out.putArchiveEntry(ent);
                 if (!src[i].getResource().isDirectory()) {
                     InputStream in = null;
@@ -533,9 +526,39 @@
         public Resource getResource() { return r; }
         public ResourceCollectionFlags getCollectionFlags() { return rcFlags; }
         public ResourceFlags getResourceFlags() { return rFlags; }
+
+        /**
+         * The name the target entry will have.
+         *
+         * <p>Already takes fullpath and prefix into account.</p>
+         *
+         * <p>Ensures directory names end in slashes while file names
+         * never will.</p>
+         */
+        public String getName() {
+            String name = r.getName();
+            if (rcFlags.hasFullpath()) {
+                name = rcFlags.getFullpath();
+            } else if (rcFlags.hasPrefix()) {
+                String prefix = rcFlags.getPrefix();
+                if (!prefix.endsWith("/")) {
+                    prefix = prefix + "/";
+                }
+                name = prefix + name;
+            }
+            if (r.isDirectory() && !name.endsWith("/")) {
+                name += "/";
+            } else if (r.isDirectory() && name.endsWith("/")) {
+                name = name.substring(0, name.length() - 1);
+            }
+            return name;
+        }
     }
 
+    /**
+     * Creates an archive entry for the concrete format.
+     */
     public static interface EntryBuilder {
-        ArchiveEntry buildEntry(String name, ResourceWithFlags resource);
+        ArchiveEntry buildEntry(ResourceWithFlags resource);
     }
 }

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java?rev=804624&r1=804623&r2=804624&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
Sun Aug 16 05:34:02 2009
@@ -30,11 +30,10 @@
     public Tar() {
         super(new TarStreamFactory(),
               new ArchiveBase.EntryBuilder() {
-                public ArchiveEntry buildEntry(String name,
-                                               ArchiveBase.ResourceWithFlags r) {
+                public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
                     boolean isDir = r.getResource().isDirectory();
                     TarArchiveEntry ent =
-                        new TarArchiveEntry(name,
+                        new TarArchiveEntry(r.getName(),
                                             isDir ? TarConstants.LF_DIR
                                             : TarConstants.LF_NORMAL);
                     ent.setModTime(r.getResource().getLastModified());

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml?rev=804624&r1=804623&r2=804624&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml Sun Aug 16 05:34:02
2009
@@ -26,6 +26,18 @@
     <mkdir dir="${input}"/>
   </target>
 
+  <target name="testAgainstAntlibArTask" depends="setUp">
+    <cmp:ar destfile="${input}/test.ar">
+      <fileset dir="." includes="unar-test.xml"/>
+    </cmp:ar>
+    <cmp:unar src="${input}/test.ar" dest="${output}"/>
+    <au:assertFileExists file="${output}/unar-test.xml"/>
+    <au:assertFilesMatch
+       actual="${output}/unar-test.xml"
+       expected="unar-test.xml"
+       />
+  </target>
+
   <target name="testAgainstNativeAr" depends="setUp">
     <cmp:unar src="../resources/asf-logo.gif.ar" dest="${output}" />
     <au:assertFileExists file="${output}/asf-logo.gif"/>



Mime
View raw message