Skip to content

Commit

Permalink
Merge pull request #3 from stadiamaps/feat/android-generated
Browse files Browse the repository at this point in the history
Android: Generating OSRM models
  • Loading branch information
ianthetechie authored Jul 19, 2024
2 parents 39ad70c + 67281ed commit 44d4563
Show file tree
Hide file tree
Showing 12 changed files with 560 additions and 1 deletion.
37 changes: 37 additions & 0 deletions .github/workflows/android-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Gradle Package

on:
release:
types: [published]

jobs:
build:

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

steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- name: Execute Gradle build
run: ./gradlew build

# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
- name: Publish to GitHub Packages
run: ./gradlew publish
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
45 changes: 45 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Kotlin CI with Gradle

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

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

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

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- name: Execute Gradle build
run: ./gradlew build

test:
runs-on: ubuntu-latest

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

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- name: Execute Gradle test
run: ./gradlew test
File renamed without changes.
46 changes: 45 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,48 @@
.build

## User settings
xcuserdata/
xcuserdata/

### Android ###
# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof

### Android Patch ###
gen-external-apklibs

# Replacement of .externalNativeBuild directories introduced
# with Android Studio 3.5.


.DS_Store
85 changes: 85 additions & 0 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode

plugins {
kotlin("jvm")
id("org.hidetake.swagger.generator") version "2.19.2"
`maven-publish`
}

repositories {
mavenCentral()
}

dependencies {
swaggerCodegen("org.openapitools:openapi-generator-cli:7.5.0")

// Dependencies of the generated code. Check out `build.gradle` in your build folder later if you're curious.
val moshiVersion = "1.15.1"
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion")
implementation("com.squareup.moshi:moshi-adapters:$moshiVersion")

testImplementation(kotlin("test"))
}

kotlin {
jvmToolchain(17)
}

tasks.test {
useJUnitPlatform()
}

swaggerSources {
register("osrm") {
val openApiFile = file("../openapi.yaml")
require(openApiFile.exists()) { "OpenAPI spec file not found: $openApiFile" }

setInputFile(openApiFile)
code(delegateClosureOf<GenerateSwaggerCode> {
language = "kotlin"
components = listOf("models")
additionalProperties = mapOf(
"groupId" to "com.osrm",
"packageName" to "com.osrm.api"
)
rawOptions = listOf(
"--skip-validate-spec"
)
})
}
}

// Comment this out if you do NOT want the code gen to run every time you build.
// There is an HTTP cache by default, so it won't necessarily make a request every single build.
tasks.compileKotlin.configure {
dependsOn(tasks.generateSwaggerCode)
}

sourceSets {
val main by getting
val osrm by swaggerSources.getting
main.kotlin.srcDir("${osrm.code.outputDir}/src/main/kotlin")
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/stadiamaps/osrm-openapi")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}

publications {
register<MavenPublication>("gpr") {
from(components["java"])

groupId = "com.osrm"
artifactId = "api"
version = "0.0.1"
}
}
}
12 changes: 12 additions & 0 deletions android/src/test/kotlin/TestModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import kotlin.test.Test
import com.osrm.api.models.Waypoint
import kotlin.test.assertEquals

class ModelTest {
@Test
fun testWaypoint() {
val waypoint = Waypoint("name", listOf(1.0, 2.0))
assertEquals("name", waypoint.name)
assertEquals(listOf(1.0, 2.0), waypoint.location)
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kotlin.code.style=official
retrofitVersion=2.9.0
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 44d4563

Please sign in to comment.