.+?vbtn release\">(?.+?)<\\/a><\\/td>.+?)\">(?.+?)<\\/a>".toRegex()
+ ".+?vbtn release\">(?.+?)<\\/a>.+?.+?)\">(?.+?)<\\/a>".toRegex()
}
//Apr 29, 2020
@@ -27,8 +27,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) {
@@ -43,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(),
@@ -50,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/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
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..9ec647a 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
@@ -19,6 +18,7 @@ class NetworkModule {
return Retrofit.Builder()
}
+ @Singleton
@Provides
fun provideGpmApiInterface(retrofitBuilder: Retrofit.Builder, moshi: Moshi): GpmApiInterface {
return retrofitBuilder
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/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/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/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/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 1b428f0..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,45 +1,29 @@
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.CommandModule
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
import org.junit.Test
import picocli.CommandLine
-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 {
- 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)
@@ -51,6 +35,7 @@ class InstallTest {
customizeBuilder {
it.gradleModule(GradleModule(isFromTest = true))
.transactionModule(TransactionModule(true))
+ .commandModule(CommandModule(true))
}
set {
tempBuildGradle = it.gradleFile()
@@ -60,47 +45,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.html").readText()
- )
-
- whenever(fakeMavenApi.search(INVALID_REPO)).thenReturn("")
- whenever(fakeGpmApi.getDependency(INVALID_REPO)).thenThrow(HttpException::class.java)
-
this.installCmd = CommandLine(install)
installCmd.out = PrintWriter(StringWriter())
}
@@ -112,6 +59,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")
@@ -142,7 +97,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)
}
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..621d8bc
--- /dev/null
+++ b/src/test/kotlin/com/theapache64/gpm/commands/subcommands/docs/DocsTest.kt
@@ -0,0 +1,113 @@
+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.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)
+
+ @InjectFromComponent
+ private lateinit var tm: TransactionManager
+
+ @get:Rule
+ val daggerRule = DaggerMock.rule(TransactionModule(true)) {
+ set {
+ tm = it.transactionManager()
+ gpmJsonFile = it.gpmJsonFile()
+ }
+ }
+
+ @Before
+ fun setUp() {
+ this.docsCmd = CommandLine(docs)
+ }
+
+ @After
+ fun tearDown() {
+ gpmJsonFile.delete()
+ }
+
+ @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`() {
+ 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
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/data/repos/MavenRepoTest.kt b/src/test/kotlin/com/theapache64/gpm/data/repos/MavenRepoTest.kt
index 0ff0d42..92e8877 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 `Getting valid artifact information 2`() = 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 c0b8bf5..f69701a 100644
--- a/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt
+++ b/src/test/kotlin/com/theapache64/gpm/rules/MyDaggerMockRule.kt
@@ -1,7 +1,9 @@
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.CommandModule
+
import com.theapache64.gpm.di.modules.GradleModule
import com.theapache64.gpm.di.modules.NetworkModule
import com.theapache64.gpm.di.modules.TransactionModule
@@ -15,6 +17,7 @@ class MyDaggerMockRule : DaggerMockRule(
init {
customizeBuilder {
it.transactionModule(TransactionModule(true))
+ .commandModule(CommandModule(true))
}
}
}
\ No newline at end of file
diff --git a/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt b/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt
index c647576..4ba1bde 100644
--- a/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt
+++ b/src/test/kotlin/com/theapache64/gpm/utils/GradleManagerTest.kt
@@ -1,11 +1,11 @@
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.CommandModule
import com.theapache64.gpm.di.modules.GradleModule
import com.theapache64.gpm.di.modules.TransactionModule
import com.winterbe.expekt.should
@@ -25,7 +25,8 @@ class GradleManagerTest {
@get:Rule
val daggerRule = DaggerMock.rule(
GradleModule(true),
- TransactionModule(true)
+ TransactionModule(true),
+ CommandModule(true)
) {
set {
gradleFile = it.gradleFile()
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
|