Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Client] Java client #198

Merged
merged 11 commits into from
Sep 4, 2024
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
45 changes: 45 additions & 0 deletions .github/workflows/publish_jar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Publish java client to GitHub Packages

on: workflow_dispatch

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: checkout
uses: actions/checkout@v4

- name: java setup
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'corretto'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Publish cac client
run: |
cd clients/java/cac-client
./gradlew publish --console=rich
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish exp client
run: |
cd clients/java/exp-client
./gradlew publish --console=rich
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ test_logs
.cargo
# pre-commit config
.pre-commit-config.yaml
.cargo
.cargo

#gradle files
.gradle
build
.java~
102 changes: 102 additions & 0 deletions clients/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# JAVA Client

## Prerequisites

- Java JDK
- Gradle 7.0 or later

## Building the Project

To build the project, run:
```
./gradlew build
```

Comment on lines +1 to +14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add documentation on how to add this to a separate project?

## Running the Application

To run the application:
```
./gradlew run
```

## Publishing the clients locally and using it

Publish cac-client
```
cd clients/java/cac-client
./gradlew publishToMavenLocal
```

Publish exp-client
```
cd clients/java/exp-client
./gradlew publishToMavenLocal
```

### Use the clients in another project

build.gradle
```
plugins {
id 'java'
id 'application'
}

repositories {
// mavenLocal() // if using local Maven repository
mavenCentral() // It's good to have this as a fallback
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/juspay/superposition")
credentials {
username = System.getenv("GITHUB_USERNAME")
password = System.getenv("GITHUB_TOKEN")
}
}
}

dependencies {
implementation 'com.github.jnr:jnr-ffi:2.2.16'
implementation 'com.github.jnr:jffi:1.3.13'
implementation 'juspay.superposition:cac-client:0.0.1'
implementation 'juspay.superposition:exp-client:0.0.1'
}

application {
mainClassName = 'Client' // main class name
}
```

Client.java
```
import cac_client.CacClient;
import exp_client.ExperimentationClient;
import cac_client.CACClientException;
import exp_client.EXPClientException;
import java.util.concurrent.CountDownLatch;

public class Client {
public static void main(String[] args) {
CountDownLatch latch = new CountDownLatch(1);
try {
CacClient cac_wrapper = new CacClient();
// Use cac-client's functions
ExperimentationClient exp_wrapper = new ExperimentationClient();
// Use exp-client's functions
latch.await(); // This will keep the main thread alive
} catch (InterruptedException e) {
System.err.println("Main thread interrupted: " + e.getMessage());
} finally {
System.out.println("Application stopped.");
}
}
}
```

## If having issues
Try exporting these
```
export SUPERPOSITION_LIB_PATH=".../superposition/target/debug"
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME=/opt/homebrew/opt/openjdk
```
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions clients/java/cac-client/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id 'java-library'
id 'maven-publish'
id 'java'
id 'application'
}

group 'juspay.superposition'
version '0.0.1'

repositories {
mavenCentral()
}

dependencies {
implementation 'com.github.jnr:jnr-ffi:2.2.16'
implementation 'com.github.jnr:jffi:1.3.13'
// Add other dependencies your library needs
}

publishing {
publications {
myLib(MavenPublication) {
from (components.java)
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri('https://maven.pkg.github.com/juspay/superposition')
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}

application {
mainClassName = 'example.Demo'
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading