<?xml version="1.0"?>
<ruleset id="jni-native-code"
    xmlns="http://windup.jboss.org/schema/jboss-ruleset"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
    <metadata>
        <description>
            This ruleset detects Java Native Interface (JNI) and Java Native Access (JNA) code, which may be problematic when migrating an application to a cloud environment.
        </description>
        <dependencies>
          <addon id="org.jboss.windup.rules,windup-rules-javaee,3.0.0.Final"/>
          <addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final"/>
        </dependencies>
        <targetTechnology id="cloud-readiness"/>
        <tag>jni</tag>
    </metadata>
    <rules>
        <rule id="jni-native-code-00000">
            <when>
                <or>
                  <javaclass references="java.lang.System.load({*})">
                      <location>METHOD_CALL</location>
                  </javaclass>
                  <javaclass references="java.lang.System.loadLibrary({*})">
                      <location>METHOD_CALL</location>
                  </javaclass>
                  <javaclass references="java.lang.System.mapLibraryName({*})">
                      <location>METHOD_CALL</location>
                  </javaclass>
                  <javaclass references="java.lang.Runtime.load({*})">
                      <location>METHOD_CALL</location>
                  </javaclass>
                  <javaclass references="java.lang.Runtime.loadLibrary({*})">
                      <location>METHOD_CALL</location>
                  </javaclass>
                  <javaclass references="com.sun.jna.{*}">
                      <location>CONSTRUCTOR_CALL</location>
                      <location>IMPORT</location>
                      <location>INHERITANCE</location>
                      <location>METHOD_CALL</location>
                      <location>VARIABLE_DECLARATION</location>
                  </javaclass>
                </or>
            </when>
            <perform>
              <hint title="Java native libraries (JNI, JNA)" effort="7" category-id="cloud-mandatory">
                  <message>
                    Java native libraries might not run in a cloud or container environment.

                    Recommendations

                    * Review the purpose of the native library in your application.
                    * Check whether the native library is compatible with a cloud environment.
                    * Reuse or embed the native library or application in a cloud environment, for example, in a JBoss module.
                    * Replace, remove, or rewrite the native library or application using a cloud-compatible equivalent.
                </message>
                <link href="https://access.redhat.com/solutions/229443" title="How to load native libraries and access them via JNI in EAP (with or without a module)"/>
                <link href="https://access.redhat.com/solutions/1444643" title="Is it supported to compile the JNI code as 32-bit shared libraries and use it in 64-bit compiled Java code ?"/>
                <tag>jni</tag>
              </hint>
            </perform>
        </rule>
  </rules>
</ruleset>
