| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: PropertyPromptTask.php 272 2007-10-30 23:06:04Z hans $
|
|
|
4 |
*
|
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
16 |
*
|
|
|
17 |
* This software consists of voluntary contributions made by many individuals
|
|
|
18 |
* and is licensed under the LGPL. For more information please see
|
|
|
19 |
* <http://phing.info>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
require_once 'phing/Task.php';
|
|
|
23 |
include_once 'phing/system/io/ConsoleReader.php';
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Deprecated task that uses console to prompt user for property values.
|
|
|
27 |
*
|
|
|
28 |
* This class is very slightly simpler than the InputTask, but lacks the ability
|
|
|
29 |
* to use a non-console input handler. You should, therefore, use InputTask. This
|
|
|
30 |
* class can serve as a reference, but will be removed in the future.
|
|
|
31 |
*
|
|
|
32 |
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
|
|
33 |
* @author Anthony J. Young-Garner <ajyoung@alum.mit.edu> (Ant)
|
|
|
34 |
* @version $Revision: 1.4 $
|
|
|
35 |
* @package phing.tasks.system
|
|
|
36 |
* @deprecated - in favor of the more capable InputTask
|
|
|
37 |
*/
|
|
|
38 |
class PropertyPromptTask extends Task {
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* The property name to set with the output.
|
|
|
42 |
* @var string
|
|
|
43 |
*/
|
|
|
44 |
private $propertyName; // required
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* The default value to use if no input is entered.
|
|
|
48 |
* @var string
|
|
|
49 |
*/
|
|
|
50 |
private $defaultValue;
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* The entered value.
|
|
|
54 |
* @var string
|
|
|
55 |
*/
|
|
|
56 |
private $proposedValue;
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* The text to use for the prompt.
|
|
|
60 |
* @var string
|
|
|
61 |
*/
|
|
|
62 |
private $promptText;
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* The character to put after the text.
|
|
|
66 |
* @var string
|
|
|
67 |
*/
|
|
|
68 |
private $promptCharacter;
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
*
|
|
|
72 |
*/
|
|
|
73 |
private $useExistingValue;
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Run the PropertyPrompt task.
|
|
|
77 |
* @throws BuildException
|
|
|
78 |
*/
|
|
|
79 |
public function main() {
|
|
|
80 |
|
|
|
81 |
$this->proposedValue = $this->project->getProperty($this->propertyName);
|
|
|
82 |
$currentValue = $this->defaultValue;
|
|
|
83 |
|
|
|
84 |
if ($currentValue == "" && $this->proposedValue !== null) {
|
|
|
85 |
$currentValue = $this->proposedValue;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
if ($this->useExistingValue !== true || $this->proposedValue === null) {
|
|
|
89 |
|
|
|
90 |
$this->log("Prompting user for " . $this->propertyName . ". " . $this->getDefaultMessage(), Project::MSG_VERBOSE);
|
|
|
91 |
|
|
|
92 |
print "\n" . $this->promptText . " [" . $currentValue . "] " . $this->promptCharacter . " ";
|
|
|
93 |
|
|
|
94 |
/** future version should probably have hooks for validation of user input.*/
|
|
|
95 |
$reader = new ConsoleReader();
|
|
|
96 |
|
|
|
97 |
try {
|
|
|
98 |
$this->proposedValue = $reader->readLine();
|
|
|
99 |
} catch (IOException $e) {
|
|
|
100 |
$this->log("Prompt failed. Using default. (Failure reason: " . $e->getMessage().")");
|
|
|
101 |
$this->proposedValue = $this->defaultValue;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
if ($this->proposedValue === "") {
|
|
|
105 |
$this->log("No value specified, using default.", Project::MSG_VERBOSE);
|
|
|
106 |
$this->proposedValue = $this->defaultValue;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
if (isset($this->proposedValue) && $this->proposedValue !== "") {
|
|
|
110 |
$this->project->setProperty($this->propertyName, $this->proposedValue);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
* Returns a string to be inserted in the log message
|
|
|
118 |
* indicating whether a default response was specified
|
|
|
119 |
* in the build file.
|
|
|
120 |
*/
|
|
|
121 |
private function getDefaultMessage() {
|
|
|
122 |
if ($this->defaultValue == "") {
|
|
|
123 |
return "No default response specified.";
|
|
|
124 |
} else return "Default response is " . $this->defaultValue . ".";
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
/**
|
|
|
128 |
* Returns defaultValue specified
|
|
|
129 |
* in this task for the Property
|
|
|
130 |
* being set.
|
|
|
131 |
* @return string
|
|
|
132 |
*/
|
|
|
133 |
public function getDefaultValue() {
|
|
|
134 |
return $this->defaultValue;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Returns the terminating character used to
|
|
|
139 |
* punctuate the prompt text.
|
|
|
140 |
* @return string
|
|
|
141 |
*/
|
|
|
142 |
public function getPromptCharacter() {
|
|
|
143 |
return $this->promptCharacter;
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Returns text of the prompt.
|
|
|
148 |
* @return java.lang.String
|
|
|
149 |
*/
|
|
|
150 |
public function getPromptText() {
|
|
|
151 |
return $this->promptText;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* Returns name of the Ant Project Property
|
|
|
156 |
* being set by this task.
|
|
|
157 |
* @return string
|
|
|
158 |
*/
|
|
|
159 |
public function getPropertyName() {
|
|
|
160 |
return $this->propertyName;
|
|
|
161 |
}
|
|
|
162 |
/**
|
|
|
163 |
* Initializes this task.
|
|
|
164 |
*/
|
|
|
165 |
public function init() {
|
|
|
166 |
parent::init();
|
|
|
167 |
$this->defaultValue = "";
|
|
|
168 |
$this->promptCharacter = "?";
|
|
|
169 |
$this->useExistingValue = false;
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
/**
|
|
|
173 |
* Insert the method's description here.
|
|
|
174 |
* Creation date: (12/10/2001 8:16:16 AM)
|
|
|
175 |
* @return boolean
|
|
|
176 |
*/
|
|
|
177 |
public function isUseExistingValue() {
|
|
|
178 |
return $this->useExistingValue;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
/**
|
|
|
182 |
* Sets defaultValue for the Property
|
|
|
183 |
* being set by this task.
|
|
|
184 |
* @param string $newDefaultvalue
|
|
|
185 |
*/
|
|
|
186 |
public function setDefaultvalue($newDefaultvalue) {
|
|
|
187 |
$this->defaultValue = $newDefaultvalue;
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
/**
|
|
|
191 |
* Sets the terminating character used to
|
|
|
192 |
* punctuate the prompt text (default is "?").
|
|
|
193 |
* @param string $newPromptcharacter
|
|
|
194 |
*/
|
|
|
195 |
public function setPromptCharacter($newPromptcharacter) {
|
|
|
196 |
$this->promptCharacter = $newPromptcharacter;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
/**
|
|
|
200 |
* Sets text of the prompt.
|
|
|
201 |
* @param string $newPrompttext
|
|
|
202 |
*/
|
|
|
203 |
public function setPromptText($newPrompttext) {
|
|
|
204 |
$this->promptText = $newPrompttext;
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
/**
|
|
|
208 |
* Specifies the Phing Project Property
|
|
|
209 |
* being set by this task.
|
|
|
210 |
* @param newPropertyname java.lang.String
|
|
|
211 |
*/
|
|
|
212 |
public function setPropertyName($newPropertyname) {
|
|
|
213 |
$this->propertyName = $newPropertyname;
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
/**
|
|
|
217 |
*
|
|
|
218 |
* @param boolean $newUseExistingValue
|
|
|
219 |
*/
|
|
|
220 |
public function setUseExistingValue($newUseExistingValue) {
|
|
|
221 |
$this->useExistingValue = $newUseExistingValue;
|
|
|
222 |
}
|
|
|
223 |
|
|
|
224 |
/**
|
|
|
225 |
* Sets the prompt text that will be presented to the user.
|
|
|
226 |
* @param string $prompt
|
|
|
227 |
* @return void
|
|
|
228 |
*/
|
|
|
229 |
public function addText($prompt) {
|
|
|
230 |
$this->setPromptText($prompt);
|
|
|
231 |
}
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
}
|