|
534 | 534 | description="Build library JAR (JNI + JCE classes)"> |
535 | 535 | </target> |
536 | 536 |
|
| 537 | + <!-- SpotBugs Static Analysis: |
| 538 | + Run with 'ant spotbugs' to generate report. |
| 539 | + Requires SPOTBUGS_HOME environment variable to be set. |
| 540 | + Download from: https://spotbugs.github.io/ |
| 541 | + Report generated at: build/reports/spotbugs.html --> |
| 542 | + |
| 543 | + <!-- Only define SpotBugs task if SPOTBUGS_HOME is set --> |
| 544 | + <condition property="spotbugs.available"> |
| 545 | + <and> |
| 546 | + <isset property="env.SPOTBUGS_HOME"/> |
| 547 | + <available |
| 548 | + file="${env.SPOTBUGS_HOME}/lib/spotbugs-ant.jar"/> |
| 549 | + </and> |
| 550 | + </condition> |
| 551 | + |
| 552 | + <!-- Check if Java version is 11+ (required by SpotBugs 4.8+) --> |
| 553 | + <condition property="spotbugs.java.compatible"> |
| 554 | + <not> |
| 555 | + <or> |
| 556 | + <equals arg1="${ant.java.version}" arg2="1.5"/> |
| 557 | + <equals arg1="${ant.java.version}" arg2="1.6"/> |
| 558 | + <equals arg1="${ant.java.version}" arg2="1.7"/> |
| 559 | + <equals arg1="${ant.java.version}" arg2="1.8"/> |
| 560 | + <equals arg1="${ant.java.version}" arg2="9"/> |
| 561 | + <equals arg1="${ant.java.version}" arg2="10"/> |
| 562 | + </or> |
| 563 | + </not> |
| 564 | + </condition> |
| 565 | + |
| 566 | + <target name="spotbugs-taskdef" if="spotbugs.available"> |
| 567 | + <taskdef |
| 568 | + resource="edu/umd/cs/findbugs/anttask/tasks.properties"> |
| 569 | + <classpath> |
| 570 | + <fileset dir="${env.SPOTBUGS_HOME}/lib" |
| 571 | + includes="*.jar"/> |
| 572 | + </classpath> |
| 573 | + </taskdef> |
| 574 | + </target> |
| 575 | + |
| 576 | + <target name="spotbugs-check"> |
| 577 | + <fail unless="spotbugs.java.compatible"> |
| 578 | +SpotBugs requires Java 11 or later to run. |
| 579 | + |
| 580 | +Current Java version: ${ant.java.version} |
| 581 | + |
| 582 | +To fix this, run ant with Java 11+: |
| 583 | + export JAVA_HOME=/path/to/jdk11 |
| 584 | + ant spotbugs |
| 585 | + </fail> |
| 586 | + <fail unless="spotbugs.available"> |
| 587 | +SpotBugs not found. Please set SPOTBUGS_HOME. |
| 588 | + |
| 589 | +To install SpotBugs: |
| 590 | + 1. Download from https://spotbugs.github.io/ |
| 591 | + 2. Extract (e.g., /opt/spotbugs-4.8.6) |
| 592 | + 3. Set SPOTBUGS_HOME=/opt/spotbugs-4.8.6 |
| 593 | + 4. Run 'ant spotbugs' |
| 594 | + </fail> |
| 595 | + </target> |
| 596 | + |
| 597 | + <target name="spotbugs" |
| 598 | + depends="build-jce-debug, spotbugs-check, spotbugs-taskdef" |
| 599 | + description="Run SpotBugs static analysis"> |
| 600 | + <mkdir dir="${reports.dir}"/> |
| 601 | + <spotbugs home="${env.SPOTBUGS_HOME}" |
| 602 | + output="html" |
| 603 | + outputFile="${reports.dir}/spotbugs.html" |
| 604 | + effort="max" |
| 605 | + reportLevel="medium" |
| 606 | + excludeFilter="spotbugs-exclude.xml" |
| 607 | + failOnError="false"> |
| 608 | + <sourcePath path="${src.dir}"/> |
| 609 | + <class location="${lib.dir}/wolfcrypt-jni.jar"/> |
| 610 | + </spotbugs> |
| 611 | + <echo message="SpotBugs report: ${reports.dir}/spotbugs.html"/> |
| 612 | + </target> |
| 613 | + |
537 | 614 | </project> |
538 | 615 |
|
0 commit comments