Skip to content

Commit

Permalink
feat: add java package (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Mar 7, 2024
2 parents 0c42b28 + 9d86f1b commit 772cdd8
Show file tree
Hide file tree
Showing 66 changed files with 8,140 additions and 3 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/main-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build and Test (Java)

on:
workflow_dispatch:
push:
branches:
- main
tags:
- 'v*'
merge_group:
paths:
- 'pkg/java/**'
- 'OpenFGAParser.g4'
- 'OpenFGALexer.g4'
- 'tests'
pull_request:
paths:
- 'pkg/java/**'
- 'OpenFGAParser.g4'
- 'OpenFGALexer.g4'
- 'tests'

permissions:
contents: read

jobs:

build:
name: Build and Test Java
runs-on: ubuntu-latest

strategy:
matrix:
java: [ '11', '17', '20' ]

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- name: Set up JDK
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: gradle
cache-dependency-path: |
./pkg/java/*.gradle*
./pkg/java/**/gradle-wrapper.properties
- name: Test and Build with Gradle
run: make all-tests-java
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ node_modules/
# Generated code
/OpenFGALexer.tokens
/gen/OpenFGALexer.*

# build files
.gradle
build
target
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,44 @@ format-js: antlr-gen-js
all-tests-js: antlr-gen-js
$(MAKE) -C pkg/js all-tests

#### Java #####

.PHONY: antlr-gen-java
antlr-gen-java: build-antlr-container
${ANTLR_CMD} -Dlanguage=Java -o pkg/java/src/main/gen/dev/openfga/language/antlr -package dev.openfga.language.antlr /app/OpenFGALexer.g4 /app/OpenFGAParser.g4

.PHONY: build-java
build-java: antlr-gen-java
$(MAKE) -C pkg/java build

.PHONY: run-java
run-java: antlr-gen-java
$(MAKE) -C pkg/java run

.PHONY: clean-java
clean-java:
$(MAKE) -C pkg/java clean

.PHONY: test-java
test-java: antlr-gen-java
$(MAKE) -C pkg/java test

.PHONY: lint-java
lint-java: antlr-gen-java
$(MAKE) -C pkg/java lint

.PHONY: audit-java
audit-java: antlr-gen-java
$(MAKE) -C pkg/java audit

.PHONY: format-java
format-java: antlr-gen-java
$(MAKE) -C pkg/java format

.PHONY: all-tests-java
all-tests-java: antlr-gen-java
$(MAKE) -C pkg/java all-tests

#### Util ####

.PHONY: build-antlr-container
Expand Down
24 changes: 24 additions & 0 deletions pkg/java/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BINARY_NAME=openfga-language
DOCKER_BINARY=docker

all: build

build:
./gradlew build

clean:
./gradlew clean

test:
./gradlew check

lint:
echo "java lint Not implemented"

audit:
echo "java audit Not implemented"

format:
echo "java format Not implemented"

all-tests: build audit lint test
81 changes: 81 additions & 0 deletions pkg/java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
plugins {
id 'java'

// Quality
id 'jacoco'
id 'jvm-test-suite'
id 'com.diffplug.spotless' version '6.23.3'

// IDE
id 'idea'
id 'eclipse'

// Publishing
id 'maven-publish'
id 'signing'
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
}

//apply from: 'publish.gradle'

group = 'dev.openfga'
version = '0.0.1'

repositories {
mavenCentral()
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

withJavadocJar()
withSourcesJar()
}

sourceSets {
main {
java {
srcDirs = [
'src/main/java',
'src/main/gen',
]
}
}
test {
java {
srcDirs = ['src/test/java']
}
}
}

javadoc {
exclude("dev/openfga/language/antlr/**")

// Ignore warnings.
options.addStringOption('Xdoclint:none', '-quiet')
}

test {
useJUnitPlatform()
// JaCoCo coverage report is always generated after tests run.
finalizedBy jacocoTestReport
}

jacocoTestReport {
// tests are required to run before generating a JaCoCo coverage report.
dependsOn test
}

ext {
junit_version = "5.10.1"
}

dependencies {
implementation 'org.antlr:antlr4:4.13.1'
implementation 'dev.openfga:openfga-sdk:0.3.1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.15.3'
}
Empty file added pkg/java/gradle.properties
Empty file.
Binary file added pkg/java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions pkg/java/gradle/wrapper/gradle-wrapper.properties
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.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 772cdd8

Please sign in to comment.