Skip to content

Commit

Permalink
Check if external process is started in java code (#995)
Browse files Browse the repository at this point in the history
* Add new runtime springboot and add JPA as supported

* 1) Add Spring App and War
2) Add label for Springboot

* Update the test jar file

* use simple test data

* Add more spring framework to runtime springboot
change spring boot war to spring war

* Divided 'Spring Boot Application' into 3 relevant technologies

* Fixed 'technology-tag's cases

* Changed consistently labels definitions

* Changed 'SpringBootApplication' annotation technologies' placement

* Rule '3rd-party-spring-03001': removed useless 'or' condition

* Added new technologies to README

* Update the jni to check if call local command/process directly

* Update the jni to check if call local command/process directly

* Update the test case

* numbering tests to match the associated rule it's testing

---------

Co-authored-by: PhilipCattanach <31246010+PhilipCattanach@users.noreply.github.com>
Co-authored-by: mrizzi <mrizzi@redhat.com>
Co-authored-by: Mark Brophy <36955467+m-brophy@users.noreply.github.com>
  • Loading branch information
4 people committed Jun 30, 2023
1 parent 91e8302 commit 2e0ed9b
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
38 changes: 38 additions & 0 deletions rules/rules-reviewed/cloud-readiness/jni-native-code.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,43 @@
</hint>
</perform>
</rule>
<rule id="jni-native-code-00001">
<when>
<or>
<javaclass references="java.lang.Process">
<location>CONSTRUCTOR_CALL</location>
<location>IMPORT</location>
<location>INHERITANCE</location>
<location>VARIABLE_DECLARATION</location>
</javaclass>
<javaclass references="java.lang.ProcessBuilder">
<location>CONSTRUCTOR_CALL</location>
<location>IMPORT</location>
<location>INHERITANCE</location>
<location>VARIABLE_DECLARATION</location>
</javaclass>
<javaclass references="java.lang.ProcessHandle">
<location>CONSTRUCTOR_CALL</location>
<location>IMPORT</location>
<location>INHERITANCE</location>
<location>VARIABLE_DECLARATION</location>
</javaclass>
</or>
</when>
<perform>
<hint title="Java Native Processes" effort="7" category-id="cloud-mandatory">
<message>
Native Processes might not run in a cloud or container environment.

Recommendations

* Review the purpose of the native process in your application.
* Check whether the native process is compatible with a cloud environment.
* Replace, remove, or rewrite the native process or application using a cloud-compatible equivalent.
</message>
<tag>jni</tag>
</hint>
</perform>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.io.IOException;
import java.util.concurrent.CompletableFuture;

public class JavaNativeProcess {

public static void main(String[] args) throws IOException {
Runtime rt = Runtime.getRuntime();
Process p = rt.exec("notepad.exe");
ProcessBuilder pb = new ProcessBuilder("javac hello.java");
ProcessHandle ph = p.toHandle();
System.out.println("Process is Running: " + ph.isAlive());

ProcessHandle.Info info = ph.info();

System.out.println("Process Command:" + info.command());
System.out.println("Process Argument:" + info.arguments());
CompletableFuture<ProcessHandle> cf = ph.onExit();

cf.thenRunAsync(() -> System.out.println("Process Exit"));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<rulePath>../jni-native-code.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="jni-native-code-test-00001">
<rule id="jni-native-code-test-00000">
<when>
<not>
<iterable-filter size="12">
Expand All @@ -17,6 +17,18 @@
<fail message="Java JNI/JNA usage was not found" />
</perform>
</rule>
<rule id="jni-native-code-test-00001">
<when>
<not>
<iterable-filter size="3">
<hint-exists message="Native Processes might not run in a cloud or container environment" />
</iterable-filter>
</not>
</when>
<perform>
<fail message="Native Process usage was not found" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>
</ruletest>

0 comments on commit 2e0ed9b

Please sign in to comment.