Skip to content

Commit

Permalink
[maven] [IDEA-342187] update maven storage version and add tests for it
Browse files Browse the repository at this point in the history
(cherry picked from commit 7bf21070a14281d2e962873fa6b896c3ac3ebe5b)

IJ-CR-152420

GitOrigin-RevId: 716a65f603d73c134af3abae806502a7f7578415
  • Loading branch information
zulkar authored and intellij-monorepo-bot committed Jan 29, 2025
1 parent 622ace3 commit b5468f5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(".")
Expand Down
1 change: 1 addition & 0 deletions plugins/maven/src/test/intellij.maven.tests.iml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit b5468f5

Please sign in to comment.