From 5a413dc915371b4b2bd2dffd783debd74078e565 Mon Sep 17 00:00:00 2001 From: mygizli04 <42012824+mygizli04@users.noreply.github.com> Date: Tue, 24 Aug 2021 21:00:26 +0400 Subject: [PATCH 1/2] Fix macOS support --- .../proxy/auth/AuthDetailsFromProcess.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/proxy/auth/AuthDetailsFromProcess.java b/src/main/java/proxy/auth/AuthDetailsFromProcess.java index 33d13dde..18df3c70 100644 --- a/src/main/java/proxy/auth/AuthDetailsFromProcess.java +++ b/src/main/java/proxy/auth/AuthDetailsFromProcess.java @@ -71,6 +71,9 @@ private List findCandidateProcesses() throws IOException { .map(this::getLaunchParametersWindows) .filter(line -> line.contains("--accessToken")) .collect(Collectors.toList()); + } else if (SystemUtils.IS_OS_MAC_OSX) { + return findCandidateProcessMacOS().stream() + .map(a -> "" + a).collect(Collectors.toList()); } else { return findCandidateProcessUnix().stream() .map(a -> "" + a).collect(Collectors.toList()); @@ -100,7 +103,7 @@ private List findJavawProcessWindows() throws IOException { } /** - * For unix systems we can use one command to get all java processes and their arguments. The first line will be a + * For unix (non-macOS) systems we can use one command to get all java processes and their arguments. The first line will be a * header that we can read out to get the required index for the arguments. */ private List findCandidateProcessUnix() throws IOException { @@ -121,6 +124,28 @@ private List findCandidateProcessUnix() throws IOException { return res; } + /** + * macOS systems have a different version of ps installed which requires different arguments, + * but we can just get the entire process list and filter through it. + */ + private List findCandidateProcessMacOS() throws IOException { + Process p = Runtime.getRuntime().exec("ps ax"); + + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + + List res = new ArrayList<>(); + + String line; + while ((line = input.readLine()) != null) { + if (line.contains("java") && line.contains("--accessToken")) { + res.add(line); + } + } + input.close(); + + return res; + } + /** * Retrieve launch parameters from a given PID on Windows. * From c54450d50a56bfdfa6c9631fb3313c8d0708dbce Mon Sep 17 00:00:00 2001 From: mygizli04 <42012824+mygizli04@users.noreply.github.com> Date: Tue, 24 Aug 2021 21:31:01 +0400 Subject: [PATCH 2/2] Remove unnecessary method --- .../proxy/auth/AuthDetailsFromProcess.java | 33 ++++--------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/main/java/proxy/auth/AuthDetailsFromProcess.java b/src/main/java/proxy/auth/AuthDetailsFromProcess.java index 18df3c70..ff862b7a 100644 --- a/src/main/java/proxy/auth/AuthDetailsFromProcess.java +++ b/src/main/java/proxy/auth/AuthDetailsFromProcess.java @@ -71,9 +71,6 @@ private List findCandidateProcesses() throws IOException { .map(this::getLaunchParametersWindows) .filter(line -> line.contains("--accessToken")) .collect(Collectors.toList()); - } else if (SystemUtils.IS_OS_MAC_OSX) { - return findCandidateProcessMacOS().stream() - .map(a -> "" + a).collect(Collectors.toList()); } else { return findCandidateProcessUnix().stream() .map(a -> "" + a).collect(Collectors.toList()); @@ -103,33 +100,17 @@ private List findJavawProcessWindows() throws IOException { } /** - * For unix (non-macOS) systems we can use one command to get all java processes and their arguments. The first line will be a + * For unix systems we can use one command to get all java processes and their arguments. The first line will be a * header that we can read out to get the required index for the arguments. */ private List findCandidateProcessUnix() throws IOException { - Process p = Runtime.getRuntime().exec("ps -fC java"); - - BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); - - List res = new ArrayList<>(); - - String line; - while ((line = input.readLine()) != null) { - if (line.contains("java") && line.contains("--accessToken")) { - res.add(line); - } + Process p; + if (SystemUtils.IS_OS_MAC_OSX) { + p = Runtime.getRuntime().exec("ps ax"); + } + else { + p = Runtime.getRuntime().exec("ps -fC java"); } - input.close(); - - return res; - } - - /** - * macOS systems have a different version of ps installed which requires different arguments, - * but we can just get the entire process list and filter through it. - */ - private List findCandidateProcessMacOS() throws IOException { - Process p = Runtime.getRuntime().exec("ps ax"); BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));