/** * Perform the resolution & set property. */ public function main() { if (!$this->name) { throw new BuildException("You must specify the name of the executable you want to select.", $this->getLocation()); } if (!$this->propertyName) { throw new BuildException("You must specify the property name to store the path in.", $this->getLocation()); } $execPath = NULL; $cmd = "which {$this->name}"; $outArray = array(); $retCode = -1; $whichResult = exec($cmd, $outArray, $retCode); if ($retCode == 0) { $execPath = $whichResult; } // verify path $request = new InputRequest("Select the path for executable: {$this->name}: "); $request->setDefaultValue($execPath); do { $this->project->getInputHandler()->handleInput($request); $execPath = $request->getInput(); } while (!file_exists($execPath)); $this->project->setProperty($this->propertyName, $execPath); $this->log("Using {$this->name} at {$execPath}", PROJECT_MSG_INFO); }
public function main() { if ($this->propertyName === null) { throw new BuildException("You must specify a value for propertyName attribute."); } if ($this->list === null) { throw new BuildException("You must specify a value for list attribute."); } if (!$this->list) { $this->log('empty list.', Project::MSG_ERR); return false; } //输出带序号的列表 $this->log($this->gen($this->list)); $promptText = '请输入数字序号'; do { $request = new InputRequest($promptText); if ($this->defaultLast) { $request->setDefaultValue(count($this->choice)); } $request->setPromptChar(':'); $this->project->getInputHandler()->handleInput($request); $proposedValue = $request->getInput(); $keys = explode(',', $proposedValue); foreach ($keys as $key) { $key = intval($key); if (isset($this->choice[$key - 1])) { $this->accept[] = $this->choice[$key - 1]; } } } while (!$this->accept); if ($this->max) { $this->accept = array_slice($this->accept, 0, $this->max); } $this->project->setUserProperty($this->propertyName, implode(',', $this->accept)); }
/** * 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); } }
/** * Executes this task. */ public function main() { if ($this->property === null) { throw new BuildException('The property attribute must be specified'); } if ($this->message === '') { throw new BuildException('The message attribute must be specified or the element must contain a message'); } if ($this->ignoreIfSet && $this->project->getProperty($this->property) !== null) { if ($this->failIfEmpty) { if ($this->project->getProperty($this->property) != '') { return; } } else { return; } } $request = new InputRequest($this->message); $request->setPromptChar($this->promptCharacter); if ($this->useExistingAsDefault === true) { $request->setDefaultValue($this->project->getProperty($this->property)); } if ($this->default !== null) { $request->setDefaultValue($this->default); } $this->project->getInputHandler()->handleInput($request); $result = $request->getInput(); if ($this->failIfEmpty && $result == '') { throw new BuildException('Input value cannot be empty'); } $this->project->setUserProperty($this->property, $result); }