Skip to content

Commit 7fd19a7

Browse files
committed
convert to kotlin multiplatform
1 parent e520ee2 commit 7fd19a7

File tree

77 files changed

+3688
-4343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3688
-4343
lines changed

build.gradle.kts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import org.apache.tools.ant.taskdefs.condition.Os
2+
3+
group = "app.teamhub"
4+
version = "4.1-SNAPSHOT"
5+
6+
plugins {
7+
`maven-publish`
8+
kotlin("multiplatform") version "1.3.21"
9+
}
10+
11+
repositories {
12+
mavenLocal()
13+
google()
14+
jcenter()
15+
maven(url = "https://dl.bintray.com/kotlin/kotlin-dev")
16+
}
17+
18+
kotlin {
19+
jvm {
20+
val main by compilations.getting {
21+
kotlinOptions {
22+
jvmTarget ="1.8"
23+
}
24+
}
25+
}
26+
27+
js {
28+
val main by compilations.getting {
29+
kotlinOptions {
30+
sourceMap = true
31+
sourceMapEmbedSources = "always"
32+
moduleKind = "commonjs"
33+
}
34+
}
35+
}
36+
37+
sourceSets {
38+
val commonMain by getting {
39+
dependencies {
40+
implementation("org.jetbrains.kotlin:kotlin-stdlib")
41+
}
42+
}
43+
val jsMain by getting {
44+
dependencies {
45+
implementation("org.jetbrains.kotlin:kotlin-stdlib-js")
46+
}
47+
}
48+
val jvmMain by getting {
49+
dependencies {
50+
implementation(kotlin("stdlib-jdk8"))
51+
}
52+
}
53+
}
54+
}
55+
56+
57+
tasks {
58+
val copyPackageJson by registering(Copy::class) {
59+
from(file("package.json"))
60+
into(file("$buildDir/node_module"))
61+
}
62+
63+
val copyJS by registering(Copy::class) {
64+
from(file("$buildDir/classes/kotlin/js/main/${project.name}.js"))
65+
into(file("$buildDir/node_module"))
66+
rename("${project.name}\\.js", "index.js")
67+
}
68+
69+
val copySourceMap by registering(Copy::class) {
70+
from(file("$buildDir/classes/kotlin/js/main/${project.name}.js.map"))
71+
into(file("$buildDir/node_module"))
72+
rename("${project.name}\\.js.map", "index.js.map")
73+
}
74+
75+
val publishToNpm by registering(Exec::class) {
76+
dependsOn(copyPackageJson, copyJS, copySourceMap)
77+
workingDir("$buildDir/node_module")
78+
if(Os.isFamily(Os.FAMILY_WINDOWS)) {
79+
commandLine("cmd", "/c", "npm unpublish --force --registry http://localhost:4873 kotlin-diff-utils & npm publish --registry http://localhost:4873")
80+
} else {
81+
commandLine("npm", "unpublish", "--force", "--registry http://localhost:4873", "kotlin-diff-utils")
82+
commandLine("npm", "publish", "--registry http://localhost:4873")
83+
}
84+
}
85+
}

gradle/wrapper/gradle-wrapper.jar

53.1 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Thu Apr 04 11:29:41 BST 2019
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip

java-diff-utils.iml

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "firebase-multiplatform",
3+
"version": "17.1.0-rev2",
4+
"description": "Wrapper around firebase for usage in Kotlin Multiplatform projects",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/multiplatform-io/firebase.git"
12+
},
13+
"keywords": [
14+
"kotlin",
15+
"mutliplatform",
16+
"kotlin-js",
17+
"firebase",
18+
"firestore"
19+
],
20+
"author": "multiplatform.io",
21+
"license": "MIT",
22+
"bugs": {
23+
"url": "https://github.com/multiplatform-io/firebase/issues"
24+
},
25+
"homepage": "https://github.com/multiplatform-io/firebase",
26+
"dependencies": {
27+
"firebase": "^6.1.1",
28+
"kotlin": "1.3.31",
29+
"kotlinx-coroutines-core": "1.2.1"
30+
}
31+
}
32+

pom.xml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
<properties>
6666
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
67+
<kotlin.version>1.3.21</kotlin.version>
6768
</properties>
6869

6970
<dependencies>
@@ -111,6 +112,17 @@
111112
<version>3.11.1</version>
112113
<scope>test</scope>
113114
</dependency>
115+
<dependency>
116+
<groupId>org.jetbrains.kotlin</groupId>
117+
<artifactId>kotlin-stdlib-jdk8</artifactId>
118+
<version>${kotlin.version}</version>
119+
</dependency>
120+
<dependency>
121+
<groupId>org.jetbrains.kotlin</groupId>
122+
<artifactId>kotlin-test</artifactId>
123+
<version>${kotlin.version}</version>
124+
<scope>test</scope>
125+
</dependency>
114126
</dependencies>
115127

116128
<build>
@@ -253,6 +265,30 @@
253265
</dependency>
254266
</dependencies>
255267
</plugin>
268+
<plugin>
269+
<groupId>org.jetbrains.kotlin</groupId>
270+
<artifactId>kotlin-maven-plugin</artifactId>
271+
<version>${kotlin.version}</version>
272+
<executions>
273+
<execution>
274+
<id>compile</id>
275+
<phase>compile</phase>
276+
<goals>
277+
<goal>compile</goal>
278+
</goals>
279+
</execution>
280+
<execution>
281+
<id>test-compile</id>
282+
<phase>test-compile</phase>
283+
<goals>
284+
<goal>test-compile</goal>
285+
</goals>
286+
</execution>
287+
</executions>
288+
<configuration>
289+
<jvmTarget>1.8</jvmTarget>
290+
</configuration>
291+
</plugin>
256292
</plugins>
257293
</build>
258294
<profiles>

settings.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
enableFeaturePreview("GRADLE_METADATA")
2+
3+
pluginManagement {
4+
repositories {
5+
gradlePluginPortal()
6+
jcenter()
7+
google()
8+
}
9+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* Copyright 2009-2017 java-diff-utils.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.github.difflib
17+
18+
import com.github.difflib.algorithm.DiffAlgorithmI
19+
import com.github.difflib.algorithm.DiffAlgorithmListener
20+
import com.github.difflib.algorithm.DiffException
21+
import com.github.difflib.algorithm.myers.MyersDiff
22+
import com.github.difflib.patch.AbstractDelta
23+
import com.github.difflib.patch.Patch
24+
import com.github.difflib.patch.PatchFailedException
25+
26+
internal typealias Predicate<T> = (T) -> Boolean
27+
internal typealias BiPredicate<T,R> = (T, R) -> Boolean
28+
internal typealias Consumer<T> = (T) -> Unit
29+
internal typealias Function<T,R> = (T) -> R
30+
31+
/**
32+
* Implements the difference and patching engine
33+
*
34+
* @author [Dmitry Naumenko]([email protected])
35+
*/
36+
object DiffUtils {
37+
38+
/**
39+
* Computes the difference between the original and revised list of elements with default diff algorithm
40+
*
41+
* @param original The original text. Must not be `null`.
42+
* @param revised The revised text. Must not be `null`.
43+
* @param progress progress listener
44+
* @return The patch describing the difference between the original and revised sequences. Never `null`.
45+
* @throws com.github.difflib.algorithm.DiffException
46+
*/
47+
// @Throws(DiffException::class)
48+
fun <T> diff(original: List<T>, revised: List<T>, progress: DiffAlgorithmListener): Patch<T> {
49+
return DiffUtils.diff(original, revised, MyersDiff(), progress)
50+
}
51+
52+
// @Throws(DiffException::class)
53+
fun <T> diff(original: List<T>, revised: List<T>): Patch<T> {
54+
return DiffUtils.diff(original, revised, MyersDiff(), null)
55+
}
56+
57+
/**
58+
* Computes the difference between the original and revised text.
59+
*/
60+
// @Throws(DiffException::class)
61+
fun diff(sourceText: String, targetText: String,
62+
progress: DiffAlgorithmListener): Patch<String> {
63+
return DiffUtils.diff(
64+
sourceText.split("\n".toRegex()).dropLastWhile { it.isEmpty() },
65+
targetText.split("\n".toRegex()).dropLastWhile { it.isEmpty() }, progress)
66+
}
67+
68+
/**
69+
* Computes the difference between the original and revised list of elements with default diff algorithm
70+
*
71+
* @param source The original text. Must not be `null`.
72+
* @param target The revised text. Must not be `null`.
73+
*
74+
* @param equalizer the equalizer object to replace the default compare algorithm (Object.equals). If `null`
75+
* the default equalizer of the default algorithm is used..
76+
* @return The patch describing the difference between the original and revised sequences. Never `null`.
77+
*/
78+
// @Throws(DiffException::class)
79+
fun <T> diff(source: List<T>, target: List<T>,
80+
equalizer: BiPredicate<T, T>?): Patch<T> {
81+
return if (equalizer != null) {
82+
DiffUtils.diff(source, target,
83+
MyersDiff(equalizer))
84+
} else DiffUtils.diff(source, target, MyersDiff())
85+
}
86+
87+
/**
88+
* Computes the difference between the original and revised list of elements with default diff algorithm
89+
*
90+
* @param original The original text. Must not be `null`.
91+
* @param revised The revised text. Must not be `null`.
92+
* @param algorithm The diff algorithm. Must not be `null`.
93+
* @param progress The diff algorithm listener.
94+
* @return The patch describing the difference between the original and revised sequences. Never `null`.
95+
*/
96+
// @Throws(DiffException::class)
97+
fun <T> diff(original: List<T>, revised: List<T>,
98+
algorithm: DiffAlgorithmI<T>, progress: DiffAlgorithmListener?): Patch<T> {
99+
return Patch.generate(original, revised, algorithm.computeDiff(original, revised, progress))
100+
}
101+
102+
/**
103+
* Computes the difference between the original and revised list of elements with default diff algorithm
104+
*
105+
* @param original The original text. Must not be `null`.
106+
* @param revised The revised text. Must not be `null`.
107+
* @param algorithm The diff algorithm. Must not be `null`.
108+
* @return The patch describing the difference between the original and revised sequences. Never `null`.
109+
*/
110+
// @Throws(DiffException::class)
111+
fun <T> diff(original: List<T>, revised: List<T>,
112+
algorithm: DiffAlgorithmI<T>): Patch<T> {
113+
return diff(original, revised, algorithm, null)
114+
}
115+
116+
/**
117+
* Computes the difference between the given texts inline. This one uses the "trick" to make out of texts lists of
118+
* characters, like DiffRowGenerator does and merges those changes at the end together again.
119+
*
120+
* @param original
121+
* @param revised
122+
* @return
123+
*/
124+
// @Throws(DiffException::class)
125+
fun diffInline(original: String, revised: String): Patch<String> {
126+
val origList = ArrayList<String>()
127+
val revList = ArrayList<String>()
128+
for (character in original) {
129+
origList.add(character.toString())
130+
}
131+
for (character in revised) {
132+
revList.add(character.toString())
133+
}
134+
val patch = DiffUtils.diff(origList, revList)
135+
for (delta in patch.deltas) {
136+
delta.source.lines = compressLines(delta.source.lines!!, "")
137+
delta.target.lines = compressLines(delta.target.lines!!, "")
138+
}
139+
return patch
140+
}
141+
142+
private fun compressLines(lines: List<String>, delimiter: String): List<String> {
143+
return if (lines.isEmpty()) {
144+
emptyList<String>()
145+
} else listOf<String>(lines.joinToString(delimiter))
146+
}
147+
148+
/**
149+
* Patch the original text with given patch
150+
*
151+
* @param original the original text
152+
* @param patch the given patch
153+
* @return the revised text
154+
* @throws PatchFailedException if can't apply patch
155+
*/
156+
// @Throws(PatchFailedException::class)
157+
fun <T> patch(original: List<T>, patch: Patch<T>): List<T> {
158+
return patch.applyTo(original)
159+
}
160+
161+
/**
162+
* Unpatch the revised text for a given patch
163+
*
164+
* @param revised the revised text
165+
* @param patch the given patch
166+
* @return the original text
167+
*/
168+
fun <T> unpatch(revised: List<T>, patch: Patch<T>): List<T> {
169+
return patch.restore(revised)
170+
}
171+
}

0 commit comments

Comments
 (0)