RepositoryLibraryUtilsTest: properly reset path macros and local maven repository path before and after test

GitOrigin-RevId: 8e7430d1597912af3b77749c2a2bf561a8baae75
This commit is contained in:
Vladislav.Yaroshchuk
2023-10-05 11:29:21 +02:00
committed by intellij-monorepo-bot
parent 0c66c4c873
commit ccd91ed6be
21 changed files with 59 additions and 42 deletions

View File

@@ -4,12 +4,12 @@
<remote-repository>
<option name="id" value="repositoryReleases" />
<option name="name" value="repositoryReleases" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
</remote-repository>
<remote-repository>
<option name="id" value="repositorySnapshots" />
<option name="name" value="repositorySnapshots" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
</remote-repository>
</component>
</project>

View File

@@ -2,13 +2,13 @@
<library name="smallSampleLibRelease" type="repository">
<properties jar-repository-id="repositoryReleases" maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0">
<verification>
<artifact url="file://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<artifact url="file://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<sha256sum>f0aaca850dd5e399541a9614da99dd194c122e9252b35dafeb088b77b8baf6b1</sha256sum>
</artifact>
</verification>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -2,7 +2,7 @@
<library name="smallSampleLibSnapshot" type="repository">
<properties jar-repository-id="repositorySnapshots" maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0-SNAPSHOT" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -13,13 +13,13 @@
<library name="smallSampleTestLibModuleLevel" type="repository">
<properties jar-repository-id="repositoryReleases" maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0">
<verification>
<artifact url="file://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<artifact url="file://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<sha256sum>f0aaca850dd5e399541a9614da99dd194c122e9252b35dafeb088b77b8baf6b1</sha256sum>
</artifact>
</verification>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -4,12 +4,12 @@
<remote-repository>
<option name="id" value="repositoryReleases" />
<option name="name" value="repositoryReleases" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
</remote-repository>
<remote-repository>
<option name="id" value="repositorySnapshots" />
<option name="name" value="repositorySnapshots" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
</remote-repository>
</component>
</project>

View File

@@ -2,13 +2,13 @@
<library name="smallSampleLibRelease" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0">
<verification>
<artifact url="file://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<artifact url="file://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<sha256sum>badchecksum</sha256sum>
</artifact>
</verification>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -2,7 +2,7 @@
<library name="smallSampleLibSnapshot" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0-SNAPSHOT" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -13,13 +13,13 @@
<library name="smallSampleTestLibModuleLevel" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0">
<verification>
<artifact url="file://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<artifact url="file://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<sha256sum>badchecksumhere</sha256sum>
</artifact>
</verification>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -4,12 +4,12 @@
<remote-repository>
<option name="id" value="repositoryReleases" />
<option name="name" value="repositoryReleases" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
</remote-repository>
<remote-repository>
<option name="id" value="repositorySnapshots" />
<option name="name" value="repositorySnapshots" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
</remote-repository>
</component>
</project>

View File

@@ -2,7 +2,7 @@
<library name="smallSampleLibRelease" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -2,7 +2,7 @@
<library name="smallSampleLibSnapshot" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0-SNAPSHOT" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -13,7 +13,7 @@
<library name="smallSampleTestLibModuleLevel" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -4,12 +4,12 @@
<remote-repository>
<option name="id" value="repositoryReleases" />
<option name="name" value="repositoryReleases" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
</remote-repository>
<remote-repository>
<option name="id" value="repositorySnapshots" />
<option name="name" value="repositorySnapshots" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
</remote-repository>
</component>
</project>

View File

@@ -2,13 +2,13 @@
<library name="smallSampleLibRelease" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0">
<verification>
<artifact url="file://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<artifact url="file://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<sha256sum>f0aaca850dd5e399541a9614da99dd194c122e9252b35dafeb088b77b8baf6b1</sha256sum>
</artifact>
</verification>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -2,7 +2,7 @@
<library name="smallSampleLibSnapshot" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0-SNAPSHOT" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -13,13 +13,13 @@
<library name="smallSampleTestLibModuleLevel" type="repository">
<properties maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0">
<verification>
<artifact url="file://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<artifact url="file://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar">
<sha256sum>f0aaca850dd5e399541a9614da99dd194c122e9252b35dafeb088b77b8baf6b1</sha256sum>
</artifact>
</verification>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -4,12 +4,12 @@
<remote-repository>
<option name="id" value="repositoryReleases" />
<option name="name" value="repositoryReleases" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositoryReleases" />
</remote-repository>
<remote-repository>
<option name="id" value="repositorySnapshots" />
<option name="name" value="repositorySnapshots" />
<option name="url" value="$TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
<option name="url" value="$REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT$/repositorySnapshots" />
</remote-repository>
</component>
</project>

View File

@@ -2,7 +2,7 @@
<library name="smallSampleLibRelease" type="repository">
<properties jar-repository-id="repositoryReleases" maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -2,7 +2,7 @@
<library name="smallSampleLibSnapshot" type="repository">
<properties jar-repository-id="repositorySnapshots" maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0-SNAPSHOT" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0-SNAPSHOT/smallSampleLib-1.0-SNAPSHOT.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -13,7 +13,7 @@
<library name="smallSampleTestLibModuleLevel" type="repository">
<properties jar-repository-id="repositoryReleases" maven-id="org.example.repository.library.utils.test:smallSampleLib:1.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
<root url="jar://$REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY$/org/example/repository/library/utils/test/smallSampleLib/1.0/smallSampleLib-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@@ -1,7 +1,6 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.jarRepository
import com.intellij.application.options.PathMacrosImpl
import com.intellij.openapi.application.PathMacros
import com.intellij.openapi.application.ex.PathManagerEx
import com.intellij.openapi.project.Project
@@ -22,14 +21,20 @@ import com.intellij.util.io.directoryContentOf
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.runBlocking
import org.junit.Before
import org.junit.ClassRule
import org.junit.Rule
import org.junit.Test
import org.junit.*
import java.nio.file.Path
class RepositoryLibraryUtilsTest {
companion object {
/**
* See .idea/libraries/ in testData
*/
private const val TEST_MAVEN_LOCAL_REPOSITORY_MACRO = "REPOSITORY_LIBRARY_UTILS_TEST_LOCAL_MAVEN_REPOSITORY"
/**
* See .idea/jarRepositories.xml in testData
*/
private const val TEST_REMOTE_REPOSITORIES_ROOT_MACRO = "REPOSITORY_LIBRARY_UTILS_TEST_REMOTE_REPOSITORIES_ROOT"
@JvmField
@ClassRule
val applicationRule = ApplicationRule()
@@ -39,6 +44,23 @@ class RepositoryLibraryUtilsTest {
val m2Directory = TemporaryDirectory()
private val m2DirectoryPath by lazy { m2Directory.createDir() }
@BeforeClass
@JvmStatic
fun beforeAll() {
val pathMacros: PathMacros = PathMacros.getInstance()
pathMacros.setMacro(TEST_MAVEN_LOCAL_REPOSITORY_MACRO, m2DirectoryPath.toString())
JarRepositoryManager.setLocalRepositoryPath(m2DirectoryPath.toFile())
}
@AfterClass
@JvmStatic
fun afterAll() {
val pathMacros: PathMacros = PathMacros.getInstance()
pathMacros.setMacro(TEST_MAVEN_LOCAL_REPOSITORY_MACRO, null)
pathMacros.setMacro(TEST_REMOTE_REPOSITORIES_ROOT_MACRO, null)
JarRepositoryManager.setLocalRepositoryPath(null)
}
}
@JvmField
@@ -61,12 +83,7 @@ class RepositoryLibraryUtilsTest {
m2DirectoryPath.createDirectory()
val pathMacros: PathMacros = PathMacros.getInstance()
/* tip: MAVEN_REPOSITORY macro is cached in JarRepositoryManager isn't updated each time */
pathMacros.setMacro(PathMacrosImpl.MAVEN_REPOSITORY, m2DirectoryPath.toString())
/* See .idea/jarRepositories.xml in testData */
pathMacros.setMacro("TEST_REMOTE_REPOSITORIES_ROOT", "file://$testRemoteRepositoriesRoot")
pathMacros.setMacro(TEST_REMOTE_REPOSITORIES_ROOT_MACRO, "file://$testRemoteRepositoriesRoot")
}
@Test