Skip to content

Commit 91179db

Browse files
takkeclaude
andcommitted
feat: KMP対応 (Phase 6)
kotlin(multiplatform) + jvm(android) + iosArm64/iosSimulatorArm64、Kotlin 2.2.21、version 2.0.0-SNAPSHOT 全ソースをcommonMainへ移動 (57 rename)、twitter4j-core 4.1.0-SNAPSHOT (KMP版) 依存へ更新 JVM依存を置換: Date→twitter4j.Date、SimpleDateFormat→kotlinx-datetime、 ConcurrentHashMap→expect/actual、equals のjavaClass→this::class メディアアップロードはV2MediaUploadSupport (expect/actual) でandroidMain分離 (iOSはstub) OAuth2TokenProvider/V2CustomConfigurationはJVM依存のためandroidMain残置 assemble/iOSコンパイル/publishToMavenLocal/TwitPane(app_research)参照ビルド成功 既存テストは本体API変更の追随が必要なため次フェーズで修復予定 (assembleには影響なし) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent cf5bab9 commit 91179db

73 files changed

Lines changed: 359 additions & 310 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 0 additions & 23 deletions
This file was deleted.

build.gradle.kts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// twitter4j-v2 私家版 - KMP移行 Phase 6
2+
// バージョン方針:
3+
// - KMP系列は 2.0 系とする(既存の 1.4.4 を mavenLocal で上書きしないため)
4+
// - 2.0.0-SNAPSHOT を採用
5+
// - artifact 座標は従来どおり io.github.takke:jp.takke.twitter4j-v2 を維持する
6+
plugins {
7+
// KMPモジュール(twitter4j-v2-support)で使用。ルートでは apply しない
8+
kotlin("multiplatform") version "2.2.21" apply false
9+
}
10+
11+
// 共通のグループ/バージョン定義
12+
// ⚠️ 本体(twitter4j-core)と同方式。subprojects への java プラグイン一括適用は KMP モジュールと
13+
// 衝突するため行わず、プラグイン適用・publish 設定は各モジュール側 build.gradle.kts に寄せる。
14+
allprojects {
15+
group = "io.github.takke"
16+
version = "2.0.0-SNAPSHOT"
17+
18+
repositories {
19+
// twitter4j-core 4.1.0-SNAPSHOT を mavenLocal から解決する
20+
mavenLocal()
21+
google()
22+
mavenCentral()
23+
}
24+
}

settings.gradle

Lines changed: 0 additions & 4 deletions
This file was deleted.

settings.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rootProject.name = "twitter4j-v2"
2+
3+
include(":twitter4j-v2-support")
4+
5+
// KMP移行 Phase 6: サンプルモジュール(kotlin/java example)は KMP 化の対象外。
6+
// 旧 Groovy ビルドでは subprojects へ kotlin-jvm を一括適用してビルド対象にしていたが、
7+
// KMP 構成では本体ライブラリのみをビルド対象とする(サンプルのソースは現状維持で残す)。
8+
//include(":twitter4j-v2-support-kotlin-example")
9+
//include(":twitter4j-v2-support-java-example")

twitter4j-v2-support/build.gradle

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// twitter4j-v2-support - KMP移行 Phase 6
2+
// 本体(twitter4j-core)の Phase 1 と同方式で KMP 化する。
3+
plugins {
4+
kotlin("multiplatform")
5+
`maven-publish`
6+
}
7+
8+
kotlin {
9+
jvmToolchain(11)
10+
11+
// 本体(twitter4j-core)と同方式: AGP は使わず jvm ターゲットを "android" という名前で構成する。
12+
jvm("android") {
13+
// 既存テストは JUnit4(org.junit.Test)ベースのため JUnit Platform は有効化しない。
14+
}
15+
16+
// iOS ターゲット(TwitPane 本体の慣例に合わせ iosX64 は含めない)。
17+
iosArm64()
18+
iosSimulatorArm64()
19+
20+
sourceSets {
21+
val commonMain by getting {
22+
dependencies {
23+
// 本体 twitter4j-core の共通API(JSONObject / HttpParameter / ParseUtil / Date 等)に依存する。
24+
api("org.twitter4j:twitter4j-core:4.1.0-SNAPSHOT")
25+
// dateToISO8601 の共通実装で使用(本体と同一の 0.8.0)。
26+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.8.0")
27+
}
28+
}
29+
val androidMain by getting {
30+
}
31+
// JVM(android)ユニットテスト。既存テストは JUnit4 + AssertJ ベース。
32+
// ネットワークが必要なテストが多く(実際の API 呼び出し)、CI/ローカルでは基本 skip 想定だが、
33+
// JSON パース系のオフラインテスト(PollResponseTest / UsersResponseTest 等)は実行可能。
34+
val androidTest by getting {
35+
dependencies {
36+
implementation("org.jetbrains.kotlin:kotlin-test")
37+
implementation("org.jetbrains.kotlin:kotlin-test-junit")
38+
implementation("junit:junit:4.13.2")
39+
implementation("org.assertj:assertj-core:3.21.0")
40+
}
41+
}
42+
}
43+
}
44+
45+
// -------------------------------------------------------------------------
46+
// publishing 設定(本体 twitter4j-core と同方式)
47+
// - KMP が自動生成する android publication の artifactId を従来の
48+
// "jp.takke.twitter4j-v2" にオーバーライドして publish する(座標を維持)。
49+
// - root(kotlinMultiplatform) publication は publish を無効化する。
50+
// - group は allprojects で io.github.takke を設定済み。
51+
// -------------------------------------------------------------------------
52+
publishing {
53+
publications {
54+
withType<MavenPublication> {
55+
if (name == "android") {
56+
artifactId = "jp.takke.twitter4j-v2"
57+
}
58+
}
59+
}
60+
}
61+
62+
// root(kotlinMultiplatform) publication は publish しない(android publication のみ publish)。
63+
tasks.matching {
64+
it.name.startsWith("publishKotlinMultiplatformPublication")
65+
}.configureEach {
66+
enabled = false
67+
}

twitter4j-v2-support/src/main/kotlin/twitter4j/OAuth2TokenProvider.kt renamed to twitter4j-v2-support/src/androidMain/kotlin/twitter4j/OAuth2TokenProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import twitter4j.conf.Configuration
66
class OAuth2TokenProvider(
77
private val conf: Configuration
88
) {
9-
private val http = HttpClientFactory.getInstance(conf.httpClientConfiguration)
9+
// KMP移行 Phase 6: core の Configuration は getHttpClientConfiguration() メソッド(プロパティ構文不可)
10+
private val http = HttpClientFactory.getInstance(conf.getHttpClientConfiguration())
1011

1112
data class Result(
1213
val tokenType: String,
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package twitter4j
2+
3+
import java.util.concurrent.ConcurrentHashMap
4+
5+
// JVM では従来どおり ConcurrentHashMap を用いる(マップ構造自体のスレッドセーフ性を維持)。
6+
internal actual fun <K : Any, V : Any> newV2ConcurrentMap(): MutableMap<K, V> = ConcurrentHashMap()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package twitter4j
2+
3+
import java.io.ByteArrayInputStream
4+
import java.io.IOException
5+
import java.nio.file.Files
6+
7+
/**
8+
* [V2MediaUploadSupport] の JVM(Android) 実装。
9+
* 従来 TwitterV2Impl / TwitterV2 に直接記述されていた java.io 依存のメディアアップロード処理を移設したもの。
10+
*/
11+
internal actual object V2MediaUploadSupport {
12+
13+
actual fun mediaHttpParameter(name: String, fileName: String, media: InputStream): HttpParameter =
14+
HttpParameter(name, fileName, media)
15+
16+
actual fun readBytes(media: InputStream): ByteArray =
17+
try {
18+
media.readBytes()
19+
} catch (ioe: IOException) {
20+
throw TwitterException("Failed to download the file.", ioe)
21+
}
22+
23+
actual fun byteArrayInputStream(bytes: ByteArray): InputStream =
24+
ByteArrayInputStream(bytes)
25+
26+
actual fun readNBytes(input: InputStream, len: Int): ByteArray =
27+
input.readNBytes(len)
28+
29+
actual fun probeContentType(file: File): String =
30+
Files.probeContentType(file.toPath())
31+
32+
actual fun fileName(file: File): String =
33+
file.name
34+
35+
actual fun openInputStream(file: File): InputStream =
36+
file.inputStream()
37+
}

twitter4j-v2-support/src/main/kotlin/twitter4j/conf/V2CustomConfiguration.kt renamed to twitter4j-v2-support/src/androidMain/kotlin/twitter4j/conf/V2CustomConfiguration.kt

File renamed without changes.

0 commit comments

Comments
 (0)