/**
  * read in lines and execute them
  * @param Reader $reader
  * @param null $out
  * @throws BuildException
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $buffer = '';
     if (is_array($this->filterChains) && !empty($this->filterChains)) {
         $in = FileUtils::getChainedReader(new BufferedReader($reader), $this->filterChains, $this->getProject());
         while (-1 !== ($read = $in->read())) {
             // -1 indicates EOF
             $buffer .= $read;
         }
         $lines = explode("\n", $buffer);
     } else {
         $in = new BufferedReader($reader);
         while (($line = $in->readLine()) !== null) {
             $lines[] = $line;
         }
     }
     try {
         foreach ($lines as $line) {
             $line = trim($line);
             $line = ProjectConfigurator::replaceProperties($this->project, $line, $this->project->getProperties());
             if (StringHelper::startsWith("//", $line) || StringHelper::startsWith("--", $line) || StringHelper::startsWith("#", $line)) {
                 continue;
             }
             if (strlen($line) > 4 && strtoupper(substr($line, 0, 4)) == "REM ") {
                 continue;
             }
             $sql .= " " . $line;
             $sql = trim($sql);
             // SQL defines "--" as a comment to EOL
             // and in Oracle it may contain a hint
             // so we cannot just remove it, instead we must end it
             if (strpos($line, "--") !== false) {
                 $sql .= "\n";
             }
             if ($this->delimiterType == self::DELIM_NORMAL && StringHelper::endsWith($this->delimiter, $sql) || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
                 $this->log("SQL: " . $sql, Project::MSG_VERBOSE);
                 $this->execSQL(StringHelper::substring($sql, 0, strlen($sql) - strlen($this->delimiter)), $out);
                 $sql = "";
             }
         }
         // Catch any statements not followed by ;
         if ($sql !== "") {
             $this->execSQL($sql, $out);
         }
     } catch (SQLException $e) {
         throw new BuildException("Error running statements", $e);
     }
 }
 /** Append the file(s). */
 function main()
 {
     if ($this->file === null && empty($this->filesets)) {
         throw new BuildException("You must specify a file or fileset(s) for the <reflexive> task.");
     }
     // compile a list of all files to modify, both file attrib and fileset elements
     // can be used.
     $files = array();
     if ($this->file !== null) {
         $files[] = $this->file;
     }
     if (!empty($this->filesets)) {
         $filenames = array();
         foreach ($this->filesets as $fs) {
             try {
                 $ds = $fs->getDirectoryScanner($this->project);
                 $filenames = $ds->getIncludedFiles();
                 // get included filenames
                 $dir = $fs->getDir($this->project);
                 foreach ($filenames as $fname) {
                     $files[] = new PhingFile($dir, $fname);
                 }
             } catch (BuildException $be) {
                 $this->log($be->getMessage(), Project::MSG_WARN);
             }
         }
     }
     $this->log("Applying reflexive processing to " . count($files) . " files.");
     // These "slots" allow filters to retrieve information about the currently-being-process files
     $slot = $this->getRegisterSlot("currentFile");
     $basenameSlot = $this->getRegisterSlot("currentFile.basename");
     foreach ($files as $file) {
         // set the register slots
         $slot->setValue($file->getPath());
         $basenameSlot->setValue($file->getName());
         // 1) read contents of file, pulling through any filters
         $in = null;
         try {
             $contents = "";
             $in = FileUtils::getChainedReader(new FileReader($file), $this->filterChains, $this->project);
             while (-1 !== ($buffer = $in->read())) {
                 $contents .= $buffer;
             }
             $in->close();
         } catch (Exception $e) {
             if ($in) {
                 $in->close();
             }
             $this->log("Erorr reading file: " . $e->getMessage(), Project::MSG_WARN);
         }
         try {
             // now create a FileWriter w/ the same file, and write to the file
             $out = new FileWriter($file);
             $out->write($contents);
             $out->close();
             $this->log("Applying reflexive processing to " . $file->getPath(), Project::MSG_VERBOSE);
         } catch (Exception $e) {
             if ($out) {
                 $out->close();
             }
             $this->log("Error writing file back: " . $e->getMessage(), Project::MSG_WARN);
         }
     }
 }
 /**
  * add a name value pair to the project property set
  * @param string $name  name of property
  * @param string $value value to set
  */
 protected function addProperty($name, $value)
 {
     if (count($this->filterChains) > 0) {
         $in = FileUtils::getChainedReader(new StringReader($value), $this->filterChains, $this->project);
         $value = $in->read();
     }
     if ($this->userProperty) {
         if ($this->project->getUserProperty($name) === null || $this->override) {
             $this->project->setInheritedProperty($name, $value);
         } else {
             $this->log("Override ignored for " . $name, Project::MSG_VERBOSE);
         }
     } else {
         if ($this->override) {
             $this->project->setProperty($name, $value);
         } else {
             $this->project->setNewProperty($name, $value);
         }
     }
 }
 private function appendFile(FileWriter $writer, PhingFile $f)
 {
     $in = FileUtils::getChainedReader(new FileReader($f), $this->filterChains, $this->project);
     while (-1 !== ($buffer = $in->read())) {
         // -1 indicates EOF
         $writer->write($buffer);
     }
     $this->log("Appending contents of " . $f->getPath() . " to " . $this->to->getPath());
 }
 /**
  * Main method
  *
  * @return void
  * @throws BuildException
  */
 public function main()
 {
     if (empty($this->file)) {
         throw new BuildException("Attribute 'file' required", $this->getLocation());
     }
     if (empty($this->property)) {
         throw new BuildException("Attribute 'property' required", $this->getLocation());
     }
     // read file (through filterchains)
     $contents = "";
     $reader = FileUtils::getChainedReader(new FileReader($this->file), $this->filterChains, $this->project);
     while (-1 !== ($buffer = $reader->read())) {
         $contents .= $buffer;
     }
     $reader->close();
     // publish as property
     $this->project->setProperty($this->property, $contents);
 }
Beispiel #6
0
 /**
  * Main method
  *
  * @return void
  * @throws BuildException
  */
 public function main()
 {
     if (empty($this->file)) {
         throw new BuildException("Attribute 'file' required", $this->getLocation());
     }
     if (empty($this->property)) {
         throw new BuildException("Attribute 'property' required", $this->getLocation());
     }
     if ($this->quiet && $this->failOnError) {
         throw new BuildException("quiet and failonerror cannot both be set to true");
     }
     try {
         if (is_string($this->file)) {
             $this->file = new PhingFile($this->file);
         }
         if (!$this->file->exists()) {
             $message = (string) $this->file . ' doesn\'t exist';
             if ($this->failOnError) {
                 throw new BuildException($message);
             } else {
                 $this->log($message, $this->quiet ? Project::MSG_WARN : Project::MSG_ERR);
                 return;
             }
         }
         $this->log("loading " . (string) $this->file . " into property " . $this->property, Project::MSG_VERBOSE);
         // read file (through filterchains)
         $contents = "";
         if ($this->file->length() > 0) {
             $reader = FileUtils::getChainedReader(new FileReader($this->file), $this->filterChains, $this->project);
             while (-1 !== ($buffer = $reader->read())) {
                 $contents .= $buffer;
             }
             $reader->close();
         } else {
             $this->log("Do not set property " . $this->property . " as its length is 0.", $this->quiet ? Project::MSG_VERBOSE : Project::MSG_INFO);
         }
         // publish as property
         if ($contents !== '') {
             $this->project->setNewProperty($this->property, $contents);
             $this->log("loaded " . strlen($contents) . " characters", Project::MSG_VERBOSE);
             $this->log($this->property . " := " . $contents, Project::MSG_DEBUG);
         }
     } catch (IOException $ioe) {
         $message = "Unable to load resource: " . $ioe->getMessage();
         if ($this->failOnError) {
             throw new BuildException($message, $ioe, $this->getLocation());
         } else {
             $this->log($message, $this->quiet ? Project::MSG_VERBOSE : Project::MSG_ERR);
         }
     } catch (BuildException $be) {
         if ($this->failOnError) {
             throw $be;
         } else {
             $this->log($be->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_ERR);
         }
     }
 }
Beispiel #7
0
 private function getFilteredReader(Reader $r)
 {
     $helper = FileUtils::getChainedReader($r, $this->filterChains, $this->getProject());
     return $helper;
 }