Skip to content

Commit

Permalink
Java SDK now depends on Kotlin SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
wkal-pubnub committed Aug 16, 2024
1 parent 6919320 commit 24d6dca
Show file tree
Hide file tree
Showing 897 changed files with 52,539 additions and 9,501 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.project
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.KtlintPlugin

class PubNubKotlinLibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
Expand All @@ -26,6 +22,7 @@ class PubNubKotlinLibraryPlugin : Plugin<Project> {
tasks.named("compileKotlin", KotlinJvmCompile::class.java) {
it.compilerOptions {
javaParameters.set(true)
freeCompilerArgs.add("-Xjvm-default=all")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class PubNubKotlinMultiplatformPlugin : Plugin<Project> {
compilation.compileTaskProvider.configure { task ->
task.compilerOptions {
javaParameters.set(true)
freeCompilerArgs.add("-Xjvm-default=all")
}
}
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.gradle.nexus.publish)
alias(libs.plugins.kotlinx.atomicfu) apply false
kotlin("plugin.lombok") version "2.0.0" apply false
}

nexusPublishing {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RELEASE_SIGNING_ENABLED=true
SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=false
GROUP=com.pubnub
VERSION_NAME=9.2.3
VERSION_NAME=9.2-DEV
POM_PACKAGING=jar

POM_NAME=PubNub SDK
Expand All @@ -43,4 +43,4 @@ SWIFT_PATH=swift

ENABLE_TARGET_JS=false
ENABLE_TARGET_IOS=false
ENABLE_TARGET_IOS_SIMULATOR=false
ENABLE_TARGET_IOS_SIMULATOR=false
13 changes: 13 additions & 0 deletions migration_utils/replace_in_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
file="$4"
search="$1"
replace="$2"
dry_run="$3"

if [[ "$dry_run" == "true" ]]; then
if grep -q "$search" "$file"; then
echo "$file"
fi
else
sed -i '' "s#$search#$replace#g" "$file"
fi
193 changes: 193 additions & 0 deletions migration_utils/replacements.txt

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions migration_utils/upgrade_v10.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
set -e
# Function to check if a file contains a search string

# Main script
if [ $# -lt 2 ]; then
echo "Usage: $0 <replacements_file> <directory> [-d]"
exit 1
fi

dry_run=false
replacements_file="$1"
directory="$2"

# Check for dry run flag
shift 2
while [[ $# -gt 0 ]]; do
case "$1" in
-d|--dry-run)
dry_run=true
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
shift
done

# Read replacements from file
while IFS= read -r line; do
if [[ $line =~ ^([^:]+):(.+)$ ]]; then
search="${BASH_REMATCH[1]}"
replace="${BASH_REMATCH[2]}"
echo "Replacing '$search' with '$replace'"

# Find all files and apply the replacement or print
find "$directory" -type f -print0 | xargs -0 -n 1 ./replace_in_file.sh "$search" "$replace" "$dry_run" | sort -u
fi
done < "$replacements_file"
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.pubnub.api.endpoints

import com.pubnub.api.v2.BasePNConfiguration

interface HasOverridableConfig {
fun overrideConfiguration(configuration: BasePNConfiguration)
fun overrideConfiguration(configuration: PNConfiguration)

val configuration: BasePNConfiguration
val configuration: PNConfiguration
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import javax.net.ssl.X509ExtendedTrustManager
* allow performing precise PubNub client configuration.
*
*/
interface BasePNConfiguration : BasePNConfigurationOverride {
interface PNConfiguration : PNConfigurationOverride {
/**
* The user ID that the PubNub client will use.
*/
Expand Down Expand Up @@ -278,7 +278,7 @@ interface BasePNConfiguration : BasePNConfigurationOverride {
* using [PubNubCore.presence]. Should be used only with ACL set on the server side.
* For more information please contact PubNub support
* @see PubNubCore.presence
* @see BasePNConfiguration.heartbeatInterval
* @see PNConfiguration.heartbeatInterval
*/
val managePresenceListManually: Boolean

Expand Down Expand Up @@ -551,7 +551,7 @@ interface BasePNConfiguration : BasePNConfigurationOverride {
* using [PubNubCore.presence]. Should be used only with ACL set on the server side.
* For more information please contact PubNub support
* @see PubNubCore.presence
* @see BasePNConfiguration.heartbeatInterval
* @see PNConfiguration.heartbeatInterval
*/
val managePresenceListManually: Boolean
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.pubnub.api.UserId
import com.pubnub.api.crypto.CryptoModule
import com.pubnub.api.retry.RetryConfiguration

interface BasePNConfigurationOverride {
interface PNConfigurationOverride {
interface Builder {
/**
* The subscribe key from the admin panel.
Expand Down
2 changes: 1 addition & 1 deletion pubnub-core/pubnub-core-impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ val generateVersion =
kotlin.sourceSets.getByName("main").kotlin.srcDir(generateVersion)

dependencies {
api(project(":pubnub-core:pubnub-core-api"))
// api(project(":pubnub-core:pubnub-core-api"))

implementation(libs.retrofit2)
implementation(libs.retrofit2.converter.gson)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pubnub.internal.vendor;

import com.pubnub.api.v2.BasePNConfiguration;
import com.pubnub.api.v2.PNConfiguration;
import com.pubnub.internal.PubNubCore;
import com.pubnub.internal.PubNubUtil;
import okhttp3.Call;
Expand All @@ -23,9 +23,9 @@

public class AppEngineFactory implements Call {
private Request request;
private final BasePNConfiguration configuration;
private final PNConfiguration configuration;

AppEngineFactory(Request request, BasePNConfiguration configuration) {
AppEngineFactory(Request request, PNConfiguration configuration) {
this.request = request;
this.configuration = configuration;
}
Expand Down Expand Up @@ -137,9 +137,9 @@ public Call clone() {
}

public static class Factory implements Call.Factory {
private final BasePNConfiguration configuration;
private final PNConfiguration configuration;

public Factory(BasePNConfiguration configuration) {
public Factory(PNConfiguration configuration) {
this.configuration = configuration;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.pubnub.internal

import com.pubnub.api.BasePubNub
import com.pubnub.api.callbacks.Listener
import com.pubnub.api.models.consumer.access_manager.v3.PNToken
import com.pubnub.api.v2.BasePNConfiguration
import com.pubnub.api.v2.callbacks.BaseEventEmitter
import com.pubnub.api.v2.callbacks.BaseEventListener
import com.pubnub.api.v2.callbacks.BaseStatusEmitter
Expand All @@ -29,13 +27,13 @@ abstract class BasePubNubImpl<
SubscriptionSet : BaseSubscriptionSet<EventListener, Subscription>,
StatusListener : BaseStatusListener,
> internal constructor(
configuration: BasePNConfiguration,
configuration: PNConfiguration,
pnsdkName: String,
eventEnginesConf: EventEnginesConf = EventEnginesConf(),
) : BasePubNub<EventListener, Subscription, Channel, ChannelGroup, ChannelMetadata, UserMetadata, SubscriptionSet, StatusListener>,
BaseEventEmitter<EventListener>,
BaseStatusEmitter<StatusListener> {
constructor(configuration: BasePNConfiguration, pnsdkName: String) : this(configuration, pnsdkName, EventEnginesConf())
constructor(configuration: PNConfiguration, pnsdkName: String) : this(configuration, pnsdkName, EventEnginesConf())

val listenerManager: ListenerManager = ListenerManager(this)
val pubNubCore = PubNubCore(configuration, listenerManager, eventEnginesConf, pnsdkName)
Expand All @@ -55,7 +53,7 @@ abstract class BasePubNubImpl<
/**
* Unique id of this PubNub instance.
*
* @see [BasePNConfiguration.includeInstanceIdentifier]
* @see [PNConfiguration.includeInstanceIdentifier]
*/
val instanceId: String
get() = pubNubCore.instanceId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import com.google.gson.JsonElement
import com.pubnub.api.PubNubError
import com.pubnub.api.PubNubException
import com.pubnub.api.retry.RetryableEndpointGroup
import com.pubnub.api.v2.BasePNConfiguration
import com.pubnub.api.v2.BasePNConfiguration.Companion.isValid
import com.pubnub.api.v2.PNConfiguration.Companion.isValid
import com.pubnub.api.v2.callbacks.Consumer
import com.pubnub.api.v2.callbacks.Result
import com.pubnub.internal.managers.RetrofitManager
Expand All @@ -29,8 +28,8 @@ import java.net.UnknownHostException
*/
abstract class EndpointCore<Input, Output> protected constructor(protected val pubnub: PubNubCore) :
EndpointInterface<Output> {
private var configOverride: BasePNConfiguration? = null
final override val configuration: BasePNConfiguration
private var configOverride: PNConfiguration? = null
final override val configuration: PNConfiguration
get() = configOverride ?: pubnub.configuration

protected val retrofitManager: RetrofitManager
Expand Down Expand Up @@ -426,7 +425,7 @@ abstract class EndpointCore<Input, Output> protected constructor(protected val p
}
}

override fun overrideConfiguration(configuration: BasePNConfiguration) {
override fun overrideConfiguration(configuration: PNConfiguration) {
this.configOverride = configuration
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.pubnub.api.models.consumer.access_manager.v3.PNToken
import com.pubnub.api.models.consumer.history.PNHistoryResult
import com.pubnub.api.models.consumer.message_actions.PNMessageAction
import com.pubnub.api.models.consumer.objects.PNPage
import com.pubnub.api.v2.BasePNConfiguration
import com.pubnub.api.v2.callbacks.BaseEventListener
import com.pubnub.api.v2.subscriptions.BaseSubscription
import com.pubnub.api.v2.subscriptions.EmptyOptions
Expand Down Expand Up @@ -110,7 +109,7 @@ import java.util.concurrent.ScheduledExecutorService
import kotlin.time.Duration.Companion.seconds

class PubNubCore internal constructor(
val configuration: BasePNConfiguration,
val configuration: PNConfiguration,
val listenerManager: ListenerManager,
eventEnginesConf: EventEnginesConf = EventEnginesConf(),
private val pnsdkName: String,
Expand Down Expand Up @@ -178,7 +177,7 @@ class PubNubCore internal constructor(
/**
* Unique id of this PubNub instance.
*
* @see [BasePNConfiguration.includeInstanceIdentifier]
* @see [PNConfiguration.includeInstanceIdentifier]
*/
val instanceId = UUID.randomUUID().toString()

Expand All @@ -203,12 +202,12 @@ class PubNubCore internal constructor(
/**
* Send a message to all subscribers of a channel.
*
* To publish a message you must first specify a valid [BasePNConfiguration.publishKey].
* To publish a message you must first specify a valid [PNConfiguration.publishKey].
* A successfully published message is replicated across the PubNub Real-Time Network and sent
* simultaneously to all subscribed clients on a channel.
*
* Messages in transit can be secured from potential eavesdroppers with SSL/TLS by setting
* [BasePNConfiguration.secure] to `true` during initialization.
* [PNConfiguration.secure] to `true` during initialization.
*
* **Publish Anytime**
*
Expand Down Expand Up @@ -719,7 +718,7 @@ class PubNubCore internal constructor(
* Obtain information about the current list of channels to which a UUID is subscribed to.
*
* @param uuid UUID of the user to get its current channel subscriptions. Defaults to the UUID of the client.
* @see [BasePNConfiguration.uuid]
* @see [PNConfiguration.uuid]
*/
fun whereNow(uuid: String = configuration.userId.value) = WhereNowEndpoint(pubnub = this, uuid = uuid)

Expand All @@ -728,7 +727,7 @@ class PubNubCore internal constructor(
*
* State information is supplied as a JSON object of key/value pairs.
*
* If [BasePNConfiguration.maintainPresenceState] is `true`, and the `uuid` matches [BasePNConfiguration.uuid], the state
* If [PNConfiguration.maintainPresenceState] is `true`, and the `uuid` matches [PNConfiguration.uuid], the state
* for channels will be saved in the PubNub client and resent with every heartbeat and initial subscribe request.
* In that case, it's not recommended to mix setting state through channels *and* channel groups, as state set
* through the channel group will be overwritten after the next heartbeat or subscribe reconnection (e.g. after loss
Expand Down Expand Up @@ -2022,7 +2021,7 @@ class PubNubCore internal constructor(
//region Encryption

/**
* Perform Cryptographic decryption of an input string using cipher key provided by [BasePNConfiguration.cipherKey].
* Perform Cryptographic decryption of an input string using cipher key provided by [PNConfiguration.cipherKey].
*
* @param inputString String to be decrypted.
*
Expand All @@ -2036,7 +2035,7 @@ class PubNubCore internal constructor(
* Perform Cryptographic decryption of an input string using a cipher key.
*
* @param inputString String to be decrypted.
* @param cipherKey cipher key to be used for decryption. Default is [BasePNConfiguration.cipherKey]
* @param cipherKey cipher key to be used for decryption. Default is [PNConfiguration.cipherKey]
*
* @return String containing the decryption of `inputString` using `cipherKey`.
* @throws PubNubException throws exception in case of failed decryption.
Expand Down Expand Up @@ -2066,7 +2065,7 @@ class PubNubCore internal constructor(
* Perform Cryptographic encryption of an input string and a cipher key.
*
* @param inputString String to be encrypted.
* @param cipherKey Cipher key to be used for encryption. Default is [BasePNConfiguration.cipherKey]
* @param cipherKey Cipher key to be used for encryption. Default is [PNConfiguration.cipherKey]
*
* @return String containing the encryption of `inputString` using `cipherKey`.
* @throws PubNubException Throws exception in case of failed encryption.
Expand Down Expand Up @@ -2246,14 +2245,14 @@ class PubNubCore internal constructor(
* Causes the client to create an open TCP socket to the PubNub Real-Time Network and begin listening for messages
* on a specified channel.
*
* To subscribe to a channel the client must send the appropriate [BasePNConfiguration.subscribeKey] at initialization.
* To subscribe to a channel the client must send the appropriate [PNConfiguration.subscribeKey] at initialization.
*
* By default, a newly subscribed client will only receive messages published to the channel
* after the `subscribe()` call completes.
*
* If a client gets disconnected from a channel, it can automatically attempt to reconnect to that channel
* and retrieve any available messages that were missed during that period.
* This can be achieved by setting [BasePNConfiguration.retryConfiguration] when
* This can be achieved by setting [PNConfiguration.retryConfiguration] when
* initializing the client.
*
* @param channels Channels to subscribe/unsubscribe. Either `channel` or [channelGroups] are required.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.pubnub.internal

import com.pubnub.api.PubNubException
import com.pubnub.api.v2.BasePNConfiguration
import com.pubnub.api.v2.BasePNConfiguration.Companion.isValid
import com.pubnub.api.v2.PNConfiguration.Companion.isValid
import okhttp3.Request
import okio.Buffer
import org.slf4j.LoggerFactory
Expand Down Expand Up @@ -59,7 +58,7 @@ internal object PubNubUtil {

fun signRequest(
originalRequest: Request,
pnConfiguration: BasePNConfiguration,
pnConfiguration: PNConfiguration,
timestamp: Int,
): Request {
// only sign if we have a secret key in place.
Expand All @@ -81,7 +80,7 @@ internal object PubNubUtil {
return originalRequest.newBuilder().url(rebuiltUrl).build()
}

fun shouldSignRequest(configuration: BasePNConfiguration): Boolean {
fun shouldSignRequest(configuration: PNConfiguration): Boolean {
return configuration.secretKey.isValid()
}

Expand Down
Loading

0 comments on commit 24d6dca

Please sign in to comment.