158 pred: JFile => Boolean = _ => true, |
158 pred: JFile => Boolean = _ => true, |
159 include_dirs: Boolean = false, |
159 include_dirs: Boolean = false, |
160 follow_links: Boolean = false): List[JFile] = |
160 follow_links: Boolean = false): List[JFile] = |
161 { |
161 { |
162 val result = new mutable.ListBuffer[JFile] |
162 val result = new mutable.ListBuffer[JFile] |
163 def check(file: JFile) { if (pred(file)) result += file } |
163 def check(file: JFile): Unit = if (pred(file)) result += file |
164 |
164 |
165 if (start.isFile) check(start) |
165 if (start.isFile) check(start) |
166 else if (start.isDirectory) { |
166 else if (start.isDirectory) { |
167 val options = |
167 val options = |
168 if (follow_links) EnumSet.of(FileVisitOption.FOLLOW_LINKS) |
168 if (follow_links) EnumSet.of(FileVisitOption.FOLLOW_LINKS) |
241 /* write */ |
241 /* write */ |
242 |
242 |
243 def writer(file: JFile): BufferedWriter = |
243 def writer(file: JFile): BufferedWriter = |
244 new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), UTF8.charset)) |
244 new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), UTF8.charset)) |
245 |
245 |
246 def write_file(file: JFile, text: CharSequence, make_stream: OutputStream => OutputStream) |
246 def write_file( |
|
247 file: JFile, text: CharSequence, make_stream: OutputStream => OutputStream): Unit = |
247 { |
248 { |
248 val stream = make_stream(new FileOutputStream(file)) |
249 val stream = make_stream(new FileOutputStream(file)) |
249 using(new BufferedWriter(new OutputStreamWriter(stream, UTF8.charset)))(_.append(text)) |
250 using(new BufferedWriter(new OutputStreamWriter(stream, UTF8.charset)))(_.append(text)) |
250 } |
251 } |
251 |
252 |
261 def write_xz(file: JFile, text: CharSequence): Unit = write_xz(file, text, XZ.options()) |
262 def write_xz(file: JFile, text: CharSequence): Unit = write_xz(file, text, XZ.options()) |
262 def write_xz(path: Path, text: CharSequence, options: XZ.Options): Unit = |
263 def write_xz(path: Path, text: CharSequence, options: XZ.Options): Unit = |
263 write_xz(path.file, text, options) |
264 write_xz(path.file, text, options) |
264 def write_xz(path: Path, text: CharSequence): Unit = write_xz(path, text, XZ.options()) |
265 def write_xz(path: Path, text: CharSequence): Unit = write_xz(path, text, XZ.options()) |
265 |
266 |
266 def write_backup(path: Path, text: CharSequence) |
267 def write_backup(path: Path, text: CharSequence): Unit = |
267 { |
268 { |
268 if (path.is_file) Isabelle_System.move_file(path, path.backup) |
269 if (path.is_file) Isabelle_System.move_file(path, path.backup) |
269 write(path, text) |
270 write(path, text) |
270 } |
271 } |
271 |
272 |
272 def write_backup2(path: Path, text: CharSequence) |
273 def write_backup2(path: Path, text: CharSequence): Unit = |
273 { |
274 { |
274 if (path.is_file) Isabelle_System.move_file(path, path.backup2) |
275 if (path.is_file) Isabelle_System.move_file(path, path.backup2) |
275 write(path, text) |
276 write(path, text) |
276 } |
277 } |
277 |
278 |
316 { |
317 { |
317 if (Platform.is_windows) Isabelle_System.bash("test -x " + bash_path(path)).check.ok |
318 if (Platform.is_windows) Isabelle_System.bash("test -x " + bash_path(path)).check.ok |
318 else path.file.canExecute |
319 else path.file.canExecute |
319 } |
320 } |
320 |
321 |
321 def set_executable(path: Path, flag: Boolean) |
322 def set_executable(path: Path, flag: Boolean): Unit = |
322 { |
323 { |
323 if (Platform.is_windows && flag) Isabelle_System.chmod("a+x", path) |
324 if (Platform.is_windows && flag) Isabelle_System.chmod("a+x", path) |
324 else if (Platform.is_windows) Isabelle_System.chmod("a-x", path) |
325 else if (Platform.is_windows) Isabelle_System.chmod("a-x", path) |
325 else path.file.setExecutable(flag, false) |
326 else path.file.setExecutable(flag, false) |
326 } |
327 } |