diff --git a/plugin/src/adapter49/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation49.kt b/plugin/src/adapter49/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation49.kt index 374e1682..d61dd204 100644 --- a/plugin/src/adapter49/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation49.kt +++ b/plugin/src/adapter49/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation49.kt @@ -1,10 +1,12 @@ package org.jlleitschuh.gradle.ktlint.worker +import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3 import com.pinterest.ktlint.rule.engine.api.Code import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine import com.pinterest.ktlint.rule.engine.api.LintError -import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider +import com.pinterest.ktlint.rule.engine.core.api.RuleProvider import java.io.File +import java.util.ServiceLoader class KtLintInvocation49( private val engine: KtLintRuleEngine @@ -12,10 +14,17 @@ class KtLintInvocation49( companion object Factory : KtLintInvocationFactory { fun initialize(): KtLintInvocation { val engine = KtLintRuleEngine( - ruleProviders = StandardRuleSetProvider().getRuleProviders() + ruleProviders = loadRuleSetsFromClasspathWithRuleSetProviderV3() ) return KtLintInvocation49(engine) } + + private fun loadRuleSetsFromClasspathWithRuleSetProviderV3(): Set { + return ServiceLoader + .load(RuleSetProviderV3::class.java) + .flatMap { it.getRuleProviders() } + .toSet() + } } override fun invokeLint(file: File): LintErrorResult { @@ -38,6 +47,8 @@ class KtLintInvocation49( override fun trimMemory() { engine.trimMemory() } + // StandardRuleSetProvider().getRuleProviders() + } internal fun LintError.toSerializable(): SerializableLintError { diff --git a/plugin/src/adapter50/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation50.kt b/plugin/src/adapter50/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation50.kt index 756dfc88..eb505023 100644 --- a/plugin/src/adapter50/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation50.kt +++ b/plugin/src/adapter50/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation50.kt @@ -1,10 +1,12 @@ package org.jlleitschuh.gradle.ktlint.worker +import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3 import com.pinterest.ktlint.rule.engine.api.Code import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine import com.pinterest.ktlint.rule.engine.api.LintError -import com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider +import com.pinterest.ktlint.rule.engine.core.api.RuleProvider import java.io.File +import java.util.ServiceLoader class KtLintInvocation50( private val engine: KtLintRuleEngine @@ -12,10 +14,17 @@ class KtLintInvocation50( companion object Factory : KtLintInvocationFactory { fun initialize(): KtLintInvocation { val engine = KtLintRuleEngine( - ruleProviders = StandardRuleSetProvider().getRuleProviders() + ruleProviders = loadRuleSetsFromClasspathWithRuleSetProviderV3() ) return KtLintInvocation50(engine) } + + private fun loadRuleSetsFromClasspathWithRuleSetProviderV3(): Set { + return ServiceLoader + .load(RuleSetProviderV3::class.java) + .flatMap { it.getRuleProviders() } + .toSet() + } } override fun invokeLint(file: File): LintErrorResult {