Beispiel #1
0
 /**
  * Append the file(s).
  *
  * {@inheritdoc}
  */
 public function main()
 {
     $this->validate();
     try {
         if ($this->to !== null) {
             // create a file writer to append to "to" file.
             $writer = new FileWriter($this->to, $this->append);
         } else {
             $writer = new LogWriter($this);
         }
         if ($this->text !== null) {
             // simply append the text
             if ($this->to instanceof PhingFile) {
                 $this->log("Appending string to " . $this->to->getPath());
             }
             $text = $this->text;
             if ($this->filtering) {
                 $fr = $this->getFilteredReader(new StringReader($text));
                 $text = $fr->read();
             }
             $text = $this->appendHeader($text);
             $text = $this->appendFooter($text);
             $writer->write($text);
         } else {
             // append explicitly-specified file
             if ($this->file !== null) {
                 try {
                     $this->appendFile($writer, $this->file);
                 } catch (Exception $ioe) {
                     $this->log("Unable to append contents of file " . $this->file->getAbsolutePath() . ": " . $ioe->getMessage(), Project::MSG_WARN);
                 }
             }
             // append any files in filesets
             foreach ($this->filesets as $fs) {
                 try {
                     if ($fs instanceof Path) {
                         $files = $fs->listPaths();
                         $this->appendFiles($writer, $files);
                     } elseif ($fs instanceof FileSet) {
                         $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
                         $this->appendFiles($writer, $files, $fs->getDir($this->project));
                     }
                 } catch (BuildException $be) {
                     if (strpos($be->getMessage(), 'is the same as the output file') === false) {
                         $this->log($be->getMessage(), Project::MSG_WARN);
                     } else {
                         throw new BuildException($be->getMessage());
                     }
                 } catch (IOException $ioe) {
                     throw new BuildException($ioe);
                 }
             }
             /** @var FileList $list */
             foreach ($this->fileList as $list) {
                 $dir = $list->getDir($this->project);
                 $files = $list->getFiles($this->project);
                 foreach ($files as $file) {
                     $this->appendFile($writer, new PhingFile($dir, $file));
                 }
             }
         }
     } catch (Exception $e) {
         throw new BuildException($e);
     }
     $writer->close();
 }