Skip to content

Commit

Permalink
Datastore kotlin new implementation (#1)
Browse files Browse the repository at this point in the history
- Adjustments to make the Library non-blocking
- Adjusting Build mechanism & Repository Publication
  • Loading branch information
AndreuZaitsev authored Mar 19, 2024
1 parent 10b8934 commit a6341b4
Show file tree
Hide file tree
Showing 46 changed files with 1,693 additions and 1,274 deletions.
23 changes: 23 additions & 0 deletions .github/actions/config-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: "Configure Cache"
description: "Download dependencies and save required cache"

runs:
using: "composite"
steps:
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Make gradle executable
shell: bash
run: chmod +x ./gradlew

- name: Download Depdendencies
shell: bash
env:
GRADLE_OPTS: "-Xms1g -Xmx4608M -XX:+HeapDumpOnOutOfMemoryError -Dorg.gradle.daemon=false -Dorg.gradle.caching=false -Dorg.gradle.configureondemand=true -Dfile.encoding=UTF-8 -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false"
run: |
./gradlew dependencies persistent-cookie-jar-okhttp:dependencies persistent-cookie-jar-okhttp:androidDependencies --no-parallel --no-daemon --max-workers 3
18 changes: 18 additions & 0 deletions .github/workflows/build-development.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Development build


on:
pull_request:
branches:
- 'master'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/config-action

- name: Run Unit Tests
run: ./gradlew persistent-cookie-jar-okhttp:test
24 changes: 24 additions & 0 deletions .github/workflows/publish_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Publish persistent-cookie-jar-okhttp Library

on:
push:
tags:
- 'v**'
env:
REPO_PUBLISH_URL: ${{ secrets.REPO_PUBLISH_URL }}
REPO_PUBLISH_USERID: ${{ secrets.REPO_PUBLISH_USERID }}
REPO_PUBLISH_PW: ${{ secrets.REPO_PUBLISH_PW }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/config-action

- name: Run Unit Tests
run: ./gradlew persistent-cookie-jar-okhttp:test

- name: Publish Library
run: ./gradlew --stacktrace -PrepoPublishURL=$REPO_PUBLISH_URL -PrepoPublishUsername=$REPO_PUBLISH_USERID -PrepoPublishPassword=$REPO_PUBLISH_PW clean persistent-cookie-jar-okhttp:assembleRelease publish
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# persistent-cookie-jar-okhttp for OkHttp 3

[![Release](https://jitpack.io/v/thomas-bouvier/persistent-cookie-jar-okhttp.svg)](https://jitpack.io/#thomas-bouvier/persistent-cookie-jar-okhttp)

A persistent CookieJar implementation for OkHttp 3 based on SharedPreferences.
A persistent CookieJar implementation for OkHttp 3 based on DataStore.

## Download

Expand All @@ -21,7 +19,7 @@ Step 2. Add the dependency

```groovy
dependencies {
implementation 'com.github.thomas-bouvier:persistent-cookie-jar-okhttp:1.0.2'
implementation "com.github.andreu-zaitsev:persistent-cookie-jar:0.1.0"
}
```

Expand All @@ -30,8 +28,7 @@ dependencies {
Create an instance of `PersistentCookieJar` passing a `CookieCache` and a `CookiePersistor`:

```java
ClearableCookieJar cookieJar =
new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context));
ClearableCookieJar cookieJar = new DataStorePersistentCookieJar(context);
```

Then just add the CookieJar when building your OkHttp client:
Expand All @@ -51,14 +48,16 @@ This is a really simple library but here are some of the things that it provides

* Decoupled and extensible: `CookieCache` and `CookiePersistor` are interfaces so you can provide your own implementation for each one.
* `CookieCache` represents an in-memory cookie storage. `SetCookieCache` is the provided implementation that uses a Set to store the Cookies.
* `CookiePersistor` represents a persistent storage. `SharedPrefsCookiePersistor` is the provided implementation that uses a SharedPreferences to persist the Cookies.
* `CoroutineCookiePersistor` represents a persistent storage.
* `CoroutineCookiePersistor.DataStoreImpl` is the provided implementation that uses a DataStore to persist the Cookies.

* Thread-safe: `PersistentCookieJar` public methods are synchronized so there is no need to worry about threading if you need to implement a `CookieCache` or a `CookiePersistor`.

## License

Copyright 2016 Francisco José Montiel Navarro
Copyright 2019 Thomas Bouvier
Copyright 2024 Andreu Zaitsev

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
20 changes: 0 additions & 20 deletions build.gradle

This file was deleted.

4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
alias(libs.plugins.androidLib) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
}
7 changes: 2 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.useAndroidX=true
35 changes: 35 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[versions]
agp = "8.3.0"
kotlin = "1.9.10"
coreKtx = "1.12.0"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
appcompat = "1.6.1"
material = "1.11.0"
okHttp = "4.12.0"
datastore = "1.0.0"
testCoreKtx = "1.5.0"
robolectric = "4.7.3"
mockito = "5.11.0"
mockitoKotlin = "5.2.1"
coroutinesTest = "1.8.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okHttp" }
androidx-datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "datastore" }
androidx-test-core-ktx = { group = "androidx.test", name = "core-ktx", version.ref = "testCoreKtx" }
robolectric = { group = "org.robolectric", name = "robolectric", version.ref = "robolectric" }
mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
mockito-kotlin = { group = "org.mockito.kotlin", name = "mockito-kotlin", version.ref = "mockitoKotlin" }
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutinesTest" }

[plugins]
androidLib = { id = "com.android.library", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Nov 12 21:26:03 CET 2019
#Fri Mar 08 09:52:39 CET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
55 changes: 0 additions & 55 deletions persistent-cookie-jar-okhttp/build.gradle

This file was deleted.

88 changes: 88 additions & 0 deletions persistent-cookie-jar-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
plugins {
alias(libs.plugins.androidLib)
alias(libs.plugins.jetbrainsKotlinAndroid)
`maven-publish`
}

group = "tv.pluto.android.libs"
version = "1.0.2-beta01-2024.03.19"

android {
namespace = "com.andreuzaitsev.persistentcookiejar"
compileSdk = 34

defaultConfig {
minSdk = 21
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
}


dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.datastore.preferences)
implementation(libs.material)
implementation(libs.okhttp)
testImplementation(libs.mockito)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.robolectric)
testImplementation(libs.junit)
testImplementation(libs.androidx.test.core.ktx)
testImplementation(libs.kotlinx.coroutines.test)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}

afterEvaluate {
publishing {
// These values are provided by the CI environment, args are retrieved from the command line.
val repoPublishURL: String? by project
val repoPublishUsername: String? by project
val repoPublishPassword: String? by project

repositories {
maven {
url = uri(repoPublishURL ?: "")
credentials {
username = repoPublishUsername
password = repoPublishPassword
}
}
}
publications {
publications.register<MavenPublication>("release") {
// Provide artifacts information requited by Maven Central
pom {
name.set("Custom persistent-cookie-jar-okhttp Library")
description.set(
"Custom version of persistent-cookie-jar-okhttp Library"
)
url.set("https://github.com/Pluto-tv/persistent-cookie-jar-okhttp")

developers {
developer {
id.set("Pluto TV")
name.set("Android Team (MH)")
}
}
scm {
url.set("https://github.com/Pluto-tv/persistent-cookie-jar-okhttp")
}
}
}
}
}
}
6 changes: 3 additions & 3 deletions persistent-cookie-jar-okhttp/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# By default, the flags in this file are appended to flags specified
# in /opt/android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
# directive in build.gradle.kts.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
Expand All @@ -16,8 +16,8 @@
# public *;
#}

-dontwarn com.thomasbouvier.persistentcookiejar.**
-keep class com.thomasbouvier.persistentcookiejar.**
-dontwarn com.andreuzaitsev.persistentcookiejar.**
-keep class com.andreuzaitsev.persistentcookiejar.**

-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion persistent-cookie-jar-okhttp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest
package="com.thomasbouvier.persistentcookiejar">
package="com.andreuzaitsev.persistentcookiejar">

<application/>

Expand Down
Loading

0 comments on commit a6341b4

Please sign in to comment.