|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the LGPL. For more information please see |
|
17
|
|
|
* <http://phing.info>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The patternset storage component. Carries all necessary data and methods |
|
22
|
|
|
* for the patternset stuff. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Andreas Aderhold, [email protected] |
|
25
|
|
|
* @package phing.types |
|
26
|
|
|
*/ |
|
27
|
|
|
class PatternSet extends DataType |
|
28
|
|
|
{ |
|
29
|
|
|
private $includeList = []; |
|
30
|
|
|
private $excludeList = []; |
|
31
|
|
|
private $includesFileList = []; |
|
32
|
|
|
private $excludesFileList = []; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Makes this instance in effect a reference to another PatternSet |
|
36
|
|
|
* instance. |
|
37
|
|
|
* You must not set another attribute or nest elements inside |
|
38
|
|
|
* this element if you make it a reference. |
|
39
|
|
|
* |
|
40
|
|
|
* @param Reference $r |
|
41
|
|
|
* @throws BuildException |
|
42
|
|
|
*/ |
|
43
|
4 |
|
public function setRefid(Reference $r) |
|
44
|
|
|
{ |
|
45
|
4 |
|
if (!empty($this->includeList) || !empty($this->excludeList)) { |
|
46
|
|
|
throw $this->tooManyAttributes(); |
|
47
|
|
|
} |
|
48
|
4 |
|
parent::setRefid($r); |
|
49
|
4 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Add a name entry on the include list |
|
53
|
|
|
* |
|
54
|
|
|
* @return PatternSetNameEntry Reference to object |
|
55
|
|
|
* @throws BuildException |
|
56
|
|
|
*/ |
|
57
|
83 |
|
public function createInclude() |
|
58
|
|
|
{ |
|
59
|
83 |
|
if ($this->isReference()) { |
|
60
|
1 |
|
throw $this->noChildrenAllowed(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
82 |
|
return $this->addPatternToList($this->includeList); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Add a name entry on the include files list |
|
68
|
|
|
* |
|
69
|
|
|
* @return PatternSetNameEntry Reference to object |
|
70
|
|
|
* @throws BuildException |
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function createIncludesFile() |
|
73
|
|
|
{ |
|
74
|
1 |
|
if ($this->isReference()) { |
|
75
|
1 |
|
throw $this->noChildrenAllowed(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->addPatternToList($this->includesFileList); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Add a name entry on the exclude list |
|
83
|
|
|
* |
|
84
|
|
|
* @return PatternSetNameEntry Reference to object |
|
85
|
|
|
* @throws BuildException |
|
86
|
|
|
*/ |
|
87
|
3 |
|
public function createExclude() |
|
88
|
|
|
{ |
|
89
|
3 |
|
if ($this->isReference()) { |
|
90
|
1 |
|
throw $this->noChildrenAllowed(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
2 |
|
return $this->addPatternToList($this->excludeList); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* add a name entry on the exclude files list |
|
98
|
|
|
* |
|
99
|
|
|
* @return PatternSetNameEntry Reference to object |
|
100
|
|
|
* @throws BuildException |
|
101
|
|
|
*/ |
|
102
|
1 |
|
public function createExcludesFile() |
|
103
|
|
|
{ |
|
104
|
1 |
|
if ($this->isReference()) { |
|
105
|
1 |
|
throw $this->noChildrenAllowed(); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return $this->addPatternToList($this->excludesFileList); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Sets the set of include patterns. Patterns may be separated by a comma |
|
113
|
|
|
* or a space. |
|
114
|
|
|
* |
|
115
|
|
|
* @param string $includes the string containing the include patterns |
|
116
|
|
|
* @return void |
|
117
|
|
|
* @throws BuildException |
|
118
|
|
|
*/ |
|
119
|
4 |
|
public function setIncludes($includes) |
|
120
|
|
|
{ |
|
121
|
4 |
|
if ($this->isReference()) { |
|
122
|
|
|
throw $this->tooManyAttributes(); |
|
123
|
|
|
} |
|
124
|
4 |
|
if ($includes !== null && strlen($includes) > 0) { |
|
125
|
4 |
|
$tok = strtok($includes, ", "); |
|
126
|
4 |
|
while ($tok !== false) { |
|
127
|
4 |
|
$o = $this->createInclude(); |
|
128
|
4 |
|
$o->setName($tok); |
|
129
|
4 |
|
$tok = strtok(", "); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
4 |
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Sets the set of exclude patterns. Patterns may be separated by a comma |
|
136
|
|
|
* or a space. |
|
137
|
|
|
* |
|
138
|
|
|
* @param string the string containing the exclude patterns |
|
139
|
|
|
* @return void |
|
140
|
|
|
* @throws BuildException |
|
141
|
|
|
*/ |
|
142
|
1 |
|
public function setExcludes($excludes) |
|
143
|
|
|
{ |
|
144
|
1 |
|
if ($this->isReference()) { |
|
145
|
|
|
throw $this->tooManyAttributes(); |
|
146
|
|
|
} |
|
147
|
1 |
|
if ($excludes !== null && strlen($excludes) > 0) { |
|
148
|
1 |
|
$tok = strtok($excludes, ", "); |
|
149
|
1 |
|
while ($tok !== false) { |
|
150
|
1 |
|
$o = $this->createExclude(); |
|
151
|
1 |
|
$o->setName($tok); |
|
152
|
1 |
|
$tok = strtok(", "); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
1 |
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* add a name entry to the given list |
|
159
|
|
|
* |
|
160
|
|
|
* @param array List onto which the nameentry should be added |
|
|
|
|
|
|
161
|
|
|
* @return PatternSetNameEntry Reference to the created PsetNameEntry instance |
|
162
|
|
|
*/ |
|
163
|
84 |
|
private function addPatternToList(&$list) |
|
164
|
|
|
{ |
|
165
|
84 |
|
$num = array_push($list, new PatternSetNameEntry()); |
|
166
|
|
|
|
|
167
|
84 |
|
return $list[$num - 1]; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Sets the name of the file containing the includes patterns. |
|
172
|
|
|
* |
|
173
|
|
|
* @param PhingFile $includesFile file to fetch the include patterns from. |
|
174
|
|
|
* |
|
175
|
|
|
* @throws BuildException |
|
176
|
|
|
*/ |
|
177
|
|
|
public function setIncludesFile($includesFile) |
|
178
|
|
|
{ |
|
179
|
|
|
if ($this->isReference()) { |
|
180
|
|
|
throw $this->tooManyAttributes(); |
|
181
|
|
|
} |
|
182
|
|
|
if ($includesFile instanceof PhingFile) { |
|
|
|
|
|
|
183
|
|
|
$includesFile = $includesFile->getPath(); |
|
184
|
|
|
} |
|
185
|
|
|
$o = $this->createIncludesFile(); |
|
186
|
|
|
$o->setName($includesFile); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Sets the name of the file containing the excludes patterns. |
|
191
|
|
|
* |
|
192
|
|
|
* @param PhingFile $excludesFile file to fetch the exclude patterns from. |
|
193
|
|
|
* @throws BuildException |
|
194
|
|
|
*/ |
|
195
|
|
|
public function setExcludesFile($excludesFile) |
|
196
|
|
|
{ |
|
197
|
|
|
if ($this->isReference()) { |
|
198
|
|
|
throw $this->tooManyAttributes(); |
|
199
|
|
|
} |
|
200
|
|
|
if ($excludesFile instanceof PhingFile) { |
|
|
|
|
|
|
201
|
|
|
$excludesFile = $excludesFile->getPath(); |
|
202
|
|
|
} |
|
203
|
|
|
$o = $this->createExcludesFile(); |
|
204
|
|
|
$o->setName($excludesFile); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Reads path matching patterns from a file and adds them to the |
|
209
|
|
|
* includes or excludes list |
|
210
|
|
|
* |
|
211
|
|
|
* @param PhingFile $patternfile |
|
212
|
|
|
* @param $patternlist |
|
213
|
|
|
* @param Project $p |
|
214
|
|
|
* |
|
215
|
|
|
* @throws BuildException |
|
216
|
|
|
*/ |
|
217
|
|
|
private function readPatterns(PhingFile $patternfile, &$patternlist, Project $p) |
|
218
|
|
|
{ |
|
219
|
|
|
$patternReader = null; |
|
|
|
|
|
|
220
|
|
|
try { |
|
221
|
|
|
// Get a FileReader |
|
222
|
|
|
$patternReader = new BufferedReader(new FileReader($patternfile)); |
|
223
|
|
|
|
|
224
|
|
|
// Create one NameEntry in the appropriate pattern list for each |
|
225
|
|
|
// line in the file. |
|
226
|
|
|
$line = $patternReader->readLine(); |
|
227
|
|
|
while ($line !== null) { |
|
228
|
|
|
if (!empty($line)) { |
|
229
|
|
|
$line = $p->replaceProperties($line); |
|
230
|
|
|
$this->addPatternToList($patternlist)->setName($line); |
|
231
|
|
|
} |
|
232
|
|
|
$line = $patternReader->readLine(); |
|
233
|
|
|
} |
|
234
|
|
|
} catch (IOException $ioe) { |
|
235
|
|
|
$msg = "An error occurred while reading from pattern file: " . $patternfile->__toString(); |
|
236
|
|
|
if ($patternReader) { |
|
|
|
|
|
|
237
|
|
|
$patternReader->close(); |
|
238
|
|
|
} |
|
239
|
|
|
throw new BuildException($msg, $ioe); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
$patternReader->close(); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* Adds the patterns of the other instance to this set. |
|
247
|
|
|
* |
|
248
|
|
|
* @param $other |
|
249
|
|
|
* @param Project $p |
|
250
|
|
|
* |
|
251
|
|
|
* @throws BuildException |
|
252
|
|
|
*/ |
|
253
|
1 |
|
public function append($other, $p) |
|
254
|
|
|
{ |
|
255
|
1 |
|
if ($this->isReference()) { |
|
256
|
|
|
throw new BuildException("Cannot append to a reference"); |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
1 |
|
$incl = $other->getIncludePatterns($p); |
|
260
|
1 |
|
if ($incl !== null) { |
|
261
|
1 |
|
foreach ($incl as $incl_name) { |
|
262
|
1 |
|
$o = $this->createInclude(); |
|
263
|
1 |
|
$o->setName($incl_name); |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
1 |
|
$excl = $other->getExcludePatterns($p); |
|
268
|
1 |
|
if ($excl !== null) { |
|
269
|
|
|
foreach ($excl as $excl_name) { |
|
270
|
|
|
$o = $this->createExclude(); |
|
271
|
|
|
$o->setName($excl_name); |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
1 |
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Returns the filtered include patterns. |
|
278
|
|
|
* |
|
279
|
|
|
* @param Project $p |
|
280
|
|
|
* |
|
281
|
|
|
* @throws BuildException |
|
282
|
|
|
* |
|
283
|
|
|
* @return array |
|
284
|
|
|
*/ |
|
285
|
102 |
|
public function getIncludePatterns(Project $p) |
|
286
|
|
|
{ |
|
287
|
102 |
|
if ($this->isReference()) { |
|
288
|
|
|
$o = $this->getRef($p); |
|
289
|
|
|
|
|
290
|
|
|
return $o->getIncludePatterns($p); |
|
|
|
|
|
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
102 |
|
$this->readFiles($p); |
|
294
|
|
|
|
|
295
|
102 |
|
return $this->makeArray($this->includeList, $p); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Returns the filtered exclude patterns. |
|
300
|
|
|
* |
|
301
|
|
|
* @param Project $p |
|
302
|
|
|
* |
|
303
|
|
|
* @throws BuildException |
|
304
|
|
|
* |
|
305
|
|
|
* @return array |
|
306
|
|
|
*/ |
|
307
|
102 |
|
public function getExcludePatterns(Project $p) |
|
308
|
|
|
{ |
|
309
|
102 |
|
if ($this->isReference()) { |
|
310
|
|
|
$o = $this->getRef($p); |
|
311
|
|
|
|
|
312
|
|
|
return $o->getExcludePatterns($p); |
|
|
|
|
|
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
102 |
|
$this->readFiles($p); |
|
316
|
|
|
|
|
317
|
102 |
|
return $this->makeArray($this->excludeList, $p); |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
/** |
|
321
|
|
|
* helper for FileSet. |
|
322
|
|
|
* |
|
323
|
|
|
* @return bool |
|
324
|
|
|
*/ |
|
325
|
3 |
|
public function hasPatterns() |
|
326
|
|
|
{ |
|
327
|
3 |
|
return (bool) count($this->includesFileList) > 0 || count($this->excludesFileList) > 0 |
|
328
|
3 |
|
|| count($this->includeList) > 0 || count($this->excludeList) > 0; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
/** |
|
332
|
|
|
* Performs the check for circular references and returns the |
|
333
|
|
|
* referenced PatternSet. |
|
334
|
|
|
* |
|
335
|
|
|
* @param Project $p |
|
336
|
|
|
* |
|
337
|
|
|
* @throws BuildException |
|
338
|
|
|
* |
|
339
|
|
|
* @return Reference |
|
340
|
|
|
*/ |
|
341
|
|
|
public function getRef(Project $p) |
|
|
|
|
|
|
342
|
|
|
{ |
|
343
|
|
|
$dataTypeName = StringHelper::substring(__CLASS__, strrpos(__CLASS__, '\\') + 1); |
|
344
|
|
|
return $this->getCheckedRef(__CLASS__, $dataTypeName); |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
/** |
|
348
|
|
|
* Convert a array of PatternSetNameEntry elements into an array of Strings. |
|
349
|
|
|
* |
|
350
|
|
|
* @param array $list |
|
351
|
|
|
* @param Project $p |
|
352
|
|
|
* |
|
353
|
|
|
* @return array |
|
354
|
|
|
*/ |
|
355
|
102 |
|
private function makeArray(&$list, Project $p) |
|
356
|
|
|
{ |
|
357
|
102 |
|
if (count($list) === 0) { |
|
358
|
102 |
|
return null; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
72 |
|
$tmpNames = []; |
|
362
|
72 |
|
foreach ($list as $ne) { |
|
363
|
72 |
|
$pattern = (string) $ne->evalName($p); |
|
364
|
72 |
|
if ($pattern !== null && strlen($pattern) > 0) { |
|
365
|
72 |
|
$tmpNames[] = $pattern; |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
72 |
|
return $tmpNames; |
|
370
|
|
|
} |
|
371
|
|
|
|
|
372
|
|
|
/** |
|
373
|
|
|
* Read includesfile or excludesfile if not already done so. |
|
374
|
|
|
* |
|
375
|
|
|
* @param Project $p |
|
376
|
|
|
* |
|
377
|
|
|
* @throws BuildException |
|
378
|
|
|
*/ |
|
379
|
102 |
|
private function readFiles(Project $p) |
|
380
|
|
|
{ |
|
381
|
102 |
|
if (!empty($this->includesFileList)) { |
|
382
|
|
|
foreach ($this->includesFileList as $ne) { |
|
383
|
|
|
$fileName = (string) $ne->evalName($p); |
|
384
|
|
|
if ($fileName !== null) { |
|
385
|
|
|
$inclFile = $p->resolveFile($fileName); |
|
386
|
|
|
if (!$inclFile->exists()) { |
|
387
|
|
|
throw new BuildException("Includesfile " . $inclFile->getAbsolutePath() . " not found."); |
|
388
|
|
|
} |
|
389
|
|
|
$this->readPatterns($inclFile, $this->includeList, $p); |
|
390
|
|
|
} |
|
391
|
|
|
} |
|
392
|
|
|
$this->includesFileList = []; |
|
393
|
|
|
} |
|
394
|
|
|
|
|
395
|
102 |
|
if (!empty($this->excludesFileList)) { |
|
396
|
|
|
foreach ($this->excludesFileList as $ne) { |
|
397
|
|
|
$fileName = (string) $ne->evalName($p); |
|
398
|
|
|
if ($fileName !== null) { |
|
399
|
|
|
$exclFile = $p->resolveFile($fileName); |
|
400
|
|
|
if (!$exclFile->exists()) { |
|
401
|
|
|
throw new BuildException("Excludesfile " . $exclFile->getAbsolutePath() . " not found."); |
|
402
|
|
|
} |
|
403
|
|
|
$this->readPatterns($exclFile, $this->excludeList, $p); |
|
404
|
|
|
} |
|
405
|
|
|
} |
|
406
|
|
|
$this->excludesFileList = []; |
|
407
|
|
|
} |
|
408
|
102 |
|
} |
|
409
|
|
|
|
|
410
|
|
|
/** |
|
411
|
|
|
* @return string |
|
412
|
|
|
*/ |
|
413
|
103 |
|
public function __toString() |
|
414
|
|
|
{ |
|
415
|
|
|
|
|
416
|
|
|
// We can't compile includeList into array because, toString() does |
|
417
|
|
|
// not know about project: |
|
418
|
|
|
// |
|
419
|
|
|
// $includes = $this->makeArray($this->includeList, $this->project); |
|
420
|
|
|
// $excludes = $this->makeArray($this->excludeList, $this->project); |
|
421
|
|
|
|
|
422
|
103 |
|
if (empty($this->includeList)) { |
|
423
|
33 |
|
$includes = "empty"; |
|
424
|
|
|
} else { |
|
425
|
70 |
|
$includes = ""; |
|
426
|
70 |
|
foreach ($this->includeList as $ne) { |
|
427
|
70 |
|
$includes .= (string) $ne . ","; |
|
428
|
|
|
} |
|
429
|
70 |
|
$includes = rtrim($includes, ","); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
103 |
|
if (empty($this->excludeList)) { |
|
433
|
102 |
|
$excludes = "empty"; |
|
434
|
|
|
} else { |
|
435
|
2 |
|
$excludes = ""; |
|
436
|
2 |
|
foreach ($this->excludeList as $ne) { |
|
437
|
2 |
|
$excludes .= (string) $ne . ","; |
|
438
|
|
|
} |
|
439
|
2 |
|
$excludes = rtrim($excludes, ","); |
|
440
|
|
|
} |
|
441
|
|
|
|
|
442
|
103 |
|
return "patternSet{ includes: $includes excludes: $excludes }"; |
|
443
|
|
|
} |
|
444
|
|
|
} |
|
445
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths