1 18 package org.apache.tools.ant.taskdefs.optional.dotnet; 19 20 import org.apache.tools.ant.BuildException; 21 22 import java.io.File ; 23 import java.util.ArrayList ; 24 import org.apache.tools.ant.types.FileSet; 25 import java.util.Iterator ; 26 import org.apache.tools.ant.Project; 27 import org.apache.tools.ant.DirectoryScanner; 28 29 34 public class DotnetResource { 35 36 39 private File file; 40 41 44 private boolean embed = true; 45 46 49 private Boolean isPublic = null; 50 51 54 private String name = null; 55 56 59 private ArrayList fileSets = new ArrayList (); 60 61 64 private String namespace = null; 65 66 70 public boolean isEmbed() { 71 return embed; 72 } 73 74 79 public void setEmbed(boolean embed) { 80 this.embed = embed; 81 } 82 83 87 public File getFile() { 88 return file; 89 } 90 91 96 public void setFile(File file) { 97 this.file = file; 98 } 99 100 104 public Boolean getPublic() { 105 return isPublic; 106 } 107 108 113 public void setPublic(Boolean aPublic) { 114 isPublic = aPublic; 115 } 116 117 121 public String getName() { 122 return name; 123 } 124 125 130 public void setName(String name) { 131 this.name = name; 132 } 133 134 139 public String getNamespace() { 140 return namespace; 141 } 142 143 149 public void setNamespace(String namespace) { 150 if (namespace == null) { 151 this.namespace = null; 152 } else { 153 this.namespace = (namespace.length() == 0 || namespace.endsWith(".") ? namespace 154 : namespace + '.'); 155 } 156 } 157 158 private void checkParameters() { 159 if (hasFilesets()) { 160 if (getName() != null) { 161 throw new BuildException( 162 "Cannot use <resource name=\"...\"> attribute with filesets"); 163 } 164 if (getFile() != null) { 165 throw new BuildException( 166 "Cannot use <resource file=\"...\"> attribute with filesets"); 167 } 168 } else { 169 if (getNamespace() != null) { 170 throw new BuildException( 171 "Cannot use <resource namespace=\"...\"> attribute without filesets"); 172 } 173 } 174 } 175 176 182 public void getParameters(Project p, NetCommand command, boolean csharpStyle) { 183 checkParameters(); 184 if (hasFilesets()) { 185 for (Iterator listIter = fileSets.iterator(); listIter.hasNext();) { 186 FileSet fs = (FileSet) listIter.next(); 187 String baseDirectory = fs.getDir(p).toString(); 188 String namespace = getNamespace(); DirectoryScanner ds = fs.getDirectoryScanner(p); 190 String [] files = ds.getIncludedFiles(); 191 for (int i = 0; i < files.length; i++) { 192 String file = files[i]; 193 command.addArgument(getParameter(baseDirectory + File.separatorChar + file, 194 (namespace == null ? null : namespace 195 + file.replace(File.separatorChar, '.')), csharpStyle)); 196 } 197 } 198 } else { 199 command.addArgument(getParameter(getFile().toString(), getName(), csharpStyle)); 200 } 201 } 202 203 private String getParameter(String fileName, String name, boolean csharpStyle) { 204 StringBuffer buffer = new StringBuffer (); 205 buffer.append(isEmbed() ? "/resource" : "/linkresource"); 206 buffer.append(':'); 207 buffer.append(fileName); 208 if (name != null) { 209 buffer.append(','); 210 buffer.append(name); 211 if (csharpStyle) { 212 if (getPublic() != null) { 213 throw new BuildException("This compiler does not support the " 214 + "public/private option."); 215 } else { 216 if (getPublic() != null) { 217 buffer.append(','); 218 buffer.append(getPublic().booleanValue() ? "public" : "private"); 219 220 } 221 } 222 } else if (getPublic() != null) { 223 throw new BuildException("You cannot have a public or private " 224 + "option without naming the resource"); 225 } 226 } 227 return buffer.toString(); 228 } 229 230 236 public void addFileset(FileSet fileset) { 237 fileSets.add(fileset); 238 } 239 240 245 public boolean hasFilesets() { 246 return fileSets.size() > 0; 247 } 248 } 249 | Popular Tags |