[Workspace Model] WM-T-67 Fix exception after removing module with a module library

GitOrigin-RevId: ff11c1e9414d00252c0d07a8b22426189d3b8cb0
This commit is contained in:
Alex Plate
2020-07-17 19:45:06 +03:00
committed by intellij-monorepo-bot
parent a2c8f3ed4a
commit 27e0a3e224
16 changed files with 221 additions and 2 deletions

View File

@@ -0,0 +1 @@
sampleProjectName

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="?*.properties" />
<entry name="?*.xml" />
<entry name="?*.gif" />
<entry name="?*.png" />
<entry name="?*.jpeg" />
<entry name="?*.jpg" />
<entry name="?*.html" />
<entry name="?*.dtd" />
<entry name="?*.tld" />
<entry name="?*.ftl" />
</wildcardResourcePatterns>
<annotationProcessing enabled="false" useClasspath="true" />
</component>
</project>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="UTF-8">
<file url="file://$PROJECT_DIR$/util" charset="windows-1251" />
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" project-jdk-name="1.6" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/main.iml" filepath="$PROJECT_DIR$/main.iml" />
</modules>
</component>
</project>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1 @@
sampleProjectName

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="?*.properties" />
<entry name="?*.xml" />
<entry name="?*.gif" />
<entry name="?*.png" />
<entry name="?*.jpeg" />
<entry name="?*.jpg" />
<entry name="?*.html" />
<entry name="?*.dtd" />
<entry name="?*.tld" />
<entry name="?*.ftl" />
</wildcardResourcePatterns>
<annotationProcessing enabled="false" useClasspath="true" />
</component>
</project>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="true" defaultCharsetForPropertiesFiles="UTF-8">
<file url="file://$PROJECT_DIR$/util" charset="windows-1251" />
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

View File

@@ -0,0 +1,11 @@
<component name="libraryTable">
<library name="log4j">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/log4j.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/lib/log4j.zip!/" />
</SOURCES>
</library>
</component>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" project-jdk-name="1.6" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/main.iml" filepath="$PROJECT_DIR$/main.iml" />
<module fileurl="file://$PROJECT_DIR$/util/util.iml" filepath="$PROJECT_DIR$/util/util.iml" />
</modules>
</component>
</project>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<output url="file://$MODULE_DIR$/../out/production-util" />
<output-test url="file://$MODULE_DIR$/../out/test-util" />
<exclude-output />
<annotation-paths>
<root url="file://$MODULE_DIR$/../lib/anno" />
</annotation-paths>
<javadoc-paths>
<root url="file://$MODULE_DIR$/../lib/javadoc" />
</javadoc-paths>
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="xxx" />
<excludeFolder url="file://$MODULE_DIR$/exc" />
<excludePattern pattern="*.xml" />
<excludePattern pattern="cvs" />
</content>
<orderEntry type="jdk" jdkName="1.5" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../lib/junit.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@@ -0,0 +1,70 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.configurationStore
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ex.PathManagerEx
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.ApplicationRule
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.TemporaryDirectory
import com.intellij.testFramework.createOrLoadProject
import kotlinx.coroutines.runBlocking
import org.junit.ClassRule
import org.junit.Rule
import org.junit.Test
import java.nio.file.Path
import java.nio.file.Paths
/**
* This class has no specific Java test. It's located in intellij.java.tests module because if Java plugin is enabled additional elements
* are added to iml file (e.g. 'exclude-output' tag) so if this test is located in a platform module it'll give different results dependening
* on whether there is Java plugin in runtime classpath or not.
*/
class ReloadProjectTest {
companion object {
@JvmField
@ClassRule
val appRule = ApplicationRule()
}
@JvmField
@Rule
val tempDirectory = TemporaryDirectory()
@Test
internal fun `reload module with module library`() {
loadProject("removeModuleWithModuleLibrary/before") { project ->
val base = Paths.get(project.basePath!!)
FileUtil.copyDir(testDataRoot.resolve("removeModuleWithModuleLibrary/after").toFile(), base.toFile())
VfsUtil.markDirtyAndRefresh(false, true, true, VfsUtil.findFile(base, true))
ApplicationManager.getApplication().invokeAndWait {
PlatformTestUtil.saveProject(project)
}
}
}
private val testDataRoot
get() = Paths.get(PathManagerEx.getCommunityHomePath()).resolve("java/java-tests/testData/reloading")
private fun loadProject(testDataDirName: String, checkProject: (Project) -> Unit) {
return loadProject(testDataRoot.resolve(testDataDirName), checkProject)
}
private fun loadProject(projectPath: Path, checkProject: (Project) -> Unit) {
@Suppress("RedundantSuspendModifier")
suspend fun copyProjectFiles(dir: VirtualFile): Path {
val projectDir = VfsUtil.virtualToIoFile(dir)
FileUtil.copyDir(projectPath.toFile(), projectDir)
VfsUtil.markDirtyAndRefresh(false, true, true, dir)
return projectDir.toPath()
}
runBlocking {
createOrLoadProject(tempDirectory, ::copyProjectFiles, loadComponentState = true, useDefaultProjectSettings = false) {
checkProject(it)
}
}
}
}

View File

@@ -76,10 +76,10 @@ internal class ModuleLibraryTableBridgeImpl(private val moduleBridge: ModuleBrid
override fun dispose() {
for (library in libraryIterator) {
Disposer.dispose(library)
if (!Disposer.isDisposed(library)) Disposer.dispose(library)
}
}
override val module: Module
get() = moduleBridge
}
}