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

Test Kotlin API #637

Merged
merged 3 commits into from
May 13, 2020
Merged

Test Kotlin API #637

merged 3 commits into from
May 13, 2020

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented May 12, 2020

From now on we officially™ support Kotlin API of JavaThemis on Android and desktop JVM.

It was possible to use JavaThemis via Kotlin before but we were not sure in the API we provided and we not guaranteeing its stability. Now we do.

User notes

API stability and maturity

All existing Kotlin API is now considered stable. That is, we will do our best to avoid breaking it and if there is a need to deprecate some parts of Kotlin API, you will be notified about that.

SecureCell APIs are considered mature for Kotlin. That is, we are happy with this API in Kotlin and will not update it unless absolutely necessary.

As of JavaThemis 0.13, other APIs are not yet mature for Kotlin. We will not break these APIs, but you might expect some new, improved APIs to appear and some APIs to be deprecated in later releases, until Kotlin API has stabilized and matured.

Java 1.7 is minimum target for apps, Java 1.8 is needed for compilation

The minimum target for applications using JavaThemis or AndroidThemis is still Java 1.7.

If you get JavaThemis from Maven, you can still use Java 1.7 to compile your applications.

However, JavaThemis now requires Java 1.8 or later for compilation from source. This is the requirement of Kotlin compiler.

Technical notes

We are using the latest current version of Kotlin: 1.3.72. Kotlin is used only for tests. JavaThemis does not and will not require Kotlin at runtime for applications.

Since Kotlin supports lambdas out of the box, a polyfill for org.junit.Assert#assertThrows is added. It makes exception testing much more readable.

The tests themselves were automatically converted from Java code by IntelliJ, they are basically the same. Though, they did require some manual cleanup after that.

We currently test only SecureCell in Kotlin. Other cryptosystems will require additional review which is out of scope for Themis 0.13. We will get back to them in next releases.

Checklist

  • Change is covered by automated tests
  • Benchmark results are attached (nope, not right now)
  • The coding guidelines are followed
  • Public API has proper documentation
  • Example projects and code samples are up-to-date (we don't have Kotlin examples, maybe later)
  • Changelog is updated

We are going to write Kotlin in JavaThemis to avoid adding new run-time
dependencies. Kotlin has great interop with Java due to this JVM thingie.
However, it will be nice to test our Java code with Kotlin to ensure that
our API works as intended.

Use the current latest stable version of Kotlin, configuruable via the
"kotlin_version" variable defined in the root project. There we also add
Maven Central repos where Kotlin pluggin and runtime are hosted.

Each subproject has Kotlin configured for it, even BoringSSL that does
not have any Kotlin code, but must have relevant targets as a
dependency. Note that desktop Java and Android use different plugin
because Kotlin compiles a little bit different on Android.

Kotlin runtime is required to run Kotlin code. Since we use Kotlin only
for tests, the runtime is added as test dependency. We build our code
for Java 1.7 so an appropriate runtime flavor is used.

Adding Kotlin also triggers a weird compilation error in Android's DEX
compiler as Kotlin runtime uses a lot of JetBrains annotations. This is
a known issue encountered by some project, and there is a workaround.
Add test suite written in Kotlin. This code has been automatically
converted by IntelliJ from Java test suite and cleaned up manually
after that.

One painful point is exception testing, the try-catch idiom from Java
looks really awful in Kotlin so I've simply polyfilled assertThrows()
method which is not available with Java 1.7. Kotlin can translate its
lambdas into Runnables so it works pretty well.
Note that Java 8 support is now required since Kotlin compiler needs it.
@ilammy ilammy added O-Android 🤖 Operating system: Android W-JavaThemis ☕ Wrapper: Java, Java and Kotlin API infrastructure Automated building and packaging labels May 12, 2020
Copy link
Contributor

@vixentael vixentael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update any java code of AndroidThemis to support kotlin?

@ilammy
Copy link
Collaborator Author

ilammy commented May 12, 2020

Do we need to update any java code of AndroidThemis to support Kotlin?

No, no changes are necessary. It is possible to import the current code and it will just work.

Gradle will also pick up any new Kotlin files automatically and will test them, both for desktop systems and for Android.

@ilammy ilammy merged commit eac3721 into cossacklabs:master May 13, 2020
@ilammy ilammy deleted the kotlin-tests branch May 13, 2020 10:55
@ilammy ilammy mentioned this pull request Jul 9, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Automated building and packaging O-Android 🤖 Operating system: Android W-JavaThemis ☕ Wrapper: Java, Java and Kotlin API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants