/** * 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); } }
/** * 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); } }
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); }
/** * 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(); }
/** * 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); } }
/** * 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); } }
/** * 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(); }
/** * 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; } }
/** * 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); } }
/** * 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); } }