Skip to content

Commit

Permalink
Merge pull request #619 from plantbreeding/gradle-build
Browse files Browse the repository at this point in the history
Gradle build
  • Loading branch information
daveneti authored Nov 11, 2024
2 parents e60eaaf + 0d72b00 commit 908780a
Show file tree
Hide file tree
Showing 10 changed files with 492 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/generate-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
push:
branches: [ "data-model-separation" ]
workflow_dispatch:
jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

# Configure Gradle for optimal use in GitHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Build with Gradle Wrapper
run: generator/gradlew validate
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.settings/
.idea
.vscode/
.idea

/_temp
brapi_blueprint.apib
Expand Down
3 changes: 3 additions & 0 deletions generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gradle
build
!gradle/wrapper/gradle-wrapper.jar
38 changes: 38 additions & 0 deletions generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# BrAPI Schema Generator

Generates the OpenAPI Specification, GraphQL Schema and OWL Model from the JSON Schema.
The files are generated in the Specification/Generated directory.

### How to use

To generate all use the following

* In windows

```powershell
./gradlew generateAll
```

* In Linux or macOS

```shell
./gradle generateAll
```
For individual tasks try

* *generateGraphQL* to generate the GraphQL Schema from the JSON Schema
* *generateOpenAPI* to generate the OpenAPI Specification from the JSON Schema
* *generateOWL* to generate the OWL Model from the JSON Schema
* *validate* to validate the JSON Schema without generating any file

The files are generated in the Specification/Generated directory.

to change the version of BrAPI used in the file name edit the *brapiVersion* in
[Settings](settings.gradle).

### Configuration

To configure the generator see https://github.com/plantbreeding/brapi-schema-tools


72 changes: 72 additions & 0 deletions generator/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apply plugin : "java"
ext {
javaMainClass = 'org.brapi.schematools.cli.BrAPICommand'
brapiSchemaToolsVersion = '0.10.0-SNAPSHOT'
brapiVersion = 'v2_1'
}

repositories {
mavenCentral()
maven {url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'}
}

dependencies {
implementation "org.brapi:brapi-schema-tools-cli:$brapiSchemaToolsVersion"
}

tasks.register("validate", JavaExec) {
group = 'BrAPI'
description = 'Validate the Json Schema'
classpath = sourceSets.main.runtimeClasspath
mainClass = javaMainClass
workingDir = '../'
args = ['validate', 'Specification/BrAPI-Schema', '-x']
}

tasks.register("generateGraphQL", JavaExec) {
group = 'BrAPI'
description = 'Generate GraphQL schema from the Json Schema'
classpath = sourceSets.main.runtimeClasspath
mainClass = javaMainClass
workingDir = '../'
def filename = "Specification/Generated/brapi_" + brapiVersion + ".graphqls"
args = ['generate',
'Specification/BrAPI-Schema',
'-l', 'GRAPHQL',
'-f', filename,
'-x']
}

tasks.register("generateOpenAPI", JavaExec) {
group = 'BrAPI'
description = 'Generate OpenAPI schema from the Json Schema'
classpath = sourceSets.main.runtimeClasspath
mainClass = javaMainClass
workingDir = '../'
def filename = "Specification/Generated/brapi_" + brapiVersion + ".json"
args = ['generate', 'Specification/BrAPI-Schema',
'-l', 'OPEN_API',
'-f', filename,
'-c', 'Specification/OpenAPI-Components',
'-x']
}

tasks.register("generateOWL", JavaExec) {
group = 'BrAPI'
description = 'Generate OWL schema from the Json Schema'
classpath = sourceSets.main.runtimeClasspath
mainClass = javaMainClass
workingDir = '../'
def filename = "Specification/Generated/brapi_" + brapiVersion + ".ttl"
args = ['generate', 'Specification/BrAPI-Schema',
'-l', 'OWL',
'-f', filename,
'-m', 'generator/ont-model-metadata.yaml',
'-x']
}

tasks.register("generateAll") {
dependsOn generateGraphQL
dependsOn generateOpenAPI
dependsOn generateOWL
}
Binary file added generator/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions generator/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.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 908780a

Please sign in to comment.