Better diagnostic for file absence in updateJar (KT-22272)
#EA-96117 Fixed #KT-22272 Fixed
This commit is contained in:
+19
-6
@@ -15,6 +15,7 @@ import com.intellij.openapi.vfs.LocalFileSystem
|
|||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import org.jetbrains.kotlin.idea.configuration.*
|
import org.jetbrains.kotlin.idea.configuration.*
|
||||||
import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil
|
import org.jetbrains.kotlin.idea.framework.JavaRuntimeDetectionUtil
|
||||||
|
import org.jetbrains.kotlin.idea.framework.isExternalLibrary
|
||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
|
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -64,12 +65,21 @@ private fun updateJar(
|
|||||||
libraryJarDescriptor: LibraryJarDescriptor
|
libraryJarDescriptor: LibraryJarDescriptor
|
||||||
) {
|
) {
|
||||||
val fileToReplace = libraryJarDescriptor.findExistingJar(library)
|
val fileToReplace = libraryJarDescriptor.findExistingJar(library)
|
||||||
|
if (fileToReplace == null) {
|
||||||
|
if (libraryJarDescriptor.shouldExist) {
|
||||||
|
error(
|
||||||
|
"Update for library was requested, but file for replacement isn't present: \n" +
|
||||||
|
"name = ${library.name}\n" +
|
||||||
|
"isExternal = `${isExternalLibrary(library)}`\n" +
|
||||||
|
"entries = ${library.getUrls(libraryJarDescriptor.orderRootType)}\n" +
|
||||||
|
"buildSystems = ${project.allModules().map { module -> module.getBuildSystemType() }.distinct()}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (fileToReplace == null && !libraryJarDescriptor.shouldExist) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val oldUrl = fileToReplace?.url
|
val oldUrl = fileToReplace.url
|
||||||
val jarPath: File = libraryJarDescriptor.getPathInPlugin()
|
val jarPath: File = libraryJarDescriptor.getPathInPlugin()
|
||||||
|
|
||||||
if (!jarPath.exists()) {
|
if (!jarPath.exists()) {
|
||||||
@@ -77,7 +87,7 @@ private fun updateJar(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val jarFileToReplace = getLocalJar(fileToReplace)!!
|
val jarFileToReplace = getLocalJar(fileToReplace) ?: error("Couldn't find local jar for ${fileToReplace.canonicalPath}")
|
||||||
val newVFile = try {
|
val newVFile = try {
|
||||||
replaceFile(jarPath, jarFileToReplace)
|
replaceFile(jarPath, jarFileToReplace)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
@@ -93,10 +103,13 @@ private fun updateJar(
|
|||||||
val model = library.modifiableModel
|
val model = library.modifiableModel
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
try {
|
try {
|
||||||
if (oldUrl != null) {
|
model.removeRoot(oldUrl, libraryJarDescriptor.orderRootType)
|
||||||
model.removeRoot(oldUrl, libraryJarDescriptor.orderRootType)
|
|
||||||
|
val newRoot = JarFileSystem.getInstance().getJarRootForLocalFile(newVFile) ?: run {
|
||||||
|
Messages.showErrorDialog(project, "Failed to find root for file: ${newVFile.canonicalPath}", "Library update failed")
|
||||||
|
return@runWriteAction
|
||||||
}
|
}
|
||||||
val newRoot = JarFileSystem.getInstance().getJarRootForLocalFile(newVFile)!!
|
|
||||||
model.addRoot(newRoot, libraryJarDescriptor.orderRootType)
|
model.addRoot(newRoot, libraryJarDescriptor.orderRootType)
|
||||||
} finally {
|
} finally {
|
||||||
model.commit()
|
model.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user