1 /* 2 * Copyright 2012 Julien Nicoulaud <julien.nicoulaud@gmail.com> 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package net.nicoulaj.maven.plugins.soot; 17 18 import org.apache.maven.plugin.AbstractMojo; 19 import org.apache.maven.plugin.MojoExecutionException; 20 import org.apache.maven.plugin.MojoFailureException; 21 import org.apache.maven.plugins.annotations.LifecyclePhase; 22 import org.apache.maven.plugins.annotations.Mojo; 23 import org.apache.maven.plugins.annotations.Parameter; 24 import org.apache.maven.project.MavenProject; 25 import soot.Main; 26 import soot.options.Options; 27 28 import java.util.List; 29 30 /** 31 * Mojo that invokes <a href="http://www.sable.mcgill.ca/soot">Soot</a>. 32 * 33 * @author <a href="mailto:julien.nicoulaud@gmail.com">Julien Nicoulaud</a> 34 * @since 0.1 35 */ 36 @Mojo( 37 name = SootMojo.NAME, 38 defaultPhase = LifecyclePhase.COMPILE, 39 threadSafe = false ) 40 public final class SootMojo 41 extends AbstractMojo 42 { 43 44 /** 45 * Mojo name. 46 */ 47 public static final String NAME = "soot"; 48 49 /** 50 * The Maven project. 51 * 52 * @since 0.1 53 */ 54 @Parameter( property = "project", required = true, readonly = true ) 55 protected MavenProject project; 56 57 /** 58 * Display the textual help message and exit immediately without further processing. 59 */ 60 @Parameter( defaultValue = "false" ) 61 protected boolean help; 62 63 /** 64 * Print a list of the available phases and sub-phases, then exit. 65 */ 66 @Parameter( defaultValue = "false" ) 67 protected boolean phaseList; 68 69 /** 70 * Print a help message about the phase or sub-phase named phase, then exit. To see the help message of more than 71 * one phase, specify multiple phase-help options. 72 */ 73 @Parameter 74 protected List phaseHelp; 75 76 /** 77 * Display information about the version of Soot being run, then exit without further processing. 78 */ 79 @Parameter( defaultValue = "false" ) 80 protected boolean version; 81 82 /** 83 * Provide detailed information about what Soot is doing as it runs. 84 */ 85 @Parameter( defaultValue = "false" ) 86 protected boolean verbose; 87 88 /** 89 * Runs interactively, with Soot providing detailed information as it iterates through intra-procedural analyses. 90 */ 91 @Parameter( defaultValue = "false" ) 92 protected boolean interactiveMode; 93 94 /** 95 * With this option, Soot does not stop even if it received no command-line options. Useful when setting Soot options 96 * programmatically and then calling soot.Main.main() with an empty list. 97 */ 98 @Parameter( defaultValue = "true" ) 99 protected boolean unfriendlyMode; 100 101 /** 102 * Run in application mode, processing all classes referenced by argument classes. 103 */ 104 @Parameter( defaultValue = "false" ) 105 protected boolean applicationMode; 106 107 /** 108 * Run in whole program mode, taking into consideration the whole program when performing analyses and transformations. 109 * Soot uses the Call Graph Constructor to build a call graph for the program, then applies enabled transformations in 110 * the Whole-Jimple Transformation, Whole-Jimple Optimization, and Whole-Jimple Annotation packs before applying 111 * enabled intraprocedural transformations. 112 * Note that the Whole-Jimple Optimization pack is normally disabled (and thus not applied by whole program mode), 113 * unless you also specify the Whole Program Optimize option. 114 */ 115 @Parameter( defaultValue = "false" ) 116 protected boolean wholeProgram; 117 118 /** 119 * Run in whole shimple mode, taking into consideration the whole program when performing Shimple analyses and 120 * transformations. Soot uses the Call Graph Constructor to build a call graph for the program, then applies enabled 121 * transformations in the Whole-Shimple Transformation and Whole-Shimple Optimization before applying enabled 122 * intraprocedural transformations. 123 * Note that the Whole-Shimple Optimization pack is normally disabled (and thus not applied by whole shimple mode), 124 * unless you also specify the Whole Program Optimize option. 125 */ 126 @Parameter( defaultValue = "false" ) 127 protected boolean wholeShimple; 128 129 /** 130 * Causes internal checks to be done on bodies in the various Soot IRs,to make sure the transformations have not done 131 * something strange. This option may degrade Soot's performance. 132 */ 133 @Parameter( defaultValue = "false" ) 134 protected boolean validate; 135 136 /** 137 * Print various debugging information as Soot runs, particularly from the Baf Body Phase and the Jimple Annotation 138 * Pack Phase. 139 */ 140 @Parameter( defaultValue = "false" ) 141 protected boolean debug; 142 143 /** 144 * Print debugging information about class resolving. 145 */ 146 @Parameter( defaultValue = "false" ) 147 protected boolean debugResolver; 148 149 /** 150 * Use path as the list of directories in which Soot should search for classes. path should be a series of directories, 151 * separated by the path separator character for your system. 152 * If no classpath is set on the command line, but the system property <tt>soot.class.path</tt> has been set, Soot 153 * uses its value as the classpath. 154 * If neither the command line nor the system properties specify a Soot classpath, Soot falls back on a default 155 * classpath consisting of the value of the system property <tt>java.class.path</tt> followed by 156 * <var>java.home</var><tt>/lib/rt.jar</tt>, where <var>java.home</var> stands for the contents of the system property 157 * <tt>java.home</tt> and <tt>/</tt> stands for the system file separator. 158 */ 159 @Parameter( property = "project.build.outputDirectory" ) 160 protected String sootClasspath; 161 162 /** 163 * Instead of replacing the default soot classpath with the classpath given on the command line, prepent it with that 164 * classpath. The default classpath holds whatever is set in the CLASSPATH environment variable, followed by rt.jar 165 * (resolved through the JAVA-UNDERSCORE-HOME environment variable). If whole-program mode is enabled, jce.jar is 166 * also appended in the end. 167 */ 168 @Parameter( defaultValue = "true" ) 169 protected boolean prependClasspath; 170 171 /** 172 * Add all classes found in directory to the set of argument classes which is analyzed and transformed by Soot. You 173 * can specify the option more than once, to add argument classes from multiple directories. You can also state JAR 174 * files. 175 * If subdirectories of directory contain <tt>.class</tt> or <tt>.jimple</tt> files, Soot assumes that the subdirectory 176 * names correspond to components of the classes' package names. If directory contains<tt>subA/subB/MyClass.class</tt>, 177 * for instance, then Soot assumes <tt>MyClass</tt> is in package <tt>subA.subB</tt>. 178 */ 179 @Parameter( property = "project.build.outputDirectory" ) 180 protected List processDirectory; 181 182 /** 183 * If this flag is set and soot converts java to jimple then AST metrics will be computed. 184 */ 185 @Parameter( defaultValue = "TODO" ) 186 protected boolean astMetrics; 187 188 /** 189 * Values for {@link #sourcePrecedence} option. 190 */ 191 @SuppressWarnings( "unused" ) 192 public enum SourcePrecedence 193 { 194 195 /** 196 * Favour class files as Soot source. 197 * <p/> 198 * Try to resolve classes first from <tt>.class</tt> files found in the Soot classpath. Fall back to 199 * <tt>.jimple</tt> files only when unable to find a <tt>.class</tt> file. 200 */ 201 CLASS( Options.src_prec_class ), 202 203 /** 204 * Use only class files as Soot source. 205 * <p/> 206 * Try to resolve classes first from <tt>.class</tt> files found in the Soot classpath. Do not try any other 207 * types of files even when unable to find a <tt>.class</tt> file. 208 */ 209 ONLY_CLASS( Options.src_prec_only_class ), 210 211 /** 212 * Favour Jimple files as Soot source. 213 * <p/> 214 * Try to resolve classes first from <tt>.jimple</tt> files found in the Soot classpath. Fall back to 215 * <tt>.class</tt> files only when unable to find a <tt>.jimple</tt> file. 216 */ 217 JIMPLE( Options.src_prec_jimple ), 218 219 /** 220 * Favour Java files as Soot source. 221 * <p/> 222 * Try to resolve classes first from <tt>.java</tt> files found in the Soot classpath. Fall back to 223 * <tt>.class</tt> files only when unable to find a <tt>.java</tt> file. 224 */ 225 JAVA( Options.src_prec_java ); 226 227 protected int value; 228 229 private SourcePrecedence( int value ) 230 { 231 this.value = value; 232 } 233 234 public int getValue() 235 { 236 return value; 237 } 238 } 239 240 /** 241 * Sets format as Soot's preference for the type of source files to read when it looks for a class. 242 */ 243 @Parameter( defaultValue = "CLASS" ) 244 protected SourcePrecedence sourcePrecedence; 245 246 /** 247 * Normally, Soot resolves only that application classes and any classes that they refer to, along with any classes 248 * it needs for the Jimple typing, but it does not transitively resolve references in these additional classes that 249 * were resolved only because they were referenced. This switch forces full transitive resolution of all references 250 * found in all classes that are resolved, regardless of why they were resolved. 251 * In whole-program mode, class resolution is always fully transitive. Therefore, in whole-program mode, this switch 252 * has no effect, and class resolution is always performed as if it were turned on. 253 */ 254 @Parameter( defaultValue = "false" ) 255 protected boolean fullResolver; 256 257 /** 258 * Allow Soot to process a class even if it cannot find all classes referenced by that class. This may cause Soot to 259 * produce incorrect results. 260 */ 261 @Parameter( defaultValue = "false" ) 262 protected boolean allowPhantomRefs; 263 264 /** 265 * Prevents Soot from loading method bodies for all excluded classes (see exclude option), even when running in 266 * whole-program mode. This is useful for computing a shallow points-to analysis that does not, for instance, take 267 * into account the JDK. Of course, such analyses may be unsound. You get what you are asking for. 268 */ 269 @Parameter( defaultValue = "false" ) 270 protected boolean noBodiesForExcluded; 271 272 /** 273 * Use J2ME mode. J2ME does not have class Cloneable nor Serializable, so we have to change type assignment to not 274 * refer to those classes. 275 */ 276 @Parameter( defaultValue = "false" ) 277 protected boolean j2me; 278 279 /** 280 * By default, the first class encountered with a main method is treated as the main class (entry point) in whole- 281 * program analysis. This option overrides this default. 282 */ 283 @Parameter 284 protected String mainClass; 285 286 /** 287 * Use Java 1.4 Polyglot frontend instead of JastAdd, which supports Java 5 syntax. 288 */ 289 @Parameter( defaultValue = "false" ) 290 protected boolean polyglot; 291 292 /** 293 * Store output files in directory. directory may be relative to the working directory. 294 */ 295 @Parameter( property = "project.build.outputDirectory" ) 296 protected String outputDirectory; 297 298 /** 299 * Values for {@link #outputFormat} option. 300 */ 301 @SuppressWarnings( "unused" ) 302 public enum OutputFormat 303 { 304 305 /** 306 * Produce <tt>.jimple</tt> files. 307 * <p/> 308 * Produce <tt>.jimple</tt> files, which contain a textual form of Soot's Jimple internal representation. 309 */ 310 JIMPLE( Options.output_format_jimple ), 311 312 /** 313 * Produce <tt>.jimp</tt> (abbreviated Jimple) files. 314 * <p/> 315 * Produce <tt>.jimp</tt> files, which contain an abbreviated form of Jimple. 316 */ 317 JIMP( Options.output_format_jimp ), 318 319 /** 320 * Produce <tt>.shimple</tt> files. 321 * <p/> 322 * Produce<tt>.shimple files</tt>, containing a textual form of Soot's SSA Shimple internal representation. 323 * Shimple adds Phi nodes to Jimple. 324 */ 325 SHIMPLE( Options.output_format_shimple ), 326 327 /** 328 * Produce <tt>.shimp</tt> (abbreviated Shimple) files. 329 * <p/> 330 * Produce .shimp files, which contain an abbreviated form of Shimple. 331 */ 332 SHIMP( Options.output_format_shimp ), 333 334 /** 335 * Produce <tt>.baf</tt> files. 336 * <p/> 337 * Produce <tt>.baf</tt> files, which contain a textual form of Soot's Baf internal representation. 338 */ 339 BAF( Options.output_format_baf ), 340 341 /** 342 * Produce <tt>.b</tt> (abbreviated Baf) files. 343 * <p/> 344 * Produce <tt>.b</tt> files, which contain an abbreviated form of Baf. 345 */ 346 B( Options.output_format_b ), 347 348 /** 349 * Produce <tt>.grimple</tt> files. 350 * <p/> 351 * Produce <tt>.grimple</tt> files, which contain a textual form of Soot's Grimp internal representation. 352 */ 353 GRIMPLE( Options.output_format_grimple ), 354 355 /** 356 * Produce <tt>.grimp</tt> (abbreviated Grimp) files. 357 * <p/> 358 * Produce <tt>.grimp</tt> files, which contain an abbreviated form of Grimp. 359 */ 360 GRIMP( Options.output_format_grimp ), 361 362 /** 363 * Produce <tt>.xml</tt> files. 364 * <p/> 365 * Produce <tt>.xml</tt> files containing an annotated version of the Soot's Jimple internal representation. 366 */ 367 XML( Options.output_format_xml ), 368 369 /** 370 * Produce no output. 371 * <p/> 372 * Produce no output files. 373 */ 374 NONE( Options.output_format_none ), 375 376 /** 377 * Produce <tt>.jasmin</tt> files. 378 * <p/> 379 * Produce <tt>.jasmin</tt> files, suitable as input to the jasmin bytecode assembler. 380 */ 381 JASMIN( Options.output_format_jasmin ), 382 383 /** 384 * Produce <tt>.class</tt> files. 385 * <p/> 386 * Produce Java <tt>.class</tt> files, executable by any Java Virtual Machine. 387 */ 388 CLASS( Options.output_format_class ), 389 390 /** 391 * Produce dava-decompiled <tt>.java</tt> files. 392 * <p/> 393 * Produce <tt>.java</tt> files generated by the Dava decompiler. 394 */ 395 DAVA( Options.output_format_dava ), 396 397 /** 398 * Produce <tt>.java</tt> files with Jimple templates. 399 * <p/> 400 * Produce <tt>.java</tt> files with Jimple templates. 401 */ 402 TEMPLATE( Options.output_format_template ); 403 404 protected int value; 405 406 private OutputFormat( int value ) 407 { 408 this.value = value; 409 } 410 411 public int getValue() 412 { 413 return value; 414 } 415 } 416 417 /** 418 * Specify the format of output files Soot should produce, if any. 419 * Note that while the abbreviated formats (<tt>jimp</tt>, <tt>shimp</tt>,<tt>b</tt>, and<tt>grimp</tt>) are easier 420 * to read than their unabbreviated counterparts (<tt>jimple</tt>, <tt>shimple</tt>,<tt>baf</tt>, and 421 * <tt>grimple</tt>), they may contain ambiguities. Method signatures in the abbreviated formats, for instance, are 422 * not uniquely determined. 423 */ 424 @Parameter( defaultValue = "CLASS" ) 425 protected OutputFormat outputFormat; 426 427 /** 428 * Make output dir a Jar file instead of dir. 429 * <p/> 430 * The output Jar file name should be specified using the {@link #outputDirectory} option. Note that if the output 431 * Jar file exists before Soot runs, any files inside it will first be removed. 432 */ 433 @Parameter( defaultValue = "false" ) 434 protected boolean outputJar; 435 436 /** 437 * Save in XML format a variety of tags which Soot has attached to its internal representations of the application 438 * classes. The XML file can then be read by the Soot plug-in for the Eclipse IDE, which can display the annotations 439 * together with the program source, to aid program understanding. 440 */ 441 @Parameter( defaultValue = "false" ) 442 protected boolean xmlAttributes; 443 444 /** 445 * Print in output files (either in Jimple or Dave) a variety of tags which Soot has attached to its internal 446 * representations of the application classes. The tags will be printed on the line succeeding the stmt that they 447 * are attached to. 448 */ 449 @Parameter( defaultValue = "false" ) 450 protected boolean printTags; 451 452 /** 453 * Don't output Source File Attribute when producing class files. 454 */ 455 @Parameter( defaultValue = "false" ) 456 protected boolean noOutputSourceFileAttribute; 457 458 /** 459 * Don't output inner classes attribute in class files. 460 * <p/> 461 * Don't output inner classes attribute in class files. 462 */ 463 @Parameter( defaultValue = "false" ) 464 protected boolean noOutputInnerClassesAttribute; 465 466 /** 467 * Dump the internal representation of each method before and after given phase. 468 */ 469 @Parameter 470 protected List dumpBody; 471 472 /** 473 * Dump the internal representation of each CFG constructed during given phase. 474 */ 475 @Parameter 476 protected List dumpCfg; 477 478 /** 479 * Include exception destination edges as well as CFG edges in dumped CFGs. 480 * <p/> 481 * Indicate whether to show exception destination edges as well as control flow edges in dumps of exceptional control 482 * flow graphs. 483 */ 484 @Parameter( defaultValue = "true" ) 485 protected boolean showExceptionDests; 486 487 /** 488 * GZip IR output files. 489 * <p/> 490 * This option causes Soot to compress output files of intermediate representations with GZip. It does not apply to 491 * class files output by Soot. 492 */ 493 @Parameter( defaultValue = "false" ) 494 protected boolean gzip; 495 496 // /** 497 // * Perform intraprocedural optimizations on the application classes. 498 // */ 499 // @Parameter(defaultValue = "true") 500 // protected boolean optimize; 501 // 502 // /** 503 // * Perform whole program optimizations. 504 // * <p/> 505 // * Perform whole program optimizations on the application classes. This enables the Whole-Jimple Optimization pack as 506 // * well as whole program mode and intraprocedural optimizations. 507 // */ 508 // @Parameter(defaultValue = "false") 509 // protected boolean wholeOptimize; 510 511 /** 512 * Convert Jimple to bytecode via the Grimp intermediate representation instead of via the Baf intermediate 513 * representation. 514 */ 515 @Parameter( defaultValue = "false" ) 516 protected boolean viaGrimp; 517 518 /** 519 * Enable Shimple, Soot's SSA representation. This generates Shimple bodies for the application classes, optionally 520 * transforms them with analyses that run on SSA form, then turns them back into Jimple for processing by the rest of 521 * Soot. For more information, see the documentation for the<tt>shimp</tt>,<tt>stp</tt>, and <tt>sop</tt> phases. 522 */ 523 @Parameter( defaultValue = "false" ) 524 protected boolean viaShimple; 525 526 /** 527 * Values for {@link #throwAnalysis} option. 528 */ 529 @SuppressWarnings( "unused" ) 530 public enum ThrowAnalysis 531 { 532 533 /** 534 * Pedantically conservative throw analysis. 535 * <p/> 536 * Says that any instruction may throw any <code>Throwable</code> whatsoever. Strictly speaking this is correct, 537 * since the Java libraries include the <code>Thread.stop(Throwable)</code> method, which allows other threads 538 * to cause arbitrary exceptions to occur at arbitrary points in the execution of a victim thread. 539 */ 540 PEDANTIC( Options.throw_analysis_pedantic ), 541 542 /** 543 * Unit Throw Analysis. 544 * <p/> 545 * Says that each statement in the intermediate representation may throw those exception types associated with 546 * the corresponding Java bytecode instructions in the JVM Specification. The analysis deals with each statement 547 * in isolation, without regard to the surrounding program. 548 */ 549 UNIT( Options.throw_analysis_unit ); 550 551 protected int value; 552 553 private ThrowAnalysis( int value ) 554 { 555 this.value = value; 556 } 557 558 public int getValue() 559 { 560 return value; 561 } 562 } 563 564 /** 565 * This option specifies how to estimate the exceptions which each statement may throw when constructing 566 * exceptional CFGs. 567 */ 568 @Parameter( defaultValue = "UNIT" ) 569 protected ThrowAnalysis throwAnalysis; 570 571 /** 572 * Omit CFG edges to handlers from excepting units which lack side effects. 573 * <p/> 574 * When constructing an <code>ExceptionalUnitGraph</code> or <code>ExceptionalBlockGraph</code>, include edges to an 575 * exception handler only from the predecessors of an instruction which may throw an exception to the handler, and 576 * not from the excepting instruction itself, unless the excepting instruction has potential side effects. 577 * Omitting edges from excepting units allows more accurate flow analyses (since if an instruction without side 578 * effects throws an exception, it has not changed the state of the computation). This accuracy, though, could lead 579 * optimizations to generate unverifiable code, since the dataflow analyses performed by bytecode verifiers might 580 * include paths to exception handlers from all protected instructions, regardless of whether the instructions have 581 * side effects. (In practice, the pedantic throw analysis suffices to pass verification in all VMs tested with Soot 582 * to date, but the JVM specification does allow for less discriminating verifiers which would reject some code that 583 * might be generated using the pedantic throw analysis without also adding edges from all excepting units.) 584 */ 585 @Parameter( defaultValue = "false" ) 586 protected boolean omitExceptingUnitEdges; 587 588 // /** 589 // * Trim unrealizable exceptional edges from CFGs. 590 // * <p/> 591 // * When constructing CFGs which include exceptional edges, minimize the number of edges leading to exception handlers 592 // * by analyzing which instructions might actually be executed before an exception is thrown, instead of assuming that 593 // * every instruction protected by a handler has the potential to throw an exception the handler catches. 594 // */ 595 // @Parameter(defaultValue = "false") 596 // protected boolean trimCfgs; 597 598 // /** 599 // * Does not throw an exception when a program references an undeclared field or method.. 600 // * <p/> 601 // * Some programs may contain dead code that references fields or methods that do not exist. By default, Soot exists 602 // * with an exception when this happens. If this option is enabled, Soot only prints a warning but does not exit. 603 // */ 604 // @Parameter(defaultValue = "false") 605 // protected boolean ignoreResolutionErrors; 606 607 /** 608 * Include classes in pkg as application classes. 609 * <p/> 610 * Designate classes in packages whose names begin with pkg (e.g.<tt>java.util.</tt>) as application classes which 611 * should be analyzed and output. This option allows you to selectively analyze classes in some packages that Soot 612 * normally treats as library classes. 613 * You can use the include option multiple times, to designate the classes of multiple packages as application classes. 614 * If you specify both include and exclude options, first the classes from all excluded packages are marked as library 615 * classes, then the classes from all included packages are marked as application classes. 616 */ 617 @Parameter 618 protected List includes; 619 620 /** 621 * Exclude classes in pkg from application classes. 622 * <p/> 623 * Excludes any classes in packages whose names begin with pkg from the set of application classes which are analyzed 624 * and output, treating them as library classes instead. 625 * This option allows you to selectively exclude classes which would normally be treated as application classes. 626 * You can use the exclude option multiple times, to designate the classes of multiple packages as library classes. 627 * If you specify both include and exclude options, first the classes from all excluded packages are marked as library 628 * classes, then the classes from all included packages are marked as application classes. 629 */ 630 @Parameter 631 protected List excludes; 632 633 /** 634 * Set default excluded packages to empty list. 635 * <p/> 636 * Soot uses a default list of packages (such as java.) which are deemed to contain library classes. This switch 637 * removes the default packages from the list of packages containing library classes. 638 * Individual packages can then be added using the exclude option. 639 */ 640 @Parameter( defaultValue = "TODO" ) 641 protected boolean includeAll; 642 643 /** 644 * Note that class may be loaded dynamically. 645 * <p/> 646 * Mark class as a class which the application may load dynamically. Soot will read it as a library class even if it 647 * is not referenced from the argument classes. This permits whole program optimizations on programs which load 648 * classes dynamically if the set of classes that can be loaded is known at compile time. 649 */ 650 @Parameter 651 protected List dynamicClasses; 652 653 /** 654 * Mark all class files in directory as classes that may be loaded dynamically. Soot will read them as library 655 * classes even if they are not referenced from the argument classes. 656 * You can specify more than one directory of potentially dynamic classes by specifying multiple dynamic directory 657 * options. 658 */ 659 @Parameter 660 protected List dynamicDirectories; 661 662 /** 663 * Marks all class files belonging to the package package or any of its subpackages as classes which the application 664 * may load dynamically. 665 * Soot will read all classes in package as library classes, even if they are not referenced by any of the argument 666 * classes. 667 */ 668 @Parameter 669 protected List dynamicPackages; 670 671 /** 672 * Keep line number tables. 673 * <p/> 674 * Preserve line number tables for class files throughout the 675 * // transformations. 676 */ 677 @Parameter( defaultValue = "true" ) 678 protected boolean keepLineNumber; 679 680 /** 681 * Maintain bytecode offset tables for class files throughout the transformations. 682 */ 683 @Parameter( defaultValue = "false" ) 684 protected boolean keepBytecodeOffset; 685 686 // /** 687 // * Emit purity attributes. 688 // * <p/> 689 // * Purity anaysis implemented by Antoine Mine and based on the paper A Combined Pointer and Purity Analysis Java 690 // * Programs by Alexandru Salcianu and Martin Rinard. 691 // */ 692 // @Parameter(defaultValue = "false") 693 // protected boolean annotPurity; 694 695 // /** 696 // * Emit null pointer attributes. 697 // * <p/> 698 // * Perform a static analysis of which dereferenced pointers may have null values, and annotate class files with 699 // * attributes encoding the results of the analysis. For details, see the documentation for Null Pointer Annotation 700 // * and for the Array Bounds and Null Pointer Check Tag Aggregator. 701 // */ 702 // @Parameter(defaultValue = "false") 703 // protected boolean annotNullPointer; 704 705 // /** 706 // * Emit array bounds check attributes. 707 // * <p/> 708 // * Perform a static analysis of which array bounds checks may safely be eliminated and annotate output class files 709 // * with attributes encoding the results of the analysis. For details, see the documentation for Array Bounds 710 // * Annotation and for the Array Bounds and Null Pointer Check Tag Aggregator. 711 // */ 712 // @Parameter(defaultValue = "false") 713 // protected boolean annotArrayBounds; 714 715 // /** 716 // * Enable the generation of side-effect attributes. 717 // */ 718 // @Parameter(defaultValue = "false") 719 // protected boolean annotSideEffect; 720 721 // /** 722 // * Enable the generation of field read/write attributes. 723 // */ 724 // @Parameter(defaultValue = "false") 725 // protected boolean annotFieldReadWrite; 726 727 /** 728 * Report the time required to perform some of Soot's transformations. 729 */ 730 @Parameter( defaultValue = "false" ) 731 protected boolean time; 732 733 /** 734 * Attempt to subtract time spent in garbage collection from the reports of times required for transformations. 735 */ 736 @Parameter( defaultValue = "false" ) 737 protected boolean subtractGC; 738 739 /** 740 * @throws MojoExecutionException 741 * @throws MojoFailureException 742 */ 743 public void execute() 744 throws MojoExecutionException, MojoFailureException 745 { 746 configureLogging(); 747 configureOptions(); 748 run(); 749 } 750 751 protected void configureLogging() 752 { 753 soot.G.v().out = new MavenLogPrintStream( getLog() ); 754 } 755 756 protected void configureOptions() 757 { 758 final Options options = Options.v(); 759 options.set_help( help ); 760 options.set_phase_list( phaseList ); 761 options.set_phase_help( phaseHelp ); 762 options.set_version( version ); 763 options.set_verbose( verbose ); 764 options.set_interactive_mode( interactiveMode ); 765 options.set_unfriendly_mode( unfriendlyMode ); 766 options.set_app( applicationMode ); 767 options.set_whole_program( wholeProgram ); 768 options.set_whole_shimple( wholeShimple ); 769 options.set_validate( validate ); 770 options.set_debug( debug ); 771 options.set_debug_resolver( debugResolver ); 772 options.set_soot_classpath( sootClasspath ); 773 options.set_prepend_classpath( prependClasspath ); 774 options.set_process_dir( processDirectory ); 775 options.set_ast_metrics( astMetrics ); 776 options.set_src_prec( sourcePrecedence.getValue() ); 777 options.set_full_resolver( fullResolver ); 778 options.set_allow_phantom_refs( allowPhantomRefs ); 779 options.set_no_bodies_for_excluded( noBodiesForExcluded ); 780 options.set_j2me( j2me ); 781 options.set_main_class( mainClass ); 782 options.set_polyglot( polyglot ); 783 options.set_output_dir( outputDirectory ); 784 options.set_output_format( outputFormat.getValue() ); 785 options.set_output_jar( outputJar ); 786 options.set_xml_attributes( xmlAttributes ); 787 options.set_print_tags_in_output( printTags ); 788 options.set_no_output_source_file_attribute( noOutputSourceFileAttribute ); 789 options.set_no_output_inner_classes_attribute( noOutputInnerClassesAttribute ); 790 options.set_dump_body( dumpBody ); 791 options.set_dump_cfg( dumpCfg ); 792 options.set_show_exception_dests( showExceptionDests ); 793 options.set_gzip( gzip ); 794 // options.set_XXXXXXX(optimize); 795 // options.set_XXXXXXX(wholeOptimize); 796 options.set_via_grimp( viaGrimp ); 797 options.set_via_shimple( viaShimple ); 798 options.set_throw_analysis( throwAnalysis.getValue() ); 799 options.set_omit_excepting_unit_edges( omitExceptingUnitEdges ); 800 // options.set_XXXXXXX(trimCfgs); 801 // options.set_XXXXXXX(ignoreResolutionErrors); 802 options.set_include( includes ); 803 options.set_exclude( excludes ); 804 options.set_include_all( includeAll ); 805 options.set_dynamic_class( dynamicClasses ); 806 options.set_dynamic_dir( dynamicDirectories ); 807 options.set_dynamic_package( dynamicPackages ); 808 options.set_keep_line_number( keepLineNumber ); 809 options.set_keep_offset( keepBytecodeOffset ); 810 // options.set_XXXXXXX(annotPurity); 811 // options.set_XXXXXXX(annotNullPointer); 812 // options.set_XXXXXXX(annotArrayBounds); 813 // options.set_XXXXXXX(annotSideEffect); 814 // options.set_XXXXXXX(annotFieldReadWrite); 815 options.set_time( time ); 816 options.set_subtract_gc( subtractGC ); 817 } 818 819 protected void run() 820 throws MojoFailureException 821 { 822 try 823 { 824 Main.v().run( new String[0] ); 825 } 826 catch ( soot.CompilationDeathException e ) 827 { 828 throw new MojoFailureException( "Soot execution failed", e ); 829 } 830 } 831 }