1 18 19 package org.apache.tools.ant.taskdefs.optional.windows; 20 21 import org.apache.tools.ant.BuildException; 22 import org.apache.tools.ant.taskdefs.ExecuteOn; 23 import org.apache.tools.ant.taskdefs.condition.Os; 24 import org.apache.tools.ant.types.FileSet; 25 26 import java.io.File ; 27 28 34 public class Attrib extends ExecuteOn { 35 36 private static final String ATTR_READONLY = "R"; 37 private static final String ATTR_ARCHIVE = "A"; 38 private static final String ATTR_SYSTEM = "S"; 39 private static final String ATTR_HIDDEN = "H"; 40 private static final String SET = "+"; 41 private static final String UNSET = "-"; 42 43 private boolean haveAttr = false; 44 45 46 public Attrib() { 47 super.setExecutable("attrib"); 48 super.setParallel(false); 49 } 50 51 55 public void setFile(File src) { 56 FileSet fs = new FileSet(); 57 fs.setFile(src); 58 addFileset(fs); 59 } 60 61 65 public void setReadonly(boolean value) { 66 addArg(value, ATTR_READONLY); 67 } 68 69 73 public void setArchive(boolean value) { 74 addArg(value, ATTR_ARCHIVE); 75 } 76 77 81 public void setSystem(boolean value) { 82 addArg(value, ATTR_SYSTEM); 83 } 84 85 89 public void setHidden(boolean value) { 90 addArg(value, ATTR_HIDDEN); 91 } 92 93 96 protected void checkConfiguration() { 97 if (!haveAttr()) { 98 throw new BuildException("Missing attribute parameter", 99 getLocation()); 100 } 101 super.checkConfiguration(); 102 } 103 104 110 public void setExecutable(String e) { 111 throw new BuildException(getTaskType() 112 + " doesn\'t support the executable attribute", getLocation()); 113 } 114 115 121 public void setCommand(String e) { 122 throw new BuildException(getTaskType() 123 + " doesn\'t support the command attribute", getLocation()); 124 } 125 126 132 public void setAddsourcefile(boolean b) { 133 throw new BuildException(getTaskType() 134 + " doesn\'t support the addsourcefile attribute", getLocation()); 135 } 136 137 143 public void setSkipEmptyFilesets(boolean skip) { 144 throw new BuildException(getTaskType() + " doesn\'t support the " 145 + "skipemptyfileset attribute", 146 getLocation()); 147 } 148 149 155 public void setParallel(boolean parallel) { 156 throw new BuildException(getTaskType() 157 + " doesn\'t support the parallel attribute", 158 getLocation()); 159 } 160 161 167 public void setMaxParallel(int max) { 168 throw new BuildException(getTaskType() 169 + " doesn\'t support the maxparallel attribute", 170 getLocation()); 171 } 172 173 178 protected boolean isValidOs() { 179 return Os.isFamily("windows") && super.isValidOs(); 180 } 181 182 private static String getSignString(boolean attr) { 183 return (attr ? SET : UNSET); 184 } 185 186 private void addArg(boolean sign, String attribute) { 187 createArg().setValue(getSignString(sign) + attribute); 188 haveAttr = true; 189 } 190 191 private boolean haveAttr() { 192 return haveAttr; 193 } 194 195 } 196 | Popular Tags |