IDEA-180005 Configurations with same name but different type disappear after project reopening

This commit is contained in:
Vladimir Krivosheev
2017-10-12 13:22:11 +02:00
parent 05ec72ae34
commit 9bf41a6d78
6 changed files with 27 additions and 32 deletions
@@ -204,7 +204,7 @@ class SchemeManagerImpl<T : Any, in MUTABLE_SCHEME : T>(val fileSpec: String,
lazyPreloadScheme(bytes, isOldSchemeNaming) { name, parser ->
val attributeProvider = Function<String, String?> { parser.getAttributeValue(null, it) }
val schemeName = name
?: processor.getName(attributeProvider, FileUtilRt.getNameWithoutExtension(fileName))
?: processor.getSchemeKey(attributeProvider, FileUtilRt.getNameWithoutExtension(fileName))
?: throw RuntimeException("Name is missed:\n${bytes.toString(Charsets.UTF_8)}")
val dataHolder = SchemeDataHolderImpl(bytes, externalInfo)
@@ -286,17 +286,15 @@ class SchemeManagerImpl<T : Any, in MUTABLE_SCHEME : T>(val fileSpec: String,
val extension = getFileExtension(fileName, true)
val externalInfo = ExternalInfo(fileName.substring(0, fileName.length - extension.length), extension)
val schemeName = name
?: (processor as LazySchemeProcessor).getName(attributeProvider, externalInfo.fileNameWithoutExtension)
?: throw RuntimeException("Name is missed:\n${bytes.toString(Charsets.UTF_8)}")
val schemeKey = name
?: (processor as LazySchemeProcessor).getSchemeKey(attributeProvider, externalInfo.fileNameWithoutExtension)
?: throw RuntimeException("Name is missed:\n${bytes.toString(Charsets.UTF_8)}")
externalInfo.schemeName = schemeName
externalInfo.schemeKey = schemeKey
val scheme = (processor as LazySchemeProcessor).createScheme(SchemeDataHolderImpl(bytes, externalInfo), schemeName,
attributeProvider, true)
val scheme = (processor as LazySchemeProcessor).createScheme(SchemeDataHolderImpl(bytes, externalInfo), schemeKey, attributeProvider, true)
val oldInfo = schemeToInfo.put(scheme, externalInfo)
LOG.assertTrue(oldInfo == null)
val schemeKey = processor.getSchemeKey(scheme)
val oldScheme = schemeListManager.readOnlyExternalizableSchemes.put(schemeKey, scheme)
if (oldScheme != null) {
LOG.warn("Duplicated scheme ${schemeKey} - old: $oldScheme, new $scheme")
@@ -475,7 +473,7 @@ class SchemeManagerImpl<T : Any, in MUTABLE_SCHEME : T>(val fileSpec: String,
element?.let {
info.digest = it.digest()
}
info.schemeName = schemeName
info.schemeKey = schemeName
return info
}
@@ -485,7 +483,7 @@ class SchemeManagerImpl<T : Any, in MUTABLE_SCHEME : T>(val fileSpec: String,
val bytes = input.readBytes()
lazyPreloadScheme(bytes, isOldSchemeNaming) { name, parser ->
val attributeProvider = Function<String, String?> { parser.getAttributeValue(null, it) }
val schemeName = name ?: processor.getName(attributeProvider, fileNameWithoutExtension)
val schemeName = name ?: processor.getSchemeKey(attributeProvider, fileNameWithoutExtension)
if (schemeName == null) {
throw RuntimeException("Name is missed:\n${bytes.toString(Charsets.UTF_8)}")
}
@@ -721,7 +719,7 @@ class SchemeManagerImpl<T : Any, in MUTABLE_SCHEME : T>(val fileSpec: String,
externalInfo.setFileNameWithoutExtension(fileNameWithoutExtension, schemeExtension)
}
externalInfo.digest = newDigest
externalInfo.schemeName = processor.getSchemeKey(scheme)
externalInfo.schemeKey = processor.getSchemeKey(scheme)
}
private fun isEqualToBundledScheme(externalInfo: ExternalInfo?, newDigest: ByteArray, scheme: MUTABLE_SCHEME): Boolean {
@@ -766,7 +764,7 @@ class SchemeManagerImpl<T : Any, in MUTABLE_SCHEME : T>(val fileSpec: String,
private fun isRenamed(scheme: T): Boolean {
val info = schemeToInfo.get(scheme)
return info != null && processor.getSchemeKey(scheme) != info.schemeName
return info != null && processor.getSchemeKey(scheme) != info.schemeKey
}
private fun deleteFiles(errors: MutableList<Throwable>, filesToDelete: MutableSet<String>) {
@@ -66,7 +66,7 @@ private fun preload(isOldSchemeNaming: Boolean, parser: MXParser): String? {
internal class ExternalInfo(var fileNameWithoutExtension: String, var fileExtension: String?) {
// we keep it to detect rename
var schemeName: String? = null
var schemeKey: String? = null
var digest: ByteArray? = null
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2017 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.codeInspection.ex;
import com.intellij.codeHighlighting.HighlightDisplayLevel;
@@ -85,7 +71,7 @@ public class ApplicationInspectionProfileManager extends BaseInspectionProfileMa
mySchemeManager = schemeManagerFactory.create(INSPECTION_DIR, new InspectionProfileProcessor() {
@NotNull
@Override
public String getName(@NotNull Function<String, String> attributeProvider, @NotNull String fileNameWithoutExtension) {
public String getSchemeKey(@NotNull Function<String, String> attributeProvider, @NotNull String fileNameWithoutExtension) {
return fileNameWithoutExtension;
}
@@ -15,7 +15,7 @@ private val LOG = logger<RunConfigurationSchemeManager>()
internal class RunConfigurationSchemeManager(private val manager: RunManagerImpl, private val isShared: Boolean) :
LazySchemeProcessor<RunnerAndConfigurationSettingsImpl, RunnerAndConfigurationSettingsImpl>(), SchemeContentChangedHandler<RunnerAndConfigurationSettingsImpl> {
override fun getSchemeKey(scheme: RunnerAndConfigurationSettingsImpl): String {
return scheme.name
return if (isShared) scheme.name else "${scheme.type.id}-${scheme.name}"
}
override fun createScheme(dataHolder: SchemeDataHolder<RunnerAndConfigurationSettingsImpl>, name: String, attributeProvider: Function<String, String?>, isBundled: Boolean): RunnerAndConfigurationSettingsImpl {
@@ -53,7 +53,7 @@ internal class RunConfigurationSchemeManager(private val manager: RunManagerImpl
return element
}
override fun getName(attributeProvider: Function<String, String?>, fileNameWithoutExtension: String): String? {
override fun getSchemeKey(attributeProvider: Function<String, String?>, fileNameWithoutExtension: String): String? {
var name = attributeProvider.apply("name")
if (name == "<template>" || name == null) {
attributeProvider.apply("type")?.let {
@@ -63,6 +63,12 @@ internal class RunConfigurationSchemeManager(private val manager: RunManagerImpl
name += " of type ${it}"
}
}
else if (name != null && !isShared) {
val typeId = attributeProvider.apply("type")
LOG.assertTrue(typeId != null)
return "$typeId-${name}"
}
return name
}
@@ -644,6 +644,11 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi
name += " of type ${it}"
}
}
else if (name != null) {
val typeId = it.getAttributeValue("type")
LOG.assertTrue(typeId != null)
name = "$typeId-${name}"
}
// in case if broken configuration, do not fail, just generate name
if (name == null) {
@@ -59,7 +59,7 @@ interface SchemeContentChangedHandler<MUTABLE_SCHEME> {
}
abstract class LazySchemeProcessor<SCHEME, MUTABLE_SCHEME : SCHEME>(private val nameAttribute: String = "name") : SchemeProcessor<SCHEME, MUTABLE_SCHEME>() {
open fun getName(attributeProvider: Function<String, String?>, fileNameWithoutExtension: String): String? {
open fun getSchemeKey(attributeProvider: Function<String, String?>, fileNameWithoutExtension: String): String? {
return attributeProvider.apply(nameAttribute)
}