Completed
Push — master ( bc194a...d90c8b )
by Siad
17:01
created

HgInitTask   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 53.56%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 59
ccs 15
cts 28
cp 0.5356
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTargetPath() 0 3 1
B main() 0 33 6
1
<?php
2
/**
3
 * Utilise Mercurial from within Phing.
4
 *
5
 * PHP Version 5.4
6
 *
7
 * @category Tasks
8
 * @package  phing.tasks.ext
9
 * @author   Ken Guest <[email protected]>
10
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
11
 * @link     https://github.com/kenguest/Phing-HG
12
 */
13
14
/**
15
 * Integration/Wrapper for hg init
16
 *
17
 * @category Tasks
18
 * @package  phing.tasks.ext.hg
19
 * @author   Ken Guest <[email protected]>
20
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
21
 * @link     HgInitTask.php
22
 */
23
class HgInitTask extends HgBaseTask
24
{
25
    /**
26
     * Path to target directory
27
     *
28
     * @var string
29
     */
30
    protected $targetPath;
31
32
    /**
33
     * Set path to source repo
34
     *
35
     * @param string $targetPath Path to repository used as source
36
     *
37
     * @return void
38
     */
39
    public function setTargetPath($targetPath)
40
    {
41
        $this->targetPath = $targetPath;
42
    }
43
44
    /**
45
     * Main entry point for this task.
46
     *
47
     * @return void
48
     */
49 6
    public function main()
50
    {
51 6
        $clone = $this->getFactoryInstance('init');
52 6
        $this->log('Initializing', Project::MSG_INFO);
53 6
        $clone->setQuiet($this->getQuiet());
54 6
        $clone->setInsecure($this->getInsecure());
55 6
        $cwd = getcwd();
56 6
        if ($this->repository === '') {
57
            $project = $this->getProject();
58
            $dir = $project->getProperty('application.startdir');
59
        } else {
60 6
            $dir = $this->repository;
61
        }
62 6
        if (!is_dir($dir)) {
63 1
            throw new BuildException("$dir is not a directory.");
64
        }
65 5
        chdir($dir);
66
        try {
67 5
            $this->log("Executing: " . $clone->asString(), Project::MSG_INFO);
68 5
            $output = $clone->execute();
69 5
            if ($output !== '') {
70
                $this->log($output);
71
            }
72
        } catch (Exception $ex) {
73
            $msg = $ex->getMessage();
74
            $p = strpos($msg, 'hg returned:');
75
            if ($p !== false) {
76
                $msg = substr($msg, $p + 13);
77
            }
78
            chdir($cwd);
79
            throw new BuildException($msg);
80
        }
81 5
        chdir($cwd);
82 5
    }
83
}
84