View Javadoc
1 /* 2 ContractChecker 3 4 Copyright (C) 2003 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the GPL license. 23 Contact info: jsr000@terra.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 ****************************************************************************** 31 * 32 * Filename: $RCSfile: ContractCheckerTask.java,v $ 33 * 34 * Author: Jose San Leandro Armend?riz 35 * 36 * Description: Generates ContractChecker aspects and weaves them using Ant. 37 * 38 * Last modified by: $Author: chous $ at $Date: 2004/02/06 07:23:19 $ 39 * 40 * File version: $Revision: 1.8 $ 41 * 42 * Project version: $Name: $ 43 * 44 * $Id: ContractCheckerTask.java,v 1.8 2004/02/06 07:23:19 chous Exp $ 45 * 46 */ 47 package org.acmsl.contractchecker; 48 49 /* 50 * Importing some Ant classes. 51 */ 52 import org.apache.tools.ant.BuildException; 53 import org.apache.tools.ant.Project; 54 import org.apache.tools.ant.taskdefs.Javadoc; 55 import org.apache.tools.ant.taskdefs.MatchingTask; 56 import org.apache.tools.ant.types.Path; 57 import org.apache.tools.ant.types.Reference; 58 59 /* 60 * Importing some AspectJ classes. 61 */ 62 import org.aspectj.tools.ant.taskdefs.AjcTask; 63 64 /* 65 * Importing some JDK classes. 66 */ 67 import java.io.File; 68 import java.io.IOException; 69 70 /*** 71 * Generates ContractChecker aspects and weaves them using Ant. 72 * @author <a href="mailto:jsanleandro@yahoo.es" 73 >Jose San Leandro</a> 74 * @version $Revision: 1.8 $ 75 */ 76 public class ContractCheckerTask 77 extends MatchingTask 78 { 79 /*** 80 * Delegated AJC task. 81 */ 82 private AjcTask m__AjcTask; 83 84 /*** 85 * The output folder for generated aspects (optional). 86 */ 87 private File m__AspectOutput; 88 89 /*** 90 * The template factory class name (optional). 91 */ 92 private String m__strTemplateFactoryClass; 93 94 /*** 95 * The AjcTask sourceroots copy (since it's private with no 96 * getter methods); 97 */ 98 private Path m__SourceRoots; 99 100 /*** 101 * The AjcTask classpath copy (since it's private with no 102 * getter methods); 103 */ 104 private Path m__Classpath; 105 106 /*** 107 * The contract violation exception. 108 */ 109 private String m__strViolationException; 110 111 /*** 112 * Creates a ContractCheckerTask. 113 */ 114 public ContractCheckerTask() {}; 115 116 /*** 117 * Specifies the AjcTask. 118 * @param task the task. 119 */ 120 protected void setAjcTask(AjcTask task) 121 { 122 m__AjcTask = task; 123 } 124 125 /*** 126 * Retrieves the AjcTask. 127 * @return such task. 128 */ 129 protected AjcTask getAjcTask() 130 { 131 AjcTask result = m__AjcTask; 132 133 if (result == null) 134 { 135 result = new AjcTask(); 136 result.setProject(getProject()); 137 result.setDescription(getDescription()); 138 139 setAjcTask(result); 140 } 141 142 return result; 143 } 144 145 /*** 146 * Specifies the output folder for the generated aspects. 147 * @param aspectOutput such folder. 148 */ 149 public void setAspectoutput(File aspectOutput) 150 { 151 m__AspectOutput = aspectOutput; 152 } 153 154 /*** 155 * Retrieves the output folder for the generated aspects. 156 * @return such folder. 157 */ 158 public File getAspectoutput() 159 { 160 return m__AspectOutput; 161 } 162 163 /*** 164 * Defines the output folder for classes, using the operating system 165 * temporary folder. 166 * @return the new folder. 167 * @throws IOException if the temporary folder could not be created. 168 */ 169 protected File getTempBasedAspectOutput() 170 throws IOException 171 { 172 File result = File.createTempFile("contractchecker", "_aspects"); 173 174 String t_strPath = result.getAbsolutePath(); 175 176 result.delete(); 177 178 result = new File(t_strPath); 179 180 result.mkdirs(); 181 182 result.mkdir(); 183 184 return result; 185 } 186 187 /*** 188 * Specifies the template factory class. 189 * @param factoryClass the new template factory class. 190 */ 191 public void setTemplatefactoryclass(String factoryClass) 192 { 193 m__strTemplateFactoryClass = factoryClass; 194 } 195 196 /*** 197 * Retrieves the template factory class. 198 * @return such class. 199 */ 200 public String getTemplatefactoryclass() 201 { 202 return m__strTemplateFactoryClass; 203 } 204 205 /*** 206 * Specifies the contract violation exception. 207 * @param exception such exception. 208 */ 209 public void setViolationexception(String exception) 210 { 211 m__strViolationException = exception; 212 } 213 214 /*** 215 * Retrieves the contract violation exception. 216 * @return such exception. 217 */ 218 public String getViolationexception() 219 { 220 return m__strViolationException; 221 } 222 223 // <AjcTask delegation methods> // 224 225 /*** 226 * Specifies the incremental behaviour. 227 * @param incremental such behaviour. 228 */ 229 public void setIncremental(boolean incremental) 230 { 231 AjcTask t_AjcTask = getAjcTask(); 232 233 if (t_AjcTask != null) 234 { 235 t_AjcTask.setIncremental(incremental); 236 } 237 } 238 239 /*** 240 * Specifies the help flag. 241 * @param help such flag. 242 */ 243 public void setHelp(boolean help) 244 { 245 AjcTask t_AjcTask = getAjcTask(); 246 247 if (t_AjcTask != null) 248 { 249 t_AjcTask.setHelp(help); 250 } 251 } 252 253 /*** 254 * Specifies the version flag. 255 * @param version such flag. 256 */ 257 public void setVersion(boolean version) 258 { 259 AjcTask t_AjcTask = getAjcTask(); 260 261 if (t_AjcTask != null) 262 { 263 t_AjcTask.setHelp(version); 264 } 265 } 266 267 /*** 268 * Specifies the xnoweave flag. 269 * @param noweave such flag. 270 */ 271 public void setXNoweave(boolean noweave) 272 { 273 AjcTask t_AjcTask = getAjcTask(); 274 275 if (t_AjcTask != null) 276 { 277 t_AjcTask.setXNoweave(noweave); 278 } 279 } 280 281 /*** 282 * Specifies the nowarn flag. 283 * @param nowarn such flag. 284 */ 285 public void setNowarn(boolean nowarn) 286 { 287 AjcTask t_AjcTask = getAjcTask(); 288 289 if (t_AjcTask != null) 290 { 291 t_AjcTask.setNowarn(nowarn); 292 } 293 } 294 295 /*** 296 * Specifies the deprecation flag. 297 * @param deprecation such flag. 298 */ 299 public void setDeprecation(boolean deprecation) 300 { 301 AjcTask t_AjcTask = getAjcTask(); 302 303 if (t_AjcTask != null) 304 { 305 t_AjcTask.setDeprecation(deprecation); 306 } 307 } 308 309 /*** 310 * Specifies the warnings. 311 * @param warnings the list of warnings. 312 */ 313 public void setWarn(String warnings) 314 { 315 AjcTask t_AjcTask = getAjcTask(); 316 317 if (t_AjcTask != null) 318 { 319 t_AjcTask.setWarn(warnings); 320 } 321 } 322 323 /*** 324 * Specifies the debug flag. 325 * @param debug such flag. 326 */ 327 public void setDebug(boolean debug) 328 { 329 AjcTask t_AjcTask = getAjcTask(); 330 331 if (t_AjcTask != null) 332 { 333 t_AjcTask.setDebug(debug); 334 } 335 } 336 337 /*** 338 * Specifies the debug level. 339 * @param level such level. 340 */ 341 public void setDebugLevel(String level) 342 { 343 AjcTask t_AjcTask = getAjcTask(); 344 345 if (t_AjcTask != null) 346 { 347 t_AjcTask.setDebugLevel(level); 348 } 349 } 350 351 /*** 352 * Specifies the emacssym flag. 353 * @param emacssym such flag. 354 */ 355 public void setEmacssym(boolean emacssym) 356 { 357 AjcTask t_AjcTask = getAjcTask(); 358 359 if (t_AjcTask != null) 360 { 361 t_AjcTask.setEmacssym(emacssym); 362 } 363 } 364 365 /*** 366 * Specifies the Xlint warnings. 367 * @param xlintwarninings such information. 368 */ 369 public void setXlintwarnings(boolean xlintwarnings) 370 { 371 AjcTask t_AjcTask = getAjcTask(); 372 373 if (t_AjcTask != null) 374 { 375 t_AjcTask.setXlintwarnings(xlintwarnings); 376 } 377 } 378 379 /*** 380 * Specifies the Xlint value. 381 * @param xlint such value. 382 */ 383 public void setXlint(String xlint) 384 { 385 AjcTask t_AjcTask = getAjcTask(); 386 387 if (t_AjcTask != null) 388 { 389 t_AjcTask.setXlint(xlint); 390 } 391 } 392 393 /*** 394 * Specifies the xlint file. 395 * @param xlintFile such file. 396 */ 397 public void setXlintfile(File xlintFile) 398 { 399 AjcTask t_AjcTask = getAjcTask(); 400 401 if (t_AjcTask != null) 402 { 403 t_AjcTask.setXlintfile(xlintFile); 404 } 405 } 406 407 /*** 408 * Specifies the preserve-all-locals flag. 409 * @param preserveAllLocals such flag. 410 */ 411 public void setPreserveAllLocals(boolean preserveAllLocals) 412 { 413 AjcTask t_AjcTask = getAjcTask(); 414 415 if (t_AjcTask != null) 416 { 417 t_AjcTask.setPreserveAllLocals(preserveAllLocals); 418 } 419 } 420 421 /*** 422 * Specifies the no-import-error flag. 423 * @param noImportError such flag. 424 */ 425 public void setNoImportError(boolean noImportError) 426 { 427 AjcTask t_AjcTask = getAjcTask(); 428 429 if (t_AjcTask != null) 430 { 431 t_AjcTask.setNoImportError(noImportError); 432 } 433 } 434 435 /*** 436 * Specifies the encoding. 437 * @param encoding such value. 438 */ 439 public void setEncoding(String encoding) 440 { 441 AjcTask t_AjcTask = getAjcTask(); 442 443 if (t_AjcTask != null) 444 { 445 t_AjcTask.setEncoding(encoding); 446 } 447 } 448 449 /*** 450 * Specifies the log file. 451 * @param file such file. 452 */ 453 public void setLog(File file) 454 { 455 AjcTask t_AjcTask = getAjcTask(); 456 457 if (t_AjcTask != null) 458 { 459 t_AjcTask.setLog(file); 460 } 461 } 462 463 /*** 464 * Specifies the proceed-on-error flag. 465 * @param proceedOnError such flag. 466 */ 467 public void setProceedOnError(boolean proceedOnError) 468 { 469 AjcTask t_AjcTask = getAjcTask(); 470 471 if (t_AjcTask != null) 472 { 473 t_AjcTask.setProceedOnError(proceedOnError); 474 } 475 } 476 477 /*** 478 * Specifies the verbose flag. 479 * @param verbose such flag. 480 */ 481 public void setVerbose(boolean verbose) 482 { 483 AjcTask t_AjcTask = getAjcTask(); 484 485 if (t_AjcTask != null) 486 { 487 t_AjcTask.setVerbose(verbose); 488 } 489 } 490 491 /*** 492 * Specifies the list-file-args flag. 493 * @param listFileArgs such flag. 494 */ 495 public void setListFileArgs(boolean listFileArgs) 496 { 497 AjcTask t_AjcTask = getAjcTask(); 498 499 if (t_AjcTask != null) 500 { 501 t_AjcTask.setListFileArgs(listFileArgs); 502 } 503 } 504 505 /*** 506 * Specifies the reference info. 507 * @param referenceInfo such value. 508 */ 509 public void setReferenceInfo(boolean referenceInfo) 510 { 511 AjcTask t_AjcTask = getAjcTask(); 512 513 if (t_AjcTask != null) 514 { 515 t_AjcTask.setReferenceInfo(referenceInfo); 516 } 517 } 518 519 /*** 520 * Specifies the progress. 521 * @param progress such value. 522 */ 523 public void setProgress(boolean progress) 524 { 525 AjcTask t_AjcTask = getAjcTask(); 526 527 if (t_AjcTask != null) 528 { 529 t_AjcTask.setProgress(progress); 530 } 531 } 532 533 /*** 534 * Specifies the time flag. 535 * @param time such value. 536 */ 537 public void setTime(boolean time) 538 { 539 AjcTask t_AjcTask = getAjcTask(); 540 541 if (t_AjcTask != null) 542 { 543 t_AjcTask.setTime(time); 544 } 545 } 546 547 /*** 548 * Specifies the no-exit flag. 549 * @param noExit such flag. 550 */ 551 public void setNoExit(boolean noExit) 552 { 553 AjcTask t_AjcTask = getAjcTask(); 554 555 if (t_AjcTask != null) 556 { 557 t_AjcTask.setNoExit(noExit); 558 } 559 } 560 561 /*** 562 * Specifies the fail-on-error flag. 563 * @param failOnError such flag. 564 */ 565 public void setFailonerror(boolean failOnError) 566 { 567 AjcTask t_AjcTask = getAjcTask(); 568 569 if (t_AjcTask != null) 570 { 571 t_AjcTask.setFailonerror(failOnError); 572 } 573 } 574 575 /*** 576 * Specifies the fork setting. 577 * @param fork such setting. 578 */ 579 public void setFork(boolean fork) 580 { 581 AjcTask t_AjcTask = getAjcTask(); 582 583 if (t_AjcTask != null) 584 { 585 t_AjcTask.setFork(fork); 586 } 587 } 588 589 /*** 590 * Specifies the maxMem flag. 591 * @param maxMem such flag. 592 */ 593 public void setMaxmem(String maxMem) 594 { 595 AjcTask t_AjcTask = getAjcTask(); 596 597 if (t_AjcTask != null) 598 { 599 t_AjcTask.setMaxmem(maxMem); 600 } 601 } 602 603 /*** 604 * Specifies the tag file. 605 * @param file such file. 606 */ 607 public void setTagFile(File file) 608 { 609 AjcTask t_AjcTask = getAjcTask(); 610 611 if (t_AjcTask != null) 612 { 613 t_AjcTask.setTagFile(file); 614 } 615 } 616 617 /*** 618 * Specifies the outjar file. 619 * @param outjar such file. 620 */ 621 public void setOutjar(File file) 622 { 623 AjcTask t_AjcTask = getAjcTask(); 624 625 if (t_AjcTask != null) 626 { 627 t_AjcTask.setOutjar(file); 628 } 629 } 630 631 /*** 632 * Specifies the destination folder. 633 * @param dir such dir. 634 */ 635 public void setDestdir(File dir) 636 { 637 AjcTask t_AjcTask = getAjcTask(); 638 639 if (t_AjcTask != null) 640 { 641 t_AjcTask.setDestdir(dir); 642 } 643 } 644 645 /*** 646 * Specifies the target. 647 * @param target the target. 648 */ 649 public void setTarget(String target) 650 { 651 AjcTask t_AjcTask = getAjcTask(); 652 653 if (t_AjcTask != null) 654 { 655 t_AjcTask.setTarget(target); 656 } 657 } 658 659 /*** 660 * Specifies the language compliance level. 661 * @param compliance either "1.3" or "1.4" 662 */ 663 public void setCompliance(String compliance) 664 { 665 AjcTask t_AjcTask = getAjcTask(); 666 667 if (t_AjcTask != null) 668 { 669 t_AjcTask.setCompliance(compliance); 670 } 671 } 672 673 /*** 674 * Specifies the source compliance level. 675 * @param source either "1.3" or "1.4" 676 */ 677 public void setSource(String source) 678 { 679 AjcTask t_AjcTask = getAjcTask(); 680 681 if (t_AjcTask != null) 682 { 683 t_AjcTask.setSource(source); 684 } 685 } 686 687 /*** 688 * Specifies whether to copy all non-.class contents of injars 689 * to outjar after compile completes. 690 * Requires both injars and outjar. 691 * @param doCopy such flag. 692 */ 693 public void setCopyInjars(boolean doCopy) 694 { 695 AjcTask t_AjcTask = getAjcTask(); 696 697 if (t_AjcTask != null) 698 { 699 t_AjcTask.setCopyInjars(doCopy); 700 } 701 } 702 703 /*** 704 * Specifies whether to copy all files from 705 * all source root directories except those specified here. 706 * If this is specified and sourceroots are specified, 707 * then this will copy all files except 708 * those specified in the filter pattern. 709 * Requires sourceroots. 710 * @param filter a String acceptable as an excludes 711 * filter for an Ant Zip fileset. 712 */ 713 public void setSourceRootCopyFilter(String filter) 714 { 715 AjcTask t_AjcTask = getAjcTask(); 716 717 if (t_AjcTask != null) 718 { 719 t_AjcTask.setSourceRootCopyFilter(filter); 720 } 721 } 722 723 /*** 724 * Specifies the X option. 725 * @param input such option. 726 */ 727 public void setX(String input) 728 { 729 AjcTask t_AjcTask = getAjcTask(); 730 731 if (t_AjcTask != null) 732 { 733 t_AjcTask.setX(input); 734 } 735 } 736 737 // </AjcTask delegation methods> // 738 739 /*** 740 * Specifies the source roots. 741 * @param roots such path. 742 */ 743 public void setSourceRoots(Path roots) 744 { 745 m__SourceRoots = roots; 746 747 AjcTask t_AjcTask = getAjcTask(); 748 749 if (t_AjcTask != null) 750 { 751 t_AjcTask.setSourceRoots(roots); 752 } 753 } 754 755 /*** 756 * Retrieves the source roots. 757 * @return such path. 758 */ 759 public Path getSourceRoots() 760 { 761 return m__SourceRoots; 762 } 763 764 /*** 765 * Creates the source-roots path. 766 * @return such path. 767 */ 768 public Path createSourceRoots() 769 { 770 Path result = getSourceRoots(); 771 772 if (result == null) 773 { 774 result = new Path(getProject()); 775 setSourceRoots(result); 776 } 777 778 AjcTask t_AjcTask = getAjcTask(); 779 780 if (t_AjcTask != null) 781 { 782 t_AjcTask.createSourceRoots(); 783 } 784 785 return result.createPath(); 786 } 787 788 /*** 789 * Adds a new file to the source path. 790 * @param file the new file. 791 */ 792 public void addSourceRoots(File file) 793 { 794 if (file != null) 795 { 796 Path t_NewPath = 797 new Path(getProject(), file.getAbsolutePath()); 798 799 Path t_SourceRoots = getSourceRoots(); 800 801 if (t_SourceRoots != null) 802 { 803 t_SourceRoots.append(t_NewPath); 804 } 805 806 AjcTask t_AjcTask = getAjcTask(); 807 808 if (t_AjcTask != null) 809 { 810 t_AjcTask.setSourceRoots(t_NewPath); 811 } 812 } 813 } 814 815 /*** 816 * Specifies the source roots reference. 817 * @param ref such reference. 818 */ 819 public void setSourcerootsref(Reference ref) 820 { 821 createSourceRoots().setRefid(ref); 822 823 AjcTask t_AjcTask = getAjcTask(); 824 825 if (t_AjcTask != null) 826 { 827 t_AjcTask.setSourcerootsref(ref); 828 } 829 } 830 831 /*** 832 * Specifies the classpath. 833 * @param classpath such path. 834 */ 835 public void setClasspath(Path classpath) 836 { 837 m__Classpath = classpath; 838 839 AjcTask t_AjcTask = getAjcTask(); 840 841 if (t_AjcTask != null) 842 { 843 t_AjcTask.setClasspath(classpath); 844 } 845 } 846 847 /*** 848 * Retrieves the classpath. 849 * @return such path. 850 */ 851 public Path getClasspath() 852 { 853 return m__Classpath; 854 } 855 856 /*** 857 * Creates the classpath. 858 * @return such path. 859 */ 860 public Path createClasspath() 861 { 862 Path result = getClasspath(); 863 864 if (result == null) 865 { 866 result = new Path(getProject()); 867 setClasspath(result); 868 } 869 870 AjcTask t_AjcTask = getAjcTask(); 871 872 if (t_AjcTask != null) 873 { 874 t_AjcTask.createClasspath(); 875 } 876 877 return result.createPath(); 878 } 879 880 /*** 881 * Specifies the classpath reference. 882 * @param ref such reference. 883 */ 884 public void setClasspathref(Reference ref) 885 { 886 createClasspath().setRefid(ref); 887 888 AjcTask t_AjcTask = getAjcTask(); 889 890 if (t_AjcTask != null) 891 { 892 t_AjcTask.setClasspathref(ref); 893 } 894 } 895 896 /*** 897 * Requests the ContractChecker compilation to be performed. 898 * @throws org.apache.tools.ant.BuildException whenever the required 899 * parameters are not present or valid. 900 */ 901 public void execute() 902 throws BuildException 903 { 904 AjcTask t_AjcTask = getAjcTask(); 905 906 if (t_AjcTask != null) 907 { 908 try 909 { 910 File t_AspectOutput = getAspectoutput(); 911 912 if (t_AspectOutput == null) 913 { 914 t_AspectOutput = getTempBasedAspectOutput(); 915 916 setAspectoutput(t_AspectOutput); 917 } 918 919 executeDoclet(t_AspectOutput, getViolationexception()); 920 921 addSourceRoots(t_AspectOutput); 922 923 t_AjcTask.execute(); 924 } 925 catch (IOException ioException) 926 { 927 throw 928 new BuildException( 929 "no aspectoutput specified and couldn't create a " 930 + "temporary folder", 931 ioException); 932 } 933 } 934 } 935 936 /*** 937 * Requests the Javadoc task invokation to generate the aspects using 938 * ContractCheckerDoclet. 939 * @param aspectOutput the output folder for the aspects. 940 * @param violationException the contract violation exception. 941 * @throws BuildException if the doclet could not be executed. 942 */ 943 public void executeDoclet(File aspectOutput, String violationException) 944 throws BuildException 945 { 946 if (aspectOutput != null) 947 { 948 ContractCheckerDoclet t_Doclet = 949 new ContractCheckerDoclet(); 950 951 t_Doclet.setProject(getProject()); 952 t_Doclet.setDescription(getDescription()); 953 954 t_Doclet.setInput(getSourceRoots()); 955 956 t_Doclet.setOutputfolder(aspectOutput); 957 958 t_Doclet.setViolationexception(violationException); 959 960 String t_strTemplateFactoryClass = getTemplatefactoryclass(); 961 962 if (t_strTemplateFactoryClass != null) 963 { 964 t_Doclet.setTemplatefactoryclass( 965 t_strTemplateFactoryClass); 966 } 967 968 t_Doclet.execute(); 969 } 970 } 971 }

This page was automatically generated by Maven