1 18 23 24 package org.apache.tools.ant.taskdefs.optional.dotnet; 25 26 27 import java.io.File ; 28 import java.util.Vector ; 29 30 import org.apache.tools.ant.BuildException; 31 import org.apache.tools.ant.Project; 32 import org.apache.tools.ant.taskdefs.condition.Os; 33 import org.apache.tools.ant.types.EnumeratedAttribute; 34 import org.apache.tools.ant.types.FileSet; 35 36 60 61 public class Ilasm 62 extends DotnetBaseMatchingTask { 63 64 70 protected static final String exe_name = "ilasm"; 71 72 75 protected static final String file_ext = "il"; 76 77 80 protected static final String file_pattern = "**/*." + file_ext; 81 82 85 protected static final String exe_title = "ilasm"; 86 87 93 protected String targetType; 94 95 98 protected boolean verbose; 99 100 103 104 protected boolean listing; 105 106 109 protected File resourceFile; 110 111 114 protected boolean failOnError; 115 116 119 protected boolean debug; 120 121 124 125 private File keyfile; 126 127 130 protected String extraOptions; 131 132 135 protected Vector referenceFilesets = new Vector (); 136 137 140 143 private boolean isMono = !Os.isFamily("windows"); 144 145 148 public Ilasm() { 149 Clear(); 150 setIncludes(file_pattern); 151 } 152 153 157 public void Clear() { 158 targetType = null; 159 srcDir = null; 160 listing = false; 161 verbose = false; 162 debug = true; 163 outputFile = null; 164 failOnError = true; 165 resourceFile = null; 166 extraOptions = null; 167 } 168 170 171 172 179 public void setTargetType(String targetType) 180 throws BuildException { 181 this.targetType = targetType.toLowerCase(); 182 if (!targetType.equals("exe") && !targetType.equals("library")) { 183 throw new BuildException("targetType " + targetType + " is not a valid type"); 184 } 185 } 186 187 188 193 public String getTargetType() { 194 return targetType; 195 } 196 197 198 203 204 protected String getTargetTypeParameter() { 205 if (!notEmpty(targetType)) { 206 return null; 207 } 208 if (targetType.equals("exe")) { 209 return "/exe"; 210 } else if (targetType.equals("library")) { 211 return "/dll"; 212 } else { 213 return null; 214 } 215 } 216 217 218 224 public void setOwner(String s) { 225 log("This option is not supported by ILASM as of Beta-2, " 226 + "and will be ignored", Project.MSG_WARN); 227 } 228 229 230 236 protected boolean notEmpty(String s) { 237 return s != null && s.length() != 0; 238 } 239 240 241 246 public void setVerbose(boolean b) { 247 verbose = b; 248 } 249 250 251 256 protected String getVerboseParameter() { 257 return verbose ? null : "/quiet"; 258 } 259 260 261 266 public void setListing(boolean b) { 267 listing = b; 268 } 269 270 271 276 protected String getListingParameter() { 277 if (!isMono) { 278 return listing ? "/listing" : "/nolisting"; 279 } 280 return null; 281 } 282 283 284 289 public void setOutputFile(File params) { 290 outputFile = params; 291 } 292 293 294 299 protected String getOutputFileParameter() { 300 if (outputFile == null) { 301 return null; 302 } 303 return "/output=" + outputFile.toString(); 304 } 305 306 307 312 public void setResourceFile(File fileName) { 313 resourceFile = fileName; 314 } 315 316 317 322 protected String getResourceFileParameter() { 323 if (resourceFile != null) { 324 return "/resource=" + resourceFile.toString(); 325 } else { 326 return null; 327 } 328 } 329 330 331 336 public void setFailOnError(boolean b) { 337 failOnError = b; 338 } 339 340 341 346 public boolean getFailOnError() { 347 return failOnError; 348 } 349 350 351 356 public void setDebug(boolean f) { 357 debug = f; 358 } 359 360 361 366 public boolean getDebug() { 367 return debug; 368 } 369 370 371 376 protected String getDebugParameter() { 377 return debug ? "/debug" : null; 378 } 379 380 381 386 public void setKeyfile(File keyfile) { 387 this.keyfile = keyfile; 388 } 389 390 391 396 protected String getKeyfileParameter() { 397 if (keyfile != null) { 398 return "/keyfile:" + keyfile.toString(); 399 } else { 400 return null; 401 } 402 } 403 404 405 411 public void setExtraOptions(String extraOptions) { 412 this.extraOptions = extraOptions; 413 } 414 415 416 421 public String getExtraOptions() { 422 return this.extraOptions; 423 } 424 425 426 431 protected String getExtraOptionsParameter() { 432 if (extraOptions != null && extraOptions.length() != 0) { 433 return extraOptions; 434 } else { 435 return null; 436 } 437 } 438 439 443 public void setTargetType(TargetTypes targetType) { 444 this.targetType = targetType.getValue(); 445 } 446 447 454 public void setMono(boolean b) { 455 isMono = b; 456 } 457 458 464 public void execute() 465 throws BuildException { 466 log("This task is deprecated and will be removed in a future version\n" 467 + "of Ant. It is now part of the .NET Antlib:\n" 468 + "http://ant.apache.org/antlibs/dotnet/index.html", 469 Project.MSG_WARN); 470 NetCommand command = buildIlasmCommand(); 471 472 addFilesAndExecute(command, false); 473 474 } 475 477 478 482 private NetCommand buildIlasmCommand() { 483 NetCommand command = new NetCommand(this, exe_title, exe_name); 484 command.setFailOnError(getFailOnError()); 485 command.addArgument(getDebugParameter()); 487 command.addArgument(getTargetTypeParameter()); 488 command.addArgument(getListingParameter()); 489 command.addArgument(getOutputFileParameter()); 490 command.addArgument(getResourceFileParameter()); 491 command.addArgument(getVerboseParameter()); 492 command.addArgument(getKeyfileParameter()); 493 command.addArgument(getExtraOptionsParameter()); 494 495 500 return command; 501 } 502 503 507 public void addReference(FileSet reference) { 508 referenceFilesets.add(reference); 509 } 510 511 518 protected static boolean isFileManagedBinary(File file) { 519 String filename = file.toString().toLowerCase(); 520 return filename.endsWith(".exe") || filename.endsWith(".dll") 521 || filename.endsWith(".netmodule"); 522 } 523 524 525 529 public static class TargetTypes extends EnumeratedAttribute { 530 531 public String [] getValues() { 532 return new String []{ 533 "exe", 534 "library", 535 }; 536 } 537 } 538 539 } 540 541 | Popular Tags |