Skip to content

Commit

Permalink
Merge pull request #174 from tangcent/merge-easy-api
Browse files Browse the repository at this point in the history
release v1.9.2.0.183.0
  • Loading branch information
tangcent authored Apr 25, 2020
2 parents 79d8185 + 62b3956 commit 1202c09
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 35 deletions.
10 changes: 9 additions & 1 deletion IDEA_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,12 @@
* new rule tool: localStorage [(#268)](https://github.com/tangcent/easy-api/pull/268)


* 1.9.0 ~

* fix: support `java`/`kt`/`scala` in all action. [(#271)](https://github.com/tangcent/easy-api/pull/271

* support new method 'method/declaration' of 'arg' [(#273)](https://github.com/tangcent/easy-api/pull/273)

* opti: support rule `folder.name` [(#274)](https://github.com/tangcent/easy-api/pull/274

* support new rule `path.multi` [(#275)](https://github.com/tangcent/easy-api/pull/275)
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group 'com.itangcent'
version '1.9.1.0.183.0'
version '1.9.2.0.183.0'
13 changes: 13 additions & 0 deletions common-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ dependencies {
// https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
compileOnly group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.10'

testCompile group: 'junit', name: 'junit', version: '4.12'

// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.2'

// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.6.2'

}


test {
useJUnitPlatform()
}

compileKotlin {
Expand Down
97 changes: 75 additions & 22 deletions common-api/src/main/kotlin/com/itangcent/common/model/URL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,58 @@ package com.itangcent.common.model

import com.itangcent.common.utils.notNullOrEmpty
import com.itangcent.http.RequestUtils
import java.util.*

/**
* Represents a url path.
*/
interface URL {

/**
* One url in [URL]
*/
fun url(): String?

/**
* All url in [URL] as list.
*/
fun urls(): List<String>

/**
* Return true if only one url be contained at this [URL].
*/
fun single(): Boolean

fun contract(url: URL): URL
/**
* Concat the special url to this url.
*
* {""} concat {/b} ==> {/b}
* {"/a"} concat {"/b"} ==> {"/a/b"}
*/
fun concat(url: URL): URL

/**
* Union the special url
* {""} union {"/b"} ==> {"","/b"}
* {"/a"} union {"/b"} ==> {"/a","/b"}
*/
fun union(url: URL): URL

/**
* Returns a new [URL] of applying the given [transform] function
* to each url.
*
* @param transform function to transform url.
*/
fun map(transform: (String) -> String?): URL

/**
* Returns a new [URL] of applying the given [transform] function
* to each url.
*
* @param transform function to transform url.
*/
fun map(transform: (String?) -> String?): URL
fun flatMap(transform: (String) -> URL?): URL

companion object {
private val NULL_URL: NullURL = NullURL()
Expand Down Expand Up @@ -73,12 +106,20 @@ private class NullURL : URL {
return true
}

override fun contract(url: URL): URL {
override fun concat(url: URL): URL {
return url
}

override fun map(transform: (String?) -> String?): URL {
return URL.of(transform(null))
override fun union(url: URL): URL {
return url
}

override fun map(transform: (String) -> String?): URL {
return URL.of(transform(""))
}

override fun flatMap(transform: (String) -> URL?): URL {
return transform("") ?: URL.nil()
}

override fun toString(): String {
Expand All @@ -103,18 +144,25 @@ private class SingleURL(private val url: String) : URL {
return true
}

override fun contract(url: URL): URL {
return when {
url == URL.nil() -> this
url.single() -> URL.of(RequestUtils.contractPath(this.url, url.url()))
else -> URL.of(url.urls().mapNotNull { RequestUtils.contractPath(this.url, it) })
}
override fun concat(url: URL): URL {
return url.map { RequestUtils.contractPath(this.url, it) }
}

override fun union(url: URL): URL {
val urls = LinkedList<String>()
urls.add(this.url)
urls.addAll(url.urls())
return URL.of(urls)
}

override fun map(transform: (String?) -> String?): URL {
override fun map(transform: (String) -> String?): URL {
return URL.of(transform(this.url))
}

override fun flatMap(transform: (String) -> URL?): URL {
return transform(url) ?: URL.nil()
}

override fun toString(): String {
return url
}
Expand All @@ -137,18 +185,23 @@ private class MultiURL(private val urls: List<String>) : URL {
return false
}

override fun contract(url: URL): URL {
return when {
url == URL.nil() -> this
url.single() -> URL.of(this.urls().mapNotNull { RequestUtils.contractPath(it, url.url()) })
else -> URL.of(this.urls().flatMap { prefixPath ->
url.urls().mapNotNull { RequestUtils.contractPath(prefixPath, it) }
})
}
override fun concat(url: URL): URL {
return this.flatMap { URL.of(it).concat(url) }
}

override fun map(transform: (String) -> String?): URL {
return URL.of(this.urls().mapNotNull(transform))
}

override fun flatMap(transform: (String) -> URL?): URL {
return this.urls.mapNotNull(transform).reduce { a, b -> a.union(b) }
}

override fun map(transform: (String?) -> String?): URL {
return URL.of(this.urls().mapNotNull { transform(it) })
override fun union(url: URL): URL {
val urls = LinkedList<String>()
urls.addAll(this.urls)
urls.addAll(url.urls())
return URL.of(urls)
}

override fun toString(): String {
Expand Down
4 changes: 2 additions & 2 deletions common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ object RequestUtils {
}

fun contractPath(pathPre: String?, pathAfter: String?): String? {
if (pathPre == null) return pathAfter
if (pathAfter == null) return pathPre
if (pathPre.isNullOrBlank()) return pathAfter
if (pathAfter.isNullOrBlank()) return pathPre
return pathPre.removeSuffix("/") + "/" + pathAfter.removePrefix("/")
}

Expand Down
34 changes: 34 additions & 0 deletions common-api/src/test/kotlin/com/itangcent/test/URLTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.itangcent.test

import com.itangcent.common.model.URL
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class URLTest {

@Test
fun testURLConcatAndUnion() {
val nil = URL.of()
val url1 = URL.of("/a")
val url2 = URL.of("/b")
val url3 = URL.of("/c", "/d")
assertEquals("/a", nil.concat(url1).toString())
assertEquals("/a/b", url1.concat(url2).toString())
assertEquals("/b/c,/b/d", url2.concat(url3).toString())
assertEquals("/a", nil.union(url1).toString())
assertEquals("/a,/b", url1.union(url2).toString())
assertEquals("/b,/c,/d", url2.union(url3).toString())
}

@Test
fun testURLMap() {
val nil = URL.of()
val url1 = URL.of("/a")
val url2 = URL.of("/b")
val url3 = URL.of("/c", "/d")
assertEquals("/x", nil.map { "$it/x" }.toString())
assertEquals("/a/x", url1.map { "$it/x" }.toString())
assertEquals("/b/x", url2.map { "$it/x" }.toString())
assertEquals("/c/x,/d/x", url3.map { "$it/x" }.toString())
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.daemon=true
org.gradle.workers.max=8
idea_version=2017.3.5
plugin_name=EasyYapi
plugin_version=1.9.1.0.183.0
plugin_version=1.9.2.0.183.0

descriptionFile=parts/pluginDescription.html
changesFile=parts/pluginChanges.html
18 changes: 13 additions & 5 deletions idea-plugin/parts/pluginChanges.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<a href="https://github.com/tangcent/easy-yapi/releases/tag/v1.9.1.0">v1.9.1.0.183.0(2020-03-31)</a>
<a href="https://github.com/tangcent/easy-yapi/releases/tag/v1.9.2.0">v1.9.2.0.183.0(2020-04-25)</a>
<br/>
<a href="https://github.com/tangcent/easy-yapi/blob/master/IDEA_CHANGELOG.md">Full Changelog</a>
<ul>bug-fix:
<li>fix HttpRequest querys<a
href="https://github.com/tangcent/easy-api/pull/267">(#267)</a>
<li>fix HttpRequfix: support `java`/`kt`/`scala` in all action<a
href="https://github.com/tangcent/easy-api/pull/271">(#271)</a>
</li>
</ul>
<ul>enhancement:
<li>new rule tool: localStorage<a
href="https://github.com/tangcent/easy-api/pull/268">(#268)</a>
<li>support new method 'method/declaration' of 'arg' <a
href="https://github.com/tangcent/easy-api/pull/273">(#273)</a>
</li>

<li>opti: support rule `folder.name` <a
href="https://github.com/tangcent/easy-api/pull/274">(#274)</a>
</li>

<li>opti: support new rule `path.multi` <a
href="https://github.com/tangcent/easy-api/pull/275">(#275)</a>
</li>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() {
var basePath: URL = findHttpPath(ctrlRequestMappingAnn)
val prefixPath = ruleComputer!!.computer(ClassExportRuleKeys.CLASS_PREFIX_PATH, cls)
if (prefixPath.notNullOrBlank()) {
basePath = URL.of(prefixPath).contract(basePath)
basePath = URL.of(prefixPath).concat(basePath)
}

val ctrlHttpMethod = findHttpMethod(ctrlRequestMappingAnn)
Expand Down Expand Up @@ -190,7 +190,7 @@ open class SpringRequestClassExporter : AbstractRequestClassExporter() {
}
request.method = httpMethod

val httpPath = basePath.contract(findHttpPath(requestMapping))
val httpPath = basePath.concat(findHttpPath(requestMapping))
requestHelper!!.setPath(request, httpPath)
}

Expand Down
2 changes: 1 addition & 1 deletion idea-plugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>com.itangcent.idea.plugin.easy-yapi</id>
<name>EasyYapi</name>
<version>1.9.1.0.183.0</version>
<version>1.9.2.0.183.0</version>
<vendor email="[email protected]" url="https://github.com/tangcent">Tangcent</vendor>

<description><![CDATA[ Description will be added by gradle build]]></description>
Expand Down

0 comments on commit 1202c09

Please sign in to comment.