1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* RoboFile.php |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-cli-magento |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Lurker\Event\FilesystemEvent; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Finder\Finder; |
24
|
|
|
use AppserverIo\RoboTasks\AbstractRoboFile; |
25
|
|
|
use Robo\Robo; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Defines the available build tasks. |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/techdivision/import-cli-magento |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
* |
36
|
|
|
* @SuppressWarnings(PHPMD) |
37
|
|
|
*/ |
38
|
|
|
class RoboFile extends AbstractRoboFile |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Configuration key for the directories. |
43
|
|
|
* |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
const DIRS = 'dirs'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Configuration key for the deploy directory. |
50
|
|
|
* |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
const DEPLOY = 'deploy'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Configuration key for the docker configuration. |
57
|
|
|
* |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
const DOCKER = 'docker'; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Configuration key for the docker target container name. |
64
|
|
|
* |
65
|
|
|
* @var string |
66
|
|
|
*/ |
67
|
|
|
const TARGET_CONTAINER = 'target-container'; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns the deploy directory. |
71
|
|
|
* |
72
|
|
|
* @return string The directory to deploy the sources to |
73
|
|
|
*/ |
74
|
|
|
protected function getDeployDir() |
75
|
|
|
{ |
76
|
|
|
return Robo::config()->get(sprintf('%s.%s', RoboFile::DIRS, RoboFile::DEPLOY)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns the name of the docker target container. |
81
|
|
|
* |
82
|
|
|
* @return string The docker target container |
83
|
|
|
*/ |
84
|
|
|
protected function getTargetContainer() |
85
|
|
|
{ |
86
|
|
|
return Robo::config()->get(sprintf('%s.%s.%s', RoboFile::DOCKER, RoboFile::TARGET_CONTAINER)); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Run's the composer install command. |
91
|
|
|
* |
92
|
|
|
* @return void |
93
|
|
|
*/ |
94
|
|
|
public function composerInstall() |
95
|
|
|
{ |
96
|
|
|
// optimize autoloader with custom path |
97
|
|
|
$this->taskComposerInstall() |
98
|
|
|
->preferDist() |
99
|
|
|
->optimizeAutoloader() |
100
|
|
|
->run(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Run's the composer update command. |
105
|
|
|
* |
106
|
|
|
* @return void |
107
|
|
|
*/ |
108
|
|
|
public function composerUpdate() |
109
|
|
|
{ |
110
|
|
|
// optimize autoloader with custom path |
111
|
|
|
$this->taskComposerUpdate() |
112
|
|
|
->preferDist() |
113
|
|
|
->optimizeAutoloader() |
114
|
|
|
->run(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Clean up the environment for a new build. |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
public function clean() |
123
|
|
|
{ |
124
|
|
|
$this->taskDeleteDir($this->getTargetDir())->run(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Prepare's the environment for a new build. |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function prepare() |
133
|
|
|
{ |
134
|
|
|
$this->taskFileSystemStack() |
135
|
|
|
->mkdir($this->getTargetDir()) |
136
|
|
|
->mkdir($this->getReportsDir()) |
137
|
|
|
->run(); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Run's the PHPMD. |
142
|
|
|
* |
143
|
|
|
* @return void |
144
|
|
|
*/ |
145
|
|
|
public function runMd() |
146
|
|
|
{ |
147
|
|
|
|
148
|
|
|
// run the mess detector |
149
|
|
|
$this->_exec( |
150
|
|
|
sprintf( |
151
|
|
|
'%s/bin/phpmd %s xml phpmd.xml --reportfile %s/reports/pmd.xml --ignore-violations-on-exit', |
152
|
|
|
$this->getVendorDir(), |
153
|
|
|
$this->getSrcDir(), |
154
|
|
|
$this->getTargetDir() |
155
|
|
|
) |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Run's the PHPCPD. |
161
|
|
|
* |
162
|
|
|
* @return void |
163
|
|
|
*/ |
164
|
|
|
public function runCpd() |
165
|
|
|
{ |
166
|
|
|
|
167
|
|
|
// run the copy past detector |
168
|
|
|
$this->_exec( |
169
|
|
|
sprintf( |
170
|
|
|
'%s/bin/phpcpd %s --log-pmd %s/reports/pmd-cpd.xml', |
171
|
|
|
$this->getVendorDir(), |
172
|
|
|
$this->getSrcDir(), |
173
|
|
|
$this->getTargetDir() |
174
|
|
|
) |
175
|
|
|
); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Run's the PHPCodeSniffer. |
180
|
|
|
* |
181
|
|
|
* @return void |
182
|
|
|
*/ |
183
|
|
|
public function runCs() |
184
|
|
|
{ |
185
|
|
|
|
186
|
|
|
// run the code sniffer |
187
|
|
|
$this->_exec( |
188
|
|
|
sprintf( |
189
|
|
|
'%s/bin/phpcs -n --report-full --extensions=php --standard=phpcs.xml --report-checkstyle=%s/reports/phpcs.xml %s', |
190
|
|
|
$this->getVendorDir(), |
191
|
|
|
$this->getTargetDir(), |
192
|
|
|
$this->getSrcDir() |
193
|
|
|
) |
194
|
|
|
); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Run's the PHPUnit tests. |
199
|
|
|
* |
200
|
|
|
* @return void |
201
|
|
|
*/ |
202
|
|
|
public function runTests() |
203
|
|
|
{ |
204
|
|
|
|
205
|
|
|
// run PHPUnit |
206
|
|
|
$this->taskPHPUnit(sprintf('%s/bin/phpunit', $this->getVendorDir())) |
207
|
|
|
->configFile('phpunit.xml') |
208
|
|
|
->run(); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Deploy's the extension to it's target directory. |
213
|
|
|
* |
214
|
|
|
* @return void |
215
|
|
|
*/ |
216
|
|
|
public function deploy() |
217
|
|
|
{ |
218
|
|
|
$this->taskCopyDir(array($this->getSrcDir() => $this->getDeployDir()))->run(); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Deploy's the extension to it's target directory in the specified docker container. |
223
|
|
|
* |
224
|
|
|
* @return void |
225
|
|
|
*/ |
226
|
|
|
public function deployDocker() |
227
|
|
|
{ |
228
|
|
|
|
229
|
|
|
// copy the file itself |
230
|
|
|
$this->taskExec('docker') |
231
|
|
|
->arg('cp') |
232
|
|
|
->arg(sprintf('%s/app', $this->getSrcDir())) |
233
|
|
|
->arg(sprintf('%s:%s', $this->getTargetContainer(), $this->getDeployDir())) |
234
|
|
|
->run(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* The complete build process. |
239
|
|
|
* |
240
|
|
|
* @return void |
241
|
|
|
*/ |
242
|
|
|
public function build() |
243
|
|
|
{ |
244
|
|
|
$this->clean(); |
245
|
|
|
$this->prepare(); |
246
|
|
|
$this->runCs(); |
247
|
|
|
$this->runCpd(); |
248
|
|
|
$this->runMd(); |
249
|
|
|
$this->runTests(); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.