initial commit

This commit is contained in:
Chris Sewell
2012-11-28 03:55:08 -05:00
parent 7adb399b2e
commit cf140a2e97
3247 changed files with 492437 additions and 0 deletions

View File

@ -0,0 +1,82 @@
<?php
/*
* $Id: DefaultInputHandler.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/input/InputHandler.php';
include_once 'phing/system/io/ConsoleReader.php';
/**
* Prompts using print(); reads input from Console.
*
* @author Hans Lellelid <hans@xmpl.org> (Phing)
* @author Stefan Bodewig <stefan.bodewig@epost.de> (Ant)
* @version $Revision: 1.6 $
* @package phing.input
*/
class DefaultInputHandler implements InputHandler {
/**
* Prompts and requests input. May loop until a valid input has
* been entered.
* @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());
}
/**
* Constructs user prompt from a request.
*
* <p>This implementation adds (choice1,choice2,choice3,...) to the
* prompt for <code>MultipleChoiceInputRequest</code>s.</p>
*
* @param $request the request to construct the prompt for.
* Must not be <code>null</code>.
*/
protected function getPrompt(InputRequest $request) {
$prompt = $request->getPrompt();
// use is_a() to avoid needing the class to be loaded
if (is_a($request, 'YesNoInputRequest')) { // (yes/no)
$prompt .= '(' . implode('/', $request->getChoices()) .')';
} elseif (is_a($request, 'MultipleChoiceInputRequest')) { // (a,b,c,d)
$prompt .= '(' . implode(',', $request->getChoices()) . ')';
}
if ($request->getDefaultValue() !== null) {
$prompt .= ' ['.$request->getDefaultValue().']';
}
$pchar = $request->getPromptChar();
return $prompt . ($pchar ? $pchar . ' ' : ' ');
}
}

View File

@ -0,0 +1,45 @@
<?php
/*
* $Id: InputHandler.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Plugin to Phing to handle requests for user input.
*
* @author Stefan Bodewig <stefan.bodewig@epost.de>
* @version $Revision: 1.3 $
* @package phing.input
*/
interface InputHandler {
/**
* Handle the request encapsulated in the argument.
*
* <p>Precondition: the request.getPrompt will return a non-null
* value.</p>
*
* <p>Postcondition: request.getInput will return a non-null
* value, request.isInputValid will return true.</p>
* @return void
* @throws BuildException
*/
public function handleInput(InputRequest $request);
}

View File

@ -0,0 +1,107 @@
<?php
/*
* $Id: InputRequest.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
/**
* Encapsulates an input request.
*
* @author Hans Lellelid <hans@xmpl.org> (Phing)
* @author Stefan Bodewig <stefan.bodewig@epost.de> (Ant)
* @version $Revision: 1.4 $
* @package phing.input
*/
class InputRequest {
protected $prompt;
protected $input;
protected $defaultValue;
protected $promptChar;
/**
* @param string $prompt The prompt to show to the user. Must not be null.
*/
public function __construct($prompt) {
if ($prompt === null) {
throw new BuildException("prompt must not be null");
}
$this->prompt = $prompt;
}
/**
* Retrieves the prompt text.
*/
public function getPrompt() {
return $this->prompt;
}
/**
* Sets the user provided input.
*/
public function setInput($input) {
$this->input = $input;
}
/**
* Is the user input valid?
*/
public function isInputValid() {
return true;
}
/**
* Retrieves the user input.
*/
public function getInput() {
return $this->input;
}
/**
* Set the default value to use.
* @param mixed $v
*/
public function setDefaultValue($v) {
$this->defaultValue = $v;
}
/**
* Return the default value to use.
* @return mixed
*/
public function getDefaultValue() {
return $this->defaultValue;
}
/**
* Set the default value to use.
* @param string $c
*/
public function setPromptChar($c) {
$this->promptChar = $c;
}
/**
* Return the default value to use.
* @return string
*/
public function getPromptChar() {
return $this->promptChar;
}
}

View File

@ -0,0 +1,58 @@
<?php
/*
* $Id: MultipleChoiceInputRequest.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/input/InputRequest.php';
/**
* Encapsulates an input request.
*
* @author Stefan Bodewig <stefan.bodewig@epost.de>
* @version $Revision: 1.5 $
* @package phing.input
*/
class MultipleChoiceInputRequest extends InputRequest {
protected $choices = array();
/**
* @param string $prompt The prompt to show to the user. Must not be null.
* @param array $choices holds all input values that are allowed.
* Must not be null.
*/
public function __construct($prompt, $choices) {
parent::__construct($prompt);
$this->choices = $choices;
}
/**
* @return The possible values.
*/
public function getChoices() {
return $this->choices;
}
/**
* @return true if the input is one of the allowed values.
*/
public function isInputValid() {
return in_array($this->getInput(), $this->choices); // not strict (?)
}
}

View File

@ -0,0 +1,129 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Ant" and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.input;
import org.apache.tools.ant.BuildException;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/**
* Reads input from a property file, the file name is read from the
* system property ant.input.properties, the prompt is the key for input.
*
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @version $Revision: 1.1 $
* @since Ant 1.5
*/
public class PropertyFileInputHandler implements InputHandler {
private Properties props = null;
/**
* Name of the system property we expect to hold the file name.
*/
public static final String FILE_NAME_KEY = "ant.input.properties";
/**
* Empty no-arg constructor.
*/
public PropertyFileInputHandler() {
}
/**
* Picks up the input from a property, using the prompt as the
* name of the property.
*
* @exception BuildException if no property of that name can be found.
*/
public void handleInput(InputRequest request) throws BuildException {
readProps();
Object o = props.get(request.getPrompt());
if (o == null) {
throw new BuildException("Unable to find input for \'"
+ request.getPrompt()+"\'");
}
request.setInput(o.toString());
if (!request.isInputValid()) {
throw new BuildException("Found invalid input " + o
+ " for \'" + request.getPrompt() + "\'");
}
}
/**
* Reads the properties file if it hasn't already been read.
*/
private synchronized void readProps() throws BuildException {
if (props == null) {
String propsFile = System.getProperty(FILE_NAME_KEY);
if (propsFile == null) {
throw new BuildException("System property "
+ FILE_NAME_KEY
+ " for PropertyFileInputHandler not"
+ " set");
}
props = new Properties();
try {
props.load(new FileInputStream(propsFile));
} catch (IOException e) {
throw new BuildException("Couldn't load " + propsFile, e);
}
}
}
}

View File

@ -0,0 +1,47 @@
<?php
/*
* $Id: YesNoInputRequest.php 3076 2006-12-18 08:52:12Z fabien $
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information please see
* <http://phing.info>.
*/
require_once 'phing/input/MultipleChoiceInputRequest.php';
/**
* Encapsulates an input request that returns a boolean (yes/no).
*
* @author Hans Lellelid <hans@xmpl.org>
* @version $Revision: 1.4 $
* @package phing.input
*/
class YesNoInputRequest extends MultipleChoiceInputRequest {
/**
* @return true if the input is one of the allowed values.
*/
public function isInputValid() {
return StringHelper::isBoolean($this->input);
}
/**
* Converts input to boolean.
* @return boolean
*/
public function getInput() {
return StringHelper::booleanValue($this->input);
}
}