Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 36 additions & 31 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,55 @@ name: Checks

on:
push:
branches: ["**"]
branches:
- main
pull_request:

permissions:
contents: read

concurrency:
group: checks-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
ci:
checks:
runs-on: ubuntu-latest

strategy:
matrix:
java-version: [24]
timeout-minutes: 15

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: "temurin"
cache: "maven"
- name: Check out repository
uses: actions/checkout@v6

- name: Cache Maven packages
uses: actions/cache@v4
- name: Set up Java
uses: actions/setup-java@v5
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
java-version: "24"
distribution: temurin
cache: maven

- name: Build with Maven
run: mvn clean compile package -DskipTests
- name: Build and test Maven reactor
run: mvn --batch-mode clean verify

- name: Test
run: mvn test
- name: Verify published artifact boundaries
run: bash scripts/verify-artifacts.sh

- uses: actions/setup-node@v4
- name: Set up Node.js
uses: actions/setup-node@v7
with:
node-version-file: ".nvmrc"
node-version-file: .nvmrc

- name: Setup Featurevisor example-1 project
- name: Set up Featurevisor example-1 project
run: |
mkdir example-1
(cd example-1 && npx @featurevisor/cli@2.x init --example=1)
(cd example-1 && npm install)
(cd example-1 && npx featurevisor test)
cd example-1
npx --yes @featurevisor/cli@3 init --example=1
npm install
npx featurevisor build
npx featurevisor test --onlyFailures

- name: Run Featurevisor project tests against Java SDK
run: mvn exec:java -Dexec.mainClass="com.featurevisor.cli.CLI" -Dexec.args="test --projectDirectoryPath=example-1"
run: >-
mvn --batch-mode -pl featurevisor-sdk exec:java
-Dexec.mainClass=com.featurevisor.cli.CLI
-Dexec.args="test --projectDirectoryPath=example-1 --onlyFailures"
58 changes: 27 additions & 31 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,45 @@ on:
tags:
- "v*"

permissions:
contents: read
packages: write

concurrency:
group: publish-${{ github.ref }}
cancel-in-progress: false

jobs:
publish:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
timeout-minutes: 15

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for flatten-maven-plugin to work with Git tags
- name: Check out repository
uses: actions/checkout@v6

- name: Set up JDK 24 and Maven
uses: actions/setup-java@v4
- name: Set up Java and Maven publishing
uses: actions/setup-java@v5
with:
java-version: "24"
distribution: "temurin"
cache: "maven"
distribution: temurin
cache: maven
server-id: github
server-username: GITHUB_ACTOR
server-password: GITHUB_TOKEN

- name: Extract version from Git tag
id: version
shell: bash
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
version="${GITHUB_REF_NAME#v}"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Publishing Featurevisor Java $version"

- name: Update version in pom.xml
run: |
# Cross-platform sed command that works on both Linux and macOS
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS (BSD sed)
sed -i '' "/<artifactId>featurevisor-java<\/artifactId>/,/<version>/ s/<version>.*<\/version>/<version>${{ steps.version.outputs.version }}<\/version>/" pom.xml
else
# Linux (GNU sed)
sed -i "/<artifactId>featurevisor-java<\/artifactId>/,/<version>/ s/<version>.*<\/version>/<version>${{ steps.version.outputs.version }}<\/version>/" pom.xml
fi

cat pom.xml | grep '<version>'

- name: Build and Publish
- name: Build, test, and publish all artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mvn clean deploy -DskipTests
run: >-
mvn --batch-mode
-Drevision=${{ steps.version.outputs.version }}
clean deploy
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2025 Fahad Heylaal (https://fahad19.com)
Copyright (c) 2026 Fahad Heylaal (https://fahad19.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: install build test test-example-1 setup-monorepo update-monorepo setup-golang-sdk update-golang-sdk setup-references update-references
.PHONY: install build test verify-artifacts test-example-1 setup-monorepo update-monorepo setup-golang-sdk update-golang-sdk setup-references update-references

install:
mvn install
Expand All @@ -9,9 +9,13 @@ build:
test:
mvn test

verify-artifacts:
mvn package
bash scripts/verify-artifacts.sh

test-example-1:
mvn test
mvn exec:java -Dexec.mainClass="com.featurevisor.cli.CLI" -Dexec.args="test --projectDirectoryPath=../featurevisor/examples/example-1 --onlyFailures"
mvn -pl featurevisor-sdk exec:java -Dexec.mainClass="com.featurevisor.cli.CLI" -Dexec.args="test --projectDirectoryPath=../featurevisor/examples/example-1 --onlyFailures"

##
# Monorepo
Expand Down
66 changes: 64 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This SDK supports Featurevisor v3 behavior and v2 datafiles. Generated datafiles
- [Registering modules](#registering-modules)
- [Child instance](#child-instance)
- [Close](#close)
- [OpenFeature](#openfeature)
- [CLI usage](#cli-usage)
- [Test](#test)
- [Benchmark](#benchmark)
Expand Down Expand Up @@ -78,7 +79,7 @@ For finding GitHub Package (public package):

### Dependency

Add Featurevisor Java SDK as a dependency with your desired version:
Add the Featurevisor Java SDK as a dependency with your desired version:

```xml
<dependencies>
Expand Down Expand Up @@ -834,6 +835,56 @@ Learn more about assessing distribution [here](https://featurevisor.com/docs/cli
$ mvn exec:java -Dexec.mainClass="com.featurevisor.cli.CLI" -Dexec.args="assess-distribution --projectDirectoryPath=/absolute/path/to/your/featurevisor/project --environment=production --feature=foo --variation --context='{\"country\": \"nl\"}' --populateUuid=userId --populateUuid=deviceId --n=1000"
```

## OpenFeature

The OpenFeature provider is published as a separate artifact. Applications that use only `com.featurevisor:featurevisor-java` receive no provider classes or OpenFeature dependency.

Add the provider with the same version as the Featurevisor Java SDK:

```xml
<dependency>
<groupId>com.featurevisor</groupId>
<artifactId>featurevisor-openfeature</artifactId>
<version>FEATUREVISOR_VERSION</version>
</dependency>
```

The provider artifact depends on the matching Featurevisor Java SDK and the compatible official OpenFeature SDK, so no additional dependency is required.

When upgrading from an earlier release, replace the direct `dev.openfeature:sdk` dependency with `com.featurevisor:featurevisor-openfeature`. The provider's Java package and public API are unchanged.

```java
import com.featurevisor.openfeature.FeaturevisorOpenFeatureProvider;
import com.featurevisor.sdk.Featurevisor;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.OpenFeatureAPI;

var provider = new FeaturevisorOpenFeatureProvider(
new Featurevisor.FeaturevisorOptions().datafile(datafileContent)
);

var api = OpenFeatureAPI.getInstance();
api.setProviderAndWait(provider);

var client = api.getClient();
boolean enabled = client.getBooleanValue("checkout", false, new ImmutableContext("user-123"));
```

Use `checkout` for a flag, `checkout:variation` for its variation, and `checkout:title` for its `title` variable. Boolean variables use the boolean resolver. Lists, structures, and JSON variables use the object resolver.

OpenFeature's targeting key maps to `userId` by default. `targetingKeyField`, `keySeparator`, and `variationKey` on `FeaturevisorOpenFeatureProvider.Options` can customize the mapping.

You can also reuse an existing Featurevisor instance:

```java
Featurevisor featurevisor = Featurevisor.createFeaturevisor(featurevisorOptions);
var provider = new FeaturevisorOpenFeatureProvider(featurevisor);
```

The caller owns an instance passed this way. Provider shutdown does not close it. Call `featurevisor.close()` when every consumer is finished with it. When the provider creates the instance from options, the provider owns and closes it. If both are configured, the existing instance takes precedence.

See the [OpenFeature provider guide](https://featurevisor.com/docs/sdks/openfeature/) for resolution reasons, errors, metadata, tracking, lifecycle, and providers for other languages.

<!-- FEATUREVISOR_DOCS_END -->

## Development of this package
Expand All @@ -852,11 +903,22 @@ $ mvn install
$ mvn test
```

The repository is a Maven reactor with two published libraries:

- `com.featurevisor:featurevisor-java`
- `com.featurevisor:featurevisor-openfeature`

To verify their published JAR and POM boundaries locally:

```bash
$ make verify-artifacts
```

### Releasing

- Manually create a new release on [GitHub](https://github.com/featurevisor/featurevisor-java/releases)
- Tag it with a prefix of `v`, like `v1.0.0`
- GitHub Actions is set up to automatically publish the package to [GitHub Packages](https://github.com/orgs/featurevisor/packages?repo_name=featurevisor-java)
- GitHub Actions publishes the parent POM, Java SDK, and OpenFeature provider to [GitHub Packages](https://github.com/orgs/featurevisor/packages?repo_name=featurevisor-java)

## License

Expand Down
73 changes: 73 additions & 0 deletions featurevisor-openfeature/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.featurevisor</groupId>
<artifactId>featurevisor-parent</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>featurevisor-openfeature</artifactId>
<packaging>jar</packaging>

<name>Featurevisor OpenFeature Provider for Java</name>
<description>OpenFeature provider for the Featurevisor Java SDK</description>
<url>https://github.com/featurevisor/featurevisor-java</url>

<scm>
<connection>scm:git:git://github.com/featurevisor/featurevisor-java.git</connection>
<developerConnection>scm:git:ssh://github.com:featurevisor/featurevisor-java.git</developerConnection>
<url>https://github.com/featurevisor/featurevisor-java</url>
<tag>HEAD</tag>
</scm>

<dependencies>
<dependency>
<groupId>com.featurevisor</groupId>
<artifactId>featurevisor-java</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.openfeature</groupId>
<artifactId>sdk</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Loading