|
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
|
|
|
* Changes the attributes of a file or all files inside specified directories. |
|
22
|
|
|
* Right now it has effect only under Windows. Each of the 4 possible |
|
23
|
|
|
* permissions has its own attribute, matching the arguments for the `attrib` |
|
24
|
|
|
* command. |
|
25
|
|
|
* |
|
26
|
|
|
* Example: |
|
27
|
|
|
* ``` |
|
28
|
|
|
* <attrib file="${input}" readonly="true" hidden="true" verbose="true"/> |
|
29
|
|
|
* ``` |
|
30
|
|
|
* |
|
31
|
|
|
* @author Siad Ardroumli <[email protected]> |
|
32
|
|
|
* @package phing.tasks.system |
|
33
|
|
|
*/ |
|
34
|
|
|
class AttribTask extends ApplyTask |
|
35
|
|
|
{ |
|
36
|
|
|
private static $ATTR_READONLY = 'R'; |
|
37
|
|
|
private static $ATTR_ARCHIVE = 'A'; |
|
38
|
|
|
private static $ATTR_SYSTEM = 'S'; |
|
39
|
|
|
private static $ATTR_HIDDEN = 'H'; |
|
40
|
|
|
private static $SET = '+'; |
|
41
|
|
|
private static $UNSET = '-'; |
|
42
|
|
|
|
|
43
|
|
|
private $attr = false; |
|
44
|
|
|
|
|
45
|
|
|
public function init() |
|
46
|
|
|
{ |
|
47
|
|
|
parent::init(); |
|
48
|
|
|
parent::setExecutable('attrib'); |
|
49
|
|
|
parent::setParallel(false); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @throws BuildException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function main() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->checkConfiguration(); |
|
58
|
|
|
parent::main(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param bool $b |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setVerbose($b) |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
$this->loglevel = Project::MSG_VERBOSE; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* A file to be attribed. |
|
71
|
|
|
* |
|
72
|
|
|
* @param PhingFile $src a file |
|
73
|
|
|
*/ |
|
74
|
|
|
public function setFile(PhingFile $src) |
|
75
|
|
|
{ |
|
76
|
|
|
$fs = new FileSet(); |
|
77
|
|
|
$fs->setFile($src); |
|
78
|
|
|
$this->addFileSet($fs); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Set the ReadOnly file attribute. |
|
83
|
|
|
* |
|
84
|
|
|
* @param boolean $value |
|
85
|
|
|
*/ |
|
86
|
|
|
public function setReadonly($value) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->addArg($value, self::$ATTR_READONLY); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Set the Archive file attribute. |
|
93
|
|
|
* |
|
94
|
|
|
* @param boolean $value |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setArchive($value) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->addArg($value, self::$ATTR_ARCHIVE); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Set the System file attribute. |
|
103
|
|
|
* |
|
104
|
|
|
* @param boolean $value |
|
105
|
|
|
*/ |
|
106
|
|
|
public function setSystem($value) |
|
107
|
|
|
{ |
|
108
|
|
|
$this->addArg($value, self::$ATTR_SYSTEM); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Set the Hidden file attribute. |
|
113
|
|
|
* |
|
114
|
|
|
* @param boolean $value |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setHidden($value) |
|
117
|
|
|
{ |
|
118
|
|
|
$this->addArg($value, self::$ATTR_HIDDEN); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Check the attributes. |
|
123
|
|
|
* |
|
124
|
|
|
* @throws BuildException |
|
125
|
|
|
*/ |
|
126
|
|
|
protected function checkConfiguration() |
|
127
|
|
|
{ |
|
128
|
|
|
if (!$this->hasAttr()) { |
|
129
|
|
|
throw new BuildException( |
|
130
|
|
|
'Missing attribute parameter', |
|
131
|
|
|
$this->getLocation() |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Set the executable. |
|
138
|
|
|
* This is not allowed, and it always throws a BuildException. |
|
139
|
|
|
* |
|
140
|
|
|
* @param mixed $e |
|
141
|
|
|
* @throws BuildException |
|
142
|
|
|
*/ |
|
143
|
|
|
public function setExecutable($e): void |
|
144
|
|
|
{ |
|
145
|
|
|
throw new BuildException( |
|
146
|
|
|
$this->getTaskType() . ' doesn\'t support the executable attribute', |
|
147
|
|
|
$this->getLocation() |
|
148
|
|
|
); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Add source file. |
|
153
|
|
|
* This is not allowed, and it always throws a BuildException. |
|
154
|
|
|
* |
|
155
|
|
|
* @param boolean $b ignored |
|
156
|
|
|
* @throws BuildException |
|
157
|
|
|
*/ |
|
158
|
|
|
public function setAddsourcefile(bool $b) |
|
159
|
|
|
{ |
|
160
|
|
|
throw new BuildException( |
|
161
|
|
|
$this->getTaskType() |
|
162
|
|
|
. ' doesn\'t support the addsourcefile attribute', |
|
163
|
|
|
$this->getLocation() |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Set max parallel. |
|
169
|
|
|
* This is not allowed, and it always throws a BuildException. |
|
170
|
|
|
* |
|
171
|
|
|
* @param int $max ignored |
|
172
|
|
|
* @throws BuildException |
|
173
|
|
|
*/ |
|
174
|
|
|
public function setMaxParallel($max) |
|
175
|
|
|
{ |
|
176
|
|
|
throw new BuildException( |
|
177
|
|
|
$this->getTaskType() |
|
178
|
|
|
. ' doesn\'t support the maxparallel attribute', |
|
179
|
|
|
$this->getLocation() |
|
180
|
|
|
); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Set parallel. |
|
185
|
|
|
* This is not allowed, and it always throws a BuildException. |
|
186
|
|
|
* |
|
187
|
|
|
* @param boolean $parallel ignored |
|
188
|
|
|
* @throws BuildException |
|
189
|
|
|
*/ |
|
190
|
|
|
public function setParallel(bool $parallel) |
|
191
|
|
|
{ |
|
192
|
|
|
throw new BuildException( |
|
193
|
|
|
$this->getTaskType() |
|
194
|
|
|
. ' doesn\'t support the parallel attribute', |
|
195
|
|
|
$this->getLocation() |
|
196
|
|
|
); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
private static function getSignString($attr) |
|
200
|
|
|
{ |
|
201
|
|
|
return ($attr ? self::$SET : self::$UNSET); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
private function addArg($sign, $attribute) |
|
205
|
|
|
{ |
|
206
|
|
|
$this->createArg()->setValue(self::getSignString($sign) . $attribute); |
|
207
|
|
|
$this->attr = true; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @return bool |
|
212
|
|
|
*/ |
|
213
|
|
|
private function hasAttr() |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->attr; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.