diff --git a/plugins/copyright/src/com/intellij/copyright/CopyrightManager.kt b/plugins/copyright/src/com/intellij/copyright/CopyrightManager.kt index a256322d348f..55c1e7ce092f 100644 --- a/plugins/copyright/src/com/intellij/copyright/CopyrightManager.kt +++ b/plugins/copyright/src/com/intellij/copyright/CopyrightManager.kt @@ -1,6 +1,4 @@ -// 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. +// Copyright 2000-2018 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.copyright import com.intellij.configurationStore.* @@ -83,6 +81,10 @@ class CopyrightManager @JvmOverloads constructor(private val project: Project, s } override fun isSchemeFile(name: CharSequence) = !StringUtil.equals(name, "profiles_settings.xml") + + override fun getSchemeKey(attributeProvider: Function, fileNameWithoutExtension: String): String? { + return super.getSchemeKey(attributeProvider, fileNameWithoutExtension) ?: fileNameWithoutExtension + } }, schemeNameToFileName = OLD_NAME_CONVERTER, streamProvider = schemeManagerIprProvider) init { @@ -258,6 +260,9 @@ private class CopyrightLazySchemeWrapper(name: String, } element.deserializeInto(scheme) + // use effective name instead of probably missed from the serialized + // https://youtrack.jetbrains.com/v2/issue/IDEA-186546 + scheme.profileName = name @Suppress("DEPRECATION") val allowReplaceKeyword = scheme.allowReplaceKeyword diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt b/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt index 0d99c71db638..a436627555dc 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/CopyrightProfile.kt @@ -1,6 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 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.maddyhome.idea.copyright import com.intellij.configurationStore.SerializableScheme @@ -22,6 +20,7 @@ val DEFAULT_COPYRIGHT_NOTICE: String = EntityUtil.encode( class CopyrightProfile @JvmOverloads constructor(profileName: String? = null) : ExternalizableScheme, BaseState(), SerializableScheme { // ugly name to preserve compatibility // must be not private because otherwise binding is not created for private accessor + @Suppress("MemberVisibilityCanBePrivate") @get:OptionTag("myName") var profileName by string() diff --git a/plugins/copyright/testSrc/com/intellij/copyright/CopyrightManagerTest.kt b/plugins/copyright/testSrc/com/intellij/copyright/CopyrightManagerTest.kt index adfe16a222a0..1836fc87917f 100644 --- a/plugins/copyright/testSrc/com/intellij/copyright/CopyrightManagerTest.kt +++ b/plugins/copyright/testSrc/com/intellij/copyright/CopyrightManagerTest.kt @@ -1,10 +1,9 @@ -// 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. +// Copyright 2000-2018 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.copyright import com.intellij.configurationStore.SchemeManagerFactoryBase import com.intellij.testFramework.ProjectRule import com.intellij.testFramework.assertions.Assertions.assertThat -import com.intellij.testFramework.assertions.Assertions.catchThrowable import com.intellij.testFramework.rules.InMemoryFsRule import com.intellij.util.io.write import com.maddyhome.idea.copyright.CopyrightProfile @@ -34,7 +33,7 @@ internal class CopyrightManagerTest { } @Test - fun serializeEmpy() { + fun serializeEmpty() { val scheme = CopyrightProfile() assertThat(scheme.writeScheme()).isEqualTo("""""") } @@ -66,20 +65,21 @@ internal class CopyrightManagerTest { } @Test - fun empty() { - val schemeFile = fsRule.fs.getPath("copyright/openapi.xml") + fun `use file name if scheme name missed`() { + val schemeFile = fsRule.fs.getPath("copyright/FooBar.xml") val schemeData = """ - + + """.trimIndent() schemeFile.write(schemeData) val schemeManagerFactory = SchemeManagerFactoryBase.TestSchemeManagerFactory(fsRule.fs.getPath("")) val profileManager = CopyrightManager(projectRule.project, schemeManagerFactory, isSupportIprProjects = false /* otherwise scheme will be not loaded from our memory fs */) - val catchThrowable = catchThrowable { profileManager.loadSchemes() } - assertThat(catchThrowable) - .isInstanceOf(AssertionError::class.java) - .hasMessageStartingWith("Cannot read scheme openapi.xml") - .hasCauseExactlyInstanceOf(RuntimeException::class.java) + profileManager.loadSchemes() + val copyrights = profileManager.getCopyrights() + assertThat(copyrights).hasSize(1) + assertThat(copyrights.first().name).isEqualTo("FooBar") } } \ No newline at end of file