Exemplo n.º 1
0
 /**
  * Run the PropertyPrompt task.
  * @throws BuildException
  */
 public function main()
 {
     $this->proposedValue = $this->project->getProperty($this->propertyName);
     $currentValue = $this->defaultValue;
     if ($currentValue == "" && $this->proposedValue !== null) {
         $currentValue = $this->proposedValue;
     }
     if ($this->useExistingValue !== true || $this->proposedValue === null) {
         $this->log("Prompting user for " . $this->propertyName . ". " . $this->getDefaultMessage(), Project::MSG_VERBOSE);
         print "\n" . $this->promptText . " [" . $currentValue . "] " . $this->promptCharacter . " ";
         /** future version should probably have hooks for validation of user input.*/
         $reader = new ConsoleReader();
         try {
             $this->proposedValue = $reader->readLine();
         } catch (IOException $e) {
             $this->log("Prompt failed. Using default. (Failure reason: " . $e->getMessage() . ")");
             $this->proposedValue = $this->defaultValue;
         }
         if ($this->proposedValue === "") {
             $this->log("No value specified, using default.", Project::MSG_VERBOSE);
             $this->proposedValue = $this->defaultValue;
         }
         if (isset($this->proposedValue)) {
             $this->project->setProperty($this->propertyName, $this->proposedValue);
         }
     }
 }
 /**
  * Prompts and requests input.
  * May loop until a valid input has been entered.
  *
  * @param InputRequest $request
  *
  * @return void
  *
  * @throws BuildException
  */
 public function handleInput(InputRequest $request)
 {
     $prompt = $this->getPrompt($request);
     $in = new ConsoleReader();
     do {
         print $prompt;
         try {
             $input = $in->readLine();
             if ($input === "" && $request->getDefaultValue() !== null) {
                 $input = $request->getDefaultValue();
             }
             $request->setInput($input);
         } catch (Exception $e) {
             throw new BuildException("Failed to read input from Console.", $e);
         }
     } while (!$request->isInputValid());
 }