From c362498d66bbbd24893bf6eefbe56b48444e0931 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Mon, 19 May 2025 18:29:07 +0530 Subject: [PATCH 1/2] Add java-dotenv dependency and refactor Credentials class to use dotenv for environment variables --- pom.xml | 6 +++ .../com/contentstack/sdk/Credentials.java | 38 +++++++++---------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 579e0db1..bfd42d89 100644 --- a/pom.xml +++ b/pom.xml @@ -201,6 +201,12 @@ slf4j-simple 1.7.36 + + + io.github.cdimascio + java-dotenv + 5.2.2 + diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index e6dce57f..ea26750e 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -1,13 +1,12 @@ package com.contentstack.sdk; -import java.io.FileInputStream; -import java.io.IOException; import java.rmi.AccessException; import java.util.Arrays; -import java.util.Properties; +import io.github.cdimascio.dotenv.Dotenv; public class Credentials { - private static final Properties properties = new Properties(); + + static Dotenv env = getEnv(); private static String envChecker() { String githubActions = System.getenv("GITHUB_ACTIONS"); @@ -18,24 +17,25 @@ private static String envChecker() { } } - static { - try (FileInputStream inputStream = new FileInputStream("src/test/resources/test-config.properties")) { - properties.load(inputStream); - } catch (IOException e) { - System.err.println("Error loading properties file: " + e.getMessage()); - } - } + public static Dotenv getEnv() { + env = Dotenv.configure() + .directory("src/test/resources") + .filename("env") // instead of '.env', use 'env' + .load(); + + return Dotenv.load(); + } - public static final String HOST = properties.getProperty("HOST", "cdn.contentstack.io"); - public static final String API_KEY = properties.getProperty("API_KEY", ""); - public static final String DELIVERY_TOKEN = properties.getProperty("DELIVERY_TOKEN", ""); - public static final String ENVIRONMENT = properties.getProperty("ENVIRONMENT", "env1"); - public static final String CONTENT_TYPE = properties.getProperty("contentType", "product"); - public static final String ENTRY_UID = properties.getProperty("assetUid", ""); - public static final String VARIANT_UID = properties.getProperty("variantUid", ""); + public static final String HOST = env.get("HOST", "cdn.contentstack.io"); + public static final String API_KEY = env.get("API_KEY", ""); + public static final String DELIVERY_TOKEN = env.get("DELIVERY_TOKEN", ""); + public static final String ENVIRONMENT = env.get("ENVIRONMENT", "env1"); + public static final String CONTENT_TYPE = env.get("contentType", "product"); + public static final String ENTRY_UID = env.get("assetUid", ""); + public static final String VARIANT_UID = env.get("variantUid", ""); public final static String[] VARIANTS_UID; static { - String variantsUidString = properties.getProperty("variantsUid"); + String variantsUidString = env.get("variantsUid"); if (variantsUidString != null && !variantsUidString.trim().isEmpty()) { VARIANTS_UID = Arrays.stream(variantsUidString.split(",")) From 5f1fc3f7143f0acda39d7fe040e0651599ede821 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Mon, 19 May 2025 18:40:34 +0530 Subject: [PATCH 2/2] Add Kotlin standard library dependency to dependency management --- pom.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bfd42d89..7068efe5 100644 --- a/pom.xml +++ b/pom.xml @@ -209,7 +209,16 @@ - + + + + + org.jetbrains.kotlin + kotlin-stdlib + 2.1.0 + + +