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. --> org.slf4j slf4j-api - - - net.java.dev.jna - jna-platform - 5.10.0 - 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 pid - * 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();