From 0ba040fee5274f799c26dd8e89436c82fd30f783 Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Fri, 9 Apr 2021 10:31:23 -0700 Subject: [PATCH 01/22] update to use current demo standards --- .circleci/config.yml | 18 ++++++++-- .gitignore | 3 +- README.md | 2 +- src/main/java/Hello.java | 40 +++++++++++++--------- src/main/resources/simplelogger.properties | 4 +-- 5 files changed, 44 insertions(+), 23 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8edd343..92c0d2a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,9 +6,21 @@ orbs: workflows: test: jobs: - - build-run-linux + - build-run-linux: + context: hello-world-demos - build-windows + test-daily: + triggers: + - schedule: + cron: "0 6 * * *" + filters: + branches: + only: master + jobs: + - build-run-linux: + context: hello-world-demos + # This CI build ensures that the demo both compiles and works correctly. For the runtime test, # we use an SDK key and flag key that are passed in via the CircleCI project configuration; # the flag is configured to return a true value. @@ -25,8 +37,8 @@ jobs: - run: name: insert SDK key and flag key into demo code command: | - sed -i.bak "s/SDK_KEY *= *\".*\"/SDK_KEY = \"${LD_DEMO_SDK_KEY}\"/" src/main/java/Hello.java - sed -i.bak "s/FEATURE_FLAG_KEY *= *\".*\"/FEATURE_FLAG_KEY = \"${LD_DEMO_FLAG_KEY}\"/" src/main/java/Hello.java + sed -i.bak "s/SDK_KEY *= *\".*\"/SDK_KEY = \"${LD_HELLO_WORLD_SDK_KEY}\"/" src/main/java/Hello.java + sed -i.bak "s/FEATURE_FLAG_KEY *= *\".*\"/FEATURE_FLAG_KEY = \"${LD_HELLO_WORLD_FLAG_KEY_WITH_TRUE_VALUE}\"/" src/main/java/Hello.java - run: name: build demo command: ./gradlew build diff --git a/.gitignore b/.gitignore index fe64b5a..6af793b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ # Eclipse project files .classpath .project - +.settings + # Intellij project files *.iml *.ipr diff --git a/README.md b/README.md index cc93626..12f24c0 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,4 @@ This project uses [Gradle](https://gradle.org/). It requires that Java is alread 2. On the command line, run `./gradlew run` (or, on Windows, `gradlew run`). -The demo should print `"Feature flag '' is for this user"`. +You should see the message `"Feature flag '' is for this user"`. diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index de9cd75..87e12bc 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -1,42 +1,50 @@ import com.launchdarkly.sdk.LDUser; -import com.launchdarkly.sdk.LDValue; import com.launchdarkly.sdk.server.LDClient; import java.io.IOException; public class Hello { - // Set SDK_KEY to your LaunchDarkly SDK key before compiling + // Set SDK_KEY to your LaunchDarkly SDK key. static final String SDK_KEY = ""; - // Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate - static final String FEATURE_FLAG_KEY = "YOUR_FEATURE_KEY"; + // Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate. + static final String FEATURE_FLAG_KEY = "my-boolean-flag"; + private static void showMessage(String s) { + System.out.println("*** " + s); + System.out.println(); + } public static void main(String... args) throws IOException { if (SDK_KEY.equals("")) { - System.out.println("Please edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first"); + showMessage("Please edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first"); System.exit(1); } LDClient client = new LDClient(SDK_KEY); + if (client.isInitialized()) { + showMessage("SDK successfully initialized!"); + } else { + showMessage("SDK failed to initialize"); + System.exit(1); + } + // Set up the user properties. This user should appear on your LaunchDarkly users dashboard // soon after you run the demo. - LDUser user = new LDUser.Builder("bob@example.com") - .firstName("Bob") - .lastName("Loblaw") - .custom("groups", LDValue.buildArray().add("beta_testers").build()) + LDUser user = new LDUser.Builder("example-user-key") + .name("Sandy") .build(); - boolean showFeature = client.boolVariation(FEATURE_FLAG_KEY, user, false); + boolean flagValue = client.boolVariation(FEATURE_FLAG_KEY, user, false); - System.out.println("Feature flag '" + FEATURE_FLAG_KEY + "' is " + showFeature + " for this user"); + showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + flagValue + " for this user"); - // Calling client.close() ensures that the SDK shuts down cleanly before the program exits. - // Unless you do this, the SDK may not have a chance to deliver analytics events to LaunchDarkly, - // so the user properties and the flag usage statistics may not appear on your dashboard. In a - // normal long-running application, events would be delivered automatically in the background - // and you would not need to close the client. + // Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics + // events to LaunchDarkly before the program exits. If analytics events are not delivered, + // the user properties and flag usage statistics will not appear on your dashboard. In a + // normal long-running application, the SDK would continue running and events would be + // delivered automatically in the background. client.close(); } } diff --git a/src/main/resources/simplelogger.properties b/src/main/resources/simplelogger.properties index df45e59..925bb73 100644 --- a/src/main/resources/simplelogger.properties +++ b/src/main/resources/simplelogger.properties @@ -4,8 +4,8 @@ # provided by org.slf4j:slf4j-simple. In a real application, there are many possible ways to # configure the logging behavior. See: http://www.slf4j.org/ -# Set defaultLogLevel to "info" or "debug" to see more detailed log output from the SDK. -org.slf4j.simpleLogger.defaultLogLevel=warn +# Set defaultLogLevel to "debug" to see more detailed log output from the SDK. +org.slf4j.simpleLogger.defaultLogLevel=info org.slf4j.simpleLogger.showDateTime=true org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z From 7e753e8848bd035acf894cbbb9f59d3b07feab9f Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Fri, 9 Apr 2021 20:04:32 -0700 Subject: [PATCH 02/22] formatting --- src/main/java/Hello.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 87e12bc..b4ebfb5 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -10,6 +10,7 @@ public class Hello { // Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate. static final String FEATURE_FLAG_KEY = "my-boolean-flag"; + private static void showMessage(String s) { System.out.println("*** " + s); System.out.println(); From d5ad34ac043cccb8dd09e685c57f496c537d0240 Mon Sep 17 00:00:00 2001 From: Alex Engelberg Date: Mon, 2 May 2022 13:10:37 -0700 Subject: [PATCH 03/22] Update CircleCI workflow to reference main branch --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 92c0d2a..c0ff916 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,7 @@ workflows: cron: "0 6 * * *" filters: branches: - only: master + only: main jobs: - build-run-linux: context: hello-world-demos From 67265db5c91d619957837730758e5ebee39b67ba Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Fri, 29 Jul 2022 12:39:10 -0700 Subject: [PATCH 04/22] simplify logging so SLF4J isn't needed --- .gitignore | 4 +++- build.gradle | 7 +------ src/main/java/Hello.java | 12 +++++++++--- src/main/resources/simplelogger.properties | 13 ------------- 4 files changed, 13 insertions(+), 23 deletions(-) delete mode 100644 src/main/resources/simplelogger.properties diff --git a/.gitignore b/.gitignore index 6af793b..cfb6e1d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ # Gradle .gradle -build \ No newline at end of file +build +bin +target diff --git a/build.gradle b/build.gradle index fd49b9d..03096cb 100644 --- a/build.gradle +++ b/build.gradle @@ -20,14 +20,9 @@ application { } ext.versions = [ - "sdk": "5.+", - "slf4j": "1.7.22" + "sdk": "5.+" ] dependencies { implementation "com.launchdarkly:launchdarkly-java-server-sdk:${versions.sdk}" - - // Adding slf4j-simple enables the basic console logging implementation of SLF4J. Most real - // applications will use one of the other SLF4J adapters. See: http://www.slf4j.org/ - implementation "org.slf4j:slf4j-simple:${versions.slf4j}" } diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index b4ebfb5..0e6e28f 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -1,5 +1,6 @@ -import com.launchdarkly.sdk.LDUser; -import com.launchdarkly.sdk.server.LDClient; +import com.launchdarkly.logging.*; +import com.launchdarkly.sdk.*; +import com.launchdarkly.sdk.server.*; import java.io.IOException; @@ -22,7 +23,12 @@ public static void main(String... args) throws IOException { System.exit(1); } - LDClient client = new LDClient(SDK_KEY); + // Using Logs.basic() allows us to get simple console logging without configuring SLF4J. + LDConfig config = new LDConfig.Builder() + .logging(Components.logging(Logs.basic())) + .build(); + + LDClient client = new LDClient(SDK_KEY, config); if (client.isInitialized()) { showMessage("SDK successfully initialized!"); diff --git a/src/main/resources/simplelogger.properties b/src/main/resources/simplelogger.properties deleted file mode 100644 index 925bb73..0000000 --- a/src/main/resources/simplelogger.properties +++ /dev/null @@ -1,13 +0,0 @@ -# SLF4J's SimpleLogger configuration file - -# For the purposes of this demo, we are using the simple console logging implementation that is -# provided by org.slf4j:slf4j-simple. In a real application, there are many possible ways to -# configure the logging behavior. See: http://www.slf4j.org/ - -# Set defaultLogLevel to "debug" to see more detailed log output from the SDK. -org.slf4j.simpleLogger.defaultLogLevel=info - -org.slf4j.simpleLogger.showDateTime=true -org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z -org.slf4j.simpleLogger.showThreadName=true -org.slf4j.simpleLogger.showLogName=true From b4109c4db2e775fb49b295c7a123603fce502ec3 Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Tue, 6 Dec 2022 15:10:27 -0800 Subject: [PATCH 05/22] use prerelease snapshot of v6 SDK --- .circleci/config.yml | 2 +- README.md | 4 ++-- build.gradle | 2 +- src/main/java/Hello.java | 22 +++++++++------------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c0ff916..fd574ea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -46,7 +46,7 @@ jobs: name: run demo command: | ./gradlew run | tee output.txt - grep "is true for this user" output.txt || (echo "Flag did not evaluate to expected true value" && exit 1) + grep "is true for this context" output.txt || (echo "Flag did not evaluate to expected true value" && exit 1) build-windows: executor: diff --git a/README.md b/README.md index 12f24c0..1bfabe0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ We've built a simple console application that demonstrates how LaunchDarkly's SD ## Build instructions
 -This project uses [Gradle](https://gradle.org/). It requires that Java is already installed on your system (version 8 or higher). It will automatically use the latest release of the LaunchDarkly SDK with major version 5. +This project uses [Gradle](https://gradle.org/). It requires that Java is already installed on your system (version 8 or higher). It will automatically use the latest release of the LaunchDarkly SDK with major version 6. 1. Edit `src/main/java/Hello.java` and set the value of `SDK_KEY` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, set `FEATURE_FLAG_KEY` to the flag key. @@ -18,4 +18,4 @@ This project uses [Gradle](https://gradle.org/). It requires that Java is alread 2. On the command line, run `./gradlew run` (or, on Windows, `gradlew run`). -You should see the message `"Feature flag '' is for this user"`. +You should see the message `"Feature flag '' is for this context"`. diff --git a/build.gradle b/build.gradle index 03096cb..ee30d4a 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ application { } ext.versions = [ - "sdk": "5.+" + "sdk": "6.0.0-SNAPSHOT" // TEMPORARY - change to "6+" after release ] dependencies { diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 0e6e28f..9bceef7 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -1,9 +1,6 @@ -import com.launchdarkly.logging.*; import com.launchdarkly.sdk.*; import com.launchdarkly.sdk.server.*; -import java.io.IOException; - public class Hello { // Set SDK_KEY to your LaunchDarkly SDK key. @@ -17,15 +14,14 @@ private static void showMessage(String s) { System.out.println(); } - public static void main(String... args) throws IOException { + public static void main(String... args) throws Exception { if (SDK_KEY.equals("")) { showMessage("Please edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first"); System.exit(1); } - // Using Logs.basic() allows us to get simple console logging without configuring SLF4J. LDConfig config = new LDConfig.Builder() - .logging(Components.logging(Logs.basic())) + .events(Components.noEvents()) .build(); LDClient client = new LDClient(SDK_KEY, config); @@ -37,20 +33,20 @@ public static void main(String... args) throws IOException { System.exit(1); } - // Set up the user properties. This user should appear on your LaunchDarkly users dashboard - // soon after you run the demo. - LDUser user = new LDUser.Builder("example-user-key") + // Set up the evaluation context. This context should appear on your LaunchDarkly contexts + // dashboard soon after you run the demo. + LDContext context = LDContext.builder("example-user-key") .name("Sandy") .build(); - boolean flagValue = client.boolVariation(FEATURE_FLAG_KEY, user, false); + boolean flagValue = client.boolVariation(FEATURE_FLAG_KEY, context, false); - showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + flagValue + " for this user"); + showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + flagValue + " for this context"); // Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics // events to LaunchDarkly before the program exits. If analytics events are not delivered, - // the user properties and flag usage statistics will not appear on your dashboard. In a - // normal long-running application, the SDK would continue running and events would be + // the context attributes and flag usage statistics will not appear on your dashboard. In + // a normal long-running application, the SDK would continue running and events would be // delivered automatically in the background. client.close(); } From 5ef71fe6dc7d2e76ba5cd11c1da0b724b44742f6 Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Wed, 7 Dec 2022 10:56:58 -0800 Subject: [PATCH 06/22] use latest 6.x SDK --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ee30d4a..5262c60 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ application { } ext.versions = [ - "sdk": "6.0.0-SNAPSHOT" // TEMPORARY - change to "6+" after release + "sdk": "6+" ] dependencies { From f300295e656bb9eb743ee85d77fe9011932c74b6 Mon Sep 17 00:00:00 2001 From: Todd Anderson Date: Mon, 8 May 2023 15:52:09 -0500 Subject: [PATCH 07/22] Removing default of sending no events. This should reduce confusion and issues. --- src/main/java/Hello.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 9bceef7..2af6bc4 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -20,9 +20,7 @@ public static void main(String... args) throws Exception { System.exit(1); } - LDConfig config = new LDConfig.Builder() - .events(Components.noEvents()) - .build(); + LDConfig config = new LDConfig.Builder().build(); LDClient client = new LDClient(SDK_KEY, config); From cdcc4c01687aed85d3893f44e373a552a877d0e0 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:20:47 -0700 Subject: [PATCH 08/22] chore: Update to use v7+ SDK. (#20) --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5262c60..9ed79d1 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ application { } ext.versions = [ - "sdk": "6+" + "sdk": "7+" ] dependencies { From 00eb948663e6e642b03f4c68f808ea54d127919b Mon Sep 17 00:00:00 2001 From: Todd Anderson <127344469+tanderson-ld@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:53:47 -0500 Subject: [PATCH 09/22] feat: application now stays running and prints flag changes (#21) * feature: application now stays running and prints flag changes in real time * ci: fixing backgrounding issue * ci: fixing backgrounding issue --- .circleci/config.yml | 3 +- src/main/java/Hello.java | 68 ++++++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fd574ea..49f7e25 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -45,7 +45,8 @@ jobs: - run: name: run demo command: | - ./gradlew run | tee output.txt + ./gradlew run | tee output.txt 2>&1 & + sleep 5 grep "is true for this context" output.txt || (echo "Flag did not evaluate to expected true value" && exit 1) build-windows: diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 2af6bc4..91e1293 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -1,3 +1,5 @@ +import java.io.IOException; + import com.launchdarkly.sdk.*; import com.launchdarkly.sdk.server.*; @@ -15,37 +17,63 @@ private static void showMessage(String s) { } public static void main(String... args) throws Exception { - if (SDK_KEY.equals("")) { - showMessage("Please edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first"); - System.exit(1); - } - LDConfig config = new LDConfig.Builder().build(); - LDClient client = new LDClient(SDK_KEY, config); - + final LDClient client = new LDClient(SDK_KEY, config); if (client.isInitialized()) { showMessage("SDK successfully initialized!"); } else { showMessage("SDK failed to initialize"); System.exit(1); } - - // Set up the evaluation context. This context should appear on your LaunchDarkly contexts - // dashboard soon after you run the demo. - LDContext context = LDContext.builder("example-user-key") - .name("Sandy") - .build(); - boolean flagValue = client.boolVariation(FEATURE_FLAG_KEY, context, false); + // Set up the evaluation context. This context should appear on your + // LaunchDarkly contexts dashboard soon after you run the demo. + final LDContext context = LDContext.builder("example-user-key") + .name("Sandy") + .build(); + // Evaluate the feature flag for this context. + boolean flagValue = client.boolVariation(FEATURE_FLAG_KEY, context, false); showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + flagValue + " for this context"); - // Here we ensure that the SDK shuts down cleanly and has a chance to deliver analytics - // events to LaunchDarkly before the program exits. If analytics events are not delivered, - // the context attributes and flag usage statistics will not appear on your dashboard. In - // a normal long-running application, the SDK would continue running and events would be - // delivered automatically in the background. - client.close(); + // Here we request that the SDK flush pending analytic events so that you see + // data for the above evaluation on the dashboard immediatelynow rather than + // at the next automatic flush interval. You don't need to do this under normal + // circumstances in your own application. + client.flush(); + + // We set up a flag change listener so you can see flag changes as you change + // the flag rules. + client.getFlagTracker().addFlagChangeListener(event -> { + showMessage("Feature flag '" + event.getKey() + "' has changed."); + if (event.getKey().equals(FEATURE_FLAG_KEY)) { + boolean value = client.boolVariation(FEATURE_FLAG_KEY, context, false); + showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + value + " for this context"); + } + }); + showMessage("Listening for feature flag changes. Use Ctrl+C to terminate."); + + // Here we ensure that when the application terminates, the SDK shuts down + // cleanly and has a chance to deliver analytics events to LaunchDarkly. + // If analytics events are not delivered, the context attributes and flag usage + // statistics may not appear on your dashboard. In a normal long-running + // application, the SDK would continue running and events would be delivered + // automatically in the background. + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + public void run() { + try { + client.close(); + } catch (IOException e) { + // ignore + } + } + }, "ldclient-cleanup-thread")); + + // Keeps example application alive. + Object mon = new Object(); + synchronized (mon) { + mon.wait(); + } } } From a8f274bbc78df99d6375dcba2daa7263d2027b54 Mon Sep 17 00:00:00 2001 From: Louis Chan Date: Tue, 26 Mar 2024 17:40:39 -0700 Subject: [PATCH 10/22] feat: hello app proposal --- src/main/java/Hello.java | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 91e1293..5b27a17 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -9,13 +9,22 @@ public class Hello { static final String SDK_KEY = ""; // Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate. - static final String FEATURE_FLAG_KEY = "my-boolean-flag"; + static final String FEATURE_FLAG_KEY = "sample-feature"; private static void showMessage(String s) { System.out.println("*** " + s); System.out.println(); } + private static void printLogo() { + showMessage("\n _ _ ____ _ _ \n" + // + " | | __ _ _ _ _ __ ___| |__ | _ \\ __ _ _ __| | _| |_ _ \n" + // + " | | / _` | | | | '_ \\ / __| '_ \\| | | |/ _` | '__| |/ / | | | |\n" + // + " | |__| (_| | |_| | | | | (__| | | | |_| | (_| | | | <| | |_| |\n" + // + " |_____\\__,_|\\__,_|_| |_|\\___|_| |_|____/ \\__,_|_| |_|\\_\\_|\\__, |\n" + // + " |___/ "); + } + public static void main(String... args) throws Exception { LDConfig config = new LDConfig.Builder().build(); @@ -37,11 +46,9 @@ public static void main(String... args) throws Exception { boolean flagValue = client.boolVariation(FEATURE_FLAG_KEY, context, false); showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + flagValue + " for this context"); - // Here we request that the SDK flush pending analytic events so that you see - // data for the above evaluation on the dashboard immediatelynow rather than - // at the next automatic flush interval. You don't need to do this under normal - // circumstances in your own application. - client.flush(); + if (flagValue) { + printLogo(); + } // We set up a flag change listener so you can see flag changes as you change // the flag rules. @@ -50,6 +57,10 @@ public static void main(String... args) throws Exception { if (event.getKey().equals(FEATURE_FLAG_KEY)) { boolean value = client.boolVariation(FEATURE_FLAG_KEY, context, false); showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + value + " for this context"); + + if (value) { + printLogo(); + } } }); showMessage("Listening for feature flag changes. Use Ctrl+C to terminate."); From 0ffe0af932f9ec812ba5ff8233d89c3b37ebc386 Mon Sep 17 00:00:00 2001 From: Louis Chan Date: Wed, 27 Mar 2024 15:21:21 -0700 Subject: [PATCH 11/22] fix: review feedback --- src/main/java/Hello.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 5b27a17..c470572 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -28,11 +28,16 @@ private static void printLogo() { public static void main(String... args) throws Exception { LDConfig config = new LDConfig.Builder().build(); + if (SDK_KEY == null || SDK_KEY.equals("")) { + showMessage("Please edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first."); + System.exit(1); + } + final LDClient client = new LDClient(SDK_KEY, config); if (client.isInitialized()) { showMessage("SDK successfully initialized!"); } else { - showMessage("SDK failed to initialize"); + showMessage("SDK failed to initialize. Please check your internet connection and SDK credential for any typo."); System.exit(1); } @@ -53,7 +58,6 @@ public static void main(String... args) throws Exception { // We set up a flag change listener so you can see flag changes as you change // the flag rules. client.getFlagTracker().addFlagChangeListener(event -> { - showMessage("Feature flag '" + event.getKey() + "' has changed."); if (event.getKey().equals(FEATURE_FLAG_KEY)) { boolean value = client.boolVariation(FEATURE_FLAG_KEY, context, false); showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + value + " for this context"); From 64a5d7f3aa367fd89ffa70a1f97e60acb18b6427 Mon Sep 17 00:00:00 2001 From: Louis Chan Date: Fri, 5 Apr 2024 16:25:07 -0700 Subject: [PATCH 12/22] fix: Update the logo and add the CI mode --- src/main/java/Hello.java | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index c470572..f2af21b 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -17,15 +17,23 @@ private static void showMessage(String s) { } private static void printLogo() { - showMessage("\n _ _ ____ _ _ \n" + // - " | | __ _ _ _ _ __ ___| |__ | _ \\ __ _ _ __| | _| |_ _ \n" + // - " | | / _` | | | | '_ \\ / __| '_ \\| | | |/ _` | '__| |/ / | | | |\n" + // - " | |__| (_| | |_| | | | | (__| | | | |_| | (_| | | | <| | |_| |\n" + // - " |_____\\__,_|\\__,_|_| |_|\\___|_| |_|____/ \\__,_|_| |_|\\_\\_|\\__, |\n" + // - " |___/ "); + showMessage("\n ██ \n" + + " ██ \n" + + " ████████ \n" + + " ███████ \n" + + "██ LAUNCHDARKLY █\n" + + " ███████ \n" + + " ████████ \n" + + " ██ \n" + + " ██ \n"); } public static void main(String... args) throws Exception { + // CI Mode (./gradlew run --args="CI") + boolean CIMode = args.length > 0 && args[0].equals("CI"); + + System.out.println(CIMode); + LDConfig config = new LDConfig.Builder().build(); if (SDK_KEY == null || SDK_KEY.equals("")) { @@ -55,6 +63,11 @@ public static void main(String... args) throws Exception { printLogo(); } + //If this is building for CI, we don't need to keep running the Hello App continously. + if(CIMode) { + System.exit(0); + } + // We set up a flag change listener so you can see flag changes as you change // the flag rules. client.getFlagTracker().addFlagChangeListener(event -> { From 7d95c2a45720b08d2ffb2338944d2176b37c8456 Mon Sep 17 00:00:00 2001 From: Louis Chan Date: Wed, 10 Apr 2024 15:46:47 -0700 Subject: [PATCH 13/22] fix: add in the environment variable support --- README.md | 16 +++++++++------- src/main/java/Hello.java | 10 +++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1bfabe0..e286d52 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,20 @@ -# LaunchDarkly Sample Java Application
 +# LaunchDarkly Sample Java Application We've built a simple console application that demonstrates how LaunchDarkly's SDK works. -
Below, you'll find the basic build procedure, but for more comprehensive instructions, you can visit your [Quickstart page](https://app.launchdarkly.com/quickstart#/) or the [Java SDK reference guide](https://docs.launchdarkly.com/sdk/server-side/java). +Below, you'll find the basic build procedure, but for more comprehensive instructions, you can visit your [Quickstart page](https://app.launchdarkly.com/quickstart#/) or the [Java SDK reference guide](https://docs.launchdarkly.com/sdk/server-side/java). -## Build instructions
 +## Build instructions -This project uses [Gradle](https://gradle.org/). It requires that Java is already installed on your system (version 8 or higher). It will automatically use the latest release of the LaunchDarkly SDK with major version 6. +This project uses [Gradle](https://gradle.org/). It requires that Java is already installed on your system (version 8 or higher). It will automatically use the latest release of the LaunchDarkly SDK with major version 7. -1. Edit `src/main/java/Hello.java` and set the value of `SDK_KEY` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, set `FEATURE_FLAG_KEY` to the flag key. +1. Set the value of environment variable `LD_SDK_KEY` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, edit `src/main/java/Hello.java` and set `FEATURE_FLAG_KEY` in code to the flag key. -```java - static final String SDK_KEY = "1234567890abcdef"; +```sh + export LD_SDK_KEY=1234567890abcdef +``` +```java static final String FEATURE_FLAG_KEY = "my-flag"; ``` diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index f2af21b..52890ef 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -6,7 +6,7 @@ public class Hello { // Set SDK_KEY to your LaunchDarkly SDK key. - static final String SDK_KEY = ""; + static String SDK_KEY = ""; // Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate. static final String FEATURE_FLAG_KEY = "sample-feature"; @@ -32,12 +32,16 @@ public static void main(String... args) throws Exception { // CI Mode (./gradlew run --args="CI") boolean CIMode = args.length > 0 && args[0].equals("CI"); - System.out.println(CIMode); + // Get SDK Key from env variable LD_SDK_KEY + String envSDKKey = System.getenv("LD_SDK_KEY"); + if(envSDKKey != null) { + SDK_KEY = envSDKKey; + } LDConfig config = new LDConfig.Builder().build(); if (SDK_KEY == null || SDK_KEY.equals("")) { - showMessage("Please edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first."); + showMessage("Please set the LD_SDK_KEY environment variable or edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first."); System.exit(1); } From 83308e1b32f2ff1b2def92eda8c4e49389cf4e53 Mon Sep 17 00:00:00 2001 From: Louis Chan Date: Wed, 17 Apr 2024 11:45:16 -0700 Subject: [PATCH 14/22] fix: line up to use enviroment variable for all three inputs and add CODEOWNERS --- CODEOWNERS | 2 ++ src/main/java/Hello.java | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..e1c9825 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,2 @@ +# Repository Maintainers +* @launchdarkly/team-sdk \ No newline at end of file diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 52890ef..e6a61a0 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -9,7 +9,7 @@ public class Hello { static String SDK_KEY = ""; // Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate. - static final String FEATURE_FLAG_KEY = "sample-feature"; + static String FEATURE_FLAG_KEY = "sample-feature"; private static void showMessage(String s) { System.out.println("*** " + s); @@ -29,15 +29,25 @@ private static void printLogo() { } public static void main(String... args) throws Exception { - // CI Mode (./gradlew run --args="CI") - boolean CIMode = args.length > 0 && args[0].equals("CI"); + // Set this environment variable to skip the loop process and evaluate the flag + // a single time. + boolean CIMode = false; + String ci = System.getenv("CI"); + if(ci != null) { + CIMode = true; + } // Get SDK Key from env variable LD_SDK_KEY - String envSDKKey = System.getenv("LD_SDK_KEY"); + String envSDKKey = System.getenv("LAUNCHDARKLY_SERVER_KEY"); if(envSDKKey != null) { SDK_KEY = envSDKKey; } + String envFlagKey = System.getenv("LAUNCHDARKLY_FLAG_KEY"); + if(envFlagKey != null) { + FEATURE_FLAG_KEY = envFlagKey; + } + LDConfig config = new LDConfig.Builder().build(); if (SDK_KEY == null || SDK_KEY.equals("")) { From 6034f680cd3e23fba0c28e769311deb9f14ced39 Mon Sep 17 00:00:00 2001 From: Louis Chan Date: Thu, 18 Apr 2024 01:17:15 -0700 Subject: [PATCH 15/22] feat: Use Github Actions instead of CircleCIt --- .circleci/config.yml | 65 ------------------------ .github/workflows/ci.yml | 35 +++++++++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 36 insertions(+), 66 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/ci.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 49f7e25..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,65 +0,0 @@ -version: 2.1 - -orbs: - win: circleci/windows@1.0.0 - -workflows: - test: - jobs: - - build-run-linux: - context: hello-world-demos - - build-windows - - test-daily: - triggers: - - schedule: - cron: "0 6 * * *" - filters: - branches: - only: main - jobs: - - build-run-linux: - context: hello-world-demos - -# This CI build ensures that the demo both compiles and works correctly. For the runtime test, -# we use an SDK key and flag key that are passed in via the CircleCI project configuration; -# the flag is configured to return a true value. - -jobs: - build-run-linux: - docker: - - image: circleci/openjdk:14-jdk-buster - steps: - - checkout - - run: - name: show dependency versions - command: ./gradlew dependencies - - run: - name: insert SDK key and flag key into demo code - command: | - sed -i.bak "s/SDK_KEY *= *\".*\"/SDK_KEY = \"${LD_HELLO_WORLD_SDK_KEY}\"/" src/main/java/Hello.java - sed -i.bak "s/FEATURE_FLAG_KEY *= *\".*\"/FEATURE_FLAG_KEY = \"${LD_HELLO_WORLD_FLAG_KEY_WITH_TRUE_VALUE}\"/" src/main/java/Hello.java - - run: - name: build demo - command: ./gradlew build - - run: - name: run demo - command: | - ./gradlew run | tee output.txt 2>&1 & - sleep 5 - grep "is true for this context" output.txt || (echo "Flag did not evaluate to expected true value" && exit 1) - - build-windows: - executor: - name: win/vs2019 - shell: powershell.exe - steps: - - checkout - - run: - name: install OpenJDK - command: | - $ProgressPreference = "SilentlyContinue" # prevents console errors from CircleCI host - iwr -outf openjdk.msi https://developers.redhat.com/download-manager/file/java-11-openjdk-11.0.5.10-2.windows.redhat.x86_64.msi - Start-Process msiexec.exe -Wait -ArgumentList '/I openjdk.msi /quiet' - - run: .\gradlew.bat --no-daemon dependencies # must use --no-daemon because CircleCI in Windows will hang if there's a daemon running - - run: .\gradlew.bat --no-daemon build # must use --no-daemon because CircleCI in Windows will hang if there's a daemon running diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..98f4d21 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +name: Build and run +on: + schedule: + # * is a special character in YAML so you have to quote this string + - cron: '0 9 * * *' + push: + branches: [ main, 'feat/**' ] + paths-ignore: + - '**.md' # Do not need to run CI for markdown changes. + pull_request: + branches: [ main, 'feat/**' ] + paths-ignore: + - '**.md' + +jobs: + build-and-run: + runs-on: ubuntu-latest + + permissions: + id-token: write # Needed if using OIDC to get release secrets. + + steps: + - uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + + - uses: launchdarkly/gh-actions/actions/verify-hello-app@verify-hello-app-v1.0.1 + with: + use_server_key: true + role_arn: ${{ vars.AWS_ROLE_ARN }} + command: ./gradlew run \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 622ab64..48c0a02 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From a47077782127b2d01597495d9d0388500dc5cba9 Mon Sep 17 00:00:00 2001 From: Louis Chan <91093020+louis-launchdarkly@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:14:07 -0700 Subject: [PATCH 16/22] Apply suggestions from code review Co-authored-by: Matthew M. Keeler --- CODEOWNERS | 2 +- README.md | 4 ++-- src/main/java/Hello.java | 10 +++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index e1c9825..1046984 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,2 +1,2 @@ # Repository Maintainers -* @launchdarkly/team-sdk \ No newline at end of file +* @launchdarkly/team-sdk-java \ No newline at end of file diff --git a/README.md b/README.md index e286d52..6d5da5e 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ Below, you'll find the basic build procedure, but for more comprehensive instruc This project uses [Gradle](https://gradle.org/). It requires that Java is already installed on your system (version 8 or higher). It will automatically use the latest release of the LaunchDarkly SDK with major version 7. -1. Set the value of environment variable `LD_SDK_KEY` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, edit `src/main/java/Hello.java` and set `FEATURE_FLAG_KEY` in code to the flag key. +1. Set the value of environment variable `LAUNCHDARKLY_SERVER_KEY` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, edit `src/main/java/Hello.java` and set `FEATURE_FLAG_KEY` in code to the flag key. ```sh - export LD_SDK_KEY=1234567890abcdef + export LAUNCHDARKLY_SERVER_KEY=1234567890abcdef ``` ```java diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index e6a61a0..db20fc6 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -31,13 +31,9 @@ private static void printLogo() { public static void main(String... args) throws Exception { // Set this environment variable to skip the loop process and evaluate the flag // a single time. - boolean CIMode = false; - String ci = System.getenv("CI"); - if(ci != null) { - CIMode = true; - } + boolean CIMode = System.getenv("CI") != null; - // Get SDK Key from env variable LD_SDK_KEY + // Get SDK Key from env variable LAUNCHDARKLY_SERVER_KEY String envSDKKey = System.getenv("LAUNCHDARKLY_SERVER_KEY"); if(envSDKKey != null) { SDK_KEY = envSDKKey; @@ -51,7 +47,7 @@ public static void main(String... args) throws Exception { LDConfig config = new LDConfig.Builder().build(); if (SDK_KEY == null || SDK_KEY.equals("")) { - showMessage("Please set the LD_SDK_KEY environment variable or edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first."); + showMessage("Please set the LAUNCHDARKLY_SERVER_KEY environment variable or edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first."); System.exit(1); } From a2df6d7717ca017d74906cc65dacdfdf64dcaaf2 Mon Sep 17 00:00:00 2001 From: Louis Chan Date: Tue, 23 Apr 2024 11:21:49 -0700 Subject: [PATCH 17/22] fix: Use individual flag change listener --- src/main/java/Hello.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index db20fc6..2011fc7 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -16,7 +16,7 @@ private static void showMessage(String s) { System.out.println(); } - private static void printLogo() { + private static void showBanner() { showMessage("\n ██ \n" + " ██ \n" + " ████████ \n" + @@ -70,7 +70,7 @@ public static void main(String... args) throws Exception { showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + flagValue + " for this context"); if (flagValue) { - printLogo(); + showBanner(); } //If this is building for CI, we don't need to keep running the Hello App continously. @@ -80,17 +80,14 @@ public static void main(String... args) throws Exception { // We set up a flag change listener so you can see flag changes as you change // the flag rules. - client.getFlagTracker().addFlagChangeListener(event -> { - if (event.getKey().equals(FEATURE_FLAG_KEY)) { - boolean value = client.boolVariation(FEATURE_FLAG_KEY, context, false); - showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + value + " for this context"); + client.getFlagTracker().addFlagValueChangeListener(FEATURE_FLAG_KEY, context, event -> { + showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + event.getNewValue() + " for this context"); - if (value) { - printLogo(); + if (event.getNewValue().booleanValue()) { + showBanner(); } - } }); - showMessage("Listening for feature flag changes. Use Ctrl+C to terminate."); + showMessage("Listening for feature flag changes."); // Here we ensure that when the application terminates, the SDK shuts down // cleanly and has a chance to deliver analytics events to LaunchDarkly. From 53408bd86ecf288a141f5f7c1e8380267b84af71 Mon Sep 17 00:00:00 2001 From: Molly Date: Wed, 24 Apr 2024 17:48:44 -0700 Subject: [PATCH 18/22] use sentence case for headers --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d5da5e..c1cae3a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# LaunchDarkly Sample Java Application +# LaunchDarkly sample Java application We've built a simple console application that demonstrates how LaunchDarkly's SDK works. From 1651231e90040b2a1930a6a6f69f87bca3ab8933 Mon Sep 17 00:00:00 2001 From: Molly Date: Wed, 24 Apr 2024 17:49:34 -0700 Subject: [PATCH 19/22] update output strings per spec update to match https://github.com/launchdarkly/sdk-specs/tree/main/specs/EXAM-SDK-example/HELLO-hello-apps#requirement-142 --- README.md | 2 +- src/main/java/Hello.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c1cae3a..ceb55ff 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,4 @@ This project uses [Gradle](https://gradle.org/). It requires that Java is alread 2. On the command line, run `./gradlew run` (or, on Windows, `gradlew run`). -You should see the message `"Feature flag '' is for this context"`. +You should receive the message "The feature flag evaluates to ." The application will run continuously and react to the flag changes in LaunchDarkly. diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 2011fc7..0f8aac0 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -67,7 +67,7 @@ public static void main(String... args) throws Exception { // Evaluate the feature flag for this context. boolean flagValue = client.boolVariation(FEATURE_FLAG_KEY, context, false); - showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + flagValue + " for this context"); + showMessage("The '" + FEATURE_FLAG_KEY + "' feature flag evaluates to " + flagValue + "."); if (flagValue) { showBanner(); @@ -81,7 +81,7 @@ public static void main(String... args) throws Exception { // We set up a flag change listener so you can see flag changes as you change // the flag rules. client.getFlagTracker().addFlagValueChangeListener(FEATURE_FLAG_KEY, context, event -> { - showMessage("Feature flag '" + FEATURE_FLAG_KEY + "' is " + event.getNewValue() + " for this context"); + showMessage("The '" + FEATURE_FLAG_KEY + "' feature flag evaluates to " + event.getNewValue() + "."); if (event.getNewValue().booleanValue()) { showBanner(); From cc83a999a54db05a4bc2b169365d4f6e33728abf Mon Sep 17 00:00:00 2001 From: Louis Chan Date: Thu, 25 Apr 2024 16:24:42 -0700 Subject: [PATCH 20/22] fix: Use LAUNCHDARKLY_SDK_KEY instead --- README.md | 4 ++-- src/main/java/Hello.java | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ceb55ff..03bc875 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ Below, you'll find the basic build procedure, but for more comprehensive instruc This project uses [Gradle](https://gradle.org/). It requires that Java is already installed on your system (version 8 or higher). It will automatically use the latest release of the LaunchDarkly SDK with major version 7. -1. Set the value of environment variable `LAUNCHDARKLY_SERVER_KEY` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, edit `src/main/java/Hello.java` and set `FEATURE_FLAG_KEY` in code to the flag key. +1. Set the value of environment variable `LAUNCHDARKLY_SDK_KEY` to your LaunchDarkly SDK key. If there is an existing boolean feature flag in your LaunchDarkly project that you want to evaluate, edit `src/main/java/Hello.java` and set `FEATURE_FLAG_KEY` in code to the flag key. ```sh - export LAUNCHDARKLY_SERVER_KEY=1234567890abcdef + export LAUNCHDARKLY_SDK_KEY=1234567890abcdef ``` ```java diff --git a/src/main/java/Hello.java b/src/main/java/Hello.java index 0f8aac0..2fd5f4c 100644 --- a/src/main/java/Hello.java +++ b/src/main/java/Hello.java @@ -29,12 +29,9 @@ private static void showBanner() { } public static void main(String... args) throws Exception { - // Set this environment variable to skip the loop process and evaluate the flag - // a single time. boolean CIMode = System.getenv("CI") != null; - // Get SDK Key from env variable LAUNCHDARKLY_SERVER_KEY - String envSDKKey = System.getenv("LAUNCHDARKLY_SERVER_KEY"); + String envSDKKey = System.getenv("LAUNCHDARKLY_SDK_KEY"); if(envSDKKey != null) { SDK_KEY = envSDKKey; } @@ -47,7 +44,7 @@ public static void main(String... args) throws Exception { LDConfig config = new LDConfig.Builder().build(); if (SDK_KEY == null || SDK_KEY.equals("")) { - showMessage("Please set the LAUNCHDARKLY_SERVER_KEY environment variable or edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first."); + showMessage("Please set the LAUNCHDARKLY_SDK_KEY environment variable or edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first."); System.exit(1); } From 4d5383bbe9e483261e84989d3f83c8a57e8edcf6 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Fri, 13 Mar 2026 08:37:36 -0700 Subject: [PATCH 21/22] fix: upgrade verify-hello-app action to v2.0.1 (#25) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary CI has been failing daily because the `verify-hello-app` action v1.0.1 sets the env var `LAUNCHDARKLY_SERVER_KEY`, but `Hello.java` was previously updated to read `LAUNCHDARKLY_SDK_KEY`. This upgrades the action to v2.0.1, which sets `LAUNCHDARKLY_SDK_KEY` to match. Also fixes a missing trailing newline in `ci.yml`. ## Review & Testing Checklist for Human - [ ] Verify that `verify-hello-app` v2.0.1 has no other breaking changes beyond the env var rename (the action inputs `use_server_key`, `role_arn`, `command` appear unchanged). The grep pattern in v2 changed from `grep -iE "is true for this context|feature flag evaluates to true"` to `grep -i "feature flag evaluates to true"` — confirm `Hello.java`'s output (`feature flag evaluates to`) still matches. - [ ] Confirm CI passes on this PR (this is the real validation — the change cannot be tested locally since it depends on AWS OIDC + SSM parameters only available in CI). ### Notes - Requested by: @kinyoklion - [Devin Session](https://app.devin.ai/sessions/ffb9d4dc10a147fba29aa9ea0b2ff559) Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98f4d21..8d72c89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,8 +28,8 @@ jobs: distribution: 'temurin' java-version: '21' - - uses: launchdarkly/gh-actions/actions/verify-hello-app@verify-hello-app-v1.0.1 + - uses: launchdarkly/gh-actions/actions/verify-hello-app@verify-hello-app-v2.0.1 with: use_server_key: true role_arn: ${{ vars.AWS_ROLE_ARN }} - command: ./gradlew run \ No newline at end of file + command: ./gradlew run From d7586a60472ba40c7680a56a84fe762dfaeec2f3 Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 18:41:55 -0400 Subject: [PATCH 22/22] chore: Adding stale workflow (#26) --- .github/workflows/stale.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..35715d7 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,14 @@ +name: "Close stale issues and PRs" +on: + workflow_dispatch: + schedule: + # Happen once per day at 1:30 AM + - cron: "30 1 * * *" + +permissions: + issues: write + pull-requests: write + +jobs: + sdk-close-stale: + uses: launchdarkly/gh-actions/.github/workflows/sdk-stale.yml@main