From a156aa6dddaa8620d6306ec4e0fdc81efa2de736 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Tue, 8 Aug 2023 18:44:08 +0530 Subject: [PATCH 01/29] Utils update --- .env | 0 .github/workflows/sast-scan.yml | 11 --- .github/workflows/secrets-scan.yml | 11 --- CHANGELOG.md | 13 +++ pom.xml | 10 +-- .../java/com/contentstack/sdk/Constants.java | 2 +- .../com/contentstack/sdk/Credentials.java | 87 +++++++++++++++++++ .../java/com/contentstack/sdk/TestAsset.java | 16 +--- .../contentstack/sdk/TestAssetLibrary.java | 24 +---- .../com/contentstack/sdk/TestContentType.java | 13 +-- .../contentstack/sdk/TestContentstack.java | 9 +- .../sdk/TestContentstackPlugin.java | 56 +++++------- .../java/com/contentstack/sdk/TestEntry.java | 23 +---- .../java/com/contentstack/sdk/TestQuery.java | 25 +----- .../com/contentstack/sdk/TestQueryCase.java | 19 +--- .../java/com/contentstack/sdk/TestStack.java | 36 ++------ 16 files changed, 151 insertions(+), 204 deletions(-) create mode 100644 .env delete mode 100644 .github/workflows/sast-scan.yml delete mode 100644 .github/workflows/secrets-scan.yml create mode 100644 src/test/java/com/contentstack/sdk/Credentials.java diff --git a/.env b/.env new file mode 100644 index 00000000..e69de29b diff --git a/.github/workflows/sast-scan.yml b/.github/workflows/sast-scan.yml deleted file mode 100644 index f9316303..00000000 --- a/.github/workflows/sast-scan.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: SAST Scan -on: - pull_request: - types: [opened, synchronize, reopened] -jobs: - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Horusec Scan - run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/src horuszup/horusec-cli:latest horusec start -p /src -P $(pwd) \ No newline at end of file diff --git a/.github/workflows/secrets-scan.yml b/.github/workflows/secrets-scan.yml deleted file mode 100644 index f62d12dc..00000000 --- a/.github/workflows/secrets-scan.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Secrets Scan -on: - pull_request: - types: [ opened, synchronize, reopened ] -jobs: - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Gittyleaks - uses: gupy-io/gittyleaks-action@v0.1 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 395dcbab..35b14704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ # CHANGELOG +## v1.12.2 + +### Date: 08-AUG-2023 + +- Updated Utils SDK to v1.2.3 + +## v1.12.1 + +### Date: 07-Jun-2023 + +- Added Support For Nested Assets +- General Code Improvement + ## v1.12.0 ### Date: 25-APR-2023 diff --git a/pom.xml b/pom.xml index 73e00663..ffdf99f3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.contentstack.sdk java - 1.12.1-SNAPSHOT + 1.12.2-SNAPSHOT jar contentstack-java Java SDK for Contentstack Content Delivery API @@ -22,7 +22,6 @@ 3.0.0 3.1.6 2.9.0 - 2.9.0 4.11.0 0.8.5 1.18.28 @@ -37,7 +36,7 @@ 20230227 0.8.7 2.5.3 - 1.2.2 + 1.2.3 @@ -129,12 +128,13 @@ ${retrofit-source.version} compile + com.squareup.retrofit2 converter-gson - ${converter-gson-source.version} - compile + ${retrofit-source.version} + com.squareup.okhttp3 logging-interceptor diff --git a/src/main/java/com/contentstack/sdk/Constants.java b/src/main/java/com/contentstack/sdk/Constants.java index a6500e1e..5a1c19c7 100644 --- a/src/main/java/com/contentstack/sdk/Constants.java +++ b/src/main/java/com/contentstack/sdk/Constants.java @@ -21,7 +21,7 @@ public class Constants { private static final Logger logger = Logger.getLogger(Constants.class.getSimpleName()); - protected static final String SDK_VERSION = "1.12.1"; + protected static final String SDK_VERSION = "1.12.2"; protected static final String ENVIRONMENT = "environment"; protected static final String CONTENT_TYPE_UID = "content_type_uid"; protected static final String ENTRY_UID = "entry_uid"; diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java new file mode 100644 index 00000000..ae63a081 --- /dev/null +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -0,0 +1,87 @@ +package com.contentstack.sdk; + +import io.github.cdimascio.dotenv.Dotenv; +import io.github.cdimascio.dotenv.DotenvException; + +import java.io.File; +import java.io.IOException; +import java.rmi.AccessException; + +public class Credentials { + static Dotenv env = getEnv(); + + /** + * The provided Java code defines a method named `getEnv()` that attempts to load environment variables from a `.env` file using the `Dotenv` library. If loading the environment variables encounters an exception (specifically, a `DotenvException`), the code takes an alternative path by creating an empty `.env` file in the current working directory. + *

+ * Here's a breakdown of what the code is doing step by step: + *

+ * 1. The method `public static Dotenv getEnv()` is defined. It returns an instance of the `Dotenv` class, which is used to manage environment variables loaded from the `.env` file. + *

+ * 2. Inside the `try` block, the code tries to load environment variables using `Dotenv.load()`. If successful, the loaded environment variables are stored in the `env` variable. + *

+ * 3. If loading the environment variables from the `.env` file encounters an exception (a `DotenvException`), the code enters the `catch` block. + *

+ * 4. In the `catch` block, it gets the current working directory using `System.getProperty("user.dir")` and creates a `File` object named `envFile` representing the `.env` file in the current directory. + *

+ * 5. The code attempts to create an empty `.env` file using `envFile.createNewFile()`. + *

+ * 6. If there's an error during the file creation process (an `IOException`), an error message is printed to the standard error output, and the exception's stack trace is printed for debugging purposes. + *

+ * 7. Finally, regardless of whether the environment variables were successfully loaded or a new `.env` file was created, the method returns the `env` variable, which may either contain the loaded environment variables or be `null` if an exception occurred during the loading process. + *

+ * In summary, this code defines a method that attempts to load environment variables from a `.env` file using the `Dotenv` library. If loading fails due to an exception, it creates an empty `.env` file in the current working directory and then returns the `Dotenv` instance, which may or may not have loaded environment variables depending on whether an exception occurred. + * + * @return Dotenv + */ + public static Dotenv getEnv() { + try { + env = Dotenv.load(); + } catch (DotenvException ex) { + String currentDirectory = System.getProperty("user.dir"); + File envFile = new File(currentDirectory, ".env"); + try { + // Create .env file in the current directory + envFile.createNewFile(); + } catch (IOException e) { + System.err.println("An error occurred while creating .env file."); + e.printStackTrace(); + } + } + return env; + } + + + public final static String pwd = (env.get("PWD") != null) ? env.get("PWD") : "contentstack-java"; + public final static String HOST = (env.get("HOST") != null) ? env.get("HOST") : "cdn.contentstack.io"; + public final static String API_KEY = (env.get("API_KEY") != null) ? env.get("API_KEY") : "blt12c8ad610ff4ddc2"; + public final static String DELIVERY_TOKEN = (env.get("DELIVERY_TOKEN") != null) ? env.get("DELIVERY_TOKEN") : "cs9c1afdffa298f8708e3459e4"; + public final static String ENVIRONMENT = (env.get("ENVIRONMENT") != null) ? env.get("ENVIRONMENT") : "env1"; + public final static String CONTENT_TYPE = (env.get("contentType") != null) ? env.get("contentType") : "product"; + public final static String ENTRY_UID = (env.get("assetUid") != null) ? env.get("assetUid") : "blt884786476373"; + + private static Stack stack; + + private Credentials() throws AccessException { + // Private constructor to prevent direct instantiation + throw new AccessException("Can not access credential access"); + } + + public static Stack getStack() { + + if (stack == null) { + synchronized (Credentials.class) { + if (stack == null) { + try { + Config config = new Config(); + config.setHost(HOST); + stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, config); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + } + return stack; + } + +} diff --git a/src/test/java/com/contentstack/sdk/TestAsset.java b/src/test/java/com/contentstack/sdk/TestAsset.java index 2bfd69ae..30197a17 100644 --- a/src/test/java/com/contentstack/sdk/TestAsset.java +++ b/src/test/java/com/contentstack/sdk/TestAsset.java @@ -1,6 +1,5 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import org.json.JSONObject; import org.junit.jupiter.api.*; @@ -11,21 +10,10 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class TestAsset { - protected String API_KEY, DELIVERY_TOKEN, ENV; private final Logger logger = Logger.getLogger(TestAsset.class.getName()); private String assetUid; - private Stack stack; - - @BeforeAll - public void initBeforeTests() throws IllegalAccessException { - Dotenv dotenv = Dotenv.load(); - API_KEY = dotenv.get("API_KEY"); - DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - ENV = dotenv.get("ENVIRONMENT"); - Config config = new Config(); - config.setHost(dotenv.get("HOST")); - stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config); - } + private Stack stack = Credentials.getStack(); + @Test @Order(1) diff --git a/src/test/java/com/contentstack/sdk/TestAssetLibrary.java b/src/test/java/com/contentstack/sdk/TestAssetLibrary.java index 8a3d8617..6e49a061 100644 --- a/src/test/java/com/contentstack/sdk/TestAssetLibrary.java +++ b/src/test/java/com/contentstack/sdk/TestAssetLibrary.java @@ -1,6 +1,5 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import org.junit.jupiter.api.*; import java.util.List; @@ -11,21 +10,9 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class TestAssetLibrary { - - protected String API_KEY, DELIVERY_TOKEN, ENV; private final Logger logger = Logger.getLogger(TestAssetLibrary.class.getName()); - private Stack stack; + private final Stack stack = Credentials.getStack(); - @BeforeAll - public void initBeforeTests() throws IllegalAccessException { - Dotenv dotenv = Dotenv.load(); - API_KEY = dotenv.get("API_KEY"); - DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - ENV = dotenv.get("ENVIRONMENT"); - Config config = new Config(); - config.setHost(dotenv.get("HOST")); - stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config); - } @Test @Order(1) @@ -55,7 +42,6 @@ void testAssetSetHeader() { AssetLibrary assetLibrary = stack.assetLibrary(); assetLibrary.setHeader("headerKey", "headerValue"); Assertions.assertTrue(assetLibrary.headers.containsKey("headerKey")); - logger.info("passed..."); } @Test @@ -64,14 +50,12 @@ void testAssetRemoveHeader() { assetLibrary.setHeader("headerKey", "headerValue"); assetLibrary.removeHeader("headerKey"); Assertions.assertFalse(assetLibrary.headers.containsKey("headerKey")); - logger.info("passed..."); } @Test void testAssetSortAscending() { AssetLibrary assetLibrary = stack.assetLibrary().sort("ascending", AssetLibrary.ORDERBY.ASCENDING); Assertions.assertFalse(assetLibrary.headers.containsKey("asc")); - logger.info("passed..."); } @Test @@ -79,14 +63,12 @@ void testAssetSortDescending() { AssetLibrary assetLibrary = stack.assetLibrary(); assetLibrary.sort("descending", AssetLibrary.ORDERBY.DESCENDING); Assertions.assertFalse(assetLibrary.headers.containsKey("desc")); - logger.info("passed..."); } @Test void testAssetIncludeCount() { AssetLibrary assetLibrary = stack.assetLibrary().includeCount(); Assertions.assertFalse(assetLibrary.headers.containsKey("include_count")); - logger.info("passed..."); } @Test @@ -94,27 +76,23 @@ void testAssetIncludeRelativeUrl() { AssetLibrary assetLibrary = stack.assetLibrary(); assetLibrary.includeRelativeUrl(); Assertions.assertFalse(assetLibrary.headers.containsKey("relative_urls")); - logger.info("passed..."); } @Test void testAssetGetCount() { AssetLibrary assetLibrary = stack.assetLibrary().includeRelativeUrl(); Assertions.assertEquals(0, assetLibrary.getCount()); - logger.info("passed..."); } @Test void testIncludeFallback() { AssetLibrary assetLibrary = stack.assetLibrary().includeFallback(); Assertions.assertFalse(assetLibrary.headers.containsKey("include_fallback")); - logger.info("passed..."); } @Test void testIncludeOwner() { AssetLibrary assetLibrary = stack.assetLibrary().includeMetadata(); Assertions.assertFalse(assetLibrary.headers.containsKey("include_owner")); - logger.info("passed..."); } } diff --git a/src/test/java/com/contentstack/sdk/TestContentType.java b/src/test/java/com/contentstack/sdk/TestContentType.java index 1a3af487..3477c3f3 100644 --- a/src/test/java/com/contentstack/sdk/TestContentType.java +++ b/src/test/java/com/contentstack/sdk/TestContentType.java @@ -1,6 +1,5 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.*; @@ -11,18 +10,8 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class TestContentType { - protected String API_KEY, DELIVERY_TOKEN, ENV; private final Logger logger = Logger.getLogger(TestContentType.class.getName()); - private Stack stack; - - @BeforeAll - public void initBeforeTests() throws IllegalAccessException { - Dotenv dotenv = Dotenv.load(); - API_KEY = dotenv.get("API_KEY"); - DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - ENV = dotenv.get("ENVIRONMENT"); - stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV); - } + private final Stack stack = Credentials.getStack(); @Test @Order(1) diff --git a/src/test/java/com/contentstack/sdk/TestContentstack.java b/src/test/java/com/contentstack/sdk/TestContentstack.java index 700e0ab7..c4c20d98 100644 --- a/src/test/java/com/contentstack/sdk/TestContentstack.java +++ b/src/test/java/com/contentstack/sdk/TestContentstack.java @@ -1,6 +1,5 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -16,10 +15,9 @@ class TestContentstack { @BeforeAll public void initBeforeTests() { - Dotenv dotenv = Dotenv.load(); - API_KEY = dotenv.get("API_KEY"); - DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - ENV = dotenv.get("ENVIRONMENT"); + API_KEY = Credentials.API_KEY; + DELIVERY_TOKEN = Credentials.DELIVERY_TOKEN; + ENV = Credentials.ENVIRONMENT; } @Test @@ -35,7 +33,6 @@ void initStackPrivateModifier() { @Test void initStackWithNullAPIKey() { try { - Contentstack.stack(null, DELIVERY_TOKEN, ENV); } catch (Exception e) { logger.info(e.getLocalizedMessage()); diff --git a/src/test/java/com/contentstack/sdk/TestContentstackPlugin.java b/src/test/java/com/contentstack/sdk/TestContentstackPlugin.java index ea0c67fc..48223995 100644 --- a/src/test/java/com/contentstack/sdk/TestContentstackPlugin.java +++ b/src/test/java/com/contentstack/sdk/TestContentstackPlugin.java @@ -1,8 +1,8 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import okhttp3.Request; import org.junit.jupiter.api.*; + import java.util.ArrayList; @@ -10,15 +10,7 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class TestContentstackPlugin { - protected String API_KEY, DELIVERY_TOKEN, ENV; - - @BeforeAll - public void initBeforeTests() { - Dotenv dotenv = Dotenv.load(); - API_KEY = dotenv.get("API_KEY"); - DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - ENV = dotenv.get("ENVIRONMENT"); - } + final Stack stack = Credentials.getStack(); static class Plugin1 implements ContentstackPlugin { @@ -56,31 +48,25 @@ public retrofit2.Response onResponse(Stack stack, Request @Test @Order(1) void testContentstackPlugin() { - try { - ArrayList plugins = new ArrayList<>(); - Plugin1 plugin1 = new Plugin1(); - Plugin2 plugin2 = new Plugin2(); - - plugins.add(plugin1); - plugins.add(plugin2); - - // Create a config instance: - Config config = new Config(); - config.setPlugins(plugins); - - Stack stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config); - ContentType contentType = stack.contentType("fakeCT"); - Entry entry = contentType.entry("something_demo"); - entry.fetch(new EntryResultCallBack() { - @Override - public void onCompletion(ResponseType responseType, Error error) { - Assertions.assertTrue(true); - } - }); - - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } + ArrayList plugins = new ArrayList<>(); + Plugin1 plugin1 = new Plugin1(); + Plugin2 plugin2 = new Plugin2(); + + plugins.add(plugin1); + plugins.add(plugin2); + + // Create a config instance: + Config config = new Config(); + config.setPlugins(plugins); + + ContentType contentType = stack.contentType("fakeCT"); + Entry entry = contentType.entry("something_demo"); + entry.fetch(new EntryResultCallBack() { + @Override + public void onCompletion(ResponseType responseType, Error error) { + Assertions.assertTrue(true); + } + }); } } diff --git a/src/test/java/com/contentstack/sdk/TestEntry.java b/src/test/java/com/contentstack/sdk/TestEntry.java index 590eb279..7dfc7d5e 100644 --- a/src/test/java/com/contentstack/sdk/TestEntry.java +++ b/src/test/java/com/contentstack/sdk/TestEntry.java @@ -1,6 +1,5 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import org.json.JSONObject; import org.junit.jupiter.api.*; @@ -15,24 +14,10 @@ class TestEntry { private final Logger logger = Logger.getLogger(TestEntry.class.getName()); - private String DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV; - private final String CONTENT_TYPE = "product"; - private String entryUid = "justFakeIt"; - private Stack stack; + private String entryUid = Credentials.ENTRY_UID; + private final Stack stack = Credentials.getStack(); private Entry entry; - - @BeforeAll - public void intOnceBeforeAll() throws Exception { - Dotenv dotenv = Dotenv.load(); - DEFAULT_API_KEY = dotenv.get("API_KEY"); - DEFAULT_DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - DEFAULT_ENV = dotenv.get("ENVIRONMENT"); - String DEFAULT_HOST = dotenv.get("HOST"); - Config config = new Config(); - config.setHost(DEFAULT_HOST); - assert DEFAULT_API_KEY != null; - stack = Contentstack.stack(DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config); - } + private final String CONTENT_TYPE = Credentials.CONTENT_TYPE; @Test @Order(1) @@ -518,7 +503,7 @@ void testEntryIncludeOwner() { void testEntryPassConfigBranchIncludeBranch() throws IllegalAccessException { Config config = new Config(); config.setBranch("feature_branch"); - Stack branchStack = Contentstack.stack(DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config); + Stack branchStack = Contentstack.stack(Credentials.API_KEY, Credentials.DELIVERY_TOKEN, Credentials.ENVIRONMENT, config); Entry entry = branchStack.contentType("product").entry(entryUid); entry.includeBranch().fetch(new EntryResultCallBack() { @Override diff --git a/src/test/java/com/contentstack/sdk/TestQuery.java b/src/test/java/com/contentstack/sdk/TestQuery.java index 9e56f282..5cabc1d1 100644 --- a/src/test/java/com/contentstack/sdk/TestQuery.java +++ b/src/test/java/com/contentstack/sdk/TestQuery.java @@ -1,13 +1,11 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import org.json.JSONObject; import org.junit.jupiter.api.*; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -18,28 +16,14 @@ class TestQuery { private final Logger logger = Logger.getLogger(TestQuery.class.getName()); - private String DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV; - private Stack stack; + private final Stack stack = Credentials.getStack(); + private final String contentType = Credentials.CONTENT_TYPE; private Query query; private String entryUid; - @BeforeAll - public void beforeAll() throws IllegalAccessException { - logger.setLevel(Level.FINE); - Dotenv dotenv = Dotenv.load(); - DEFAULT_API_KEY = dotenv.get("API_KEY"); - DEFAULT_DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - DEFAULT_ENV = dotenv.get("ENVIRONMENT"); - String DEFAULT_HOST = dotenv.get("HOST"); - Config config = new Config(); - config.setHost(DEFAULT_HOST); - assert DEFAULT_API_KEY != null; - stack = Contentstack.stack(DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config); - } - @BeforeEach public void beforeEach() { - query = stack.contentType("product").query(); + query = stack.contentType(contentType).query(); } @Test @@ -863,7 +847,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err void testQueryPassConfigBranchIncludeBranch() throws IllegalAccessException { Config config = new Config(); config.setBranch("feature_branch"); - Stack branchStack = Contentstack.stack(DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config); + Stack branchStack = Contentstack.stack(Credentials.API_KEY, Credentials.DELIVERY_TOKEN, Credentials.ENVIRONMENT, config); Query query = branchStack.contentType("product").query(); query.includeBranch().find(new QueryResultsCallBack() { @Override @@ -874,7 +858,6 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err Assertions.assertTrue(query.urlQueries.has("include_branch")); Assertions.assertEquals(true, query.urlQueries.opt("include_branch")); Assertions.assertTrue(query.headers.containsKey("branch")); - logger.info("passed..."); } } \ No newline at end of file diff --git a/src/test/java/com/contentstack/sdk/TestQueryCase.java b/src/test/java/com/contentstack/sdk/TestQueryCase.java index 0010d60e..05bdbf13 100644 --- a/src/test/java/com/contentstack/sdk/TestQueryCase.java +++ b/src/test/java/com/contentstack/sdk/TestQueryCase.java @@ -1,6 +1,5 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.*; @@ -8,7 +7,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -19,25 +17,10 @@ class TestQueryCase { private final Logger logger = Logger.getLogger(TestQueryCase.class.getName()); - private Stack stack; + private final Stack stack = Credentials.getStack(); private Query query; private String entryUid; - @BeforeAll - public void beforeAll() throws IllegalAccessException { - logger.setLevel(Level.FINE); - Dotenv dotenv = Dotenv.load(); - String DEFAULT_API_KEY = dotenv.get("API_KEY"); - String DEFAULT_DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - String DEFAULT_ENV = dotenv.get("ENVIRONMENT"); - String DEFAULT_HOST = dotenv.get("HOST"); - Config config = new Config(); - config.setHost(DEFAULT_HOST); - //config.setRegion(Config.ContentstackRegion.US); - assert DEFAULT_API_KEY != null; - stack = Contentstack.stack(DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config); - } - @BeforeEach public void beforeEach() { query = stack.contentType("product").query(); diff --git a/src/test/java/com/contentstack/sdk/TestStack.java b/src/test/java/com/contentstack/sdk/TestStack.java index 476453c5..b59ad734 100644 --- a/src/test/java/com/contentstack/sdk/TestStack.java +++ b/src/test/java/com/contentstack/sdk/TestStack.java @@ -1,6 +1,5 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; import org.json.JSONArray; import org.json.JSONObject; import org.junit.jupiter.api.*; @@ -10,26 +9,16 @@ import java.util.LinkedHashMap; import java.util.logging.Logger; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; @TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestMethodOrder(MethodOrderer.OrderAnnotation.class) class TestStack { - Stack stack; - protected String API_KEY, DELIVERY_TOKEN, ENV; + Stack stack = Credentials.getStack(); protected String paginationToken; private final Logger logger = Logger.getLogger(TestStack.class.getName()); - @BeforeEach - public void initBeforeTests() throws IllegalAccessException { - Dotenv dotenv = Dotenv.load(); - API_KEY = dotenv.get("API_KEY"); - DELIVERY_TOKEN = dotenv.get("DELIVERY_TOKEN"); - ENV = dotenv.get("ENVIRONMENT"); - stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV); - } @Test @Order(1) @@ -107,7 +96,7 @@ void testGetApiKey() { @Test @Order(13) void testGetDeliveryToken() { - assertTrue(stack.getDeliveryToken().startsWith("blt")); + assertNotNull(stack.getDeliveryToken()); } @Test @@ -115,13 +104,13 @@ void testGetDeliveryToken() { void testRemoveHeader() { stack.removeHeader("environment"); Assertions.assertFalse(stack.headers.containsKey("environment")); - stack.setHeader("environment", ENV); + stack.setHeader("environment", Credentials.ENVIRONMENT); } @Test @Order(16) void testSetHeader() { - stack.setHeader("environment", ENV); + stack.setHeader("environment", Credentials.ENVIRONMENT); assertTrue(stack.headers.containsKey("environment")); } @@ -221,7 +210,7 @@ void testSyncLocaleWithoutCallback() { @Test @Order(28) void testSyncPublishTypeEntryPublished() { - // deepcode ignore NullPassTo/test: + // decode ignore NullPassTo/test: stack.syncPublishType(Stack.PublishType.ENTRY_PUBLISHED, null); assertEquals(3, stack.syncParams.length()); assertEquals("entry_published", stack.syncParams.get("type")); @@ -282,7 +271,7 @@ void testSyncPublishTypeEntryDeleted() { @Test @Order(34) void testSyncPublishTypeEntryUnpublished() { - // deepcode ignore NullPassTo/test: + // decode ignore NullPassTo/test: stack.syncPublishType(Stack.PublishType.ENTRY_UNPUBLISHED, null); assertEquals(3, stack.syncParams.length()); assertEquals("entry_unpublished", stack.syncParams.get("type")); @@ -360,11 +349,7 @@ void testConfigGetHost() { @Disabled("No relevant code") @Order(41) void testSynchronizationAPIRequest() throws IllegalAccessException { - Dotenv dotenv = Dotenv.load(); - String apiKey = dotenv.get("API_KEY"); - String deliveryToken = dotenv.get("DELIVERY_TOKEN"); - String env = dotenv.get("ENVIRONMENT"); - Stack stack = Contentstack.stack(apiKey, deliveryToken, env); + stack.sync(new SyncResultCallBack() { @Override public void onCompletion(SyncStack response, Error error) { @@ -385,11 +370,6 @@ public void onCompletion(SyncStack response, Error error) { @Disabled("No relevant code") @Order(42) void testSyncPaginationToken() throws IllegalAccessException { - Dotenv dotenv = Dotenv.load(); - String apiKey = dotenv.get("API_KEY"); - String deliveryToken = dotenv.get("DELIVERY_TOKEN"); - String env = dotenv.get("ENVIRONMENT"); - Stack stack = Contentstack.stack(apiKey, deliveryToken, env); stack.syncPaginationToken(paginationToken, new SyncResultCallBack() { @Override public void onCompletion(SyncStack response, Error error) { From 8bfb5745cea7433a11e032417e994b46e9cd8807 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Tue, 8 Aug 2023 18:49:44 +0530 Subject: [PATCH 02/29] Utils update --- .github/workflows/maven-publish.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index e10b45d5..17cb45e8 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,7 +1,8 @@ name: Publish package to the Maven Central Repository -on: - release: - types: [ created ] +on: [ push ] # Trigger the workflow when a push (commit) event occurs +#on: +# release: +# types: [ created ] jobs: publish-maven: runs-on: ubuntu-latest From 280bc9a8fb5472a9c4c64b641abbc62755239c6d Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 9 Aug 2023 17:05:31 +0530 Subject: [PATCH 03/29] Utils update --- pom.xml | 6 ++++- .../com/contentstack/sdk/Credentials.java | 26 +++++++++++-------- .env => src/test/resources/env | 0 3 files changed, 20 insertions(+), 12 deletions(-) rename .env => src/test/resources/env (100%) diff --git a/pom.xml b/pom.xml index ffdf99f3..4ec1d93a 100644 --- a/pom.xml +++ b/pom.xml @@ -104,24 +104,28 @@ ${contentstack-utils-version} compile + org.json json ${json-version} compile + io.github.cdimascio dotenv-java ${dotenv-source.version} - runtime + + io.reactivex.rxjava3 rxjava ${rxjava-source.version} compile + com.squareup.retrofit2 retrofit diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index ae63a081..79c15493 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -3,8 +3,6 @@ import io.github.cdimascio.dotenv.Dotenv; import io.github.cdimascio.dotenv.DotenvException; -import java.io.File; -import java.io.IOException; import java.rmi.AccessException; public class Credentials { @@ -34,18 +32,24 @@ public class Credentials { * @return Dotenv */ public static Dotenv getEnv() { + String currentDirectory = System.getProperty("user.dir"); + //File envFile = new File(currentDirectory, "env"); + env = Dotenv.configure() + .directory("src/test/resources") + .filename("env") // instead of '.env', use 'env' + .load(); try { env = Dotenv.load(); } catch (DotenvException ex) { - String currentDirectory = System.getProperty("user.dir"); - File envFile = new File(currentDirectory, ".env"); - try { - // Create .env file in the current directory - envFile.createNewFile(); - } catch (IOException e) { - System.err.println("An error occurred while creating .env file."); - e.printStackTrace(); - } + System.out.println("Could not load from local .env"); +// File envFile = new File(currentDirectory, ".env"); +// try { +// // Create .env file in the current directory +// envFile.createNewFile(); +// } catch (IOException e) { +// System.err.println("An error occurred while creating .env file."); +// e.printStackTrace(); +// } } return env; } diff --git a/.env b/src/test/resources/env similarity index 100% rename from .env rename to src/test/resources/env From 7b4898586299748ac8c6fff94cf756efd1568d90 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 9 Aug 2023 17:09:53 +0530 Subject: [PATCH 04/29] Utils update --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4ec1d93a..f4886e8e 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ - 1.8 - 1.8 + 11 + 11 UTF-8 2.22.0 2.2.1 From 730fcf9ee4ab890613dd6fec9a4372d276c809d6 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 9 Aug 2023 17:13:43 +0530 Subject: [PATCH 05/29] run ci --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f4886e8e..4ec1d93a 100644 --- a/pom.xml +++ b/pom.xml @@ -13,8 +13,8 @@ - 11 - 11 + 1.8 + 1.8 UTF-8 2.22.0 2.2.1 From 030dfe48a35b3398c853c721b7eee56561b81c01 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 9 Aug 2023 18:44:57 +0530 Subject: [PATCH 06/29] run ci --- .../com/contentstack/sdk/Credentials.java | 109 +++++++++--------- .../java/com/contentstack/sdk/TestAsset.java | 15 ++- 2 files changed, 67 insertions(+), 57 deletions(-) diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index 79c15493..d1b9a99b 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -1,78 +1,75 @@ package com.contentstack.sdk; -import io.github.cdimascio.dotenv.Dotenv; -import io.github.cdimascio.dotenv.DotenvException; +import lombok.var; import java.rmi.AccessException; public class Credentials { - static Dotenv env = getEnv(); + //static Dotenv env = getEnv(); - /** - * The provided Java code defines a method named `getEnv()` that attempts to load environment variables from a `.env` file using the `Dotenv` library. If loading the environment variables encounters an exception (specifically, a `DotenvException`), the code takes an alternative path by creating an empty `.env` file in the current working directory. - *

- * Here's a breakdown of what the code is doing step by step: - *

- * 1. The method `public static Dotenv getEnv()` is defined. It returns an instance of the `Dotenv` class, which is used to manage environment variables loaded from the `.env` file. - *

- * 2. Inside the `try` block, the code tries to load environment variables using `Dotenv.load()`. If successful, the loaded environment variables are stored in the `env` variable. - *

- * 3. If loading the environment variables from the `.env` file encounters an exception (a `DotenvException`), the code enters the `catch` block. - *

- * 4. In the `catch` block, it gets the current working directory using `System.getProperty("user.dir")` and creates a `File` object named `envFile` representing the `.env` file in the current directory. - *

- * 5. The code attempts to create an empty `.env` file using `envFile.createNewFile()`. - *

- * 6. If there's an error during the file creation process (an `IOException`), an error message is printed to the standard error output, and the exception's stack trace is printed for debugging purposes. - *

- * 7. Finally, regardless of whether the environment variables were successfully loaded or a new `.env` file was created, the method returns the `env` variable, which may either contain the loaded environment variables or be `null` if an exception occurred during the loading process. - *

- * In summary, this code defines a method that attempts to load environment variables from a `.env` file using the `Dotenv` library. If loading fails due to an exception, it creates an empty `.env` file in the current working directory and then returns the `Dotenv` instance, which may or may not have loaded environment variables depending on whether an exception occurred. - * - * @return Dotenv - */ - public static Dotenv getEnv() { - String currentDirectory = System.getProperty("user.dir"); - //File envFile = new File(currentDirectory, "env"); - env = Dotenv.configure() - .directory("src/test/resources") - .filename("env") // instead of '.env', use 'env' - .load(); - try { - env = Dotenv.load(); - } catch (DotenvException ex) { - System.out.println("Could not load from local .env"); -// File envFile = new File(currentDirectory, ".env"); -// try { -// // Create .env file in the current directory -// envFile.createNewFile(); -// } catch (IOException e) { -// System.err.println("An error occurred while creating .env file."); -// e.printStackTrace(); -// } + private static String envChecker() { + String githubActions = System.getenv("GITHUB_ACTIONS"); + if (githubActions != null && githubActions.equals("true")) { + System.out.println("Tests are running in GitHub Actions environment."); + String mySecretKey = System.getenv("API_KEY"); + System.out.println("My Secret Key: " + mySecretKey); + return "GitHub"; + } else { + System.out.println("Tests are running in a local environment."); + return "local"; } - return env; } +// public static Dotenv getEnv() { +// String currentDirectory = System.getProperty("user.dir"); +// File envFile = new File(currentDirectory, "env"); +// env = Dotenv.configure() +// .directory("src/test/resources") +// .filename("env") // instead of '.env', use 'env' +// .load(); +// try { +// env = Dotenv.load(); +// } catch (DotenvException ex) { +// System.out.println("Could not load from local .env"); +//// File envFile = new File(currentDirectory, ".env"); +//// try { +//// // Create .env file in the current directory +//// envFile.createNewFile(); +//// } catch (IOException e) { +//// System.err.println("An error occurred while creating .env file."); +//// e.printStackTrace(); +//// } +// } +// return env; +// } - public final static String pwd = (env.get("PWD") != null) ? env.get("PWD") : "contentstack-java"; - public final static String HOST = (env.get("HOST") != null) ? env.get("HOST") : "cdn.contentstack.io"; - public final static String API_KEY = (env.get("API_KEY") != null) ? env.get("API_KEY") : "blt12c8ad610ff4ddc2"; - public final static String DELIVERY_TOKEN = (env.get("DELIVERY_TOKEN") != null) ? env.get("DELIVERY_TOKEN") : "cs9c1afdffa298f8708e3459e4"; - public final static String ENVIRONMENT = (env.get("ENVIRONMENT") != null) ? env.get("ENVIRONMENT") : "env1"; - public final static String CONTENT_TYPE = (env.get("contentType") != null) ? env.get("contentType") : "product"; - public final static String ENTRY_UID = (env.get("assetUid") != null) ? env.get("assetUid") : "blt884786476373"; - private static Stack stack; +// public final static String pwd = (env.get("PWD") != null) ? env.get("PWD") : "contentstack-java"; +// public final static String HOST = (env.get("HOST") != null) ? env.get("HOST") : "cdn.contentstack.io"; +// public final static String API_KEY = (env.get("API_KEY") != null) ? env.get("API_KEY") : "blt12c8ad610ff4ddc2"; +// public final static String DELIVERY_TOKEN = (env.get("DELIVERY_TOKEN") != null) ? env.get("DELIVERY_TOKEN") : "cs9c1afdffa298f8708e3459e4"; +// public final static String ENVIRONMENT = (env.get("ENVIRONMENT") != null) ? env.get("ENVIRONMENT") : "env1"; +// public final static String CONTENT_TYPE = (env.get("contentType") != null) ? env.get("contentType") : "product"; +// public final static String ENTRY_UID = (env.get("assetUid") != null) ? env.get("assetUid") : "blt884786476373"; + + + public final static String HOST = "cdn.contentstack.io"; + public final static String API_KEY = "blt12c8ad610ff4ddc2"; + public final static String DELIVERY_TOKEN = "cs9c1afdffa298f8708e3459e4"; + public final static String ENVIRONMENT = "env1"; + public final static String CONTENT_TYPE = "product"; + public final static String ENTRY_UID = "blt884786476373"; + + private static volatile Stack stack; private Credentials() throws AccessException { - // Private constructor to prevent direct instantiation throw new AccessException("Can not access credential access"); } public static Stack getStack() { - if (stack == null) { + var envCheck = envChecker(); + System.out.println(envCheck); synchronized (Credentials.class) { if (stack == null) { try { diff --git a/src/test/java/com/contentstack/sdk/TestAsset.java b/src/test/java/com/contentstack/sdk/TestAsset.java index 30197a17..0991b583 100644 --- a/src/test/java/com/contentstack/sdk/TestAsset.java +++ b/src/test/java/com/contentstack/sdk/TestAsset.java @@ -12,12 +12,25 @@ class TestAsset { private final Logger logger = Logger.getLogger(TestAsset.class.getName()); private String assetUid; - private Stack stack = Credentials.getStack(); + private final Stack stack = Credentials.getStack(); + private String envChecker() { + String githubActions = System.getenv("GITHUB_ACTIONS"); + if (githubActions != null && githubActions.equals("true")) { + System.out.println("Tests are running in GitHub Actions environment."); + String mySecretKey = System.getenv("API_KEY"); + System.out.println("My Secret Key: " + mySecretKey); + return "GitHub"; + } else { + System.out.println("Tests are running in a local environment."); + return "local"; + } + } @Test @Order(1) void testNewAssetLibrary() { + envChecker(); AssetLibrary assets = stack.assetLibrary(); assets.fetchAll(new FetchAssetsCallback() { @Override From 5cb11d6d112133b7c10ec7645f0d1841b85c01b7 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 11:19:12 +0530 Subject: [PATCH 07/29] run ci --- .github/workflows/maven-publish.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 17cb45e8..91c37f88 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -11,10 +11,14 @@ jobs: packages: write steps: - uses: actions/checkout@v3 + - name: Import GPG Key + run: | + echo "$GPG_PRIVATE_KEY" | gpg --import + echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust - name: Set up Maven Central Repository uses: actions/setup-java@v3 with: - java-version: '8' + java-version: '11' distribution: 'adopt' server-id: ossrh server-username: ${{ secrets.OSSRH_USERNAME }} @@ -29,7 +33,7 @@ jobs: - name: Set up Java for publishing to GitHub Packages uses: actions/setup-java@v3 with: - java-version: '8' + java-version: '11' distribution: 'adopt' server-id: github - name: Publish to GitHub Packages From b8d0a866e24e87ccc17bd1112a9349de4fe19de5 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 11:34:16 +0530 Subject: [PATCH 08/29] run ci --- .github/workflows/maven-publish.yml | 2 ++ pom.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 91c37f88..06287184 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -15,6 +15,8 @@ jobs: run: | echo "$GPG_PRIVATE_KEY" | gpg --import echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust + - name: Set GPG_TTY + run: echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - name: Set up Maven Central Repository uses: actions/setup-java@v3 with: diff --git a/pom.xml b/pom.xml index 4ec1d93a..e80dc7f5 100644 --- a/pom.xml +++ b/pom.xml @@ -240,7 +240,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.5 + 1.6 sign-artifacts From 2f0f3c9388e1f0f42738a05339a9648af0c9653d Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 11:39:07 +0530 Subject: [PATCH 09/29] run ci --- .github/workflows/maven-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 06287184..3e12c780 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -25,6 +25,7 @@ jobs: server-id: ossrh server-username: ${{ secrets.OSSRH_USERNAME }} server-password: ${{ secrets.OSSRH_TOKEN }} + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} - name: Publish package run: mvn --batch-mode deploy From c257e970b82dc16dd4514949a2ba9dd1eac58ace Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 11:40:06 +0530 Subject: [PATCH 10/29] run ci --- .github/workflows/maven-publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 3e12c780..2a30a1d1 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -11,10 +11,10 @@ jobs: packages: write steps: - uses: actions/checkout@v3 - - name: Import GPG Key - run: | - echo "$GPG_PRIVATE_KEY" | gpg --import - echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust +# - name: Import GPG Key +# run: | +# echo "$GPG_PRIVATE_KEY" | gpg --import +# echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust - name: Set GPG_TTY run: echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - name: Set up Maven Central Repository From 0082ce98353d8eb55ed1384556020e125d942c2f Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 11:54:53 +0530 Subject: [PATCH 11/29] run ci --- .github/workflows/maven-publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 2a30a1d1..3e12c780 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -11,10 +11,10 @@ jobs: packages: write steps: - uses: actions/checkout@v3 -# - name: Import GPG Key -# run: | -# echo "$GPG_PRIVATE_KEY" | gpg --import -# echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust + - name: Import GPG Key + run: | + echo "$GPG_PRIVATE_KEY" | gpg --import + echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust - name: Set GPG_TTY run: echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - name: Set up Maven Central Repository From 5bfbabe486c22e247b6608a05fd06de076288ef8 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 11:57:04 +0530 Subject: [PATCH 12/29] run ci --- .github/workflows/maven-publish.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 3e12c780..2a30a1d1 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -11,10 +11,10 @@ jobs: packages: write steps: - uses: actions/checkout@v3 - - name: Import GPG Key - run: | - echo "$GPG_PRIVATE_KEY" | gpg --import - echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust +# - name: Import GPG Key +# run: | +# echo "$GPG_PRIVATE_KEY" | gpg --import +# echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust - name: Set GPG_TTY run: echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - name: Set up Maven Central Repository From d4e611e4c55a39ef6e560370f5f51504bb201e40 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 12:02:04 +0530 Subject: [PATCH 13/29] run ci --- .github/workflows/maven-publish.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 2a30a1d1..b40f437e 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -11,12 +11,11 @@ jobs: packages: write steps: - uses: actions/checkout@v3 -# - name: Import GPG Key -# run: | -# echo "$GPG_PRIVATE_KEY" | gpg --import -# echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback --edit-key KEY_ID trust - - name: Set GPG_TTY - run: echo "GPG_TTY=$(tty)" >> $GITHUB_ENV + - name: Import private gpg key + run: | + gpg --batch --import <(echo "$GPG_PRIVATE_KEY") + env: + GPG_TTY: $(tty) - name: Set up Maven Central Repository uses: actions/setup-java@v3 with: From b046ecabc6a1888ac54f2ae45e0c9602668c6d8f Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 12:08:40 +0530 Subject: [PATCH 14/29] run ci --- pom.xml | 58 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index e80dc7f5..71feeaa1 100644 --- a/pom.xml +++ b/pom.xml @@ -175,6 +175,36 @@ + + + release-sign-artifacts + + + performRelease + true + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + + + + + + + + + + + + + + + + org.apache.maven.plugins maven-compiler-plugin From 69e1bf7bdcaea328045e6d179d440099632231e0 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 12:15:01 +0530 Subject: [PATCH 15/29] run ci --- .github/workflows/maven-publish.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index b40f437e..52395518 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -11,11 +11,11 @@ jobs: packages: write steps: - uses: actions/checkout@v3 - - name: Import private gpg key - run: | - gpg --batch --import <(echo "$GPG_PRIVATE_KEY") - env: - GPG_TTY: $(tty) +# - name: Import private gpg key +# run: | +# gpg --batch --import <(echo "$GPG_PRIVATE_KEY") +# env: +# GPG_TTY: $(tty) - name: Set up Maven Central Repository uses: actions/setup-java@v3 with: From ae97d857c9f495b1c006098ad926be6d4c06b94e Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 12:20:39 +0530 Subject: [PATCH 16/29] run ci --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 71feeaa1..44199d64 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.contentstack.sdk java - 1.12.2-SNAPSHOT + 1.12.2 jar contentstack-java Java SDK for Contentstack Content Delivery API From f3ad4a6f7ad22a96633aed39d7cf889a06aaf1eb Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 12:28:23 +0530 Subject: [PATCH 17/29] run ci --- .github/workflows/github-publish.yml | 25 ++++++++++++++++++ .github/workflows/maven-publish.yml | 24 ------------------ pom.xml | 38 +++++++++++++++------------- 3 files changed, 46 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/github-publish.yml diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml new file mode 100644 index 00000000..a42bcdd0 --- /dev/null +++ b/.github/workflows/github-publish.yml @@ -0,0 +1,25 @@ +name: Publish package to the Maven Central Repository +on: [ push ] # Trigger the workflow when a push (commit) event occurs +#on: +# release: +# types: [ created ] +jobs: + publish-maven: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + - name: Set up Maven Central Repository + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + server-id: ossrh + server-username: ${{ secrets.OSSRH_USERNAME }} + server-password: ${{ secrets.OSSRH_TOKEN }} + gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} + gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} + - name: Publish package + run: mvn --batch-mode deploy diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 52395518..b32d07d1 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -4,30 +4,6 @@ on: [ push ] # Trigger the workflow when a push (commit) event occurs # release: # types: [ created ] jobs: - publish-maven: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - steps: - - uses: actions/checkout@v3 -# - name: Import private gpg key -# run: | -# gpg --batch --import <(echo "$GPG_PRIVATE_KEY") -# env: -# GPG_TTY: $(tty) - - name: Set up Maven Central Repository - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'adopt' - server-id: ossrh - server-username: ${{ secrets.OSSRH_USERNAME }} - server-password: ${{ secrets.OSSRH_TOKEN }} - gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} - gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} - - name: Publish package - run: mvn --batch-mode deploy publish-github: runs-on: ubuntu-latest steps: diff --git a/pom.xml b/pom.xml index 44199d64..3dd90338 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.contentstack.sdk java - 1.12.2 + 1.12.2-SNAPSHOT jar contentstack-java Java SDK for Contentstack Content Delivery API @@ -86,9 +86,13 @@ + + + + - ossrh - https://oss.sonatype.org/content/repositories/snapshots + github + https://maven.pkg.github.com/contentstack/contentstack-java ossrh @@ -267,20 +271,20 @@ maven-enforcer-plugin 3.0.0-M2 - - - - - - - - - - - - - - + + + + + + + + + + + + + + org.apache.maven.plugins maven-compiler-plugin From 02d6fa62f816c0792aa4d8a277e0e247458151f1 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:22:09 +0530 Subject: [PATCH 18/29] run ci --- .github/workflows/github-publish.yml | 4 +++- pom.xml | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml index a42bcdd0..7a777bed 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/github-publish.yml @@ -22,4 +22,6 @@ jobs: gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} - name: Publish package - run: mvn --batch-mode deploy + run: mvn clean deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/contentstack/contentstack-java + +# run: mvn --batch-mode deploy diff --git a/pom.xml b/pom.xml index 3dd90338..361dc5fa 100644 --- a/pom.xml +++ b/pom.xml @@ -86,18 +86,25 @@ - - - - + + - github - https://maven.pkg.github.com/contentstack/contentstack-java + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ + github + https://maven.pkg.github.com/contentstack/contentstack-java + + + + + + + From 1d5e995e84fdb446298c0a2b7817fccd1b8be3bc Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:23:25 +0530 Subject: [PATCH 19/29] run ci --- .github/workflows/github-publish.yml | 8 ++++---- .github/workflows/maven-publish.yml | 8 ++++---- pom.xml | 16 ++++++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml index 7a777bed..62de10d7 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/github-publish.yml @@ -1,8 +1,8 @@ name: Publish package to the Maven Central Repository -on: [ push ] # Trigger the workflow when a push (commit) event occurs -#on: -# release: -# types: [ created ] +#on: [ push ] # Trigger the workflow when a push (commit) event occurs +on: + release: + types: [ created ] jobs: publish-maven: runs-on: ubuntu-latest diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index b32d07d1..628855d7 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,8 +1,8 @@ name: Publish package to the Maven Central Repository -on: [ push ] # Trigger the workflow when a push (commit) event occurs -#on: -# release: -# types: [ created ] +#on: [ push ] # Trigger the workflow when a push (commit) event occurs +on: + release: + types: [ created ] jobs: publish-github: runs-on: ubuntu-latest diff --git a/pom.xml b/pom.xml index 361dc5fa..473597d5 100644 --- a/pom.xml +++ b/pom.xml @@ -94,17 +94,17 @@ - - github - https://maven.pkg.github.com/contentstack/contentstack-java - - - - - + + + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + From a7eb3bb7e8dc539b742b34861b86ef577ec8519f Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:24:22 +0530 Subject: [PATCH 20/29] run ci --- pom.xml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 473597d5..a078a495 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.contentstack.sdk java - 1.12.2-SNAPSHOT + 1.12.2 jar contentstack-java Java SDK for Contentstack Content Delivery API @@ -93,18 +93,18 @@ https://oss.sonatype.org/content/repositories/snapshots - - - - - - - + - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ + github + https://maven.pkg.github.com/contentstack/contentstack-java + + + + + + From 0c0f1290c321e670b3832ac931d67c307b4eff6f Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:26:58 +0530 Subject: [PATCH 21/29] run ci --- .github/workflows/github-publish.yml | 10 +++++----- pom.xml | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/github-publish.yml b/.github/workflows/github-publish.yml index 62de10d7..77caec1c 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/github-publish.yml @@ -1,8 +1,8 @@ -name: Publish package to the Maven Central Repository -#on: [ push ] # Trigger the workflow when a push (commit) event occurs -on: - release: - types: [ created ] +name: Publish package to the Github Repository +on: [ push ] # Trigger the workflow when a push (commit) event occurs +#on: +# release: +# types: [ created ] jobs: publish-maven: runs-on: ubuntu-latest diff --git a/pom.xml b/pom.xml index a078a495..156e9d71 100644 --- a/pom.xml +++ b/pom.xml @@ -94,17 +94,17 @@ - - github - https://maven.pkg.github.com/contentstack/contentstack-java - - - - - - + + + + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + From 917854b190125c0dc7afc86b7d813c6deb470b59 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:28:16 +0530 Subject: [PATCH 22/29] run ci --- pom.xml | 12 ++-- src/main/java/com/contentstack/sdk/Asset.java | 57 ++++++++----------- .../com/contentstack/sdk/AssetLibrary.java | 18 ++---- .../java/com/contentstack/sdk/AssetModel.java | 6 +- 4 files changed, 39 insertions(+), 54 deletions(-) diff --git a/pom.xml b/pom.xml index 156e9d71..3802ee0a 100644 --- a/pom.xml +++ b/pom.xml @@ -94,16 +94,16 @@ - + - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + diff --git a/src/main/java/com/contentstack/sdk/Asset.java b/src/main/java/com/contentstack/sdk/Asset.java index e5991d54..9352224b 100644 --- a/src/main/java/com/contentstack/sdk/Asset.java +++ b/src/main/java/com/contentstack/sdk/Asset.java @@ -57,8 +57,7 @@ protected void setStackInstance(@NotNull Stack stack) { /** * Configure asset. * - * @param jsonObject - * the json object + * @param jsonObject the json object * @return the asset */ public Asset configure(JSONObject jsonObject) { @@ -77,19 +76,17 @@ public Asset configure(JSONObject jsonObject) { /** * Sets header. * - * @param headerKey - * the header key - * @param headerValue - * the header value - * - *
- *
- * Example :
- *

- * - * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment"); Asset asset = - * stack.asset(asset_uid); asset.setHeader(); - * + * @param headerKey the header key + * @param headerValue the header value + * + *
+ *
+ * Example :
+ *

+ * + * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment"); Asset asset = + * stack.asset(asset_uid); asset.setHeader(); + * */ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) { headers.put(headerKey, headerValue); @@ -98,17 +95,16 @@ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) { /** * Remove header. * - * @param headerKey - * the header key - * - *
- *
- * Example : - *

- * - * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment"); Asset asset = - * stack.asset(asset_uid); asset.removeHeader(); - * + * @param headerKey the header key + * + *
+ *
+ * Example : + *

+ * + * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment"); Asset asset = + * stack.asset(asset_uid); asset.removeHeader(); + * */ public void removeHeader(@NotNull String headerKey) { headers.remove(headerKey); @@ -457,10 +453,8 @@ public Asset includeDimension() { /** * Add param asset. * - * @param paramKey - * the param key - * @param paramValue - * the param value + * @param paramKey the param key + * @param paramValue the param value * @return the asset * *
@@ -538,8 +532,7 @@ public Asset includeMetadata() { /** * Fetch. * - * @param callback - * the callback + * @param callback the callback */ public void fetch(FetchResultCallback callback) { urlQueries.put(ENVIRONMENT, this.headers.get(ENVIRONMENT)); diff --git a/src/main/java/com/contentstack/sdk/AssetLibrary.java b/src/main/java/com/contentstack/sdk/AssetLibrary.java index 8401a568..5bb86ba8 100644 --- a/src/main/java/com/contentstack/sdk/AssetLibrary.java +++ b/src/main/java/com/contentstack/sdk/AssetLibrary.java @@ -34,10 +34,8 @@ protected void setStackInstance(@NotNull Stack stack) { /** * Sets header. * - * @param headerKey - * the header key - * @param headerValue - * the header value + * @param headerKey the header key + * @param headerValue the header value */ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) { this.headers.put(headerKey, headerValue); @@ -46,8 +44,7 @@ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) { /** * Remove header. * - * @param headerKey - * the header key + * @param headerKey the header key */ public void removeHeader(@NotNull String headerKey) { if (!headerKey.isEmpty()) { @@ -58,10 +55,8 @@ public void removeHeader(@NotNull String headerKey) { /** * Sort asset library. * - * @param keyOrderBy - * the key order by - * @param orderby - * the orderby + * @param keyOrderBy the key order by + * @param orderby the orderby * @return the asset library */ public AssetLibrary sort(String keyOrderBy, ORDERBY orderby) { @@ -141,8 +136,7 @@ public int getCount() { /** * Fetch all. * - * @param callback - * the callback + * @param callback the callback */ public void fetchAll(FetchAssetsCallback callback) { this.callback = callback; diff --git a/src/main/java/com/contentstack/sdk/AssetModel.java b/src/main/java/com/contentstack/sdk/AssetModel.java index c0d84f08..15c4ffb3 100644 --- a/src/main/java/com/contentstack/sdk/AssetModel.java +++ b/src/main/java/com/contentstack/sdk/AssetModel.java @@ -21,10 +21,8 @@ class AssetModel { /** * Instantiates a new Asset model. * - * @param response - * the response - * @param isArray - * the is array + * @param response the response + * @param isArray the is array */ public AssetModel(JSONObject response, boolean isArray) { From 56ca186991c1e26b89b21ad20d066983b9b04f9a Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:33:03 +0530 Subject: [PATCH 23/29] GitHub Package Release --- ...en-publish.yml => github-package-publish.yml} | 10 +++++----- ...ub-publish.yml => maven--package-publish.yml} | 10 +++++----- pom.xml | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) rename .github/workflows/{maven-publish.yml => github-package-publish.yml} (72%) rename .github/workflows/{github-publish.yml => maven--package-publish.yml} (82%) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/github-package-publish.yml similarity index 72% rename from .github/workflows/maven-publish.yml rename to .github/workflows/github-package-publish.yml index 628855d7..80ac5cb1 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/github-package-publish.yml @@ -1,8 +1,8 @@ -name: Publish package to the Maven Central Repository -#on: [ push ] # Trigger the workflow when a push (commit) event occurs -on: - release: - types: [ created ] +name: Publishing to GitHub Packages +on: [ push ] # Trigger the workflow when a push (commit) event occurs +#on: +# release: +# types: [ created ] jobs: publish-github: runs-on: ubuntu-latest diff --git a/.github/workflows/github-publish.yml b/.github/workflows/maven--package-publish.yml similarity index 82% rename from .github/workflows/github-publish.yml rename to .github/workflows/maven--package-publish.yml index 77caec1c..396debad 100644 --- a/.github/workflows/github-publish.yml +++ b/.github/workflows/maven--package-publish.yml @@ -1,8 +1,8 @@ -name: Publish package to the Github Repository -on: [ push ] # Trigger the workflow when a push (commit) event occurs -#on: -# release: -# types: [ created ] +name: Publishing to Maven Packages +#on: [ push ] # Trigger the workflow when a push (commit) event occurs +on: + release: + types: [ created ] jobs: publish-maven: runs-on: ubuntu-latest diff --git a/pom.xml b/pom.xml index 3802ee0a..6975fb8b 100644 --- a/pom.xml +++ b/pom.xml @@ -94,17 +94,17 @@ - - - - - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ + github + https://maven.pkg.github.com/contentstack/contentstack-java + + + + + + From 801ac632997adc6706f1528c544af5b2ad9cfbdc Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:36:19 +0530 Subject: [PATCH 24/29] GitHub Package Release --- .github/workflows/github-package-publish.yml | 2 +- .github/workflows/maven--package-publish.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-package-publish.yml b/.github/workflows/github-package-publish.yml index 80ac5cb1..d630e242 100644 --- a/.github/workflows/github-package-publish.yml +++ b/.github/workflows/github-package-publish.yml @@ -15,6 +15,6 @@ jobs: distribution: 'adopt' server-id: github - name: Publish to GitHub Packages - run: mvn --batch-mode deploy + run: mvn clean deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/contentstack/contentstack-java env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/maven--package-publish.yml b/.github/workflows/maven--package-publish.yml index 396debad..f7f37c44 100644 --- a/.github/workflows/maven--package-publish.yml +++ b/.github/workflows/maven--package-publish.yml @@ -22,6 +22,6 @@ jobs: gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }} - name: Publish package - run: mvn clean deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/contentstack/contentstack-java + run: mvn clean deploy # run: mvn --batch-mode deploy From 32e3ea8ba2a5b19a14e9749b0393e15ba5a04a0f Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:40:16 +0530 Subject: [PATCH 25/29] GitHub Package Release --- .github/workflows/github-package-publish.yml | 2 +- pom.xml | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/github-package-publish.yml b/.github/workflows/github-package-publish.yml index d630e242..80ac5cb1 100644 --- a/.github/workflows/github-package-publish.yml +++ b/.github/workflows/github-package-publish.yml @@ -15,6 +15,6 @@ jobs: distribution: 'adopt' server-id: github - name: Publish to GitHub Packages - run: mvn clean deploy -DaltDeploymentRepository=github::default::https://maven.pkg.github.com/contentstack/contentstack-java + run: mvn --batch-mode deploy env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6975fb8b..74eb46fd 100644 --- a/pom.xml +++ b/pom.xml @@ -93,17 +93,17 @@ https://oss.sonatype.org/content/repositories/snapshots - + github https://maven.pkg.github.com/contentstack/contentstack-java - - - - - + + + + + From 20b66511e7512a3a2210738ce73b807f16ff4f86 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:50:27 +0530 Subject: [PATCH 26/29] GitHub Package Release --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 74eb46fd..454a33e2 100644 --- a/pom.xml +++ b/pom.xml @@ -313,8 +313,8 @@ ${nexus-staging-maven-plugin.version} true - ossrh - https://oss.sonatype.org/ + github + https://maven.pkg.github.com/contentstack/contentstack-java true From 369b2f1434f68f35043e7827237849f5d0962c3d Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:57:52 +0530 Subject: [PATCH 27/29] GitHub Package Release --- .../com/contentstack/sdk/Credentials.java | 70 +++++++++---------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index d1b9a99b..9b5bb2c5 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -1,11 +1,14 @@ package com.contentstack.sdk; +import io.github.cdimascio.dotenv.Dotenv; +import io.github.cdimascio.dotenv.DotenvException; import lombok.var; +import java.io.File; import java.rmi.AccessException; public class Credentials { - //static Dotenv env = getEnv(); + static Dotenv env = getEnv(); private static String envChecker() { String githubActions = System.getenv("GITHUB_ACTIONS"); @@ -20,45 +23,38 @@ private static String envChecker() { } } -// public static Dotenv getEnv() { -// String currentDirectory = System.getProperty("user.dir"); -// File envFile = new File(currentDirectory, "env"); -// env = Dotenv.configure() -// .directory("src/test/resources") -// .filename("env") // instead of '.env', use 'env' -// .load(); -// try { -// env = Dotenv.load(); -// } catch (DotenvException ex) { -// System.out.println("Could not load from local .env"); -//// File envFile = new File(currentDirectory, ".env"); -//// try { -//// // Create .env file in the current directory -//// envFile.createNewFile(); -//// } catch (IOException e) { -//// System.err.println("An error occurred while creating .env file."); -//// e.printStackTrace(); -//// } -// } -// return env; -// } - + public static Dotenv getEnv() { + String currentDirectory = System.getProperty("user.dir"); + File envFile = new File(currentDirectory, "env"); + env = Dotenv.configure() + .directory("src/test/resources") + .filename("env") // instead of '.env', use 'env' + .load(); + try { + env = Dotenv.load(); + } catch (DotenvException ex) { + System.out.println("Could not load from local .env"); +// File envFile = new File(currentDirectory, ".env"); +// try { +// // Create .env file in the current directory +// envFile.createNewFile(); +// } catch (IOException e) { +// System.err.println("An error occurred while creating .env file."); +// e.printStackTrace(); +// } + } + return env; + } -// public final static String pwd = (env.get("PWD") != null) ? env.get("PWD") : "contentstack-java"; -// public final static String HOST = (env.get("HOST") != null) ? env.get("HOST") : "cdn.contentstack.io"; -// public final static String API_KEY = (env.get("API_KEY") != null) ? env.get("API_KEY") : "blt12c8ad610ff4ddc2"; -// public final static String DELIVERY_TOKEN = (env.get("DELIVERY_TOKEN") != null) ? env.get("DELIVERY_TOKEN") : "cs9c1afdffa298f8708e3459e4"; -// public final static String ENVIRONMENT = (env.get("ENVIRONMENT") != null) ? env.get("ENVIRONMENT") : "env1"; -// public final static String CONTENT_TYPE = (env.get("contentType") != null) ? env.get("contentType") : "product"; -// public final static String ENTRY_UID = (env.get("assetUid") != null) ? env.get("assetUid") : "blt884786476373"; + public final static String pwd = (env.get("PWD") != null) ? env.get("PWD") : "contentstack-java"; + public final static String HOST = (env.get("HOST") != null) ? env.get("HOST") : "cdn.contentstack.io"; + public final static String API_KEY = (env.get("API_KEY") != null) ? env.get("API_KEY") : ""; + public final static String DELIVERY_TOKEN = (env.get("DELIVERY_TOKEN") != null) ? env.get("DELIVERY_TOKEN") : ""; + public final static String ENVIRONMENT = (env.get("ENVIRONMENT") != null) ? env.get("ENVIRONMENT") : "env1"; + public final static String CONTENT_TYPE = (env.get("contentType") != null) ? env.get("contentType") : "product"; + public final static String ENTRY_UID = (env.get("assetUid") != null) ? env.get("assetUid") : ""; - public final static String HOST = "cdn.contentstack.io"; - public final static String API_KEY = "blt12c8ad610ff4ddc2"; - public final static String DELIVERY_TOKEN = "cs9c1afdffa298f8708e3459e4"; - public final static String ENVIRONMENT = "env1"; - public final static String CONTENT_TYPE = "product"; - public final static String ENTRY_UID = "blt884786476373"; private static volatile Stack stack; From 87fa40c527ba8cca9602c7f84010f2cc514317ef Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 10 Aug 2023 13:59:58 +0530 Subject: [PATCH 28/29] GitHub Package Release --- .github/workflows/github-package-publish.yml | 8 ++++---- pom.xml | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/github-package-publish.yml b/.github/workflows/github-package-publish.yml index 80ac5cb1..02456b05 100644 --- a/.github/workflows/github-package-publish.yml +++ b/.github/workflows/github-package-publish.yml @@ -1,8 +1,8 @@ name: Publishing to GitHub Packages -on: [ push ] # Trigger the workflow when a push (commit) event occurs -#on: -# release: -# types: [ created ] +#on: [ push ] # Trigger the workflow when a push (commit) event occurs +on: + release: + types: [ created ] jobs: publish-github: runs-on: ubuntu-latest diff --git a/pom.xml b/pom.xml index 454a33e2..c4a942a9 100644 --- a/pom.xml +++ b/pom.xml @@ -94,17 +94,17 @@ - - github - https://maven.pkg.github.com/contentstack/contentstack-java - - - - - + + + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + From 51c2765ea6940ffec97181152b7d00ad633346c3 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 17 Aug 2023 20:11:49 +0530 Subject: [PATCH 29/29] tests fixed --- src/test/java/com/contentstack/sdk/TestEntry.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/contentstack/sdk/TestEntry.java b/src/test/java/com/contentstack/sdk/TestEntry.java index 7dfc7d5e..3cd0f4ff 100644 --- a/src/test/java/com/contentstack/sdk/TestEntry.java +++ b/src/test/java/com/contentstack/sdk/TestEntry.java @@ -356,7 +356,7 @@ void entryGetAsset() { @Test @Order(42) void entryExcept() { - String[] arrField = {"fieldOne", "fieldTwo", "fieldThree"}; + String[] arrField = { "fieldOne", "fieldTwo", "fieldThree" }; Entry initEntry = stack.contentType("product").entry(entryUid).except(arrField); Assertions.assertEquals(3, initEntry.exceptFieldArray.length()); logger.info("passed..."); @@ -374,7 +374,7 @@ void entryIncludeReference() { @Test @Order(44) void entryIncludeReferenceList() { - String[] arrField = {"fieldOne", "fieldTwo", "fieldThree"}; + String[] arrField = { "fieldOne", "fieldTwo", "fieldThree" }; Entry initEntry = stack.contentType("product").entry(entryUid).includeReference(arrField); Assertions.assertEquals(3, initEntry.referenceArray.length()); Assertions.assertTrue(initEntry.params.has("include[]")); @@ -384,7 +384,7 @@ void entryIncludeReferenceList() { @Test @Order(45) void entryOnlyList() { - String[] arrField = {"fieldOne", "fieldTwo", "fieldThree"}; + String[] arrField = { "fieldOne", "fieldTwo", "fieldThree" }; Entry initEntry = stack.contentType("product").entry(entryUid); initEntry.only(arrField); Assertions.assertEquals(3, initEntry.objectUidForOnly.length()); @@ -503,7 +503,8 @@ void testEntryIncludeOwner() { void testEntryPassConfigBranchIncludeBranch() throws IllegalAccessException { Config config = new Config(); config.setBranch("feature_branch"); - Stack branchStack = Contentstack.stack(Credentials.API_KEY, Credentials.DELIVERY_TOKEN, Credentials.ENVIRONMENT, config); + Stack branchStack = Contentstack.stack(Credentials.API_KEY, Credentials.DELIVERY_TOKEN, Credentials.ENVIRONMENT, + config); Entry entry = branchStack.contentType("product").entry(entryUid); entry.includeBranch().fetch(new EntryResultCallBack() { @Override