Beispiel #1
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);
     }
 }
Beispiel #2
0
 /**
  * Actual method executed by phing.
  * @throws BuildException
  */
 public function main()
 {
     if ($this->propertyName === null) {
         throw new BuildException("You must specify a value for propertyName attribute.");
     }
     if ($this->validargs !== null) {
         $accept = preg_split('/[\\s,]+/', $this->validargs);
         // is it a boolean (yes/no) inputrequest?
         $yesno = false;
         if (count($accept) == 2) {
             $yesno = true;
             foreach ($accept as $ans) {
                 if (!StringHelper::isBoolean($ans)) {
                     $yesno = false;
                     break;
                 }
             }
         }
         if ($yesno) {
             $request = new YesNoInputRequest($this->message, $accept);
         } else {
             $request = new MultipleChoiceInputRequest($this->message, $accept);
         }
     } else {
         $request = new InputRequest($this->message);
     }
     // default default is curr prop value
     $request->setDefaultValue($this->project->getProperty($this->propertyName));
     $request->setPromptChar($this->promptChar);
     // unless overridden...
     if ($this->defaultValue !== null) {
         $request->setDefaultValue($this->defaultValue);
     }
     $this->project->getInputHandler()->handleInput($request);
     $value = $request->getInput();
     if ($value !== null) {
         $this->project->setUserProperty($this->propertyName, $value);
     }
 }
Beispiel #3
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();
 }
Beispiel #4
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();
 }
 /**
  * @return true if the input is one of the allowed values.
  */
 public function isInputValid()
 {
     return StringHelper::isBoolean($this->input);
 }