コード例 #1
0
 /**
  * @dataProvider fileSystemMappingsDataProvider
  */
 public function testGetFileSystemReturnsCorrect($expectedFileSystemClass, $fsTypeKey)
 {
     $this->_resetFileSystem();
     Phing::setProperty('host.fstype', $fsTypeKey);
     $system = FileSystem::getFileSystem();
     $this->assertInstanceOf($expectedFileSystemClass, $system);
 }
コード例 #2
0
 /**
  * @param $path
  * @param $mode
  * @param $options
  * @param $opened_path
  *
  * @return bool
  * @throws IOException
  */
 public function stream_open($path, $mode, $options, &$opened_path)
 {
     // if we're on Windows, urldecode() the path again
     if (FileSystem::getFileSystem()->getSeparator() == '\\') {
         $path = urldecode($path);
     }
     $filepath = substr($path, 8);
     $this->createDirectories(dirname($filepath));
     $this->fp = fopen($filepath, $mode);
     return true;
 }
コード例 #3
0
ファイル: AtoumTask.php プロジェクト: atoum/atoum
 private function getFiles()
 {
     $files = array();
     foreach ($this->fileSets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $dir = $fs->getDir($this->project);
         $srcFiles = $ds->getIncludedFiles();
         foreach ($srcFiles as $file) {
             $files[] = $dir . FileSystem::getFileSystem()->getSeparator() . $file;
         }
     }
     return $files;
 }
コード例 #4
0
 /**
  * @param $path
  * @param $mode
  * @param $options
  * @param $opened_path
  * @return bool
  * @throws IOException
  */
 public function stream_open($path, $mode, $options, &$opened_path)
 {
     // if we're on Windows, urldecode() the path again
     if (FileSystem::getFileSystem()->getSeparator() == '\\') {
         $path = urldecode($path);
     }
     $filepath = substr($path, 8);
     $this->createDirectories(dirname($filepath));
     $this->fp = fopen($filepath, $mode);
     if (!$this->fp) {
         throw new BuildException("Unable to open stream for path {$path}");
     }
     return true;
 }
コード例 #5
0
 public function main()
 {
     if ('' === $this->property) {
         throw new BuildException('You must specify the property attribute!');
     }
     if (true === is_null($this->baseDir)) {
         $baseDir = new PhingFile($this->project->getBaseDir());
         $this->addBaseDir($baseDir);
     }
     $directorySeparator = FileSystem::getFileSystem()->getSeparator();
     $baseName = $this->baseDir->getPath();
     $baseNameParts = explode($directorySeparator, $baseName);
     $numberOfBaseNameParts = count($baseNameParts);
     if ($this->strip > $numberOfBaseNameParts) {
         throw new BuildException('Cannot strip ' . $this->strip . ' components from a ' . $numberOfBaseNameParts . ' components path!');
     }
     while ($this->strip > 0) {
         array_pop($baseNameParts);
         $this->strip = $this->strip - 1;
     }
     $baseName = implode($directorySeparator, $baseNameParts);
     $baseName = basename($baseName);
     $this->project->setProperty($this->property, $baseName);
 }
コード例 #6
0
ファイル: AvailableTask.php プロジェクト: Ingewikkeld/phing
 /**
  * @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();
 }
コード例 #7
0
ファイル: FtpDeployTask.php プロジェクト: sergeytsivin/haru
 /**
  * The main entry point method.
  */
 public function main()
 {
     $project = $this->getProject();
     require_once 'Net/FTP.php';
     $ftp = new Net_FTP($this->host, $this->port);
     $ret = $ftp->connect();
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage());
     } else {
         $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel);
     }
     $ret = $ftp->login($this->username, $this->password);
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage());
     } else {
         $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel);
     }
     if ($this->passive) {
         $this->log('Setting passive mode', $this->logLevel);
         $ret = $ftp->setPassive();
         if (@PEAR::isError($ret)) {
             $ftp->disconnect();
             throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage());
         }
     }
     // append '/' to the end if necessary
     $dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/';
     if ($this->clearFirst) {
         // TODO change to a loop through all files and directories within current directory
         $this->log('Clearing directory ' . $dir, $this->logLevel);
         $ftp->rm($dir, true);
     }
     // Create directory just in case
     $ret = $ftp->mkdir($dir, true);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage());
     }
     $ret = $ftp->cd($dir);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage());
     } else {
         $this->log('Changed directory ' . $dir, $this->logLevel);
     }
     $fs = FileSystem::getFileSystem();
     $convert = $fs->getSeparator() == '\\';
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         foreach ($srcDirs as $dirname) {
             if ($convert) {
                 $dirname = str_replace('\\', '/', $dirname);
             }
             $this->log('Will create directory ' . $dirname, $this->logLevel);
             $ret = $ftp->mkdir($dirname, true);
             if (@PEAR::isError($ret)) {
                 $ftp->disconnect();
                 throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage());
             }
         }
         foreach ($srcFiles as $filename) {
             $file = new PhingFile($fromDir->getAbsolutePath(), $filename);
             if ($convert) {
                 $filename = str_replace('\\', '/', $filename);
             }
             $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel);
             $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
             if (@PEAR::isError($ret)) {
                 $ftp->disconnect();
                 throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage());
             }
         }
     }
     $ftp->disconnect();
     $this->log('Disconnected from FTP server', $this->logLevel);
 }
コード例 #8
0
 /**
  * Transforms the DOM document
  */
 protected function transform(DOMDocument $document)
 {
     if (!$this->toDir->exists()) {
         throw new BuildException("Directory '" . $this->toDir . "' does not exist");
     }
     $xslfile = $this->getStyleSheet();
     $xsl = new DOMDocument();
     $xsl->load($xslfile->getAbsolutePath());
     $proc = new XSLTProcessor();
     if (defined('XSL_SECPREF_WRITE_FILE')) {
         if (version_compare(PHP_VERSION, '5.4', "<")) {
             ini_set("xsl.security_prefs", XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY);
         } else {
             $proc->setSecurityPrefs(XSL_SECPREF_WRITE_FILE | XSL_SECPREF_CREATE_DIRECTORY);
         }
     }
     $proc->importStyleSheet($xsl);
     $proc->setParameter('', 'output.sorttable', $this->useSortTable);
     if ($this->format == "noframes") {
         $writer = new FileWriter(new PhingFile($this->toDir, "phpunit-noframes.html"));
         $writer->write($proc->transformToXML($document));
         $writer->close();
     } else {
         ExtendedFileStream::registerStream();
         $toDir = (string) $this->toDir;
         // urlencode() the path if we're on Windows
         if (FileSystem::getFileSystem()->getSeparator() == '\\') {
             $toDir = urlencode($toDir);
         }
         // no output for the framed report
         // it's all done by extension...
         $proc->setParameter('', 'output.dir', $toDir);
         $proc->transformToXML($document);
         ExtendedFileStream::unregisterStream();
     }
 }
コード例 #9
0
 /**
  * This method does the work.
  * @return void
  */
 function main()
 {
     if ($this->list === null && count($this->filesets) == 0) {
         throw new BuildException("Need either list or nested fileset to iterate through");
     }
     if ($this->param === null) {
         throw new BuildException("You must supply a property name to set on each iteration in param");
     }
     if ($this->calleeTarget === null) {
         throw new BuildException("You must supply a target to perform");
     }
     $callee = $this->callee;
     $callee->setTarget($this->calleeTarget);
     $callee->setInheritAll(true);
     $callee->setInheritRefs(true);
     if (trim($this->list)) {
         $arr = explode($this->delimiter, $this->list);
         foreach ($arr as $value) {
             $value = trim($value);
             $this->log("Setting param '{$this->param}' to value '{$value}'", Project::MSG_VERBOSE);
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->param);
             $prop->setValue($value);
             $callee->main();
         }
     }
     $total_files = 0;
     $total_dirs = 0;
     // filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $fromDir = $fs->getDir($this->project);
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         $this->log(count($srcDirs) . ' directories and ' . count($srcFiles) . ' files', Project::MSG_VERBOSE);
         $filecount = count($srcFiles);
         $total_files = $total_files + $filecount;
         for ($j = 0; $j < $filecount; $j++) {
             $value = $srcFiles[$j];
             if ($this->param) {
                 $this->log("Setting param '{$this->param}' to value '{$value}'", Project::MSG_VERBOSE);
                 $prop = $callee->createProperty();
                 $prop->setOverride(true);
                 $prop->setName($this->param);
                 $prop->setValue($value);
             }
             if ($this->absparam) {
                 $prop = $callee->createProperty();
                 $prop->setOverride(true);
                 $prop->setName($this->absparam);
                 $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value);
             }
             $callee->main();
         }
         $dircount = count($srcDirs);
         $total_dirs = $total_dirs + $dircount;
         for ($j = 0; $j < $dircount; $j++) {
             $value = $srcDirs[$j];
             if ($this->param) {
                 $this->log("Setting param '{$this->param}' to value '{$value}'", Project::MSG_VERBOSE);
                 $prop = $callee->createProperty();
                 $prop->setOverride(true);
                 $prop->setName($this->param);
                 $prop->setValue($value);
             }
             if ($this->absparam) {
                 $prop = $callee->createProperty();
                 $prop->setOverride(true);
                 $prop->setName($this->absparam);
                 $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value);
             }
             $callee->main();
         }
     }
 }
コード例 #10
0
 /**
  * Build a list of files (from the fileset elements)
  * and call the phpDocumentor parser
  *
  * @return string
  */
 private function parseFiles()
 {
     $parser = $this->app['parser'];
     $builder = $this->app['descriptor.builder'];
     $builder->createProjectDescriptor();
     $projectDescriptor = $builder->getProjectDescriptor();
     $projectDescriptor->setName($this->title);
     $paths = array();
     // filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $dir = $fs->getDir($this->project);
         $srcFiles = $ds->getIncludedFiles();
         foreach ($srcFiles as $file) {
             $paths[] = $dir . FileSystem::getFileSystem()->getSeparator() . $file;
         }
     }
     $this->project->log("Will parse " . count($paths) . " file(s)", Project::MSG_VERBOSE);
     $files = new \phpDocumentor\Fileset\Collection();
     $files->addFiles($paths);
     $mapper = new \phpDocumentor\Descriptor\Cache\ProjectDescriptorMapper($this->app['descriptor.cache']);
     $mapper->garbageCollect($files);
     $mapper->populate($projectDescriptor);
     $parser->setPath($files->getProjectRoot());
     $parser->setDefaultPackageName($this->defaultPackageName);
     $parser->parse($builder, $files);
     $mapper->save($projectDescriptor);
     return $mapper;
 }
コード例 #11
0
 /**
  * The main entry point method.
  */
 public function main()
 {
     $project = $this->getProject();
     require_once 'Net/FTP.php';
     $ftp = new Net_FTP($this->host, $this->port);
     if ($this->ssl) {
         $ret = $ftp->setSsl();
         if (@PEAR::isError($ret)) {
             throw new BuildException('SSL connection not supported by php' . ': ' . $ret->getMessage());
         } else {
             $this->log('Use SSL connection', $this->logLevel);
         }
     }
     $ret = $ftp->connect();
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage());
     } else {
         $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel);
     }
     $ret = $ftp->login($this->username, $this->password);
     if (@PEAR::isError($ret)) {
         throw new BuildException('Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage());
     } else {
         $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel);
     }
     if ($this->passive) {
         $this->log('Setting passive mode', $this->logLevel);
         $ret = $ftp->setPassive();
         if (@PEAR::isError($ret)) {
             $ftp->disconnect();
             throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage());
         }
     }
     // append '/' to the end if necessary
     $dir = substr($this->dir, -1) == '/' ? $this->dir : $this->dir . '/';
     if ($this->clearFirst) {
         // TODO change to a loop through all files and directories within current directory
         $this->log('Clearing directory ' . $dir, $this->logLevel);
         $ftp->rm($dir, true);
     }
     // Create directory just in case
     $ret = $ftp->mkdir($dir, true);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage());
     }
     $ret = $ftp->cd($dir);
     if (@PEAR::isError($ret)) {
         $ftp->disconnect();
         throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage());
     } else {
         $this->log('Changed directory ' . $dir, $this->logLevel);
     }
     $fs = FileSystem::getFileSystem();
     $convert = $fs->getSeparator() == '\\';
     foreach ($this->filesets as $fs) {
         // Array for holding directory content informations
         $remoteFileInformations = array();
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         foreach ($srcDirs as $dirname) {
             if ($convert) {
                 $dirname = str_replace('\\', '/', $dirname);
             }
             // Read directory informations, if file exists, else create the directory
             if (!$this->_directoryInformations($ftp, $remoteFileInformations, $dirname)) {
                 $this->log('Will create directory ' . $dirname, $this->logLevel);
                 $ret = $ftp->mkdir($dirname, true);
                 if (@PEAR::isError($ret)) {
                     $ftp->disconnect();
                     throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage());
                 }
             }
             if ($this->dirmode) {
                 if ($this->dirmode == 'inherit') {
                     $mode = fileperms($dirname);
                 } else {
                     $mode = $this->dirmode;
                 }
                 // Because Net_FTP does not support a chmod call we call ftp_chmod directly
                 ftp_chmod($ftp->_handle, $mode, $dirname);
             }
         }
         foreach ($srcFiles as $filename) {
             $file = new PhingFile($fromDir->getAbsolutePath(), $filename);
             if ($convert) {
                 $filename = str_replace('\\', '/', $filename);
             }
             $local_filemtime = filemtime($file->getCanonicalPath());
             if (isset($remoteFileInformations[$filename]['stamp'])) {
                 $remoteFileModificationTime = $remoteFileInformations[$filename]['stamp'];
             } else {
                 $remoteFileModificationTime = 0;
             }
             if (!$this->depends || $local_filemtime > $remoteFileModificationTime) {
                 if ($this->skipOnSameSize === true && $file->length() === $ftp->size($filename)) {
                     $this->log('Skipped ' . $file->getCanonicalPath(), $this->logLevel);
                     continue;
                 }
                 $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel);
                 $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode);
                 if (@PEAR::isError($ret)) {
                     $ftp->disconnect();
                     throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage());
                 }
             }
             if ($this->filemode) {
                 if ($this->filemode == 'inherit') {
                     $mode = fileperms($filename);
                 } else {
                     $mode = $this->filemode;
                 }
                 // Because Net_FTP does not support a chmod call we call ftp_chmod directly
                 ftp_chmod($ftp->_handle, $mode, $filename);
             }
         }
     }
     $ftp->disconnect();
     $this->log('Disconnected from FTP server', $this->logLevel);
 }
コード例 #12
0
 /**
  * Interpret the filename as a file relative to the given file -
  * unless the filename already represents an absolute filename.
  *
  * @param  $file the "reference" file for relative paths. This
  *         instance must be an absolute file and must not contain
  *         ./ or ../ sequences (same for \ instead of /).
  * @param  $filename a file name
  *
  * @return PhingFile A PhingFile object pointing to an absolute file that doesn't contain ./ or ../ sequences
  *         and uses the correct separator for the current platform.
  */
 function resolveFile($file, $filename)
 {
     // remove this and use the static class constant File::seperator
     // as soon as ZE2 is ready
     $fs = FileSystem::getFileSystem();
     $filename = str_replace('/', $fs->getSeparator(), str_replace('\\', $fs->getSeparator(), $filename));
     // deal with absolute files
     if (StringHelper::startsWith($fs->getSeparator(), $filename) || strlen($filename) >= 2 && Character::isLetter($filename[0]) && $filename[1] === ':') {
         return new PhingFile($this->normalize($filename));
     }
     if (strlen($filename) >= 2 && Character::isLetter($filename[0]) && $filename[1] === ':') {
         return new PhingFile($this->normalize($filename));
     }
     $helpFile = new PhingFile($file->getAbsolutePath());
     $tok = strtok($filename, $fs->getSeparator());
     while ($tok !== false) {
         $part = $tok;
         if ($part === '..') {
             $parentFile = $helpFile->getParent();
             if ($parentFile === null) {
                 $msg = "The file or path you specified ({$filename}) is invalid relative to " . $file->getPath();
                 throw new IOException($msg);
             }
             $helpFile = new PhingFile($parentFile);
         } else {
             if ($part === '.') {
                 // Do nothing here
             } else {
                 $helpFile = new PhingFile($helpFile, $part);
             }
         }
         $tok = strtok($fs->getSeparator());
     }
     return new PhingFile($helpFile->getAbsolutePath());
 }
コード例 #13
0
 protected function replaceSeparator($item)
 {
     $fs = FileSystem::getFileSystem();
     return str_replace($fs->getSeparator(), '/', $item);
 }
コード例 #14
0
ファイル: PhingFile.php プロジェクト: kenguest/phing
 /**
  * Compares two abstract pathnames lexicographically.  The ordering
  * defined by this method depends upon the underlying system.  On UNIX
  * systems, alphabetic case is significant in comparing pathnames; on Win32
  * systems it is not.
  *
  * @param PhingFile $file Th file whose pathname sould be compared to the pathname of this file.
  *
  * @return int Zero if the argument is equal to this abstract pathname, a
  *             value less than zero if this abstract pathname is
  *             lexicographically less than the argument, or a value greater
  *             than zero if this abstract pathname is lexicographically
  *             greater than the argument
  */
 public function compareTo(PhingFile $file)
 {
     $fs = FileSystem::getFileSystem();
     return $fs->compare($this, $file);
 }
コード例 #15
0
ファイル: ImportTask.php プロジェクト: alangalipaud/ProjetQCM
 /**
  * Initialize task.
  * @return void
  */
 public function init()
 {
     $this->fs = FileSystem::getFileSystem();
 }
コード例 #16
0
 /**
  * Build a list of files (from the fileset elements) and call the DocBlox parser
  * @return string
  */
 private function parseFiles()
 {
     $parser = new DocBlox_Parser();
     DocBlox_Parser_Abstract::$event_dispatcher = new sfEventDispatcher();
     $parser->setTitle($this->title);
     $paths = array();
     // filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $dir = $fs->getDir($this->project);
         $srcFiles = $ds->getIncludedFiles();
         foreach ($srcFiles as $file) {
             $paths[] = $dir . FileSystem::getFileSystem()->getSeparator() . $file;
         }
     }
     $this->log("Will parse " . count($paths) . " file(s)", Project::MSG_VERBOSE);
     $files = new DocBlox_Parser_Files();
     $files->addFiles($paths);
     $parser->setPath($files->getProjectRoot());
     return $parser->parseFiles($files);
 }
コード例 #17
0
 public function tearDown()
 {
     $this->outStream->close();
     FileSystem::getFileSystem()->unlink($this->tmpFile->getAbsolutePath());
 }
コード例 #18
0
 /**
  * set file readonly on unix
  *
  * @param PhingFile $f
  *
  * @throws Exception
  * @throws IOException
  */
 public function setReadOnly($f)
 {
     if ($f instanceof PhingFile) {
         $strPath = (string) $f->getPath();
         $perms = (int) (@fileperms($strPath) & 0444);
         return FileSystem::getFileSystem()->chmod($strPath, $perms);
     } else {
         throw new Exception("IllegalArgumentType: Argument is not File");
     }
 }
コード例 #19
0
 /**
  * Build a list of files (from the fileset elements) and call the DocBlox parser
  * @return string
  */
 private function parseFiles()
 {
     $parser = new DocBlox_Parser();
     $parser->setTitle($this->title);
     if ($this->quiet) {
         $parser->setLogLevel(Zend_Log::CRIT);
     }
     $files = array();
     // filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $dir = $fs->getDir($this->project);
         $srcFiles = $ds->getIncludedFiles();
         foreach ($srcFiles as $file) {
             $files[] = $dir . FileSystem::getFileSystem()->getSeparator() . $file;
         }
     }
     $this->log("Will parse " . count($files) . " file(s)", Project::MSG_VERBOSE);
     return $parser->parseFiles($files);
 }
コード例 #20
0
 /**
  * Create the actual link
  * 
  * @access protected
  * @param string $target
  * @param string $link
  * @return bool
  */
 protected function symlink($target, $link)
 {
     $fs = FileSystem::getFileSystem();
     if (is_link($link) && readlink($link) == $target) {
         $this->log('Link exists: ' . $link, Project::MSG_INFO);
         return true;
     } elseif (file_exists($link)) {
         if (!$this->getOverwrite()) {
             $this->log('Not overwriting existing link ' . $link, Project::MSG_ERR);
             return false;
         }
         if (is_link($link) || is_file($link)) {
             $fs->unlink($link);
             $this->log('Link removed: ' . $link, Project::MSG_INFO);
         } else {
             $fs->rmdir($link, true);
             $this->log('Directory removed: ' . $link, Project::MSG_INFO);
         }
     }
     $this->log('Linking: ' . $target . ' to ' . $link, Project::MSG_INFO);
     return $fs->symlink($target, $link);
 }
コード例 #21
0
 /**
  * Processes a list of files & directories 
  * 
  * @param Task      $callee
  * @param PhingFile $fromDir
  * @param array     $srcFiles
  * @param array     $srcDirs
  */
 protected function process(Task $callee, PhingFile $fromDir, $srcFiles, $srcDirs)
 {
     $filecount = count($srcFiles);
     $this->total_files += $filecount;
     for ($j = 0; $j < $filecount; $j++) {
         $value = $srcFiles[$j];
         if ($this->param) {
             $this->log("Setting param '{$this->param}' to value '{$value}'", Project::MSG_VERBOSE);
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->param);
             $prop->setValue($value);
         }
         if ($this->absparam) {
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->absparam);
             $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value);
         }
         $callee->main();
     }
     $dircount = count($srcDirs);
     $this->total_dirs += $dircount;
     for ($j = 0; $j < $dircount; $j++) {
         $value = $srcDirs[$j];
         if ($this->param) {
             $this->log("Setting param '{$this->param}' to value '{$value}'", Project::MSG_VERBOSE);
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->param);
             $prop->setValue($value);
         }
         if ($this->absparam) {
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->absparam);
             $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value);
         }
         $callee->main();
     }
 }
コード例 #22
0
ファイル: ExtractBaseTask.php プロジェクト: Ingewikkeld/phing
 /**
  * @param PhingFile $compressedArchiveFile
  * @throws BuildException
  * @internal param array $files array of filenames
  * @internal param PhingFile $dir
  * @return boolean
  */
 protected function isDestinationUpToDate(PhingFile $compressedArchiveFile)
 {
     if (!$compressedArchiveFile->exists()) {
         throw new BuildException("Could not find file " . $compressedArchiveFile->__toString() . " to extract.");
     }
     $compressedArchiveContent = $this->listArchiveContent($compressedArchiveFile);
     if (is_array($compressedArchiveContent)) {
         $fileSystem = FileSystem::getFileSystem();
         foreach ($compressedArchiveContent as $compressArchivePathInfo) {
             $compressArchiveFilename = $compressArchivePathInfo['filename'];
             if (!empty($this->removepath) && strlen($compressArchiveFilename) >= strlen($this->removepath)) {
                 $compressArchiveFilename = preg_replace('/^' . $this->removepath . '/', '', $compressArchiveFilename);
             }
             $compressArchivePath = new PhingFile($this->todir, $compressArchiveFilename);
             if (!$compressArchivePath->exists() || $fileSystem->compareMTimes($compressedArchiveFile->getCanonicalPath(), $compressArchivePath->getCanonicalPath()) == 1) {
                 return false;
             }
         }
     }
     return true;
 }
コード例 #23
0
 /**
  * Perform the resolution & set property.
  */
 public function main()
 {
     if (!$this->propertyName) {
         throw new BuildException("You must specify the propertyName attribute", $this->getLocation());
     }
     // Currently only files are supported
     if ($this->file === null) {
         throw new BuildException("You must specify a path to resolve", $this->getLocation());
     }
     $fs = FileSystem::getFileSystem();
     // if dir attribute was specified then we should
     // use that as basedir to which file was relative.
     // -- unless the file specified is an absolute path
     if ($this->dir !== null && !$fs->isAbsolute(new PhingFile($this->file))) {
         $resolved = new PhingFile($this->dir->getPath(), $this->file);
     } else {
         // otherwise just resolve it relative to project basedir
         $resolved = $this->project->resolveFile($this->file);
     }
     $this->log("Resolved " . $this->file . " to " . $resolved->getAbsolutePath(), $this->logLevel);
     $this->project->setProperty($this->propertyName, $resolved->getAbsolutePath());
 }
コード例 #24
0
 /**
  * Build a list of files (from the fileset elements)
  * and call the phpDocumentor parser
  *
  * @return string
  */
 private function parseFiles()
 {
     $parser = new \phpDocumentor\Parser\Parser();
     $parser->setTitle($this->title);
     $paths = array();
     // filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $dir = $fs->getDir($this->project);
         $srcFiles = $ds->getIncludedFiles();
         foreach ($srcFiles as $file) {
             $paths[] = $dir . FileSystem::getFileSystem()->getSeparator() . $file;
         }
     }
     $this->project->log("Will parse " . count($paths) . " file(s)", Project::MSG_VERBOSE);
     $files = new phpDocumentor\Fileset\Collection();
     $files->addFiles($paths);
     $parser->setPath($files->getProjectRoot());
     return $parser->parseFiles($files);
 }
コード例 #25
0
ファイル: ForeachTask.php プロジェクト: codebubb/web_ssh
 /**
  * Processes a list of files & directories
  *
  * @param Task      $callee
  * @param PhingFile $fromDir
  * @param array     $srcFiles
  * @param array     $srcDirs
  */
 protected function process(Task $callee, PhingFile $fromDir, $srcFiles, $srcDirs)
 {
     $mapper = null;
     if ($this->mapperElement !== null) {
         $mapper = $this->mapperElement->getImplementation();
     }
     $filecount = count($srcFiles);
     $this->total_files += $filecount;
     for ($j = 0; $j < $filecount; $j++) {
         $value = $srcFiles[$j];
         $premapped = "";
         if ($this->absparam) {
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->absparam);
             $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value);
         }
         if ($mapper !== null) {
             $premapped = $value;
             $value = $mapper->main($value);
             if ($value === null) {
                 continue;
             }
             $value = array_shift($value);
         }
         if ($this->param) {
             $this->log("Setting param '{$this->param}' to value '{$value}'" . ($premapped ? " (mapped from '{$premapped}')" : ''), Project::MSG_VERBOSE);
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->param);
             $prop->setValue($value);
         }
         $callee->main();
     }
     $dircount = count($srcDirs);
     $this->total_dirs += $dircount;
     for ($j = 0; $j < $dircount; $j++) {
         $value = $srcDirs[$j];
         $premapped = "";
         if ($this->absparam) {
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->absparam);
             $prop->setValue($fromDir . FileSystem::getFileSystem()->getSeparator() . $value);
         }
         if ($mapper !== null) {
             $premapped = $value;
             $value = $mapper->main($value);
             if ($value === null) {
                 continue;
             }
             $value = array_shift($value);
         }
         if ($this->param) {
             $this->log("Setting param '{$this->param}' to value '{$value}'" . ($premapped ? " (mapped from '{$premapped}')" : ''), Project::MSG_VERBOSE);
             $prop = $callee->createProperty();
             $prop->setOverride(true);
             $prop->setName($this->param);
             $prop->setValue($value);
         }
         $callee->main();
     }
 }
コード例 #26
0
ファイル: SymlinkTask.php プロジェクト: namesco/phing
 /**
  * Create the actual link
  * 
  * @access protected
  * @param string $target
  * @param string $link
  * @return bool
  */
 protected function symlink($target, $link)
 {
     if (file_exists($link)) {
         if (!is_link($link)) {
             $this->log('File exists: ' . $link, Project::MSG_ERR);
             return false;
         }
         if (readlink($link) == $target || !$this->getOverwrite()) {
             $this->log('Link exists: ' . $link, Project::MSG_ERR);
             return false;
         }
         unlink($link);
     }
     $fs = FileSystem::getFileSystem();
     $this->log('Linking: ' . $target . ' to ' . $link, Project::MSG_INFO);
     return $fs->symlink($target, $link);
 }
コード例 #27
0
 /**
  * Create the actual link
  * 
  * @access protected
  * @param string $target
  * @param string $link
  * @return bool
  */
 protected function symlink($target, $link)
 {
     if (file_exists($link)) {
         $this->log('Link exists: ' . $link, Project::MSG_ERR);
         return false;
     }
     $fs = FileSystem::getFileSystem();
     $this->log('Linking: ' . $target . ' to ' . $link, Project::MSG_INFO);
     return $fs->symlink($target, $link);
 }
コード例 #28
0
 /**
  * Replaces all external-schema nodes with the content of xml schema that node refers to
  *
  * Recurses to include any external schema referenced from in an included xml (and deeper)
  * Note: this function very much assumes at least a reasonable XML schema, maybe it'll proof
  * users don't have those and adding some more informative exceptions would be better
  *
  * @param      DomDocument $dom
  * @param      string $srcDir
  * @return     void (objects, DomDocument, are references by default in PHP 5, so returning it is useless)
  **/
 protected function includeExternalSchemas(DomDocument $dom, $srcDir)
 {
     $databaseNode = $dom->getElementsByTagName("database")->item(0);
     $externalSchemaNodes = $dom->getElementsByTagName("external-schema");
     $fs = FileSystem::getFileSystem();
     while ($externalSchema = $externalSchemaNodes->item(0)) {
         $include = $externalSchema->getAttribute("filename");
         $externalSchema->parentNode->removeChild($externalSchema);
         if ($fs->prefixLength($include) != 0) {
             $externalSchemaFile = new PhingFile($include);
         } else {
             $externalSchemaFile = new PhingFile($srcDir, $include);
         }
         $externalSchemaDom = new DomDocument('1.0', 'UTF-8');
         $externalSchemaDom->load($externalSchemaFile->getAbsolutePath());
         $this->includeExternalSchemas($externalSchemaDom, $srcDir);
         foreach ($externalSchemaDom->getElementsByTagName("table") as $tableNode) {
             // see xsd, datatase may only have table or external-schema, the latter was just deleted so this should cover everything
             $databaseNode->appendChild($dom->importNode($tableNode, true));
         }
     }
 }
コード例 #29
0
 public function tearDown()
 {
     FileSystem::getFileSystem()->unlink($this->tmpFile->getAbsolutePath());
 }