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

Port to Kotlin Multiplatform #25

Merged
merged 105 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
916052c
Ported Feature and BaseFeature to Kotlin
Ercalvez Nov 20, 2023
b98a883
Ported Feature and BaseFeature to Kotlin
Ercalvez Nov 23, 2023
f64ae87
Rename .java to .kt
Ercalvez Dec 9, 2023
b3cf2b2
kmp WIP, use okio for I/O
Ercalvez Dec 9, 2023
47c30a4
Rename .java to .kt
Ercalvez Dec 16, 2023
3b53d73
trying to fix unit test
Ercalvez Dec 16, 2023
37258f4
Fixed file access tests + Locale equality
Ercalvez Dec 17, 2023
788dfdb
Rename .java to .kt
Ercalvez Dec 17, 2023
28b420d
Fixed dissectCountryCode
Ercalvez Dec 17, 2023
b4aca73
Fixed dissectCountryCode
Ercalvez Dec 17, 2023
6b067f9
Merge remote-tracking branch 'origin/kmp' into kmp
Ercalvez Dec 17, 2023
145f846
Fixed remove useless trycatch
Ercalvez Dec 18, 2023
102c10a
Rename .java to .kt
Ercalvez Dec 20, 2023
d3a45d5
Converted all files to Kotlin
Ercalvez Dec 20, 2023
3832f45
Converted all files to Kotlin
Ercalvez Dec 20, 2023
efa97a9
Merge remote-tracking branch 'origin/kmp' into kmp
Ercalvez Jan 16, 2024
49f0c9b
Fix build
Ercalvez Jan 16, 2024
08b67d8
fix resource path
Ercalvez Feb 15, 2024
0355d0f
cleaned imports and unused files
Ercalvez Feb 18, 2024
86a375d
cleaned imports and unused files
Ercalvez Feb 18, 2024
fcdb098
Merge remote-tracking branch 'origin/kmp' into kmp
Ercalvez Feb 18, 2024
55c4d61
fixed getAll methods in tests
Ercalvez Feb 20, 2024
2382034
fix excludeCountryCodes unit tests + dependencies
Ercalvez Feb 22, 2024
e2d344b
fix excludeCountryCodes unit tests + dependencies
Ercalvez Feb 22, 2024
f71a920
fix merge conflict
Ercalvez Feb 24, 2024
7d7b1fd
fix build gradle
Ercalvez Feb 24, 2024
5a35637
Apply suggestions from code review
westnordost Feb 25, 2024
2dad8c1
Shorter code
westnordost Feb 25, 2024
3391252
add comment
westnordost Feb 25, 2024
8056008
make canonicalize a kotlin extension function
westnordost Feb 26, 2024
78b992b
add missing import
westnordost Feb 26, 2024
10f3e7c
fix doc comment
westnordost Feb 26, 2024
bba61db
simplify/kotlinize constructor
westnordost Feb 26, 2024
796301d
make startsWith parameter not nullable
westnordost Feb 26, 2024
b1103e9
improve readability:
westnordost Feb 26, 2024
a97473b
fix build (sorry, my bad)
westnordost Feb 26, 2024
0ead17f
make canonicalTerms non-nullable
westnordost Feb 26, 2024
4f54b2d
simplify constructor
westnordost Feb 26, 2024
704479b
remove equals and hashCode - data classes generate this automatically
westnordost Feb 26, 2024
1bb77dd
remove Builder - unnecessary, just using constructor will do
westnordost Feb 26, 2024
7a91894
simplify languageTag function
westnordost Feb 26, 2024
aa29df6
no need for Locale constants in production code
westnordost Feb 26, 2024
ecdb82c
format
westnordost Feb 26, 2024
19f5388
fix documentation comment
westnordost Feb 26, 2024
2502926
simplify constructor
westnordost Feb 26, 2024
a9ac25e
make non-nullable
westnordost Feb 26, 2024
ca1b7cd
make into extension functions for better readability
westnordost Feb 26, 2024
3428fff
use more descriptive variable names
westnordost Feb 26, 2024
5c2ce26
rename some variables, remove unnecessary type declarations
westnordost Feb 26, 2024
753ba34
remove TestUtils object, assertEqualsIgnoreOrder will report more hel…
westnordost Feb 26, 2024
6e6fb35
remove some unnecessary type declarations
westnordost Feb 26, 2024
7a956b9
BaseFeature is immutable
westnordost Feb 26, 2024
11d5088
remove unnecessary private vals from BaseFeature
westnordost Feb 26, 2024
ce1c5a7
make synchronizedGetOrCreate an extension function
westnordost Feb 27, 2024
e896893
correct indentation
westnordost Feb 27, 2024
fe5e4de
fixed indentation, removed unnecessary type declarations, use getOrPut
westnordost Feb 27, 2024
688d125
replace selector interface with function
westnordost Feb 27, 2024
f93f3a6
improve readability
westnordost Feb 27, 2024
9495b2f
improve readability, remove some unnecessary copying, operator get fu…
westnordost Feb 27, 2024
a72e383
fix LocalizedFeature
westnordost Feb 27, 2024
db13f9c
no need for assertEqualsIgnoreOrder helper function
westnordost Feb 27, 2024
c5934c2
fix operator access
westnordost Feb 27, 2024
74a313f
clean FeatureDictionary
westnordost Feb 27, 2024
6060392
move JVM specific tests to jvmTest
westnordost Feb 27, 2024
95bad31
remove Locale data class, use string instead
westnordost Feb 28, 2024
4de0ab7
make LocalizedFeature a data class
westnordost Feb 28, 2024
7b409ab
make classes that should be internal internal
westnordost Feb 28, 2024
fb55933
Merge remote-tracking branch 'origin/kmp-language-tag' into pr/25
westnordost Mar 1, 2024
b68f5c4
use ktor
Ercalvez Mar 4, 2024
0b1d7d7
Merge remote-tracking branch 'origin/kmp' into kmp
Ercalvez Mar 4, 2024
4ae4615
use ktor
Ercalvez Mar 4, 2024
293ba52
solve failing test
westnordost Mar 4, 2024
23ba651
synchronized map using `lazy` operator
Ercalvez Mar 8, 2024
52fad29
de.westnordost.osmfeatures -> de/westnordost/osmfeatures
Ercalvez Mar 23, 2024
fc67633
move android-specific stuff
westnordost May 10, 2024
b806f01
gradle shenanigans
westnordost May 10, 2024
6234dd3
move up
westnordost May 10, 2024
56fbda0
remove actually not supported platforms
westnordost May 10, 2024
6fe7b1a
formatting
westnordost May 10, 2024
a2dec4f
replace okio with kotlinx-io
westnordost May 10, 2024
5b9c5fc
correct synchronization / lazynization
westnordost May 10, 2024
0fec5c7
Classes from kotlinx-io-core are on the interface
westnordost May 10, 2024
46bc930
add entry for changelog
westnordost May 10, 2024
b7ecd80
fix tests
westnordost May 10, 2024
8316895
should be internal
westnordost May 10, 2024
6d1c037
fix android build
westnordost May 10, 2024
4b0b7a8
update readme
westnordost May 10, 2024
2004dc1
prettify parsers
westnordost May 10, 2024
0c99a57
more parser stuff
westnordost May 10, 2024
aeaee48
remove todo
westnordost May 10, 2024
71b7143
add test also for brand data
westnordost May 13, 2024
ab9037e
remove unnecessary map
westnordost May 13, 2024
29bbe6c
don't create a new regex every time that function is called
westnordost May 13, 2024
dad3413
naming
westnordost May 13, 2024
89f893a
rename file
westnordost May 13, 2024
7354d42
add test and fix
westnordost May 13, 2024
4fdd7a2
declare io exception can be thrown
westnordost May 13, 2024
5b82c63
make getters public
westnordost May 13, 2024
2f5c4e4
update readme
westnordost May 13, 2024
cc75a24
fix building names and terms index
westnordost May 13, 2024
3e4715a
fix tests
westnordost May 13, 2024
b6f3e0c
add link to ticket to monitor
westnordost May 14, 2024
e58ce94
is is more correct to use "language" rather than "locale"
westnordost May 14, 2024
6572300
builders should only be constructable from the methods of FeatureDict…
westnordost May 14, 2024
7e66378
Merge branch 'master' into kmp
westnordost May 15, 2024
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
46 changes: 0 additions & 46 deletions build.gradle

This file was deleted.

83 changes: 83 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//import groovy.json.JsonSlurper
//import java.io.File
//import java.net.URL
//import java.util.Locale
//
//plugins {
// `java`
//}
//
//repositories {
// mavenCentral()
// google()
//}
//
//val downloadPresets by tasks.registering {
// doLast {
// val targetDir = "$projectDir/presets"
// val presetsUrl = URL("https://raw.githubusercontent.com/openstreetmap/id-tagging-schema/main/dist/presets.json")
// val contentsUrl = URL("https://api.github.com/repos/openstreetmap/id-tagging-schema/contents/dist/translations")
//
// File("$targetDir/presets.json").outputStream().use { it.write(presetsUrl.openStream().readBytes()) }
//
// val slurper = JsonSlurper()
// val contents = slurper.parse(contentsUrl, "UTF-8") as List<Map<String, Any>>
// contents.forEach {
// if (it["type"] == "file") {
// val language = it["name"].toString().substringBeforeLast(".")
// val translationsUrl = URL(it["download_url"].toString())
// val javaLanguage = bcp47LanguageTagToJavaLanguageTag(language)
// File("$targetDir/${javaLanguage}.json").outputStream().use { os ->
// os.write(translationsUrl.openStream().readBytes())
// }
// }
// }
// }
//}
//
//fun bcp47LanguageTagToJavaLanguageTag(bcp47: String): String {
// val locale = Locale.forLanguageTag(bcp47)
// var result = locale.language
// if (locale.country.isNotEmpty()) result += "-" + locale.country
// return result
//}

//publishing {
// repositories {
// maven {
// url = uri("https://github.com/westnordost/osmfeatures")
// }
// }
// publications {
// create<MavenPublication>("mavenJava") {
// groupId = "de.westnordost"
// artifactId = "osmfeatures"
// version = "5.2"
// from(components["java"])
//
// pom {
// name.value("osmfeatures")
// description.value("Java library to translate OSM tags to and from localized names.")
// url.value("https://github.com/westnordost/osmfeatures")
// scm {
// connection.value("https://github.com/westnordost/osmfeatures.git")
// developerConnection.value("https://github.com/westnordost/osmfeatures.git")
// url.value("https://github.com/westnordost/osmfeatures")
// }
// licenses {
// license {
// name.value("The Apache License, Version 2.0")
// url.value("http://www.apache.org/licenses/LICENSE-2.0.txt")
// }
// }
// developers {
// developer {
// id.value("westnordost")
// name.value("Tobias Zwick")
// email.value("[email protected]")
// }
// }
// }
// }
// }
//}
17 changes: 17 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[versions]
agp = "8.2.1"
kotlin = "1.9.22"
kotlinx-serialization-json = "1.6.0"
normalize = "1.0.5"
okio = "3.6.0"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
normalize = { module = "com.doist.x:normalize", version.ref = "normalize" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }


[plugins]
android-library = { id = "com.android.library", version.ref = "agp" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
12 changes: 6 additions & 6 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Mar 04 22:04:30 CET 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
#Fri Dec 22 21:31:41 CET 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 6 additions & 6 deletions library-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
}

dependencies {
//api (project(':library')) {
// api (project(':library')) {
api ('de.westnordost:osmfeatures:5.2') {
// it's already included in Android
exclude group: 'org.json', module: 'json'
Expand All @@ -23,12 +23,11 @@ dependencies {

android {
compileSdkVersion 32

defaultConfig {
minSdkVersion 9
targetSdkVersion 32
versionCode 1
versionName project.version
versionName "1"
}

compileOptions {
Expand All @@ -37,18 +36,19 @@ android {
}
}

task sourcesJar(type: Jar) {
tasks.register('sourcesJar', Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}

task javadoc(type: Javadoc) {
tasks.register('javadoc', Javadoc) {
source = android.sourceSets.main.java.srcDirs
failOnError = false
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task javadocJar(type: Jar, dependsOn: javadoc) {
tasks.register('javadocJar', Jar) {
dependsOn javadoc
from javadoc.destinationDir
classifier = 'javadoc'
}
Expand Down
1 change: 0 additions & 1 deletion library-android/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package de.westnordost.osmfeatures

import android.content.res.AssetManager

object AndroidFeatureDictionary {
/** Create a new FeatureDictionary which gets its data from the given directory in the app's asset folder. */
fun create(assetManager: AssetManager, presetsBasePath: String): FeatureDictionary {
return create(assetManager, presetsBasePath, null)
}

/** Create a new FeatureDictionary which gets its data from the given directory in the app's
* asset folder. Optionally, the path to the brand presets can be specified. */
fun create(
assetManager: AssetManager,
presetsBasePath: String,
brandPresetsBasePath: String?
): FeatureDictionary {
val featureCollection: LocalizedFeatureCollection =
IDLocalizedFeatureCollection(AssetManagerAccess(assetManager, presetsBasePath))

val brandsFeatureCollection: PerCountryFeatureCollection? = if (brandPresetsBasePath != null
) IDBrandPresetsFeatureCollection(AssetManagerAccess(assetManager, brandPresetsBasePath))
else null

return FeatureDictionary(featureCollection, brandsFeatureCollection)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.westnordost.osmfeatures

import android.content.res.AssetManager
import java.io.File

internal class AssetManagerAccess(assetManager: AssetManager, private val basePath: String) : FileAccessAdapter {
private val assetManager: AssetManager = assetManager

override fun exists(name: String): Boolean {
val files: Array<String> = assetManager.list(basePath) ?: return false
for (file in files) {
if (file == name) return true
}
return false
}

override fun open(name: String): okio.Source {
return assetManager.open(basePath + File.separator + name)
}
}
Loading