Passed
Push — master ( f1e2bc...c4cbbf )
by Michiel
05:24
created

MatchingTask::addSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
namespace Phing\Task\System;
21
22
use Phing\Exception\BuildException;
23
use Phing\Io\DirectoryScanner;
24
use Phing\Io\File;
25
use Phing\Project;
26
use Phing\ProjectComponent;
27
use Phing\Task;
28
use Phing\Type\FileSet;
29
use Phing\Type\PatternSet;
30
use Phing\Type\PatternSetNameEntry;
31
use Phing\Type\Selector\AndSelector;
32
use Phing\Type\Selector\ContainsRegexpSelector;
33
use Phing\Type\Selector\ContainsSelector;
34
use Phing\Type\Selector\DateSelector;
35
use Phing\Type\Selector\DependSelector;
36
use Phing\Type\Selector\DepthSelector;
37
use Phing\Type\Selector\DifferentSelector;
38
use Phing\Type\Selector\ExecutableSelector;
39
use Phing\Type\Selector\ExtendSelector;
40
use Phing\Type\Selector\FilenameSelector;
41
use Phing\Type\Selector\FileSelector;
42
use Phing\Type\Selector\MajoritySelector;
43
use Phing\Type\Selector\ModifiedSelector;
44
use Phing\Type\Selector\NoneSelector;
45
use Phing\Type\Selector\NotSelector;
46
use Phing\Type\Selector\OrSelector;
47
use Phing\Type\Selector\PresentSelector;
48
use Phing\Type\Selector\ReadableSelector;
49
use Phing\Type\Selector\SelectorContainer;
50
use Phing\Type\Selector\SelectSelector;
51
use Phing\Type\Selector\SizeSelector;
52
use Phing\Type\Selector\SymlinkSelector;
53
use Phing\Type\Selector\TypeSelector;
54
use Phing\Type\Selector\WritableSelector;
55
56
/**
57
 * This is an abstract task that should be used by all those tasks that
58
 * require to include or exclude files based on pattern matching.
59
 *
60
 * This is very closely based on the ANT class of the same name.
61
 *
62
 * @author  Hans Lellelid <[email protected]> (Phing)
63
 * @author  Arnout J. Kuiper <[email protected]> (Ant)
64
 * @author  Stefano Mazzocchi  <[email protected]> (Ant)
65
 * @author  Sam Ruby <[email protected]> (Ant)
66
 * @author  Jon S. Stevens <[email protected]> (Ant
67
 * @author  Stefan Bodewig <[email protected]> (Ant)
68
 * @author  Bruce Atherton <[email protected]> (Ant)
69
 */
70
abstract class MatchingTask extends Task implements SelectorContainer
71
{
72
73
    /**
74
     * @var boolean
75
     */
76
    protected $useDefaultExcludes = true;
77
78
    /**
79
     * @var FileSet
80
     */
81
    protected $fileset;
82
83
    /**
84
     * Create instance; set fileset to new FileSet.
85
     */
86 14
    public function __construct()
87
    {
88 14
        parent::__construct();
89 14
        $this->fileset = new FileSet();
90 14
    }
91
92
    /**
93
     * @see ProjectComponent::setProject()
94
     * @param Project $project
95
     */
96 14
    public function setProject($project)
97
    {
98 14
        parent::setProject($project);
99 14
        $this->fileset->setProject($project);
100 14
    }
101
102
    /**
103
     * add a name entry on the include list
104
     *
105
     * @return PatternSetNameEntry
106
     */
107
    public function createInclude()
108
    {
109
        return $this->fileset->createInclude();
110
    }
111
112
    /**
113
     * add a name entry on the include files list
114
     *
115
     * @return PatternSetNameEntry
116
     */
117
    public function createIncludesFile()
118
    {
119
        return $this->fileset->createIncludesFile();
120
    }
121
122
    /**
123
     * add a name entry on the exclude list
124
     *
125
     * @return PatternSetNameEntry
126
     */
127
    public function createExclude()
128
    {
129
        return $this->fileset->createExclude();
130
    }
131
132
    /**
133
     * add a name entry on the include files list
134
     *
135
     * @return PatternSetNameEntry
136
     */
137
    public function createExcludesFile()
138
    {
139
        return $this->fileset->createExcludesFile();
140
    }
141
142
    /**
143
     * add a set of patterns
144
     *
145
     * @return PatternSet
146
     */
147
    public function createPatternSet()
148
    {
149
        return $this->fileset->createPatternSet();
150
    }
151
152
    /**
153
     * Sets the set of include patterns. Patterns may be separated by a comma
154
     * or a space.
155
     *
156
     * @param  string $includes the string containing the include patterns
157
     * @return void
158
     */
159
    public function setIncludes($includes)
160
    {
161
        $this->fileset->setIncludes($includes);
162
    }
163
164
    /**
165
     * Sets the set of exclude patterns. Patterns may be separated by a comma
166
     * or a space.
167
     *
168
     * @param string $excludes the string containing the exclude patterns
169
     */
170
    public function setExcludes($excludes)
171
    {
172
        $this->fileset->setExcludes($excludes);
173
    }
174
175
    /**
176
     * Sets whether default exclusions should be used or not.
177
     *
178
     * @param boolean $useDefaultExcludes "true"|"on"|"yes" when default exclusions
179
     *                                    should be used, "false"|"off"|"no" when they
180
     *                                    shouldn't be used.
181
     */
182
    public function setDefaultexcludes(bool $useDefaultExcludes)
183
    {
184
        $this->useDefaultExcludes = $useDefaultExcludes;
185
    }
186
187
    /**
188
     * Returns the directory scanner needed to access the files to process.
189
     *
190
     * @param  File $baseDir
191
     * @return DirectoryScanner
192
     *@throws BuildException
193
     */
194
    protected function getDirectoryScanner(File $baseDir)
195
    {
196
        $this->fileset->setDir($baseDir);
197
        $this->fileset->setDefaultexcludes($this->useDefaultExcludes);
198
199
        return $this->fileset->getDirectoryScanner($this->project);
200
    }
201
202
    /**
203
     * Sets the name of the file containing the includes patterns.
204
     *
205
     * @param  File $includesfile A string containing the filename to fetch
206
     *                                 the include patterns from.
207
     * @return void
208
     */
209
    public function setIncludesfile(File $includesfile)
210
    {
211
        $this->fileset->setIncludesfile($includesfile);
212
    }
213
214
    /**
215
     * Sets the name of the file containing the includes patterns.
216
     *
217
     * @param  File $excludesfile A string containing the filename to fetch
218
     *                                 the include patterns from.
219
     * @return void
220
     */
221
    public function setExcludesfile(File $excludesfile)
222
    {
223
        $this->fileset->setExcludesfile($excludesfile);
224
    }
225
226
    /**
227
     * Sets case sensitivity of the file system
228
     *
229
     * @param  boolean $isCaseSensitive "true"|"on"|"yes" if file system is case
230
     *                                  sensitive, "false"|"off"|"no" when not.
231
     * @return void
232
     */
233
    public function setCaseSensitive($isCaseSensitive)
234
    {
235
        $this->fileset->setCaseSensitive($isCaseSensitive);
236
    }
237
238
    /**
239
     * Sets whether or not symbolic links should be followed.
240
     *
241
     * @param  boolean $followSymlinks whether or not symbolic links should be followed
242
     * @return void
243
     */
244
    public function setFollowSymlinks($followSymlinks)
245
    {
246
        $this->fileset->setExpandSymbolicLinks($followSymlinks);
247
    }
248
249
    /**
250
     * Indicates whether there are any selectors here.
251
     *
252
     * @return boolean Whether any selectors are in this container
253
     */
254
    public function hasSelectors()
255
    {
256
        return $this->fileset->hasSelectors();
257
    }
258
259
    /**
260
     * Gives the count of the number of selectors in this container
261
     *
262
     * @return int The number of selectors in this container
263
     */
264
    public function count()
265
    {
266
        return $this->fileset->count();
267
    }
268
269
    /**
270
     * Returns the set of selectors as an array.
271
     *
272
     * @param  Project $p
273
     * @return array FileSelector[] An array of selectors in this container
274
     */
275
    public function getSelectors(Project $p)
276
    {
277
        return $this->fileset->getSelectors($p);
278
    }
279
280
    /**
281
     * Returns an enumerator for accessing the set of selectors.
282
     *
283
     * @return array an enumerator that goes through each of the selectors
284
     */
285
    public function selectorElements()
286
    {
287
        return $this->fileset->selectorElements();
288
    }
289
290
    /**
291
     * Add a new selector into this container.
292
     *
293
     * @param  FileSelector $selector the new selector to add
294
     */
295
    public function appendSelector(FileSelector $selector)
296
    {
297
        $this->fileset->appendSelector($selector);
298
    }
299
300
    /* Methods below all add specific selectors */
301
302
    /**
303
     * add a "Select" selector entry on the selector list
304
     */
305
    public function addSelector(SelectSelector $selector)
306
    {
307
        $this->fileset->addSelector($selector);
308
    }
309
310
    /**
311
     * add an "And" selector entry on the selector list
312
     */
313
    public function addAnd(AndSelector $selector)
314
    {
315
        $this->fileset->addAnd($selector);
316
    }
317
318
    /**
319
     * add an "Or" selector entry on the selector list
320
     */
321
    public function addOr(OrSelector $selector)
322
    {
323
        $this->fileset->addOr($selector);
324
    }
325
326
    /**
327
     * add a "Not" selector entry on the selector list
328
     */
329
    public function addNot(NotSelector $selector)
330
    {
331
        $this->fileset->addNot($selector);
332
    }
333
334
    /**
335
     * add a "None" selector entry on the selector list
336
     */
337
    public function addNone(NoneSelector $selector)
338
    {
339
        $this->fileset->addNone($selector);
340
    }
341
342
    /**
343
     * add a majority selector entry on the selector list
344
     */
345
    public function addMajority(MajoritySelector $selector)
346
    {
347
        $this->fileset->addMajority($selector);
348
    }
349
350
    /**
351
     * add a selector date entry on the selector list
352
     */
353
    public function addDate(DateSelector $selector)
354
    {
355
        $this->fileset->addDate($selector);
356
    }
357
358
    /**
359
     * add a selector size entry on the selector list
360
     */
361
    public function addSize(SizeSelector $selector)
362
    {
363
        $this->fileset->addSize($selector);
364
    }
365
366
    /**
367
     * add a selector filename entry on the selector list
368
     */
369
    public function addFilename(FilenameSelector $selector)
370
    {
371
        $this->fileset->addFilename($selector);
372
    }
373
374
    /**
375
     * add an extended selector entry on the selector list
376
     */
377
    public function addCustom(ExtendSelector $selector)
378
    {
379
        $this->fileset->addCustom($selector);
380
    }
381
382
    /**
383
     * add a contains selector entry on the selector list
384
     */
385
    public function addContains(ContainsSelector $selector)
386
    {
387
        $this->fileset->addContains($selector);
388
    }
389
390
    /**
391
     * add a present selector entry on the selector list
392
     */
393
    public function addPresent(PresentSelector $selector)
394
    {
395
        $this->fileset->addPresent($selector);
396
    }
397
398
    /**
399
     * add a depth selector entry on the selector list
400
     */
401
    public function addDepth(DepthSelector $selector)
402
    {
403
        $this->fileset->addDepth($selector);
404
    }
405
406
    /**
407
     * add a depends selector entry on the selector list
408
     */
409
    public function addDepend(DependSelector $selector)
410
    {
411
        $this->fileset->addDepend($selector);
412
    }
413
414
    /**
415
     * add a executable selector entry on the selector list
416
     */
417
    public function addExecutable(ExecutableSelector $selector)
418
    {
419
        $this->fileset->addExecutable($selector);
420
    }
421
422
    /**
423
     * add a readable selector entry on the selector list
424
     */
425
    public function addReadable(ReadableSelector $selector)
426
    {
427
        $this->fileset->addReadable($selector);
428
    }
429
430
    /**
431
     * add a writable selector entry on the selector list
432
     */
433
    public function addWritable(WritableSelector $selector)
434
    {
435
        $this->fileset->addWritable($selector);
436
    }
437
438
    /**
439
     * add a different selector entry on the selector list
440
     */
441
    public function addDifferent(DifferentSelector $selector)
442
    {
443
        $this->fileset->addDifferent($selector);
444
    }
445
446
    /**
447
     * add a different selector entry on the selector list
448
     */
449
    public function addModified(ModifiedSelector $selector)
450
    {
451
        $this->fileset->addModified($selector);
452
    }
453
454
    /**
455
     * add a type selector entry on the selector list
456
     *
457
     * @param TypeSelector $selector
458
     */
459
    public function addType(TypeSelector $selector)
460
    {
461
        $this->fileset->addType($selector);
462
    }
463
464
    /**
465
     * add a contains selector entry on the selector list
466
     *
467
     * @param ContainsRegexpSelector $selector
468
     */
469
    public function addContainsRegexp(ContainsRegexpSelector $selector)
470
    {
471
        $this->fileset->addContainsRegexp($selector);
472
    }
473
474
    public function addSymlink(SymlinkSelector $selector)
475
    {
476
        $this->fileset->addSymlink($selector);
477
    }
478
479
    /**
480
     * Accessor for the implict fileset.
481
     *
482
     * @return FileSet
483
     */
484
    final protected function getImplicitFileSet()
485
    {
486
        return $this->fileset;
487
    }
488
}
489