| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | require_once "phing/Task.php"; |
|---|
| 11 | require_once 'phing/system/io/PhingFile.php'; |
|---|
| 12 | |
|---|
| 13 | class ManifestTask extends Task { |
|---|
| 14 | |
|---|
| 15 | var $taskname = 'manifest'; |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | private $file = null; |
|---|
| 21 | |
|---|
| 22 | private $filesets = array(); |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | private $checksum = false; |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | public function setFile(PhingFile $file) { |
|---|
| 34 | $this->file = $file; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | public function setChecksum($bool) { |
|---|
| 41 | $this->checksum = $bool; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | function createFileSet() { |
|---|
| 51 | $num = array_push($this->filesets, new FileSet()); |
|---|
| 52 | return $this->filesets[$num-1]; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | public function init() { |
|---|
| 59 | |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | public function main() { |
|---|
| 66 | $project = $this->getProject(); |
|---|
| 67 | $this->validateAttributes(); |
|---|
| 68 | |
|---|
| 69 | $this->log("Building Manifest: " . $this->file->__toString(), Project::MSG_INFO); |
|---|
| 70 | |
|---|
| 71 | foreach($this->filesets as $fs) { |
|---|
| 72 | |
|---|
| 73 | $dir = $fs->getDir($this->project); |
|---|
| 74 | |
|---|
| 75 | $ds = $fs->getDirectoryScanner($project); |
|---|
| 76 | $fromDir = $fs->getDir($project); |
|---|
| 77 | $srcFiles = $ds->getIncludedFiles(); |
|---|
| 78 | $srcDirs = $ds->getIncludedDirectories(); |
|---|
| 79 | |
|---|
| 80 | foreach($ds->getIncludedFiles() as $file_path) { |
|---|
| 81 | $line = $file_path; |
|---|
| 82 | if($this->checksum) { |
|---|
| 83 | $line .= "\t".md5_file($dir.'/'.$file_path); |
|---|
| 84 | } |
|---|
| 85 | $line .= "\n"; |
|---|
| 86 | $manifest[] = $line; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | file_put_contents($this->file,$manifest); |
|---|
| 92 | |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | |
|---|
| 102 | protected function validateAttributes() { |
|---|
| 103 | |
|---|
| 104 | if ($this->file === null && count($this->filesets) === 0) { |
|---|
| 105 | throw new BuildException("Specify at least sources and destination - a file or a fileset."); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | if ($this->file !== null && $this->file->exists() && $this->file->isDirectory()) { |
|---|
| 109 | throw new BuildException("Destination file cannot be a directory."); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | ?> |
|---|