/**
  * Construct a new FileInputStream.
  * 
  * @param PhingFile|string $file Path to the file
  * @param boolean $append Whether to append (ignored)
  * @throws Exception - if invalid argument specified.
  * @throws IOException - if unable to open file.
  */
 public function __construct($file, $append = false)
 {
     if ($file instanceof PhingFile) {
         $this->file = $file;
     } elseif (is_string($file)) {
         $this->file = new PhingFile($file);
     } else {
         throw new Exception("Invalid argument type for \$file.");
     }
     $stream = @fopen($this->file->getAbsolutePath(), "rb");
     if ($stream === false) {
         throw new IOException("Unable to open " . $this->file->__toString() . " for reading: " . $php_errormsg);
     }
     parent::__construct($stream);
 }
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         /*
          * Delete old package, if exists.
          */
         if ($this->destinationFile->exists()) {
             /*
              * TODO Check operation for errors...
              */
             $this->destinationFile->delete();
         }
         $phar = $this->buildPhar();
         $phar->startBuffering();
         $baseDirectory = realpath($this->baseDirectory->getPath());
         foreach ($this->filesets as $fileset) {
             $this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to package', Project::MSG_VERBOSE);
             $phar->buildFromIterator($fileset, $baseDirectory);
         }
         $phar->stopBuffering();
         /*
          * File compression, if needed.
          */
         if (Phar::NONE != $this->compression) {
             $phar->compressFiles($this->compression);
         }
     } catch (Exception $e) {
         throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
Example #3
0
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         /*
          * Delete old package, if exists.
          */
         if ($this->destinationFile->exists()) {
             /*
              * TODO Check operation for errors...
              */
             $this->destinationFile->delete();
         }
         $phar = $this->buildPhar();
         $phar->startBuffering();
         $baseDirectory = realpath($this->baseDirectory->getPath());
         foreach ($this->filesets as $fileset) {
             foreach ($fileset as $realFileName) {
                 /*
                  * Calculate local file name.
                  */
                 $localFileName = $realFileName;
                 if (0 === strpos($realFileName, $baseDirectory)) {
                     $localFileName = substr($realFileName, strlen($baseDirectory));
                 }
                 $this->log('Adding ' . $realFileName . ' as ' . $localFileName . ' to package', Project::MSG_VERBOSE);
                 $phar->addFile($realFileName, $localFileName);
             }
         }
         $phar->stopBuffering();
     } catch (Exception $e) {
         throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building archive: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         /**
          * Delete old archive, if exists.
          */
         if ($this->destinationFile->exists()) {
             $isDeleted = $this->destinationFile->delete();
             if (!$isDeleted) {
                 $this->log("Could not delete destination file {$this->destinationFile}", Project::MSG_WARN);
             }
         }
         $pharData = new PharData($this->baseDirectory->getPath() . '/' . $this->destinationFile->getName());
         foreach ($this->filesets as $fileset) {
             $this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to archive', Project::MSG_VERBOSE);
             $pharData->buildFromIterator($fileset->getIterator(), $fileset->getDir($this->project));
         }
         if ($this->compression !== PHAR::NONE && $pharData->canCompress($this->compression)) {
             try {
                 $pharData->compress($this->compression);
             } catch (UnexpectedValueException $uve) {
                 $pharData->compressFiles($this->compression);
             }
             unset($pharData);
         }
     } catch (Exception $e) {
         throw new BuildException('Problem creating archive: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
Example #5
0
 /**
  * Extract archive content into $this->todir directory
  * @param PhingFile Zip file to extract
  * @return boolean
  */
 protected function extractArchive(PhingFile $zipfile)
 {
     $this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO);
     $zip = new ZipArchive();
     $result = $zip->open($zipfile->getAbsolutePath());
     if (!$result) {
         $this->log("Unable to open zipfile " . $zipfile->__toString(), Project::MSG_ERR);
         return false;
     }
     $result = $zip->extractTo($this->todir->getAbsolutePath());
     if (!$result) {
         $this->log("Unable to extract zipfile " . $zipfile->__toString(), Project::MSG_ERR);
         return false;
     }
     return true;
 }
Example #6
0
 /**
  * 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;
 }
Example #7
0
 /**
  * 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;
 }
Example #8
0
 /**
  * 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());
     }
     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
         if ($this->areFilesetsUpToDate()) {
             $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);
         }
         if ($this->comment !== '') {
             $isCommented = $zip->setArchiveComment($this->comment);
             if ($isCommented === false) {
                 $this->log("Could not add a comment for the Archive.", Project::MSG_INFO);
             }
         }
         $this->addFilesetsToArchive($zip);
         $zip->close();
     } catch (IOException $ioe) {
         $msg = "Problem creating ZIP: " . $ioe->getMessage();
         throw new BuildException($msg, $ioe, $this->getLocation());
     }
 }
Example #9
0
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         /**
          * Delete old package, if exists.
          */
         if ($this->destinationFile->exists()) {
             /**
              * TODO Check operation for errors...
              */
             $this->destinationFile->delete();
         }
         $phar = $this->buildPhar();
         $phar->startBuffering();
         $baseDirectory = realpath($this->baseDirectory->getPath());
         foreach ($this->filesets as $fileset) {
             $this->log('Adding specified files in ' . $fileset->getDir($this->project) . ' to package', Project::MSG_VERBOSE);
             $phar->buildFromIterator($fileset, $baseDirectory);
         }
         $phar->stopBuffering();
         /**
          * File compression, if needed.
          */
         if (Phar::NONE != $this->compression) {
             $phar->compressFiles($this->compression);
         }
         if ($this->signatureAlgorithm == Phar::OPENSSL) {
             // Load up the contents of the key
             $keyContents = file_get_contents($this->key);
             // Attempt to load the given key as a PKCS#12 Cert Store first.
             if (openssl_pkcs12_read($keyContents, $certs, $this->keyPassword)) {
                 $private = openssl_pkey_get_private($certs['pkey']);
             } else {
                 // Fall back to a regular PEM-encoded private key.
                 // Setup an OpenSSL resource using the private key
                 // and tell the Phar to sign it using that key.
                 $private = openssl_pkey_get_private($keyContents, $this->keyPassword);
             }
             openssl_pkey_export($private, $pkey);
             $phar->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
             // Get the details so we can get the public key and write that out
             // alongside the phar.
             $details = openssl_pkey_get_details($private);
             file_put_contents($this->destinationFile . '.pubkey', $details['key']);
         } else {
             $phar->setSignatureAlgorithm($this->signatureAlgorithm);
         }
     } catch (Exception $e) {
         throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
Example #10
0
 protected function extractArchive(PhingFile $tarfile)
 {
     $this->log("Extracting tar file: " . $tarfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO);
     try {
         $tar = $this->initTar($tarfile);
         if (!$tar->extractModify($this->todir->getAbsolutePath(), $this->removepath)) {
             throw new BuildException('Failed to extract tar file: ' . $tarfile->getAbsolutePath());
         }
     } catch (IOException $ioe) {
         $msg = "Could not extract tar file: " . $ioe->getMessage();
         throw new BuildException($msg, $ioe, $this->getLocation());
     }
 }
 /**
  * @throws BuildException
  */
 public function main()
 {
     $this->checkPreconditions();
     try {
         $this->log('Building package: ' . $this->destinationFile->__toString(), Project::MSG_INFO);
         $baseDirectory = realpath($this->baseDirectory->getPath());
         try {
             $this->compressAllFiles($this->initPhar(), $baseDirectory);
         } catch (\RuntimeException $e) {
             $this->log('Most likely compression failed (known bug): ' . $e->getMessage());
             $this->compressEachFile($this->initPhar(), $baseDirectory);
         }
     } catch (Exception $e) {
         throw new BuildException('Problem creating package: ' . $e->getMessage(), $e, $this->getLocation());
     }
 }
Example #12
0
 /**
  * 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.");
     }
 }
Example #13
0
 /**
  * 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;
 }
Example #14
0
 /**
  * Does the actual work.
  */
 public function _touch()
 {
     if ($this->file !== null) {
         if (!$this->file->exists()) {
             $this->log("Creating " . $this->file->__toString(), $this->verbose ? Project::MSG_INFO : Project::MSG_VERBOSE);
             try {
                 // try to create file
                 $this->file->createNewFile($this->mkdirs);
             } catch (IOException $ioe) {
                 throw new BuildException("Error creating new file " . $this->file->__toString(), $ioe, $this->location);
             }
         }
     }
     $resetMillis = false;
     if ($this->millis < 0) {
         $resetMillis = true;
         $this->millis = Phing::currentTimeMillis();
     }
     if ($this->file !== null) {
         $this->touchFile($this->file);
     }
     // deal with the filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->getProject());
         $fromDir = $fs->getDir($this->getProject());
         $srcFiles = $ds->getIncludedFiles();
         $srcDirs = $ds->getIncludedDirectories();
         for ($j = 0, $_j = count($srcFiles); $j < $_j; $j++) {
             $this->touchFile(new PhingFile($fromDir, (string) $srcFiles[$j]));
         }
         for ($j = 0, $_j = count($srcDirs); $j < $_j; $j++) {
             $this->touchFile(new PhingFile($fromDir, (string) $srcDirs[$j]));
         }
     }
     if ($resetMillis) {
         $this->millis = -1;
     }
 }
Example #15
0
 protected function extractArchive(PhingFile $zipfile)
 {
     $extractParams = array('add_path' => $this->todir->getAbsolutePath());
     if (!empty($this->removepath)) {
         $extractParams['remove_path'] = $this->removepath;
     }
     $this->log("Extracting zip: " . $zipfile->__toString() . ' to ' . $this->todir->__toString(), Project::MSG_INFO);
     try {
         $zip = new Archive_Zip($zipfile->getAbsolutePath());
         $extractResponse = $zip->extract($extractParams);
         if (is_array($extractResponse)) {
             foreach ($extractResponse as $extractedPath) {
                 $this->log('Extracted' . $extractedPath['stored_filename'] . ' to ' . $this->todir->__toString(), Project::MSG_VERBOSE);
             }
         } else {
             if ($extractResponse === 0) {
                 throw new BuildException('Failed to extract zipfile: ' . $zip->errorInfo(true));
             }
         }
     } catch (IOException $ioe) {
         $msg = "Could not extract ZIP: " . $ioe->getMessage();
         throw new BuildException($msg, $ioe, $this->getLocation());
     }
 }
 /**
  * The main entry point
  *
  * @throws BuildException
  */
 function main()
 {
     $arguments = $this->constructArguments();
     $encoder = new PhingFile($this->ioncubePath, $this->encoderName . ($this->phpVersion == 5 ? '5' : ''));
     $this->log("Running ionCube Encoder...");
     exec($encoder->__toString() . ' ' . $arguments . " 2>&1", $output, $return);
     if ($return != 0) {
         throw new BuildException("Could not execute ionCube Encoder: " . implode(' ', $output));
     }
 }
Example #17
0
 /**
  * Actually copies the files
  *
  * @return void
  * @throws BuildException
  */
 protected function doWork()
 {
     // These "slots" allow filters to retrieve information about the currently-being-process files
     $fromSlot = $this->getRegisterSlot("currentFromFile");
     $fromBasenameSlot = $this->getRegisterSlot("currentFromFile.basename");
     $toSlot = $this->getRegisterSlot("currentToFile");
     $toBasenameSlot = $this->getRegisterSlot("currentToFile.basename");
     $mapSize = count($this->fileCopyMap);
     $total = $mapSize;
     // handle empty dirs if appropriate
     if ($this->includeEmpty) {
         $count = 0;
         foreach ($this->dirCopyMap as $srcdir => $destdir) {
             $s = new PhingFile((string) $srcdir);
             $d = new PhingFile((string) $destdir);
             if (!$d->exists()) {
                 // Setting source directory permissions to target
                 // (On permissions preservation, the target directory permissions
                 // will be inherited from the source directory, otherwise the 'mode'
                 // will be used)
                 $dirMode = $this->preservePermissions ? $s->getMode() : $this->mode;
                 // Directory creation with specific permission mode
                 if (!$d->mkdirs($dirMode)) {
                     $this->logError("Unable to create directory " . $d->__toString());
                 } else {
                     if ($this->preserveLMT) {
                         $d->setLastModified($s->lastModified());
                     }
                     $count++;
                 }
             }
         }
         if ($count > 0) {
             $this->log("Created " . $count . " empty director" . ($count == 1 ? "y" : "ies") . " in " . $this->destDir->getAbsolutePath());
         }
     }
     if ($mapSize == 0) {
         return;
     }
     $this->log("Copying " . $mapSize . " file" . ($mapSize === 1 ? '' : 's') . " to " . $this->destDir->getAbsolutePath());
     // walks the map and actually copies the files
     $count = 0;
     foreach ($this->fileCopyMap as $from => $toFiles) {
         if (is_array($toFiles)) {
             foreach ($toFiles as $to) {
                 $this->copyToSingleDestination($from, $to, $fromSlot, $fromBasenameSlot, $toSlot, $toBasenameSlot, $count, $total);
             }
         } else {
             $this->copyToSingleDestination($from, $toFiles, $fromSlot, $fromBasenameSlot, $toSlot, $toBasenameSlot, $count, $total);
         }
     }
 }
Example #18
0
 /**
  * Actually copies the files
  *
  * @access  private
  * @return  void
  * @throws  BuildException
  */
 protected function doWork()
 {
     // These "slots" allow filters to retrieve information about the currently-being-process files
     $fromSlot = $this->getRegisterSlot("currentFromFile");
     $fromBasenameSlot = $this->getRegisterSlot("currentFromFile.basename");
     $toSlot = $this->getRegisterSlot("currentToFile");
     $toBasenameSlot = $this->getRegisterSlot("currentToFile.basename");
     $mapSize = count($this->fileCopyMap);
     $total = $mapSize;
     if ($mapSize > 0) {
         $this->log("Copying " . $mapSize . " file" . ($mapSize === 1 ? '' : 's') . " to " . $this->destDir->getAbsolutePath());
         // walks the map and actually copies the files
         $count = 0;
         foreach ($this->fileCopyMap as $from => $to) {
             if ($from === $to) {
                 $this->log("Skipping self-copy of " . $from, $this->verbosity);
                 $total--;
                 continue;
             }
             $this->log("From " . $from . " to " . $to, $this->verbosity);
             try {
                 // try to copy file
                 $fromFile = new PhingFile($from);
                 $toFile = new PhingFile($to);
                 $fromSlot->setValue($fromFile->getPath());
                 $fromBasenameSlot->setValue($fromFile->getName());
                 $toSlot->setValue($toFile->getPath());
                 $toBasenameSlot->setValue($toFile->getName());
                 $this->fileUtils->copyFile($fromFile, $toFile, $this->overwrite, $this->preserveLMT, $this->filterChains, $this->getProject());
                 $count++;
             } catch (IOException $ioe) {
                 $this->log("Failed to copy " . $from . " to " . $to . ": " . $ioe->getMessage(), Project::MSG_ERR);
             }
         }
     }
     // handle empty dirs if appropriate
     if ($this->includeEmpty) {
         $destdirs = array_values($this->dirCopyMap);
         $count = 0;
         foreach ($destdirs as $destdir) {
             $d = new PhingFile((string) $destdir);
             if (!$d->exists()) {
                 if (!$d->mkdirs()) {
                     $this->log("Unable to create directory " . $d->__toString(), Project::MSG_ERR);
                 } else {
                     $count++;
                 }
             }
         }
         if ($count > 0) {
             $this->log("Copied " . $count . " empty director" . ($count == 1 ? "y" : "ies") . " to " . $this->destDir->getAbsolutePath());
         }
     }
 }
 /**
  * Actually change the mode for the file.
  *
  * @param PhingFile $file
  * @param string    $user
  * @param string    $group
  *
  * @throws BuildException
  * @throws Exception
  */
 private function chownFile(PhingFile $file, $user, $group = "")
 {
     if (!$file->exists()) {
         throw new BuildException("The file " . $file->__toString() . " does not exist");
     }
     try {
         if (!empty($user)) {
             $file->setUser($user);
         }
         if (!empty($group)) {
             $file->setGroup($group);
         }
         if ($this->verbose) {
             $this->log("Changed file owner on '" . $file->__toString() . "' to " . $user . ($group ? "." . $group : ""));
         }
     } catch (Exception $e) {
         if ($this->failonerror) {
             throw $e;
         } else {
             $this->log($e->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN);
         }
     }
 }
 /**
  * Load the sql file and then execute it
  *
  * @throws     BuildException
  */
 public function main()
 {
     $this->sqlCommand = trim($this->sqlCommand);
     if ($this->sqldbmap === null || $this->getSqlDbMap()->exists() === false) {
         throw new BuildException("You haven't provided an sqldbmap, or " . "the one you specified doesn't exist: " . $this->sqldbmap->getPath());
     }
     if ($this->url === null) {
         throw new BuildException("DSN url attribute must be set!");
     }
     $map = new Properties();
     try {
         $map->load($this->getSqlDbMap());
     } catch (IOException $ioe) {
         throw new BuildException("Cannot open and process the sqldbmap!");
     }
     $databases = array();
     foreach ($map->keys() as $sqlfile) {
         $database = $map->getProperty($sqlfile);
         // Q: already there?
         if (!isset($databases[$database])) {
             // A: No.
             $databases[$database] = array();
         }
         // We want to make sure that the base schemas
         // are inserted first.
         if (strpos($sqlfile, "schema.sql") !== false) {
             // add to the beginning of the array
             array_unshift($databases[$database], $sqlfile);
         } else {
             array_push($databases[$database], $sqlfile);
         }
     }
     foreach ($databases as $db => $files) {
         $transactions = array();
         foreach ($files as $fileName) {
             $file = new PhingFile($this->srcDir, $fileName);
             if ($file->exists()) {
                 $this->log("Executing statements in file: " . $file->__toString());
                 $transaction = new PropelSQLExecTransaction($this);
                 $transaction->setSrc($file);
                 $transactions[] = $transaction;
             } else {
                 $this->log("File '" . $file->__toString() . "' in sqldbmap does not exist, so skipping it.");
             }
         }
         $this->insertDatabaseSqlFiles($this->url, $db, $transactions);
     }
 }
Example #21
0
 /**
  * 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;
 }
Example #22
0
 /**
  * Attempts to rename a file from a source to a destination.
  * If overwrite is set to true, this method overwrites existing file
  * even if the destination file is newer.
  * Otherwise, the source f
  * ile is renamed only if the destination file #
  * is older than it.
  */
 private function renameFile(PhingFile $sourceFile, PhingFile $destFile, $overwrite)
 {
     $renamed = true;
     // ensure that parent dir of dest file exists!
     $parent = $destFile->getParentFile();
     if ($parent !== null) {
         if (!$parent->exists()) {
             $parent->mkdirs();
         }
     }
     if ($destFile->exists()) {
         try {
             $destFile->delete();
         } catch (Exception $e) {
             throw new BuildException("Unable to remove existing file " . $destFile->__toString() . ": " . $e->getMessage());
         }
     }
     $renamed = $sourceFile->renameTo($destFile);
     return $renamed;
 }
 /**
  * Actually change the mode for the file.
  * @param PhingFile $file
  * @param int $mode
  */
 private function chmodFile(PhingFile $file, $mode)
 {
     if (!$file->exists()) {
         throw new BuildException("The file " . $file->__toString() . " does not exist");
     }
     try {
         $file->setMode($mode);
         if ($this->verbose) {
             $this->log("Changed file mode on '" . $file->__toString() . "' to " . vsprintf("%o", $mode));
         }
     } catch (Exception $e) {
         if ($this->failonerror) {
             throw $e;
         } else {
             $this->log($e->getMessage(), $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN);
         }
     }
 }
Example #24
0
 /**
  * The main entry point
  *
  * @throws BuildException
  */
 public function main()
 {
     $arguments = $this->constructArguments();
     if (in_array($this->phpVersion, array(5, 53, 54))) {
         $encoderName = $this->encoderName . $this->phpVersion;
     } else {
         $encoderName = $this->encoderName;
     }
     $encoder = new PhingFile($this->ioncubePath, $encoderName);
     $this->log("Running ionCube Encoder...");
     if ($this->showCommandLine) {
         $this->log("Command line: " . $encoder->__toString() . ' ' . $arguments);
     }
     exec($encoder->__toString() . ' ' . $arguments . " 2>&1", $output, $return);
     if ($return != 0) {
         throw new BuildException("Could not execute ionCube Encoder: " . implode(' ', $output));
     }
 }
Example #25
0
 /**
  * Executes PHP_Depend_TextUI_Runner against PhingFile or a FileSet
  *
  * @return void
  * @throws BuildException
  */
 public function main()
 {
     $autoload = new PHP_Depend_Autoload();
     $autoload->register();
     if (!isset($this->_file) and count($this->_filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     if (count($this->_loggers) == 0) {
         throw new BuildException("Missing nested 'logger' element");
     }
     $this->validateLoggers();
     $this->validateAnalyzers();
     $filesToParse = array();
     if ($this->_file instanceof PhingFile) {
         $filesToParse[] = $this->_file->__toString();
     } else {
         // append any files in filesets
         foreach ($this->_filesets as $fs) {
             $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
             foreach ($files as $filename) {
                 $f = new PhingFile($fs->getDir($this->project), $filename);
                 $filesToParse[] = $f->getAbsolutePath();
             }
         }
     }
     $this->_runner = new PHP_Depend_TextUI_Runner();
     $this->_runner->addProcessListener(new PHP_Depend_TextUI_ResultPrinter());
     $configurationFactory = new PHP_Depend_Util_Configuration_Factory();
     $configuration = $configurationFactory->createDefault();
     $this->_runner->setConfiguration($configuration);
     $this->_runner->setSourceArguments($filesToParse);
     foreach ($this->_loggers as $logger) {
         // Register logger
         $this->_runner->addLogger($logger->getType(), $logger->getOutfile()->__toString());
     }
     foreach ($this->_analyzers as $analyzer) {
         // Register additional analyzer
         $this->_runner->addOption($analyzer->getType(), $analyzer->getValue());
     }
     // Disable annotation parsing
     if ($this->_withoutAnnotations) {
         $this->_runner->setWithoutAnnotations();
     }
     // Enable bad documentation support
     if ($this->_supportBadDocumentation) {
         $this->_runner->setSupportBadDocumentation();
     }
     // Check for suffix
     if (count($this->_allowedFileExtensions) > 0) {
         $this->_runner->setFileExtensions($this->_allowedFileExtensions);
     }
     // Check for ignore directories
     if (count($this->_excludeDirectories) > 0) {
         $this->_runner->setExcludeDirectories($this->_excludeDirectories);
     }
     // Check for exclude packages
     if (count($this->_excludePackages) > 0) {
         $this->_runner->setExcludePackages($this->_excludePackages);
     }
     // Check for configuration option
     if ($this->_configFile instanceof PhingFile) {
         if (file_exists($this->_configFile->__toString()) === false) {
             throw new BuildException('The configuration file "' . $this->_configFile->__toString() . '" doesn\'t exist.');
         }
         // Load configuration file
         $config = new PHP_Depend_Util_Configuration($this->_configFile->__toString(), null, true);
         // Store in config registry
         PHP_Depend_Util_ConfigurationInstance::set($config);
     }
     if ($this->_debug) {
         require_once 'PHP/Depend/Util/Log.php';
         // Enable debug logging
         PHP_Depend_Util_Log::setSeverity(PHP_Depend_Util_Log::DEBUG);
     }
     $this->_runner->run();
     if ($this->_runner->hasParseErrors() === true) {
         $this->log('Following errors occurred:');
         foreach ($this->_runner->getParseErrors() as $error) {
             $this->log($error);
         }
         if ($this->_haltonerror === true) {
             throw new BuildException('Errors occurred during parse process');
         }
     }
 }
Example #26
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();
 }
Example #27
0
 /**
  * Adds the options that are set via attributes and the nested tags to the options array.
  */
 private function populateOptions()
 {
     // These values could be overridden if explicitly defined using nested tags
     $this->preparedOptions['package'] = $this->package;
     $this->preparedOptions['packagedirectory'] = $this->dir->getAbsolutePath();
     if ($this->packageFile !== null) {
         // create one w/ full path
         $f = new PhingFile($this->packageFile->getAbsolutePath());
         $this->preparedOptions['packagefile'] = $f->getName();
         // must end in trailing slash
         $this->preparedOptions['outputdirectory'] = $f->getParent() . DIRECTORY_SEPARATOR;
         $this->log("Creating package file: " . $f->__toString(), Project::MSG_INFO);
     } else {
         $this->log("Creating [default] package.xml file in base directory.", Project::MSG_INFO);
     }
     // converts option objects and mapping objects into
     // key => value options that can be passed to PEAR_PackageFileManager
     foreach ($this->options as $opt) {
         $this->preparedOptions[$opt->getName()] = $opt->getValue();
         //no arrays yet. preg_split('/\s*,\s*/', $opt->getValue());
     }
     foreach ($this->mappings as $map) {
         $value = $map->getValue();
         // getValue returns complex value
         if ($map->getName() == 'deps') {
             $value = $this->fixDeps($value);
         }
         $this->preparedOptions[$map->getName()] = $value;
     }
 }
 /**
  * The main entry point
  *
  * @throws BuildException
  */
 function main()
 {
     $arguments = $this->constructArguments();
     $makelicense = new PhingFile($this->ioncubePath, 'make_license');
     $this->log("Running ionCube make_license...");
     exec($makelicense->__toString() . " " . $arguments . " 2>&1", $output, $return);
     if ($return != 0) {
         throw new BuildException("Could not execute ionCube make_license: " . implode(' ', $output));
     }
 }
Example #29
0
 /**
  * remove an array of files in a directory, and a list of subdirectories
  * which will only be deleted if 'includeEmpty' is true
  * @param PhingFile $d directory to work from
  * @param array &$files array of files to delete; can be of zero length
  * @param array &$dirs array of directories to delete; can of zero length
  */
 private function removeFiles(PhingFile $d, &$files, &$dirs)
 {
     if (count($files) > 0) {
         $this->log("Deleting " . count($files) . " files from " . $d->__toString());
         for ($j = 0, $_j = count($files); $j < $_j; $j++) {
             $f = new PhingFile($d, $files[$j]);
             $this->log("Deleting " . $f->getAbsolutePath(), $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);
                 }
             }
         }
     }
     if (count($dirs) > 0 && $this->includeEmpty) {
         $dirCount = 0;
         for ($j = count($dirs) - 1; $j >= 0; --$j) {
             $dir = new PhingFile($d, $dirs[$j]);
             $dirFiles = $dir->listDir();
             if ($dirFiles === null || count($dirFiles) === 0) {
                 $this->log("Deleting " . $dir->__toString(), $this->verbosity);
                 try {
                     $dir->delete();
                     $dirCount++;
                 } catch (Exception $e) {
                     $message = "Unable to delete directory " . $dir->__toString();
                     if ($this->failonerror) {
                         throw new BuildException($message);
                     } else {
                         $this->log($message, $this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN);
                     }
                 }
             }
         }
         if ($dirCount > 0) {
             $this->log("Deleted {$dirCount} director" . ($dirCount == 1 ? "y" : "ies") . " from " . $d->__toString());
         }
     }
 }
 /**
  * Loads configuration file
  *
  * @return null|PHP_Depend_Util_Configuration
  * @throws BuildException
  */
 private function getConfiguration()
 {
     // Check for configuration option
     if ($this->configFile == null || !$this->configFile instanceof PhingFile) {
         return null;
     }
     if (file_exists($this->configFile->__toString()) === false) {
         throw new BuildException('The configuration file "' . $this->configFile->__toString() . '" doesn\'t exist.');
     }
     if ($this->oldVersion) {
         $configurationClassName = 'PHP_Depend_Util_Configuration';
     } else {
         $configurationClassName = 'PDepend\\Util\\Configuration';
     }
     return new $configurationClassName($this->configFile->__toString(), null, true);
 }