[15023] | 1 | package ise.antelope.tasks;
|
---|
| 2 |
|
---|
| 3 | import ise.antelope.tasks.typedefs.file.*;
|
---|
| 4 |
|
---|
| 5 | import java.io.File;
|
---|
| 6 | import java.util.*;
|
---|
| 7 | import org.apache.tools.ant.BuildException;
|
---|
| 8 |
|
---|
| 9 | import org.apache.tools.ant.Task;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * A task to answer a bunch of questions about a file or directory.
|
---|
| 13 | *
|
---|
| 14 | * Copyright 2003
|
---|
| 15 | *
|
---|
| 16 | * @version $Revision: 1.3 $
|
---|
| 17 | */
|
---|
| 18 | public class FileUtilTask extends Task {
|
---|
| 19 |
|
---|
| 20 | private File file = null;
|
---|
| 21 |
|
---|
| 22 | private String property = null;
|
---|
| 23 |
|
---|
| 24 | private Vector ops = new Vector();
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * @param f the file in question
|
---|
| 28 | */
|
---|
| 29 | public void setFile(File f) {
|
---|
| 30 | file = f;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @param name where to put the answer
|
---|
| 35 | */
|
---|
| 36 | public void setProperty(String name) {
|
---|
| 37 | property = name;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public void addFileop(FileOp op) {
|
---|
| 41 | ops.add(op);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * Is the file readable?
|
---|
| 46 | */
|
---|
| 47 | public void addCanread(CanRead op) {
|
---|
| 48 | ops.add(op);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * Is the file writable?
|
---|
| 53 | */
|
---|
| 54 | public void addCanwrite(CanWrite op) {
|
---|
| 55 | ops.add(op);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | /**
|
---|
| 59 | * How many files are in the directory?
|
---|
| 60 | */
|
---|
| 61 | public void addFilecount(FileCount op) {
|
---|
| 62 | ops.add(op);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | /**
|
---|
| 66 | * Is the file a directory?
|
---|
| 67 | */
|
---|
| 68 | public void addIsdirectory(IsDirectory op) {
|
---|
| 69 | ops.add(op);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /**
|
---|
| 73 | * Is the file a file?
|
---|
| 74 | */
|
---|
| 75 | public void addIsfile(IsFile op) {
|
---|
| 76 | ops.add(op);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | /**
|
---|
| 80 | * Is the file hidden?
|
---|
| 81 | */
|
---|
| 82 | public void addIshidden(IsHidden op) {
|
---|
| 83 | ops.add(op);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /**
|
---|
| 87 | * What is the length of the file?
|
---|
| 88 | */
|
---|
| 89 | public void addFilelength(FileLength op) {
|
---|
| 90 | ops.add(op);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | /**
|
---|
| 94 | * When was the file last modified?
|
---|
| 95 | */
|
---|
| 96 | public void addLastmodified(LastModified op) {
|
---|
| 97 | ops.add(op);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | /**
|
---|
| 101 | * What files are in the directory?
|
---|
| 102 | */
|
---|
| 103 | public void addListFiles(FileList op) {
|
---|
| 104 | ops.add(op);
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * How many lines are in the file?
|
---|
| 109 | */
|
---|
| 110 | public void addLineCount(FileLineCount op) {
|
---|
| 111 | ops.add(op);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | /** While multiple ops could be added, only the first one is executed. */
|
---|
| 115 | public void execute() {
|
---|
| 116 | if (file == null)
|
---|
| 117 | return;
|
---|
| 118 | if (ops.size() == 0)
|
---|
| 119 | return;
|
---|
| 120 | FileOp op = (FileOp)ops.get(0);
|
---|
| 121 | String value = op.execute(file);
|
---|
| 122 | if (property != null) {
|
---|
| 123 | Unset unset = new Unset();
|
---|
| 124 | unset.setProject(getProject());
|
---|
| 125 | unset.setName(property);
|
---|
| 126 | unset.execute();
|
---|
| 127 | getProject().setProperty(property, value);
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | }
|
---|
| 132 |
|
---|