From 60a320dc9e680868608efbd2e46ae0910b8ba5f2 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 22 Nov 2023 23:19:48 -0800 Subject: Added a Procfile - change settings config to env vars - allows for easier Heroku deployment Signed-off-by: Pinapelz --- Procfile | 1 + pom.xml | 28 +++------------------------- settings/config.json | 6 ------ src/main/java/Main.java | 13 +++++-------- src/main/java/utility/SpotifyAPI.java | 12 ++++-------- 5 files changed, 13 insertions(+), 47 deletions(-) create mode 100644 Procfile delete mode 100644 settings/config.json diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..a3d21af --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +worker: java $JAVA_OPTS -cp target/classes:target/dependency/* src/main/java/Main.java \ No newline at end of file diff --git a/pom.xml b/pom.xml index f47c925..ddccf53 100644 --- a/pom.xml +++ b/pom.xml @@ -67,40 +67,18 @@ clean package - - maven-dependency-plugin - 3.3.0 - org.apache.maven.plugins - maven-shade-plugin + maven-dependency-plugin 3.1.0 + copy-dependencies package - - shade - - - - - Main - - - false - true - + copy-dependencies - - org.apache.maven.plugins - maven-compiler-plugin - - 10 - 10 - - diff --git a/settings/config.json b/settings/config.json deleted file mode 100644 index c4eb359..0000000 --- a/settings/config.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "discordToken": "", - "youtubeApi": "", - "spotifyClientID": "", - "spotifyClientSecret": "" -} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index fbb066a..636cd3b 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -11,18 +11,15 @@ public class Main extends ListenerAdapter { public static void main( String[] args) { - new Music("$",readSetting("youtubeApi"),readSetting("discordToken")); + new Music("$",readSetting("YOUTUBEAPIKEY"),readSetting("DISCORDTOKEN")); } public static String readSetting(String parameter){ - Object obj = null; - try { - obj = new JSONParser().parse(new FileReader("settings//config.json")); - } catch (Exception e) { - e.printStackTrace(); + String value = System.getenv(parameter); + if (value != null) { + return value; } - JSONObject jo = (JSONObject) obj; - return (String) jo.get(parameter); + throw new RuntimeException("Environment variable " + parameter + " not found"); } diff --git a/src/main/java/utility/SpotifyAPI.java b/src/main/java/utility/SpotifyAPI.java index 4eb4d6e..acf79eb 100644 --- a/src/main/java/utility/SpotifyAPI.java +++ b/src/main/java/utility/SpotifyAPI.java @@ -83,15 +83,11 @@ public class SpotifyAPI { } } public static String readSetting(String parameter){ - Object obj = null; - - try { - obj = new JSONParser().parse(new FileReader("settings//config.json")); - } catch (Exception e) { - e.printStackTrace(); + String value = System.getenv(parameter); + if (value != null) { + return value; } - JSONObject jo = (JSONObject) obj; - return (String) jo.get(parameter); + throw new RuntimeException("Environment variable " + parameter + " not found"); } public static void checkRefreshToken(){ long unixTime = Instant.now().getEpochSecond(); -- cgit v1.2.3