Skip to content

Commit

Permalink
KoDI
Browse files Browse the repository at this point in the history
  • Loading branch information
Revolucent committed Sep 19, 2021
1 parent b3ee002 commit 826f1fd
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 65 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 1 addition & 61 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,64 +41,4 @@ dependencies {

// This dependency is exported to consumers, that is to say found on their compile classpath.
api("org.apache.commons:commons-math3:3.6.1")
}

// Library Publishing
val sourcesJar by tasks.creating(Jar::class) {
from(sourceSets["main"].java.srcDirs)
archiveClassifier.set("sources")
}

/*
val doc by tasks.creating(Javadoc::class) {
source = sourceSets["main"].allSource
}
val javadocJar by tasks.creating(Jar::class) {
dependsOn(doc)
from(doc)
archiveClassifier.set("javadoc")
}
*/

artifacts {
// archives(tasks.getByName("javadocJar"))
archives(tasks.getByName("sourcesJar"))
}

publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/prosumma/KoDI")
credentials {
username = System.getenv("GITHUB_USER")
password = System.getenv("GITHUB_TOKEN")
}
}
}
publications {
create<MavenPublication>("main") {
groupId = project.group.toString()
artifactId = "KoDI"
version = "0.1.0"
artifact(sourcesJar)
// artifact(javadocJar)
// artifact("$buildDir/outputs/aar/${artifactId}-release.aar")
pom.withXml {
val dependencies = asNode().appendNode("dependencies")
configurations.getByName("implementation").dependencies.forEach {
if (it.group != null &&
it.name != "unspecified" &&
it.version != null
) {
val dependencyNode = dependencies.appendNode("dependency")
dependencyNode.appendNode("groupId", it.group)
dependencyNode.appendNode("artifactId", it.name)
dependencyNode.appendNode("version", it.version)
}
}
}
}
}
}
}
7 changes: 6 additions & 1 deletion lib/src/main/kotlin/com/prosumma/di/Params.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package com.prosumma.di
/**
* Class used to pass params.
*/
class Params(vararg params: Any) {
class Params(vararg params: Any?) {
private val parameters = params

@Suppress("UNCHECKED_CAST")
operator fun <T> get(index: Int): T = parameters[index] as T

fun <T> getOrNull(index: Int): T? =
if (index < parameters.size)
this[index]
else null

operator fun <T> component1(): T = this[0]
operator fun <T> component2(): T = this[1]
operator fun <T> component3(): T = this[2]
Expand Down
2 changes: 1 addition & 1 deletion lib/src/test/kotlin/com/prosumma/di/AssemblyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AssemblyTest {
}

@Test
fun `assembly is registered only once`() {
fun `assembly is registered only once by type`() {
val container = DIContainer()
val assembly1 = ServiceAssembly()
val assembly2 = ServiceAssembly()
Expand Down
10 changes: 9 additions & 1 deletion lib/src/test/kotlin/com/prosumma/di/ParamsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import kotlin.test.assertNull
import kotlin.test.assertTrue

class ParamsTest {
@Test
fun `parameter destructuring`() {
val s: String? = null
val params = Params(7, "something", 4.3, true, s as Any)
val params = Params(7, "something", 4.3, true, s)
val (i: Int, s2: String, f: Double, b: Boolean, q: String?) = params
assertEquals(i, 7)
assertEquals(s2, "something")
Expand All @@ -17,6 +18,13 @@ class ParamsTest {
assertNull(q)
}

@Test
fun getOrNull() {
val params = Params(3)
assertNull(params.getOrNull(1) as String?)
}

@Test
fun `type coercion`() {
fun coerce(s: String) = s
val params = Params("something")
Expand Down
1 change: 0 additions & 1 deletion lib/src/test/kotlin/com/prosumma/di/ResolverTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import kotlin.test.*
class ResolverTest {
class Service
class SuperService(val service: Service)

class Something(val s: String)

@Test
Expand Down

0 comments on commit 826f1fd

Please sign in to comment.