-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maven] [IDEA-342187] update maven storage version and add tests for it
(cherry picked from commit 7bf21070a14281d2e962873fa6b896c3ac3ebe5b) IJ-CR-152420 GitOrigin-RevId: 716a65f603d73c134af3abae806502a7f7578415
- Loading branch information
1 parent
622ace3
commit b5468f5
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...test/java/org/jetbrains/idea/maven/project/importing/MavenProjectTreeVersionNumberTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |