Skip to content

Commit

Permalink
Released 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyr committed May 5, 2020
1 parent acd3e32 commit fa72237
Show file tree
Hide file tree
Showing 24 changed files with 280 additions and 253 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
.mtj.tmp/

# Package Files #
*.jar
#*.jar
*.war
*.nar
*.ear
*.zip
#*.zip
*.tar.gz
*.rar

Expand Down
9 changes: 0 additions & 9 deletions .idea/libraries/jsoup.xml

This file was deleted.

1 change: 0 additions & 1 deletion GoogleLibraryVersionQuerier.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jsoup" level="project" />
<orderEntry type="library" name="gson" level="project" />
</component>
</module>
Binary file added GoogleLibraryVersionQuerier.zip
Binary file not shown.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# GoogleLibraryVersionQuerier
一款Android Studio插件,用于快速查询和替换Google最新版本仓库。
## 一款Android Studio插件,帮助你快速添加Google依赖库和查询历史版本
### 特性:
#### 1. 编辑build.gradle时,会有代码提示:
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/1.gif)
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/2.gif)

<br/>

#### 2. 光标定位在目标类库,右键可快速查看和替换某个版本:
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/3.gif) ![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/4.gif)
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/5.gif)
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/6.gif)
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/7.gif)

<br/>

### 安装:
*Android Studio -> Settings -> Plugins -> Marketplace*
搜索:***Google Library Version Querier***即可:
![preview](https://github.com/wuyr/GoogleLibraryVersionQuerier/raw/master/previews/8.gif)

<br/>

### 数据来源:[wanandroid.com](https://wanandroid.com/maven_pom/index)
Binary file added lib/gson-2.8.5.jar
Binary file not shown.
Binary file not shown.
10 changes: 6 additions & 4 deletions out/production/GoogleLibraryVersionQuerier/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<idea-plugin>
<id>com.wuyr.google_library_query</id>
<name>Google Library Version Querier</name>
<version>1.0</version>
<version>2.0</version>
<vendor email="ifxcyr@gmail.com" url="https://www.github.com/wuyr">陈小缘</vendor>

<description><![CDATA[
<p>Query and replace the latest version of Google Library.</p>
<p>A plugin to facilitate adding Google library dependencies and choice historical versions.</p>
<br/>
<p><strong>Github: </strong><a href="https://github.com/wuyr/GoogleLibraryVersionQuerier"> github.com/wuyr/GoogleLibraryVersionQuerier</a></p>
<br/>
<p>Powered by wanandroid.com</p>
]]></description>

<change-notes><![CDATA[
<li><strong>1.0 </strong>Query and replace the latest version of Google Library.</li>
<p><li><strong>2.0 </strong>Add build.gradle dependency code completion and free choice of historical version.</li></p>
<p><li><strong>1.0 </strong>Completed the function of finding and replacing the latest version of Google Library.</li></p>
<br>
]]>
</change-notes>
Expand All @@ -29,7 +31,7 @@

<actions>
<action id="com.wuyr.google_library_query.QueryAction" class="com.wuyr.google_library_query.QueryAction"
text="Query The Latest Version" description="Query the latest version">
text="Query Available Versions" description="Query available versions">
<add-to-group group-id="XmlGenerateToolsGroup"/>
<keyboard-shortcut keymap="$default" first-keystroke="alt Q"/>
</action>
Expand Down
Binary file added previews/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 6 additions & 4 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<idea-plugin>
<id>com.wuyr.google_library_query</id>
<name>Google Library Version Querier</name>
<version>1.0</version>
<version>2.0</version>
<vendor email="ifxcyr@gmail.com" url="https://www.github.com/wuyr">陈小缘</vendor>

<description><![CDATA[
<p>Query and replace the latest version of Google Library.</p>
<p>A plugin to facilitate adding Google library dependencies and choice historical versions.</p>
<br/>
<p><strong>Github: </strong><a href="https://github.com/wuyr/GoogleLibraryVersionQuerier"> github.com/wuyr/GoogleLibraryVersionQuerier</a></p>
<br/>
<p>Powered by wanandroid.com</p>
]]></description>

<change-notes><![CDATA[
<li><strong>1.0 </strong>Query and replace the latest version of Google Library.</li>
<p><li><strong>2.0 </strong>Add build.gradle dependency code completion and free choice of historical version.</li></p>
<p><li><strong>1.0 </strong>Completed the function of finding and replacing the latest version of Google Library.</li></p>
<br>
]]>
</change-notes>
Expand All @@ -29,7 +31,7 @@

<actions>
<action id="com.wuyr.google_library_query.QueryAction" class="com.wuyr.google_library_query.QueryAction"
text="Query The Latest Version" description="Query the latest version">
text="Query Available Versions" description="Query available versions">
<add-to-group group-id="XmlGenerateToolsGroup"/>
<keyboard-shortcut keymap="$default" first-keystroke="alt Q"/>
</action>
Expand Down
46 changes: 0 additions & 46 deletions src/com/wuyr/google_library_query/GradleContributor.java

This file was deleted.

52 changes: 52 additions & 0 deletions src/com/wuyr/google_library_query/GradleContributor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.wuyr.google_library_query

import com.intellij.codeInsight.completion.CompletionContributor
import com.intellij.codeInsight.completion.CompletionInitializationContext
import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.openapi.util.TextRange
import com.intellij.util.PlatformIcons


class GradleContributor : CompletionContributor() {

private var needShow = false
private val acceptFilesName = arrayOf("build.gradle")

override fun beforeCompletion(context: CompletionInitializationContext) {
needShow = acceptFilesName.contains(context.file.name)
}

override fun fillCompletionVariants(parameters: CompletionParameters, result: CompletionResultSet) {
if (needShow) {
val lineStartPosition = parameters.editor.caretModel.visualLineStart
val lineEndPosition = parameters.editor.caretModel.visualLineEnd
val currentLineContent = parameters.editor.document.getText(TextRange(lineStartPosition, lineEndPosition)).replace("\n".toRegex(), "").trim()
if (currentLineContent.length < 4) {
return
}
currentLineContent.split("\\s+".toRegex()).let {
if (it.isNotEmpty()) {
var removeImplementation = false
val keyword = if (it.size == 1) {
it.first()
} else {
if (it.first() == "implementation") removeImplementation = true
it.last()
}
matchingLibraries(keyword).forEach { e ->
result.addElement(e.toLookupElement(removeImplementation))
}
}
}
needShow = false
}
super.fillCompletionVariants(parameters, result)
}

private fun Pair<String, String>.toLookupElement(removeImplementation: Boolean) = LookupElementBuilder
.create(if (removeImplementation) first.replace("implementation ", "") else first)
.bold().withIcon(PlatformIcons.LIBRARY_ICON).withTypeText(second, true)
.withTypeIconRightAligned(true)
}
68 changes: 68 additions & 0 deletions src/com/wuyr/google_library_query/NetworkRequstter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@file:Suppress("UNCHECKED_CAST")

package com.wuyr.google_library_query

import com.google.gson.Gson
import java.net.URL
import java.nio.charset.Charset
import javax.net.ssl.HttpsURLConnection
import javax.swing.DefaultListModel

const val BASE_URL = "https://wanandroid.com/maven_pom/"

@Throws(java.lang.Exception::class)
fun getAvailableVersions(libraryGroup: String, libraryName: String) = search("$libraryGroup:$libraryName") { dataList ->
dataList.find { it["groupName"] == libraryGroup }?.run {
(this["artifactMap"] as? Map<String, Any>)?.run {
(this[libraryName] as? List<Map<String, Any>>)?.map {
it["version"].toString()
}
}
}
}

@Throws(java.lang.Exception::class)
fun matchingLibraries(keyword: String) = ArrayList<Pair<String, String>>().apply {
runSafely {
search(keyword) { dataList ->
dataList.map {
(it["artifactMap"] as? Map<String, List<Map<String, Any>>>)?.values?.map { e ->
e.last().run {
this["content"].toString() to this["group"].toString()
}
}
}.forEach { it?.let { addAll(it) } }
}
}
}

@Throws(java.lang.Exception::class)
inline fun <O> search(keyword: String, block: (List<Map<String, Any>>) -> O): O? = (URL(BASE_URL + "search/json?k=$keyword").openConnection() as HttpsURLConnection).run {
if (responseCode == 200) {
val json = inputStream.readBytes().toString(Charset.forName("utf-8"))
((Gson().fromJson(json, Map::class.java)["data"]) as? List<Map<String, Any>>)?.run {
block(this)
}
} else null
}

inline fun <T, R> T.runSafely(block: (T) -> R) = try {
block(this)
} catch (e: Exception) {
e.printStackTrace()
null
}

fun main() {
val libraryGroup = "androidx.recyclerview"
val libraryName = "recyclerview"
println("json: " + getAvailableVersions(libraryGroup, libraryName))
println("matchingLibraries: " + matchingLibraries("recy"))
VersionSelectorDialog.show(DefaultListModel<String>().apply {
getAvailableVersions(libraryGroup, libraryName)?.forEach {
addElement(it)
}
}) {
println(it)
}
}
Loading

0 comments on commit fa72237

Please sign in to comment.