Skip to content

Commit 789ef27

Browse files
Fix false positive on versions not equal to 4
The version check was quite primitive, checking the jar name and extracting the name from that. This made it quite unreliable, and disabled the plugin for users with their own `axon-*` module (#327). The version check has now been changed. JARs found to contain the name axon will now be checked its META-INF for it's groupId and artifactID, and only be disabled/detected if it is the correct group. Resolves #327
1 parent 7ddbe4f commit 789ef27

File tree

3 files changed

+76
-40
lines changed

3 files changed

+76
-40
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
# Axon Framework plugin Changelog
44

5+
## [0.9.2]
6+
- Fix false positive on versions not equal to 4
7+
58
## [0.9.1]
69
- Disable plugin when Axon Framework 5 or greater is detected. The plugin is not compatible with Axon Framework 5 and greater at this time, as it is an experimental branch. Future versions of the plugin will be compatible with Axon Framework 5 and greater, once it approaches release readiness.
710

src/main/kotlin/org/axonframework/intellij/ide/plugin/usage/AxonDependency.kt

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,42 @@
1616

1717
package org.axonframework.intellij.ide.plugin.usage
1818

19-
enum class AxonDependency(val moduleName: String, val checkVersion: Boolean = true) {
20-
Core("axon-core"), // Axon 2 only
21-
Integration("axon-integration"), // Axon 2 only
22-
SpringMessaging("axon-springmessaging"), // Axon 2 only
23-
DistributedCommandBus("axon-distributed-commandbus"), // Axon 2 only
24-
Spring("axon-spring"), // Axon 3 and 4
25-
SpringAutoconfigure("axon-spring-boot-autoconfigure"), // Axon 3 and 4
26-
SpringStarter("axon-spring-boot-starter"), // Axon 3 and 4
27-
Messaging("axon-messaging"), // Axon 4 only
28-
EventSourcing("axon-eventsourcing"), // Axon 4 only
29-
Modelling("axon-modelling"), // Axon 4 only
30-
Configuration("axon-configuration"), // Axon 4 only
31-
Test("axon-test"), // Axon 2, 3 and 4
32-
Metrics("axon-metrics"), // Axon 3 and 4
33-
Legacy("axon-legacy"), // Axon 3 and 4
34-
Micrometer("axon-micrometer"), // Axon 4 only
35-
Disruptor("axon-disruptor"), // Axon 4 only
36-
ServerConnector("axon-server-connector"), // Axon 4 only
19+
enum class AxonDependency(
20+
val groupId: String,
21+
val artifactId: String,
22+
val checkVersion: Boolean = true
23+
) {
24+
Core("org.axonframework", "axon-core"), // Axon 2 only
25+
Integration("org.axonframework", "axon-integration"), // Axon 2 only
26+
SpringMessaging("org.axonframework", "axon-springmessaging"), // Axon 2 only
27+
DistributedCommandBus("org.axonframework", "axon-distributed-commandbus"), // Axon 2 only
28+
Spring("org.axonframework", "axon-spring"), // Axon 3 and 4
29+
SpringAutoconfigure("org.axonframework", "axon-spring-boot-autoconfigure"), // Axon 3 and 4
30+
SpringStarter("org.axonframework", "axon-spring-boot-starter"), // Axon 3 and 4
31+
Messaging("org.axonframework", "axon-messaging"), // Axon 4 only
32+
EventSourcing("org.axonframework", "axon-eventsourcing"), // Axon 4 only
33+
Modelling("org.axonframework", "axon-modelling"), // Axon 4 only
34+
Configuration("org.axonframework", "axon-configuration"), // Axon 4 only
35+
Test("org.axonframework", "axon-test"), // Axon 2, 3 and 4
36+
Metrics("org.axonframework", "axon-metrics"), // Axon 3 and 4
37+
Legacy("org.axonframework", "axon-legacy"), // Axon 3 and 4
38+
Micrometer("org.axonframework", "axon-micrometer"), // Axon 4 only
39+
Disruptor("org.axonframework", "axon-disruptor"), // Axon 4 only
40+
ServerConnector("org.axonframework", "axon-server-connector"), // Axon 4 only
3741

3842
// Extensions, used for reporting during bugs, not for version check
39-
Mongo("axon-mongo", false),
40-
Mongo3("axon-mongo3", false),
41-
Amqp("axon-amqp", false),
42-
Jgroups("axon-jgroups", false),
43-
Reactor("axon-reactor", false),
44-
Kotlin("axon-kotlin", false),
45-
Kafka("axon-kafka", false),
46-
Multitenancy("axon-multitenancy", false),
47-
SpringCloud("axon-springcloud", false),
48-
Tracing("axon-tracing", false),
49-
Cdi("axon-cdi", false),
43+
Mongo("org.axonframework.extensions.mongo", "axon-mongo", false),
44+
Amqp("org.axonframework", "axon-amqp", false),
45+
Jgroups("org.axonframework.extensions.jgroups", "axon-jgroups", false),
46+
Reactor("org.axonframework.extensions.reactor", "axon-reactor", false),
47+
Kotlin("org.axonframework.extensions.kotlin", "axon-kotlin", false),
48+
Kafka("org.axonframework.extensions.kafka", "axon-kafka", false),
49+
Multitenancy("org.axonframework.extensions.multitenancy", "axon-multitenancy", false),
50+
SpringCloud("org.axonframework.extensions.springcloud", "axon-springcloud", false),
51+
Tracing("org.axonframework.extensions.tracing", "axon-tracing", false),
52+
Cdi("org.axonframework.extensions.cdi", "axon-cdi", false),
53+
;
54+
55+
val moduleName: String
56+
get() = "$groupId:$artifactId"
5057
}

src/main/kotlin/org/axonframework/intellij/ide/plugin/usage/AxonVersionService.kt

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ import com.intellij.openapi.project.Project
2323
import com.intellij.openapi.roots.ModuleRootEvent
2424
import com.intellij.openapi.roots.ModuleRootListener
2525
import com.intellij.openapi.roots.OrderEnumerator
26+
import com.intellij.openapi.vfs.VfsUtilCore
27+
import java.util.Properties
28+
import java.util.jar.JarFile
2629

2730
class AxonVersionService(val project: Project) {
2831
private var enabled = false
2932
private var messageShownOutdated = false
3033
private var messageShownExperimental = false
3134

32-
private val regex = Regex(".*(axon-.*)-(\\d+)\\.(\\d+)\\.(\\d+)(.*)\\.jar")
35+
private val versionRegex = Regex("(\\d+)\\.(\\d+)\\.(\\d+)(.*)")
3336

3437

3538
init {
@@ -127,26 +130,49 @@ class AxonVersionService(val project: Project) {
127130
private fun List<AxonDependencyVersion>.outdated() = filter { it.dependency.checkVersion && it.major < 4 }
128131
private fun List<AxonDependencyVersion>.experimental() = filter { it.dependency.checkVersion && it.major > 4 }
129132

130-
fun getAxonVersions() = OrderEnumerator.orderEntries(project)
133+
fun getAxonVersions(): List<AxonDependencyVersion> = OrderEnumerator.orderEntries(project)
131134
.librariesOnly()
132135
.productionOnly()
133136
.classes()
134137
.roots
135-
.filter { !it.presentableName.contains("inspector") }
136-
.filter { it.presentableName.matches(regex) }
137-
.mapNotNull {
138-
extractVersion(it.name)
138+
.filter { it.presentableName.contains("axon") }
139+
.flatMap { root ->
140+
val jarFile = VfsUtilCore.virtualToIoFile(root)
141+
if (jarFile.extension == "jar") {
142+
val jar = JarFile(jarFile)
143+
jar.entries()
144+
.toList()
145+
.filter { it.name.startsWith("META-INF/maven/") && it.name.endsWith("pom.properties") }
146+
.mapNotNull { entry ->
147+
jar.getInputStream(entry).use { input ->
148+
// Process the input stream as needed
149+
val properties = Properties().apply { load(input) }
150+
extractVersion(properties)
151+
}
152+
}
153+
} else {
154+
emptyList()
155+
}
139156
}
140157

141-
private fun extractVersion(name: String): AxonDependencyVersion? {
142-
val match = regex.find(name)!!
143-
val (moduleName, majorVersion, minorVersion, patchVersion, remaining) = match.destructured
144-
val dependency = AxonDependency.entries.firstOrNull { it.moduleName == moduleName } ?: return null
158+
private fun extractVersion(properties: Properties): AxonDependencyVersion? {
159+
val groupId = properties.getProperty("groupId")
160+
val artifactId = properties.getProperty("artifactId")
161+
val version = properties.getProperty("version")
162+
if(groupId.isNullOrEmpty() || artifactId.isNullOrEmpty() || version.isNullOrEmpty()) {
163+
return null
164+
}
165+
val dependency = AxonDependency.entries.firstOrNull { it.groupId == groupId && it.artifactId == artifactId }
166+
if(dependency == null) {
167+
return null
168+
}
169+
val (majorVersion, minorVersion, patchVersion, remaining) = versionRegex.find(version)!!.destructured
145170
return AxonDependencyVersion(
146171
dependency,
147172
Integer.parseInt(majorVersion),
148173
Integer.parseInt(minorVersion),
149-
Integer.parseInt(patchVersion), remaining
174+
Integer.parseInt(patchVersion),
175+
remaining
150176
)
151177
}
152178

0 commit comments

Comments
 (0)