You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jf...@apache.org on 2022/07/12 18:56:56 UTC

[nifi] branch main updated: NIFI-10219 Removed jna-platform from nifi-bootstrap-utils

This is an automated email from the ASF dual-hosted git repository.

jfrazee pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 2a9139c57a NIFI-10219 Removed jna-platform from nifi-bootstrap-utils
2a9139c57a is described below

commit 2a9139c57ab5c68387d3ed84e3d28119f33d9168
Author: exceptionfactory <ex...@apache.org>
AuthorDate: Tue Jul 12 08:50:34 2022 -0500

    NIFI-10219 Removed jna-platform from nifi-bootstrap-utils
    
    - Removed OSUtils.getWindowsProcessId() which removes JNA-based retrieval of Process ID retrieval for Windows on Java 8
    - Removing jna-platform from nifi-bootstrap-utils eliminates the library from lib/bootstrap and allows it as a dependency in lib/properties
    
    This closes #6199
    
    Signed-off-by: Joey Frazee <jf...@apache.org>
---
 nifi-commons/nifi-bootstrap-utils/pom.xml          |  7 -----
 .../org/apache/nifi/bootstrap/util/OSUtils.java    | 34 +---------------------
 .../apache/nifi/bootstrap/util/OSUtilsTest.java    |  3 ++
 3 files changed, 4 insertions(+), 40 deletions(-)

diff --git a/nifi-commons/nifi-bootstrap-utils/pom.xml b/nifi-commons/nifi-bootstrap-utils/pom.xml
index 4ff93e6803..1aa72efc4a 100644
--- a/nifi-commons/nifi-bootstrap-utils/pom.xml
+++ b/nifi-commons/nifi-bootstrap-utils/pom.xml
@@ -24,12 +24,5 @@ language governing permissions and limitations under the License. -->
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
-        <!-- This needs to be here because it is relied upon by the nifi-runtime which starts NiFi.  It uses this bootstrap module
-        and the libs that get laid down in lib/bootstrap to create a child classloader with these bits in it -->
-        <dependency>
-            <groupId>net.java.dev.jna</groupId>
-            <artifactId>jna-platform</artifactId>
-            <version>5.10.0</version>
-        </dependency>
     </dependencies>
 </project>
diff --git a/nifi-commons/nifi-bootstrap-utils/src/main/java/org/apache/nifi/bootstrap/util/OSUtils.java b/nifi-commons/nifi-bootstrap-utils/src/main/java/org/apache/nifi/bootstrap/util/OSUtils.java
index cde0bafe23..71047a55bb 100644
--- a/nifi-commons/nifi-bootstrap-utils/src/main/java/org/apache/nifi/bootstrap/util/OSUtils.java
+++ b/nifi-commons/nifi-bootstrap-utils/src/main/java/org/apache/nifi/bootstrap/util/OSUtils.java
@@ -17,9 +17,6 @@
 
 package org.apache.nifi.bootstrap.util;
 
-import com.sun.jna.Pointer;
-import com.sun.jna.platform.win32.Kernel32;
-import com.sun.jna.platform.win32.WinNT;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -64,11 +61,8 @@ public final class OSUtils {
             final String processClassName = process.getClass().getName();
             if (processClassName.equals("java.lang.UNIXProcess")) {
                 pid = getUnixPid(process, logger);
-            } else if (processClassName.equals("java.lang.Win32Process")
-                    || processClassName.equals("java.lang.ProcessImpl")) {
-                pid = getWindowsProcessId(process, logger);
             } else {
-                logger.debug("Failed to determine Process ID from [{}]: {}", processClassName, e.getMessage());
+                logger.info("Failed to determine Process ID from [{}]: {}", processClassName, e.getMessage());
             }
         }
 
@@ -122,30 +116,4 @@ public final class OSUtils {
             return null;
         }
     }
-
-    /**
-     * @param process NiFi Process Reference
-     * @param logger  Logger Reference for Debug
-     * @return        Returns pid or null in-case pid could not be determined
-     * This method takes {@link Process} and {@link Logger} and returns
-     * the platform specific Handle for Win32 Systems, a.k.a <b>pid</b>
-     * In-case it fails to determine the pid, it will return Null.
-     * Purpose for the Logger is to log any interaction for debugging.
-     */
-    private static Long getWindowsProcessId(final Process process, final Logger logger) {
-        Long pid = null;
-        try {
-            final Field handleField = process.getClass().getDeclaredField("handle");
-            handleField.setAccessible(true);
-            long peer = handleField.getLong(process);
-
-            final Kernel32 kernel = Kernel32.INSTANCE;
-            final WinNT.HANDLE handle = new WinNT.HANDLE();
-            handle.setPointer(Pointer.createConstant(peer));
-            pid = Long.valueOf(kernel.GetProcessId(handle));
-        } catch (final IllegalAccessException | NoSuchFieldException e) {
-            logger.debug("Could not find Windows PID", e);
-        }
-        return pid;
-    }
 }
diff --git a/nifi-commons/nifi-bootstrap-utils/src/test/java/org/apache/nifi/bootstrap/util/OSUtilsTest.java b/nifi-commons/nifi-bootstrap-utils/src/test/java/org/apache/nifi/bootstrap/util/OSUtilsTest.java
index bfe85c3b87..a3f9c43fec 100644
--- a/nifi-commons/nifi-bootstrap-utils/src/test/java/org/apache/nifi/bootstrap/util/OSUtilsTest.java
+++ b/nifi-commons/nifi-bootstrap-utils/src/test/java/org/apache/nifi/bootstrap/util/OSUtilsTest.java
@@ -17,6 +17,8 @@
 package org.apache.nifi.bootstrap.util;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,6 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 public class OSUtilsTest {
 
+    @DisabledOnOs(OS.WINDOWS)
     @Test
     public void testGetPid() throws IOException {
         final ProcessBuilder builder = new ProcessBuilder();