Skip to content

Commit 75b47f3

Browse files
committed
Fix #1 and upload to our maven
1 parent 2130ed8 commit 75b47f3

File tree

5 files changed

+70
-42
lines changed

5 files changed

+70
-42
lines changed

.github/workflows/publish.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ jobs:
1212
uses: actions/setup-java@v1
1313
with:
1414
java-version: 1.8
15-
- name: Upload to Bintray
16-
run: ./gradlew bintrayUpload
15+
- name: Upload to Maven
16+
run: ./gradlew publish
1717
env:
18-
BINTRAY_USER: shedaniel
19-
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
18+
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}

build.gradle

+10-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ plugins {
55
id("maven-publish")
66
id("maven")
77
id("signing")
8-
id("com.jfrog.bintray") version("1.8.4")
98
}
109

1110
group "me.shedaniel"
@@ -24,7 +23,6 @@ tasks.test {
2423
}
2524

2625
repositories {
27-
jcenter()
2826
mavenCentral()
2927
maven {
3028
url "https://maven.fabricmc.net"
@@ -34,8 +32,7 @@ repositories {
3432
}
3533
}
3634
maven { url "https://jitpack.io" }
37-
maven { url "https://dl.bintray.com/kotlin/kotlinx/" }
38-
maven { url "https://dl.bintray.com/kotlin/kotlin-dev/" }
35+
maven { url "https://dl.bintray.com/korlibs/korlibs/" }
3936
}
4037

4138
dependencies {
@@ -80,24 +77,6 @@ task javadocsJar(type: Jar, dependsOn: javadocs) {
8077
from javadocs.destinationDir
8178
}
8279

83-
bintray {
84-
user = project.hasProperty("bintrayUser") ? project.property("bintrayUser") : System.getenv("BINTRAY_USER")
85-
key = project.hasProperty("bintrayApiKey") ? project.property("bintrayApiKey") : System.getenv("BINTRAY_KEY")
86-
publications = ["publication"]
87-
publish = true
88-
pkg {
89-
repo = "linkie"
90-
name = "linkie-core"
91-
userOrg = "shedaniel"
92-
licenses = ["GPL-3.0"]
93-
version {
94-
gpg {
95-
sign = true
96-
}
97-
}
98-
}
99-
}
100-
10180
publishing {
10281
publications {
10382
publication(MavenPublication) {
@@ -108,5 +87,14 @@ publishing {
10887
}
10988

11089
repositories {
90+
if (System.getenv("MAVEN_PASS") != null) {
91+
maven {
92+
url = "https://deploy.shedaniel.me/"
93+
credentials {
94+
username = "shedaniel"
95+
password = System.getenv("MAVEN_PASS")
96+
}
97+
}
98+
}
11199
}
112100
}

settings.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
pluginManagement {
22
repositories {
3-
jcenter()
43
mavenCentral()
54
maven { url "https://dl.bintray.com/kotlin/kotlin-dev/" }
65
gradlePluginPortal()

src/main/kotlin/me/shedaniel/linkie/utils/LinkieUtils.kt

+51-13
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,57 @@
11
package me.shedaniel.linkie.utils
22

33
import com.soywiz.korio.file.VfsFile
4-
import me.shedaniel.linkie.MappingsContainer
5-
import me.shedaniel.linkie.getClassByObfName
6-
import me.shedaniel.linkie.optimumName
74
import java.io.StringReader
85
import kotlin.math.min
96

107
fun <T> Iterable<T>.dropAndTake(drop: Int, take: Int): Sequence<T> =
118
asSequence().drop(drop).take(take)
129

13-
fun <T, R> Iterable<T>.firstMapped(filterTransform: (entry: T) -> R?): R? {
10+
inline fun <T, R> Iterable<T>.firstMapped(filterTransform: (entry: T) -> R?): R? {
1411
for (entry in this) {
1512
return filterTransform(entry) ?: continue
1613
}
1714
return null
1815
}
1916

20-
fun <T, R> Sequence<T>.firstMapped(filterTransform: (entry: T) -> R?): R? {
21-
for (entry in this) {
22-
return filterTransform(entry) ?: continue
17+
inline fun <T, R> Sequence<T>.firstMapped(filterTransform: (entry: T) -> R?): R? = asIterable().firstMapped(filterTransform)
18+
19+
inline fun <T, R : Comparable<R>> Iterable<T>.maxOfIgnoreNull(filterTransform: (entry: T) -> R?): R? {
20+
val iterator = iterator()
21+
if (!iterator.hasNext()) return null
22+
var maxValue = filterTransform(iterator.next())
23+
while (iterator.hasNext()) {
24+
val v = filterTransform(iterator.next())
25+
maxValue = when {
26+
maxValue == null -> v
27+
v == null -> maxValue
28+
else -> maxOf(maxValue, v)
29+
}
2330
}
24-
return null
31+
return maxValue
32+
}
33+
34+
inline fun <T, R : Comparable<R>> Sequence<T>.maxOfIgnoreNull(filterTransform: (entry: T) -> R?): R? = asIterable().maxOfIgnoreNull(filterTransform)
35+
36+
inline fun <T, R : Comparable<R>> Iterable<T>.maxOfIgnoreNullSelf(filterTransform: (entry: T) -> R?): T? {
37+
val iterator = iterator()
38+
if (!iterator.hasNext()) return null
39+
var max = iterator.next()
40+
var maxValue = filterTransform(max)
41+
while (iterator.hasNext()) {
42+
val next = iterator.next()
43+
val v = filterTransform(next)
44+
45+
if (v != null && (maxValue == null || v > maxValue)) {
46+
maxValue = v
47+
max = next
48+
}
49+
}
50+
return if (maxValue == null) null else max
2551
}
2652

53+
inline fun <T, R : Comparable<R>> Sequence<T>.maxOfIgnoreNullSelf(filterTransform: (entry: T) -> R?): R? = asIterable().maxOfIgnoreNull(filterTransform)
54+
2755
private fun editDistance(s11: String, s22: String): Int {
2856
val costs = IntArray(s22.length + 1)
2957
for (i in 0..s11.length) {
@@ -71,12 +99,22 @@ fun String.onlyClassOrNull(c: Char = '/'): String? {
7199
return if (indexOf < 0) null else substring(indexOf + 1)
72100
}
73101

74-
fun String?.doesContainsOrMatchWildcard(searchTerm: String): Boolean {
75-
if (this == null) return false
76-
return if (searchTerm.onlyClassOrNull() != null) {
77-
contains(searchTerm, true)
102+
fun String?.matchWithSimilarity(searchTerm: String): Double? {
103+
if (this == null) return null
104+
val searchOnlyClass = searchTerm.onlyClassOrNull()
105+
return if (searchOnlyClass != null) {
106+
if (contains(searchTerm, true)) {
107+
this.similarity(searchTerm)
108+
} else {
109+
null
110+
}
78111
} else {
79-
onlyClass().contains(searchTerm, true)
112+
val onlyClass = onlyClass()
113+
if (onlyClass.contains(searchTerm, true)) {
114+
this.similarity(searchTerm)
115+
} else {
116+
null
117+
}
80118
}
81119
}
82120

src/main/kotlin/me/shedaniel/linkie/utils/MappingsQuery.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object MappingsQuery {
6767
}
6868

6969
fun MappingsEntry.searchDefinition(classKey: String): QueryDefinition? {
70-
return QueryDefinition.allProper.firstOrNull { it(this).doesContainsOrMatchWildcard(classKey) }
70+
return QueryDefinition.allProper.maxOfIgnoreNullSelf { it(this).matchWithSimilarity(classKey) }
7171
}
7272

7373
fun MappingsEntry.searchWithDefinition(classKey: String): MatchResultWithDefinition? {
@@ -78,6 +78,10 @@ object MappingsQuery {
7878
return QueryDefinition.allProper.firstMapped { it(this).containsOrMatchWildcardOrNull(classKey) }
7979
}
8080

81+
fun MappingsEntry.searchWithSimilarity(classKey: String): Double? {
82+
return QueryDefinition.allProper.maxOfIgnoreNull { it(this).matchWithSimilarity(classKey) }
83+
}
84+
8185
suspend fun queryClasses(context: QueryContext): QueryResult<MappingsContainer, ClassResultSequence> {
8286
val searchKey = context.searchKey
8387
val isSearchKeyWildcard = searchKey == "*"
@@ -90,7 +94,7 @@ object MappingsQuery {
9094
} else {
9195
mappings.classes.values.asSequence()
9296
.map { c ->
93-
c.search(searchKey)?.let { c hold it.selfTerm.similarity(it.matchStr) }
97+
c.searchWithSimilarity(searchKey)?.let { c hold it }
9498
}
9599
.filterNotNull()
96100
}.sortedWith(compareByDescending<ResultHolder<Class>> { it.score }

0 commit comments

Comments
 (0)