/**
  * Uses a builder class to create the output class.
  * This method assumes that the DataModelBuilder class has been initialized with the build properties.
  *
  * @param OMBuilder $builder
  * @param boolean   $overwrite Whether to overwrite existing files with te new ones (default is YES).
  *
  * @todo       -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).
  * @return int
  */
 protected function build(OMBuilder $builder, $overwrite = true)
 {
     $path = $builder->getClassFilePath();
     $this->ensureDirExists(dirname($path));
     $_f = new PhingFile($this->getOutputDirectory(), $path);
     // skip files already created once
     if ($_f->exists() && !$overwrite) {
         $this->log("\t-> (exists) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
         return 0;
     }
     $script = $builder->build();
     foreach ($builder->getWarnings() as $warning) {
         $this->log($warning, Project::MSG_WARN);
     }
     // skip unchanged files
     if ($_f->exists() && $script == $_f->contents()) {
         $this->log("\t-> (unchanged) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
         return 0;
     }
     // write / overwrite new / changed files
     $action = $_f->exists() ? 'Updating' : 'Creating';
     $this->log(sprintf("\t-> %s %s (table: %s, builder: %s)", $action, $builder->getClassFilePath(), $builder->getTable()->getName(), get_class($builder)));
     file_put_contents($_f->getAbsolutePath(), $script);
     return 1;
 }
Example #2
0
 /**
  * @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());
         }
     }
 }
 public function main()
 {
     if (empty($this->filesets)) {
         throw new BuildException("You must specify a file or fileset(s).");
     }
     if (empty($this->_compilePath)) {
         throw new BuildException("You must specify location for compiled templates.");
     }
     date_default_timezone_set("America/New_York");
     $project = $this->getProject();
     $this->_count = $this->_total = 0;
     $smartyCompilePath = new PhingFile($this->_compilePath);
     if (!$smartyCompilePath->exists()) {
         $this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
         if (!$smartyCompilePath->mkdirs()) {
             throw new BuildException("Error creating compile path for Smarty in " . $this->_compilePath);
         }
     }
     $this->_smarty = new Smarty();
     $this->_smarty->use_sub_dirs = true;
     $this->_smarty->compile_dir = $smartyCompilePath;
     $this->_smarty->plugins_dir[] = $this->_pluginsPath;
     $this->_smarty->force_compile = $this->_forceCompile;
     // process filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($project);
         $fromDir = $fs->getDir($project);
         $srcFiles = $ds->getIncludedFiles();
         $this->_compile($fromDir, $srcFiles);
     }
     $this->log("Compiled " . $this->_count . " out of " . $this->_total . " Smarty templates");
 }
Example #4
0
 public function checkFileExists()
 {
     //Get the correct path to asset
     switch ($this->type) {
         case Asset::ASSET_TYPE_CSS:
             $this->assetFolder = $this->paths['css'];
             break;
         case Asset::ASSET_TYPE_JS:
             $this->assetFolder = $this->paths['js'];
             break;
         case Asset::ASSET_TYPE_IMAGE:
             $this->assetFolder = $this->paths['images'];
             break;
         default:
             $folder = '';
     }
     //Path to file
     $file = new PhingFile($this->assetsDir . '/' . $this->assetFolder . $this->file);
     //Check file exists
     if (!$file->exists()) {
         throw new BuildException("Unable to find asset file: " . $file->getAbsolutePath());
     }
     //Check we can read it
     if (!$file->canRead()) {
         throw IOException("Unable to read asset file: " . $file->getPath());
     }
     return $file;
 }
 /**
  * This test is our selection test that compared the file with the destfile.
  *
  * @param PhingFile $srcfile the source file
  * @param PhingFile $destfile the destination file
  * @return bool true if the files are different
  *
  * @throws BuildException
  */
 protected function selectionTest(PhingFile $srcfile, PhingFile $destfile)
 {
     try {
         // if either of them is missing, they are different
         if ($srcfile->exists() !== $destfile->exists()) {
             return true;
         }
         if ($srcfile->length() !== $destfile->length()) {
             // different size => different files
             return true;
         }
         if (!$this->ignoreFileTimes) {
             // different dates => different files
             if ($destfile->lastModified() !== $srcfile->lastModified()) {
                 return true;
             }
         }
         if (!$this->ignoreContents) {
             //here do a bulk comparison
             $fu = new FileUtils();
             return !$fu->contentEquals($srcfile, $destfile);
         }
     } catch (IOException $e) {
         throw new BuildException("while comparing {$srcfile} and {$destfile}", $e);
     }
     return false;
 }
 /**
  * Set the sqldbmap.
  * @param      PhingFile $sqldbmap The db map.
  */
 public function setOutputDirectory(PhingFile $out)
 {
     if (!$out->exists()) {
         $out->mkdirs();
     }
     $this->outDir = $out;
 }
Example #7
0
 private function createDirectories($path)
 {
     $f = new PhingFile($path);
     if (!$f->exists()) {
         $f->mkdirs();
     }
 }
Example #8
0
 public function setDir(PhingFile $dir)
 {
     if (!$dir->exists()) {
         throw new BuildException("Can not find asset directory: " . $dir->getAbsolutePath(), $this->location);
     }
     $this->assetDir = $dir->getAbsolutePath();
 }
Example #9
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;
 }
 /**
  *  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);
     }
 }
Example #11
0
 /**
  * Copied from 'CopyTask.php'
  */
 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("Minifying " . $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());
                 // perform ''minification'' once all other things are done on it.
                 $this->minify($toFile);
                 $count++;
             } catch (IOException $ioe) {
                 $this->log("Failed to minify " . $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());
         }
     }
 }
Example #12
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 #13
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());
     }
 }
 /**
  * @return Phar
  */
 private function initPhar()
 {
     /**
      * Delete old package, if exists.
      */
     if ($this->destinationFile->exists()) {
         $this->destinationFile->delete();
     }
     $phar = $this->buildPhar();
     return $phar;
 }
Example #15
0
 private function output($is_css, $data, $js)
 {
     if (!$is_css) {
         $folder = '/js/';
     } else {
         $folder = '/css/';
     }
     //Build path to output file
     $out = new PhingFile($this->assetDir . $folder . $js->file);
     //Check whether to overwrite files
     if ($out->exists() && !$js->overwrite) {
         throw new BuildException("Trying to write to " . $js->file . " but the overwrite flag has not been set to TRUE", $this->location);
     } else {
         if ($out->exists()) {
             $out->delete();
         }
     }
     //Write compressed JS to file
     file_put_contents($out->getAbsolutePath(), $data);
 }
Example #16
0
 /**
  * create the directory and all parents
  *
  * @throws BuildException if dir is somehow invalid, or creation failed.
  */
 public function main()
 {
     if ($this->dir === null) {
         throw new BuildException("dir attribute is required", $this->location);
     }
     if ($this->dir->isFile()) {
         throw new BuildException("Unable to create directory as a file already exists with that name: " . $this->dir->getAbsolutePath());
     }
     if (!$this->dir->exists()) {
         $result = $this->dir->mkdirs($this->mode);
         if (!$result) {
             if ($this->dir->exists()) {
                 $this->log("A different process or task has already created " . $this->dir->getAbsolutePath());
                 return;
             }
             $msg = "Directory " . $this->dir->getAbsolutePath() . " creation was not successful for an unknown reason";
             throw new BuildException($msg, $this->location);
         }
         $this->log("Created dir: " . $this->dir->getAbsolutePath());
     }
 }
 /**
  * Evaluate the condition.
  */
 public function evaluate()
 {
     foreach ($this->filelists as $filelist) {
         $dir = $filelist->getDir($this->getProject());
         foreach ($filelist->getFiles($this->getProject()) as $file) {
             $file = new PhingFile($dir, $file);
             if (!$file->exists()) {
                 return FALSE;
             }
         }
     }
     return TRUE;
 }
 /**
  * @return void
  */
 protected function _checkJarPath()
 {
     if ($this->_jarPath === null) {
         throw new BuildException(
             'Path to YUI compressor jar file must be specified',
             $this->location
         );
     } else if (!$this->_jarPath->exists()) {
         throw new BuildException(
             'Unable to locate jar file at specified path',
             $this->location
         );
     }
 }
 /**
  * [REQUIRED] Set the output directory. It will be
  * created if it doesn't exist.
  * @param  PhingFile $outputDirectory
  * @return void
  * @throws Exception
  */
 public function setOutputDirectory(PhingFile $outputDirectory)
 {
     try {
         if (!$outputDirectory->exists()) {
             $this->log("Output directory does not exist, creating: " . $outputDirectory->getPath(), Project::MSG_VERBOSE);
             if (!$outputDirectory->mkdirs()) {
                 throw new IOException("Unable to create Ouptut directory: " . $outputDirectory->getAbsolutePath());
             }
         }
         $this->outputDirectory = $outputDirectory->getCanonicalPath();
     } catch (IOException $ioe) {
         throw new BuildException($ioe);
     }
 }
Example #20
0
 /**
  * Uses a builder class to create the output class.
  * This method assumes that the DataModelBuilder class has been initialized with the build properties.
  * @param      OMBuilder $builder
  * @param      boolean $overwrite Whether to overwrite existing files with te new ones (default is YES).
  * @todo       -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).
  */
 protected function build(OMBuilder $builder, $overwrite = true)
 {
     $path = $builder->getClassFilePath();
     $this->ensureDirExists(dirname($path));
     $_f = new PhingFile($this->getOutputDirectory(), $path);
     if ($overwrite || !$_f->exists()) {
         $this->log("\t\t-> " . $builder->getClassname() . " [builder: " . get_class($builder) . "]");
         $script = $builder->build();
         file_put_contents($_f->getAbsolutePath(), $script);
         foreach ($builder->getWarnings() as $warning) {
             $this->log($warning, Project::MSG_WARN);
         }
     } else {
         $this->log("\t\t-> (exists) " . $builder->getClassname());
     }
 }
Example #21
0
 /**
  * @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());
         }
     }
 }
 /**
  * load properties from an XML file.
  *
  * @param PhingFile $file
  */
 protected function _loadFile(PhingFile $file)
 {
     $this->log("Loading " . $file->getAbsolutePath(), Project::MSG_INFO);
     if ($file->exists()) {
         $data = $this->_getData($file);
         $obj = new PropertyResolve($data);
         $properties = $obj->process();
         if (isset($properties['config']['phing'])) {
             unset($properties['config']['phing']);
             if (empty($properties['config'])) {
                 unset($properties['config']);
             }
         }
         $this->_save($properties);
     } else {
         $this->log("Unable to find property file: " . $file->getAbsolutePath() . "... skipped", Project::MSG_WARN);
     }
 }
Example #23
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 #24
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;
 }
    /**
     * @return void
     */
    public function main()
    {
        $this->_checkTargetDir();

        /* @var $fileSet FileSet */
        foreach ($this->_fileSets as $fileSet) {

            $files = $fileSet->getDirectoryScanner($this->project)
                ->getIncludedFiles();

            foreach ($files as $file) {

                $targetDir = new PhingFile($this->_targetDir, dirname($file));
                if (!$targetDir->exists()) {
                    $targetDir->mkdirs();
                }
                unset ($targetDir);

                $source = new PhingFile(
                    $fileSet->getDir($this->project),
                    $file
                );
                $target = new PhingFile(
                    $this->_targetDir,
                    str_replace('.less', '.css', $file)
                );

                $this->log("Processing ${file}");
                try {
                    $lessc = new lessc($source->getAbsolutePath());
                    file_put_contents(
                        $target->getAbsolutePath(),
                        $lessc->parse()
                    );
                } catch (Exception $e) {
                    $this->log("Failed processing ${file}!", Project::MSG_ERR);
                    $this->log($e->getMessage(), Project::MSG_DEBUG);
                }

            }

        }
    }
Example #26
0
 /**
  * set the text using a file
  * @param file the file to use
  * @throws BuildException if the file does not exist, or cannot be
  *                        read
  */
 public function setFile(PhingFile $file)
 {
     // non-existing files are not allowed
     if (!$file->exists()) {
         throw new BuildException("File " . $file . " does not exist.");
     }
     $reader = null;
     try {
         if ($this->encoding == null) {
             $reader = new BufferedReader(new FileReader($file));
         } else {
             $reader = new BufferedReader(new InputStreamReader(new FileInputStream($file)));
         }
         $this->value = $reader->read();
     } catch (IOException $ex) {
         $reader->close();
         throw new BuildException($ex);
     }
     $reader->close();
 }
 /**
  * @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());
     }
 }
Example #28
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 #29
0
 /**
  * Transforms the DOM document
  * @param DOMDocument $document
  * @throws BuildException
  * @throws IOException
  */
 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', (string) $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();
     }
 }
 private function transform(DOMDocument $document)
 {
     $dir = new PhingFile($this->toDir);
     if (!$dir->exists()) {
         throw new BuildException("Directory '" . $this->toDir . "' does not exist");
     }
     $xslfile = $this->getStyleSheet();
     $xsl = new DOMDocument();
     $xsl->load($xslfile->getAbsolutePath());
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     if ($this->format == "noframes") {
         $writer = new FileWriter(new PhingFile($this->toDir, "checkstyle-noframes.html"));
         $writer->write($proc->transformToXML($document));
         $writer->close();
     } else {
         ExtendedFileStream::registerStream();
         // no output for the framed report
         // it's all done by extension...
         $dir = new PhingFile($this->toDir);
         $proc->setParameter('', 'output.dir', $dir->getAbsolutePath());
         $proc->transformToXML($document);
     }
 }