From 604fd183a8591c4257401070331b48209ff4585d Mon Sep 17 00:00:00 2001 From: Anton Piontkovskiy Date: Fri, 23 Jun 2023 10:15:50 +0300 Subject: [PATCH 1/2] Drop dev.dirs:directories dependency --- pom.xml | 7 ------ pom_all.xml | 7 ------ .../one/profiler/AsyncProfilerLoader.java | 23 +++++++++++++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 25fc290..f788893 100644 --- a/pom.xml +++ b/pom.xml @@ -233,13 +233,6 @@ - - - dev.dirs - directories - 26 - - ossrh diff --git a/pom_all.xml b/pom_all.xml index 808df80..05fc333 100644 --- a/pom_all.xml +++ b/pom_all.xml @@ -222,13 +222,6 @@ - - - dev.dirs - directories - 26 - - ossrh diff --git a/src/main/java/one/profiler/AsyncProfilerLoader.java b/src/main/java/one/profiler/AsyncProfilerLoader.java index 4f8ca25..91f1227 100644 --- a/src/main/java/one/profiler/AsyncProfilerLoader.java +++ b/src/main/java/one/profiler/AsyncProfilerLoader.java @@ -17,8 +17,6 @@ package one.profiler; -import dev.dirs.ProjectDirectories; - import java.io.*; import java.lang.instrument.Instrumentation; import java.lang.management.ManagementFactory; @@ -124,9 +122,7 @@ public static void deleteExtractionDirectory() throws IOException { /** Returns the directory used for storing the extracted libraries, binaries and JARs */ public static Path getExtractionDirectory() throws IOException { if (extractionDir == null) { - extractionDir = - Paths.get( - ProjectDirectories.from("me", "bechberger", "ap-loader-" + getVersion()).dataDir); + extractionDir = Paths.get(getApplicationsDir(), "me.bechberger.ap-loader", getVersion()); if (Files.notExists(extractionDir)) { Files.createDirectories(extractionDir); } @@ -134,6 +130,23 @@ public static Path getExtractionDirectory() throws IOException { return extractionDir; } + /** + * Returns directory where applications places their files. Specific to operating system + */ + private static String getApplicationsDir() { + String os = System.getProperty("os.name").toLowerCase(); + if (os.contains("linux")) { + String xdgDataHome = System.getenv("XDG_DATA_HOME"); + if (xdgDataHome != null && !xdgDataHome.isEmpty()) { + return xdgDataHome; + } + return Paths.get(System.getProperty("user.home"), ".local", "share").toString(); + } else if (os.contains("mac")) { + return Paths.get(System.getProperty("user.home"), "Library", "Application Support").toString(); + } + throw new UnsupportedOperationException("Unsupported os " + os); + } + /** * @throws IllegalStateException if OS or Arch not supported */ From 3a1dc706aa0a5ac202154ef4f36763a258003a7f Mon Sep 17 00:00:00 2001 From: Anton Piontkovskiy Date: Fri, 23 Jun 2023 14:47:01 +0300 Subject: [PATCH 2/2] Use more consistent approach in library code --- .../java/one/profiler/AsyncProfilerLoader.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/one/profiler/AsyncProfilerLoader.java b/src/main/java/one/profiler/AsyncProfilerLoader.java index 91f1227..1ad59ec 100644 --- a/src/main/java/one/profiler/AsyncProfilerLoader.java +++ b/src/main/java/one/profiler/AsyncProfilerLoader.java @@ -122,7 +122,7 @@ public static void deleteExtractionDirectory() throws IOException { /** Returns the directory used for storing the extracted libraries, binaries and JARs */ public static Path getExtractionDirectory() throws IOException { if (extractionDir == null) { - extractionDir = Paths.get(getApplicationsDir(), "me.bechberger.ap-loader", getVersion()); + extractionDir = getApplicationsDir().resolve(Paths.get("me.bechberger.ap-loader", getVersion())); if (Files.notExists(extractionDir)) { Files.createDirectories(extractionDir); } @@ -133,16 +133,16 @@ public static Path getExtractionDirectory() throws IOException { /** * Returns directory where applications places their files. Specific to operating system */ - private static String getApplicationsDir() { + private static Path getApplicationsDir() { String os = System.getProperty("os.name").toLowerCase(); - if (os.contains("linux")) { + if (os.startsWith("linux")) { String xdgDataHome = System.getenv("XDG_DATA_HOME"); if (xdgDataHome != null && !xdgDataHome.isEmpty()) { - return xdgDataHome; + return Paths.get(xdgDataHome); } - return Paths.get(System.getProperty("user.home"), ".local", "share").toString(); - } else if (os.contains("mac")) { - return Paths.get(System.getProperty("user.home"), "Library", "Application Support").toString(); + return Paths.get(System.getProperty("user.home"), ".local", "share"); + } else if (os.startsWith("macosx") || os.startsWith("mac os x")) { + return Paths.get(System.getProperty("user.home"), "Library", "Application Support"); } throw new UnsupportedOperationException("Unsupported os " + os); }