Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 698   Methods: 38
NCLOC: 370   Classes: 4
 
 Source file Conditionals Statements Methods TOTAL
Tar.java 71.4% 78.3% 73.7% 75.8%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 
 55   
 package org.apache.tools.ant.taskdefs;
 56   
 
 57   
 import java.io.BufferedOutputStream;
 58   
 import java.io.File;
 59   
 import java.io.FileInputStream;
 60   
 import java.io.FileOutputStream;
 61   
 import java.io.IOException;
 62   
 import java.io.OutputStream;
 63   
 import java.util.Enumeration;
 64   
 import java.util.Vector;
 65   
 import java.util.zip.GZIPOutputStream;
 66   
 import org.apache.tools.ant.BuildException;
 67   
 import org.apache.tools.ant.DirectoryScanner;
 68   
 import org.apache.tools.ant.Project;
 69   
 import org.apache.tools.ant.types.EnumeratedAttribute;
 70   
 import org.apache.tools.ant.types.FileSet;
 71   
 import org.apache.tools.ant.util.MergingMapper;
 72   
 import org.apache.tools.ant.util.SourceFileScanner;
 73   
 import org.apache.tools.bzip2.CBZip2OutputStream;
 74   
 import org.apache.tools.tar.TarConstants;
 75   
 import org.apache.tools.tar.TarEntry;
 76   
 import org.apache.tools.tar.TarOutputStream;
 77   
 import org.apache.tools.zip.UnixStat;
 78   
 
 79   
 /**
 80   
  * Creates a tar archive.
 81   
  *
 82   
  * @author Stefano Mazzocchi
 83   
  *         <a href="mailto:stefano@apache.org">stefano@apache.org</a>
 84   
  * @author Stefan Bodewig
 85   
  * @author Magesh Umasankar
 86   
  *
 87   
  * @since Ant 1.1
 88   
  *
 89   
  * @ant.task category="packaging"
 90   
  */
 91   
 
 92   
 public class Tar extends MatchingTask {
 93   
 
 94   
     /**
 95   
      * @deprecated Tar.WARN is deprecated and is replaced with
 96   
      *             Tar.TarLongFileMode.WARN
 97   
      */
 98   
     public static final String WARN = "warn";
 99   
     /**
 100   
      * @deprecated Tar.FAIL is deprecated and is replaced with
 101   
      *             Tar.TarLongFileMode.FAIL
 102   
      */
 103   
     public static final String FAIL = "fail";
 104   
     /**
 105   
      * @deprecated Tar.TRUNCATE is deprecated and is replaced with
 106   
      *             Tar.TarLongFileMode.TRUNCATE
 107   
      */
 108   
     public static final String TRUNCATE = "truncate";
 109   
     /**
 110   
      * @deprecated Tar.GNU is deprecated and is replaced with
 111   
      *             Tar.TarLongFileMode.GNU
 112   
      */
 113   
     public static final String GNU = "gnu";
 114   
     /**
 115   
      * @deprecated Tar.OMIT is deprecated and is replaced with
 116   
      *             Tar.TarLongFileMode.OMIT
 117   
      */
 118   
     public static final String OMIT = "omit";
 119   
 
 120   
     File tarFile;
 121   
     File baseDir;
 122   
 
 123   
     private TarLongFileMode longFileMode = new TarLongFileMode();
 124   
 
 125   
     Vector filesets = new Vector();
 126   
     Vector fileSetFiles = new Vector();
 127   
 
 128   
     /**
 129   
      * Indicates whether the user has been warned about long files already.
 130   
      */
 131   
     private boolean longWarningGiven = false;
 132   
 
 133   
     private TarCompressionMethod compression = new TarCompressionMethod();
 134   
 
 135   
     /**
 136   
      * Add a new fileset with the option to specify permissions
 137   
      */
 138  5
     public TarFileSet createTarFileSet() {
 139  5
         TarFileSet fileset = new TarFileSet();
 140  5
         filesets.addElement(fileset);
 141  5
         return fileset;
 142   
     }
 143   
 
 144   
 
 145   
     /**
 146   
      * Set is the name/location of where to create the tar file.
 147   
      * @deprecated for consistency with other tasks, please use setDestFile()
 148   
      */
 149  1
     public void setTarfile(File tarFile) {
 150  1
         this.tarFile = tarFile;
 151   
     }
 152   
 
 153   
     /**
 154   
      * Set is the name/location of where to create the tar file.
 155   
      * @since Ant 1.5
 156   
      * @param destFile The output of the tar
 157   
      */
 158  17
     public void setDestFile(File destFile) {
 159  17
         this.tarFile = destFile;
 160   
     }
 161   
 
 162   
     /**
 163   
      * This is the base directory to look in for things to tar.
 164   
      */
 165  12
     public void setBasedir(File baseDir) {
 166  12
         this.baseDir = baseDir;
 167   
     }
 168   
 
 169   
     /**
 170   
      * Set how to handle long files, those with a path&gt;100 chars.
 171   
      * Optional, default=warn.
 172   
      * <p>
 173   
      * Allowable values are
 174   
      * <ul>
 175   
      * <li>  truncate - paths are truncated to the maximum length
 176   
      * <li>  fail - paths greater than the maximim cause a build exception
 177   
      * <li>  warn - paths greater than the maximum cause a warning and GNU is used
 178   
      * <li>  gnu - GNU extensions are used for any paths greater than the maximum.
 179   
      * <li>  omit - paths greater than the maximum are omitted from the archive
 180   
      * </ul>
 181   
      * @deprecated setLongFile(String) is deprecated and is replaced with
 182   
      *             setLongFile(Tar.TarLongFileMode) to make Ant's Introspection
 183   
      *             mechanism do the work and also to encapsulate operations on
 184   
      *             the mode in its own class.
 185   
      */
 186  0
     public void setLongfile(String mode) {
 187  0
         log("DEPRECATED - The setLongfile(String) method has been deprecated."
 188   
             + " Use setLongfile(Tar.TarLongFileMode) instead.");
 189  0
         this.longFileMode = new TarLongFileMode();
 190  0
         longFileMode.setValue(mode);
 191   
     }
 192   
 
 193   
     /**
 194   
      * Set how to handle long files, those with a path&gt;100 chars.
 195   
      * Optional, default=warn.
 196   
      * <p>
 197   
      * Allowable values are
 198   
      * <ul>
 199   
      * <li>  truncate - paths are truncated to the maximum length
 200   
      * <li>  fail - paths greater than the maximim cause a build exception
 201   
      * <li>  warn - paths greater than the maximum cause a warning and GNU is used
 202   
      * <li>  gnu - GNU extensions are used for any paths greater than the maximum.
 203   
      * <li>  omit - paths greater than the maximum are omitted from the archive
 204   
      * </ul>
 205   
      */
 206  0
     public void setLongfile(TarLongFileMode mode) {
 207  0
         this.longFileMode = mode;
 208   
     }
 209   
 
 210   
     /**
 211   
      * Set compression method.
 212   
      * Allowable values are
 213   
      * <ul>
 214   
      * <li>  none - no compression
 215   
      * <li>  gzip - Gzip compression
 216   
      * <li>  bzip2 - Bzip2 compression
 217   
      * </ul>
 218   
      */
 219  8
     public void setCompression(TarCompressionMethod mode) {
 220  8
         this.compression = mode;
 221   
     }
 222   
     
 223   
     /**
 224   
      * do the business
 225   
      */
 226  18
     public void execute() throws BuildException {
 227  18
         if (tarFile == null) {
 228  2
             throw new BuildException("tarfile attribute must be set!",
 229   
                                      getLocation());
 230   
         }
 231   
 
 232  16
         if (tarFile.exists() && tarFile.isDirectory()) {
 233  1
             throw new BuildException("tarfile is a directory!",
 234   
                                      getLocation());
 235   
         }
 236   
 
 237  15
         if (tarFile.exists() && !tarFile.canWrite()) {
 238  0
             throw new BuildException("Can not write to the specified tarfile!",
 239   
                                      getLocation());
 240   
         }
 241   
 
 242  15
         Vector savedFileSets = (Vector) filesets.clone();
 243  15
         try {
 244  15
             if (baseDir != null) {
 245  11
                 if (!baseDir.exists()) {
 246  0
                     throw new BuildException("basedir does not exist!",
 247   
                                              getLocation());
 248   
                 }
 249   
 
 250   
                 // add the main fileset to the list of filesets to process.
 251  11
                 TarFileSet mainFileSet = new TarFileSet(fileset);
 252  11
                 mainFileSet.setDir(baseDir);
 253  11
                 filesets.addElement(mainFileSet);
 254   
             }
 255   
 
 256  15
             if (filesets.size() == 0) {
 257  0
                 throw new BuildException("You must supply either a basedir "
 258   
                                          + "attribute or some nested filesets.",
 259   
                                          getLocation());
 260   
             }
 261   
 
 262   
             // check if tar is out of date with respect to each
 263   
             // fileset
 264  15
             boolean upToDate = true;
 265  15
             for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
 266  16
                 TarFileSet fs = (TarFileSet) e.nextElement();
 267  16
                 String[] files = fs.getFiles(getProject());
 268   
 
 269  16
                 if (!archiveIsUpToDate(files, fs.getDir(getProject()))) {
 270  15
                     upToDate = false;
 271   
                 }
 272   
 
 273  16
                 for (int i = 0; i < files.length; ++i) {
 274  289
                     if (tarFile.equals(new File(fs.getDir(getProject()),
 275   
                                                 files[i]))) {
 276  1
                         throw new BuildException("A tar file cannot include "
 277   
                                                  + "itself", getLocation());
 278   
                     }
 279   
                 }
 280   
             }
 281   
 
 282  14
             if (upToDate) {
 283  0
                 log("Nothing to do: " + tarFile.getAbsolutePath()
 284   
                     + " is up to date.", Project.MSG_INFO);
 285  0
                 return;
 286   
             }
 287   
 
 288  14
             log("Building tar: " + tarFile.getAbsolutePath(), Project.MSG_INFO);
 289   
 
 290  14
             TarOutputStream tOut = null;
 291  14
             try {
 292  14
                 tOut = new TarOutputStream(
 293   
                     compression.compress(
 294   
                         new BufferedOutputStream(
 295   
                             new FileOutputStream(tarFile))));
 296  14
                 tOut.setDebug(true);
 297  14
                 if (longFileMode.isTruncateMode()) {
 298  0
                     tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
 299  14
                 } else if (longFileMode.isFailMode() ||
 300   
                          longFileMode.isOmitMode()) {
 301  0
                     tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
 302   
                 } else {
 303   
                     // warn or GNU
 304  14
                     tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
 305   
                 }
 306   
 
 307  14
                 longWarningGiven = false;
 308  14
                 for (Enumeration e = filesets.elements();
 309  29
                      e.hasMoreElements();) {
 310  15
                     TarFileSet fs = (TarFileSet) e.nextElement();
 311  15
                     String[] files = fs.getFiles(getProject());
 312  15
                     if (files.length > 1 && fs.getFullpath().length() > 0) {
 313  0
                         throw new BuildException("fullpath attribute may only "
 314   
                                                  + "be specified for "
 315   
                                                  + "filesets that specify a "
 316   
                                                  + "single file.");
 317   
                     }
 318  15
                     for (int i = 0; i < files.length; i++) {
 319  15
                         File f = new File(fs.getDir(getProject()), files[i]);
 320  15
                         String name = files[i].replace(File.separatorChar, '/');
 321  15
                         tarFile(f, tOut, name, fs);
 322   
                     }
 323   
                 }
 324   
             } catch (IOException ioe) {
 325  0
                 String msg = "Problem creating TAR: " + ioe.getMessage();
 326  0
                 throw new BuildException(msg, ioe, getLocation());
 327   
             } finally {
 328  14
                 if (tOut != null) {
 329  14
                     try {
 330   
                         // close up
 331  14
                         tOut.close();
 332   
                     } catch (IOException e) {}
 333   
                 }
 334   
             }
 335   
         } finally {
 336  15
             filesets = savedFileSets;
 337   
         }
 338   
     }
 339   
     
 340   
     /**
 341   
      * tar a file
 342   
      */
 343  15
     protected void tarFile(File file, TarOutputStream tOut, String vPath,
 344   
                            TarFileSet tarFileSet)
 345   
         throws IOException {
 346  15
         FileInputStream fIn = null;
 347   
 
 348  15
         String fullpath = tarFileSet.getFullpath();
 349  15
         if (fullpath.length() > 0) {
 350  3
             vPath = fullpath;
 351   
         } else {
 352   
             // don't add "" to the archive
 353  12
             if (vPath.length() <= 0) {
 354  0
                 return;
 355   
             }
 356   
 
 357  12
             if (file.isDirectory() && !vPath.endsWith("/")) {
 358  3
                 vPath += "/";
 359   
             }
 360   
 
 361  12
             String prefix = tarFileSet.getPrefix();
 362   
             // '/' is appended for compatibility with the zip task.
 363  12
             if (prefix.length() > 0 && !prefix.endsWith("/")) {
 364  0
                 prefix = prefix + "/";
 365   
             }
 366  12
             vPath = prefix + vPath;
 367   
         }
 368   
 
 369  15
         if (vPath.startsWith("/") && !tarFileSet.getPreserveLeadingSlashes()) {
 370  3
             int l = vPath.length();
 371  3
             if (l <= 1) {
 372   
                 // we would end up adding "" to the archive
 373  0
                 return;
 374   
             }
 375  3
             vPath = vPath.substring(1, l);
 376   
         }
 377   
 
 378  15
         try {
 379  15
             if (vPath.length() >= TarConstants.NAMELEN) {
 380  0
                 if (longFileMode.isOmitMode()) {
 381  0
                     log("Omitting: " + vPath, Project.MSG_INFO);
 382  0
                     return;
 383  0
                 } else if (longFileMode.isWarnMode()) {
 384  0
                     log("Entry: " + vPath + " longer than " +
 385   
                         TarConstants.NAMELEN + " characters.",
 386   
                         Project.MSG_WARN);
 387  0
                     if (!longWarningGiven) {
 388  0
                         log("Resulting tar file can only be processed "
 389   
                             + "successfully by GNU compatible tar commands",
 390   
                             Project.MSG_WARN);
 391  0
                         longWarningGiven = true;
 392   
                     }
 393  0
                 } else if (longFileMode.isFailMode()) {
 394  0
                     throw new BuildException(
 395   
                         "Entry: " + vPath + " longer than " +
 396   
                         TarConstants.NAMELEN + "characters.", getLocation());
 397   
                 }
 398   
             }
 399   
 
 400  15
             TarEntry te = new TarEntry(vPath);
 401  15
             te.setModTime(file.lastModified());
 402  15
             if (!file.isDirectory()) {
 403  12
                 te.setSize(file.length());
 404  12
                 te.setMode(tarFileSet.getMode());
 405   
             } else {
 406  3
                 te.setMode(tarFileSet.getDirMode());
 407   
             }
 408  15
             te.setUserName(tarFileSet.getUserName());
 409  15
             te.setGroupName(tarFileSet.getGroup());
 410   
 
 411  15
             tOut.putNextEntry(te);
 412   
 
 413  15
             if (!file.isDirectory()) {
 414  12
                 fIn = new FileInputStream(file);
 415   
 
 416  12
                 byte[] buffer = new byte[8 * 1024];
 417  12
                 int count = 0;
 418  12
                 do {
 419  24
                     tOut.write(buffer, 0, count);
 420  24
                     count = fIn.read(buffer, 0, buffer.length);
 421  24
                 } while (count != -1);
 422   
             }
 423   
 
 424  15
             tOut.closeEntry();
 425   
         } finally {
 426  15
             if (fIn != null) {
 427  12
                 fIn.close();
 428   
             }
 429   
         }
 430   
     }
 431   
 
 432   
     /**
 433   
      * @deprecated use the two-arg version instead.
 434   
      */
 435  0
     protected boolean archiveIsUpToDate(String[] files) {
 436  0
         return archiveIsUpToDate(files, baseDir);
 437   
     }
 438   
 
 439   
     /**
 440   
      * @since Ant 1.5.2
 441   
      */
 442  16
     protected boolean archiveIsUpToDate(String[] files, File dir) {
 443  16
         SourceFileScanner sfs = new SourceFileScanner(this);
 444  16
         MergingMapper mm = new MergingMapper();
 445  16
         mm.setTo(tarFile.getAbsolutePath());
 446  16
         return sfs.restrict(files, dir, null, mm).length == 0;
 447   
     }
 448   
 
 449   
     /**
 450   
      * This is a FileSet with the option to specify permissions
 451   
      */
 452   
     public static class TarFileSet extends FileSet {
 453   
         private String[] files = null;
 454   
 
 455   
         private int fileMode = UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM;
 456   
         private int dirMode = UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM;
 457   
 
 458   
         private String userName = "";
 459   
         private String groupName = "";
 460   
         private String prefix = "";
 461   
         private String fullpath = "";
 462   
         private boolean preserveLeadingSlashes = false;
 463   
 
 464  11
         public TarFileSet(FileSet fileset) {
 465  11
             super(fileset);
 466   
         }
 467   
 
 468  5
         public TarFileSet() {
 469  5
             super();
 470   
         }
 471   
 
 472   
         /**
 473   
          *  Get a list of files and directories specified in the fileset.
 474   
          *  @return a list of file and directory names, relative to
 475   
          *    the baseDir for the project.
 476   
          */
 477  31
         public String[] getFiles(Project p) {
 478  31
             if (files == null) {
 479  16
                 DirectoryScanner ds = getDirectoryScanner(p);
 480  16
                 String[] directories = ds.getIncludedDirectories();
 481  16
                 String[] filesPerSe = ds.getIncludedFiles();
 482  16
                 files = new String [directories.length + filesPerSe.length];
 483  16
                 System.arraycopy(directories, 0, files, 0, directories.length);
 484  16
                 System.arraycopy(filesPerSe, 0, files, directories.length,
 485   
                         filesPerSe.length);
 486   
             }
 487   
 
 488  31
             return files;
 489   
         }
 490   
 
 491   
         /**
 492   
          * A 3 digit octal string, specify the user, group and 
 493   
          * other modes in the standard Unix fashion; 
 494   
          * optional, default=0644
 495   
          */
 496  0
         public void setMode(String octalString) {
 497  0
             this.fileMode = 
 498   
                 UnixStat.FILE_FLAG | Integer.parseInt(octalString, 8);
 499   
         }
 500   
 
 501  12
         public int getMode() {
 502  12
             return fileMode;
 503   
         }
 504   
 
 505   
         /**
 506   
          * A 3 digit octal string, specify the user, group and 
 507   
          * other modes in the standard Unix fashion; 
 508   
          * optional, default=0755
 509   
          *
 510   
          * @since Ant 1.6
 511   
          */
 512  0
         public void setDirMode(String octalString) {
 513  0
             this.dirMode = 
 514   
                 UnixStat.DIR_FLAG | Integer.parseInt(octalString, 8);
 515   
         }
 516   
 
 517   
         /**
 518   
          * @since Ant 1.6
 519   
          */
 520  3
         public int getDirMode() {
 521  3
             return dirMode;
 522   
         }
 523   
 
 524   
         /**
 525   
          * The username for the tar entry 
 526   
          * This is not the same as the UID, which is
 527   
          * not currently set by the task.
 528   
          */
 529  0
         public void setUserName(String userName) {
 530  0
             this.userName = userName;
 531   
         }
 532   
 
 533  15
         public String getUserName() {
 534  15
             return userName;
 535   
         }
 536   
 
 537   
         /**
 538   
          * The groupname for the tar entry; optional, default=""
 539   
          * This is not the same as the GID, which is
 540   
          * not currently set by the task.
 541   
          */
 542  0
         public void setGroup(String groupName) {
 543  0
             this.groupName = groupName;
 544   
         }
 545   
 
 546  15
         public String getGroup() {
 547  15
             return groupName;
 548   
         }
 549   
 
 550   
         /**
 551   
          * If the prefix attribute is set, all files in the fileset
 552   
          * are prefixed with that path in the archive.
 553   
          * optional.
 554   
          */
 555  2
         public void setPrefix(String prefix) {
 556  2
             this.prefix = prefix;
 557   
         }
 558   
 
 559  12
         public String getPrefix() {
 560  12
             return prefix;
 561   
         }
 562   
 
 563   
         /**
 564   
          * If the fullpath attribute is set, the file in the fileset
 565   
          * is written with that path in the archive. The prefix attribute,
 566   
          * if specified, is ignored. It is an error to have more than one file specified in
 567   
          * such a fileset.
 568   
          */
 569  3
         public void setFullpath(String fullpath) {
 570  3
             this.fullpath = fullpath;
 571   
         }
 572   
 
 573  15
         public String getFullpath() {
 574  15
             return fullpath;
 575   
         }
 576   
 
 577   
         /**
 578   
          * Flag to indicates whether leading `/'s should
 579   
          * be preserved in the file names.
 580   
          * Optional, default is <code>false</code>.
 581   
          */
 582  0
         public void setPreserveLeadingSlashes(boolean b) {
 583  0
             this.preserveLeadingSlashes = b;
 584   
         }
 585   
 
 586  3
         public boolean getPreserveLeadingSlashes() {
 587  3
             return preserveLeadingSlashes;
 588   
         }
 589   
     }
 590   
 
 591   
     /**
 592   
      * Set of options for long file handling in the task. 
 593   
      *
 594   
      * @author Magesh Umasankar
 595   
      */
 596   
     public static class TarLongFileMode extends EnumeratedAttribute {
 597   
 
 598   
         // permissable values for longfile attribute
 599   
         public static final String WARN = "warn";
 600   
         public static final String FAIL = "fail";
 601   
         public static final String TRUNCATE = "truncate";
 602   
         public static final String GNU = "gnu";
 603   
         public static final String OMIT = "omit";
 604   
 
 605   
         private final String[] validModes = {WARN, FAIL, TRUNCATE, GNU, OMIT};
 606   
 
 607  21
         public TarLongFileMode() {
 608  21
             super();
 609  21
             setValue(WARN);
 610   
         }
 611   
 
 612  22
         public String[] getValues() {
 613  22
             return validModes;
 614   
         }
 615   
 
 616  14
         public boolean isTruncateMode() {
 617  14
             return TRUNCATE.equalsIgnoreCase(getValue());
 618   
         }
 619   
 
 620  0
         public boolean isWarnMode() {
 621  0
             return WARN.equalsIgnoreCase(getValue());
 622   
         }
 623   
 
 624  0
         public boolean isGnuMode() {
 625  0
             return GNU.equalsIgnoreCase(getValue());
 626   
         }
 627   
 
 628  14
         public boolean isFailMode() {
 629  14
             return FAIL.equalsIgnoreCase(getValue());
 630   
         }
 631   
 
 632  14
         public boolean isOmitMode() {
 633  14
             return OMIT.equalsIgnoreCase(getValue());
 634   
         }
 635   
     }
 636   
 
 637   
     /**
 638   
      * Valid Modes for Compression attribute to Tar Task
 639   
      *
 640   
      */
 641   
     public static final class TarCompressionMethod extends EnumeratedAttribute {
 642   
 
 643   
         // permissable values for compression attribute
 644   
         /**
 645   
          *    No compression
 646   
          */
 647   
         private static final String NONE = "none";
 648   
         /**
 649   
          *    GZIP compression
 650   
          */
 651   
         private static final String GZIP = "gzip";
 652   
         /**
 653   
          *    BZIP2 compression
 654   
          */
 655   
         private static final String BZIP2 = "bzip2";
 656   
 
 657   
 
 658   
         /**
 659   
          * Default constructor
 660   
          */
 661  29
         public TarCompressionMethod() {
 662  29
             super();
 663  29
             setValue(NONE);
 664   
         }
 665   
 
 666   
         /**
 667   
          *  Get valid enumeration values.
 668   
          *  @return valid enumeration values
 669   
          */
 670  38
         public String[] getValues() {
 671  38
             return new String[] { NONE, GZIP, BZIP2 };
 672   
         }
 673   
 
 674   
         /**
 675   
          *  This method wraps the output stream with the
 676   
          *     corresponding compression method
 677   
          *
 678   
          *  @param ostream output stream
 679   
          *  @return output stream with on-the-fly compression
 680   
          *  @exception IOException thrown if file is not writable
 681   
          */
 682  14
         private OutputStream compress(final OutputStream ostream)
 683   
             throws IOException {
 684  14
             final String value = getValue();
 685  14
             if (GZIP.equals(value)) {
 686  4
                 return new GZIPOutputStream(ostream);
 687   
             } else {
 688  10
                 if (BZIP2.equals(value)) {
 689  4
                     ostream.write('B');
 690  4
                     ostream.write('Z');
 691  4
                     return new CBZip2OutputStream(ostream);
 692   
                 }
 693   
             }
 694  6
             return ostream;
 695   
         }
 696   
     }
 697   
 }
 698