/**
  * Sets the flag if the used sniffs should be listed
  * @param boolean $show
  */
 public function setShowSniffs($show)
 {
     $this->showSniffs = StringHelper::booleanValue($show);
 }
 /**
  * Sets whether directives should be expanded as well as variables.
  *
  * @param      bool Whether to expand directives in the input string.
  */
 public function setExpandDirectives($expandDirectives)
 {
     $this->expandDirectives = StringHelper::booleanValue($expandDirectives);
 }
Beispiel #3
0
 /** Sets the named attribute. */
 function setAttribute(Project $project, $element, $attributeName, &$value)
 {
     // we want to check whether the value we are setting looks like
     // a slot-listener variable:  %{task.current_file}
     //
     // slot-listener variables are not like properties, in that they cannot be mixed with
     // other text values.  The reason for this disparity is that properties are only
     // set when first constructing objects from XML, whereas slot-listeners are always dynamic.
     //
     // This is made possible by PHP5 (objects automatically passed by reference) and PHP's loose
     // typing.
     if (StringHelper::isSlotVar($value)) {
         $as = "setlistening" . strtolower($attributeName);
         if (!isset($this->slotListeners[$as])) {
             $msg = $this->getElementName($project, $element) . " doesn't support a slot-listening '{$attributeName}' attribute.";
             throw new BuildException($msg);
         }
         $method = $this->slotListeners[$as];
         $key = StringHelper::slotVar($value);
         $value = Register::getSlot($key);
         // returns a RegisterSlot object which will hold current value of that register (accessible using getValue())
     } else {
         // Traditional value options
         $as = "set" . strtolower($attributeName);
         if (!isset($this->attributeSetters[$as])) {
             $msg = $this->getElementName($project, $element) . " doesn't support the '{$attributeName}' attribute.";
             throw new BuildException($msg);
         }
         $method = $this->attributeSetters[$as];
         if ($as == "setrefid") {
             $value = new Reference($value);
         } else {
             // decode any html entities in string
             $value = html_entity_decode($value);
             // value is a string representation of a boolean type,
             // convert it to primitive
             if (StringHelper::isBoolean($value)) {
                 $value = StringHelper::booleanValue($value);
             }
             // does method expect a PhingFile object? if so, then
             // pass a project-relative file.
             $params = $method->getParameters();
             $classname = null;
             if (($hint = $params[0]->getClass()) !== null) {
                 $classname = $hint->getName();
             }
             // there should only be one param; we'll just assume ....
             if ($classname !== null) {
                 switch (strtolower($classname)) {
                     case "phingfile":
                         $value = $project->resolveFile($value);
                         break;
                     case "path":
                         $value = new Path($project, $value);
                         break;
                     case "reference":
                         $value = new Reference($value);
                         break;
                         // any other object params we want to support should go here ...
                 }
             }
             // if hint !== null
         }
         // if not setrefid
     }
     // if is slot-listener
     try {
         $project->log("    -calling setter " . $method->getDeclaringClass()->getName() . "::" . $method->getName() . "()", PROJECT_MSG_DEBUG);
         $method->invoke($element, $value);
     } catch (Exception $exc) {
         throw new BuildException($exc);
     }
 }
 /**
  * Sets the flag if warnings should be shown
  * @param boolean $show
  */
 public function setShowWarnings($show)
 {
     $this->showWarnings = StringHelper::booleanValue($show);
 }
 /**
  * Sets whether to enable detailed logging or not
  *
  * @param boolean $verbose
  */
 public function setVerbose($verbose)
 {
     $this->_verbose = StringHelper::booleanValue($verbose);
 }
Beispiel #6
0
 /**
  * Sets the flag if test execution should stop in the event of a failure.
  *
  * @param bool $stop If all tests should stop on failure.
  *
  * @return void
  */
 public function setHaltonerror($stop)
 {
     $this->haltonerror = StringHelper::booleanValue($stop);
 }
Beispiel #7
0
 /**
  * Gets the recorder that's associated with the passed in name. If the
  * recorder doesn't exist, then a new one is created.
  * @param string $name the name of the recorder
  * @param Project $proj the current project
  * @return RecorderEntry a recorder
  * @throws BuildException on error
  */
 protected function getRecorder($name, Project $proj)
 {
     // create a recorder entry
     $entry = isset(self::$recorderEntries[$name]) ? self::$recorderEntries[$name] : new RecorderEntry($name);
     if ($this->append == null) {
         $entry->openFile(false);
     } else {
         $entry->openFile(StringHelper::booleanValue($this->append));
     }
     $entry->setProject($proj);
     self::$recorderEntries[$name] = $entry;
     return $entry;
 }
 /**
  * Whether to check the liquibase return code.
  *
  * @param $passthru
  * @internal param bool $checkreturn
  */
 public function setPassthru($passthru)
 {
     $this->passthru = StringHelper::booleanValue($passthru);
 }
 /**
  * Sets whether this task will overwrite or update the file.
  *
  * @param      boolean Whether the file should be updated or replaced.
  */
 public function setUpdate($update)
 {
     $this->update = StringHelper::booleanValue($update);
 }
 /**
  * Whether to use the scssphp compiler.
  *
  * @param string $value Jenkins style boolean value.
  *
  * @return void
  * @link   http://leafo.github.io/scssphp/
  */
 public function setUseScssphp($value)
 {
     $this->useScssphp = StringHelper::booleanValue($value);
     if (version_compare(PHP_VERSION, '5.2', '<=')) {
         $this->useScssphp = false;
         $this->log("SCSSPHP is incompatible with this version of PHP", Project::MSG_INFO);
     }
 }
 /**
  * Set whether all files are to be reverted.
  *
  * @param string $value Jenkins style boolean value
  *
  * @return void
  */
 public function setAll($value)
 {
     $this->all = StringHelper::booleanValue($value);
 }
 /**
  * Sets whether to use the existing value for the property as the default
  * value for the prompt.
  *
  * @param      bool Whether to use the existing property value as the
  *                  default.
  */
 public function setUseExistingAsDefault($useExistingAsDefault)
 {
     $this->useExistingAsDefault = StringHelper::booleanValue($useExistingAsDefault);
 }
Beispiel #13
0
 /**
  * Sets whether log messages for this task will be suppressed.
  *
  * @param      bool Whether to suppressing log messages for this task.
  */
 public function setQuiet($quiet)
 {
     $this->quiet = StringHelper::booleanValue($quiet);
 }
Beispiel #14
0
 /**
  * Executes initialization actions required to setup the data structures
  * related to the tag.
  * <p>
  * This includes:
  * <ul>
  * <li>creation of the target object</li>
  * <li>calling the setters for attributes</li>
  * <li>adding the target to the project</li>
  * <li>adding a reference to the target (if id attribute is given)</li>
  * </ul>
  *
  * @param $tag
  * @param $attrs
  * @throws BuildException
  * @throws ExpatParseException
  * @internal param the $string tag that comes in
  * @internal param attributes $array the tag carries
  */
 public function init($tag, $attrs)
 {
     $name = null;
     $depends = "";
     $ifCond = null;
     $unlessCond = null;
     $id = null;
     $description = null;
     $isHidden = false;
     $logskipped = false;
     foreach ($attrs as $key => $value) {
         switch ($key) {
             case "name":
                 $name = (string) $value;
                 break;
             case "depends":
                 $depends = (string) $value;
                 break;
             case "if":
                 $ifCond = (string) $value;
                 break;
             case "unless":
                 $unlessCond = (string) $value;
                 break;
             case "id":
                 $id = (string) $value;
                 break;
             case "hidden":
                 $isHidden = $value == 'true' || $value == '1' ? true : false;
                 break;
             case "description":
                 $description = (string) $value;
                 break;
             case "logskipped":
                 $logskipped = $value;
                 break;
             default:
                 throw new ExpatParseException("Unexpected attribute '{$key}'", $this->parser->getLocation());
         }
     }
     if ($name === null) {
         throw new ExpatParseException("target element appears without a name attribute", $this->parser->getLocation());
     }
     // shorthand
     $project = $this->configurator->project;
     // check to see if this target is a dup within the same file
     if (isset($this->context->getCurrentTargets[$name])) {
         throw new BuildException("Duplicate target: {$name}", $this->parser->getLocation());
     }
     $this->target = new Target();
     $this->target->setHidden($isHidden);
     $this->target->setIf($ifCond);
     $this->target->setUnless($unlessCond);
     $this->target->setDescription($description);
     $this->target->setLogSkipped(StringHelper::booleanValue($logskipped));
     // take care of dependencies
     if (strlen($depends) > 0) {
         $this->target->setDepends($depends);
     }
     // check to see if target with same name is already defined
     $projectTargets = $project->getTargets();
     if (isset($projectTargets[$name])) {
         if ($this->configurator->isIgnoringProjectTag() && $this->configurator->getCurrentProjectName() != null && strlen($this->configurator->getCurrentProjectName()) != 0) {
             // In an impored file (and not completely
             // ignoring the project tag)
             $newName = $this->configurator->getCurrentProjectName() . "." . $name;
             $project->log("Already defined in main or a previous import, " . "define {$name} as {$newName}", Project::MSG_VERBOSE);
             $name = $newName;
         } else {
             $project->log("Already defined in main or a previous import, " . "ignore {$name}", Project::MSG_VERBOSE);
             $name = null;
         }
     }
     if ($name != null) {
         $this->target->setName($name);
         $project->addOrReplaceTarget($name, $this->target);
         if ($id !== null && $id !== "") {
             $project->addReference($id, $this->target);
         }
     }
 }
Beispiel #15
0
 /**
  * Set the showheaders attribute.
  * @param boolean $v
  */
 public function setShowheaders($v)
 {
     $this->showheaders = StringHelper::booleanValue($v);
 }
Beispiel #16
0
 /**
  * Execute the input script with Velocity
  *
  * @throws BuildException
  *                        BuildExceptions are thrown when required attributes are missing.
  *                        Exceptions thrown by Velocity are rethrown as BuildExceptions.
  */
 public function main()
 {
     // Make sure the template path is set.
     if (empty($this->templatePath)) {
         throw new BuildException("The template path needs to be defined!");
     }
     // Make sure the control template is set.
     if ($this->controlTemplate === null) {
         throw new BuildException("The control template needs to be defined!");
     }
     // Make sure the output directory is set.
     if ($this->outputDirectory === null) {
         throw new BuildException("The output directory needs to be defined!");
     }
     // Make sure there is an output file.
     if ($this->outputFile === null) {
         throw new BuildException("The output file needs to be defined!");
     }
     // Setup Smarty runtime.
     // Smarty uses one object to store properties and to store
     // the context for the template (unlike Velocity).  We setup this object, calling it
     // $this->context, and then initControlContext simply zeros out
     // any assigned variables.
     //
     // Use the smarty backwards compatibility layer if existent.
     if (class_exists('SmartyBC')) {
         $this->context = new SmartyBC();
     } else {
         $this->context = new Smarty();
     }
     if ($this->compilePath !== null) {
         $this->log("Using compilePath: " . $this->compilePath);
         $this->context->compile_dir = $this->compilePath;
     }
     if ($this->configPath !== null) {
         $this->log("Using configPath: " . $this->configPath);
         $this->context->config_dir = $this->configPath;
     }
     if ($this->forceCompile !== null) {
         $this->context->force_compile = $this->forceCompile;
     }
     if ($this->leftDelimiter !== null) {
         $this->context->left_delimiter = $this->leftDelimiter;
     }
     if ($this->rightDelimiter !== null) {
         $this->context->right_delimiter = $this->rightDelimiter;
     }
     if ($this->templatePath !== null) {
         $this->log("Using templatePath: " . $this->templatePath);
         $this->context->template_dir = $this->templatePath;
     }
     $smartyCompilePath = new PhingFile($this->context->compile_dir);
     if (!$smartyCompilePath->exists()) {
         $this->log("Compile directory does not exist, creating: " . $smartyCompilePath->getPath(), Project::MSG_VERBOSE);
         if (!$smartyCompilePath->mkdirs()) {
             throw new BuildException("Smarty needs a place to compile templates; specify a 'compilePath' or create " . $this->context->compile_dir);
         }
     }
     // Make sure the output directory exists, if it doesn't
     // then create it.
     $file = new PhingFile($this->outputDirectory);
     if (!$file->exists()) {
         $this->log("Output directory does not exist, creating: " . $file->getAbsolutePath());
         $file->mkdirs();
     }
     $path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
     $this->log("Generating to file " . $path);
     $writer = new FileWriter($path);
     // The generator and the output path should
     // be placed in the init context here and
     // not in the generator class itself.
     $c = $this->initControlContext();
     // Set any variables that need to always
     // be loaded
     $this->populateInitialContext($c);
     // Feed all the options into the initial
     // control context so they are available
     // in the control/worker templates.
     if ($this->contextProperties !== null) {
         foreach ($this->contextProperties->keys() as $property) {
             $value = $this->contextProperties->getProperty($property);
             // Special exception (from Texen)
             // for properties ending in file.contents:
             // in that case we dump the contents of the file
             // as the "value" for the Property.
             if (StringHelper::endsWith("file.contents", $property)) {
                 // pull in contents of file specified
                 $property = substr($property, 0, strpos($property, "file.contents") - 1);
                 // reset value, and then
                 // read in teh contents of the file into that var
                 $value = "";
                 $f = new PhingFile($this->project->resolveFile($value)->getCanonicalPath());
                 if ($f->exists()) {
                     try {
                         $fr = new FileReader($f);
                         $fr->readInto($value);
                     } catch (Exception $e) {
                         throw $e;
                     }
                 }
             }
             // if ends with file.contents
             if (StringHelper::isBoolean($value)) {
                 $value = StringHelper::booleanValue($value);
             }
             $c->assign($property, $value);
         }
         // foreach property
     }
     // if contextProperties !== null
     try {
         //$c->display($this->controlTemplate);
         $writer->write($c->fetch($this->controlTemplate));
         $writer->close();
     } catch (IOException $ioe) {
         $writer->close();
         throw new BuildException("Cannot write parsed template.");
     }
     $this->cleanup();
 }
 /**
  * @param boolean $countTests
  */
 public function setCountTests($countTests)
 {
     $this->countTests = StringHelper::booleanValue($countTests);
 }
Beispiel #18
0
 /**
  * Sets whether to ignore this check if the property is already set.
  *
  * @param      bool Whether to bypass the check if the property is set.
  */
 public function setIgnoreIfSet($ignoreIfSet)
 {
     $this->ignoreIfSet = StringHelper::booleanValue($ignoreIfSet);
 }
 /**
  * Set 'clean' attribute.
  *
  * @param string $value Clean attribute value
  *
  * @return void
  */
 public function setClean($value)
 {
     $this->clean = StringHelper::booleanValue($value);
 }
 /**
  * Sets whether exceptions are fatal for targets called by this task.
  *
  * @param      bool Whether exceptions should be considered fatal.
  */
 public function setExceptionsFatal($exceptionsFatal)
 {
     $this->exceptionsFatal = StringHelper::booleanValue($exceptionsFatal);
 }
 /**
  * Scans the parameters list
  */
 private function initialize()
 {
     // get parameters
     $params = $this->getParameters();
     foreach ($params as $param) {
         $paramName = $param->getName();
         if (self::$REVERSE_KEY === $paramName) {
             $this->setReverse(StringHelper::booleanValue($param->getValue()));
             continue;
         }
     }
 }
Beispiel #22
0
 /**
  * Turns off or on this recorder.
  *
  * @param bool|null state true for on, false for off, null for no change.
  */
 public function setRecordState($state)
 {
     if ($state != null) {
         $this->flush();
         $this->record = StringHelper::booleanValue($state);
     }
 }
 /**
  * Converts input to boolean.
  * @return boolean
  */
 public function getInput()
 {
     return StringHelper::booleanValue($this->input);
 }
 /**
  * @param bool|string|int $skipOnSameSize
  */
 public function setSkipOnSameSize($skipOnSameSize)
 {
     $this->skipOnSameSize = StringHelper::booleanValue($skipOnSameSize);
 }
 /**
  * Set insecure attribute
  *
  * @param string $insecure 'yes', etc.
  *
  * @return void
  */
 public function setInsecure($insecure)
 {
     $this->insecure = StringHelper::booleanValue($insecure);
 }
Beispiel #26
0
 /**
  * Set halt on error
  *
  * @param boolean $haltonerror
  *
  * @return void
  */
 public function setHaltonerror($haltonerror)
 {
     $this->_haltonerror = StringHelper::booleanValue($haltonerror);
 }
Beispiel #27
0
 /**
  * Execute the input script with Velocity
  *
  * @throws BuildException
  *                        BuildExceptions are thrown when required attributes are missing.
  *                        Exceptions thrown by Velocity are rethrown as BuildExceptions.
  */
 public function main()
 {
     // Make sure the template path is set.
     if (empty($this->templatePath)) {
         throw new BuildException("The template path needs to be defined!");
     }
     // Make sure the control template is set.
     if ($this->controlTemplate === null) {
         throw new BuildException("The control template needs to be defined!");
     }
     // Make sure the output directory is set.
     if ($this->outputDirectory === null) {
         throw new BuildException("The output directory needs to be defined!");
     }
     // Make sure there is an output file.
     if ($this->outputFile === null) {
         throw new BuildException("The output file needs to be defined!");
     }
     // Setup Smarty runtime.
     // Smarty uses one object to store properties and to store
     // the context for the template (unlike Velocity).  We setup this object, calling it
     // $this->context, and then initControlContext simply zeros out
     // any assigned variables.
     $this->context = new Capsule();
     if ($this->templatePath !== null) {
         $this->log("Using templatePath: " . $this->templatePath);
         $this->context->setTemplatePath($this->templatePath);
     }
     // Make sure the output directory exists, if it doesn't
     // then create it.
     $outputDir = new PhingFile($this->outputDirectory);
     if (!$outputDir->exists()) {
         $this->log("Output directory does not exist, creating: " . $outputDir->getAbsolutePath());
         $outputDir->mkdirs();
     }
     $this->context->setOutputDirectory($outputDir->getAbsolutePath());
     $path = $this->outputDirectory . DIRECTORY_SEPARATOR . $this->outputFile;
     $this->log("Generating to file " . $path);
     //$writer = new FileWriter($path);
     // The generator and the output path should
     // be placed in the init context here and
     // not in the generator class itself.
     $c = $this->initControlContext();
     // Set any variables that need to always
     // be loaded
     $this->populateInitialContext($c);
     // Feed all the options into the initial
     // control context so they are available
     // in the control/worker templates.
     if ($this->contextProperties !== null) {
         foreach ($this->contextProperties->keys() as $property) {
             $value = $this->contextProperties->getProperty($property);
             // Special exception (from Texen)
             // for properties ending in file.contents:
             // in that case we dump the contents of the file
             // as the "value" for the Property.
             if (preg_match('/file\\.contents$/', $property)) {
                 // pull in contents of file specified
                 $property = substr($property, 0, strpos($property, "file.contents") - 1);
                 // reset value, and then
                 // read in the contents of the file into that var
                 $value = "";
                 $f = new PhingFile($this->project->resolveFile($value)->getCanonicalPath());
                 if ($f->exists()) {
                     $fr = new FileReader($f);
                     $fr->readInto($value);
                 }
             }
             // if ends with file.contents
             if (StringHelper::isBoolean($value)) {
                 $value = StringHelper::booleanValue($value);
             }
             $c->put($property, $value);
         }
         // foreach property
     }
     // if contextProperties !== null
     try {
         $this->log("Parsing control template: " . $this->controlTemplate);
         $c->parse($this->controlTemplate, $path);
     } catch (Exception $ioe) {
         throw new BuildException("Cannot write parsed template: " . $ioe->getMessage());
     }
     $this->cleanup();
 }
 /**
  * Set whether to write formatter results to file or not.
  *
  * @param boolean $useFile True or false.
  */
 public function setUseFile($useFile)
 {
     $this->useFile = StringHelper::booleanValue($useFile);
 }
 /**
  * Sends the mail
  *
  * @see DefaultLogger#buildFinished
  * @param BuildEvent $event
  */
 public function buildFinished(BuildEvent $event)
 {
     parent::buildFinished($event);
     $project = $event->getProject();
     $properties = $project->getProperties();
     $filename = $properties['phing.log.mail.properties.file'];
     // overlay specified properties file (if any), which overrides project
     // settings
     $fileProperties = new Properties();
     $file = new PhingFile($filename);
     try {
         $fileProperties->load($file);
     } catch (IOException $ioe) {
         // ignore because properties file is not required
     }
     foreach ($fileProperties as $key => $value) {
         $properties['key'] = $project->replaceProperties($value);
     }
     $success = $event->getException() === null;
     $prefix = $success ? 'success' : 'failure';
     try {
         $notify = StringHelper::booleanValue($this->getValue($properties, $prefix . '.notify', 'on'));
         if (!$notify) {
             return;
         }
         if (is_string(Phing::getDefinedProperty('phing.log.mail.subject'))) {
             $defaultSubject = Phing::getDefinedProperty('phing.log.mail.subject');
         } else {
             $defaultSubject = $success ? 'Build Success' : 'Build Failure';
         }
         $hdrs = array();
         $hdrs['From'] = $this->getValue($properties, 'from', $this->from);
         $hdrs['Reply-To'] = $this->getValue($properties, 'replyto', '');
         $hdrs['Cc'] = $this->getValue($properties, $prefix . '.cc', '');
         $hdrs['Bcc'] = $this->getValue($properties, $prefix . '.bcc', '');
         $hdrs['Body'] = $this->getValue($properties, $prefix . '.body', '');
         $hdrs['Subject'] = $this->getValue($properties, $prefix . '.subject', $defaultSubject);
         $tolist = $this->getValue($properties, $prefix . '.to', $this->tolist);
     } catch (BadMethodCallException $e) {
         $project->log($e->getMessage(), Project::MSG_WARN);
     }
     if (empty($tolist)) {
         return;
     }
     $mail = Mail::factory('mail');
     $mail->send($tolist, $hdrs, $this->mailMessage);
 }