Changeset 220
- Timestamp:
- 08/21/07 00:03:13 (1 year ago)
- Files:
-
- trunk/classes/phing/tasks/ext/TarTask.php (modified) (1 diff)
- trunk/classes/phing/tasks/ext/ZipTask.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/classes/phing/tasks/ext/TarTask.php
r144 r220 242 242 for ($i=0, $fcount=count($files); $i < $fcount; $i++) { 243 243 $f = new PhingFile($fsBasedir, $files[$i]); 244 $filesToTar[] = $f->getAbsolutePath(); 244 $filesToTar[] = $f->getAbsolutePath(); 245 $this->log("Adding file " . $f->getPath() . " to archive.", Project::MSG_VERBOSE); 245 246 } 246 247 $tar->addModify($filesToTar, '', $fsBasedir->getAbsolutePath()); trunk/classes/phing/tasks/ext/ZipTask.php
r191 r220 37 37 class ZipTask extends MatchingTask { 38 38 39 /** 40 * @var PhingFile 41 */ 39 42 private $zipFile; 43 44 /** 45 * @var PhingFile 46 */ 40 47 private $baseDir; 41 48 49 /** 50 * Whether to include empty dirs in the archive. 51 */ 52 private $includeEmpty = true; 53 42 54 private $filesets = array(); 43 55 private $fileSetFiles = array(); … … 48 60 */ 49 61 public function createFileSet() { 50 $this->fileset = new FileSet();62 $this->fileset = new ZipFileSet(); 51 63 $this->filesets[] = $this->fileset; 52 64 return $this->fileset; … … 69 81 } 70 82 83 /** 84 * Set the include empty dirs flag. 85 * @param boolean Flag if empty dirs should be tarred too 86 * @return void 87 * @access public 88 */ 89 function setIncludeEmptyDirs($bool) { 90 $this->includeEmpty = (boolean) $bool; 91 } 92 71 93 /** 72 94 * do the work … … 116 138 $upToDate = true; 117 139 foreach($this->filesets as $fs) { 118 $ds = $fs->getDirectoryScanner($this->project); 119 $files = $ds->getIncludedFiles(); 140 $files = $fs->getFiles($this->project, $this->includeEmpty); 120 141 if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) { 121 142 $upToDate = false; … … 137 158 $zip = new Archive_Zip($this->zipFile->getAbsolutePath()); 138 159 139 foreach($this->filesets as $fs) { 140 $ds = $fs->getDirectoryScanner($this->project); 141 $files = $ds->getIncludedFiles(); 142 143 // FIXME 144 // Current model is only adding directories implicitly. This 145 // won't add any empty directories. Perhaps modify FileSet::getFiles() 146 // to also include empty directories. Not high priority, since non-inclusion 147 // of empty dirs is probably not unexpected behavior for ZipTask. 160 foreach($this->filesets as $fs) { 161 162 $files = $fs->getFiles($this->project, $this->includeEmpty); 163 148 164 $fsBasedir = (null != $this->baseDir) ? $this->baseDir : 149 165 $fs->getDir($this->project); … … 152 168 for ($i=0, $fcount=count($files); $i < $fcount; $i++) { 153 169 $f = new PhingFile($fsBasedir, $files[$i]); 154 $filesToZip[] = $f->getAbsolutePath(); 170 $filesToZip[] = $f->getAbsolutePath(); 171 $this->log("Adding " . $f->getPath() . " to archive.", Project::MSG_VERBOSE); 155 172 } 156 173 $zip->add($filesToZip, array('remove_path' => $fsBasedir->getCanonicalPath())); … … 180 197 181 198 } 199 200 201 202 203 /** 204 * This is a FileSet with the to specify permissions. 205 * 206 * Permissions are currently not implemented by PEAR Archive_Tar, 207 * but hopefully they will be in the future. 208 * 209 */ 210 class ZipFileSet extends FileSet { 211 212 private $files = null; 213 214 /** 215 * Get a list of files and directories specified in the fileset. 216 * @return array a list of file and directory names, relative to 217 * the baseDir for the project. 218 */ 219 public function getFiles(Project $p, $includeEmpty = true) { 220 221 if ($this->files === null) { 222 223 $ds = $this->getDirectoryScanner($p); 224 $this->files = $ds->getIncludedFiles(); 225 226 if ($includeEmpty) { 227 228 // first any empty directories that will not be implicitly added by any of the files 229 $implicitDirs = array(); 230 foreach($this->files as $file) { 231 $implicitDirs[] = dirname($file); 232 } 233 234 $incDirs = $ds->getIncludedDirectories(); 235 236 // we'll need to add to that list of implicit dirs any directories 237 // that contain other *directories* (and not files), since otherwise 238 // we get duplicate directories in the resulting tar 239 foreach($incDirs as $dir) { 240 foreach($incDirs as $dircheck) { 241 if (!empty($dir) && $dir == dirname($dircheck)) { 242 $implicitDirs[] = $dir; 243 } 244 } 245 } 246 247 $implicitDirs = array_unique($implicitDirs); 248 249 // Now add any empty dirs (dirs not covered by the implicit dirs) 250 // to the files array. 251 252 foreach($incDirs as $dir) { // we cannot simply use array_diff() since we want to disregard empty/. dirs 253 if ($dir != "" && $dir != "." && !in_array($dir, $implicitDirs)) { 254 // it's an empty dir, so we'll add it. 255 $this->files[] = $dir; 256 } 257 } 258 } // if $includeEmpty 259 260 } // if ($this->files===null) 261 262 return $this->files; 263 } 264 265 }
