Changeset 110
- Timestamp:
- 08/17/06 16:23:36 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.2/classes/phing/tasks/ext/ExtractBaseTask.php
r107 r110 30 30 */ 31 31 abstract class ExtractBaseTask extends MatchingTask { 32 /** 33 * @var PhingFile $file 34 */ 32 35 protected $file; 33 protected $destDir; 36 /** 37 * @var PhingFile $todir 38 */ 39 protected $todir; 40 protected $removepath; 34 41 protected $filesets = array(); // all fileset objects assigned to this task 35 42 … … 56 63 * @param PhingFile $baseDir 57 64 */ 58 public function setDestDir(PhingFile $destDir) { 59 $this->destDir = $destDir; 65 public function setToDir(PhingFile $todir) { 66 $this->todir = $todir; 67 } 68 69 public function setRemovePath($removepath) 70 { 71 $this->removepath = $removepath; 60 72 } 61 73 … … 68 80 $this->validateAttributes(); 69 81 70 $destinationFileSet = new FileSet();71 $destinationFileSet->setDir($this->destDir);72 $destinationDirScanner = $destinationFileSet->getDirectoryScanner($this->project);73 $destinationFiles = $destinationDirScanner->getIncludedFiles();74 75 82 $filesToExtract = array(); 76 83 if ($this->file !== null) { … … 78 85 $filesToExtract[] = $this->file; 79 86 } else { 80 $this->log('Nothing to do: ' . $this-> destDir->getAbsolutePath() . ' is up to date for ' . $this->file->getCanonicalPath(), PROJECT_MSG_INFO);87 $this->log('Nothing to do: ' . $this->todir->getAbsolutePath() . ' is up to date for ' . $this->file->getCanonicalPath(), PROJECT_MSG_INFO); 81 88 } 82 89 } … … 97 104 $filesToExtract[] = $compressedArchiveFile; 98 105 } else { 99 $this->log('Nothing to do: ' . $this-> destDir->getAbsolutePath() . ' is up to date for ' . $compressedArchiveFile->getCanonicalPath(), PROJECT_MSG_INFO);106 $this->log('Nothing to do: ' . $this->todir->getAbsolutePath() . ' is up to date for ' . $compressedArchiveFile->getCanonicalPath(), PROJECT_MSG_INFO); 100 107 } 101 108 } … … 109 116 abstract protected function extractArchive(PhingFile $compressedArchiveFile); 110 117 111 abstract protected function isDestinationUpToDate(PhingFile $compressedArchiveFile); 118 /** 119 * @param array $files array of filenames 120 * @param PhingFile $dir 121 * @return boolean 122 */ 123 protected function isDestinationUpToDate(PhingFile $compressedArchiveFile) { 124 if (!$compressedArchiveFile->exists()) { 125 throw new BuildException("Could not find file " . $compressedArchiveFile->__toString() . " to extract."); 126 } 127 128 $compressedArchiveContent = $this->listArchiveContent($compressedArchiveFile); 129 if(is_array($compressedArchiveContent)) { 130 131 $fileSystem = FileSystem::getFileSystem(); 132 $compressArchiveFilename = $compressArchivePathInfo['filename']; 133 foreach ($compressedArchiveContent as $compressArchivePathInfo) { 134 if(!empty($this->removepath) && strlen($compressArchiveFilename) >= strlen($this->removepath)) 135 { 136 $compressArchiveFilename = preg_replace('/^' . $this->removepath . '/','', $compressArchiveFilename); 137 } 138 $compressArchivePath = new PhingFile($this->todir, $compressArchiveFilename); 139 140 if(!$compressArchivePath->exists() || 141 $fileSystem->compareMTimes($compressedArchiveFile->getCanonicalPath(), $compressArchivePath->getCanonicalPath()) == 1) { 142 return false; 143 } 144 } 145 146 } 147 148 return true; 149 } 150 151 abstract protected function listArchiveContent(PhingFile $compressedArchiveFile); 112 152 113 153 /** … … 124 164 } 125 165 126 if ($this-> destDir === null) {127 throw new BuildException(" Destdir must be set.");166 if ($this->todir === null) { 167 throw new BuildException("todir must be set."); 128 168 } 129 169 130 if ($this-> destDir !== null && $this->destDir->exists() && !$this->destDir->isDirectory()) {131 throw new BuildException(" Destdir must be a directory.");170 if ($this->todir !== null && $this->todir->exists() && !$this->todir->isDirectory()) { 171 throw new BuildException("todir must be a directory."); 132 172 } 133 173 branches/2.2/classes/phing/tasks/ext/UntarTask.php
r107 r110 43 43 protected function extractArchive(PhingFile $tarfile) 44 44 { 45 $this->log("Extracting tar file: " . $tarfile->__toString() . ' to ' . $this-> destDir->__toString(), PROJECT_MSG_INFO);45 $this->log("Extracting tar file: " . $tarfile->__toString() . ' to ' . $this->todir->__toString(), PROJECT_MSG_INFO); 46 46 47 47 try { 48 48 $tar = $this->initTar($tarfile); 49 if(!$tar->extract ($this->destDir->getAbsolutePath())) {50 throw new BuildException('Failed to extract tar file: ' . $tar->errorInfo(true));49 if(!$tar->extractModify($this->todir->getAbsolutePath(), $this->removepath)) { 50 throw new BuildException('Failed to extract tar file: ' . $tarfile->getAbsolutePath()); 51 51 } 52 52 } catch (IOException $ioe) { … … 56 56 } 57 57 58 /** 59 * @param array $files array of filenames 60 * @param PhingFile $dir 61 * @return boolean 62 */ 63 protected function isDestinationUpToDate(PhingFile $tarfile) { 64 if (!$tarfile->exists()) { 65 throw new BuildException("Could not find file " . $tarfile->__toString() . " to untar."); 66 } 67 58 protected function listArchiveContent(PhingFile $tarfile) 59 { 68 60 $tar = $this->initTar($tarfile); 69 $tarContents = $tar->listContent(); 70 if(is_array($tarContents)) { 71 /* Get first file/dir to match against destination directory path to find 72 when the file was last unziped */ 73 $firstPathInfo = current($tarContents); 74 $firstPath = new PhingFile($this->destDir, $firstPathInfo['filename']); 75 76 $fileSystem = FileSystem::getFileSystem(); 77 if(!$firstPath->exists() || $fileSystem->compareMTimes($tarfile->getCanonicalPath(), $firstPath->getCanonicalPath()) == 1) { 78 return false; 79 } 80 } 81 82 return true; 61 return $tar->listContent(); 83 62 } 84 63 branches/2.2/classes/phing/tasks/ext/UnzipTask.php
r107 r110 36 36 protected function extractArchive(PhingFile $zipfile) 37 37 { 38 $extractParams = array('add_path' => $this->destDir->getAbsolutePath()); 39 $this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->destDir->__toString(), PROJECT_MSG_INFO); 38 $extractParams = array('add_path' => $this->todir->getAbsolutePath()); 39 if(!empty($this->removepath)) 40 { 41 $extractParams['remove_path'] = $this->removepath; 42 } 43 44 $this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), PROJECT_MSG_INFO); 40 45 41 46 try { … … 45 50 if(is_array($extractResponse)) { 46 51 foreach ($extractResponse as $extractedPath) { 47 $this->log('Extracted' . $extractedPath['stored_filename'] . ' to ' . $this-> destDir->__toString(), PROJECT_MSG_VERBOSE);52 $this->log('Extracted' . $extractedPath['stored_filename'] . ' to ' . $this->todir->__toString(), PROJECT_MSG_VERBOSE); 48 53 } 49 54 } else if ($extractResponse === 0) { … … 56 61 } 57 62 58 /** 59 * @param array $files array of filenames 60 * @param PhingFile $dir 61 * @return boolean 62 */ 63 protected function isDestinationUpToDate(PhingFile $zipfile) { 64 if (!$zipfile->exists()) { 65 throw new BuildException("Could not find file " . $zipfile->__toString() . " to unzip."); 66 } 67 63 protected function listArchiveContent(PhingFile $zipfile) 64 { 68 65 $zip = new Archive_Zip($zipfile->getAbsolutePath()); 69 $zipContents = $zip->listContent(); 70 if(is_array($zipContents)) { 71 /* Get first file/dir to match against destination directory path to find 72 when the file was last unziped */ 73 $firstPathInfo = current($zipContents); 74 $firstPath = new PhingFile($this->destDir, $firstPathInfo['filename']); 75 76 $fileSystem = FileSystem::getFileSystem(); 77 if(!$firstPath->exists() || $fileSystem->compareMTimes($zipfile->getCanonicalPath(), $firstPath->getCanonicalPath()) == 1) { 78 return false; 79 } 80 } 81 82 return true; 66 return $zip->listContent(); 83 67 } 84 68 }
