From ac0aa49bc5e6129c1b16df293042f79089648161 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 1 May 2020 11:15:23 +0530 Subject: [PATCH 01/24] =?UTF-8?q?=E2=97=80=EF=B8=8F=20building=20dagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 9 +++-- .../gpm/core/GpmDependencyCollector.kt | 11 ------- .../gpm/core/MavenDependencyCollector.kt | 10 ------ .../theapache64/gpm/core/RegistryManager.kt | 4 +-- ...DependencyCollector.kt => BaseRegistry.kt} | 3 +- .../core/registries/gpm/GpmApiInterface.kt | 11 +++++++ .../gpm/core/registries/gpm/GpmRegistry.kt | 19 +++++++++++ .../registries/maven/MavenApiInterface.kt | 5 +++ .../core/registries/maven/MavenRegistry.kt | 17 ++++++++++ .../gpm/di/modules/NetworkModule.kt | 33 +++++++++++++++++++ .../com/theapache64/gpm/models/Dependency.kt | 15 ++++----- 11 files changed, 103 insertions(+), 34 deletions(-) delete mode 100644 src/main/kotlin/com/theapache64/gpm/core/GpmDependencyCollector.kt delete mode 100644 src/main/kotlin/com/theapache64/gpm/core/MavenDependencyCollector.kt rename src/main/kotlin/com/theapache64/gpm/core/base/{BaseDependencyCollector.kt => BaseRegistry.kt} (65%) create mode 100644 src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmApiInterface.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmRegistry.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenApiInterface.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenRegistry.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt diff --git a/build.gradle b/build.gradle index b28abe7..d6481a6 100644 --- a/build.gradle +++ b/build.gradle @@ -25,8 +25,13 @@ dependencies { implementation 'info.picocli:picocli:4.2.0' kapt 'info.picocli:picocli-codegen:4.2.0' - // Gson - implementation 'com.google.code.gson:gson:2.8.6' + // Retrofit + implementation 'com.squareup.retrofit2:retrofit:2.8.1' + implementation 'com.squareup.retrofit2:converter-moshi:2.8.1' + + // Dagger + implementation 'com.google.dagger:dagger:2.27' + kapt 'com.google.dagger:dagger-compiler:2.27' testImplementation group: 'junit', name: 'junit', version: '4.12' testImplementation 'com.winterbe:expekt:0.5.0' diff --git a/src/main/kotlin/com/theapache64/gpm/core/GpmDependencyCollector.kt b/src/main/kotlin/com/theapache64/gpm/core/GpmDependencyCollector.kt deleted file mode 100644 index 0e700ba..0000000 --- a/src/main/kotlin/com/theapache64/gpm/core/GpmDependencyCollector.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.theapache64.gpm.core - -import com.theapache64.gpm.core.base.BaseDependencyCollector -import com.theapache64.gpm.models.Dependency - -object GpmDependencyCollector : BaseDependencyCollector { - - override fun getDependency(name: String): Dependency? { - TODO("Not yet implemented") - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/core/MavenDependencyCollector.kt b/src/main/kotlin/com/theapache64/gpm/core/MavenDependencyCollector.kt deleted file mode 100644 index 9eaedc3..0000000 --- a/src/main/kotlin/com/theapache64/gpm/core/MavenDependencyCollector.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.theapache64.gpm.core - -import com.theapache64.gpm.core.base.BaseDependencyCollector -import com.theapache64.gpm.models.Dependency - -object MavenDependencyCollector : BaseDependencyCollector { - override fun getDependency(name: String): Dependency? { - TODO("Not yet implemented") - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/core/RegistryManager.kt b/src/main/kotlin/com/theapache64/gpm/core/RegistryManager.kt index c5ddf98..b0d7953 100644 --- a/src/main/kotlin/com/theapache64/gpm/core/RegistryManager.kt +++ b/src/main/kotlin/com/theapache64/gpm/core/RegistryManager.kt @@ -1,12 +1,12 @@ package com.theapache64.gpm.core +import com.theapache64.gpm.core.registries.gpm.GpmRegistry import com.theapache64.gpm.models.Dependency object RegistryManager { - private val dependencyCollectors = listOf( - GpmDependencyCollector + GpmRegistry ) /** diff --git a/src/main/kotlin/com/theapache64/gpm/core/base/BaseDependencyCollector.kt b/src/main/kotlin/com/theapache64/gpm/core/base/BaseRegistry.kt similarity index 65% rename from src/main/kotlin/com/theapache64/gpm/core/base/BaseDependencyCollector.kt rename to src/main/kotlin/com/theapache64/gpm/core/base/BaseRegistry.kt index 68de208..69c898b 100644 --- a/src/main/kotlin/com/theapache64/gpm/core/base/BaseDependencyCollector.kt +++ b/src/main/kotlin/com/theapache64/gpm/core/base/BaseRegistry.kt @@ -2,6 +2,7 @@ package com.theapache64.gpm.core.base import com.theapache64.gpm.models.Dependency -interface BaseDependencyCollector { +interface BaseRegistry { + fun getDependencyUrl(name: String): String fun getDependency(name: String): Dependency? } \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmApiInterface.kt b/src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmApiInterface.kt new file mode 100644 index 0000000..4e77d60 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmApiInterface.kt @@ -0,0 +1,11 @@ +package com.theapache64.gpm.core.registries.gpm + +import com.theapache64.gpm.models.Dependency +import retrofit2.http.GET + +interface GpmApiInterface { + + @GET("https://raw.githubusercontent.com/theapache64/gpm/master/registry/{name}.json") + suspend fun getDependency(): Dependency + +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmRegistry.kt b/src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmRegistry.kt new file mode 100644 index 0000000..096df22 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmRegistry.kt @@ -0,0 +1,19 @@ +package com.theapache64.gpm.core.registries.gpm + +import com.theapache64.gpm.core.base.BaseRegistry +import com.theapache64.gpm.models.Dependency +import java.net.URLEncoder + +object GpmRegistry : BaseRegistry { + + override fun getDependencyUrl(name: String): String { + val nameEnc = URLEncoder.encode(name, "UTF-8") + return "https://raw.githubusercontent.com/theapache64/gpm/master/registry/$nameEnc.json" + } + + override fun getDependency(name: String): Dependency? { + val url = getDependencyUrl(name) + + return null + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenApiInterface.kt b/src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenApiInterface.kt new file mode 100644 index 0000000..83419b8 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenApiInterface.kt @@ -0,0 +1,5 @@ +package com.theapache64.gpm.core.registries.maven + +interface MavenApiInterface { + +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenRegistry.kt b/src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenRegistry.kt new file mode 100644 index 0000000..855b797 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenRegistry.kt @@ -0,0 +1,17 @@ +package com.theapache64.gpm.core.registries.maven + +import com.theapache64.gpm.core.base.BaseRegistry +import com.theapache64.gpm.models.Dependency +import java.net.URLEncoder + +object MavenRegistry : BaseRegistry { + + override fun getDependencyUrl(name: String): String { + val nameEnc = URLEncoder.encode(name, "UTF-8") + return "https://search.maven.org/solrsearch/select?q=${nameEnc}okhttp&rows=1&wt=json" + } + + override fun getDependency(name: String): Dependency? { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt new file mode 100644 index 0000000..18c308c --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt @@ -0,0 +1,33 @@ +package com.theapache64.gpm.di.modules + +import com.theapache64.gpm.core.registries.gpm.GpmApiInterface +import com.theapache64.gpm.core.registries.maven.MavenApiInterface +import dagger.Module +import dagger.Provides +import retrofit2.Retrofit +import retrofit2.converter.moshi.MoshiConverterFactory +import javax.inject.Singleton + +@Module +class NetworkModule { + + @Singleton + @Provides + fun provideRetrofit(): Retrofit { + return Retrofit.Builder() + .addConverterFactory(MoshiConverterFactory.create()) + .build() + } + + @Singleton + @Provides + fun provideGpmApiInterface(retrofit: Retrofit): GpmApiInterface { + return retrofit.create(GpmApiInterface::class.java) + } + + @Singleton + @Provides + fun provideMavenApiInterface(retrofit: Retrofit): MavenApiInterface { + return retrofit.create(MavenApiInterface::class.java) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/models/Dependency.kt b/src/main/kotlin/com/theapache64/gpm/models/Dependency.kt index d68b1e1..b268929 100644 --- a/src/main/kotlin/com/theapache64/gpm/models/Dependency.kt +++ b/src/main/kotlin/com/theapache64/gpm/models/Dependency.kt @@ -1,19 +1,18 @@ package com.theapache64.gpm.models -import com.google.gson.annotations.SerializedName - +import com.squareup.moshi.Json data class Dependency( - @SerializedName("default_type") + @Json(name = "default_type") val defaultType: String, // implementation - @SerializedName("dependency_signature") + @Json(name = "dependency_signature") val dependencySignature: String, // com.squareup.okhttp3:okhttp - @SerializedName("docs") + @Json(name = "docs") val docs: String, // https://square.github.io/okhttp/ - @SerializedName("github") + @Json(name = "github") val github: String, // square/okhttp - @SerializedName("latest_version") + @Json(name = "latest_version") val latestVersion: String, // 4.6.0 - @SerializedName("name") + @Json(name = "name") val name: String // OkHttp ) \ No newline at end of file From d671c9b1d62614ae4720f5e9c10b80a750f2c9a9 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 1 May 2020 12:17:52 +0530 Subject: [PATCH 02/24] =?UTF-8?q?=E2=97=80=EF=B8=8F=20adpot=20semi-MVVM=20?= =?UTF-8?q?architecture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/jarRepositories.xml | 5 +++ build.gradle | 19 ++++++++ .../gpm/commands/subcommands/Install.kt | 25 ++++++++++- .../core/registries/gpm/GpmApiInterface.kt | 11 ----- .../registries/maven/MavenApiInterface.kt | 5 --- .../gpm/data/remote/GpmApiInterface.kt | 14 ++++++ .../gpm/data/remote/MavenApiInterface.kt | 5 +++ .../com/theapache64/gpm/data/repos/GpmRepo.kt | 23 ++++++++++ .../theapache64/gpm/data/repos/MavenRepo.kt | 8 ++++ .../gpm/di/components/InstallComponent.kt | 12 +++++ .../gpm/di/modules/NetworkModule.kt | 32 +++++++++++--- .../com/theapache64/gpm/utils/GsonUtils.kt | 10 ----- .../gpm/commands/subcommands/InstallTest.kt | 21 +++++++-- .../theapache64/gpm/data/repos/GpmRepoTest.kt | 44 +++++++++++++++++++ 14 files changed, 195 insertions(+), 39 deletions(-) delete mode 100644 src/main/kotlin/com/theapache64/gpm/core/registries/gpm/GpmApiInterface.kt delete mode 100644 src/main/kotlin/com/theapache64/gpm/core/registries/maven/MavenApiInterface.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/data/remote/GpmApiInterface.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/data/remote/MavenApiInterface.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/di/components/InstallComponent.kt delete mode 100644 src/main/kotlin/com/theapache64/gpm/utils/GsonUtils.kt create mode 100644 src/test/kotlin/com/theapache64/gpm/data/repos/GpmRepoTest.kt diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index fdc392f..f5a0c5d 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -16,5 +16,10 @@