From 42f782960f024da74c18d71c42a38abaaa40cb9a Mon Sep 17 00:00:00 2001 From: Niklas Baudy Date: Thu, 26 May 2022 10:27:16 +0200 Subject: [PATCH] Multiplatform: Generate EmojiProviders into jvmMain. (#829) --- emoji-facebook/api/current.txt | 7 +++ emoji-facebook/build.gradle | 2 +- .../emoji/facebook/FacebookEmojiProvider.kt | 44 +++++++++++++++++++ emoji-google-compat/api/current.txt | 7 +++ emoji-google-compat/build.gradle | 2 +- .../googlecompat/GoogleCompatEmojiProvider.kt | 44 +++++++++++++++++++ emoji-google/api/current.txt | 7 +++ emoji-google/build.gradle | 2 +- .../emoji/google/GoogleEmojiProvider.kt | 44 +++++++++++++++++++ emoji-ios/api/current.txt | 7 +++ emoji-ios/build.gradle | 2 +- .../vanniktech/emoji/ios/IosEmojiProvider.kt | 44 +++++++++++++++++++ emoji-twitter/api/current.txt | 7 +++ emoji-twitter/build.gradle | 2 +- .../emoji/twitter/TwitterEmojiProvider.kt | 44 +++++++++++++++++++ generator/index.js | 11 +++++ generator/template/EmojiProviderJvm.kt | 30 +++++++++++++ 17 files changed, 301 insertions(+), 5 deletions(-) create mode 100644 emoji-facebook/src/jvmMain/kotlin/com/vanniktech/emoji/facebook/FacebookEmojiProvider.kt create mode 100644 emoji-google-compat/src/jvmMain/kotlin/com/vanniktech/emoji/googlecompat/GoogleCompatEmojiProvider.kt create mode 100644 emoji-google/src/jvmMain/kotlin/com/vanniktech/emoji/google/GoogleEmojiProvider.kt create mode 100644 emoji-ios/src/jvmMain/kotlin/com/vanniktech/emoji/ios/IosEmojiProvider.kt create mode 100644 emoji-twitter/src/jvmMain/kotlin/com/vanniktech/emoji/twitter/TwitterEmojiProvider.kt create mode 100644 generator/template/EmojiProviderJvm.kt diff --git a/emoji-facebook/api/current.txt b/emoji-facebook/api/current.txt index 534e83ec9c..098ed27b76 100644 --- a/emoji-facebook/api/current.txt +++ b/emoji-facebook/api/current.txt @@ -10,5 +10,12 @@ package com.vanniktech.emoji.facebook { property public com.vanniktech.emoji.EmojiCategory![] categories; } + public final class FacebookEmojiProvider implements com.vanniktech.emoji.EmojiProvider { + ctor public FacebookEmojiProvider(); + method public com.vanniktech.emoji.EmojiCategory![] getCategories(); + method public void release(); + property public com.vanniktech.emoji.EmojiCategory![] categories; + } + } diff --git a/emoji-facebook/build.gradle b/emoji-facebook/build.gradle index ff9ddc3846..65a4d1a541 100644 --- a/emoji-facebook/build.gradle +++ b/emoji-facebook/build.gradle @@ -10,7 +10,7 @@ plugins { metalava { filename = "api/current.txt" - sourcePaths = ["src/commonMain", "src/androidMain"] + sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"] } // CocoaPods requires a version. diff --git a/emoji-facebook/src/jvmMain/kotlin/com/vanniktech/emoji/facebook/FacebookEmojiProvider.kt b/emoji-facebook/src/jvmMain/kotlin/com/vanniktech/emoji/facebook/FacebookEmojiProvider.kt new file mode 100644 index 0000000000..e601c138d1 --- /dev/null +++ b/emoji-facebook/src/jvmMain/kotlin/com/vanniktech/emoji/facebook/FacebookEmojiProvider.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.vanniktech.emoji.facebook + +import com.vanniktech.emoji.EmojiCategory +import com.vanniktech.emoji.EmojiProvider +import com.vanniktech.emoji.facebook.category.ActivitiesCategory +import com.vanniktech.emoji.facebook.category.AnimalsAndNatureCategory +import com.vanniktech.emoji.facebook.category.FlagsCategory +import com.vanniktech.emoji.facebook.category.FoodAndDrinkCategory +import com.vanniktech.emoji.facebook.category.ObjectsCategory +import com.vanniktech.emoji.facebook.category.SmileysAndPeopleCategory +import com.vanniktech.emoji.facebook.category.SymbolsCategory +import com.vanniktech.emoji.facebook.category.TravelAndPlacesCategory + +class FacebookEmojiProvider : EmojiProvider { + override val categories: Array + get() = arrayOf( + SmileysAndPeopleCategory(), + AnimalsAndNatureCategory(), + FoodAndDrinkCategory(), + ActivitiesCategory(), + TravelAndPlacesCategory(), + ObjectsCategory(), + SymbolsCategory(), + FlagsCategory(), + ) + + override fun release() = Unit +} diff --git a/emoji-google-compat/api/current.txt b/emoji-google-compat/api/current.txt index b3eb558538..a3c026d4aa 100644 --- a/emoji-google-compat/api/current.txt +++ b/emoji-google-compat/api/current.txt @@ -11,5 +11,12 @@ package com.vanniktech.emoji.googlecompat { property public com.vanniktech.emoji.EmojiCategory![] categories; } + public final class GoogleCompatEmojiProvider implements com.vanniktech.emoji.EmojiProvider { + ctor public GoogleCompatEmojiProvider(); + method public com.vanniktech.emoji.EmojiCategory![] getCategories(); + method public void release(); + property public com.vanniktech.emoji.EmojiCategory![] categories; + } + } diff --git a/emoji-google-compat/build.gradle b/emoji-google-compat/build.gradle index ef4536bdbc..4c40ea0ae0 100644 --- a/emoji-google-compat/build.gradle +++ b/emoji-google-compat/build.gradle @@ -10,7 +10,7 @@ plugins { metalava { filename = "api/current.txt" - sourcePaths = ["src/commonMain", "src/androidMain"] + sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"] } // CocoaPods requires a version. diff --git a/emoji-google-compat/src/jvmMain/kotlin/com/vanniktech/emoji/googlecompat/GoogleCompatEmojiProvider.kt b/emoji-google-compat/src/jvmMain/kotlin/com/vanniktech/emoji/googlecompat/GoogleCompatEmojiProvider.kt new file mode 100644 index 0000000000..7419cbba28 --- /dev/null +++ b/emoji-google-compat/src/jvmMain/kotlin/com/vanniktech/emoji/googlecompat/GoogleCompatEmojiProvider.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.vanniktech.emoji.googlecompat + +import com.vanniktech.emoji.EmojiCategory +import com.vanniktech.emoji.EmojiProvider +import com.vanniktech.emoji.googlecompat.category.ActivitiesCategory +import com.vanniktech.emoji.googlecompat.category.AnimalsAndNatureCategory +import com.vanniktech.emoji.googlecompat.category.FlagsCategory +import com.vanniktech.emoji.googlecompat.category.FoodAndDrinkCategory +import com.vanniktech.emoji.googlecompat.category.ObjectsCategory +import com.vanniktech.emoji.googlecompat.category.SmileysAndPeopleCategory +import com.vanniktech.emoji.googlecompat.category.SymbolsCategory +import com.vanniktech.emoji.googlecompat.category.TravelAndPlacesCategory + +class GoogleCompatEmojiProvider : EmojiProvider { + override val categories: Array + get() = arrayOf( + SmileysAndPeopleCategory(), + AnimalsAndNatureCategory(), + FoodAndDrinkCategory(), + ActivitiesCategory(), + TravelAndPlacesCategory(), + ObjectsCategory(), + SymbolsCategory(), + FlagsCategory(), + ) + + override fun release() = Unit +} diff --git a/emoji-google/api/current.txt b/emoji-google/api/current.txt index 5e9fcddde2..e14ddf2b08 100644 --- a/emoji-google/api/current.txt +++ b/emoji-google/api/current.txt @@ -10,5 +10,12 @@ package com.vanniktech.emoji.google { property public com.vanniktech.emoji.EmojiCategory![] categories; } + public final class GoogleEmojiProvider implements com.vanniktech.emoji.EmojiProvider { + ctor public GoogleEmojiProvider(); + method public com.vanniktech.emoji.EmojiCategory![] getCategories(); + method public void release(); + property public com.vanniktech.emoji.EmojiCategory![] categories; + } + } diff --git a/emoji-google/build.gradle b/emoji-google/build.gradle index c3e0d971d2..0ac28332bb 100644 --- a/emoji-google/build.gradle +++ b/emoji-google/build.gradle @@ -10,7 +10,7 @@ plugins { metalava { filename = "api/current.txt" - sourcePaths = ["src/commonMain", "src/androidMain"] + sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"] } // CocoaPods requires a version. diff --git a/emoji-google/src/jvmMain/kotlin/com/vanniktech/emoji/google/GoogleEmojiProvider.kt b/emoji-google/src/jvmMain/kotlin/com/vanniktech/emoji/google/GoogleEmojiProvider.kt new file mode 100644 index 0000000000..c1f720da84 --- /dev/null +++ b/emoji-google/src/jvmMain/kotlin/com/vanniktech/emoji/google/GoogleEmojiProvider.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.vanniktech.emoji.google + +import com.vanniktech.emoji.EmojiCategory +import com.vanniktech.emoji.EmojiProvider +import com.vanniktech.emoji.google.category.ActivitiesCategory +import com.vanniktech.emoji.google.category.AnimalsAndNatureCategory +import com.vanniktech.emoji.google.category.FlagsCategory +import com.vanniktech.emoji.google.category.FoodAndDrinkCategory +import com.vanniktech.emoji.google.category.ObjectsCategory +import com.vanniktech.emoji.google.category.SmileysAndPeopleCategory +import com.vanniktech.emoji.google.category.SymbolsCategory +import com.vanniktech.emoji.google.category.TravelAndPlacesCategory + +class GoogleEmojiProvider : EmojiProvider { + override val categories: Array + get() = arrayOf( + SmileysAndPeopleCategory(), + AnimalsAndNatureCategory(), + FoodAndDrinkCategory(), + ActivitiesCategory(), + TravelAndPlacesCategory(), + ObjectsCategory(), + SymbolsCategory(), + FlagsCategory(), + ) + + override fun release() = Unit +} diff --git a/emoji-ios/api/current.txt b/emoji-ios/api/current.txt index 9ac41e78ca..c2d0ac72f1 100644 --- a/emoji-ios/api/current.txt +++ b/emoji-ios/api/current.txt @@ -10,5 +10,12 @@ package com.vanniktech.emoji.ios { property public com.vanniktech.emoji.EmojiCategory![] categories; } + public final class IosEmojiProvider implements com.vanniktech.emoji.EmojiProvider { + ctor public IosEmojiProvider(); + method public com.vanniktech.emoji.EmojiCategory![] getCategories(); + method public void release(); + property public com.vanniktech.emoji.EmojiCategory![] categories; + } + } diff --git a/emoji-ios/build.gradle b/emoji-ios/build.gradle index 8b9a4725a9..bcde8a542b 100644 --- a/emoji-ios/build.gradle +++ b/emoji-ios/build.gradle @@ -10,7 +10,7 @@ plugins { metalava { filename = "api/current.txt" - sourcePaths = ["src/commonMain", "src/androidMain"] + sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"] } // CocoaPods requires a version. diff --git a/emoji-ios/src/jvmMain/kotlin/com/vanniktech/emoji/ios/IosEmojiProvider.kt b/emoji-ios/src/jvmMain/kotlin/com/vanniktech/emoji/ios/IosEmojiProvider.kt new file mode 100644 index 0000000000..75e8661374 --- /dev/null +++ b/emoji-ios/src/jvmMain/kotlin/com/vanniktech/emoji/ios/IosEmojiProvider.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.vanniktech.emoji.ios + +import com.vanniktech.emoji.EmojiCategory +import com.vanniktech.emoji.EmojiProvider +import com.vanniktech.emoji.ios.category.ActivitiesCategory +import com.vanniktech.emoji.ios.category.AnimalsAndNatureCategory +import com.vanniktech.emoji.ios.category.FlagsCategory +import com.vanniktech.emoji.ios.category.FoodAndDrinkCategory +import com.vanniktech.emoji.ios.category.ObjectsCategory +import com.vanniktech.emoji.ios.category.SmileysAndPeopleCategory +import com.vanniktech.emoji.ios.category.SymbolsCategory +import com.vanniktech.emoji.ios.category.TravelAndPlacesCategory + +class IosEmojiProvider : EmojiProvider { + override val categories: Array + get() = arrayOf( + SmileysAndPeopleCategory(), + AnimalsAndNatureCategory(), + FoodAndDrinkCategory(), + ActivitiesCategory(), + TravelAndPlacesCategory(), + ObjectsCategory(), + SymbolsCategory(), + FlagsCategory(), + ) + + override fun release() = Unit +} diff --git a/emoji-twitter/api/current.txt b/emoji-twitter/api/current.txt index f9297c9fba..a0ea0987d7 100644 --- a/emoji-twitter/api/current.txt +++ b/emoji-twitter/api/current.txt @@ -10,5 +10,12 @@ package com.vanniktech.emoji.twitter { property public com.vanniktech.emoji.EmojiCategory![] categories; } + public final class TwitterEmojiProvider implements com.vanniktech.emoji.EmojiProvider { + ctor public TwitterEmojiProvider(); + method public com.vanniktech.emoji.EmojiCategory![] getCategories(); + method public void release(); + property public com.vanniktech.emoji.EmojiCategory![] categories; + } + } diff --git a/emoji-twitter/build.gradle b/emoji-twitter/build.gradle index b9af04744b..6529e74509 100644 --- a/emoji-twitter/build.gradle +++ b/emoji-twitter/build.gradle @@ -10,7 +10,7 @@ plugins { metalava { filename = "api/current.txt" - sourcePaths = ["src/commonMain", "src/androidMain"] + sourcePaths = ["src/commonMain", "src/androidMain", "src/jvmMain"] } // CocoaPods requires a version. diff --git a/emoji-twitter/src/jvmMain/kotlin/com/vanniktech/emoji/twitter/TwitterEmojiProvider.kt b/emoji-twitter/src/jvmMain/kotlin/com/vanniktech/emoji/twitter/TwitterEmojiProvider.kt new file mode 100644 index 0000000000..bbb0f83bc1 --- /dev/null +++ b/emoji-twitter/src/jvmMain/kotlin/com/vanniktech/emoji/twitter/TwitterEmojiProvider.kt @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.vanniktech.emoji.twitter + +import com.vanniktech.emoji.EmojiCategory +import com.vanniktech.emoji.EmojiProvider +import com.vanniktech.emoji.twitter.category.ActivitiesCategory +import com.vanniktech.emoji.twitter.category.AnimalsAndNatureCategory +import com.vanniktech.emoji.twitter.category.FlagsCategory +import com.vanniktech.emoji.twitter.category.FoodAndDrinkCategory +import com.vanniktech.emoji.twitter.category.ObjectsCategory +import com.vanniktech.emoji.twitter.category.SmileysAndPeopleCategory +import com.vanniktech.emoji.twitter.category.SymbolsCategory +import com.vanniktech.emoji.twitter.category.TravelAndPlacesCategory + +class TwitterEmojiProvider : EmojiProvider { + override val categories: Array + get() = arrayOf( + SmileysAndPeopleCategory(), + AnimalsAndNatureCategory(), + FoodAndDrinkCategory(), + ActivitiesCategory(), + TravelAndPlacesCategory(), + ObjectsCategory(), + SymbolsCategory(), + FlagsCategory(), + ) + + override fun release() = Unit +} diff --git a/generator/index.js b/generator/index.js index 1db208b88c..1b034a1f32 100644 --- a/generator/index.js +++ b/generator/index.js @@ -390,6 +390,7 @@ async function generateCode(map, targets) { const categoryChunkTemplate = await fs.readFile("template/CategoryChunk.kt", "utf-8"); const emojiProviderTemplate = await fs.readFile("template/EmojiProvider.kt", "utf-8"); const emojiProviderCompatTemplate = await fs.readFile("template/EmojiProviderCompat.kt", "utf-8"); + const emojiProviderJvm = await fs.readFile("template/EmojiProviderJvm.kt", "utf-8"); const entries = stable([...map.entries()], (first, second) => { return categoryInfo.findIndex(it => it.name === first[0]) - categoryInfo.findIndex(it => it.name === second[0]); @@ -398,6 +399,7 @@ async function generateCode(map, targets) { for (const target of targets) { const srcDir = `../emoji-${target.module}/src/androidMain/kotlin/com/vanniktech/emoji/${target.package}`; const commonSrcDir = `../emoji-${target.module}/src/commonMain/kotlin/com/vanniktech/emoji/${target.package}`; + const jvmSrcDir = `../emoji-${target.module}/src/jvmMain/kotlin/com/vanniktech/emoji/${target.package}`; if (target.module !== "google-compat") { await fs.emptyDir(commonSrcDir); @@ -406,6 +408,8 @@ async function generateCode(map, targets) { await fs.emptyDir(`${commonSrcDir}/category`) } + await fs.emptyDir(jvmSrcDir); + let strips = 0; for (const [category, emojis] of entries) { emojis.forEach(emoji => strips = Math.max(strips, emoji.x + 1)); @@ -468,6 +472,13 @@ async function generateCode(map, targets) { })); } + await fs.writeFile(`${jvmSrcDir}/${target.name}Provider.kt`, template(emojiProviderJvm)({ + package: target.package, + imports: imports, + name: target.name, + categories: categories, + })); + if (target.module !== "google-compat") { await fs.writeFile(`${commonSrcDir}/${target.name}.kt`, template(emojiTemplate)({ package: target.package, diff --git a/generator/template/EmojiProviderJvm.kt b/generator/template/EmojiProviderJvm.kt new file mode 100644 index 0000000000..f0b8a53c6f --- /dev/null +++ b/generator/template/EmojiProviderJvm.kt @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2016 - Niklas Baudy, Ruben Gees, Mario Đanić and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.vanniktech.emoji.<%= package %> + +import com.vanniktech.emoji.EmojiCategory +import com.vanniktech.emoji.EmojiProvider +<%= imports %> + +class <%= name %>Provider : EmojiProvider { + override val categories: Array + get() = arrayOf(<% categories.forEach(function(category) { %> + <%= category.name %>(),<% }); %> + ) + + override fun release() = Unit +}