[maven] [IDEA-342187] update maven storage version and add tests for it

(cherry picked from commit 7bf21070a14281d2e962873fa6b896c3ac3ebe5b)

IJ-CR-152420

GitOrigin-RevId: ae9e7121c612d2b58b2e426fface43cedbf2db22
This commit is contained in:
Alexander Bubenchikov
2024-10-23 18:02:41 +02:00
committed by intellij-monorepo-bot
parent 8f0ffde38e
commit b14956ba7a
3 changed files with 62 additions and 2 deletions

View File

@@ -1063,8 +1063,8 @@ class MavenProjectsTree(val project: Project) {
companion object {
private val LOG = Logger.getInstance(MavenProjectsTree::class.java)
private const val STORAGE_VERSION_NUMBER = 10
private val STORAGE_VERSION = MavenProjectsTree::class.java.simpleName + "." + STORAGE_VERSION_NUMBER
private const val STORAGE_VERSION_NUMBER = 11
val STORAGE_VERSION = MavenProjectsTree::class.java.simpleName + "." + STORAGE_VERSION_NUMBER
private fun String.getStorageVersionNumber(): Int {
val parts = this.split(".")

View File

@@ -35,5 +35,6 @@
<orderEntry type="module" module-name="intellij.java.impl" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.backend.observation" scope="TEST" />
<orderEntry type="library" scope="TEST" name="hash4j" level="project" />
<orderEntry type="library" name="kotlin-reflect" level="project" />
</component>
</module>

View File

@@ -0,0 +1,59 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.maven.project.importing
import com.dynatrace.hash4j.hashing.HashSink
import com.dynatrace.hash4j.hashing.Hashing
import com.intellij.testFramework.UsefulTestCase
import org.jetbrains.idea.maven.project.MavenProjectsTree
import kotlin.reflect.KClass
import kotlin.reflect.KProperty
import kotlin.reflect.KType
import kotlin.reflect.full.createType
import kotlin.reflect.full.declaredMembers
import kotlin.reflect.full.findAnnotation
class MavenProjectTreeVersionNumberTest : UsefulTestCase() {
fun `test do not forget updating STORAGE_VERSION_NUMBER when structure changed`() {
val hash = Hashing.komihash5_0().hashStream();
val recursionKeeper = HashSet<String>()
hashKType(MavenProjectsTree::class.createType(), recursionKeeper, hash)
hash.putString(MavenProjectsTree.STORAGE_VERSION)
assertEquals("UPDATE STORAGE VERSION ALONG WITH THIS HASH!!!", -1853310441163155393L, hash.asLong)
}
private fun hashKType(type: KType, recursionKeeper: MutableSet<String>, hash: HashSink) {
val klass = type.classifier as? KClass<*> ?: return
hash.putString(klass.qualifiedName)
hash.putBoolean(type.isMarkedNullable)
type.arguments.forEach { projection ->
val type = projection.type
if (type == null) {
hash.putString(projection.toString())
}
else {
hashKType(type, recursionKeeper, hash)
}
}
if (shouldGoDeeper(klass) && recursionKeeper.add(klass.qualifiedName!!)) {
klass.declaredMembers.filterIsInstance<KProperty<*>>().forEach { t ->
if (!isTransient(t)) {
hash.putString(t.name)
hashKType(t.returnType, recursionKeeper, hash)
}
}
}
}
private fun shouldGoDeeper(klass: KClass<*>): Boolean {
return klass.qualifiedName?.startsWith("org.jetbrains.idea.maven") == true
}
private fun isTransient(prop: KProperty<*>): Boolean {
return prop.findAnnotation<Transient>() != null &&
prop.findAnnotation<kotlinx.serialization.Transient>() == null
}
}