phing/phingcludes/DrushTask.php
public function main()
    {
        $command = [];

        $command[] = !empty($this->bin) ? $this->bin : 'drush';

        if (!empty($this->alias)) {
            $command[] = '@' . $this->alias;
        }

        if (!empty($this->root)) {
            $option = new DrushOption();
            $option->setName('root');
            $option->addText($this->root);
            $this->options[] = $option;
        }

        if (!empty($this->uri)) {
            $option = new DrushOption();
            $option->setName('uri');
            $option->addText($this->uri);
            $this->options[] = $option;
        }

        if (is_bool($this->assume)) {
            $option = new DrushOption();
            $option->setName(($this->assume ? 'yes' : 'no'));
            $this->options[] = $option;
        }

        if ($this->simulate) {
            $option = new DrushOption();
            $option->setName('simulate');
            $this->options[] = $option;
        }

        if ($this->pipe) {
            $option = new DrushOption();
            $option->setName('pipe');
            $this->options[] = $option;
        }

        if (Phing::getMsgOutputLevel() >= Project::MSG_VERBOSE) {
            $this->setVerbose('true');
        }

        if ($this->verbose) {
            $option = new DrushOption();
            $option->setName('verbose');
            $this->options[] = $option;
            $exec_level = Project::MSG_INFO;
        } else {
            $exec_level = Project::MSG_VERBOSE;
        }

        foreach ($this->options as $option) {
            $command[] = $option->toString();
        }

        $command[] = $this->command;

        foreach ($this->params as $param) {
            $command[] = $param->getValue();
        }

        if (!empty($this->dir)) {
            $this->log("Changing working directory to: $this->dir", $exec_level);
            $initial_cwd = getcwd();
            chdir($this->dir);
        }

        // Execute Drush.
        $output = [];
        $return = null;

        if ($this->passthru) {
            $command = implode(' ', $command);
            $this->log("Executing: $command", $exec_level);
            passthru($command, $return);
        } else {
            // Redirect sterr to stout for Phing log.
            $command[] = '2>&1';

            $command = implode(' ', $command);
            $this->log("Executing: $command", $exec_level);
            exec($command, $output, $return);

            if ($this->logoutput) {
                // Collect Drush output for display through Phing's log.
                foreach ($output as $line) {
                    $this->log($line);
                }
            }
        }

        if (isset($initial_cwd)) {
            $this->log("Changing working directory back to $initial_cwd.", $exec_level);
            chdir($initial_cwd);
        }

        // Set value of the return property.
        if (!empty($this->return_property)) {
            $this->getProject()->setProperty($this->return_property, $return);
        }
        // Build fail.
        if ($this->haltonerror && $return != 0) {
            throw new BuildException("Drush exited with code $return");
        }

        return $return != 0;
    }
public function main()
    {
        $command = [];

        $command[] = !empty($this->bin) ? $this->bin : 'drush';

        if (!empty($this->alias)) {
            $command[] = '@' . $this->alias;
        }

        if (!empty($this->root)) {
            $option = new DrushOption();
            $option->setName('root');
            $option->addText($this->root);
            $this->options[] = $option;
        }

        if (!empty($this->uri)) {
            $option = new DrushOption();
            $option->setName('uri');
            $option->addText($this->uri);
            $this->options[] = $option;
        }

        if (is_bool($this->assume)) {
            $option = new DrushOption();
            $option->setName(($this->assume ? 'yes' : 'no'));
            $this->options[] = $option;
        }

        if ($this->simulate) {
            $option = new DrushOption();
            $option->setName('simulate');
            $this->options[] = $option;
        }

        if ($this->pipe) {
            $option = new DrushOption();
            $option->setName('pipe');
            $this->options[] = $option;
        }

        if (Phing::getMsgOutputLevel() >= Project::MSG_VERBOSE) {
            $this->setVerbose('true');
        }

        if ($this->verbose) {
            $option = new DrushOption();
            $option->setName('verbose');
            $this->options[] = $option;
            $exec_level = Project::MSG_INFO;
        } else {
            $exec_level = Project::MSG_VERBOSE;
        }

        foreach ($this->options as $option) {
            $command[] = $option->toString();
        }

        $command[] = $this->command;

        foreach ($this->params as $param) {
            $command[] = $param->getValue();
        }

        if (!empty($this->dir)) {
            $this->log("Changing working directory to: $this->dir", $exec_level);
            $initial_cwd = getcwd();
            chdir($this->dir);
        }

        // Execute Drush.
        $output = [];
        $return = null;

        if ($this->passthru) {
            $command = implode(' ', $command);
            $this->log("Executing: $command", $exec_level);
            passthru($command, $return);
        } else {
            // Redirect sterr to stout for Phing log.
            $command[] = '2>&1';

            $command = implode(' ', $command);
            $this->log("Executing: $command", $exec_level);
            exec($command, $output, $return);

            if ($this->logoutput) {
                // Collect Drush output for display through Phing's log.
                foreach ($output as $line) {
                    $this->log($line);
                }
            }
        }

        if (isset($initial_cwd)) {
            $this->log("Changing working directory back to $initial_cwd.", $exec_level);
            chdir($initial_cwd);
        }

        // Set value of the return property.
        if (!empty($this->return_property)) {
            $this->getProject()->setProperty($this->return_property, $return);
        }
        // Build fail.
        if ($this->haltonerror && $return != 0) {
            throw new BuildException("Drush exited with code $return");
        }

        return $return != 0;
    }
The main entry point method.