From bd8641e98954517108ca2debb3b3e4b1ed787c9f Mon Sep 17 00:00:00 2001 From: theapache64 Date: Thu, 7 May 2020 08:23:55 +0530 Subject: [PATCH 01/17] =?UTF-8?q?=F0=9F=9A=9A=20rename=20html=20res=20to?= =?UTF-8?q?=20txt=20to=20avoid=20github=20language=20tracking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/theapache64/gpm/commands/subcommands/InstallTest.kt | 2 +- ....mavenrepository.com.html => okhttp.mavenrepository.com.txt} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/test/resources/{okhttp.mavenrepository.com.html => okhttp.mavenrepository.com.txt} (100%) diff --git a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt index 1b428f0..9f14da5 100644 --- a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt @@ -95,7 +95,7 @@ class InstallTest { ) whenever(fakeMavenApi.getArtifact(any(), any())).thenReturn( - File("src/test/resources/okhttp.mavenrepository.com.html").readText() + File("src/test/resources/okhttp.mavenrepository.com.txt").readText() ) whenever(fakeMavenApi.search(INVALID_REPO)).thenReturn("") diff --git a/src/test/resources/okhttp.mavenrepository.com.html b/src/test/resources/okhttp.mavenrepository.com.txt similarity index 100% rename from src/test/resources/okhttp.mavenrepository.com.html rename to src/test/resources/okhttp.mavenrepository.com.txt From f3d3f04f089e04b5dd639044cfe255660a07353e Mon Sep 17 00:00:00 2001 From: theapache64 Date: Thu, 7 May 2020 14:30:59 +0530 Subject: [PATCH 02/17] =?UTF-8?q?=E2=98=91=EF=B8=8F=20add=20base=20test=20?= =?UTF-8?q?for=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gpm/commands/base/BaseCommand.kt | 3 +- .../base/BaseInstallUninstallViewModel.kt | 6 +- .../gpm/commands/base/BaseViewModel.kt | 2 +- .../gpm/commands/subcommands/docs/Docs.kt | 37 ++++++++++ .../subcommands/docs/DocsComponent.kt | 15 ++++ .../subcommands/docs/DocsViewModel.kt | 43 ++++++++++++ .../commands/subcommands/install/Install.kt | 6 -- .../subcommands/install}/InstallComponent.kt | 3 +- .../subcommands/uninstall/Uninstall.kt | 1 - .../uninstall}/UninstallComponent.kt | 7 +- .../gpm/core/TransactionManager.kt | 4 +- .../theapache64/gpm/core/gm/GradleManager.kt | 1 - .../gpm/data/remote/gpm/models/GpmDep.kt | 2 +- .../gpm/di/modules/GradleModule.kt | 3 +- .../gpm/di/modules/NetworkModule.kt | 1 - .../gpm/di/modules/TransactionModule.kt | 3 +- .../com/theapache64/gpm/utils/InputUtils.kt | 1 - .../com/theapache64/gpm/utils/StringUtils.kt | 2 +- .../gpm/commands/subcommands/InstallTest.kt | 8 +-- .../gpm/commands/subcommands/docs/DocsTest.kt | 68 +++++++++++++++++++ .../subcommands/uninstall/UninstallTest.kt | 2 - .../gpm/core/gm/GradleDependencyTest.kt | 3 - .../theapache64/gpm/rules/MyDaggerMockRule.kt | 5 +- .../gpm/utils/GradleManagerTest.kt | 3 +- 24 files changed, 185 insertions(+), 44 deletions(-) create mode 100644 src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/Docs.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsComponent.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsViewModel.kt rename src/main/kotlin/com/theapache64/gpm/{di/components => commands/subcommands/install}/InstallComponent.kt (91%) rename src/main/kotlin/com/theapache64/gpm/{di/components => commands/subcommands/uninstall}/UninstallComponent.kt (87%) create mode 100644 src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt diff --git a/src/main/kotlin/com/theapache64/gpm/commands/base/BaseCommand.kt b/src/main/kotlin/com/theapache64/gpm/commands/base/BaseCommand.kt index 99b7b1e..77cf1a6 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/base/BaseCommand.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/base/BaseCommand.kt @@ -1,6 +1,5 @@ package com.theapache64.gpm.commands.base -import com.theapache64.gpm.utils.GpmConfig import com.theapache64.gpm.utils.InputUtils import kotlinx.coroutines.delay import java.util.concurrent.Callable @@ -20,7 +19,7 @@ abstract class BaseCommand( @Suppress("ConstantConditionIf") return if (isFromTest) { delay(1000) - 1 + 0 } else { InputUtils.getInt("Choose one", 1, items.size) - 1 } diff --git a/src/main/kotlin/com/theapache64/gpm/commands/base/BaseInstallUninstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/base/BaseInstallUninstallViewModel.kt index 0d434c9..46b6633 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/base/BaseInstallUninstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/base/BaseInstallUninstallViewModel.kt @@ -5,9 +5,9 @@ import com.theapache64.gpm.core.gm.GradleDep abstract class BaseInstallUninstallViewModel : BaseViewModel() { fun getDepTypes( - isSave : Boolean, - isSaveDev : Boolean, - isSaveDevAndroid:Boolean, + isSave: Boolean, + isSaveDev: Boolean, + isSaveDevAndroid: Boolean, defaultType: String? ): List = mutableListOf().apply { diff --git a/src/main/kotlin/com/theapache64/gpm/commands/base/BaseViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/base/BaseViewModel.kt index 17691ae..0bed580 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/base/BaseViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/base/BaseViewModel.kt @@ -1,5 +1,5 @@ package com.theapache64.gpm.commands.base abstract class BaseViewModel { - abstract suspend fun call(command: T) : Int + abstract suspend fun call(command: T): Int } \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/Docs.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/Docs.kt new file mode 100644 index 0000000..17f0f9c --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/Docs.kt @@ -0,0 +1,37 @@ +package com.theapache64.gpm.commands.subcommands.docs + +import com.theapache64.gpm.commands.base.BaseCommand +import com.theapache64.gpm.di.modules.TransactionModule +import kotlinx.coroutines.runBlocking +import picocli.CommandLine +import javax.inject.Inject + +@CommandLine.Command( + name = "docs", + aliases = ["d"], + description = ["To open library docs in default browser"] +) +class Docs( + isFromTest: Boolean +) : BaseCommand(isFromTest) { + @CommandLine.Parameters(index = "0", description = ["Dependency name"]) + lateinit var depName: String + + @Inject + lateinit var docsViewModel: DocsViewModel + + init { + DaggerDocsComponent.builder() + .transactionModule(TransactionModule(isFromTest)) + .build() + .inject(this) + } + + override fun call(): Int = runBlocking { + docsViewModel.call(this@Docs) + } + + fun onDocUrl(docsUrl: String) { + println("Docs -> $docsUrl") + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsComponent.kt new file mode 100644 index 0000000..e146780 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsComponent.kt @@ -0,0 +1,15 @@ +package com.theapache64.gpm.commands.subcommands.docs + +import com.theapache64.gpm.core.TransactionManager +import com.theapache64.gpm.di.modules.NetworkModule +import com.theapache64.gpm.di.modules.TransactionModule +import dagger.Component +import javax.inject.Singleton + +@Singleton +@Component(modules = [TransactionModule::class, NetworkModule::class]) +interface DocsComponent { + fun transactionManager(): TransactionManager + fun inject(docs: Docs) + +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsViewModel.kt new file mode 100644 index 0000000..81ddca3 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsViewModel.kt @@ -0,0 +1,43 @@ +package com.theapache64.gpm.commands.subcommands.docs + +import com.theapache64.gpm.commands.base.BaseViewModel +import com.theapache64.gpm.core.TransactionManager +import com.theapache64.gpm.data.repos.GpmRepo +import javax.inject.Inject + +class DocsViewModel @Inject constructor( + private val tm: TransactionManager, + private val gpmRepo: GpmRepo +) : BaseViewModel() { + + companion object { + const val RESULT_DOC_FOUND = 123 + const val RESULT_NOT_FOUND = 404 + } + + override suspend fun call(command: Docs): Int { + + val depName = command.depName.trim().toLowerCase() + val transaction = tm.getInstalled(null, depName) + + if (transaction.isEmpty()) { + // check if remote registry got info about the repo in question + val remoteDep = gpmRepo.getDep(depName) ?: return RESULT_NOT_FOUND + + command.onDocUrl(remoteDep.docs) + return RESULT_DOC_FOUND + + } else { + + val index = command.chooseIndex(transaction.map { + "${it.type} ${it.gpmDep.groupId}:${it.gpmDep.artifactId}" + }) + + val selDep = transaction[index] + command.onDocUrl(selDep.gpmDep.docs) + + return RESULT_DOC_FOUND + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt index a603a22..3ec3693 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt @@ -1,17 +1,11 @@ package com.theapache64.gpm.commands.subcommands.install import com.theapache64.gpm.commands.base.BaseCommand -import com.theapache64.gpm.di.components.DaggerInstallComponent import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule -import com.theapache64.gpm.utils.GpmConfig -import com.theapache64.gpm.utils.InputUtils -import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import picocli.CommandLine -import java.util.concurrent.Callable import javax.inject.Inject -import javax.inject.Singleton @CommandLine.Command( name = "install", diff --git a/src/main/kotlin/com/theapache64/gpm/di/components/InstallComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt similarity index 91% rename from src/main/kotlin/com/theapache64/gpm/di/components/InstallComponent.kt rename to src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt index 871040b..c3b4c20 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/components/InstallComponent.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt @@ -1,8 +1,7 @@ -package com.theapache64.gpm.di.components +package com.theapache64.gpm.commands.subcommands.install import com.squareup.moshi.Moshi import com.theapache64.gpm.commands.Gpm -import com.theapache64.gpm.commands.subcommands.install.Install import com.theapache64.gpm.core.TransactionManager import com.theapache64.gpm.data.remote.gpm.GpmApiInterface import com.theapache64.gpm.data.remote.maven.MavenApiInterface diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt index 827daaa..17adb6c 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt @@ -2,7 +2,6 @@ package com.theapache64.gpm.commands.subcommands.uninstall import com.theapache64.gpm.commands.base.BaseCommand import com.theapache64.gpm.core.gm.GradleDep -import com.theapache64.gpm.di.components.DaggerUninstallComponent import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule import kotlinx.coroutines.runBlocking diff --git a/src/main/kotlin/com/theapache64/gpm/di/components/UninstallComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallComponent.kt similarity index 87% rename from src/main/kotlin/com/theapache64/gpm/di/components/UninstallComponent.kt rename to src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallComponent.kt index 9e0b670..07545ef 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/components/UninstallComponent.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallComponent.kt @@ -1,15 +1,14 @@ -package com.theapache64.gpm.di.components +package com.theapache64.gpm.commands.subcommands.uninstall -import com.theapache64.gpm.commands.subcommands.uninstall.Uninstall import com.theapache64.gpm.core.TransactionManager import com.theapache64.gpm.core.gm.GradleManager +import com.theapache64.gpm.di.GpmJsonFile +import com.theapache64.gpm.di.GradleFile import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule import com.theapache64.gpm.di.modules.ViewModelModule import dagger.Component import java.io.File -import com.theapache64.gpm.di.GpmJsonFile -import com.theapache64.gpm.di.GradleFile import javax.inject.Singleton @Singleton diff --git a/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt b/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt index 652c613..8e23118 100644 --- a/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt +++ b/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt @@ -72,9 +72,9 @@ class TransactionManager @Inject constructor( gpmJsonFile.writeText(gpmFileDataJson) } - fun getInstalled(type: String, depName: String): List { + fun getInstalled(type: String?, depName: String): List { return getData()?.deps?.filter { - it.installedName == depName && it.type == type + it.installedName == depName && (type == null || it.type == type) } ?: listOf() } diff --git a/src/main/kotlin/com/theapache64/gpm/core/gm/GradleManager.kt b/src/main/kotlin/com/theapache64/gpm/core/gm/GradleManager.kt index 87c7e19..423592d 100644 --- a/src/main/kotlin/com/theapache64/gpm/core/gm/GradleManager.kt +++ b/src/main/kotlin/com/theapache64/gpm/core/gm/GradleManager.kt @@ -8,7 +8,6 @@ import com.theapache64.gpm.utils.StringUtils import com.theapache64.gpm.utils.insertAt import java.io.File import java.io.IOException -import java.lang.IllegalArgumentException /** * Currently supports 'implementation' and 'testImplementation' only. diff --git a/src/main/kotlin/com/theapache64/gpm/data/remote/gpm/models/GpmDep.kt b/src/main/kotlin/com/theapache64/gpm/data/remote/gpm/models/GpmDep.kt index 1e1b916..6872007 100644 --- a/src/main/kotlin/com/theapache64/gpm/data/remote/gpm/models/GpmDep.kt +++ b/src/main/kotlin/com/theapache64/gpm/data/remote/gpm/models/GpmDep.kt @@ -21,6 +21,6 @@ data class GpmDep( val description: String, @Transient var version: String? = null // OkHttp -){ +) { } \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/GradleModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/GradleModule.kt index 55477a0..7dc0f93 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/GradleModule.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/GradleModule.kt @@ -2,11 +2,10 @@ package com.theapache64.gpm.di.modules import com.theapache64.gpm.core.TransactionManager import com.theapache64.gpm.core.gm.GradleManager +import com.theapache64.gpm.di.GradleFile import dagger.Module import dagger.Provides import java.io.File -import com.theapache64.gpm.di.GpmJsonFile -import com.theapache64.gpm.di.GradleFile @Module(includes = [TransactionModule::class]) class GradleModule( diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt index e92eed4..e644355 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt @@ -1,7 +1,6 @@ package com.theapache64.gpm.di.modules import com.squareup.moshi.Moshi -import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import com.theapache64.gpm.data.remote.gpm.GpmApiInterface import com.theapache64.gpm.data.remote.maven.MavenApiInterface import dagger.Module diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/TransactionModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/TransactionModule.kt index a687fdd..9812049 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/TransactionModule.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/TransactionModule.kt @@ -2,11 +2,10 @@ package com.theapache64.gpm.di.modules import com.squareup.moshi.Moshi import com.theapache64.gpm.core.TransactionManager +import com.theapache64.gpm.di.GpmJsonFile import dagger.Module import dagger.Provides import java.io.File -import com.theapache64.gpm.di.GpmJsonFile -import com.theapache64.gpm.di.GradleFile @Module(includes = [MoshiModule::class]) class TransactionModule(private val isFromTest: Boolean) { diff --git a/src/main/kotlin/com/theapache64/gpm/utils/InputUtils.kt b/src/main/kotlin/com/theapache64/gpm/utils/InputUtils.kt index 1c05398..5059311 100644 --- a/src/main/kotlin/com/theapache64/gpm/utils/InputUtils.kt +++ b/src/main/kotlin/com/theapache64/gpm/utils/InputUtils.kt @@ -1,6 +1,5 @@ package com.theapache64.gpm.utils -import java.lang.NumberFormatException import java.util.* /** diff --git a/src/main/kotlin/com/theapache64/gpm/utils/StringUtils.kt b/src/main/kotlin/com/theapache64/gpm/utils/StringUtils.kt index 19a087f..b45acde 100644 --- a/src/main/kotlin/com/theapache64/gpm/utils/StringUtils.kt +++ b/src/main/kotlin/com/theapache64/gpm/utils/StringUtils.kt @@ -3,7 +3,7 @@ package com.theapache64.gpm.utils object StringUtils { - fun getClosingIndexOf(text: String, openingChar: Char, openingIndex: Int, closingChar : Char): Int { + fun getClosingIndexOf(text: String, openingChar: Char, openingIndex: Int, closingChar: Char): Int { var closePos: Int = openingIndex var counter = 1 while (counter > 0) { diff --git a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt index 9f14da5..84c9baf 100644 --- a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt @@ -3,21 +3,21 @@ package com.theapache64.gpm.commands.subcommands import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever +import com.theapache64.gpm.commands.subcommands.install.DaggerInstallComponent import com.theapache64.gpm.commands.subcommands.install.Install +import com.theapache64.gpm.commands.subcommands.install.InstallComponent import com.theapache64.gpm.commands.subcommands.install.InstallViewModel import com.theapache64.gpm.core.gm.GradleDep import com.theapache64.gpm.data.remote.gpm.GpmApiInterface import com.theapache64.gpm.data.remote.gpm.models.GpmDep import com.theapache64.gpm.data.remote.maven.MavenApiInterface -import com.theapache64.gpm.di.components.DaggerInstallComponent -import com.theapache64.gpm.di.components.InstallComponent + import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.NetworkModule import com.theapache64.gpm.di.modules.TransactionModule import com.theapache64.gpm.runBlockingUnitTest import com.winterbe.expekt.should import it.cosenonjaviste.daggermock.DaggerMock -import it.cosenonjaviste.daggermock.InjectFromComponent import org.junit.After import org.junit.Before import org.junit.Rule @@ -27,8 +27,6 @@ import retrofit2.HttpException import java.io.File import java.io.PrintWriter import java.io.StringWriter -import com.theapache64.gpm.di.GpmJsonFile -import com.theapache64.gpm.di.GradleFile class InstallTest { diff --git a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt new file mode 100644 index 0000000..dc0a969 --- /dev/null +++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt @@ -0,0 +1,68 @@ +package com.theapache64.gpm.commands.subcommands.docs + +import com.theapache64.gpm.core.TransactionManager +import com.theapache64.gpm.core.gm.GradleDep +import com.theapache64.gpm.data.remote.gpm.models.GpmDep +import com.theapache64.gpm.di.modules.TransactionModule +import com.winterbe.expekt.should +import it.cosenonjaviste.daggermock.DaggerMock +import it.cosenonjaviste.daggermock.InjectFromComponent +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import picocli.CommandLine + +class DocsTest { + + private lateinit var docsCmd: CommandLine + private val docs = Docs(true) + + @InjectFromComponent + private lateinit var tm: TransactionManager + + @get:Rule + val daggerRule = DaggerMock.rule(TransactionModule(true)) { + set { + tm = it.transactionManager() + } + } + + @Before + fun setUp() { + this.docsCmd = CommandLine(docs) + } + + @Test + fun `Opening docs for installed dependency`() { + // Adding fake transaction + tm.add( + "okhttp", + GradleDep.Type.IMP, + GpmDep( + "okhttp", + GradleDep.Type.IMP.key, + "https://square.github.io/okhttp/", + "jcenter", + "https://github.com/square/okhttp/", + "com.square.okhttp3", + "Material Colors", + "A networking library", + "1.0.0" + ) + ) + + val exitCode = docsCmd.execute("okhttp") + exitCode.should.equal(DocsViewModel.RESULT_DOC_FOUND) + + } + + @Test + fun `Opening docs for not installed dependency`() { + + } + + @Test + fun `Opening docs for dependency installed with similar name`() { + + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallTest.kt b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallTest.kt index 6ef5ce3..66c27e3 100644 --- a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallTest.kt @@ -3,8 +3,6 @@ package com.theapache64.gpm.commands.subcommands.uninstall import com.theapache64.gpm.core.gm.GradleDep import com.theapache64.gpm.core.gm.GradleManager import com.theapache64.gpm.data.remote.gpm.models.GpmDep -import com.theapache64.gpm.di.components.DaggerUninstallComponent -import com.theapache64.gpm.di.components.UninstallComponent import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule import com.winterbe.expekt.should diff --git a/src/test/kotlin/com/theapache64/gpm/core/gm/GradleDependencyTest.kt b/src/test/kotlin/com/theapache64/gpm/core/gm/GradleDependencyTest.kt index 0deb418..254d5d3 100644 --- a/src/test/kotlin/com/theapache64/gpm/core/gm/GradleDependencyTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/core/gm/GradleDependencyTest.kt @@ -1,8 +1,5 @@ package com.theapache64.gpm.core.gm -import com.winterbe.expekt.should -import org.junit.Test - class GradleDependencyTest { diff --git a/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt b/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt index c0b8bf5..6cab835 100644 --- a/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt +++ b/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt @@ -1,7 +1,8 @@ package com.theapache64.gpm.rules -import com.theapache64.gpm.di.components.DaggerInstallComponent -import com.theapache64.gpm.di.components.InstallComponent +import com.theapache64.gpm.commands.subcommands.install.DaggerInstallComponent +import com.theapache64.gpm.commands.subcommands.install.InstallComponent + import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.NetworkModule import com.theapache64.gpm.di.modules.TransactionModule diff --git a/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt b/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt index c647576..f3763cc 100644 --- a/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt @@ -1,11 +1,10 @@ package com.theapache64.gpm.utils +import com.theapache64.gpm.commands.subcommands.install.InstallComponent import com.theapache64.gpm.core.TransactionManager import com.theapache64.gpm.core.gm.GradleDep import com.theapache64.gpm.core.gm.GradleManager import com.theapache64.gpm.data.remote.gpm.models.GpmDep -import com.theapache64.gpm.di.GradleFile -import com.theapache64.gpm.di.components.InstallComponent import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule import com.winterbe.expekt.should From 2ed1f7f6289d1ef2e17b67570aa9cef40eb80d18 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 07:27:42 +0530 Subject: [PATCH 03/17] =?UTF-8?q?=F0=9F=8C=9F=20add=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subcommands/docs/DocsComponent.kt | 5 ++ .../gpm/commands/subcommands/docs/DocsTest.kt | 47 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsComponent.kt index e146780..ba92f41 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsComponent.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsComponent.kt @@ -1,15 +1,20 @@ package com.theapache64.gpm.commands.subcommands.docs import com.theapache64.gpm.core.TransactionManager +import com.theapache64.gpm.di.GpmJsonFile import com.theapache64.gpm.di.modules.NetworkModule import com.theapache64.gpm.di.modules.TransactionModule import dagger.Component +import java.io.File import javax.inject.Singleton @Singleton @Component(modules = [TransactionModule::class, NetworkModule::class]) interface DocsComponent { + fun transactionManager(): TransactionManager fun inject(docs: Docs) + @GpmJsonFile + fun gpmJsonFile(): File } \ No newline at end of file diff --git a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt index dc0a969..621d8bc 100644 --- a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt @@ -7,13 +7,16 @@ import com.theapache64.gpm.di.modules.TransactionModule import com.winterbe.expekt.should import it.cosenonjaviste.daggermock.DaggerMock import it.cosenonjaviste.daggermock.InjectFromComponent +import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test import picocli.CommandLine +import java.io.File class DocsTest { + private lateinit var gpmJsonFile: File private lateinit var docsCmd: CommandLine private val docs = Docs(true) @@ -24,6 +27,7 @@ class DocsTest { val daggerRule = DaggerMock.rule(TransactionModule(true)) { set { tm = it.transactionManager() + gpmJsonFile = it.gpmJsonFile() } } @@ -32,6 +36,11 @@ class DocsTest { this.docsCmd = CommandLine(docs) } + @After + fun tearDown() { + gpmJsonFile.delete() + } + @Test fun `Opening docs for installed dependency`() { // Adding fake transaction @@ -58,11 +67,47 @@ class DocsTest { @Test fun `Opening docs for not installed dependency`() { - + val exitCode = docsCmd.execute("not-installed-dep") + exitCode.should.equal(DocsViewModel.RESULT_NOT_FOUND) } @Test fun `Opening docs for dependency installed with similar name`() { + tm.add( + "okhttp", + GradleDep.Type.IMP, + GpmDep( + "okhttp", + GradleDep.Type.IMP.key, + "https://square.github.io/okhttp/", + "jcenter", + "https://github.com/square/okhttp/", + "com.square.okhttp3", + "Material Colors", + "A networking library", + "1.0.0" + ) + ) + tm.add( + "okhttp", + GradleDep.Type.IMP, + GpmDep( + "some-other-lib", + GradleDep.Type.IMP.key, + "https://square.github.io/okhttp/", + "jcenter", + "https://github.com/square/okhttp/", + "some-other-lib", + "some-other-lib", + "Some lib", + "1.0.0" + ) + ) + + val exitCode = docsCmd.execute("okhttp") + exitCode.should.equal(DocsViewModel.RESULT_DOC_FOUND) } + + } \ No newline at end of file From dd43780861b89d807e002bae85f6f5bcc8706210 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 07:33:59 +0530 Subject: [PATCH 04/17] =?UTF-8?q?=F0=9F=93=96=20update=20README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf8c149..a72beb4 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ | `uninstall` | To uninstall the dependency from `implementation` | ✔️ | Done | v1.0.0-alpha01 | | `uninstall dev` | To uninstall the dependency from `testImplementation` | ✔️ | Done | v1.0.0-alpha01 | | `uninstall dev-android` | To uninstall the dependency from `androidTestImplementation` | ✔️ | Done | v1.0.0-alpha01 | -| `docs` | To open the documentation in default browser | ⏳ | Implementing | v1.0.0-alpha01 | +| `docs` | To open the documentation in default browser | ✔️ | Done | v1.0.0-alpha01 | | `update` | To update the dependency version to latest | ❌ | Pending | - | | `list` | To list all the dependencies | ❌ | Pending | - | From fa5b1d69cb53c4636ceee29bb44e1d9ee938397a Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 08:47:25 +0530 Subject: [PATCH 05/17] =?UTF-8?q?=F0=9F=8C=9F=20add=20jar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/artifacts/gpm_main_jar.xml | 31 ++++++++++++++++ META-INF/MANIFEST.MF | 3 ++ src/main/kotlin/com/theapache64/gpm/Main.kt | 12 ++++++- .../com/theapache64/gpm/commands/Gpm.kt | 19 ---------- .../com/theapache64/gpm/commands/gpm/Gpm.kt | 36 +++++++++++++++++++ .../gpm/commands/gpm/GpmComponent.kt | 10 ++++++ .../gpm/commands/gpm/GpmViewModel.kt | 10 ++++++ .../gpm/commands/subcommands/docs/Docs.kt | 4 +-- .../commands/subcommands/install/Install.kt | 4 ++- .../subcommands/install/InstallComponent.kt | 2 +- .../subcommands/uninstall/Uninstall.kt | 2 +- .../gpm/di/modules/CommandModule.kt | 6 ++-- 12 files changed, 111 insertions(+), 28 deletions(-) create mode 100644 .idea/artifacts/gpm_main_jar.xml create mode 100644 META-INF/MANIFEST.MF delete mode 100644 src/main/kotlin/com/theapache64/gpm/commands/Gpm.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/commands/gpm/GpmComponent.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/commands/gpm/GpmViewModel.kt diff --git a/.idea/artifacts/gpm_main_jar.xml b/.idea/artifacts/gpm_main_jar.xml new file mode 100644 index 0000000..5599878 --- /dev/null +++ b/.idea/artifacts/gpm_main_jar.xml @@ -0,0 +1,31 @@ + + + $PROJECT_DIR$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3235440 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.theapache64.gpm.MainKt + diff --git a/src/main/kotlin/com/theapache64/gpm/Main.kt b/src/main/kotlin/com/theapache64/gpm/Main.kt index d62d182..ccea83e 100644 --- a/src/main/kotlin/com/theapache64/gpm/Main.kt +++ b/src/main/kotlin/com/theapache64/gpm/Main.kt @@ -1,5 +1,15 @@ package com.theapache64.gpm -fun main(args: Array) { +import com.theapache64.gpm.commands.gpm.Gpm +import picocli.CommandLine +import kotlin.system.exitProcess +fun main(args: Array) { + val cmd = CommandLine(Gpm(false)) + if (args.isEmpty()) { + cmd.usage(System.out) + } else { + val exitCode = cmd.execute(*args) + exitProcess(exitCode) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/Gpm.kt b/src/main/kotlin/com/theapache64/gpm/commands/Gpm.kt deleted file mode 100644 index 3a854b9..0000000 --- a/src/main/kotlin/com/theapache64/gpm/commands/Gpm.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.theapache64.gpm.commands - -import com.theapache64.gpm.commands.subcommands.install.Install -import com.theapache64.gpm.commands.subcommands.uninstall.Uninstall -import picocli.CommandLine -import javax.inject.Inject -import javax.inject.Singleton - -@CommandLine.Command( - name = "gpm", - version = ["v1.0.0-alpha01"], - subcommands = [ - Install::class, - Uninstall::class - ] -) -@Singleton -class Gpm @Inject constructor() { -} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt b/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt new file mode 100644 index 0000000..c8b7949 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt @@ -0,0 +1,36 @@ +package com.theapache64.gpm.commands.gpm + +import com.theapache64.gpm.commands.base.BaseCommand +import com.theapache64.gpm.commands.subcommands.docs.Docs +import com.theapache64.gpm.commands.subcommands.install.Install +import com.theapache64.gpm.commands.subcommands.uninstall.Uninstall +import kotlinx.coroutines.runBlocking +import picocli.CommandLine +import javax.inject.Inject +import javax.inject.Singleton +import javax.print.Doc + +@CommandLine.Command( + name = "gpm", + version = ["v1.0.0-alpha01"], + mixinStandardHelpOptions = true, + subcommands = [ + Install::class, + Uninstall::class, + Docs::class + ] +) +@Singleton +class Gpm @Inject constructor(isFromTest: Boolean) : BaseCommand(isFromTest) { + + init { + DaggerGpmComponent.create().inject(this) + } + + @Inject + lateinit var viewModel: GpmViewModel + + override fun call(): Int = runBlocking { + viewModel.call(this@Gpm) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/gpm/GpmComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/gpm/GpmComponent.kt new file mode 100644 index 0000000..e2e4808 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/commands/gpm/GpmComponent.kt @@ -0,0 +1,10 @@ +package com.theapache64.gpm.commands.gpm + +import dagger.Component +import javax.inject.Singleton + +@Singleton +@Component +interface GpmComponent { + fun inject(gpm: Gpm) +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/gpm/GpmViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/gpm/GpmViewModel.kt new file mode 100644 index 0000000..0438692 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/commands/gpm/GpmViewModel.kt @@ -0,0 +1,10 @@ +package com.theapache64.gpm.commands.gpm + +import com.theapache64.gpm.commands.base.BaseViewModel +import javax.inject.Inject + +class GpmViewModel @Inject constructor() : BaseViewModel() { + override suspend fun call(command: Gpm): Int { + return 0 + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/Docs.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/Docs.kt index 17f0f9c..93fdc79 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/Docs.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/Docs.kt @@ -9,10 +9,10 @@ import javax.inject.Inject @CommandLine.Command( name = "docs", aliases = ["d"], - description = ["To open library docs in default browser"] + description = ["To open library docs"] ) class Docs( - isFromTest: Boolean + isFromTest: Boolean = false ) : BaseCommand(isFromTest) { @CommandLine.Parameters(index = "0", description = ["Dependency name"]) lateinit var depName: String diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt index 3ec3693..a67e50e 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt @@ -1,6 +1,7 @@ package com.theapache64.gpm.commands.subcommands.install import com.theapache64.gpm.commands.base.BaseCommand +import com.theapache64.gpm.di.modules.CommandModule import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule import kotlinx.coroutines.runBlocking @@ -12,7 +13,7 @@ import javax.inject.Inject aliases = ["i"], description = ["To install the dependency"] ) -class Install(isFromTest: Boolean) : BaseCommand(isFromTest) { +class Install(isFromTest: Boolean = false) : BaseCommand(isFromTest) { @CommandLine.Option( names = ["-S", "--save"], @@ -41,6 +42,7 @@ class Install(isFromTest: Boolean) : BaseCommand(isFromTest) { init { DaggerInstallComponent .builder() + .commandModule(CommandModule(isFromTest = false)) .gradleModule(GradleModule(isFromTest = false)) .transactionModule(TransactionModule(false)) .build() diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt index c3b4c20..1fdad01 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt @@ -1,7 +1,7 @@ package com.theapache64.gpm.commands.subcommands.install import com.squareup.moshi.Moshi -import com.theapache64.gpm.commands.Gpm +import com.theapache64.gpm.commands.gpm.Gpm import com.theapache64.gpm.core.TransactionManager import com.theapache64.gpm.data.remote.gpm.GpmApiInterface import com.theapache64.gpm.data.remote.maven.MavenApiInterface diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt index 17adb6c..4282840 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt @@ -13,7 +13,7 @@ import javax.inject.Inject aliases = ["u"], description = ["To uninstall a dependency"] ) -class Uninstall(isFromTest: Boolean) : BaseCommand(isFromTest) { +class Uninstall(isFromTest: Boolean = false) : BaseCommand(isFromTest) { @CommandLine.Option( names = ["-S", "--save"], diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/CommandModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/CommandModule.kt index 8f7a2d8..80f0bc6 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/CommandModule.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/CommandModule.kt @@ -1,16 +1,16 @@ package com.theapache64.gpm.di.modules -import com.theapache64.gpm.commands.Gpm +import com.theapache64.gpm.commands.gpm.Gpm import dagger.Module import dagger.Provides import javax.inject.Singleton @Module -class CommandModule { +class CommandModule(private val isFromTest: Boolean) { @Singleton @Provides fun provideGpm(): Gpm { - return Gpm() + return Gpm(isFromTest) } } \ No newline at end of file From 762855c2bc32ada30162d259faa9517802f6847d Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 09:38:23 +0530 Subject: [PATCH 06/17] =?UTF-8?q?=E2=97=80=EF=B8=8F=20backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/artifacts/gpm_main_jar.xml | 31 ------------------- .idea/gpm.iml | 2 ++ .idea/misc.xml | 3 ++ .../theapache64/gpm/data/repos/MavenRepo.kt | 2 +- .../com/theapache64/gpm/utils/Logger.kt | 2 ++ .../com/theapache64/gpm/utils/TestMain.kt | 5 +++ .../gpm/data/repos/MavenRepoTest.kt | 9 ++++++ .../theapache64/gpm/rules/MyDaggerMockRule.kt | 2 ++ 8 files changed, 24 insertions(+), 32 deletions(-) delete mode 100644 .idea/artifacts/gpm_main_jar.xml create mode 100644 .idea/gpm.iml create mode 100644 src/main/kotlin/com/theapache64/gpm/utils/Logger.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt diff --git a/.idea/artifacts/gpm_main_jar.xml b/.idea/artifacts/gpm_main_jar.xml deleted file mode 100644 index 5599878..0000000 --- a/.idea/artifacts/gpm_main_jar.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - $PROJECT_DIR$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/gpm.iml b/.idea/gpm.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/.idea/gpm.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 2266f6b..32e560b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,6 +4,9 @@ + + diff --git a/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt b/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt index a5ace8f..c74fa27 100644 --- a/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt +++ b/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt @@ -19,7 +19,7 @@ class MavenRepo @Inject constructor( } private val ARTIFACT_VERSION_REGEX by lazy { - ".+?vbtn release\">(?.+?)<\\/a><\\/td>.+?)\">(?.+?)<\\/a>".toRegex() + ".+?vbtn release\">(?.+?)<\\/a>.+?.+?)\">(?.+?)<\\/a>".toRegex() } //Apr 29, 2020 diff --git a/src/main/kotlin/com/theapache64/gpm/utils/Logger.kt b/src/main/kotlin/com/theapache64/gpm/utils/Logger.kt new file mode 100644 index 0000000..d17d815 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/utils/Logger.kt @@ -0,0 +1,2 @@ +package com.theapache64.gpm.utils + diff --git a/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt b/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt new file mode 100644 index 0000000..af4270e --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt @@ -0,0 +1,5 @@ +package com.theapache64.gpm.utils + +fun main(args: Array) { + println("Hello World!") +} \ No newline at end of file diff --git a/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt b/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt index 0ff0d42..5834e2a 100644 --- a/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt @@ -46,9 +46,18 @@ class MavenRepoTest { info.repoUrl.should.equal("/repos/central") } + @Test + fun `Hey yo`() = runBlockingUnitTest { + val info = mavenRepo.getLatestVersion("me.tongfei", "progressbar") + info.should.not.`null` + info!!.version.should.not.empty + } + + @Test(expected = HttpException::class) fun `Getting invalid artifact information`() = runBlockingUnitTest { val info = mavenRepo.getLatestVersion("gfh", "jhj") info.should.`null` } + } \ No newline at end of file diff --git a/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt b/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt index 6cab835..f69701a 100644 --- a/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt +++ b/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt @@ -2,6 +2,7 @@ package com.theapache64.gpm.rules import com.theapache64.gpm.commands.subcommands.install.DaggerInstallComponent import com.theapache64.gpm.commands.subcommands.install.InstallComponent +import com.theapache64.gpm.di.modules.CommandModule import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.NetworkModule @@ -16,6 +17,7 @@ class MyDaggerMockRule : DaggerMockRule( init { customizeBuilder { it.transactionModule(TransactionModule(true)) + .commandModule(CommandModule(true)) } } } \ No newline at end of file From 2ace652c4597ee4066d858ac946cf1f51812d1e7 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 09:56:30 +0530 Subject: [PATCH 07/17] =?UTF-8?q?=E2=97=80=EF=B8=8F=20backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/artifacts/gpm_main_jar.xml | 31 +++++++++++++++++++ .../gpm/data/remote/gpm/GpmApiInterface.kt | 2 +- .../com/theapache64/gpm/data/repos/GpmRepo.kt | 20 +++++++----- .../gpm/commands/subcommands/InstallTest.kt | 10 ++++++ .../gpm/data/repos/MavenRepoTest.kt | 2 +- .../gpm/utils/GradleManagerTest.kt | 4 ++- 6 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 .idea/artifacts/gpm_main_jar.xml diff --git a/.idea/artifacts/gpm_main_jar.xml b/.idea/artifacts/gpm_main_jar.xml new file mode 100644 index 0000000..fa99715 --- /dev/null +++ b/.idea/artifacts/gpm_main_jar.xml @@ -0,0 +1,31 @@ + + + $PROJECT_DIR$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/data/remote/gpm/GpmApiInterface.kt b/src/main/kotlin/com/theapache64/gpm/data/remote/gpm/GpmApiInterface.kt index 1bb7996..fa518dc 100644 --- a/src/main/kotlin/com/theapache64/gpm/data/remote/gpm/GpmApiInterface.kt +++ b/src/main/kotlin/com/theapache64/gpm/data/remote/gpm/GpmApiInterface.kt @@ -9,6 +9,6 @@ interface GpmApiInterface { @GET("registry/{name}.json") suspend fun getDependency( @Path("name") repoName: String - ): GpmDep + ): GpmDep? } \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt b/src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt index d77c3ec..ffc22c6 100644 --- a/src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt +++ b/src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt @@ -15,14 +15,20 @@ class GpmRepo @Inject constructor( /** * To get dependency from GPM github registry */ - suspend fun getDep(depName: String): GpmDep? = - try { + suspend fun getDep(depName: String): GpmDep? { + return try { val dep = gpmApiInterface.getDependency(depName) - val versionInfo = mavenRepo.getLatestVersion(dep.groupId, dep.artifactId) - require(versionInfo != null) { "Couldn't get version info for '$depName'" } - dep.version = versionInfo.version - dep - } catch (e: HttpException) { + if (dep == null) { + null + } else { + val versionInfo = mavenRepo.getLatestVersion(dep.groupId, dep.artifactId) + require(versionInfo != null) { "Couldn't get version info for '$depName'" } + dep.version = versionInfo.version + dep + } + } catch (e: Exception) { null } + } + } \ No newline at end of file diff --git a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt index 84c9baf..8307351 100644 --- a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt @@ -11,6 +11,7 @@ import com.theapache64.gpm.core.gm.GradleDep import com.theapache64.gpm.data.remote.gpm.GpmApiInterface import com.theapache64.gpm.data.remote.gpm.models.GpmDep import com.theapache64.gpm.data.remote.maven.MavenApiInterface +import com.theapache64.gpm.di.modules.CommandModule import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.NetworkModule @@ -49,6 +50,7 @@ class InstallTest { customizeBuilder { it.gradleModule(GradleModule(isFromTest = true)) .transactionModule(TransactionModule(true)) + .commandModule(CommandModule(true)) } set { tempBuildGradle = it.gradleFile() @@ -110,6 +112,14 @@ class InstallTest { tempBuildGradle.readText().should.contain("implementation 'com.squareup.okhttp3:okhttp:") } + @Test + fun `Install default another`() { + val exitCode = installCmd.execute("progressbar") + exitCode.should.equal(InstallViewModel.RESULT_DEP_INSTALLED) + /* + tempBuildGradle.readText().should.contain("implementation 'com.squareup.okhttp3:okhttp:")*/ + } + @Test fun `Install non existing registry`() { val exitCode = installCmd.execute("retrofit") diff --git a/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt b/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt index 5834e2a..92e8877 100644 --- a/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt @@ -47,7 +47,7 @@ class MavenRepoTest { } @Test - fun `Hey yo`() = runBlockingUnitTest { + fun `Getting valid artifact information 2`() = runBlockingUnitTest { val info = mavenRepo.getLatestVersion("me.tongfei", "progressbar") info.should.not.`null` info!!.version.should.not.empty diff --git a/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt b/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt index f3763cc..4ba1bde 100644 --- a/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt @@ -5,6 +5,7 @@ import com.theapache64.gpm.core.TransactionManager import com.theapache64.gpm.core.gm.GradleDep import com.theapache64.gpm.core.gm.GradleManager import com.theapache64.gpm.data.remote.gpm.models.GpmDep +import com.theapache64.gpm.di.modules.CommandModule import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule import com.winterbe.expekt.should @@ -24,7 +25,8 @@ class GradleManagerTest { @get:Rule val daggerRule = DaggerMock.rule( GradleModule(true), - TransactionModule(true) + TransactionModule(true), + CommandModule(true) ) { set { gradleFile = it.gradleFile() From 36a43e4895633099785ee850fd78b578dc7461ea Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 11:39:00 +0530 Subject: [PATCH 08/17] =?UTF-8?q?=F0=9F=92=9A=20fix=20test=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subcommands/install/InstallViewModel.kt | 1 + .../theapache64/gpm/data/repos/MavenRepo.kt | 3 +- .../gpm/di/modules/NetworkModule.kt | 4 ++ .../gpm/commands/subcommands/InstallTest.kt | 46 +------------------ 4 files changed, 8 insertions(+), 46 deletions(-) diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt index 14e19c1..b052264 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt @@ -98,6 +98,7 @@ class InstallViewModel @Inject constructor( null, selMavenDep.groupId, selMavenDep.name, + selMavenDep.description, artifactInfo.version ) } else { diff --git a/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt b/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt index c74fa27..f0ef0d2 100644 --- a/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt +++ b/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt @@ -28,7 +28,8 @@ class MavenRepo @Inject constructor( suspend fun search(depName: String): List { - val htmlResp = mavenApiInterface.search(depName).removeNewLinesAndMultipleSpaces() + val searchHtml = mavenApiInterface.search(depName) + val htmlResp = searchHtml.removeNewLinesAndMultipleSpaces() val matches = SEARCH_RESULT_REGEX.findAll(htmlResp) val searchResults = mutableListOf() for (match in matches) { diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt index e644355..32f7784 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt @@ -5,6 +5,9 @@ import com.theapache64.gpm.data.remote.gpm.GpmApiInterface import com.theapache64.gpm.data.remote.maven.MavenApiInterface import dagger.Module import dagger.Provides +import okhttp3.Interceptor +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory import retrofit2.converter.scalars.ScalarsConverterFactory @@ -18,6 +21,7 @@ class NetworkModule { return Retrofit.Builder() } + @Singleton @Provides fun provideGpmApiInterface(retrofitBuilder: Retrofit.Builder, moshi: Moshi): GpmApiInterface { return retrofitBuilder diff --git a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt index 8307351..bea96f7 100644 --- a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt @@ -31,14 +31,8 @@ import java.io.StringWriter class InstallTest { - companion object { - private const val OKHTTP = "okhttp" - private const val RETROFIT = "retrofit" - private const val INVALID_REPO = "^%&^%some-invalid-repo&^%" - } private lateinit var installCmd: CommandLine - private val install = Install(true) @@ -60,47 +54,9 @@ class InstallTest { } - private var fakeGpmApi: GpmApiInterface = mock() - private var fakeMavenApi: MavenApiInterface = mock() - @Before fun setUp() = runBlockingUnitTest { - whenever(fakeGpmApi.getDependency(OKHTTP)).thenReturn( - GpmDep( - "okhttp", - GradleDep.Type.IMP.key, - "https://square.github.io/okhttp/", - "jcenter", - "https://github.com/square/okhttp/", - "com.squareup.okhttp3", - "OkHttp", - "Square’s meticulous HTTP client for Java and Kotlin.\n", - "4.6.0" - ) - ) - - whenever(fakeGpmApi.getDependency(RETROFIT)).thenReturn( - GpmDep( - "retrofit", - GradleDep.Type.IMP.key, - "https://square.github.io/retrofit/", - "jcenter", - "https://github.com/square/retrofit/", - "com.squareup.retrofit2", - "Retrofit", - "Square’s meticulous type-safe HTTP client for Java and Kotlin.\n", - "2.8.1" - ) - ) - - whenever(fakeMavenApi.getArtifact(any(), any())).thenReturn( - File("src/test/resources/okhttp.mavenrepository.com.txt").readText() - ) - - whenever(fakeMavenApi.search(INVALID_REPO)).thenReturn("") - whenever(fakeGpmApi.getDependency(INVALID_REPO)).thenThrow(HttpException::class.java) - this.installCmd = CommandLine(install) installCmd.out = PrintWriter(StringWriter()) } @@ -150,7 +106,7 @@ class InstallTest { @Test fun `Install not existing library`() { - val exitCode = installCmd.execute(INVALID_REPO) + val exitCode = installCmd.execute("gdfhdfghdfghfdg") exitCode.should.equal(InstallViewModel.RESULT_REPO_NOT_FOUND) } From 2cc2d86360fe3b43e827a9093746a1ea83197b07 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 11:41:46 +0530 Subject: [PATCH 09/17] =?UTF-8?q?=F0=9F=92=9A=20fix=20test=20cases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/artifacts/gpm_main_jar.xml | 31 ------------------- META-INF/MANIFEST.MF | 3 -- .../gpm/di/modules/NetworkModule.kt | 3 -- 3 files changed, 37 deletions(-) delete mode 100644 .idea/artifacts/gpm_main_jar.xml delete mode 100644 META-INF/MANIFEST.MF diff --git a/.idea/artifacts/gpm_main_jar.xml b/.idea/artifacts/gpm_main_jar.xml deleted file mode 100644 index fa99715..0000000 --- a/.idea/artifacts/gpm_main_jar.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - $PROJECT_DIR$ - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF deleted file mode 100644 index 3235440..0000000 --- a/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: com.theapache64.gpm.MainKt - diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt index 32f7784..9ec647a 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/NetworkModule.kt @@ -5,9 +5,6 @@ import com.theapache64.gpm.data.remote.gpm.GpmApiInterface import com.theapache64.gpm.data.remote.maven.MavenApiInterface import dagger.Module import dagger.Provides -import okhttp3.Interceptor -import okhttp3.OkHttpClient -import okhttp3.logging.HttpLoggingInterceptor import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory import retrofit2.converter.scalars.ScalarsConverterFactory From 47dcfa943a2e986ea69ee3166062c24e17065b1f Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 12:00:48 +0530 Subject: [PATCH 10/17] =?UTF-8?q?=F0=9F=8C=9F=20add=20terminal=20progessba?= =?UTF-8?q?r=20deps=20using=20gpm=20itself=20;)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/artifacts/gpm_main_jar.xml | 31 ++++++++++++++++++++++++++++ META-INF/MANIFEST.MF | 3 +++ build.gradle | 3 +++ gpm.json | 18 ++++++++++++++++ src/main/kotlin/META-INF/MANIFEST.MF | 3 +++ 5 files changed, 58 insertions(+) create mode 100644 .idea/artifacts/gpm_main_jar.xml create mode 100644 META-INF/MANIFEST.MF create mode 100644 gpm.json create mode 100644 src/main/kotlin/META-INF/MANIFEST.MF diff --git a/.idea/artifacts/gpm_main_jar.xml b/.idea/artifacts/gpm_main_jar.xml new file mode 100644 index 0000000..cf6e9b8 --- /dev/null +++ b/.idea/artifacts/gpm_main_jar.xml @@ -0,0 +1,31 @@ + + + $PROJECT_DIR$ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3235440 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.theapache64.gpm.MainKt + diff --git a/build.gradle b/build.gradle index a71a398..18d00a2 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,9 @@ dependencies { // DaggerMock testImplementation 'com.github.fabioCollini.daggermock:daggermock:0.8.5' testImplementation 'com.github.fabioCollini.daggermock:daggermock-kotlin:0.8.5' + + // ProgressBar:A terminal-based progress bar for JVM + implementation 'me.tongfei:progressbar:0.8.1' } compileKotlin { diff --git a/gpm.json b/gpm.json new file mode 100644 index 0000000..334e1c8 --- /dev/null +++ b/gpm.json @@ -0,0 +1,18 @@ +{ + "added": [ + { + "id": 1, + "type": "implementation", + "installed_name": "progressbar", + "gpm_dep": { + "artifact_id": "progressbar", + "default_type": "implementation", + "docs": "https://mvnrepository.com/artifact/me.tongfei/progressbar", + "get_from": "Central", + "group_id": "me.tongfei", + "name": "ProgressBar", + "description": "A terminal-based progress bar for JVM" + } + } + ] +} \ No newline at end of file diff --git a/src/main/kotlin/META-INF/MANIFEST.MF b/src/main/kotlin/META-INF/MANIFEST.MF new file mode 100644 index 0000000..3235440 --- /dev/null +++ b/src/main/kotlin/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.theapache64.gpm.MainKt + From 099f2940e72bf640ee28dfe7bd0cb07a1d20fe5e Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 12:41:35 +0530 Subject: [PATCH 11/17] =?UTF-8?q?=E2=97=80=EF=B8=8F=20backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 +- gpm.json | 47 ++++++++++++------- src/main/kotlin/META-INF/MANIFEST.MF | 3 -- .../com/theapache64/gpm/commands/gpm/Gpm.kt | 1 - .../subcommands/docs/DocsViewModel.kt | 10 ++-- .../subcommands/install/InstallComponent.kt | 6 ++- .../subcommands/install/InstallViewModel.kt | 7 ++- .../uninstall/UninstallComponent.kt | 3 +- .../com/theapache64/gpm/data/repos/GpmRepo.kt | 1 - .../gpm/di/modules/ViewModelModule.kt | 25 ---------- .../gpm/utils/ProgressBarExtension.kt | 8 ++++ .../com/theapache64/gpm/utils/TestMain.kt | 17 ++++++- .../gpm/commands/subcommands/InstallTest.kt | 9 ---- 13 files changed, 75 insertions(+), 66 deletions(-) delete mode 100644 src/main/kotlin/META-INF/MANIFEST.MF delete mode 100644 src/main/kotlin/com/theapache64/gpm/di/modules/ViewModelModule.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/utils/ProgressBarExtension.kt diff --git a/build.gradle b/build.gradle index 18d00a2..466f4b5 100644 --- a/build.gradle +++ b/build.gradle @@ -60,8 +60,8 @@ dependencies { testImplementation 'com.github.fabioCollini.daggermock:daggermock:0.8.5' testImplementation 'com.github.fabioCollini.daggermock:daggermock-kotlin:0.8.5' - // ProgressBar:A terminal-based progress bar for JVM - implementation 'me.tongfei:progressbar:0.8.1' + // ProgressBar:A terminal-based progress bar for JVM + implementation 'me.tongfei:progressbar:0.8.1' } compileKotlin { diff --git a/gpm.json b/gpm.json index 334e1c8..3de286c 100644 --- a/gpm.json +++ b/gpm.json @@ -1,18 +1,33 @@ { - "added": [ - { - "id": 1, - "type": "implementation", - "installed_name": "progressbar", - "gpm_dep": { - "artifact_id": "progressbar", - "default_type": "implementation", - "docs": "https://mvnrepository.com/artifact/me.tongfei/progressbar", - "get_from": "Central", - "group_id": "me.tongfei", - "name": "ProgressBar", - "description": "A terminal-based progress bar for JVM" - } - } - ] + "added": [ + { + "id": 1, + "type": "implementation", + "installed_name": "progressbar", + "gpm_dep": { + "artifact_id": "progressbar", + "default_type": "implementation", + "docs": "https://mvnrepository.com/artifact/me.tongfei/progressbar", + "get_from": "Central", + "group_id": "me.tongfei", + "name": "ProgressBar", + "description": "A terminal-based progress bar for JVM" + } + }, + { + "id": 2, + "type": "implementation", + "installed_name": "okhttp", + "gpm_dep": { + "artifact_id": "okhttp", + "default_type": "implementation", + "docs": "https://square.github.io/okhttp/", + "get_from": "maven", + "github": "square/okhttp", + "group_id": "com.squareup.okhttp3", + "name": "OkHttp", + "description": "For networking" + } + } + ] } \ No newline at end of file diff --git a/src/main/kotlin/META-INF/MANIFEST.MF b/src/main/kotlin/META-INF/MANIFEST.MF deleted file mode 100644 index 3235440..0000000 --- a/src/main/kotlin/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: com.theapache64.gpm.MainKt - diff --git a/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt b/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt index c8b7949..c0e7250 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt @@ -8,7 +8,6 @@ import kotlinx.coroutines.runBlocking import picocli.CommandLine import javax.inject.Inject import javax.inject.Singleton -import javax.print.Doc @CommandLine.Command( name = "gpm", diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsViewModel.kt index 81ddca3..3929936 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsViewModel.kt @@ -29,9 +29,13 @@ class DocsViewModel @Inject constructor( } else { - val index = command.chooseIndex(transaction.map { - "${it.type} ${it.gpmDep.groupId}:${it.gpmDep.artifactId}" - }) + val index = if (transaction.size > 1) { + command.chooseIndex(transaction.map { + "${it.type} ${it.gpmDep.groupId}:${it.gpmDep.artifactId}" + }) + } else { + 0 + } val selDep = transaction[index] command.onDocUrl(selDep.gpmDep.docs) diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt index 1fdad01..5748216 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt @@ -8,7 +8,10 @@ import com.theapache64.gpm.data.remote.maven.MavenApiInterface import com.theapache64.gpm.data.repos.MavenRepo import com.theapache64.gpm.di.GpmJsonFile import com.theapache64.gpm.di.GradleFile -import com.theapache64.gpm.di.modules.* +import com.theapache64.gpm.di.modules.CommandModule +import com.theapache64.gpm.di.modules.GradleModule +import com.theapache64.gpm.di.modules.MoshiModule +import com.theapache64.gpm.di.modules.NetworkModule import dagger.Component import java.io.File import javax.inject.Singleton @@ -16,7 +19,6 @@ import javax.inject.Singleton @Singleton @Component( modules = [ - ViewModelModule::class, NetworkModule::class, MoshiModule::class, GradleModule::class, diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt index b052264..fcdb276 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt @@ -12,7 +12,8 @@ import javax.inject.Inject class InstallViewModel @Inject constructor( private val gpmRepo: GpmRepo, private val mavenRepo: MavenRepo, - private val gradleManager: GradleManager + private val gradleManager: GradleManager/*, + private val progressBar: ProgressBar*/ ) : BaseInstallUninstallViewModel() { companion object { @@ -25,6 +26,7 @@ class InstallViewModel @Inject constructor( val depName = command.depName.trim().toLowerCase() // first get from + //progressBar.set(20, "Searching '$depName'") val gpmDep = getDep(command, depName) ?: return RESULT_REPO_NOT_FOUND @@ -35,11 +37,13 @@ class InstallViewModel @Inject constructor( command.isSaveDevAndroid, gpmDep.defaultType ) + require(depTypes.isNotEmpty()) { "Dependency type can't be empty" } // Getting latest version // Adding each dependency + //progressBar.set(50, "Installing '$depName'") for (depType in depTypes) { gradleManager.addDep( depName, @@ -48,6 +52,7 @@ class InstallViewModel @Inject constructor( ) } + //progressBar.set(100, "Done") return RESULT_DEP_INSTALLED } diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallComponent.kt index 07545ef..c1a132a 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallComponent.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallComponent.kt @@ -6,14 +6,13 @@ import com.theapache64.gpm.di.GpmJsonFile import com.theapache64.gpm.di.GradleFile import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule -import com.theapache64.gpm.di.modules.ViewModelModule import dagger.Component import java.io.File import javax.inject.Singleton @Singleton @Component( - modules = [ViewModelModule::class, GradleModule::class, TransactionModule::class] + modules = [GradleModule::class, TransactionModule::class] ) interface UninstallComponent { fun inject(uninstall: Uninstall) diff --git a/src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt b/src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt index ffc22c6..1bab2a0 100644 --- a/src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt +++ b/src/main/kotlin/com/theapache64/gpm/data/repos/GpmRepo.kt @@ -2,7 +2,6 @@ package com.theapache64.gpm.data.repos import com.theapache64.gpm.data.remote.gpm.GpmApiInterface import com.theapache64.gpm.data.remote.gpm.models.GpmDep -import retrofit2.HttpException import javax.inject.Inject import javax.inject.Singleton diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/ViewModelModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/ViewModelModule.kt deleted file mode 100644 index 619ae95..0000000 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/ViewModelModule.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.theapache64.gpm.di.modules - -import com.theapache64.gpm.commands.subcommands.install.InstallViewModel -import com.theapache64.gpm.core.gm.GradleManager -import com.theapache64.gpm.data.repos.GpmRepo -import com.theapache64.gpm.data.repos.MavenRepo -import dagger.Module -import dagger.Provides - -@Module(includes = [GradleModule::class]) -class ViewModelModule { - - @Provides - fun provideInstallViewModel( - gpmRepo: GpmRepo, - mavenRepo: MavenRepo, - gradleManager: GradleManager - ): InstallViewModel { - return InstallViewModel( - gpmRepo, - mavenRepo, - gradleManager - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/utils/ProgressBarExtension.kt b/src/main/kotlin/com/theapache64/gpm/utils/ProgressBarExtension.kt new file mode 100644 index 0000000..6929c0b --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/utils/ProgressBarExtension.kt @@ -0,0 +1,8 @@ +package com.theapache64.gpm.utils + +import me.tongfei.progressbar.ProgressBar + +fun ProgressBar.set(stepTo: Long, msg: String) { + stepTo(stepTo) + extraMessage = msg +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt b/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt index af4270e..a78fa9c 100644 --- a/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt +++ b/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt @@ -1,5 +1,20 @@ package com.theapache64.gpm.utils +import me.tongfei.progressbar.ProgressBarBuilder +import me.tongfei.progressbar.ProgressBarStyle + fun main(args: Array) { - println("Hello World!") + val pb = ProgressBarBuilder() + .setInitialMax(100) + .setStyle(ProgressBarStyle.COLORFUL_UNICODE_BLOCK) + .setTaskName("Print task") + .setUpdateIntervalMillis(100) + .build() + pb.use { + for (name in (0..100)) { + it.extraMessage = "Printing $name" + Thread.sleep(50) + it.step() + } + } } \ No newline at end of file diff --git a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt index bea96f7..134f24e 100644 --- a/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt +++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/InstallTest.kt @@ -1,18 +1,10 @@ package com.theapache64.gpm.commands.subcommands -import com.nhaarman.mockitokotlin2.any -import com.nhaarman.mockitokotlin2.mock -import com.nhaarman.mockitokotlin2.whenever import com.theapache64.gpm.commands.subcommands.install.DaggerInstallComponent import com.theapache64.gpm.commands.subcommands.install.Install import com.theapache64.gpm.commands.subcommands.install.InstallComponent import com.theapache64.gpm.commands.subcommands.install.InstallViewModel -import com.theapache64.gpm.core.gm.GradleDep -import com.theapache64.gpm.data.remote.gpm.GpmApiInterface -import com.theapache64.gpm.data.remote.gpm.models.GpmDep -import com.theapache64.gpm.data.remote.maven.MavenApiInterface import com.theapache64.gpm.di.modules.CommandModule - import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.NetworkModule import com.theapache64.gpm.di.modules.TransactionModule @@ -24,7 +16,6 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import picocli.CommandLine -import retrofit2.HttpException import java.io.File import java.io.PrintWriter import java.io.StringWriter From 68bb5d3a7ddbddeeaba377d894ed0d8aefa0f046 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 12:46:59 +0530 Subject: [PATCH 12/17] =?UTF-8?q?=F0=9F=8C=9F=20add=20progressbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../subcommands/install/InstallComponent.kt | 9 ++- .../subcommands/install/InstallViewModel.kt | 59 +++++++++++-------- .../com/theapache64/gpm/di/Qualifiers.kt | 7 ++- .../gpm/di/modules/ProgressBarModule.kt | 16 +++++ 4 files changed, 59 insertions(+), 32 deletions(-) create mode 100644 src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt index 5748216..89cea43 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt @@ -8,10 +8,8 @@ import com.theapache64.gpm.data.remote.maven.MavenApiInterface import com.theapache64.gpm.data.repos.MavenRepo import com.theapache64.gpm.di.GpmJsonFile import com.theapache64.gpm.di.GradleFile -import com.theapache64.gpm.di.modules.CommandModule -import com.theapache64.gpm.di.modules.GradleModule -import com.theapache64.gpm.di.modules.MoshiModule -import com.theapache64.gpm.di.modules.NetworkModule +import com.theapache64.gpm.di.InstallProgress +import com.theapache64.gpm.di.modules.* import dagger.Component import java.io.File import javax.inject.Singleton @@ -22,7 +20,8 @@ import javax.inject.Singleton NetworkModule::class, MoshiModule::class, GradleModule::class, - CommandModule::class + CommandModule::class, + ProgressBarModule::class ] ) interface InstallComponent { diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt index fcdb276..c5b5c66 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt @@ -6,14 +6,18 @@ import com.theapache64.gpm.core.gm.GradleManager import com.theapache64.gpm.data.remote.gpm.models.GpmDep import com.theapache64.gpm.data.repos.GpmRepo import com.theapache64.gpm.data.repos.MavenRepo +import com.theapache64.gpm.di.InstallProgress +import com.theapache64.gpm.utils.set +import me.tongfei.progressbar.ProgressBar import picocli.CommandLine import javax.inject.Inject class InstallViewModel @Inject constructor( private val gpmRepo: GpmRepo, private val mavenRepo: MavenRepo, - private val gradleManager: GradleManager/*, - private val progressBar: ProgressBar*/ + private val gradleManager: GradleManager, + @InstallProgress + private val progressBar: ProgressBar ) : BaseInstallUninstallViewModel() { companion object { @@ -23,37 +27,40 @@ class InstallViewModel @Inject constructor( override suspend fun call(command: Install): Int { - val depName = command.depName.trim().toLowerCase() + return progressBar.use { - // first get from - //progressBar.set(20, "Searching '$depName'") - val gpmDep = getDep(command, depName) - ?: return RESULT_REPO_NOT_FOUND + val depName = command.depName.trim().toLowerCase() + // first get from + progressBar.set(20, "Searching '$depName'") + val gpmDep = getDep(command, depName) + ?: return RESULT_REPO_NOT_FOUND - val depTypes = getDepTypes( - command.isSave, - command.isSaveDev, - command.isSaveDevAndroid, - gpmDep.defaultType - ) - require(depTypes.isNotEmpty()) { "Dependency type can't be empty" } + val depTypes = getDepTypes( + command.isSave, + command.isSaveDev, + command.isSaveDevAndroid, + gpmDep.defaultType + ) - // Getting latest version + require(depTypes.isNotEmpty()) { "Dependency type can't be empty" } - // Adding each dependency - //progressBar.set(50, "Installing '$depName'") - for (depType in depTypes) { - gradleManager.addDep( - depName, - depType, - gpmDep - ) - } + // Getting latest version - //progressBar.set(100, "Done") - return RESULT_DEP_INSTALLED + // Adding each dependency + progressBar.set(50, "Installing '$depName'") + for (depType in depTypes) { + gradleManager.addDep( + depName, + depType, + gpmDep + ) + } + + progressBar.set(100, "Done") + RESULT_DEP_INSTALLED + } } private suspend fun getDep(install: Install, depName: String): GpmDep? { diff --git a/src/main/kotlin/com/theapache64/gpm/di/Qualifiers.kt b/src/main/kotlin/com/theapache64/gpm/di/Qualifiers.kt index 89c81b8..5f32695 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/Qualifiers.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/Qualifiers.kt @@ -10,4 +10,9 @@ annotation class GradleFile @Qualifier @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) -annotation class GpmJsonFile \ No newline at end of file +annotation class GpmJsonFile + +@Qualifier +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +annotation class InstallProgress \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt new file mode 100644 index 0000000..6f10c15 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt @@ -0,0 +1,16 @@ +package com.theapache64.gpm.di.modules + +import com.theapache64.gpm.di.InstallProgress +import dagger.Module +import dagger.Provides +import me.tongfei.progressbar.ProgressBar + +@Module +class ProgressBarModule { + + @InstallProgress + @Provides + fun provideInstallProgressBar(): ProgressBar { + return ProgressBar("Install", 100) + } +} \ No newline at end of file From 7dea38406bba0016131c7d979ffb8472ab8eccc6 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 12:57:08 +0530 Subject: [PATCH 13/17] =?UTF-8?q?=F0=9F=8C=9F=20add=20install=20progress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/artifacts/gpm_main_jar.xml | 31 +++++++++++-------- build.gradle | 1 + .../subcommands/install/InstallViewModel.kt | 4 ++- .../gpm/di/modules/ProgressBarModule.kt | 8 +++-- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.idea/artifacts/gpm_main_jar.xml b/.idea/artifacts/gpm_main_jar.xml index cf6e9b8..1aaaec7 100644 --- a/.idea/artifacts/gpm_main_jar.xml +++ b/.idea/artifacts/gpm_main_jar.xml @@ -6,26 +6,31 @@ - - - + + + + + + - - + + + + + - - - + + + + + + - - - - - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 466f4b5..46bf6f1 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,7 @@ dependencies { // ProgressBar:A terminal-based progress bar for JVM implementation 'me.tongfei:progressbar:0.8.1' + } compileKotlin { diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt index c5b5c66..2663acf 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt @@ -9,6 +9,7 @@ import com.theapache64.gpm.data.repos.MavenRepo import com.theapache64.gpm.di.InstallProgress import com.theapache64.gpm.utils.set import me.tongfei.progressbar.ProgressBar +import me.tongfei.progressbar.ProgressBarBuilder import picocli.CommandLine import javax.inject.Inject @@ -17,7 +18,7 @@ class InstallViewModel @Inject constructor( private val mavenRepo: MavenRepo, private val gradleManager: GradleManager, @InstallProgress - private val progressBar: ProgressBar + private val progressBarBuilder: ProgressBarBuilder ) : BaseInstallUninstallViewModel() { companion object { @@ -27,6 +28,7 @@ class InstallViewModel @Inject constructor( override suspend fun call(command: Install): Int { + val progressBar = progressBarBuilder.build() return progressBar.use { val depName = command.depName.trim().toLowerCase() diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt index 6f10c15..cfe9d85 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt @@ -4,13 +4,17 @@ import com.theapache64.gpm.di.InstallProgress import dagger.Module import dagger.Provides import me.tongfei.progressbar.ProgressBar +import me.tongfei.progressbar.ProgressBarBuilder @Module class ProgressBarModule { @InstallProgress @Provides - fun provideInstallProgressBar(): ProgressBar { - return ProgressBar("Install", 100) + fun provideInstallProgressBar(): ProgressBarBuilder { + return ProgressBarBuilder() + .setTaskName("🚛 Install") + .setInitialMax(100) + .setUpdateIntervalMillis(200) } } \ No newline at end of file From 75199e3c91584a36581316a4693262f4d274994f Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 16:26:50 +0530 Subject: [PATCH 14/17] =?UTF-8?q?=F0=9F=8C=9F=20add=20custom=20progressbar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/artifacts/gpm_main_jar.xml | 38 +++---- build.gradle | 4 - gpm.json | 33 ------ .../subcommands/install/InstallComponent.kt | 4 +- .../subcommands/install/InstallViewModel.kt | 102 +++++++++--------- .../subcommands/uninstall/Uninstall.kt | 4 +- .../uninstall/UninstallViewModel.kt | 1 - .../gpm/core/TransactionManager.kt | 4 +- .../data/remote/maven/models/SearchResult.kt | 2 +- .../theapache64/gpm/data/repos/MavenRepo.kt | 12 ++- .../com/theapache64/gpm/di/Qualifiers.kt | 7 +- .../gpm/di/modules/ProgressBarModule.kt | 20 ---- .../gpm/utils/ProgressBarExtension.kt | 8 -- .../theapache64/gpm/utils/ProgressPrinter.kt | 9 ++ .../com/theapache64/gpm/utils/TestMain.kt | 17 +-- 15 files changed, 97 insertions(+), 168 deletions(-) delete mode 100644 gpm.json delete mode 100644 src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt delete mode 100644 src/main/kotlin/com/theapache64/gpm/utils/ProgressBarExtension.kt create mode 100644 src/main/kotlin/com/theapache64/gpm/utils/ProgressPrinter.kt diff --git a/.idea/artifacts/gpm_main_jar.xml b/.idea/artifacts/gpm_main_jar.xml index 1aaaec7..383e02e 100644 --- a/.idea/artifacts/gpm_main_jar.xml +++ b/.idea/artifacts/gpm_main_jar.xml @@ -6,31 +6,31 @@ - - - + + - - - - - - - + - - + + + + + + + + - - + + + + - - + - - - + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 46bf6f1..a71a398 100644 --- a/build.gradle +++ b/build.gradle @@ -59,10 +59,6 @@ dependencies { // DaggerMock testImplementation 'com.github.fabioCollini.daggermock:daggermock:0.8.5' testImplementation 'com.github.fabioCollini.daggermock:daggermock-kotlin:0.8.5' - - // ProgressBar:A terminal-based progress bar for JVM - implementation 'me.tongfei:progressbar:0.8.1' - } compileKotlin { diff --git a/gpm.json b/gpm.json deleted file mode 100644 index 3de286c..0000000 --- a/gpm.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "added": [ - { - "id": 1, - "type": "implementation", - "installed_name": "progressbar", - "gpm_dep": { - "artifact_id": "progressbar", - "default_type": "implementation", - "docs": "https://mvnrepository.com/artifact/me.tongfei/progressbar", - "get_from": "Central", - "group_id": "me.tongfei", - "name": "ProgressBar", - "description": "A terminal-based progress bar for JVM" - } - }, - { - "id": 2, - "type": "implementation", - "installed_name": "okhttp", - "gpm_dep": { - "artifact_id": "okhttp", - "default_type": "implementation", - "docs": "https://square.github.io/okhttp/", - "get_from": "maven", - "github": "square/okhttp", - "group_id": "com.squareup.okhttp3", - "name": "OkHttp", - "description": "For networking" - } - } - ] -} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt index 89cea43..0cb22cc 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallComponent.kt @@ -8,7 +8,6 @@ import com.theapache64.gpm.data.remote.maven.MavenApiInterface import com.theapache64.gpm.data.repos.MavenRepo import com.theapache64.gpm.di.GpmJsonFile import com.theapache64.gpm.di.GradleFile -import com.theapache64.gpm.di.InstallProgress import com.theapache64.gpm.di.modules.* import dagger.Component import java.io.File @@ -20,8 +19,7 @@ import javax.inject.Singleton NetworkModule::class, MoshiModule::class, GradleModule::class, - CommandModule::class, - ProgressBarModule::class + CommandModule::class ] ) interface InstallComponent { diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt index 2663acf..1b1d5bc 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt @@ -6,21 +6,16 @@ import com.theapache64.gpm.core.gm.GradleManager import com.theapache64.gpm.data.remote.gpm.models.GpmDep import com.theapache64.gpm.data.repos.GpmRepo import com.theapache64.gpm.data.repos.MavenRepo -import com.theapache64.gpm.di.InstallProgress -import com.theapache64.gpm.utils.set -import me.tongfei.progressbar.ProgressBar -import me.tongfei.progressbar.ProgressBarBuilder import picocli.CommandLine import javax.inject.Inject class InstallViewModel @Inject constructor( private val gpmRepo: GpmRepo, private val mavenRepo: MavenRepo, - private val gradleManager: GradleManager, - @InstallProgress - private val progressBarBuilder: ProgressBarBuilder + private val gradleManager: GradleManager ) : BaseInstallUninstallViewModel() { + companion object { const val RESULT_DEP_INSTALLED = 200 const val RESULT_REPO_NOT_FOUND = 404 @@ -28,48 +23,47 @@ class InstallViewModel @Inject constructor( override suspend fun call(command: Install): Int { - val progressBar = progressBarBuilder.build() - return progressBar.use { + val depName = command.depName.trim().toLowerCase() - val depName = command.depName.trim().toLowerCase() + // first get from + val gpmDep = getDep(command, depName) + ?: return RESULT_REPO_NOT_FOUND - // first get from - progressBar.set(20, "Searching '$depName'") - val gpmDep = getDep(command, depName) - ?: return RESULT_REPO_NOT_FOUND + val depTypes = getDepTypes( + command.isSave, + command.isSaveDev, + command.isSaveDevAndroid, + gpmDep.defaultType + ) - val depTypes = getDepTypes( - command.isSave, - command.isSaveDev, - command.isSaveDevAndroid, - gpmDep.defaultType - ) + require(depTypes.isNotEmpty()) { "Dependency type can't be empty" } - require(depTypes.isNotEmpty()) { "Dependency type can't be empty" } + // Getting latest version - // Getting latest version + // Adding each dependency + for (depType in depTypes) { + gradleManager.addDep( + depName, + depType, + gpmDep + ) + } - // Adding each dependency - progressBar.set(50, "Installing '$depName'") - for (depType in depTypes) { - gradleManager.addDep( - depName, - depType, - gpmDep - ) - } - progressBar.set(100, "Done") - RESULT_DEP_INSTALLED - } + return RESULT_DEP_INSTALLED } - private suspend fun getDep(install: Install, depName: String): GpmDep? { + private suspend fun getDep( + install: Install, + depName: String + ): GpmDep? { + var gpmDep = gpmRepo.getDep(depName) if (gpmDep == null) { // Searching for maven + gpmDep = getFromMaven(install, depName) } @@ -77,26 +71,34 @@ class InstallViewModel @Inject constructor( } private suspend fun getFromMaven(install: Install, depName: String): GpmDep? { - val mavenDeps = mavenRepo.search(depName) - if (mavenDeps.isNotEmpty()) { - val mostUsed = mavenDeps.maxBy { it.usage }!! - val selDepIndex = install.chooseIndex( - mavenDeps.map { - val text = "${it.groupId}:${it.artifactId}" - if (it == mostUsed) { - // color text - CommandLine.Help.Ansi.AUTO.string("@|bold,green $text|@") - } else { - //normal text - text + + val mostUsed = mavenDeps.maxBy { it.usage ?: 0 }!! + val selDepIndex = if (mavenDeps.size > 1) { + + val index = install.chooseIndex( + mavenDeps.map { + val text = "${it.groupId}:${it.artifactId}" + if (it == mostUsed) { + // color text + CommandLine.Help.Ansi.AUTO.string("@|bold,green $text|@") + } else { + //normal text + text + } } - } - ) + ) + + index + } else { + 0 + } + val selMavenDep = mavenDeps[selDepIndex] - // Getting last version + // Getting latest version + val artifactInfo = mavenRepo.getLatestVersion( selMavenDep.groupId, selMavenDep.artifactId diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt index 4282840..96ccca5 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt @@ -53,10 +53,10 @@ class Uninstall(isFromTest: Boolean = false) : BaseCommand(isFromTest) { } fun onNoDepInstalled(depType: GradleDep.Type, depName: String) { - println("No dependency named '$depName' installed as '${depType.key}' using gpm. You might have installed it manually.") + println("⚠️ No dependency named '$depName' installed as '${depType.key}' using gpm. You might have installed it manually.") } fun onBeforeDepRemove(depType: GradleDep.Type, depName: String) { - println("Removing '${depType.key}' of $depName...'") + println("🗑️ Removing '${depType.key}' of '$depName'...") } } \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallViewModel.kt index 37e1466..db89fd9 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallViewModel.kt @@ -31,7 +31,6 @@ class UninstallViewModel @Inject constructor( command.onBeforeDepRemove(depType, depName) val installedDeps = tm.getInstalled(depType.key, depName) - println("Size is ${installedDeps.size}") if (installedDeps.isEmpty()) { command.onNoDepInstalled(depType, depName) diff --git a/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt b/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt index 8e23118..04ca262 100644 --- a/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt +++ b/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt @@ -25,12 +25,12 @@ class TransactionManager @Inject constructor( // Need to login val newDepId = getLastDepAdded()?.id?.plus(1) ?: 1 - if (newDepId != 1) { + /*if (newDepId != 1) { // got prev transaction, so check if this is a duplicate one if (isDuplicate(installedName, type, newGpmDep)) { return } - } + }*/ val depToStore = GpmFileData.AddedDep( newDepId, diff --git a/src/main/kotlin/com/theapache64/gpm/data/remote/maven/models/SearchResult.kt b/src/main/kotlin/com/theapache64/gpm/data/remote/maven/models/SearchResult.kt index 095c960..3899711 100644 --- a/src/main/kotlin/com/theapache64/gpm/data/remote/maven/models/SearchResult.kt +++ b/src/main/kotlin/com/theapache64/gpm/data/remote/maven/models/SearchResult.kt @@ -8,7 +8,7 @@ data class SearchResult( val groupId: String, val artifactId: String, val description: String, - val usage: Int, + val usage: Int?, val lastRelease: Date ) { val url = "https://mvnrepository.com/artifact/$groupId/$artifactId" diff --git a/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt b/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt index f0ef0d2..40dfffd 100644 --- a/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt +++ b/src/main/kotlin/com/theapache64/gpm/data/repos/MavenRepo.kt @@ -15,7 +15,7 @@ class MavenRepo @Inject constructor( ) { companion object { private val SEARCH_RESULT_REGEX by lazy { - "
.+?(?\\d+?)\\. <\\/span>.+?)\\/(?.+?)\">(?.+?)<\\/a>.+?(?.+?)<\\/b> usages<\\/a>.+?im-description\">(?.+?).+?)<\\/div>".toRegex() + "
.+?(?\\d+?)\\. <\\/span>.+?)\\/(?.+?)\">(?.+?)<\\/a>.+?(?:(?.+?)<\\/b> usages<\\/a>.+?)?im-description\">(?.+?).+?)<\\/div".toRegex() } private val ARTIFACT_VERSION_REGEX by lazy { @@ -27,7 +27,6 @@ class MavenRepo @Inject constructor( } suspend fun search(depName: String): List { - val searchHtml = mavenApiInterface.search(depName) val htmlResp = searchHtml.removeNewLinesAndMultipleSpaces() val matches = SEARCH_RESULT_REGEX.findAll(htmlResp) @@ -44,6 +43,13 @@ class MavenRepo @Inject constructor( lastRelease ) = match.destructured + val usage = usages.trim().replace(",", "").let { + if (it.isEmpty()) { + null + } else { + it.toInt() + } + } searchResults.add( SearchResult( number.trim().toInt(), @@ -51,7 +57,7 @@ class MavenRepo @Inject constructor( groupId.trim(), artifactId.trim(), StringEscapeUtils.unescapeHtml4(description.trim()), - usages.trim().replace(",", "").toInt(), + usage, SEARCH_RESULT_DATE_FORMAT.parse(lastRelease.trim()) ) ) diff --git a/src/main/kotlin/com/theapache64/gpm/di/Qualifiers.kt b/src/main/kotlin/com/theapache64/gpm/di/Qualifiers.kt index 5f32695..89c81b8 100644 --- a/src/main/kotlin/com/theapache64/gpm/di/Qualifiers.kt +++ b/src/main/kotlin/com/theapache64/gpm/di/Qualifiers.kt @@ -10,9 +10,4 @@ annotation class GradleFile @Qualifier @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) -annotation class GpmJsonFile - -@Qualifier -@MustBeDocumented -@Retention(AnnotationRetention.RUNTIME) -annotation class InstallProgress \ No newline at end of file +annotation class GpmJsonFile \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt b/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt deleted file mode 100644 index cfe9d85..0000000 --- a/src/main/kotlin/com/theapache64/gpm/di/modules/ProgressBarModule.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.theapache64.gpm.di.modules - -import com.theapache64.gpm.di.InstallProgress -import dagger.Module -import dagger.Provides -import me.tongfei.progressbar.ProgressBar -import me.tongfei.progressbar.ProgressBarBuilder - -@Module -class ProgressBarModule { - - @InstallProgress - @Provides - fun provideInstallProgressBar(): ProgressBarBuilder { - return ProgressBarBuilder() - .setTaskName("🚛 Install") - .setInitialMax(100) - .setUpdateIntervalMillis(200) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/utils/ProgressBarExtension.kt b/src/main/kotlin/com/theapache64/gpm/utils/ProgressBarExtension.kt deleted file mode 100644 index 6929c0b..0000000 --- a/src/main/kotlin/com/theapache64/gpm/utils/ProgressBarExtension.kt +++ /dev/null @@ -1,8 +0,0 @@ -package com.theapache64.gpm.utils - -import me.tongfei.progressbar.ProgressBar - -fun ProgressBar.set(stepTo: Long, msg: String) { - stepTo(stepTo) - extraMessage = msg -} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/utils/ProgressPrinter.kt b/src/main/kotlin/com/theapache64/gpm/utils/ProgressPrinter.kt new file mode 100644 index 0000000..3f940c0 --- /dev/null +++ b/src/main/kotlin/com/theapache64/gpm/utils/ProgressPrinter.kt @@ -0,0 +1,9 @@ +package com.theapache64.gpm.utils + +fun printProgress(text: String) { + println("🔄 $text") +} + +fun printSuccess(text: String) { + println("✔️ $text") +} \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt b/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt index a78fa9c..80101d1 100644 --- a/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt +++ b/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt @@ -1,20 +1,5 @@ package com.theapache64.gpm.utils -import me.tongfei.progressbar.ProgressBarBuilder -import me.tongfei.progressbar.ProgressBarStyle - fun main(args: Array) { - val pb = ProgressBarBuilder() - .setInitialMax(100) - .setStyle(ProgressBarStyle.COLORFUL_UNICODE_BLOCK) - .setTaskName("Print task") - .setUpdateIntervalMillis(100) - .build() - pb.use { - for (name in (0..100)) { - it.extraMessage = "Printing $name" - Thread.sleep(50) - it.step() - } - } + } \ No newline at end of file From 1f792108e735b11e6e2b5e15a5734da292cdfae2 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 16:48:50 +0530 Subject: [PATCH 15/17] =?UTF-8?q?=F0=9F=8C=9F=20add=20basic=20progress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/subcommands/install/Install.kt | 26 +++++++++++++++++++ .../subcommands/install/InstallViewModel.kt | 26 ++++++++++++------- .../theapache64/gpm/utils/ProgressPrinter.kt | 9 ------- 3 files changed, 42 insertions(+), 19 deletions(-) delete mode 100644 src/main/kotlin/com/theapache64/gpm/utils/ProgressPrinter.kt diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt index a67e50e..751c3b1 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt @@ -1,6 +1,8 @@ package com.theapache64.gpm.commands.subcommands.install import com.theapache64.gpm.commands.base.BaseCommand +import com.theapache64.gpm.core.gm.GradleDep +import com.theapache64.gpm.data.remote.gpm.models.GpmDep import com.theapache64.gpm.di.modules.CommandModule import com.theapache64.gpm.di.modules.GradleModule import com.theapache64.gpm.di.modules.TransactionModule @@ -52,4 +54,28 @@ class Install(isFromTest: Boolean = false) : BaseCommand(isFromTest) { override fun call(): Int = runBlocking { installViewModel.call(this@Install) } + + fun onBeforeGetDep() { + println("🔍 Searching for '$depName'") + } + + fun onDepGot(gpmDep: GpmDep) { + println("✔️ Found dependency") + } + + fun onBeforeSearchingInGpmRegistry() { + println("🔍 Searching in gpm registry for '$depName'...") + } + + fun onBeforeSearchingInMavenCentral() { + println("🔍 Searching in maven for '$depName'") + } + + fun onDepNotFoundAnywhere() { + println("❌ Couldn't find dependency with name '$depName'") + } + + fun onBeforeAddDependency(depType: GradleDep.Type) { + println("⌨️ Adding ${depType.key} to build.gradle...") + } } \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt index 1b1d5bc..0f50358 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt @@ -21,28 +21,28 @@ class InstallViewModel @Inject constructor( const val RESULT_REPO_NOT_FOUND = 404 } - override suspend fun call(command: Install): Int { + override suspend fun call(install: Install): Int { - val depName = command.depName.trim().toLowerCase() + val depName = install.depName.trim().toLowerCase() // first get from - val gpmDep = getDep(command, depName) + install.onBeforeGetDep() + val gpmDep = getDep(install, depName) ?: return RESULT_REPO_NOT_FOUND - + install.onDepGot(gpmDep) val depTypes = getDepTypes( - command.isSave, - command.isSaveDev, - command.isSaveDevAndroid, + install.isSave, + install.isSaveDev, + install.isSaveDevAndroid, gpmDep.defaultType ) require(depTypes.isNotEmpty()) { "Dependency type can't be empty" } - // Getting latest version - // Adding each dependency for (depType in depTypes) { + install.onBeforeAddDependency(depType) gradleManager.addDep( depName, depType, @@ -59,19 +59,25 @@ class InstallViewModel @Inject constructor( depName: String ): GpmDep? { + install.onBeforeSearchingInGpmRegistry() var gpmDep = gpmRepo.getDep(depName) if (gpmDep == null) { // Searching for maven - + install.onBeforeSearchingInMavenCentral() gpmDep = getFromMaven(install, depName) } + if (gpmDep == null) { + install.onDepNotFoundAnywhere() + } + return gpmDep } private suspend fun getFromMaven(install: Install, depName: String): GpmDep? { val mavenDeps = mavenRepo.search(depName) + if (mavenDeps.isNotEmpty()) { val mostUsed = mavenDeps.maxBy { it.usage ?: 0 }!! diff --git a/src/main/kotlin/com/theapache64/gpm/utils/ProgressPrinter.kt b/src/main/kotlin/com/theapache64/gpm/utils/ProgressPrinter.kt deleted file mode 100644 index 3f940c0..0000000 --- a/src/main/kotlin/com/theapache64/gpm/utils/ProgressPrinter.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.theapache64.gpm.utils - -fun printProgress(text: String) { - println("🔄 $text") -} - -fun printSuccess(text: String) { - println("✔️ $text") -} \ No newline at end of file From 572c83615de05f3031761473a98104cc125a0a87 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 17:32:14 +0530 Subject: [PATCH 16/17] =?UTF-8?q?=F0=9F=93=96=20update=20progress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/subcommands/install/Install.kt | 2 +- .../subcommands/install/InstallViewModel.kt | 18 +++++++++--------- .../subcommands/uninstall/Uninstall.kt | 4 ++-- .../uninstall/UninstallViewModel.kt | 3 ++- .../theapache64/gpm/core/TransactionManager.kt | 4 ++-- .../com/theapache64/gpm/utils/TestMain.kt | 5 ----- 6 files changed, 16 insertions(+), 20 deletions(-) delete mode 100644 src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt index 751c3b1..fda4502 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/Install.kt @@ -59,7 +59,7 @@ class Install(isFromTest: Boolean = false) : BaseCommand(isFromTest) { println("🔍 Searching for '$depName'") } - fun onDepGot(gpmDep: GpmDep) { + fun onDepGot() { println("✔️ Found dependency") } diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt index 0f50358..953cf5e 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/install/InstallViewModel.kt @@ -21,20 +21,20 @@ class InstallViewModel @Inject constructor( const val RESULT_REPO_NOT_FOUND = 404 } - override suspend fun call(install: Install): Int { + override suspend fun call(command: Install): Int { - val depName = install.depName.trim().toLowerCase() + val depName = command.depName.trim().toLowerCase() // first get from - install.onBeforeGetDep() - val gpmDep = getDep(install, depName) + command.onBeforeGetDep() + val gpmDep = getDep(command, depName) ?: return RESULT_REPO_NOT_FOUND - install.onDepGot(gpmDep) + command.onDepGot() val depTypes = getDepTypes( - install.isSave, - install.isSaveDev, - install.isSaveDevAndroid, + command.isSave, + command.isSaveDev, + command.isSaveDevAndroid, gpmDep.defaultType ) @@ -42,7 +42,7 @@ class InstallViewModel @Inject constructor( // Adding each dependency for (depType in depTypes) { - install.onBeforeAddDependency(depType) + command.onBeforeAddDependency(depType) gradleManager.addDep( depName, depType, diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt index 96ccca5..c56b1eb 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/Uninstall.kt @@ -56,7 +56,7 @@ class Uninstall(isFromTest: Boolean = false) : BaseCommand(isFromTest) { println("⚠️ No dependency named '$depName' installed as '${depType.key}' using gpm. You might have installed it manually.") } - fun onBeforeDepRemove(depType: GradleDep.Type, depName: String) { - println("🗑️ Removing '${depType.key}' of '$depName'...") + fun onAfterDepRemove(depType: GradleDep.Type, depName: String) { + println("🗑️ Removed '${depType.key}' of '$depName'...") } } \ No newline at end of file diff --git a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallViewModel.kt b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallViewModel.kt index db89fd9..fb56dd1 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallViewModel.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/subcommands/uninstall/UninstallViewModel.kt @@ -29,7 +29,7 @@ class UninstallViewModel @Inject constructor( for (depType in depTypes) { - command.onBeforeDepRemove(depType, depName) + val installedDeps = tm.getInstalled(depType.key, depName) if (installedDeps.isEmpty()) { @@ -50,6 +50,7 @@ class UninstallViewModel @Inject constructor( } gradleManager.removeDep(depToRemove) + command.onAfterDepRemove(depType, depName) } return RESULT_DEP_UNINSTALLED diff --git a/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt b/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt index 04ca262..8e23118 100644 --- a/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt +++ b/src/main/kotlin/com/theapache64/gpm/core/TransactionManager.kt @@ -25,12 +25,12 @@ class TransactionManager @Inject constructor( // Need to login val newDepId = getLastDepAdded()?.id?.plus(1) ?: 1 - /*if (newDepId != 1) { + if (newDepId != 1) { // got prev transaction, so check if this is a duplicate one if (isDuplicate(installedName, type, newGpmDep)) { return } - }*/ + } val depToStore = GpmFileData.AddedDep( newDepId, diff --git a/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt b/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt deleted file mode 100644 index 80101d1..0000000 --- a/src/main/kotlin/com/theapache64/gpm/utils/TestMain.kt +++ /dev/null @@ -1,5 +0,0 @@ -package com.theapache64.gpm.utils - -fun main(args: Array) { - -} \ No newline at end of file From 7e83f45c592a591379d1ac6adb21adfac1469cd4 Mon Sep 17 00:00:00 2001 From: theapache64 Date: Fri, 8 May 2020 18:00:38 +0530 Subject: [PATCH 17/17] =?UTF-8?q?=E2=97=80=EF=B8=8F=20audo=20completion=20?= =?UTF-8?q?script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 + gpm_completion | 262 ++++++++++++++++++ install.sh | 0 .../com/theapache64/gpm/commands/gpm/Gpm.kt | 2 +- 4 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 gpm_completion create mode 100644 install.sh diff --git a/build.gradle b/build.gradle index a71a398..67863ea 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,9 @@ dependencies { // DaggerMock testImplementation 'com.github.fabioCollini.daggermock:daggermock:0.8.5' testImplementation 'com.github.fabioCollini.daggermock:daggermock-kotlin:0.8.5' + + // OkHttp:For networking + implementation 'com.squareup.okhttp3:okhttp:4.6.0' } compileKotlin { diff --git a/gpm_completion b/gpm_completion new file mode 100644 index 0000000..3042e66 --- /dev/null +++ b/gpm_completion @@ -0,0 +1,262 @@ +#!/usr/bin/env bash +# +# gpm Bash Completion +# ======================= +# +# Bash completion support for the `gpm` command, +# generated by [picocli](http://picocli.info/) version 4.2.0. +# +# Installation +# ------------ +# +# 1. Source all completion scripts in your .bash_profile +# +# cd $YOUR_APP_HOME/bin +# for f in $(find . -name "*_completion"); do line=". $(pwd)/$f"; grep "$line" ~/.bash_profile || echo "$line" >> ~/.bash_profile; done +# +# 2. Open a new bash console, and type `gpm [TAB][TAB]` +# +# 1a. Alternatively, if you have [bash-completion](https://github.com/scop/bash-completion) installed: +# Place this file in a `bash-completion.d` folder: +# +# * /etc/bash-completion.d +# * /usr/local/etc/bash-completion.d +# * ~/bash-completion.d +# +# Documentation +# ------------- +# The script is called by bash whenever [TAB] or [TAB][TAB] is pressed after +# 'gpm (..)'. By reading entered command line parameters, +# it determines possible bash completions and writes them to the COMPREPLY variable. +# Bash then completes the user input if only one entry is listed in the variable or +# shows the options if more than one is listed in COMPREPLY. +# +# References +# ---------- +# [1] http://stackoverflow.com/a/12495480/1440785 +# [2] http://tiswww.case.edu/php/chet/bash/FAQ +# [3] https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html +# [4] http://zsh.sourceforge.net/Doc/Release/Options.html#index-COMPLETE_005fALIASES +# [5] https://stackoverflow.com/questions/17042057/bash-check-element-in-array-for-elements-in-another-array/17042655#17042655 +# [6] https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion +# [7] https://stackoverflow.com/questions/3249432/can-a-bash-tab-completion-script-be-used-in-zsh/27853970#27853970 +# + +if [ -n "$BASH_VERSION" ]; then + # Enable programmable completion facilities when using bash (see [3]) + shopt -s progcomp +elif [ -n "$ZSH_VERSION" ]; then + # Make alias a distinct command for completion purposes when using zsh (see [4]) + setopt COMPLETE_ALIASES + alias compopt=complete + + # Enable bash completion in zsh (see [7]) + autoload -U +X compinit && compinit + autoload -U +X bashcompinit && bashcompinit +fi + +# CompWordsContainsArray takes an array and then checks +# if all elements of this array are in the global COMP_WORDS array. +# +# Returns zero (no error) if all elements of the array are in the COMP_WORDS array, +# otherwise returns 1 (error). +function CompWordsContainsArray() { + declare -a localArray + localArray=("$@") + local findme + for findme in "${localArray[@]}"; do + if ElementNotInCompWords "$findme"; then return 1; fi + done + return 0 +} +function ElementNotInCompWords() { + local findme="$1" + local element + for element in "${COMP_WORDS[@]}"; do + if [[ "$findme" = "$element" ]]; then return 1; fi + done + return 0 +} + +# The `currentPositionalIndex` function calculates the index of the current positional parameter. +# +# currentPositionalIndex takes three parameters: +# the command name, +# a space-separated string with the names of options that take a parameter, and +# a space-separated string with the names of boolean options (that don't take any params). +# When done, this function echos the current positional index to std_out. +# +# Example usage: +# local currIndex=$(currentPositionalIndex "mysubcommand" "$ARG_OPTS" "$FLAG_OPTS") +function currentPositionalIndex() { + local commandName="$1" + local optionsWithArgs="$2" + local booleanOptions="$3" + local previousWord + local result=0 + + for i in $(seq $((COMP_CWORD - 1)) -1 0); do + previousWord=${COMP_WORDS[i]} + if [ "${previousWord}" = "$commandName" ]; then + break + fi + if [[ "${optionsWithArgs}" =~ ${previousWord} ]]; then + ((result-=2)) # Arg option and its value not counted as positional param + elif [[ "${booleanOptions}" =~ ${previousWord} ]]; then + ((result-=1)) # Flag option itself not counted as positional param + fi + ((result++)) + done + echo "$result" +} + +# Bash completion entry point function. +# _complete_gpm finds which commands and subcommands have been specified +# on the command line and delegates to the appropriate function +# to generate possible options and subcommands for the last specified subcommand. +function _complete_gpm() { + local cmds0=(install) + local cmds1=(i) + local cmds2=(uninstall) + local cmds3=(u) + local cmds4=(docs) + local cmds5=(d) + + if CompWordsContainsArray "${cmds5[@]}"; then _picocli_gpm_d; return $?; fi + if CompWordsContainsArray "${cmds4[@]}"; then _picocli_gpm_docs; return $?; fi + if CompWordsContainsArray "${cmds3[@]}"; then _picocli_gpm_u; return $?; fi + if CompWordsContainsArray "${cmds2[@]}"; then _picocli_gpm_uninstall; return $?; fi + if CompWordsContainsArray "${cmds1[@]}"; then _picocli_gpm_i; return $?; fi + if CompWordsContainsArray "${cmds0[@]}"; then _picocli_gpm_install; return $?; fi + + # No subcommands were specified; generate completions for the top-level command. + _picocli_gpm; return $?; +} + +# Generates completions for the options and subcommands of the `gpm` command. +function _picocli_gpm() { + # Get completion data + local curr_word=${COMP_WORDS[COMP_CWORD]} + + local commands="install i uninstall u docs d" + local flag_opts="-h --help -V --version" + local arg_opts="" + + if [[ "${curr_word}" == -* ]]; then + COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) + else + local positionals="" + COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) + fi +} + +# Generates completions for the options and subcommands of the `install` subcommand. +function _picocli_gpm_install() { + # Get completion data + local curr_word=${COMP_WORDS[COMP_CWORD]} + + local commands="" + local flag_opts="-S --save -D --save-dev -DA --save-dev-android" + local arg_opts="" + + if [[ "${curr_word}" == -* ]]; then + COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) + else + local positionals="" + COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) + fi +} + +# Generates completions for the options and subcommands of the `i` subcommand. +function _picocli_gpm_i() { + # Get completion data + local curr_word=${COMP_WORDS[COMP_CWORD]} + + local commands="" + local flag_opts="-S --save -D --save-dev -DA --save-dev-android" + local arg_opts="" + + if [[ "${curr_word}" == -* ]]; then + COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) + else + local positionals="" + COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) + fi +} + +# Generates completions for the options and subcommands of the `uninstall` subcommand. +function _picocli_gpm_uninstall() { + # Get completion data + local curr_word=${COMP_WORDS[COMP_CWORD]} + + local commands="" + local flag_opts="-S --save -D --save-dev -DA --save-dev-android" + local arg_opts="" + + if [[ "${curr_word}" == -* ]]; then + COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) + else + local positionals="" + COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) + fi +} + +# Generates completions for the options and subcommands of the `u` subcommand. +function _picocli_gpm_u() { + # Get completion data + local curr_word=${COMP_WORDS[COMP_CWORD]} + + local commands="" + local flag_opts="-S --save -D --save-dev -DA --save-dev-android" + local arg_opts="" + + if [[ "${curr_word}" == -* ]]; then + COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) + else + local positionals="" + COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) + fi +} + +# Generates completions for the options and subcommands of the `docs` subcommand. +function _picocli_gpm_docs() { + # Get completion data + local curr_word=${COMP_WORDS[COMP_CWORD]} + + local commands="" + local flag_opts="" + local arg_opts="" + + if [[ "${curr_word}" == -* ]]; then + COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) + else + local positionals="" + COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) + fi +} + +# Generates completions for the options and subcommands of the `d` subcommand. +function _picocli_gpm_d() { + # Get completion data + local curr_word=${COMP_WORDS[COMP_CWORD]} + + local commands="" + local flag_opts="" + local arg_opts="" + + if [[ "${curr_word}" == -* ]]; then + COMPREPLY=( $(compgen -W "${flag_opts} ${arg_opts}" -- "${curr_word}") ) + else + local positionals="" + COMPREPLY=( $(compgen -W "${commands} ${positionals}" -- "${curr_word}") ) + fi +} + +# Define a completion specification (a compspec) for the +# `gpm`, `gpm.sh`, and `gpm.bash` commands. +# Uses the bash `complete` builtin (see [6]) to specify that shell function +# `_complete_gpm` is responsible for generating possible completions for the +# current word on the command line. +# The `-o default` option means that if the function generated no matches, the +# default Bash completions and the Readline default filename completions are performed. +complete -F _complete_gpm -o default gpm gpm.sh gpm.bash diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..e69de29 diff --git a/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt b/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt index c0e7250..5ed6deb 100644 --- a/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt +++ b/src/main/kotlin/com/theapache64/gpm/commands/gpm/Gpm.kt @@ -20,7 +20,7 @@ import javax.inject.Singleton ] ) @Singleton -class Gpm @Inject constructor(isFromTest: Boolean) : BaseCommand(isFromTest) { +class Gpm @Inject constructor(isFromTest: Boolean = false) : BaseCommand(isFromTest) { init { DaggerGpmComponent.create().inject(this)