Skip to content

Commit eb01d85

Browse files
authored
remove-version-for-maven-deps Closes #2014 (#2018)
remove-version-for-maven-deps
1 parent 2713002 commit eb01d85

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/deps/ModulesDepsService.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class ModulesDepsService(private val project: Project) : Disposable {
259259
private val timer = Timer()
260260

261261
@NotNull
262-
private var mapName2Module: ConcurrentMap<String, ModuleExt> = ConcurrentHashMap<String, ModuleExt>()
262+
private var mapName2Module: ConcurrentMap<String, ModuleExt> = ConcurrentHashMap()
263263

264264
init {
265265
//todo: change to coroutines
@@ -297,7 +297,7 @@ class ModulesDepsService(private val project: Project) : Disposable {
297297
moduleManager.modules.forEach { module ->
298298
val modName = module.name
299299
val moduleMetadata = buildMetadata(module)
300-
theMap.put(modName, ModuleExt(module, moduleMetadata))
300+
theMap[modName] = ModuleExt(module, moduleMetadata)
301301
}
302302
return theMap
303303
}
@@ -332,7 +332,7 @@ class ModulesDepsService(private val project: Project) : Disposable {
332332
}
333333

334334
fun getModuleExt(moduleName: String): ModuleExt? {
335-
var mExt = mapName2Module.get(moduleName)
335+
var mExt = mapName2Module[moduleName]
336336
if (mExt == null) {
337337
// println("DBG: module '${moduleName}' - metadata not built yet, building it...")
338338
//try to build MD for this entry
@@ -345,14 +345,11 @@ class ModulesDepsService(private val project: Project) : Disposable {
345345

346346
private fun tryBuildAndStoreModuleExt(moduleName: String): ModuleExt? {
347347
val moduleManager = ModuleManager.getInstance(project)
348-
val module = moduleManager.findModuleByName(moduleName)
349-
if (module == null) {
350-
return null
351-
}
348+
val module = moduleManager.findModuleByName(moduleName) ?: return null
352349

353350
val moduleMetadata = buildMetadata(module)
354351
val moduleExt = ModuleExt(module, moduleMetadata)
355-
mapName2Module.put(moduleName, moduleExt)
352+
mapName2Module[moduleName] = moduleExt
356353
// println("DBG: module '${moduleName}' - built moduleExt = $moduleExt")
357354
return moduleExt
358355
}

jvm-common/src/main/kotlin/org/digma/intellij/plugin/idea/frameworks/SpringBootMicrometerConfigureDepsService.kt

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,29 @@ class SpringBootMicrometerConfigureDepsService(private val project: Project) : D
6666
return buildUnifiedDependency(libCoordinates, javaBuildSystem)
6767
}
6868

69-
fun buildUnifiedDependency(libCoordinates: UnifiedCoordinates, javaBuildSystem: BuildSystem): UnifiedDependency {
70-
return buildUnifiedDependency(libCoordinates, javaBuildSystem, true)
71-
}
72-
7369
fun buildUnifiedDependency(
7470
libCoordinates: UnifiedCoordinates,
7571
javaBuildSystem: BuildSystem,
76-
removeVersionIfCan: Boolean,
72+
removeVersion: Boolean = true,
7773
): UnifiedDependency {
78-
val dep: UnifiedDependency =
79-
when (javaBuildSystem) {
80-
BuildSystem.MAVEN -> UnifiedDependency(libCoordinates, null)
81-
BuildSystem.GRADLE -> {
82-
val newLibCoordinates =
83-
if (!removeVersionIfCan) {
84-
libCoordinates
85-
} else {
86-
coordsWithoutVersion(libCoordinates)
87-
}
88-
return UnifiedDependency(newLibCoordinates, "implementation")
89-
}
9074

91-
else -> UnifiedDependency(libCoordinates, "compile")
75+
val coordinatesWithoutVersionIfNecessary =
76+
if (removeVersion) {
77+
coordinatesWithoutVersion(libCoordinates)
78+
} else {
79+
libCoordinates
9280
}
9381

94-
return dep
82+
return when (javaBuildSystem) {
83+
BuildSystem.MAVEN -> UnifiedDependency(coordinatesWithoutVersionIfNecessary, null)
84+
BuildSystem.GRADLE -> UnifiedDependency(coordinatesWithoutVersionIfNecessary, "implementation")
85+
//if not maven or gradle always add with version, probably not so relevant coz we will not get here
86+
// if it's not maven or gradle
87+
else -> UnifiedDependency(libCoordinates, "compile")
88+
}
9589
}
9690

97-
private fun coordsWithoutVersion(orig: UnifiedCoordinates): UnifiedCoordinates {
91+
private fun coordinatesWithoutVersion(orig: UnifiedCoordinates): UnifiedCoordinates {
9892
// version as empty string works well, while null value throws exception (both for maven and gradle)
9993
return UnifiedCoordinates(orig.groupId, orig.artifactId, "")
10094
}

0 commit comments

Comments
 (0)