|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Utilise Mercurial from within Phing. |
|
5
|
|
|
* |
|
6
|
|
|
* PHP Version 5.4 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Tasks |
|
9
|
|
|
* @package phing.tasks.ext |
|
10
|
|
|
* @author Ken Guest <[email protected]> |
|
11
|
|
|
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html) |
|
12
|
|
|
* @link https://github.com/kenguest/Phing-HG |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Phing\Task\Ext\Hg; |
|
16
|
|
|
|
|
17
|
|
|
use Phing\Task; |
|
18
|
|
|
use Phing\Exception\BuildException; |
|
19
|
|
|
use Phing\Util\StringHelper; |
|
20
|
|
|
use Siad007\VersionControl\HG\Factory; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Base task for integrating phing and mercurial. |
|
24
|
|
|
* |
|
25
|
|
|
* @category Tasks |
|
26
|
|
|
* @package phing.tasks.ext.hg |
|
27
|
|
|
* @author Ken Guest <[email protected]> |
|
28
|
|
|
* @license LGPL (see http://www.gnu.org/licenses/lgpl.html) |
|
29
|
|
|
* @link HgBaseTask.php |
|
30
|
|
|
*/ |
|
31
|
|
|
abstract class HgBaseTask extends Task |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* Insecure argument |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $insecure = ''; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Repository directory |
|
42
|
|
|
* |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $repository = ''; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Whether to be quiet... --quiet argument. |
|
49
|
|
|
* |
|
50
|
|
|
* @var bool |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $quiet = false; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Username. |
|
56
|
|
|
* |
|
57
|
|
|
* @var string |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $user = ''; |
|
60
|
|
|
|
|
61
|
|
|
public static $factory = null; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Initialize Task. |
|
65
|
|
|
* Check and include necessary libraries. |
|
66
|
|
|
*/ |
|
67
|
|
|
public function init() |
|
68
|
|
|
{ |
|
69
|
16 |
|
if (!class_exists(Factory::class)) { |
|
70
|
|
|
throw new BuildException( |
|
71
|
16 |
|
"The Hg tasks depend on the siad007/versioncontrol_hg package being installed.", |
|
72
|
|
|
$this->getLocation() |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set repository attribute |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $repository Repository |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public function setRepository($repository) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->repository = $repository; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Set the quiet attribute --quiet |
|
92
|
15 |
|
* |
|
93
|
|
|
* @param string $quiet yes|no|true|false|1|0 |
|
94
|
15 |
|
* |
|
95
|
|
|
* @return void |
|
96
|
|
|
*/ |
|
97
|
|
|
public function setQuiet($quiet) |
|
98
|
|
|
{ |
|
99
|
|
|
$this->quiet = StringHelper::booleanValue($quiet); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
3 |
|
/** |
|
103
|
|
|
* Get the quiet attribute value. |
|
104
|
3 |
|
* |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getQuiet() |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->quiet; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get Repository attribute/directory. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getRepository() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->repository; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Set insecure attribute |
|
124
|
11 |
|
* |
|
125
|
|
|
* @param string $insecure 'yes', etc. |
|
126
|
11 |
|
* |
|
127
|
|
|
* @return void |
|
128
|
|
|
*/ |
|
129
|
|
|
public function setInsecure($insecure) |
|
130
|
|
|
{ |
|
131
|
|
|
$this->insecure = StringHelper::booleanValue($insecure); |
|
|
|
|
|
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Get 'insecure' attribute value. (--insecure or null) |
|
136
|
2 |
|
* |
|
137
|
|
|
* @return string |
|
138
|
2 |
|
*/ |
|
139
|
|
|
public function getInsecure() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->insecure; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Set user attribute |
|
146
|
1 |
|
* |
|
147
|
|
|
* @param string $user username/email address. |
|
148
|
1 |
|
* |
|
149
|
|
|
* @return void |
|
150
|
|
|
*/ |
|
151
|
|
|
public function setUser($user) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->user = $user; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Get username attribute. |
|
158
|
|
|
* |
|
159
|
11 |
|
* @return string |
|
160
|
|
|
*/ |
|
161
|
11 |
|
public function getUser() |
|
162
|
7 |
|
{ |
|
163
|
|
|
return $this->user; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
4 |
|
/** |
|
167
|
|
|
* Check provided repository directory actually is an existing directory. |
|
168
|
7 |
|
* |
|
169
|
|
|
* @param string $dir Repository directory |
|
170
|
|
|
* |
|
171
|
21 |
|
* @return bool |
|
172
|
|
|
* @throws BuildException |
|
173
|
21 |
|
*/ |
|
174
|
21 |
|
public function checkRepositoryIsDirAndExists($dir) |
|
175
|
|
|
{ |
|
176
|
|
|
if (file_exists($dir)) { |
|
177
|
|
|
if (!is_dir($dir)) { |
|
178
|
|
|
throw new BuildException("Repository '$dir' is not a directory."); |
|
179
|
|
|
} |
|
180
|
|
|
} else { |
|
181
|
|
|
throw new BuildException("Repository directory '$dir' does not exist."); |
|
182
|
|
|
} |
|
183
|
|
|
return true; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
public function getFactoryInstance($command, $options = []) |
|
187
|
|
|
{ |
|
188
|
|
|
self::$factory = Factory::getInstance($command, $options); |
|
189
|
|
|
return self::$factory; |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.