Skip to content

Commit 604dd21

Browse files
committed
Remove unused dependencyRulesApplied and make jackson object mapper lazy
1 parent 22693a8 commit 604dd21

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/main/kotlin/nebula/plugin/resolutionrules/json.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package nebula.plugin.resolutionrules
1919
import com.fasterxml.jackson.databind.*
2020
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
2121

22-
fun objectMapper(): ObjectMapper {
23-
return jacksonObjectMapper()
24-
}
22+
/**
23+
* Lazily initialized, shared ObjectMapper instance for JSON deserialization.
24+
* Thread-safe singleton that is only created when first accessed.
25+
*/
26+
val objectMapper: ObjectMapper by lazy { jacksonObjectMapper() }

src/main/kotlin/nebula/plugin/resolutionrules/plugin.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ class ResolutionRulesPlugin : Plugin<Project> {
107107
return@configureEach
108108
}
109109

110-
var dependencyRulesApplied = false
111110
project.onExecute {
112111
val ruleSet = extension.ruleSet()
113112
when {
@@ -122,7 +121,6 @@ class ResolutionRulesPlugin : Plugin<Project> {
122121
ruleSet.dependencyRulesPartTwo().forEach { rule ->
123122
rule.apply(project, config, config.resolutionStrategy, extension)
124123
}
125-
dependencyRulesApplied = true
126124
}
127125
}
128126
}
@@ -150,7 +148,7 @@ class ResolutionRulesPlugin : Plugin<Project> {
150148
abstract class NebulaResolutionRulesService : BuildService<NebulaResolutionRulesService.Params> {
151149
companion object {
152150
private val Logger: Logger = Logging.getLogger(NebulaResolutionRulesService::class.java)
153-
private val Mapper = objectMapper()
151+
private val Mapper = objectMapper
154152

155153
fun registerService(project: Project): Provider<NebulaResolutionRulesService> {
156154
return project.gradle.sharedServices.registerIfAbsent(
@@ -174,7 +172,7 @@ abstract class NebulaResolutionRulesService : BuildService<NebulaResolutionRules
174172
"jar", "zip" -> {
175173
Logger.info("nebula.resolution-rules is using ruleset: {}", file.name)
176174
val zipFile = ZipFile(file)
177-
Collections.list(zipFile.entries()).stream()
175+
zipFile.entries().toList().stream()
178176
.onClose(zipFile::close)
179177
.flatMap { entry ->
180178
val entryFile = File(entry.name)

src/test/groovy/nebula/plugin/resolutionrules/RulesTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class RulesTest extends Specification {
7373
}
7474

7575
static RuleSet parseJsonText(String json) {
76-
def ruleSet = JsonKt.objectMapper().readValue(json, RuleSet)
76+
def ruleSet = JsonKt.getObjectMapper().readValue(json, RuleSet)
7777
return RulesKt.withName(ruleSet, "dummy")
7878
}
7979
}

0 commit comments

Comments
 (0)