summaryrefslogtreecommitdiff
path: root/buildscripts/phing/classes/phing/TaskAdapter.php
blob: ba323c56a47349a73ad2ccd972c6234431002881 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
 *  $Id: 8cd2a3322c659a5de7fcb47e21192730e5cc863d $
 *
 * 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/Task.php';

/**
 *  Use introspection to "adapt" an arbitrary ( not extending Task, but with
 *  similar patterns).
 *
 *  @author    Andreas Aderhold <andi@binarycloud.com>
 *  @copyright 2001,2002 THYRELL. All rights reserved
 *  @version   $Id$
 *  @package   phing
 */
class TaskAdapter extends Task {
    
    /** target object */
    private $proxy;
    
    /**
     * Main entry point.
     * @return void
     */
    function main() {
    
        if (method_exists($this->proxy, "setProject")) {
            try {  // try to set project
                $this->proxy->setProject($this->project);
            } catch (Exception $ex) {
                $this->log("Error setting project in " . get_class($this->proxy) . Project::MSG_ERR);
                throw new BuildException($ex);
            }
        } else {
            throw new Exception("Error setting project in class " . get_class($this->proxy));
        }
               
        if (method_exists($this->proxy, "main")) {
            try { //try to call main
                $this->proxy->main($this->project);
            } catch (Exception $ex) {
                $this->log("Error in " . get_class($this->proxy), Project::MSG_ERR);
                $this->log($ex->getTraceAsString(), Project::MSG_DEBUG);
                throw new BuildException($ex->getMessage());
            }
        } else {
            throw new BuildException("Your task-like class '" . get_class($this->proxy) ."' does not have a main() method");
        }
    }

    /**
     * Set the target object.
     * @param object $o
     * @return void
     */
    function setProxy($o) {
        $this->proxy = $o;
    }

    /**
     * Gets the target object.
     * @return object
     */
    function getProxy() {
        return $this->proxy;
    }

}