상속: extends Reader
예제 #1
0
 /**
  *
  */
 public function parseFile($xmlFile)
 {
     try {
         $this->data = array();
         try {
             $fr = new FileReader($xmlFile);
         } catch (Exception $e) {
             $f = new PhingFile($xmlFile);
             throw new BuildException("XML File not found: " . $f->getAbsolutePath());
         }
         $br = new BufferedReader($fr);
         $this->parser = new ExpatParser($br);
         $this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
         $this->parser->setHandler($this);
         try {
             $this->parser->parse();
         } catch (Exception $e) {
             print $e->getMessage() . "\n";
             $br->close();
         }
         $br->close();
     } catch (Exception $e) {
         print $e->getMessage() . "\n";
         print $e->getTraceAsString();
     }
     return $this->data;
 }
 /**
  * Does the work.
  *
  * @throws BuildException if someting goes wrong with the build
  */
 public final function main()
 {
     if ($this->cvsRoot === null) {
         throw new BuildException("cvsroot is required");
     }
     if ($this->password === null) {
         throw new BuildException("password is required");
     }
     $this->log("cvsRoot: " . $this->cvsRoot, Project::MSG_DEBUG);
     $this->log("password: "******"passFile: " . $this->passFile->__toString(), Project::MSG_DEBUG);
     $reader = null;
     $writer = null;
     try {
         $buf = "";
         if ($this->passFile->exists()) {
             $reader = new BufferedReader(new FileReader($this->passFile));
             $line = null;
             while (($line = $reader->readLine()) !== null) {
                 if (!StringHelper::startsWith($this->cvsRoot, $line)) {
                     $buf .= $line . PHP_EOL;
                 }
             }
         }
         $pwdfile = $buf . $this->cvsRoot . " A" . $this->mangle($this->password);
         $this->log("Writing -> " . $pwdfile, Project::MSG_DEBUG);
         $writer = new BufferedWriter(new FileWriter($this->passFile));
         $writer->write($pwdfile);
         $writer->newLine();
         $writer->close();
         if ($reader) {
             $reader->close();
         }
     } catch (IOException $e) {
         if ($reader) {
             try {
                 $reader->close();
             } catch (Exception $e) {
             }
         }
         if ($writer) {
             try {
                 $writer->close();
             } catch (Exception $e) {
             }
         }
         throw new BuildException($e);
     }
 }
 /**
  * Creates the ExpatParser, sets root handler and kick off parsing
  * process.
  *
  * @throws BuildException if there is any kind of execption during
  *         the parsing process
  * @access private
  */
 protected function parse()
 {
     try {
         $reader = new BufferedReader(new FileReader($this->buildFile));
         $reader->open();
         $parser = new ExpatParser($reader);
         $parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
         $parser->setHandler(new RootHandler($parser, $this));
         $this->project->log("parsing buildfile " . $this->buildFile->getName(), PROJECT_MSG_VERBOSE);
         $parser->parse();
         $reader->close();
     } catch (Exception $exc) {
         throw new BuildException("Error reading project file", $exc);
     }
 }
예제 #4
0
 /**
  * Returns the next character in the filtered stream. If the desired
  * number of lines have already been read, the resulting stream is
  * effectively at an end. Otherwise, the next character from the
  * underlying stream is read and returned.
  *
  * @param int $len
  * @return int|string the next character in the resulting stream, or -1
  * if the end of the resulting stream has been reached
  *
  * @throws IOException if the underlying stream throws an IOException
  *                     during reading
  * @throws BuildException
  */
 public function read($len = 0)
 {
     // do the "singleton" initialization
     if (!$this->getInitialized()) {
         $this->initialize();
         $this->setInitialized(true);
     }
     $ch = -1;
     // The readers return -1 if they end. So simply read the "prepend"
     // after that the "content" and at the end the "append" file.
     if ($this->prependReader !== null) {
         $ch = $this->prependReader->read();
         if ($ch === -1) {
             // I am the only one so I have to close the reader
             $this->prependReader->close();
             $this->prependReader = null;
         }
     }
     if ($ch === -1) {
         $ch = parent::read();
     }
     if ($ch === -1 && $this->appendReader !== null) {
         $ch = $this->appendReader->read();
         if ($ch === -1) {
             // I am the only one so I have to close the reader
             $this->appendReader->close();
             $this->appendReader = null;
         }
     }
     return $ch;
 }
예제 #5
0
 /**
  * set the text using a file
  * @param file the file to use
  * @throws BuildException if the file does not exist, or cannot be
  *                        read
  */
 public function setFile(PhingFile $file)
 {
     // non-existing files are not allowed
     if (!$file->exists()) {
         throw new BuildException("File " . $file . " does not exist.");
     }
     $reader = null;
     try {
         if ($this->encoding == null) {
             $reader = new BufferedReader(new FileReader($file));
         } else {
             $reader = new BufferedReader(new InputStreamReader(new FileInputStream($file)));
         }
         $this->value = $reader->read();
     } catch (IOException $ex) {
         $reader->close();
         throw new BuildException($ex);
     }
     $reader->close();
 }
 public static function loadFromStream($filename, GenericList $classNotFoundExceptions)
 {
     if (is_null($filename)) {
         throw new NullPointerException('InputStream');
     }
     $whitelistSer = new HashMap();
     $whitelistDeser = new HashMap();
     $typeIds = new HashMap();
     $clientFields = new HashMap();
     $br = new BufferedReader($filename);
     $line = $br->readLine();
     $lineNum = 1;
     while (!is_null($line)) {
         $line = trim($line);
         if (mb_strlen($line) > 0) {
             $components = explode(',', $line);
             if ($components[0] === self::CLIENT_FIELDS_KEYWORD) {
                 /*
                  * Lines starting with '@ClientFields' list potentially serializable fields known to
                  * client code for classes that may be enhanced with additional fields on the server.
                  * If additional server  fields are found, they will be serizalized separately from the
                  * normal RPC process and transmitted to the client as an opaque blob of data stored
                  * in a WeakMapping associated with the object instance.
                  */
                 $binaryTypeName = trim($components[1]);
                 try {
                     $clazz = Classes::classOf($binaryTypeName);
                     $fieldNames = new HashSet();
                     for ($i = 2; $i < count($components); $i++) {
                         $fieldNames->add($components[$i]);
                     }
                     $clientFields->put($clazz, $fieldNames);
                 } catch (ClassNotFoundException $e) {
                     // Ignore the error, but add it to the list of errors if one was
                     // provided.
                     if (!is_null($classNotFoundExceptions)) {
                         $classNotFoundExceptions->add($e);
                     }
                 }
             } else {
                 if (count($components) != 2 && count($components) != 7) {
                     throw new ParseException(self::FORMAT_ERROR_MESSAGE, $lineNum);
                 }
                 for ($i = 0; $i < count($components); $i++) {
                     $components[$i] = trim($components[$i]);
                     if (mb_strlen($components[$i]) == 0) {
                         throw new ParseException(self::FORMAT_ERROR_MESSAGE, $lineNum);
                     }
                 }
                 $binaryTypeName = trim($components[0]);
                 if (count($components) == 2) {
                     $fieldSer = $fieldDeser = true;
                     $instantSer = $instantDeser = Boolean::valueOf($components[1]);
                     $typeId = $binaryTypeName;
                 } else {
                     $idx = 1;
                     // TODO: Validate the instantiable string better
                     $fieldSer = Boolean::valueOf($components[$idx++]);
                     $instantSer = Boolean::valueOf($components[$idx++]);
                     $fieldDeser = Boolean::valueOf($components[$idx++]);
                     $instantDeser = Boolean::valueOf($components[$idx++]);
                     $typeId = $components[$idx++];
                     if (!$fieldSer && !$fieldDeser && TypeNameObfuscator::SERVICE_INTERFACE_ID != $typeId) {
                         throw new ParseException('Type ' . $binaryTypeName . ' is neither field serializable, field deserializable ' . 'nor the service interface : ', $lineNum);
                     }
                 }
                 try {
                     $clazz = Classes::classOf($binaryTypeName);
                     if ($fieldSer) {
                         $whitelistSer->put($clazz, $instantSer);
                     }
                     if ($fieldDeser) {
                         $whitelistDeser->put($clazz, $instantDeser);
                     }
                     $typeIds->put($clazz, $typeId);
                 } catch (ClassNotFoundException $e) {
                     // Ignore the error, but add it to the list of errors if one was
                     // provided.
                     if (!is_null($classNotFoundExceptions)) {
                         $classNotFoundExceptions->add($e);
                     }
                 }
             }
         }
         $line = $br->readLine();
         $lineNum++;
     }
     return new StandardSerializationPolicy($whitelistSer, $whitelistDeser, $typeIds, $clientFields);
 }
 /**
  * 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);
     }
 }
 /**
  * The heart of the matter. This is where the selector gets to decide
  * on the inclusion of a file in a particular fileset.
  *
  * @param PhingFile $basedir base directory the scan is being done from
  * @param string $filename the name of the file to check
  * @param PhingFile $file PhingFile object the selector can use
  *
  * @throws BuildException
  *
  * @return bool whether the file should be selected or not
  */
 public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
 {
     $this->validate();
     if ($file->isDirectory()) {
         return true;
     }
     if ($this->myRegExp === null) {
         $this->myRegExp = new RegularExpression();
         $this->myRegExp->setPattern($this->userProvidedExpression);
         if (!$this->casesensitive) {
             $this->myRegExp->setIgnoreCase(true);
         }
         $this->myExpression = $this->myRegExp->getRegexp($this->getProject());
     }
     $in = null;
     try {
         $in = new BufferedReader(new FileReader($file));
         $teststr = $in->readLine();
         while ($teststr !== null) {
             if ($this->myExpression->matches($teststr)) {
                 return true;
             }
             $teststr = $in->readLine();
         }
         $in->close();
         return false;
     } catch (IOException $ioe) {
         if ($in) {
             $in->close();
         }
         throw new BuildException("Could not read file " . $filename);
     }
 }
예제 #9
0
파일: FileList.php 프로젝트: tammyd/phing
 /**
  * Reads file names from a file and adds them to the files array.
  *
  * @param Project $p
  *
  * @throws BuildException
  */
 private function readListFile(Project $p)
 {
     $listReader = null;
     try {
         // Get a FileReader
         $listReader = new BufferedReader(new FileReader($this->listfile));
         $line = $listReader->readLine();
         while ($line !== null) {
             if (!empty($line)) {
                 $line = $p->replaceProperties($line);
                 $this->filenames[] = trim($line);
             }
             $line = $listReader->readLine();
         }
     } catch (Exception $e) {
         if ($listReader) {
             $listReader->close();
         }
         throw new BuildException("An error occurred while reading from list file " . $this->listfile->__toString() . ": " . $e->getMessage());
     }
     $listReader->close();
 }
예제 #10
0
 /**
  * Parses a XML input file and returns a newly created and
  * populated AppData structure.
  *
  * @param      string $xmlFile The input file to parse.
  * @return     AppData populated by <code>xmlFile</code>.
  */
 public function parseFile($xmlFile)
 {
     // we don't want infinite recursion
     if ($this->isAlreadyParsed($xmlFile)) {
         return;
     }
     $domDocument = new DomDocument('1.0', 'UTF-8');
     $domDocument->load($xmlFile);
     // store current schema file path
     $this->schemasTagsStack[$xmlFile] = array();
     $this->currentXmlFile = $xmlFile;
     try {
         $fr = new FileReader($xmlFile);
     } catch (Exception $e) {
         $f = new PhingFile($xmlFile);
         throw new Exception("XML File not found: " . $f->getAbsolutePath());
     }
     $br = new BufferedReader($fr);
     $this->parser = new ExpatParser($br);
     $this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
     $this->parser->setHandler($this);
     try {
         $this->parser->parse();
     } catch (Exception $e) {
         $br->close();
         throw $e;
     }
     $br->close();
     array_pop($this->schemasTagsStack);
     return $this->app;
 }
예제 #11
0
 /**
  * The heart of the matter. This is where the selector gets to decide
  * on the inclusion of a file in a particular fileset.
  *
  * @param PhingFile $basedir
  * @param string $filename
  * @param PhingFile $file
  *
  * @throws BuildException
  *
  * @internal param the $basedir base directory the scan is being done from
  * @internal param is $filename the name of the file to check
  * @internal param a $file PhingFile object the selector can use
  *
  * @return bool whether the file should be selected or not
  */
 public function isSelected(PhingFile $basedir, $filename, PhingFile $file)
 {
     $this->validate();
     if ($file->isDirectory()) {
         return true;
     }
     $userstr = $this->contains;
     if (!$this->casesensitive) {
         $userstr = strtolower($this->contains);
     }
     $in = null;
     try {
         $in = new BufferedReader(new FileReader($file));
         $teststr = $in->readLine();
         while ($teststr !== null) {
             if (!$this->casesensitive) {
                 $teststr = strtolower($teststr);
             }
             if (strpos($teststr, $userstr) !== false) {
                 return true;
             }
             $teststr = $in->readLine();
         }
         $in->close();
         return false;
     } catch (IOException $ioe) {
         if ($in) {
             $in->close();
         }
         throw new BuildException("Could not read file " . $filename);
     }
 }
예제 #12
0
 /**
  * Transform the data dump input file into SQL and writes it to the output stream.
  *
  * @param      PhingFile $xmlFile
  * @param      Writer $out
  */
 public function transform(PhingFile $xmlFile, Writer $out)
 {
     $this->sqlWriter = $out;
     // Reset some vars just in case this is being run multiple times.
     $this->currTableName = $this->currBuilder = null;
     $this->builderClazz = $this->generatorConfig->getBuilderClassname('datasql');
     try {
         $fr = new FileReader($xmlFile);
     } catch (Exception $e) {
         throw new BuildException("XML File not found: " . $xmlFile->getAbsolutePath());
     }
     $br = new BufferedReader($fr);
     $this->parser = new ExpatParser($br);
     $this->parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
     $this->parser->setHandler($this);
     try {
         $this->parser->parse();
     } catch (Exception $e) {
         print $e->getMessage() . "\n";
         $br->close();
     }
     $br->close();
 }
 /**
  * Read the statements from the .sql file and execute them.
  * Lines starting with '//', '--' or 'REM ' are ignored.
  *
  * Developer note:  must be public in order to be called from
  * sudo-"inner" class PropelSQLExecTransaction.
  *
  * @param      Reader $reader
  * @param      $out Optional output stream.
  * @throws     SQLException
  * @throws     IOException
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $sqlBacklog = "";
     $hasQuery = false;
     $in = new BufferedReader($reader);
     try {
         while (($line = $in->readLine()) !== null) {
             $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;
             }
             if ($sqlBacklog !== "") {
                 $sql = $sqlBacklog;
                 $sqlBacklog = "";
             }
             $sql .= " " . $line . "\n";
             // 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";
             }
             // DELIM_ROW doesn't need this (as far as i can tell)
             if ($this->delimiterType == self::DELIM_NORMAL) {
                 $reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($this->delimiter) . ")#";
                 $sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE);
                 $sqlBacklog = "";
                 foreach ($sqlParts as $sqlPart) {
                     // we always want to append, even if it's a delim (which will be stripped off later)
                     $sqlBacklog .= $sqlPart;
                     // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query
                     if ($sqlPart === $this->delimiter) {
                         $sql = $sqlBacklog;
                         $sqlBacklog = "";
                         $hasQuery = true;
                     }
                 }
             }
             if ($hasQuery || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
                 // this assumes there is always a delimter on the end of the SQL statement.
                 $sql = StringHelper::substring($sql, 0, strlen($sql) - 1 - strlen($this->delimiter));
                 $this->log("SQL: " . $sql, PROJECT_MSG_VERBOSE);
                 $this->execSQL($sql, $out);
                 $sql = "";
                 $hasQuery = false;
             }
         }
         // Catch any statements not followed by ;
         if ($sql !== "") {
             $this->execSQL($sql, $out);
         }
     } catch (SQLException $e) {
         throw $e;
     }
 }
예제 #14
0
 /**
  * Read the statements from the .sql file and execute them.
  * Lines starting with '//', '--' or 'REM ' are ignored.
  *
  * Developer note:  must be public in order to be called from
  * sudo-"inner" class PropelSQLExecTransaction.
  *
  * @param      Reader $reader
  * @param      $out Optional output stream.
  * @throws     PDOException
  * @throws     IOException
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $sqlBacklog = "";
     $hasQuery = false;
     $in = new BufferedReader($reader);
     $parser['pointer'] = 0;
     $parser['isInString'] = false;
     $parser['stringQuotes'] = "";
     $parser['backslashCount'] = 0;
     $parser['parsedString'] = "";
     $sqlParts = array();
     while (($line = $in->readLine()) !== null) {
         $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;
         }
         if ($sqlBacklog !== "") {
             $sql = $sqlBacklog;
             $sqlBacklog = "";
         }
         $sql .= " " . $line . PHP_EOL;
         // 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 .= PHP_EOL;
         }
         // DELIM_ROW doesn't need this (as far as i can tell)
         if ($this->delimiterType == self::DELIM_NORMAL) {
             // old regex, being replaced due to segfaults:
             // See: http://propel.phpdb.org/trac/ticket/294
             //$reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($this->delimiter) . ")#";
             //$sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE);
             $i = $parser['pointer'];
             $c = strlen($sql);
             while ($i < $c) {
                 $char = $sql[$i];
                 switch ($char) {
                     case "\\":
                         $parser['backslashCount']++;
                         $this->log("c{$i}: found " . $parser['backslashCount'] . " backslash(es)", Project::MSG_VERBOSE);
                         break;
                     case "'":
                     case "\"":
                         if ($parser['isInString'] && $parser['stringQuotes'] == $char) {
                             if (($parser['backslashCount'] & 1) == 0) {
                                 #$this->log("$i: out of string", Project::MSG_VERBOSE);
                                 $parser['isInString'] = false;
                             } else {
                                 $this->log("c{$i}: rejected quoted delimiter", Project::MSG_VERBOSE);
                             }
                         } elseif (!$parser['isInString']) {
                             $parser['stringQuotes'] = $char;
                             $parser['isInString'] = true;
                             #$this->log("$i: into string with $parser['stringQuotes']", Project::MSG_VERBOSE);
                         }
                         break;
                 }
                 if ($char == $this->delimiter && !$parser['isInString']) {
                     $this->log("c{$i}: valid end of command found!", Project::MSG_VERBOSE);
                     $sqlParts[] = $parser['parsedString'];
                     $sqlParts[] = $this->delimiter;
                     break;
                 }
                 $parser['parsedString'] .= $char;
                 if ($char !== "\\") {
                     if ($parser['backslashCount']) {
                         $this->log("{$i}: backslash reset", Project::MSG_VERBOSE);
                     }
                     $parser['backslashCount'] = 0;
                 }
                 $i++;
                 $parser['pointer']++;
             }
             $sqlBacklog = "";
             foreach ($sqlParts as $sqlPart) {
                 // we always want to append, even if it's a delim (which will be stripped off later)
                 $sqlBacklog .= $sqlPart;
                 // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query
                 if ($sqlPart === $this->delimiter) {
                     $sql = $sqlBacklog;
                     $sqlBacklog = "";
                     $hasQuery = true;
                 }
             }
         }
         if ($hasQuery || $this->delimiterType == self::DELIM_ROW && $line == $this->delimiter) {
             // this assumes there is always a delimter on the end of the SQL statement.
             $sql = StringHelper::substring($sql, 0, strlen($sql) - 1 - strlen($this->delimiter));
             $this->log("SQL: " . $sql, Project::MSG_VERBOSE);
             $this->execSQL($sql, $out);
             $sql = "";
             $hasQuery = false;
             $parser['pointer'] = 0;
             $parser['isInString'] = false;
             $parser['stringQuotes'] = "";
             $parser['backslashCount'] = 0;
             $parser['parsedString'] = "";
             $sqlParts = array();
         }
     }
     // Catch any statements not followed by ;
     if ($sql !== "") {
         $this->execSQL($sql, $out);
     }
 }
예제 #15
0
 /**
  * @param PhingXMLContext $ctx
  * @throws ExpatParseException
  */
 protected function _parse(PhingXMLContext $ctx)
 {
     // push action onto global stack
     $ctx->startConfigure($this);
     $reader = new BufferedReader(new FileReader($this->buildFile));
     $parser = new ExpatParser($reader);
     $parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
     $parser->setHandler(new RootHandler($parser, $this, $ctx));
     $this->project->log("parsing buildfile " . $this->buildFile->getName(), Project::MSG_VERBOSE);
     $parser->parse();
     $reader->close();
     // mark parse phase as completed
     $this->isParsing = false;
     // execute delayed tasks
     $this->parseEndTarget->main();
     // pop this action from the global stack
     $ctx->endConfigure();
 }
 /**
  * read in lines and execute them
  * @throws SQLException, IOException 
  */
 public function runStatements(Reader $reader, $out = null)
 {
     $sql = "";
     $line = "";
     $in = new BufferedReader($reader);
     try {
         while (($line = $in->readLine()) !== null) {
             $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) - 1), $out);
                 $sql = "";
             }
         }
         // Catch any statements not followed by ;
         if ($sql !== "") {
             $this->execSQL($sql, $out);
         }
     } catch (SQLException $e) {
         throw new BuildException("Error running statements", $e);
     }
 }
예제 #17
0
 /**
  * Creates the ExpatParser, sets root handler and kick off parsing
  * process.
  *
  * @throws BuildException if there is any kind of execption during
  *         the parsing process
  * @access private
  */
 protected function parse()
 {
     try {
         // get parse context
         $ctx = $this->project->getReference("phing.parsing.context");
         if (null == $ctx) {
             // make a new context and register it with project
             $ctx = new PhingXMLContext($this->project);
             $this->project->addReference("phing.parsing.context", $ctx);
         }
         //record this parse with context
         $ctx->addImport($this->buildFile);
         if (count($ctx->getImportStack()) > 1) {
             // this is an imported file
             // modify project tag parse behavior
             $this->setIgnoreProjectTag(true);
         }
         // push action onto global stack
         $ctx->startConfigure($this);
         $reader = new BufferedReader(new FileReader($this->buildFile));
         $parser = new ExpatParser($reader);
         $parser->parserSetOption(XML_OPTION_CASE_FOLDING, 0);
         $parser->setHandler(new RootHandler($parser, $this));
         $this->project->log("parsing buildfile " . $this->buildFile->getName(), Project::MSG_VERBOSE);
         $parser->parse();
         $reader->close();
         // mark parse phase as completed
         $this->isParsing = false;
         // execute delayed tasks
         $this->parseEndTarget->main();
         // pop this action from the global stack
         $ctx->endConfigure();
     } catch (Exception $exc) {
         throw new BuildException("Error reading project file", $exc);
     }
 }
예제 #18
0
 /**
  *  Reads path matching patterns from a file and adds them to the
  *  includes or excludes list
  */
 private function readPatterns(PhingFile $patternfile, &$patternlist, Project $p)
 {
     $patternReader = null;
     try {
         // Get a FileReader
         $patternReader = new BufferedReader(new FileReader($patternfile));
         // Create one NameEntry in the appropriate pattern list for each
         // line in the file.
         $line = $patternReader->readLine();
         while ($line !== null) {
             if (!empty($line)) {
                 $line = $p->replaceProperties($line);
                 $this->addPatternToList($patternlist)->setName($line);
             }
             $line = $patternReader->readLine();
         }
     } catch (IOException $ioe) {
         $msg = "An error occured while reading from pattern file: " . $patternfile->__toString();
         if ($patternReader) {
             $patternReader->close();
         }
         throw new BuildException($msg, $ioe);
     }
     $patternReader->close();
 }