[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/phing/tasks/ext/ -> UntarTask.php (source)

   1  <?php
   2  /*
   3   *
   4   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   5   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   6   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   7   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   8   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   9   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  10   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  11   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  12   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  13   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  14   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  15   *
  16   * This software consists of voluntary contributions made by many individuals
  17   * and is licensed under the LGPL. For more information please see
  18   * <http://phing.info>.
  19   */
  20  
  21  require_once 'phing/tasks/ext/ExtractBaseTask.php';
  22  
  23  /**
  24   * Extracts one or several tar archives using PEAR Archive_Tar
  25   *
  26   * @author    Joakim Bodin <joakim.bodin+phing@gmail.com>
  27   * @version   $Revision: 1.0 $
  28   * @package   phing.tasks.ext
  29   * @since     2.2.0
  30   */
  31  class UntarTask extends ExtractBaseTask {
  32      
  33      /**
  34       * Ensures that PEAR lib exists.
  35       */
  36      public function init() {
  37          include_once 'Archive/Tar.php';
  38          if (!class_exists('Archive_Tar')) {
  39              throw new BuildException("You must have installed the PEAR Archive_Tar class in order to use UntarTask.");
  40          }
  41      }
  42      
  43      protected function extractArchive(PhingFile $tarfile)
  44      {
  45          $this->log("Extracting tar file: " . $tarfile->__toString() . ' to ' . $this->todir->__toString(), PROJECT_MSG_INFO);
  46          
  47          try {
  48              $tar = $this->initTar($tarfile);
  49              if(!$tar->extractModify($this->todir->getAbsolutePath(), $this->removepath)) {
  50                  throw new BuildException('Failed to extract tar file: ' . $tarfile->getAbsolutePath());
  51              }
  52          } catch (IOException $ioe) {
  53              $msg = "Could not extract tar file: " . $ioe->getMessage();
  54              throw new BuildException($msg, $ioe, $this->getLocation());
  55          }
  56      }
  57      
  58      protected function listArchiveContent(PhingFile $tarfile)
  59      {
  60          $tar = $this->initTar($tarfile);
  61          return $tar->listContent();
  62      }
  63      
  64      /**
  65       * Init a Archive_Tar class with correct compression for the given file.
  66       *
  67       * @param PhingFile $tarfile
  68       * @return Archive_Tar the tar class instance
  69       */
  70      private function initTar(PhingFile $tarfile)
  71      {
  72          $compression = null;
  73          $tarfileName = $tarfile->getName();
  74          $mode = substr($tarfileName, strrpos($tarfileName, '.'));
  75          switch($mode) {
  76              case '.gz':
  77                  $compression = 'gz';
  78                  break;
  79              case '.bz2':
  80                  $compression = 'bz2';
  81                  break;
  82              case '.tar':
  83                  break;
  84              default:
  85                  $this->log('Ignoring unknown compression mode: ' . $mode, PROJECT_MSG_WARN);
  86          }
  87          
  88          return new Archive_Tar($tarfile->getAbsolutePath(), $compression);
  89      }
  90  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7