Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

코드 정리 및 문서화 #38

Merged
merged 2 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion common-lint-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ plugins {
}

dependencies {
api("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0")
apis(
"org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import kotlinx.metadata.jvm.KotlinClassHeader
import kotlinx.metadata.jvm.KotlinClassMetadata
import kotlinx.metadata.jvm.signature

/**
* 코틀린 메타 데이터의 full qualified name 상수 값
*/
private const val KotlinMetadataFqn = "kotlin.Metadata"

/**
* @return the corresponding [KmFunction] for this [PsiMethod], or `null` if there is no
* corresponding [KmFunction]. This method is only meaningful if this [PsiMethod] represents a
Expand Down Expand Up @@ -125,5 +130,3 @@ private fun KmDeclarationContainer.findKmFunctionForPsiMethod(method: PsiMethod)
)
}
}

private const val KotlinMetadataFqn = "kotlin.Metadata"
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import com.android.tools.lint.checks.infrastructure.LintDetectorTest.kotlin
import com.android.tools.lint.checks.infrastructure.TestFile
import org.intellij.lang.annotations.Language

/**
* [TestFile] 로 사용할 @Composable 어노테이션 더미 파일
*/
val ComposableAnnotationFile: TestFile = kotlin(
"""
package androidx.compose.runtime
Expand All @@ -35,6 +38,13 @@ val ComposableAnnotationFile: TestFile = kotlin(
""".trimIndent()
)

/**
* @Composable 을 사용하기 위한 준비를 마친 [TestFile] 로 만들어 줍니다.
*
* @param source @Composable 을 사용할 코틀린 코드
*
* @return [source] 코드에서 @Composable 을 사용하기 위한 준비를 마친 [TestFile]
*/
fun composableTestFile(@Language("kotlin") source: String): TestFile = kotlin(
"""
package land.sungbin.dummy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,26 @@ import org.junit.runner.Description
import org.junit.runners.model.Statement
import team.duckie.quackquack.common.runIf

/**
* [LintTestRule] 인터페이스를 반환합니다.
*
* @return [LintTestRule] 구현체
*/
fun LintTestRule(): LintTestRule = LintTestRuleImpl()

/**
* 린트 테스트를 쉽게 하기 위한 커스텀 테스트 룰
*/
interface LintTestRule : TestRule {
/**
* 린트 에러 개수를 검증합니다.
*
* @param files 테스트할 [TestFile] 목록
* @param issues 검증할 [Issue] 목록
* @param expectedCount 발생해야 하는 린트 에러 개수
* @param fixedFile QuickFix 가 가능하다면 QuickFix 가 적용된 후 [TestFile]
* 만약 QuickFix 가 불가능 하다면 null 입력, 기본값은 null
*/
fun assertErrorCount(
files: List<TestFile>,
issues: List<Issue>,
Expand Down Expand Up @@ -59,6 +76,14 @@ private class LintTestRuleImpl : LintTestRule {
}
}

/**
* [TestFile] 목록에 [ComposableAnnotationFile] 를 추가합니다.
*
* @receiver [ComposableAnnotationFile] 이 추가되기 전 [TestFile] 목록
*
* @return receiver 로 받은 [TestFile] 목록에
* [ComposableAnnotationFile] 이 추가된 새로운 [TestFile] 목록
*/
private fun List<TestFile>.toComposableTestableFiles() = ArrayList(this).apply {
add(ComposableAnnotationFile)
}.toTypedArray()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Designed and developed by 2022 SungbinLand, Team Duckie
*
* [empty.kt] created by Ji Sungbin on 22. 8. 20. 오후 4:16
*
* Licensed under the MIT.
* Please see full license: https://github.com/sungbinland/quack-quack/blob/main/LICENSE
*/

package team.duckie.quackquack.common.lint

class Empty

This file was deleted.

25 changes: 25 additions & 0 deletions common/src/main/kotlin/team/duckie/quackquack/common/assert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,34 @@ internal val DefaultMessage = """
https://github.com/sungbinland/quack-quack/issues/
""".trimIndent()

/**
* 주어진 값이 참인지 확인합니다. QuackQuack 에 맞는 기본 에러 메시지를 사용하기 위해 구현됐습니다.
*
* @param value 참인지 확인할 값
* @param lazyMessage [value] 가 참이 아니라면 에러로 사용될 메시지를 반환하는 람다
* 기본값은 [DefaultMessage] 상수 참고
*
* @throw [value] 가 참이 아니라면 [lazyMessage] 값으로 [IllegalArgumentException]
*/
inline fun runtimeCheck(value: Boolean, lazyMessage: () -> String = { DefaultMessage }) {
if (!value) throw IllegalStateException(lazyMessage())
}

/**
* 주어진 메시지로 NPE 을 발생시킵니다.
*
* 주어진 값이 null 이라면 해당 구문을 NPE 과 함께 break 하는데 사용됩니다.
* QuackQuack 에 맞는 기본 에러 메시지를 사용하기 위해 구현됐습니다.
*
* ```kotlin
* val value: String? = null
* print(value ?: npe())
* ```
*
* @param lazyMessage NPE 에 사용될 메시지를 반환하는 람다
* 기본값은 [DefaultMessage] 상수 참고
*
* @throw [lazyMessage] 의 반환값을 메시지로 사용하는 [NullPointerException]
*/
inline fun npe(lazyMessage: () -> String = { DefaultMessage }): Nothing =
throw NullPointerException(lazyMessage())
16 changes: 16 additions & 0 deletions common/src/main/kotlin/team/duckie/quackquack/common/runIf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,26 @@

package team.duckie.quackquack.common

/**
* [condition] 이 참이면 [run] 을 실행합니다.
*
* @param condition 실행할 조건 [Boolean] 값
* @param run [condition] 이 참일 때 실행할 람다
*
* @return [condition] 이 참일 때 [run] 을 실행한 결과
*/
inline fun <T> T.runIf(condition: Boolean, run: T.() -> T) = if (condition) {
run()
} else this

/**
* [condition] 이 true 이면 [run] 을 실행합니다.
*
* @param condition 실행할 조건 [Boolean] 값을 반환하는 람다
* @param run [condition] 이 참일 때 실행할 람다
*
* @return [condition] 이 참일 때 [run] 을 실행한 결과
*/
inline fun <T> T.runIfBuilder(condition: (T) -> Boolean, run: T.() -> T) = if (condition(this)) {
run()
} else this
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import team.duckie.quackquack.convention.configureCompose
import team.duckie.quackquack.convention.libs
import team.duckie.quackquack.convention.setupCompose

/**
* Android 프레임워크의 Application 환경에서 Jetpack Compose 를 사용할 준비를 합니다.
*/
internal class AndroidApplicationComposePlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand All @@ -30,7 +33,8 @@ internal class AndroidApplicationComposePlugin : Plugin<Project> {
dependencies {
setupCompose(
core = libs.findBundle("compose-core").get(),
debug = libs.findBundle("compose-debug").get(),
debug = libs.findBundle("compose-debug")
.get(), // preview 빌드에 debugImplementation 이 사용됩니다.
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import team.duckie.quackquack.convention.PluginEnum
import team.duckie.quackquack.convention.applyPlugins
import team.duckie.quackquack.convention.configureApplication

/**
* Android 프레임워크의 Application 환경을 구성합니다.
*/
internal class AndroidApplicationPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand Down
5 changes: 5 additions & 0 deletions gradle-conventions/src/main/kotlin/AndroidBenchmarkPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import team.duckie.quackquack.convention.configureApplication
import team.duckie.quackquack.convention.implementations
import team.duckie.quackquack.convention.libs

/**
* Android 프레임워크에 의존적인 밴치마크 모듈을 구성합니다.
*
* 밴치마크 모듈은 baseline profiles 를 산출하기 위해 사용됩니다.
*/
internal class AndroidBenchmarkPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand Down
10 changes: 9 additions & 1 deletion gradle-conventions/src/main/kotlin/AndroidCommonLintPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import team.duckie.quackquack.convention.libs
import team.duckie.quackquack.convention.setupJunit
import team.duckie.quackquack.convention.setupLint

/**
* Android 프레임워크에 의존적인 린트 개발 환경을 구성합니다.
*
* 의존성 순환 참조를 방지하기 위해
* 린트 개발에 필요한 필수 의존성만을 사용하여 구성합니다.
*/
internal class AndroidCommonLintPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand All @@ -37,7 +43,9 @@ internal class AndroidCommonLintPlugin : Plugin<Project> {

dependencies {
dependencies {
compileOnlys(libs.findLibrary("kotlin-stdlib").get())
compileOnlys(
libs.findLibrary("kotlin-stdlib").get(),
)
setupJunit(
core = libs.findLibrary("test-junit-core").get(),
engine = libs.findLibrary("test-junit-engine").get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import team.duckie.quackquack.convention.configureCompose
import team.duckie.quackquack.convention.libs
import team.duckie.quackquack.convention.setupCompose

/**
* Android 프레임워크의 Library 환경에서 Jetpack Compose 를 사용할 준비를 합니다.
*/
internal class AndroidLibraryComposePlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand All @@ -30,7 +33,8 @@ internal class AndroidLibraryComposePlugin : Plugin<Project> {
dependencies {
setupCompose(
core = libs.findBundle("compose-core").get(),
debug = libs.findBundle("compose-debug").get(),
debug = libs.findBundle("compose-debug")
.get(), // preview 빌드에 debugImplementation 이 사용됩니다.
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import team.duckie.quackquack.convention.configureCompose
import team.duckie.quackquack.convention.debugImplementations
import team.duckie.quackquack.convention.libs

/**
* Android 프레임워크의 Library 환경에서 Jetpack Compose 의 UI 테스트를 진행할 준비를 합니다.
*/
internal class AndroidLibraryComposeUiTestPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand All @@ -35,8 +38,12 @@ internal class AndroidLibraryComposeUiTestPlugin : Plugin<Project> {
}

dependencies {
debugImplementations(libs.findLibrary("test-compose-manifest").get())
androidTestImplementations(libs.findLibrary("test-compose-junit").get())
debugImplementations(
libs.findLibrary("test-compose-manifest").get(),
)
androidTestImplementations(
libs.findLibrary("test-compose-junit").get(),
)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions gradle-conventions/src/main/kotlin/AndroidLibraryPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import team.duckie.quackquack.convention.PluginEnum
import team.duckie.quackquack.convention.applyPlugins
import team.duckie.quackquack.convention.configureApplication

/**
* Android 프레임워크의 Library 환경을 구성합니다.
*/
internal class AndroidLibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand Down
18 changes: 15 additions & 3 deletions gradle-conventions/src/main/kotlin/AndroidLintPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import team.duckie.quackquack.convention.setupJunit
import team.duckie.quackquack.convention.setupLint
import team.duckie.quackquack.convention.testImplementations

/**
* Android 프레임워크에 의존적인 린트 개발 환경을 구성합니다.
*
* [AndroidCommonLintPlugin] 와 달리
* 린트 개발에 도움이 될 수 있는 추가적인 다른 의존성들도 같이 구성합니다.
*/
internal class AndroidLintPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand All @@ -41,9 +47,15 @@ internal class AndroidLintPlugin : Plugin<Project> {

dependencies {
dependencies {
compileOnlys(libs.findLibrary("kotlin-stdlib").get())
implementations(project(":common-lint"))
testImplementations(project(":common-lint-test"))
compileOnlys(
libs.findLibrary("kotlin-stdlib").get(),
)
implementations(
project(":common-lint"),
)
testImplementations(
project(":common-lint-test"),
)
setupJunit(
core = libs.findLibrary("test-junit-core").get(),
engine = libs.findLibrary("test-junit-engine").get(),
Expand Down
3 changes: 3 additions & 0 deletions gradle-conventions/src/main/kotlin/JvmLibraryPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import team.duckie.quackquack.convention.applyPlugins
* Please see full license: https://github.com/sungbinland/quack-quack/blob/main/LICENSE
*/

/**
* Android 프레임워크에 의존적이지 않은 순수한 자바 라이브러리 모듈을 구성합니다.
*/
internal class JvmLibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
Expand Down
9 changes: 7 additions & 2 deletions gradle-conventions/src/main/kotlin/ModuleJacocoPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.dependencies
import team.duckie.quackquack.convention.PluginEnum
import team.duckie.quackquack.convention.applyPlugins
import team.duckie.quackquack.convention.configureJacocoForOnceCoverage
import team.duckie.quackquack.convention.configureJacocoForModule
import team.duckie.quackquack.convention.libs
import team.duckie.quackquack.convention.setupJunit

/**
* Android 프레임워크에 의존적이지 않은 순수한 Jacoco 모듈을 구성합니다.
*
* 모듈 그레이들 단위에서 사용되므로 [configureJacocoForModule] 를 사용합니다.
*/
internal class ModuleJacocoPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
applyPlugins(
PluginEnum.Jacoco,
)

configureJacocoForOnceCoverage()
configureJacocoForModule()

dependencies {
setupJunit(
Expand Down
9 changes: 7 additions & 2 deletions gradle-conventions/src/main/kotlin/ProjectJacocoPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import team.duckie.quackquack.convention.PluginEnum
import team.duckie.quackquack.convention.applyPlugins
import team.duckie.quackquack.convention.configureJacocoForAllCoverage
import team.duckie.quackquack.convention.configureJacocoForProject

/**
* Android 프레임워크에 의존적이지 않은 순수한 Jacoco 모듈을 구성합니다.
*
* 프로젝트 그레이들 단위에서 사용되므로 [configureJacocoForProject] 를 사용합니다.
*/
class ProjectJacocoPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
applyPlugins(
PluginEnum.Jacoco,
)

configureJacocoForAllCoverage()
configureJacocoForProject()
}
}
}
Loading