split up app/lib
This commit is contained in:
parent
d90fe5a7c8
commit
b2316b0029
11 changed files with 477 additions and 152 deletions
|
@ -1,17 +1,20 @@
|
|||
import buildsrc.utils.Rife2TestListener
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
import org.jetbrains.dokka.gradle.DokkaTask
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
|
||||
plugins {
|
||||
buildsrc.conventions.lang.`kotlin-jvm`
|
||||
buildsrc.conventions.publishing
|
||||
id("application")
|
||||
id("com.github.ben-manes.versions")
|
||||
}
|
||||
|
||||
description = "A simple defensive library to encode/decode URL components"
|
||||
|
||||
val deployDir = project.layout.projectDirectory.dir("deploy")
|
||||
val urlEncoderMainClass = "net.thauvin.erik.urlencoder.UrlEncoder"
|
||||
val mainClassName = "net.thauvin.erik.urlencoder.UrlEncoder"
|
||||
|
||||
dependencies {
|
||||
// testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
|
||||
|
@ -22,37 +25,37 @@ base {
|
|||
archivesName.set(rootProject.name)
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set(urlEncoderMainClass)
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
tasks {
|
||||
jar {
|
||||
manifest {
|
||||
attributes["Main-Class"] = urlEncoderMainClass
|
||||
withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions.jvmTarget = java.targetCompatibility.toString()
|
||||
}
|
||||
|
||||
test {
|
||||
addTestListener(Rife2TestListener(project.properties["testsBadgeApiKey"]?.toString()))
|
||||
}
|
||||
|
||||
withType<Test>().configureEach {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
|
||||
}
|
||||
}
|
||||
|
||||
val fatJar by registering(Jar::class) {
|
||||
group = LifecycleBasePlugin.BUILD_GROUP
|
||||
dependsOn.addAll(listOf("compileJava", "compileKotlin", "processResources"))
|
||||
archiveClassifier.set("all")
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
manifest { attributes(mapOf("Main-Class" to application.mainClass)) }
|
||||
val sourcesMain = sourceSets.main.get()
|
||||
val contents = configurations.runtimeClasspath.get()
|
||||
.map { if (it.isDirectory) it else zipTree(it) } + sourcesMain.output
|
||||
from(contents)
|
||||
}
|
||||
|
||||
build {
|
||||
dependsOn(fatJar)
|
||||
}
|
||||
|
||||
withType<GenerateMavenPom>().configureEach {
|
||||
destination = file("$projectDir/pom.xml")
|
||||
}
|
||||
|
||||
clean {
|
||||
delete(deployDir)
|
||||
}
|
||||
|
||||
withType<DokkaTask>().configureEach {
|
||||
dokkaSourceSets {
|
||||
named("main") {
|
||||
|
@ -77,8 +80,8 @@ tasks {
|
|||
dependsOn(build, copyToDeploy)
|
||||
}
|
||||
|
||||
clean {
|
||||
delete(deployDir)
|
||||
"sonar" {
|
||||
dependsOn(koverReport)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +89,7 @@ publishing {
|
|||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
from(components["java"])
|
||||
artifactId = rootProject.name
|
||||
artifactId = "${rootProject.name}-lib"
|
||||
artifact(tasks.javadocJar)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues/>
|
||||
<CurrentIssues>
|
||||
<ID>ComplexCondition:UrlEncoder.kt$UrlEncoder$hasOption && args.size == 2 || !hasOption && args.size == 1</ID>
|
||||
<ID>MagicNumber:UrlEncoder.kt$UrlEncoder$0x80</ID>
|
||||
<ID>MagicNumber:UrlEncoder.kt$UrlEncoder$0xFF</ID>
|
||||
<ID>MagicNumber:UrlEncoder.kt$UrlEncoder$16</ID>
|
||||
<ID>MagicNumber:UrlEncoder.kt$UrlEncoder$3</ID>
|
||||
<ID>MagicNumber:UrlEncoder.kt$UrlEncoder$4</ID>
|
||||
<ID>MaxLineLength:UrlEncoder.kt$UrlEncoder$*</ID>
|
||||
<ID>NestedBlockDepth:UrlEncoder.kt$UrlEncoder$@JvmStatic @JvmOverloads fun decode(source: String, plusToSpace: Boolean = false): String</ID>
|
||||
<ID>NestedBlockDepth:UrlEncoder.kt$UrlEncoder$@JvmStatic @JvmOverloads fun encode(source: String, allow: String = "", spaceToPlus: Boolean = false): String</ID>
|
||||
<ID>MagicNumber:UrlEncoderUtil.kt$UrlEncoderUtil$0x80</ID>
|
||||
<ID>MagicNumber:UrlEncoderUtil.kt$UrlEncoderUtil$0xFF</ID>
|
||||
<ID>MagicNumber:UrlEncoderUtil.kt$UrlEncoderUtil$16</ID>
|
||||
<ID>MagicNumber:UrlEncoderUtil.kt$UrlEncoderUtil$3</ID>
|
||||
<ID>MagicNumber:UrlEncoderUtil.kt$UrlEncoderUtil$4</ID>
|
||||
<ID>MaxLineLength:UrlEncoderUtil.kt$UrlEncoderUtil$*</ID>
|
||||
<ID>NestedBlockDepth:UrlEncoderUtil.kt$UrlEncoderUtil$@JvmStatic @JvmOverloads fun decode(source: String, plusToSpace: Boolean = false): String</ID>
|
||||
<ID>NestedBlockDepth:UrlEncoderUtil.kt$UrlEncoderUtil$@JvmStatic @JvmOverloads fun encode(source: String, allow: String = "", spaceToPlus: Boolean = false): String</ID>
|
||||
</CurrentIssues>
|
||||
</SmellBaseline>
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
<!-- that they should prefer consuming it instead. -->
|
||||
<!-- do_not_remove: published-with-gradle-metadata -->
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.thauvin.erik</groupId>
|
||||
<artifactId>urlencoder</artifactId>
|
||||
<version>1.3.1-SNAPSHOT</version>
|
||||
<groupId>urlencoder</groupId>
|
||||
<artifactId>urlencoder-lib</artifactId>
|
||||
<version>unspecified</version>
|
||||
<name>UrlEncoder for Kotlin</name>
|
||||
<description>A simple defensive library to encode/decode URL components</description>
|
||||
<url>https://github.com/ethauvin/urlencoder</url>
|
||||
|
|
|
@ -19,7 +19,6 @@ package net.thauvin.erik.urlencoder
|
|||
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.BitSet
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
* Most defensive approach to URL encoding and decoding.
|
||||
|
@ -37,13 +36,8 @@ import kotlin.system.exitProcess
|
|||
* @author Geert Bevin (gbevin(remove) at uwyn dot com)
|
||||
* @author Erik C. Thauvin (erik@thauvin.net)
|
||||
**/
|
||||
object UrlEncoder {
|
||||
object UrlEncoderUtil {
|
||||
private val hexDigits = "0123456789ABCDEF".toCharArray()
|
||||
internal val usage =
|
||||
"Usage : java -jar urlencoder-*all.jar [-ed] text" + System.lineSeparator() +
|
||||
"Encode and decode URL components defensively." + System.lineSeparator() +
|
||||
" -e encode (default) " + System.lineSeparator() +
|
||||
" -d decode"
|
||||
|
||||
// see https://www.rfc-editor.org/rfc/rfc3986#page-13
|
||||
// and https://url.spec.whatwg.org/#application-x-www-form-urlencoded-percent-encode-set
|
||||
|
@ -196,45 +190,4 @@ object UrlEncoder {
|
|||
|
||||
return out?.toString() ?: source
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes and decodes URLs from the command line.
|
||||
*
|
||||
* - `java -jar urlencoder-*all.jar [-ed] text`
|
||||
*/
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
try {
|
||||
val result = processMain(args)
|
||||
if (result.status == 1) {
|
||||
System.err.println(result.output)
|
||||
} else {
|
||||
println(result.output)
|
||||
}
|
||||
exitProcess(result.status)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
System.err.println("${UrlEncoder::class.java.simpleName}: ${e.message}")
|
||||
exitProcess(1)
|
||||
}
|
||||
}
|
||||
|
||||
internal data class MainResult(var output: String = usage, var status: Int = 1)
|
||||
|
||||
internal fun processMain(args: Array<String>): MainResult {
|
||||
val result = MainResult()
|
||||
if (args.isNotEmpty() && args[0].isNotEmpty()) {
|
||||
val hasDecode = (args[0] == "-d")
|
||||
val hasOption = (hasDecode || args[0] == "-e")
|
||||
if (hasOption && args.size == 2 || !hasOption && args.size == 1) {
|
||||
val arg = if (hasOption) args[1] else args[0]
|
||||
if (hasDecode) {
|
||||
result.output = decode(arg)
|
||||
} else {
|
||||
result.output = encode(arg)
|
||||
}
|
||||
result.status = 0
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
|
@ -17,10 +17,8 @@
|
|||
|
||||
package net.thauvin.erik.urlencoder
|
||||
|
||||
import net.thauvin.erik.urlencoder.UrlEncoder.decode
|
||||
import net.thauvin.erik.urlencoder.UrlEncoder.encode
|
||||
import net.thauvin.erik.urlencoder.UrlEncoder.processMain
|
||||
import net.thauvin.erik.urlencoder.UrlEncoder.usage
|
||||
import net.thauvin.erik.urlencoder.UrlEncoderUtil.decode
|
||||
import net.thauvin.erik.urlencoder.UrlEncoderUtil.encode
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertSame
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
|
@ -30,10 +28,9 @@ import org.junit.jupiter.params.ParameterizedTest
|
|||
import org.junit.jupiter.params.provider.Arguments
|
||||
import org.junit.jupiter.params.provider.Arguments.arguments
|
||||
import org.junit.jupiter.params.provider.MethodSource
|
||||
import org.junit.jupiter.params.provider.ValueSource
|
||||
import java.util.stream.Stream
|
||||
|
||||
class UrlEncoderTest {
|
||||
class UrlEncoderUtilTest {
|
||||
private val same = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVQXYZ0123456789-_."
|
||||
|
||||
companion object {
|
||||
|
@ -114,58 +111,4 @@ class UrlEncoderTest {
|
|||
assertEquals("foo+bar++foo", encode("foo bar foo", spaceToPlus = true))
|
||||
assertEquals("foo bar", encode("foo bar", " ", true))
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "processMain(-d {1}) should be {0}")
|
||||
@MethodSource("validMap")
|
||||
fun `Main Decode`(expected: String, source: String) {
|
||||
val result: UrlEncoder.MainResult = processMain(arrayOf("-d", source))
|
||||
assertEquals(expected, result.output)
|
||||
assertEquals(0, result.status, "processMain(-d $source).status")
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "processMain(-d {0})")
|
||||
@MethodSource("invalid")
|
||||
fun `Main Decode with Exception`(source: String) {
|
||||
assertThrows(IllegalArgumentException::class.java, { processMain(arrayOf("-d", source)) }, source)
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "processMain(-e {0})")
|
||||
@MethodSource("validMap")
|
||||
fun `Main Encode`(source: String, expected: String) {
|
||||
val result = processMain(arrayOf(source))
|
||||
assertEquals(expected, result.output)
|
||||
assertEquals(0, result.status, "processMain(-e $source).status")
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "processMain(-e {0})")
|
||||
@MethodSource("validMap")
|
||||
fun `Main Encode with Option`(source: String, expected: String) {
|
||||
val result = processMain(arrayOf("-e", source))
|
||||
assertEquals(expected, result.output)
|
||||
assertEquals(0, result.status, "processMain(-e $source).status")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `Main Usage with Empty Args`() {
|
||||
assertEquals(usage, processMain(arrayOf(" ", " ")).output, "processMain(' ', ' ')")
|
||||
assertEquals(usage, processMain(arrayOf("foo", " ")).output, "processMain('foo', ' ')")
|
||||
assertEquals(usage, processMain(arrayOf(" ", "foo")).output, "processMain(' ', 'foo')")
|
||||
assertEquals(usage, processMain(arrayOf("-d ", "")).output, "processMain('-d', '')")
|
||||
assertEquals("%20", processMain(arrayOf("-e", " ")).output, "processMain('-e', ' ')")
|
||||
assertEquals(" ", processMain(arrayOf("-d", " ")).output, "processMain('-d', ' ')")
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = ["", "-d", "-e"])
|
||||
fun `Main Usage with Invalid arg`(arg: String) {
|
||||
val result = processMain(arrayOf(arg))
|
||||
assertEquals(usage, result.output, "processMain('$arg')")
|
||||
assertEquals(1, result.status, "processMain('$arg').status")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Main Usage with too Many Args`() {
|
||||
assertEquals(usage, processMain(arrayOf("foo", "bar", "test")).output, "too many args")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue