public function main() { if ($this->dataDir === null || !$this->dataDir->isDirectory()) { $path = $this->dataDir ? $this->dataDir->getAbsolutePath() : ''; $message = sprintf('Unable to apply migrations. EC-CUBE data directory not available at "%s"', $path); throw new BuildException($message); } if ($this->htmlDir === null || !$this->htmlDir->isDirectory()) { $path = $this->htmlDir ? $this->htmlDir->getAbsolutePath() : ''; $message = sprintf('Unable to apply migrations. EC-CUBE html directory not available at "%s"', $path); throw new BuildException($message); } $this->setupDatabase(); }
/** * @throws BuildException */ private function checkPreconditions() { if (is_null($this->destinationFile)) { throw new BuildException("destfile attribute must be set!", $this->getLocation()); } if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) { throw new BuildException("destfile is a directory!", $this->getLocation()); } if (!$this->destinationFile->canWrite()) { throw new BuildException("Can not write to the specified destfile!", $this->getLocation()); } if (!is_null($this->baseDirectory)) { if (!$this->baseDirectory->exists()) { throw new BuildException("basedir '" . (string) $this->baseDirectory . "' does not exist!", $this->getLocation()); } } if ($this->signatureAlgorithm == Phar::OPENSSL) { if (!extension_loaded('openssl')) { throw new BuildException("PHP OpenSSL extension is required for OpenSSL signing of Phars!", $this->getLocation()); } if (is_null($this->key)) { throw new BuildException("key attribute must be set for OpenSSL signing!", $this->getLocation()); } if (!$this->key->exists()) { throw new BuildException("key '" . (string) $this->key . "' does not exist!", $this->getLocation()); } if (!$this->key->canRead()) { throw new BuildException("key '" . (string) $this->key . "' cannot be read!", $this->getLocation()); } } }
/** * do the work * @throws BuildException */ public function main() { if ($this->zipFile === null) { throw new BuildException("zipFile attribute must be set!", $this->getLocation()); } if ($this->zipFile->exists() && $this->zipFile->isDirectory()) { throw new BuildException("zipFile is a directory!", $this->getLocation()); } if ($this->zipFile->exists() && !$this->zipFile->canWrite()) { throw new BuildException("Can not write to the specified zipFile!", $this->getLocation()); } // shouldn't need to clone, since the entries in filesets // themselves won't be modified -- only elements will be added $savedFileSets = $this->filesets; try { if (empty($this->filesets)) { throw new BuildException("You must supply some nested filesets.", $this->getLocation()); } $this->log("Building ZIP: " . $this->zipFile->__toString(), Project::MSG_INFO); $zip = new PclZip($this->zipFile->getAbsolutePath()); if ($zip->errorCode() != 1) { throw new Exception("PclZip::open() failed: " . $zip->errorInfo()); } foreach ($this->filesets as $fs) { $files = $fs->getFiles($this->project, $this->includeEmpty); $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project); $filesToZip = array(); for ($i = 0, $fcount = count($files); $i < $fcount; $i++) { $f = new PhingFile($fsBasedir, $files[$i]); //$filesToZip[] = realpath($f->getPath()); $fileAbsolutePath = $f->getPath(); $fileDir = rtrim(dirname($fileAbsolutePath), '/\\'); $fileBase = basename($fileAbsolutePath); if (substr($fileDir, -4) == '.svn') { continue; } if ($fileBase == '.svn') { continue; } if (substr(rtrim($fileAbsolutePath, '/\\'), -4) == '.svn') { continue; } //echo "\t\t$fileAbsolutePath\n"; $filesToZip[] = $f->getPath(); } /* $zip->add($filesToZip, PCLZIP_OPT_ADD_PATH, is_null($this->prefix) ? '' : $this->prefix , PCLZIP_OPT_REMOVE_PATH, realpath($fsBasedir->getPath()) ); */ $zip->add($filesToZip, PCLZIP_OPT_ADD_PATH, is_null($this->prefix) ? '' : $this->prefix, PCLZIP_OPT_REMOVE_PATH, $fsBasedir->getPath()); } } catch (IOException $ioe) { $msg = "Problem creating ZIP: " . $ioe->getMessage(); $this->filesets = $savedFileSets; throw new BuildException($msg, $ioe, $this->getLocation()); } $this->filesets = $savedFileSets; }
/** * Run the task. * * @throws BuildException trouble, probably file IO */ public function main() { if ($this->prefix != null && $this->regex != null) { throw new BuildException("Please specify either prefix or regex, but not both", $this->getLocation()); } //copy the properties file $allProps = array(); /* load properties from file if specified, otherwise use Phing's properties */ if ($this->inFile == null) { // add phing properties $allProps = $this->getProject()->getProperties(); } elseif ($this->inFile != null) { if ($this->inFile->exists() && $this->inFile->isDirectory()) { $message = "srcfile is a directory!"; $this->failOnErrorAction(null, $message, Project::MSG_ERR); return; } if ($this->inFile->exists() && !$this->inFile->canRead()) { $message = "Can not read from the specified srcfile!"; $this->failOnErrorAction(null, $message, Project::MSG_ERR); return; } try { $props = new Properties(); $props->load(new PhingFile($this->inFile)); $allProps = $props->getProperties(); } catch (IOException $ioe) { $message = "Could not read file " . $this->inFile->getAbsolutePath(); $this->failOnErrorAction($ioe, $message, Project::MSG_WARN); return; } } $os = null; try { if ($this->destfile == null) { $os = Phing::getOutputStream(); $this->saveProperties($allProps, $os); $this->log($os, Project::MSG_INFO); } else { if ($this->destfile->exists() && $this->destfile->isDirectory()) { $message = "destfile is a directory!"; $this->failOnErrorAction(null, $message, Project::MSG_ERR); return; } if ($this->destfile->exists() && !$this->destfile->canWrite()) { $message = "Can not write to the specified destfile!"; $this->failOnErrorAction(null, $message, Project::MSG_ERR); return; } $os = new FileOutputStream($this->destfile); $this->saveProperties($allProps, $os); } } catch (IOException $ioe) { $this->failOnErrorAction($ioe); } }
/** * Do the work * * @throws BuildException */ public function main() { if ($this->zipFile === null) { throw new BuildException("zipFile attribute must be set!", $this->getLocation()); } if ($this->zipFile->exists() && $this->zipFile->isDirectory()) { throw new BuildException("zipFile is a directory!", $this->getLocation()); } if ($this->zipFile->exists() && !$this->zipFile->canWrite()) { throw new BuildException("Can not write to the specified zipFile!", $this->getLocation()); } // shouldn't need to clone, since the entries in filesets // themselves won't be modified -- only elements will be added $savedFileSets = $this->filesets; try { if (empty($this->filesets)) { throw new BuildException("You must supply some nested filesets.", $this->getLocation()); } $this->log("Building ZIP: " . $this->zipFile->__toString(), Project::MSG_INFO); $zip = new PclZip($this->zipFile->getAbsolutePath()); if ($zip->errorCode() != 1) { throw new Exception("PclZip::open() failed: " . $zip->errorInfo()); } foreach ($this->filesets as $fs) { $files = $fs->getFiles($this->project, $this->includeEmpty); $fsBasedir = $this->baseDir != null ? $this->baseDir : $fs->getDir($this->project); $filesToZip = array(); foreach ($files as $file) { $f = new PhingFile($fsBasedir, $file); $fileAbsolutePath = $f->getPath(); $fileDir = rtrim(dirname($fileAbsolutePath), '/\\'); $fileBase = basename($fileAbsolutePath); // Only use lowercase for $disallowedBases because we'll convert $fileBase to lowercase $disallowedBases = array('.ds_store', '.svn', '.gitignore', 'thumbs.db'); $fileBaseLower = strtolower($fileBase); if (in_array($fileBaseLower, $disallowedBases)) { continue; } if (substr($fileDir, -4) == '.svn') { continue; } if (substr(rtrim($fileAbsolutePath, '/\\'), -4) == '.svn') { continue; } $filesToZip[] = $fileAbsolutePath; } $zip->add($filesToZip, PCLZIP_OPT_ADD_PATH, is_null($this->prefix) ? '' : $this->prefix, PCLZIP_OPT_REMOVE_PATH, $fsBasedir->getPath()); } } catch (IOException $ioe) { $msg = "Problem creating ZIP: " . $ioe->getMessage(); $this->filesets = $savedFileSets; throw new BuildException($msg, $ioe, $this->getLocation()); } $this->filesets = $savedFileSets; }
/** * {@inheritdoc} * * @throws BuildException * @throws IOException */ public function main() { if ($this->dir == null) { throw new BuildException("missing dir"); } if ($this->name == null) { throw new BuildException("missing name"); } if ($this->pathRefId == null) { throw new BuildException("missing pathrefid"); } if (!$this->dir->isDirectory()) { throw new BuildException($this->dir->toString() . " is not a directory"); } $path = $this->getProject()->getReference($this->pathRefId); if ($path == null) { throw new BuildException("Unknown reference " . $this->pathRefId); } if (!$path instanceof Path) { throw new BuildException($this->pathRefId . " is not a path"); } $sources = $path->listPaths(); $fileSet = new FileSet(); $fileSet->setProject($this->getProject()); $fileSet->setDir($this->dir); $fileUtils = new FileUtils(); $dirNormal = $fileUtils->normalize($this->dir->getAbsolutePath()); $dirNormal = rtrim($dirNormal, PhingFile::$separator) . PhingFile::$separator; $atLeastOne = false; for ($i = 0; $i < count($sources); ++$i) { $sourceFile = new PhingFile($sources[$i]); if (!$sourceFile->exists()) { continue; } $includePattern = $this->getIncludePattern($dirNormal, $sourceFile); if ($includePattern === false && !$this->ignoreNonRelative) { throw new BuildException($sources[$i] . " is not relative to " . $this->dir->getAbsolutePath()); } if ($includePattern === false) { continue; } $fileSet->createInclude()->setName($includePattern); $atLeastOne = true; } if (!$atLeastOne) { $fileSet->createInclude()->setName("a:b:c:d//THis si &&& not a file !!! "); } $this->getProject()->addReference($this->name, $fileSet); }
/** * @throws BuildException */ private function checkPreconditions() { if (is_null($this->destinationFile)) { throw new BuildException("destfile attribute must be set!", $this->getLocation()); } if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) { throw new BuildException("destfile is a directory!", $this->getLocation()); } if (!$this->destinationFile->canWrite()) { throw new BuildException("Can not write to the specified destfile!", $this->getLocation()); } if (!is_null($this->baseDirectory)) { if (!$this->baseDirectory->exists()) { throw new BuildException("basedir '" . (string) $this->baseDirectory . "' does not exist!", $this->getLocation()); } } }
/** * Validates attributes coming in from XML * * @return void * @throws BuildException */ protected function validateAttributes() { if ($this->file === null && count($this->filesets) === 0) { throw new BuildException("Specify at least one source compressed archive - a file or a fileset."); } if ($this->todir === null) { throw new BuildException("todir must be set."); } if ($this->todir !== null && $this->todir->exists() && !$this->todir->isDirectory()) { throw new BuildException("todir must be a directory."); } if ($this->file !== null && $this->file->exists() && $this->file->isDirectory()) { throw new BuildException("Compressed archive file cannot be a directory."); } if ($this->file !== null && !$this->file->exists()) { throw new BuildException("Could not find compressed archive file " . $this->file->__toString() . " to extract."); } }
/** * do the work * * @throws BuildException */ public function main() { if ($this->jpaFile === null) { throw new BuildException("jpafile attribute must be set!", $this->getLocation()); } if ($this->jpaFile->exists() && $this->jpaFile->isDirectory()) { throw new BuildException("jpafile is a directory!", $this->getLocation()); } if ($this->jpaFile->exists() && !$this->jpaFile->canWrite()) { throw new BuildException("Can not write to the specified jpafile!", $this->getLocation()); } // shouldn't need to clone, since the entries in filesets // themselves won't be modified -- only elements will be added $savedFileSets = $this->filesets; try { if (empty($this->filesets)) { throw new BuildException("You must supply some nested filesets.", $this->getLocation()); } $this->log("Building JPA: " . $this->jpaFile->__toString(), Project::MSG_INFO); $jpa = new JPAMaker(); $res = $jpa->create($this->jpaFile->getAbsolutePath()); if ($res !== true) { throw new Exception("JPAMaker::open() failed: " . $jpa->error); } foreach ($this->filesets as $fs) { $files = $fs->getFiles($this->project, $this->includeEmpty); $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project); $filesToZip = array(); for ($i = 0, $fcount = count($files); $i < $fcount; $i++) { $f = new PhingFile($fsBasedir, $files[$i]); $pathInJPA = $this->prefix . $f->getPathWithoutBase($fsBasedir); $jpa->addFile($f->getPath(), $pathInJPA); $this->log("Adding " . $f->getPath() . " as " . $pathInJPA . " to archive.", Project::MSG_VERBOSE); } } $jpa->finalize(); } catch (IOException $ioe) { $msg = "Problem creating JPA: " . $ioe->getMessage(); $this->filesets = $savedFileSets; throw new BuildException($msg, $ioe, $this->getLocation()); } $this->filesets = $savedFileSets; }
/** * @throws BuildException */ private function checkPreconditions() { if (!extension_loaded('phar')) { throw new BuildException("PharDataTask require either PHP 5.3 or better or the PECL's Phar extension"); } if (is_null($this->destinationFile)) { throw new BuildException("destfile attribute must be set!", $this->getLocation()); } if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) { throw new BuildException("destfile is a directory!", $this->getLocation()); } if (!$this->destinationFile->canWrite()) { throw new BuildException("Can not write to the specified destfile!", $this->getLocation()); } if (is_null($this->baseDirectory)) { throw new BuildException("basedir cattribute must be set", $this->getLocation()); } if (!$this->baseDirectory->exists()) { throw new BuildException("basedir '" . (string) $this->baseDirectory . "' does not exist!", $this->getLocation()); } }
/** * Execute the touch operation. * @throws BuildException */ public function main() { $savedMillis = $this->millis; if ($this->file === null && count($this->filesets) === 0) { throw new BuildException("Specify at least one source - a file or a fileset."); } if ($this->file !== null && $this->file->exists() && $this->file->isDirectory()) { throw new BuildException("Use a fileset to touch directories."); } try { // try to touch file if ($this->dateTime !== null) { $this->setMillis(strtotime($this->dateTime)); if ($this->millis < 0) { throw new BuildException("Date of {$this->dateTime} results in negative milliseconds value relative to epoch (January 1, 1970, 00:00:00 GMT)."); } } $this->_touch(); } catch (Exception $ex) { throw new BuildException("Error touch()ing file", $ex, $this->location); } $this->millis = $savedMillis; }
/** Go and delete the directory tree. */ private function deleteDir($d) { $list = $d->listDir(); if ($list === null) { return; // on an io error list() can return null } foreach ($list as $fname) { $f = new PhingFile($d, $fname); if ($f->isDirectory()) { $this->deleteDir($f); } else { throw new BuildException("UNEXPECTED ERROR - The file " . $f->getAbsolutePath() . " should not exist!"); } } $this->log("Deleting directory " . $d->getPath(), $this->verbosity); try { $d->delete(); } catch (Exception $e) { throw new BuildException("Unable to delete directory " . $d->__toString() . ": " . $e->getMessage()); } }
/** * @param PhingFile $file * @return bool * @throws IOException */ private function _checkFile1(PhingFile $file) { // Resolve symbolic links if ($this->followSymlinks && $file->isLink()) { $linkTarget = new PhingFile($file->getLinkTarget()); if ($linkTarget->isAbsolute()) { $file = $linkTarget; } else { $fs = FileSystem::getFileSystem(); $file = new PhingFile($fs->resolve($fs->normalize($file->getParent()), $fs->normalize($file->getLinkTarget()))); } } if ($this->type !== null) { if ($this->type === "dir") { return $file->isDirectory(); } else { if ($this->type === "file") { return $file->isFile(); } } } return $file->exists(); }
/** * 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 the base directory the scan is being done from * @param string $filename is the name of the file to check * @param PhingFile $file is a PhingFile object the selector can use * @return boolean Whether the file should be selected or not */ public function isSelected(PhingFile $basedir, $filename, PhingFile $file) { // throw BuildException on error $this->validate(); if ($file->isDirectory()) { return $this->type === 'dir'; } else { return $this->type === 'file'; } }
/** * 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); } }
/** * 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 the base directory the scan is being done from * @param string $filename is the name of the file to check * @param PhingFile $file is a PhingFile object the selector can use * @return boolean Whether the file should be selected or not */ public function isSelected(PhingFile $basedir, $filename, PhingFile $file) { $this->validate(); if ($file->isDirectory() && $this->includeDirs === false) { return true; } if ($this->cmp === 0) { return $file->lastModified() - $this->granularity < $this->seconds; } elseif ($this->cmp === 1) { return $file->lastModified() - $this->granularity > $this->seconds; } else { return abs($file->lastModified() - $this->seconds) <= $this->granularity; } }
/** * Copy a file. * * @param PhingFile $src Source path and name file to copy. * @param PhingFile $dest Destination path and name of new file. * * @return void * * @throws IOException if file cannot be copied. */ public function copy(PhingFile $src, PhingFile $dest) { global $php_errormsg; // Recursively copy a directory if ($src->isDirectory()) { return $this->copyr($src->getAbsolutePath(), $dest->getAbsolutePath()); } $srcPath = $src->getAbsolutePath(); $destPath = $dest->getAbsolutePath(); if (false === @copy($srcPath, $destPath)) { // Copy FAILED. Log and return err. // Add error from php to end of log message. $php_errormsg. $msg = "FileSystem::copy() FAILED. Cannot copy {$srcPath} to {$destPath}. {$php_errormsg}"; throw new IOException($msg); } $dest->setMode($src->getMode()); }
/** * 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); } }
private function _checkFile1(PhingFile $file) { if ($this->type !== null) { if ($this->type === "dir") { return $file->isDirectory(); } else { if ($this->type === "file") { return $file->isFile(); } } } return $file->exists(); }
/** * do the work * @throws BuildException */ public function main() { if (!extension_loaded('zip')) { throw new BuildException("Zip extension is required"); } if ($this->zipFile === null) { throw new BuildException("zipfile attribute must be set!", $this->getLocation()); } if ($this->zipFile->exists() && $this->zipFile->isDirectory()) { throw new BuildException("zipfile is a directory!", $this->getLocation()); } if ($this->zipFile->exists() && !$this->zipFile->canWrite()) { throw new BuildException("Can not write to the specified zipfile!", $this->getLocation()); } // shouldn't need to clone, since the entries in filesets // themselves won't be modified -- only elements will be added $savedFileSets = $this->filesets; try { if ($this->baseDir !== null) { if (!$this->baseDir->exists()) { throw new BuildException("basedir '" . (string) $this->baseDir . "' does not exist!", $this->getLocation()); } if (empty($this->filesets)) { // add the main fileset to the list of filesets to process. $mainFileSet = new ZipFileSet($this->fileset); $mainFileSet->setDir($this->baseDir); $this->filesets[] = $mainFileSet; } } if (empty($this->filesets)) { throw new BuildException("You must supply either a basedir " . "attribute or some nested filesets.", $this->getLocation()); } // check if zip is out of date with respect to each // fileset $upToDate = true; foreach ($this->filesets as $fs) { $files = $fs->getFiles($this->project, $this->includeEmpty); if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) { $upToDate = false; } for ($i = 0, $fcount = count($files); $i < $fcount; $i++) { if ($this->zipFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) { throw new BuildException("A zip file cannot include itself", $this->getLocation()); } } } if ($upToDate) { $this->log("Nothing to do: " . $this->zipFile->__toString() . " is up to date.", Project::MSG_INFO); return; } $this->log("Building zip: " . $this->zipFile->__toString(), Project::MSG_INFO); $zip = new ZipArchive(); $res = $zip->open($this->zipFile->getAbsolutePath(), ZIPARCHIVE::CREATE); if ($res !== true) { throw new Exception("ZipArchive::open() failed with code " . $res); } foreach ($this->filesets as $fs) { $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project); $files = $fs->getFiles($this->project, $this->includeEmpty); $filesToZip = array(); for ($i = 0, $fcount = count($files); $i < $fcount; $i++) { $f = new PhingFile($fsBasedir, $files[$i]); $pathInZip = $this->prefix . $f->getPathWithoutBase($fsBasedir); $pathInZip = str_replace('\\', '/', $pathInZip); if ($f->isDirectory()) { if ($pathInZip != '.') { $zip->addEmptyDir($pathInZip); } } else { $zip->addFile($f->getPath(), $pathInZip); } $this->log("Adding " . $f->getPath() . " as " . $pathInZip . " to archive.", Project::MSG_VERBOSE); } } $zip->close(); } catch (IOException $ioe) { $msg = "Problem creating ZIP: " . $ioe->getMessage(); $this->filesets = $savedFileSets; throw new BuildException($msg, $ioe, $this->getLocation()); } $this->filesets = $savedFileSets; }
/** * Copy a file. * * @param PhingFile $src Source path and name file to copy. * @param PhingFile $dest Destination path and name of new file. * * @return void * @throws IOException if file cannot be copied. */ function copy(PhingFile $src, PhingFile $dest) { global $php_errormsg; // Recursively copy a directory if ($src->isDirectory()) { return $this->copyr($src->getAbsolutePath(), $dest->getAbsolutePath()); } $srcPath = $src->getAbsolutePath(); $destPath = $dest->getAbsolutePath(); if (false === @copy($srcPath, $destPath)) { // Copy FAILED. Log and return err. // Add error from php to end of log message. $php_errormsg. $msg = "FileSystem::copy() FAILED. Cannot copy {$srcPath} to {$destPath}. {$php_errormsg}"; throw new IOException($msg); } try { $dest->setMode($src->getMode()); } catch (Exception $exc) { // [MA] does chmod returns an error on systems that do not support it ? // eat it up for now. } }
/** * 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 the base directory the scan is being done from * @param string $filename is the name of the file to check * @param PhingFile $file is a PhingFile object the selector can use * @return boolean Whether the file should be selected or not */ public function isSelected(PhingFile $basedir, $filename, PhingFile $file) { // throw BuildException on error $this->validate(); if ($file->isLink()) { if ($this->type == 'link') { return true; } $this->log($file->getAbsolutePath() . " is a link, proceeding with " . $file->getCanonicalPath() . " instead.", Project::MSG_DEBUG); $file = new PhingFile($file->getCanonicalPath()); } if ($file->isDirectory()) { return $this->type === 'dir'; } else { return $this->type === 'file'; } }
private function _checkFile1(PhingFile $file) { // Resolve symbolic links if ($this->followSymlinks && $file->isLink()) { $file = new PhingFile($file->getLinkTarget()); } if ($this->type !== null) { if ($this->type === "dir") { return $file->isDirectory(); } else { if ($this->type === "file") { return $file->isFile(); } } } return $file->exists(); }
/** * do the work * @throws BuildException */ public function main() { if ($this->zipFile === null) { throw new BuildException("zipfile attribute must be set!", $this->getLocation()); } if ($this->zipFile->exists() && $this->zipFile->isDirectory()) { throw new BuildException("zipfile is a directory!", $this->getLocation()); } if ($this->zipFile->exists() && !$this->zipFile->canWrite()) { throw new BuildException("Can not write to the specified zipfile!", $this->getLocation()); } // shouldn't need to clone, since the entries in filesets // themselves won't be modified -- only elements will be added $savedFileSets = $this->filesets; try { if ($this->baseDir !== null) { if (!$this->baseDir->exists()) { throw new BuildException("basedir does not exist!", $this->getLocation()); } if (empty($this->filesets)) { // add the main fileset to the list of filesets to process. $mainFileSet = new ZipFileSet($this->fileset); $mainFileSet->setDir($this->baseDir); $this->filesets[] = $mainFileSet; } } if (empty($this->filesets)) { throw new BuildException("You must supply either a basedir " . "attribute or some nested filesets.", $this->getLocation()); } // check if zip is out of date with respect to each // fileset $upToDate = true; foreach ($this->filesets as $fs) { $files = $fs->getFiles($this->project, $this->includeEmpty); if (!$this->archiveIsUpToDate($files, $fs->getDir($this->project))) { $upToDate = false; } for ($i = 0, $fcount = count($files); $i < $fcount; $i++) { if ($this->zipFile->equals(new PhingFile($fs->getDir($this->project), $files[$i]))) { throw new BuildException("A zip file cannot include itself", $this->getLocation()); } } } if ($upToDate) { $this->log("Nothing to do: " . $this->zipFile->__toString() . " is up to date.", Project::MSG_INFO); return; } $this->log("Building zip: " . $this->zipFile->__toString(), Project::MSG_INFO); $zip = new Archive_Zip($this->zipFile->getAbsolutePath()); foreach ($this->filesets as $fs) { $files = $fs->getFiles($this->project, $this->includeEmpty); $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project); $filesToZip = array(); for ($i = 0, $fcount = count($files); $i < $fcount; $i++) { $f = new PhingFile($fsBasedir, $files[$i]); $filesToZip[] = $f->getAbsolutePath(); $this->log("Adding " . $f->getPath() . " to archive.", Project::MSG_VERBOSE); } $zip->add($filesToZip, array('remove_path' => $fsBasedir->getCanonicalPath())); } } catch (IOException $ioe) { $msg = "Problem creating ZIP: " . $ioe->getMessage(); $this->filesets = $savedFileSets; throw new BuildException($msg, $ioe, $this->getLocation()); } $this->filesets = $savedFileSets; }
/** * Delete the file or directory denoted by the given abstract pathname, * returning true if and only if the operation succeeds. */ function delete(PhingFile $f) { if ($f->isDirectory()) { return $this->rmdir($f->getPath()); } else { return $this->unlink($f->getPath()); } }
/** * The heart of the matter. This is where the selector gets to decide * on the inclusion of a file in a particular fileset. * * {@inheritdoc} * * @param PhingFile $basedir A PhingFile object for the base directory * @param string $filename The name of the file to check * @param PhingFile $file A PhingFile object for this filename * * @return bool whether the file should be selected or not */ public function isSelected(PhingFile $basedir, $filename, PhingFile $file) { $this->validate(); // Directory size never selected for if ($file->isDirectory()) { return true; } if ($this->cmp === 0) { return $file->length() < $this->sizelimit; } elseif ($this->cmp === 1) { return $file->length() > $this->sizelimit; } else { return $file->length() === $this->sizelimit; } }
/** * Set basedir object from xm * @param PhingFile|string $dir * @throws BuildException */ public function setBasedir($dir) { if ($dir instanceof PhingFile) { $dir = $dir->getAbsolutePath(); } $dir = $this->fileUtils->normalize($dir); $dir = FileSystem::getFilesystem()->canonicalize($dir); $dir = new PhingFile((string) $dir); if (!$dir->exists()) { throw new BuildException("Basedir " . $dir->getAbsolutePath() . " does not exist"); } if (!$dir->isDirectory()) { throw new BuildException("Basedir " . $dir->getAbsolutePath() . " is not a directory"); } $this->basedir = $dir; $this->setPropertyInternal("project.basedir", $this->basedir->getAbsolutePath()); $this->log("Project base dir set to: " . $this->basedir->getPath(), Project::MSG_VERBOSE); // [HL] added this so that ./ files resolve correctly. This may be a mistake ... or may be in wrong place. chdir($dir->getAbsolutePath()); }
/** * Validates attributes coming in from XML. * * @param void * @return void * @throws BuildException * @access protected */ protected function _validateAttributes() { if (null === $this->_resource) { throw new BuildException('You must specify a file to load.'); } if (null === $this->_destFile && empty($this->_filesets)) { throw new BuildException('Specify at least one source - a file or a fileset.'); } if (null !== $this->_destFile && !empty($this->_filesets)) { throw new BuildException('Only one of destination file and fileset may be set.'); } if ($this->_resource->exists()) { if ($this->_resource->isDirectory()) { throw new BuildException('Cannot load a directory as a file.'); } try { if (0 === $this->_resource->length()) { $this->log('The file ' . $this->_resource . ' is empty!', $this->getVerbose()); } } catch (IOException $e) { throw new BuildException($e->getMessage(), $e->getLocation()); } } else { throw new BuildException($this->_resource . ' does not exist!'); } }
/** * Recursively removes a directory. * @param PhingFile $d The directory to remove. */ private function removeDir($d) { $list = $d->listDir(); if ($list === null) { $list = array(); } foreach ($list as $s) { $f = new PhingFile($d, $s); if ($f->isDirectory()) { $this->removeDir($f); } else { $this->log("Deleting " . $f->__toString(), $this->verbosity); try { $f->delete(); } catch (Exception $e) { $message = "Unable to delete file " . $f->__toString() . ": " . $e->getMessage(); if ($this->failonerror) { throw new BuildException($message); } else { $this->log($message, $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN); } } } } $this->log("Deleting directory " . $d->getAbsolutePath(), $this->verbosity); try { $d->delete(); } catch (Exception $e) { $message = "Unable to delete directory " . $d->__toString() . ": " . $e->getMessage(); if ($this->failonerror) { throw new BuildException($message); } else { $this->log($message, $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN); } } }
/** * @param $zip */ private function addFilesetsToArchive($zip) { foreach ($this->filesets as $fs) { $fsBasedir = null != $this->baseDir ? $this->baseDir : $fs->getDir($this->project); $files = $fs->getFiles($this->project, $this->includeEmpty); for ($i = 0, $fcount = count($files); $i < $fcount; $i++) { $f = new PhingFile($fsBasedir, $files[$i]); $pathInZip = $this->prefix . $f->getPathWithoutBase($fsBasedir); $pathInZip = str_replace('\\', '/', $pathInZip); if ($this->ignoreLinks && $f->isLink()) { continue; } elseif ($f->isDirectory()) { if ($pathInZip != '.') { $zip->addEmptyDir($pathInZip); } } else { $zip->addFile($f->getAbsolutePath(), $pathInZip); } $this->log("Adding " . $f->getPath() . " as " . $pathInZip . " to archive.", Project::MSG_VERBOSE); } } }