-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Create module with shared utilities (#1418)
Fixes #1402 `:common` modules with shared utils created. Many files has been changed in this PR, however they are mostly import changes ## Test Plan > How do we know the code works? `:common` is available, all tests passed
- Loading branch information
1 parent
a4553ae
commit f3f2455
Showing
155 changed files
with
457 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
*.iml | ||
.idea/ | ||
build/ | ||
out/ | ||
.gradle/ | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
application | ||
kotlin(Plugins.Kotlin.PLUGIN_JVM) | ||
} | ||
|
||
tasks.test { | ||
maxHeapSize = "2048m" | ||
minHeapSize = "512m" | ||
} | ||
|
||
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "1.8" } | ||
|
||
dependencies { | ||
implementation(kotlin("stdlib", org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION)) // or "stdlib-jdk8" | ||
// Fuel | ||
api(Dependencies.Fuel.CORE) | ||
api(Dependencies.Fuel.KOTLINX_SERIALIZATION) | ||
api(Dependencies.Fuel.COROUTINES) | ||
// Archive | ||
api(Dependencies.ARCHIVE_LIB) | ||
api(Dependencies.TUKAANI_XZ) | ||
|
||
testImplementation(Dependencies.JUNIT) | ||
testImplementation(Dependencies.MOCKK) | ||
testImplementation(Dependencies.TRUTH) | ||
|
||
testImplementation(Dependencies.SYSTEM_RULES) | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
val compileKotlin: KotlinCompile by tasks | ||
compileKotlin.kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
val compileTestKotlin: KotlinCompile by tasks | ||
compileTestKotlin.kotlinOptions { | ||
jvmTarget = "1.8" | ||
} |
2 changes: 1 addition & 1 deletion
2
...ain/kotlin/flank/scripts/utils/Archive.kt → ...n/src/main/kotlin/flank.common/Archive.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package flank.common | ||
|
||
import com.github.kittinunf.fuel.Fuel | ||
import java.io.File | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.nio.file.Paths | ||
|
||
val userHome: String by lazy { | ||
if (isWindows) System.getenv("HOMEPATH") else System.getProperty("user.home") | ||
} | ||
|
||
fun createSymbolicLink( | ||
link: String, | ||
target: String | ||
) { | ||
Files.createSymbolicLink( | ||
Paths.get(link) | ||
.also { linkPath -> if (Files.isSymbolicLink(linkPath)) Files.delete(linkPath) } | ||
.toAbsolutePath().normalize(), | ||
|
||
Paths.get(target) | ||
.toAbsolutePath().normalize() | ||
) | ||
} | ||
|
||
fun createSymbolicLinkToFile(link: Path, target: Path) { | ||
Files.createSymbolicLink(link, target.fileName) | ||
} | ||
|
||
fun downloadFile(sourceUrl: String, destination: String) { | ||
Fuel.download(sourceUrl) | ||
.fileDestination { _, _ -> File(destination) } | ||
.responseString() | ||
} | ||
|
||
fun downloadFile(sourceUrl: String, destinationPath: Path) { | ||
Fuel.download(sourceUrl) | ||
.fileDestination { _, _ -> destinationPath.toFile() } | ||
.responseString() | ||
} | ||
|
||
fun createDirectoryIfNotExist(path: Path) { | ||
if (Files.notExists(path)) Files.createDirectory(path) | ||
} | ||
|
||
fun File.hasAllFiles(fileList: List<String>): Boolean { | ||
val directoryFiles = list() ?: emptyArray() | ||
return fileList.all { it in directoryFiles } | ||
} |
2 changes: 1 addition & 1 deletion
2
...rc/main/kotlin/flank/scripts/utils/Net.kt → common/src/main/kotlin/flank.common/Net.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flank.scripts.utils | ||
package flank.common | ||
|
||
import java.net.InetAddress | ||
import java.net.InetSocketAddress | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package flank.common | ||
|
||
private val osName = System.getProperty("os.name")?.toLowerCase() ?: "" | ||
|
||
val isMacOS: Boolean by lazy { | ||
val isMacOS = osName.indexOf("mac") >= 0 | ||
logLn("isMacOS = $isMacOS ($osName)") | ||
isMacOS | ||
} | ||
|
||
val isWindows: Boolean by lazy { | ||
osName.indexOf("win") >= 0 | ||
} |
2 changes: 1 addition & 1 deletion
2
...r/src/main/kotlin/ftl/log/OutputLogger.kt → .../main/kotlin/flank.common/OutputLogger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ftl.log | ||
package flank.common | ||
|
||
fun setLogLevel(logLevel: OutputLogLevel) { | ||
minimumLogLevel = logLevel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package flank.common | ||
|
||
import java.io.StringWriter | ||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
|
||
fun String.withNewLineAtTheEnd() = plus(System.lineSeparator()) | ||
|
||
fun String.normalizeLineEnding(): String { | ||
// required for tests to pass on Windows | ||
return this.replace("\r\n", "\n") | ||
} | ||
|
||
fun String.trimStartLine(): String { | ||
return this.split("\n").drop(1).joinToString("\n") | ||
} | ||
|
||
fun StringWriter.println(msg: String = "") { | ||
appendLine(msg) | ||
} | ||
|
||
fun String.write(data: String) { | ||
Files.write(Paths.get(this), data.toByteArray()) | ||
} | ||
|
||
fun join(first: String, vararg more: String): String { | ||
// Note: Paths.get(...) does not work for joining because the path separator | ||
// will be '\' on Windows which is invalid for a URI | ||
return listOf(first, *more) | ||
.joinToString("/") | ||
.replace("\\", "/") | ||
.replace(regex = Regex("/+"), replacement = "/") | ||
} |
41 changes: 23 additions & 18 deletions
41
...rc/main/kotlin/flank/scripts/utils/Zip.kt → common/src/main/kotlin/flank.common/Zip.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...t/kotlin/flank/scripts/utils/ZipKtTest.kt → ...n/src/test/kotlin/flank/common/ZipTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import kotlin.system.exitProcess | ||
|
||
// DEPS com.github.kittinunf.fuel:fuel:2.3.0 | ||
|
||
//DEPS com.github.kittinunf.fuel:fuel:2.3.0 | ||
|
||
//INCLUDE slackService.kt | ||
//INCLUDE common.kt | ||
// INCLUDE slackService.kt | ||
// INCLUDE common.kt | ||
|
||
val result = sendMessage(args) | ||
|
||
println("Message has been sent with result $result") | ||
|
||
if (result != 0){ | ||
if (result != 0) { | ||
exitProcess(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.