ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umag...@apache.org
Subject cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs TarTest.java
Date Mon, 04 Feb 2002 20:44:17 GMT
umagesh     02/02/04 12:44:17

  Modified:    .        WHATSNEW
               src/etc/testcases/taskdefs tar.xml
               src/main/org/apache/tools/ant/taskdefs Tar.java
               src/testcases/org/apache/tools/ant/taskdefs TarTest.java
  Log:
  New attributes to tarfileset to allow equivalent of tar -P option
  
  PR: 5874
  
  Submitted by: Stefan Heimann (mail@stefanheimann.net)
  
  Revision  Changes    Path
  1.204     +3 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.203
  retrieving revision 1.204
  diff -u -r1.203 -r1.204
  --- WHATSNEW	3 Feb 2002 01:53:34 -0000	1.203
  +++ WHATSNEW	4 Feb 2002 20:44:16 -0000	1.204
  @@ -70,6 +70,9 @@
   
   Other changes:
   --------------
  +* TarFileset takes in three new attributes - fullpath, prefix
  +  and preserveLeadingSlashes.
  +
   * <move> attempts to rename the directory, if everything inside it is
     included, before performing file-by-file moves.  This attempt will
     be done only if filtering is off and if mappers are not used.  This
  
  
  
  1.9       +11 -0     jakarta-ant/src/etc/testcases/taskdefs/tar.xml
  
  Index: tar.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/tar.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- tar.xml	3 Feb 2002 22:23:37 -0000	1.8
  +++ tar.xml	4 Feb 2002 20:44:16 -0000	1.9
  @@ -44,6 +44,15 @@
       <untar src="test7.tar" dest="."/>
     </target>
   
  +  <target name="test8">
  +    <tar destfile="test8.tar">
  +      <tarfileset dir="." fullpath="/test8.xml">
  +        <include name="tar.xml"/>
  +      </tarfileset>
  +    </tar>
  +    <untar src="test8.tar" dest="."/>
  +  </target>
  +
     <target name="cleanup"> 
       <delete file="test4.tar"/>
       <delete file="test5.tar"/>
  @@ -52,6 +61,8 @@
       <delete dir="test7dir"/>
       <delete dir="test7-prefix"/>
       <delete file="test7.tar"/>
  +    <delete file="test8.tar"/>
  +    <delete file="test8.xml"/>
     </target>
   
     <target name="feather">
  
  
  
  1.24      +50 -13    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java
  
  Index: Tar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Tar.java	3 Feb 2002 22:23:37 -0000	1.23
  +++ Tar.java	4 Feb 2002 20:44:16 -0000	1.24
  @@ -265,6 +265,10 @@
               for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
                   TarFileSet fs = (TarFileSet)e.nextElement();
                   String[] files = fs.getFiles(project);
  +                if (files.length > 1 && fs.getFullpath().length() > 0) {
  +                    throw new BuildException("fullpath attribute may only be specified
for " +
  +                                             "filesets that specify a single file.");
  +                }
                   for (int i = 0; i < files.length; i++) {
                       File f = new File(fs.getDir(project), files[i]);
                       String name = files[i].replace(File.separatorChar,'/');
  @@ -291,13 +295,34 @@
       {
           FileInputStream fIn = null;
   
  -        // don't add "" to the archive
  -        if (vPath.length() <= 0) {
  -            return;
  +        String fullpath = tarFileSet.getFullpath();
  +        if (fullpath.length() > 0) {
  +            vPath = fullpath;
  +        } else {
  +            // don't add "" to the archive
  +            if (vPath.length() <= 0) {
  +                return;
  +            }
  +        
  +            if (file.isDirectory() && !vPath.endsWith("/")) {
  +                vPath += "/";
  +            }
  +        
  +            String prefix = tarFileSet.getPrefix();
  +            // '/' is appended for compatibility with the zip task.
  +            if (prefix.length() > 0 && !prefix.endsWith("/")) {
  +                prefix = prefix + "/";
  +            }
  +            vPath = prefix + vPath;
           }
   
  -        if (file.isDirectory() && !vPath.endsWith("/")) {
  -            vPath += "/";
  +        if (vPath.startsWith("/") && !tarFileSet.getPreserveLeadingSlashes()) {
  +            int l = vPath.length();
  +            if (l <= 1) {
  +                // we would end up adding "" to the archive
  +                return;
  +            } 
  +            vPath = vPath.substring(1, l);
           }
   
           try {
  @@ -320,13 +345,7 @@
                   }
               }
   
  -            String prefix = tarFileSet.getPrefix();
  -            // '/' is appended for compatibility with the zip task.
  -            if(prefix.length() > 0 && !prefix.endsWith("/")) {
  -                prefix = prefix + "/";
  -            }
  -
  -            TarEntry te = new TarEntry(prefix + vPath);
  +            TarEntry te = new TarEntry(vPath);
               te.setModTime(file.lastModified());
               if (!file.isDirectory()) {
                   te.setSize(file.length());
  @@ -371,7 +390,9 @@
           private String userName = "";
           private String groupName = "";
           private String prefix = "";
  -
  +        private String fullpath = "";
  +        private boolean preserveLeadingSlashes = false;
  +        
           public TarFileSet(FileSet fileset) {
               super(fileset);
           }
  @@ -429,6 +450,22 @@
   
           public String getPrefix() {
               return prefix;
  +        }
  +
  +        public void setFullpath(String fullpath) {
  +            this.fullpath = fullpath;
  +        }
  +
  +        public String getFullpath() {
  +            return fullpath;
  +        }
  +
  +        public void setPreserveLeadingSlashes(boolean b) {
  +            this.preserveLeadingSlashes = b;
  +        }
  +
  +        public boolean getPreserveLeadingSlashes() {
  +            return preserveLeadingSlashes;
           }
       }
   
  
  
  
  1.9       +9 -0      jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java
  
  Index: TarTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TarTest.java	3 Feb 2002 22:23:37 -0000	1.8
  +++ TarTest.java	4 Feb 2002 20:44:16 -0000	1.9
  @@ -115,6 +115,15 @@
           }
       }
   
  +    public void test8() {
  +        executeTarget("test8");
  +        java.io.File f1
  +            = new java.io.File("src/etc/testcases/taskdefs/test8.xml");
  +        if (! f1.exists()) {
  +            fail("The fullpath attribute or the preserveLeadingSlashes attribute does not
work propertly");
  +        }
  +    }
  +
       public void tearDown() {
           executeTarget("cleanup");
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message