Skip to content

Commit

Permalink
Merge pull request #120 from AxonFramework/fix/119-version-detection-…
Browse files Browse the repository at this point in the history
…overachieve

Add filter to dependency check, fixes #109
  • Loading branch information
CodeDrivenMitch authored Jul 18, 2022
2 parents 5844f0d + 8a71990 commit 1390c7e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Axon Framework plugin Changelog

## [0.7.3]

### Fixed
- Issue where Axon version detection did not work properly, disabling the plugin while it should not.
- NPE when analyzing Kotlin files for AggregateIdentifier inspection

## [0.7.2]

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class JavaAggregateIdInspection : AbstractBaseJavaLocalInspectionTool() {
if (!aClass.isAggregate()) {
return null
}
val entity = aClass.aggregateResolver().getEntityByName(aClass.qualifiedName!!)!!
val entity = aClass.qualifiedName?.let { aClass.aggregateResolver().getEntityByName(it) } ?: return emptyArray()
if (entity.routingKey == null) {
return arrayOf(
manager.createProblemDescriptor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class KotlinAggregateIdInspection : AbstractKotlinInspection() {
if (!uClass.isAggregate()) {
return
}
val entity = uClass.aggregateResolver().getEntityByName(uClass.qualifiedName!!)!!
val entity = uClass.qualifiedName?.let { uClass.aggregateResolver().getEntityByName(it) } ?: return
if (entity.routingKey == null) {
holder.registerProblem(
element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ReportingService {

private fun Project.addLibraryVersionsToExtras() {
versionService().getAxonVersions().forEach { dep ->
Sentry.setExtra(dep.name, dep.toVersionString())
Sentry.setExtra(dep.dependency.moduleName, dep.toVersionString())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) (2010-2022). Axon Framework
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

enum class AxonDependency(val moduleName: String, val checkVersion: Boolean = true) {
Core("axon-core"), // Axon 2 only
Integration("axon-integration"), // Axon 2 only
SpringMessaging("axon-springmessaging"), // Axon 2 only
DistributedCommandBus("axon-distributed-commandbus"), // Axon 2 only
Spring("axon-spring"), // Axon 3 and 4
SpringAutoconfigure("axon-spring-boot-autoconfigure"), // Axon 3 and 4
SpringStarter("axon-spring-boot-starter"), // Axon 3 and 4
Messaging("axon-messaging"), // Axon 4 only
EventSourcing("axon-eventsourcing"), // Axon 4 only
Modelling("axon-modelling"), // Axon 4 only
Configuration("axon-configuration"), // Axon 4 only
Test("axon-test"), // Axon 2, 3 and 4
Metrics("axon-metrics"), // Axon 3 and 4
Legacy("axon-legacy"), // Axon 3 and 4
Micrometer("axon-micrometer"), // Axon 4 only
Disruptor("axon-disruptor"), // Axon 4 only
ServerConnector("axon-server-connector"), // Axon 4 only

// Extensions, used for reporting during bugs, not for version check
Mongo("axon-mongo", false),
Mongo3("axon-mongo3", false),
Amqp("axon-amqp", false),
Jgroups("axon-jgroups", false),
Reactor("axon-reactor", false),
Kotlin("axon-kotlin", false),
Kafka("axon-kafka", false),
Multitenancy("axon-multitenancy", false),
SpringCloud("axon-springcloud", false),
Tracing("axon-tracing", false),
Cdi("axon-cdi", false),
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import com.intellij.openapi.roots.OrderEnumerator
class AxonVersionService(val project: Project) {
private var enabled = false
private var messageShown = false
private val regex = Regex("(axon-.*)-(\\d+)\\.(\\d+)\\.(\\d+)(.*)\\.jar")

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


init {
Expand Down Expand Up @@ -64,13 +65,13 @@ class AxonVersionService(val project: Project) {
messageShown = true
}

private fun showDisabledMessage(outdatedDeps: List<AxonDependency>) {
private fun showDisabledMessage(outdatedDeps: List<AxonDependencyVersion>) {
NotificationGroupManager.getInstance()
.getNotificationGroup("AxonNotificationGroup")
.createNotification(
"Your project has an Axon Framework version older than 4. The plugin has been disabled. The specific dependencies are: " + outdatedDeps.joinToString(
separator = ","
) { it.name + "(${it.toVersionString()})" }, NotificationType.ERROR
) { it.dependency.moduleName + "(${it.toVersionString()})" }, NotificationType.ERROR
)
.notify(project)
}
Expand All @@ -90,34 +91,32 @@ class AxonVersionService(val project: Project) {
if(useCache) {
return enabled
}
val axonVersions = getAxonVersions()
return axonVersions.isNotEmpty() && axonVersions.all {
it.major >= 4
}
return getAxonVersions().outdated().isEmpty()
}

private fun List<AxonDependency>.outdated() = filter { it.major < 4 }
private fun List<AxonDependencyVersion>.outdated() = filter { it.dependency.checkVersion && it.major < 4 }

fun getAxonVersions() = OrderEnumerator.orderEntries(project)
.librariesOnly()
.productionOnly()
.classes()
.roots
.filter { it.presentableName.matches(regex) }
.map {
.mapNotNull {
extractVersion(it.name)
}

private fun extractVersion(name: String): AxonDependency {
private fun extractVersion(name: String): AxonDependencyVersion? {
val match = regex.find(name)!!
val (moduleName, majorVersion, minorVersion, patchVersion, remaining) = match.destructured
return AxonDependency(moduleName,
val dependency = AxonDependency.values().firstOrNull { it.moduleName == moduleName } ?: return null
return AxonDependencyVersion(dependency,
Integer.parseInt(majorVersion),
Integer.parseInt(minorVersion),
Integer.parseInt(patchVersion), remaining)
}

data class AxonDependency(val name: String, val major: Int, val minor: Int, val patch: Int, val remaining: String) {
data class AxonDependencyVersion(val dependency: AxonDependency, val major: Int, val minor: Int, val patch: Int, val remaining: String) {
fun toVersionString() = "$major.$minor.$patch$remaining"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ fun PsiElement.deadlineReferenceResolver(): DeadlineManagerReferenceResolver = p
fun Project.aggregateResolver(): AggregateStructureResolver = getService(AggregateStructureResolver::class.java)
fun PsiElement.aggregateResolver(): AggregateStructureResolver = project.aggregateResolver()
fun Project.versionService(): AxonVersionService = getService(AxonVersionService::class.java)
fun Project.isAxonEnabled() = versionService().isAxonEnabled()
fun PsiElement.isAxonEnabled() = project.versionService().isAxonEnabled()
fun Project.isAxonEnabled() = versionService().isAxonEnabled(true)
fun PsiElement.isAxonEnabled() = project.versionService().isAxonEnabled(true)

fun PsiClass?.isAggregate() = this?.hasAnnotation(AxonAnnotation.AGGREGATE_ROOT) == true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import org.axonframework.intellij.ide.plugin.AbstractAxonFixtureTestCase
internal class ProjectUtilsKtTest : AbstractAxonFixtureTestCase() {
fun testGetAxonDependencies() {
val axonVersions = project.versionService().getAxonVersions()
assertThat(axonVersions).anySatisfy { it.name == "axon-eventsourcing" && it.major == 4 }
assertThat(axonVersions).anySatisfy { it.name == "axon-modelling" && it.major == 4 }
assertThat(axonVersions).anySatisfy { it.name == "axon-messaging" && it.major == 4 }
assertThat(axonVersions).anySatisfy { it.name == "axon-configuration" && it.major == 4 }
assertThat(axonVersions).anySatisfy { it.dependency.moduleName == "axon-eventsourcing" && it.major == 4 }
assertThat(axonVersions).anySatisfy { it.dependency.moduleName == "axon-modelling" && it.major == 4 }
assertThat(axonVersions).anySatisfy { it.dependency.moduleName == "axon-messaging" && it.major == 4 }
assertThat(axonVersions).anySatisfy { it.dependency.moduleName == "axon-configuration" && it.major == 4 }

assertThat(project.versionService().isAxonEnabled()).isTrue
assertThat(project.versionService().isAxonEnabled(true)).isTrue
Expand Down

0 comments on commit 1390c7e

Please sign in to comment.