mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
scheme-based copyright manager
This commit is contained in:
+2
-8
@@ -21,6 +21,7 @@ import com.intellij.codeInspection.ex.InspectionToolRegistrar
|
||||
import com.intellij.configurationStore.SchemeDataHolder
|
||||
import com.intellij.configurationStore.SchemeManagerIprProvider
|
||||
import com.intellij.configurationStore.digest
|
||||
import com.intellij.configurationStore.wrapState
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
@@ -32,7 +33,6 @@ import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.project.ProjectManagerListener
|
||||
import com.intellij.openapi.startup.StartupActivity
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.packageDependencies.DependencyValidationManager
|
||||
import com.intellij.profile.Profile
|
||||
@@ -264,13 +264,7 @@ class ProjectInspectionProfileManager(val project: Project,
|
||||
|
||||
severityRegistrar.writeExternal(result)
|
||||
|
||||
if (JDOMUtil.isEmpty(result)) {
|
||||
result.name = "state"
|
||||
return result
|
||||
}
|
||||
else {
|
||||
return Element("state").addContent(result)
|
||||
}
|
||||
return wrapState(result)
|
||||
}
|
||||
|
||||
override fun getScopesManager() = scopeManager
|
||||
|
||||
@@ -370,12 +370,16 @@ class SchemeManagerImpl<T : Scheme, MUTABLE_SCHEME : T>(val fileSpec: String,
|
||||
|
||||
override fun updateDigest(scheme: MUTABLE_SCHEME) {
|
||||
try {
|
||||
externalInfo.digest = (processor.writeScheme(scheme) as Element).digest()
|
||||
updateDigest(processor.writeScheme(scheme) as Element)
|
||||
}
|
||||
catch (e: WriteExternalException) {
|
||||
LOG.error("Cannot update digest", e)
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateDigest(data: Element) {
|
||||
externalInfo.digest = data.digest()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadScheme(fileName: String, input: InputStream, schemes: MutableList<T>, filesToDelete: MutableSet<String>? = null): MUTABLE_SCHEME? {
|
||||
@@ -438,7 +442,7 @@ class SchemeManagerImpl<T : Scheme, MUTABLE_SCHEME : T>(val fileSpec: String,
|
||||
XmlPullParser.START_TAG -> {
|
||||
if (!isUseOldFileNameSanitize || parser.name != "component") {
|
||||
var name: String? = null
|
||||
if (isUseOldFileNameSanitize && parser.name == "profile") {
|
||||
if (isUseOldFileNameSanitize && (parser.name == "profile" || parser.name == "copyright")) {
|
||||
eventType = parser.next()
|
||||
findName@ while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||
when (eventType) {
|
||||
|
||||
@@ -15,8 +15,11 @@
|
||||
*/
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.options.ExternalizableSchemeAdapter
|
||||
import com.intellij.openapi.options.Scheme
|
||||
import com.intellij.openapi.options.SchemeProcessor
|
||||
import com.intellij.openapi.options.SchemeState
|
||||
import com.intellij.util.isEmpty
|
||||
import org.jdom.Element
|
||||
import java.io.OutputStream
|
||||
import java.security.MessageDigest
|
||||
@@ -29,6 +32,8 @@ interface SchemeDataHolder<in MUTABLE_SCHEME : Scheme> {
|
||||
fun read(): Element
|
||||
|
||||
fun updateDigest(scheme: MUTABLE_SCHEME)
|
||||
|
||||
fun updateDigest(data: Element)
|
||||
}
|
||||
|
||||
interface SerializableScheme {
|
||||
@@ -84,4 +89,29 @@ fun Element.digest(): ByteArray {
|
||||
val digest = MessageDigest.getInstance("SHA-1")
|
||||
serializeElementToBinary(this, DigestOutputStream(digest))
|
||||
return digest.digest()
|
||||
}
|
||||
|
||||
abstract class SchemeWrapper<out T : Scheme>(name: String) : ExternalizableSchemeAdapter(), SerializableScheme {
|
||||
protected abstract val lazyScheme: Lazy<T>
|
||||
|
||||
val scheme: T
|
||||
get() = lazyScheme.value
|
||||
|
||||
val schemeState: SchemeState
|
||||
get() = if (lazyScheme.isInitialized()) SchemeState.POSSIBLY_CHANGED else SchemeState.UNCHANGED
|
||||
|
||||
init {
|
||||
this.name = name
|
||||
}
|
||||
}
|
||||
|
||||
fun wrapState(element: Element): Element {
|
||||
if (element.isEmpty()) {
|
||||
element.name = "state"
|
||||
return element
|
||||
}
|
||||
|
||||
val wrapper = Element("state")
|
||||
wrapper.addContent(element)
|
||||
return wrapper
|
||||
}
|
||||
@@ -82,6 +82,8 @@ fun Element.element(name: String): Element {
|
||||
return element
|
||||
}
|
||||
|
||||
fun Element.attribute(name: String, value: String?): Element = setAttribute(name, value)
|
||||
|
||||
fun <T> Element.remove(name: String, transform: (child: Element) -> T): List<T> {
|
||||
val result = SmartList<T>()
|
||||
val groupIterator = getContent(ElementFilter(name)).iterator()
|
||||
|
||||
@@ -14,5 +14,6 @@
|
||||
<orderEntry type="module" module-name="openapi" />
|
||||
<orderEntry type="library" name="Velocity" level="project" />
|
||||
<orderEntry type="module" module-name="xml" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
package com.intellij.copyright
|
||||
|
||||
import com.intellij.configurationStore.LazySchemeProcessor
|
||||
import com.intellij.configurationStore.SchemeDataHolder
|
||||
import com.intellij.configurationStore.SchemeWrapper
|
||||
import com.intellij.configurationStore.wrapState
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.components.PersistentStateComponent
|
||||
import com.intellij.openapi.components.State
|
||||
import com.intellij.openapi.components.Storage
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.editor.EditorFactory
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter
|
||||
import com.intellij.openapi.editor.event.DocumentEvent
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.options.SchemeManagerFactory
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.ProjectRootManager
|
||||
import com.intellij.openapi.startup.StartupActivity
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.InvalidDataException
|
||||
import com.intellij.openapi.util.WriteExternalException
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.packageDependencies.DependencyValidationManager
|
||||
import com.intellij.project.isDirectoryBased
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.util.attribute
|
||||
import com.intellij.util.element
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile
|
||||
import com.maddyhome.idea.copyright.actions.UpdateCopyrightProcessor
|
||||
import com.maddyhome.idea.copyright.options.LanguageOptions
|
||||
import com.maddyhome.idea.copyright.options.Options
|
||||
import com.maddyhome.idea.copyright.util.FileTypeUtil
|
||||
import com.maddyhome.idea.copyright.util.NewFileTracker
|
||||
import org.jdom.Element
|
||||
import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import java.util.function.Function
|
||||
|
||||
private const val DEFAULT = "default"
|
||||
private const val MODULE2COPYRIGHT = "module2copyright"
|
||||
private const val COPYRIGHT = "copyright"
|
||||
private const val ELEMENT = "element"
|
||||
private const val MODULE = "module"
|
||||
|
||||
private val LOG = Logger.getInstance(CopyrightManager::class.java)
|
||||
|
||||
@State(name = "CopyrightManager", storages = arrayOf(Storage(value = "copyright/profiles_settings.xml", exclusive = true)))
|
||||
class CopyrightManager(private val project: Project, schemeManagerFactory: SchemeManagerFactory) : PersistentStateComponent<Element> {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun getInstance(project: Project) = project.service<CopyrightManager>()
|
||||
}
|
||||
|
||||
var defaultCopyright: CopyrightProfile? = null
|
||||
val scopeToCopyright = LinkedHashMap<String, String>()
|
||||
val options = Options()
|
||||
|
||||
val schemeManager = schemeManagerFactory.create("copyright", object : LazySchemeProcessor<SchemeWrapper<CopyrightProfile>, SchemeWrapper<CopyrightProfile>>() {
|
||||
override fun createScheme(dataHolder: SchemeDataHolder<SchemeWrapper<CopyrightProfile>>,
|
||||
name: String,
|
||||
attributeProvider: Function<String, String?>): SchemeWrapper<CopyrightProfile> {
|
||||
return LazySchemeWrapper(name, dataHolder, schemeWriter)
|
||||
}
|
||||
|
||||
override fun getState(scheme: SchemeWrapper<CopyrightProfile>) = scheme.schemeState
|
||||
|
||||
override fun isSchemeFile(name: CharSequence) = !StringUtil.equals(name, "profiles_settings.xml")
|
||||
}, isUseOldFileNameSanitize = true)
|
||||
|
||||
init {
|
||||
val app = ApplicationManager.getApplication()
|
||||
if (project.isDirectoryBased || !app.isUnitTestMode) {
|
||||
schemeManager.loadSchemes()
|
||||
}
|
||||
}
|
||||
|
||||
fun mapCopyright(scopeName: String, copyrightProfileName: String) {
|
||||
scopeToCopyright.put(scopeName, copyrightProfileName)
|
||||
}
|
||||
|
||||
fun unmapCopyright(scopeName: String) {
|
||||
scopeToCopyright.remove(scopeName)
|
||||
}
|
||||
|
||||
fun hasAnyCopyrights(): Boolean {
|
||||
return defaultCopyright != null || !scopeToCopyright.isEmpty()
|
||||
}
|
||||
|
||||
override fun getState(): Element? {
|
||||
val state = Element("settings")
|
||||
try {
|
||||
if (!scopeToCopyright.isEmpty()) {
|
||||
val map = Element(MODULE2COPYRIGHT)
|
||||
for ((scopeName, profileName) in scopeToCopyright) {
|
||||
map.element(ELEMENT)
|
||||
.attribute(MODULE, scopeName)
|
||||
.attribute(COPYRIGHT, profileName)
|
||||
}
|
||||
state.addContent(map)
|
||||
}
|
||||
|
||||
options.writeExternal(state)
|
||||
}
|
||||
catch (e: WriteExternalException) {
|
||||
LOG.error(e)
|
||||
return null
|
||||
}
|
||||
|
||||
if (defaultCopyright != null) {
|
||||
state.setAttribute(DEFAULT, defaultCopyright!!.name)
|
||||
}
|
||||
|
||||
return wrapState(state)
|
||||
}
|
||||
|
||||
override fun loadState(state: Element) {
|
||||
val moduleToCopyright = state.getChild(MODULE2COPYRIGHT)
|
||||
if (moduleToCopyright != null) {
|
||||
for (element in moduleToCopyright.getChildren(ELEMENT)) {
|
||||
scopeToCopyright.put(element.getAttributeValue(MODULE), element.getAttributeValue(COPYRIGHT))
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
defaultCopyright = schemeManager.findSchemeByName(state.getAttributeValue(DEFAULT).orEmpty())?.scheme
|
||||
options.readExternal(state)
|
||||
}
|
||||
catch (e: InvalidDataException) {
|
||||
LOG.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
fun addCopyright(profile: CopyrightProfile) {
|
||||
schemeManager.addScheme(InitializedSchemeWrapper(profile, schemeWriter))
|
||||
}
|
||||
|
||||
fun getCopyrights(): Collection<CopyrightProfile> = schemeManager.allSchemes.map { it.scheme }
|
||||
|
||||
fun clearMappings() {
|
||||
scopeToCopyright.clear()
|
||||
}
|
||||
|
||||
fun removeCopyright(copyrightProfile: CopyrightProfile) {
|
||||
schemeManager.removeScheme(copyrightProfile.name)
|
||||
|
||||
val it = scopeToCopyright.keys.iterator()
|
||||
while (it.hasNext()) {
|
||||
if (scopeToCopyright.get(it.next()) == copyrightProfile.name) {
|
||||
it.remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun replaceCopyright(name: String, profile: CopyrightProfile) {
|
||||
if (defaultCopyright?.name == name) {
|
||||
defaultCopyright = profile
|
||||
}
|
||||
|
||||
val existingScheme = schemeManager.findSchemeByName(name)
|
||||
if (existingScheme == null) {
|
||||
addCopyright(profile)
|
||||
}
|
||||
else {
|
||||
existingScheme.scheme.copyFrom(profile)
|
||||
}
|
||||
}
|
||||
|
||||
fun getCopyrightOptions(file: PsiFile): CopyrightProfile? {
|
||||
val virtualFile = file.virtualFile
|
||||
if (virtualFile == null || options.getOptions(virtualFile.fileType.name).getFileTypeOverride() == LanguageOptions.NO_COPYRIGHT) {
|
||||
return null
|
||||
}
|
||||
|
||||
val validationManager = DependencyValidationManager.getInstance(project)
|
||||
for (scopeName in scopeToCopyright.keys) {
|
||||
val packageSet = validationManager.getScope(scopeName)?.value ?: continue
|
||||
if (packageSet.contains(file, validationManager)) {
|
||||
scopeToCopyright.get(scopeName)?.let { schemeManager.findSchemeByName(it) }?.let { return it.scheme }
|
||||
}
|
||||
}
|
||||
return defaultCopyright
|
||||
}
|
||||
}
|
||||
|
||||
private class CopyrightManagerPostStartupActivity : StartupActivity {
|
||||
val newFileTracker = NewFileTracker()
|
||||
|
||||
override fun runActivity(project: Project) {
|
||||
Disposer.register(project, Disposable { newFileTracker.clear() })
|
||||
|
||||
EditorFactory.getInstance().eventMulticaster.addDocumentListener(object : DocumentAdapter() {
|
||||
override fun documentChanged(e: DocumentEvent) {
|
||||
val virtualFile = FileDocumentManager.getInstance().getFile(e.document) ?: return
|
||||
val module = ProjectRootManager.getInstance(project).fileIndex.getModuleForFile(virtualFile) ?: return
|
||||
if (!newFileTracker.poll(virtualFile) ||
|
||||
!FileTypeUtil.getInstance().isSupportedFile(virtualFile) ||
|
||||
PsiManager.getInstance(project).findFile(virtualFile) == null) {
|
||||
return
|
||||
}
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(Runnable {
|
||||
if (!virtualFile.isValid) {
|
||||
return@Runnable
|
||||
}
|
||||
|
||||
val file = PsiManager.getInstance(project).findFile(virtualFile)
|
||||
if (file != null && file.isWritable) {
|
||||
CopyrightManager.getInstance(project).getCopyrightOptions(file)?.let {
|
||||
UpdateCopyrightProcessor(project, module, file).run()
|
||||
}
|
||||
}
|
||||
}, ModalityState.NON_MODAL, project.disposed)
|
||||
}
|
||||
}, project)
|
||||
}
|
||||
}
|
||||
|
||||
private fun wrapScheme(element: Element): Element {
|
||||
val wrapper = Element("component")
|
||||
.attribute("name", "CopyrightManager")
|
||||
wrapper.addContent(element)
|
||||
return wrapper
|
||||
}
|
||||
|
||||
private val schemeWriter = { scheme: CopyrightProfile ->
|
||||
val element = Element("copyright")
|
||||
scheme.writeExternal(element)
|
||||
wrapScheme(element)
|
||||
}
|
||||
|
||||
private class InitializedSchemeWrapper(scheme: CopyrightProfile, private val writer: (scheme: CopyrightProfile) -> Element) : SchemeWrapper<CopyrightProfile>(scheme.name) {
|
||||
override val lazyScheme = lazyOf(scheme)
|
||||
|
||||
override fun writeScheme() = writer(scheme)
|
||||
}
|
||||
|
||||
private class LazySchemeWrapper(name: String,
|
||||
dataHolder: SchemeDataHolder<SchemeWrapper<CopyrightProfile>>,
|
||||
private val writer: (scheme: CopyrightProfile) -> Element,
|
||||
private val subStateTagName: String = "copyright") : SchemeWrapper<CopyrightProfile>(name) {
|
||||
private val dataHolder = AtomicReference(dataHolder)
|
||||
|
||||
override val lazyScheme = lazy {
|
||||
val scheme = CopyrightProfile()
|
||||
@Suppress("NAME_SHADOWING")
|
||||
val dataHolder = this.dataHolder.getAndSet(null)
|
||||
val element = dataHolder.read().getChild(subStateTagName)
|
||||
scheme.readExternal(element)
|
||||
dataHolder.updateDigest(writer(scheme))
|
||||
scheme
|
||||
}
|
||||
|
||||
override fun writeScheme(): Element {
|
||||
val dataHolder = dataHolder.get()
|
||||
return if (dataHolder == null) writer(scheme) else dataHolder.read()
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,50 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
|
||||
<idea-plugin version="2">
|
||||
<name>Copyright</name>
|
||||
<id>com.intellij.copyright</id>
|
||||
<description>
|
||||
Copyright Notice. This plugin is used to ensure files in a project or module have
|
||||
a consistent copyright notice.
|
||||
</description>
|
||||
<version>8.1</version>
|
||||
<vendor>JetBrains</vendor>
|
||||
<depends optional="true" config-file="java.xml">com.intellij.modules.java</depends>
|
||||
<name>Copyright</name>
|
||||
<id>com.intellij.copyright</id>
|
||||
<description>
|
||||
Copyright Notice. This plugin is used to ensure files in a project or module have a consistent copyright notice.
|
||||
</description>
|
||||
<version>8.1</version>
|
||||
<vendor>JetBrains</vendor>
|
||||
<depends optional="true" config-file="java.xml">com.intellij.modules.java</depends>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<projectConfigurable groupId="editor" groupWeight="110" dynamic="true" displayName="Copyright" id="copyright" instance="com.maddyhome.idea.copyright.ui.CopyrightProjectConfigurable"/>
|
||||
<checkinHandlerFactory implementation="com.maddyhome.idea.copyright.actions.UpdateCopyrightCheckinHandlerFactory"/>
|
||||
<applicationService serviceInterface="com.maddyhome.idea.copyright.util.FileTypeUtil"
|
||||
serviceImplementation="com.maddyhome.idea.copyright.util.FileTypeUtil"/>
|
||||
<projectService serviceInterface="com.maddyhome.idea.copyright.actions.UpdateCopyrightCheckinHandlerState"
|
||||
serviceImplementation="com.maddyhome.idea.copyright.actions.UpdateCopyrightCheckinHandlerState"/>
|
||||
</extensions>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<projectConfigurable groupId="editor" groupWeight="110" dynamic="true" displayName="Copyright" id="copyright"
|
||||
instance="com.maddyhome.idea.copyright.ui.CopyrightProjectConfigurable"/>
|
||||
<checkinHandlerFactory implementation="com.maddyhome.idea.copyright.actions.UpdateCopyrightCheckinHandlerFactory"/>
|
||||
<applicationService serviceInterface="com.maddyhome.idea.copyright.util.FileTypeUtil"
|
||||
serviceImplementation="com.maddyhome.idea.copyright.util.FileTypeUtil"/>
|
||||
<projectService serviceInterface="com.maddyhome.idea.copyright.actions.UpdateCopyrightCheckinHandlerState"
|
||||
serviceImplementation="com.maddyhome.idea.copyright.actions.UpdateCopyrightCheckinHandlerState"/>
|
||||
<postStartupActivity implementation="com.intellij.copyright.CopyrightManagerPostStartupActivity"/>
|
||||
|
||||
<project-components>
|
||||
<component>
|
||||
<implementation-class>com.maddyhome.idea.copyright.CopyrightManager</implementation-class>
|
||||
<loadForDefaultProject/>
|
||||
</component>
|
||||
</project-components>
|
||||
<projectService serviceImplementation="com.intellij.copyright.CopyrightManager"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij.copyright">
|
||||
<updater filetype="XML" implementationClass="com.maddyhome.idea.copyright.psi.UpdateXmlCopyrightsProvider"/>
|
||||
<updater filetype="HTML" implementationClass="com.maddyhome.idea.copyright.psi.UpdateXmlCopyrightsProvider"/>
|
||||
</extensions>
|
||||
<extensionPoints>
|
||||
<extensionPoint name="updater" beanClass="com.intellij.openapi.fileTypes.FileTypeExtensionPoint">
|
||||
<with attribute="implementationClass" implements="com.maddyhome.idea.copyright.psi.UpdateCopyrightsProvider"/>
|
||||
</extensionPoint>
|
||||
<extensionPoint name="variablesProvider" beanClass="com.intellij.openapi.fileTypes.FileTypeExtensionPoint">
|
||||
<with attribute="implementationClass" implements="com.maddyhome.idea.copyright.pattern.CopyrightVariablesProvider"/>
|
||||
</extensionPoint>
|
||||
|
||||
</extensionPoints>
|
||||
<extensions defaultExtensionNs="com.intellij.copyright">
|
||||
<updater filetype="XML" implementationClass="com.maddyhome.idea.copyright.psi.UpdateXmlCopyrightsProvider"/>
|
||||
<updater filetype="HTML" implementationClass="com.maddyhome.idea.copyright.psi.UpdateXmlCopyrightsProvider"/>
|
||||
</extensions>
|
||||
<extensionPoints>
|
||||
<extensionPoint name="updater" beanClass="com.intellij.openapi.fileTypes.FileTypeExtensionPoint">
|
||||
<with attribute="implementationClass" implements="com.maddyhome.idea.copyright.psi.UpdateCopyrightsProvider"/>
|
||||
</extensionPoint>
|
||||
<extensionPoint name="variablesProvider" beanClass="com.intellij.openapi.fileTypes.FileTypeExtensionPoint">
|
||||
<with attribute="implementationClass" implements="com.maddyhome.idea.copyright.pattern.CopyrightVariablesProvider"/>
|
||||
</extensionPoint>
|
||||
|
||||
</extensionPoints>
|
||||
|
||||
<actions>
|
||||
<action id="UpdateCopyright" class="com.maddyhome.idea.copyright.actions.UpdateCopyrightAction" text="Update Copyright..." description="Generate/Update the copyright notice.">
|
||||
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
|
||||
<add-to-group group-id="CodeMenu" anchor="last"/>
|
||||
<add-to-group group-id="NavbarPopupMenu" anchor="last"/>
|
||||
</action>
|
||||
<action id="GenerateCopyright" class="com.maddyhome.idea.copyright.actions.GenerateCopyrightAction" text="Copyright" description="Generate/Update the copyright notice.">
|
||||
<add-to-group group-id="GenerateGroup" anchor="last"/>
|
||||
</action>
|
||||
</actions>
|
||||
<actions>
|
||||
<action id="UpdateCopyright" class="com.maddyhome.idea.copyright.actions.UpdateCopyrightAction" text="Update Copyright..."
|
||||
description="Generate/Update the copyright notice.">
|
||||
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
|
||||
<add-to-group group-id="CodeMenu" anchor="last"/>
|
||||
<add-to-group group-id="NavbarPopupMenu" anchor="last"/>
|
||||
</action>
|
||||
<action id="GenerateCopyright" class="com.maddyhome.idea.copyright.actions.GenerateCopyrightAction" text="Copyright"
|
||||
description="Generate/Update the copyright notice.">
|
||||
<add-to-group group-id="GenerateGroup" anchor="last"/>
|
||||
</action>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -1,292 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.copyright;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.event.DocumentAdapter;
|
||||
import com.intellij.openapi.editor.event.DocumentEvent;
|
||||
import com.intellij.openapi.editor.event.DocumentListener;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
import com.intellij.psi.search.scope.packageSet.PackageSet;
|
||||
import com.maddyhome.idea.copyright.actions.UpdateCopyrightProcessor;
|
||||
import com.maddyhome.idea.copyright.options.LanguageOptions;
|
||||
import com.maddyhome.idea.copyright.options.Options;
|
||||
import com.maddyhome.idea.copyright.util.FileTypeUtil;
|
||||
import com.maddyhome.idea.copyright.util.NewFileTracker;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@State(name = "CopyrightManager", storages = @Storage(value = "copyright", stateSplitter = CopyrightManager.CopyrightStateSplitter.class))
|
||||
public class CopyrightManager extends AbstractProjectComponent implements PersistentStateComponent<Element> {
|
||||
private static final Logger LOG = Logger.getInstance("#" + CopyrightManager.class.getName());
|
||||
@Nullable
|
||||
private CopyrightProfile myDefaultCopyright = null;
|
||||
private final LinkedHashMap<String, String> myModuleToCopyrights = new LinkedHashMap<>();
|
||||
private final Map<String, CopyrightProfile> myCopyrights = new TreeMap<>();
|
||||
private final Options myOptions = new Options();
|
||||
|
||||
public CopyrightManager(@NotNull Project project,
|
||||
@NotNull final EditorFactory editorFactory,
|
||||
@NotNull final Application application,
|
||||
@NotNull final FileDocumentManager fileDocumentManager,
|
||||
@NotNull final FileTypeUtil fileTypeUtil,
|
||||
@NotNull final ProjectRootManager projectRootManager,
|
||||
@NotNull final PsiManager psiManager,
|
||||
@NotNull StartupManager startupManager) {
|
||||
super(project);
|
||||
if (!myProject.isDefault()) {
|
||||
final NewFileTracker newFileTracker = NewFileTracker.getInstance();
|
||||
Disposer.register(myProject, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
newFileTracker.clear();
|
||||
}
|
||||
});
|
||||
startupManager.runWhenProjectIsInitialized(() -> {
|
||||
DocumentListener listener = new DocumentAdapter() {
|
||||
@Override
|
||||
public void documentChanged(DocumentEvent e) {
|
||||
final Document document = e.getDocument();
|
||||
final VirtualFile virtualFile = fileDocumentManager.getFile(document);
|
||||
if (virtualFile == null) return;
|
||||
final Module module = projectRootManager.getFileIndex().getModuleForFile(virtualFile);
|
||||
if (module == null) return;
|
||||
if (!newFileTracker.poll(virtualFile)) return;
|
||||
if (!fileTypeUtil.isSupportedFile(virtualFile)) return;
|
||||
if (psiManager.findFile(virtualFile) == null) return;
|
||||
application.invokeLater(() -> {
|
||||
if (!virtualFile.isValid()) return;
|
||||
final PsiFile file = psiManager.findFile(virtualFile);
|
||||
if (file != null && file.isWritable()) {
|
||||
final CopyrightProfile opts = getCopyrightOptions(file);
|
||||
if (opts != null) {
|
||||
new UpdateCopyrightProcessor(myProject, module, file).run();
|
||||
}
|
||||
}
|
||||
}, ModalityState.NON_MODAL, myProject.getDisposed());
|
||||
}
|
||||
};
|
||||
editorFactory.getEventMulticaster().addDocumentListener(listener, myProject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@NonNls
|
||||
static final String COPYRIGHT = "copyright";
|
||||
@NonNls
|
||||
private static final String MODULE2COPYRIGHT = "module2copyright";
|
||||
@NonNls
|
||||
private static final String ELEMENT = "element";
|
||||
@NonNls
|
||||
private static final String MODULE = "module";
|
||||
@NonNls
|
||||
private static final String DEFAULT = "default";
|
||||
|
||||
public static CopyrightManager getInstance(Project project) {
|
||||
return project.getComponent(CopyrightManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNls
|
||||
@NotNull
|
||||
public String getComponentName() {
|
||||
return "CopyrightManager";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element getState() {
|
||||
Element state = new Element("settings");
|
||||
|
||||
try {
|
||||
if (!myCopyrights.isEmpty()) {
|
||||
for (CopyrightProfile copyright : myCopyrights.values()) {
|
||||
Element copyrightElement = new Element(COPYRIGHT);
|
||||
copyright.serializeInto(copyrightElement, true);
|
||||
if (!JDOMUtil.isEmpty(copyrightElement)) {
|
||||
state.addContent(copyrightElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!myModuleToCopyrights.isEmpty()) {
|
||||
final Element map = new Element(MODULE2COPYRIGHT);
|
||||
for (String moduleName : myModuleToCopyrights.keySet()) {
|
||||
final Element setting = new Element(ELEMENT);
|
||||
setting.setAttribute(MODULE, moduleName);
|
||||
setting.setAttribute(COPYRIGHT, myModuleToCopyrights.get(moduleName));
|
||||
map.addContent(setting);
|
||||
}
|
||||
state.addContent(map);
|
||||
}
|
||||
|
||||
myOptions.writeExternal(state);
|
||||
}
|
||||
catch (WriteExternalException e) {
|
||||
LOG.error(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (myDefaultCopyright != null) {
|
||||
state.setAttribute(DEFAULT, myDefaultCopyright.getName());
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadState(Element state) {
|
||||
clearCopyrights();
|
||||
|
||||
final Element moduleToCopyright = state.getChild(MODULE2COPYRIGHT);
|
||||
if (moduleToCopyright != null) {
|
||||
for (Element element : moduleToCopyright.getChildren(ELEMENT)) {
|
||||
myModuleToCopyrights.put(element.getAttributeValue(MODULE), element.getAttributeValue(COPYRIGHT));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
for (Element element : state.getChildren(COPYRIGHT)) {
|
||||
final CopyrightProfile copyrightProfile = new CopyrightProfile();
|
||||
copyrightProfile.readExternal(element);
|
||||
myCopyrights.put(copyrightProfile.getName(), copyrightProfile);
|
||||
}
|
||||
myDefaultCopyright = myCopyrights.get(StringUtil.notNullize(state.getAttributeValue(DEFAULT)));
|
||||
myOptions.readExternal(state);
|
||||
}
|
||||
catch (InvalidDataException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getCopyrightsMapping() {
|
||||
return myModuleToCopyrights;
|
||||
}
|
||||
|
||||
public void setDefaultCopyright(@Nullable CopyrightProfile copyright) {
|
||||
myDefaultCopyright = copyright;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CopyrightProfile getDefaultCopyright() {
|
||||
return myDefaultCopyright;
|
||||
}
|
||||
|
||||
public void addCopyright(CopyrightProfile copyrightProfile) {
|
||||
myCopyrights.put(copyrightProfile.getName(), copyrightProfile);
|
||||
}
|
||||
|
||||
public void removeCopyright(CopyrightProfile copyrightProfile) {
|
||||
myCopyrights.values().remove(copyrightProfile);
|
||||
for (Iterator<String> it = myModuleToCopyrights.keySet().iterator(); it.hasNext();) {
|
||||
final String profileName = myModuleToCopyrights.get(it.next());
|
||||
if (profileName.equals(copyrightProfile.getName())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCopyrights() {
|
||||
myDefaultCopyright = null;
|
||||
myCopyrights.clear();
|
||||
myModuleToCopyrights.clear();
|
||||
}
|
||||
|
||||
public void mapCopyright(String scopeName, String copyrightProfileName) {
|
||||
myModuleToCopyrights.put(scopeName, copyrightProfileName);
|
||||
}
|
||||
|
||||
public void unmapCopyright(String scopeName) {
|
||||
myModuleToCopyrights.remove(scopeName);
|
||||
}
|
||||
|
||||
public Collection<CopyrightProfile> getCopyrights() {
|
||||
return myCopyrights.values();
|
||||
}
|
||||
|
||||
public boolean hasAnyCopyrights() {
|
||||
return myDefaultCopyright != null || !myModuleToCopyrights.isEmpty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public CopyrightProfile getCopyrightOptions(@NotNull PsiFile file) {
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile == null || myOptions.getOptions(virtualFile.getFileType().getName()).getFileTypeOverride() == LanguageOptions.NO_COPYRIGHT) return null;
|
||||
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(myProject);
|
||||
for (String scopeName : myModuleToCopyrights.keySet()) {
|
||||
final NamedScope namedScope = validationManager.getScope(scopeName);
|
||||
if (namedScope != null) {
|
||||
final PackageSet packageSet = namedScope.getValue();
|
||||
if (packageSet != null) {
|
||||
if (packageSet.contains(file, validationManager)) {
|
||||
final CopyrightProfile profile = myCopyrights.get(myModuleToCopyrights.get(scopeName));
|
||||
if (profile != null) {
|
||||
return profile;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return myDefaultCopyright != null ? myDefaultCopyright : null;
|
||||
}
|
||||
|
||||
public Options getOptions() {
|
||||
return myOptions;
|
||||
}
|
||||
|
||||
public void replaceCopyright(String displayName, CopyrightProfile copyrightProfile) {
|
||||
if (myDefaultCopyright != null && Comparing.strEqual(myDefaultCopyright.getName(), displayName)) {
|
||||
myDefaultCopyright = copyrightProfile;
|
||||
}
|
||||
myCopyrights.remove(displayName);
|
||||
addCopyright(copyrightProfile);
|
||||
}
|
||||
|
||||
static final class CopyrightStateSplitter extends MainConfigurationStateSplitter {
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getComponentStateFileName() {
|
||||
return "profiles_settings";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getSubStateTagName() {
|
||||
return COPYRIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-39
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.maddyhome.idea.copyright.actions;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
@@ -30,13 +31,12 @@ import com.intellij.openapi.roots.ContentIterator;
|
||||
import com.intellij.openapi.roots.ModuleFileIndex;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile;
|
||||
import com.maddyhome.idea.copyright.util.FileTypeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -51,39 +51,11 @@ public abstract class AbstractFileProcessor {
|
||||
private PsiDirectory directory = null;
|
||||
private PsiFile file = null;
|
||||
private PsiFile[] files = null;
|
||||
private boolean subdirs = false;
|
||||
private final String message;
|
||||
private final String title;
|
||||
|
||||
protected abstract Runnable preprocessFile(PsiFile file, boolean allowReplacement) throws IncorrectOperationException;
|
||||
|
||||
protected AbstractFileProcessor(Project project, String title, String message) {
|
||||
myProject = project;
|
||||
myModule = null;
|
||||
directory = null;
|
||||
subdirs = true;
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
protected AbstractFileProcessor(Project project, Module module, String title, String message) {
|
||||
myProject = project;
|
||||
myModule = module;
|
||||
directory = null;
|
||||
subdirs = true;
|
||||
this.title = title;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
protected AbstractFileProcessor(Project project, PsiDirectory dir, boolean subdirs, String title, String message) {
|
||||
myProject = project;
|
||||
myModule = null;
|
||||
directory = dir;
|
||||
this.subdirs = subdirs;
|
||||
this.message = message;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
protected AbstractFileProcessor(Project project, PsiFile file, String title, String message) {
|
||||
myProject = project;
|
||||
myModule = null;
|
||||
@@ -92,7 +64,7 @@ public abstract class AbstractFileProcessor {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
protected AbstractFileProcessor(Project project, PsiFile[] files, String title, String message, Runnable runnable) {
|
||||
protected AbstractFileProcessor(Project project, PsiFile[] files, String title, String message) {
|
||||
myProject = project;
|
||||
myModule = null;
|
||||
this.files = files;
|
||||
@@ -102,7 +74,7 @@ public abstract class AbstractFileProcessor {
|
||||
|
||||
public void run() {
|
||||
if (directory != null) {
|
||||
process(directory, subdirs);
|
||||
process(directory, false);
|
||||
}
|
||||
else if (files != null) {
|
||||
process(files);
|
||||
@@ -275,7 +247,7 @@ public abstract class AbstractFileProcessor {
|
||||
for (PsiFile psiFile : files) {
|
||||
vFiles.add(psiFile.getVirtualFile());
|
||||
}
|
||||
if (!ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(VfsUtil.toVirtualFileArray(vFiles))
|
||||
if (!ReadonlyStatusHandler.getInstance(myProject).ensureFilesWritable(VfsUtilCore.toVirtualFileArray(vFiles))
|
||||
.hasReadonlyFiles()) {
|
||||
if (!files.isEmpty()) {
|
||||
final Runnable[] resultRunnable = new Runnable[1];
|
||||
@@ -296,15 +268,12 @@ public abstract class AbstractFileProcessor {
|
||||
if (opts != null && FileTypeUtil.isSupportedFile(local)) {
|
||||
files.add(local);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (subdirs) {
|
||||
PsiDirectory[] dirs = directory.getSubdirectories();
|
||||
for (PsiDirectory dir : dirs) {
|
||||
findFiles(files, dir, subdirs);
|
||||
for (PsiDirectory dir : directory.getSubdirectories()) {
|
||||
findFiles(files, dir, true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -13,9 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.copyright.actions;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.ui.CopyrightProjectConfigurable;
|
||||
import com.maddyhome.idea.copyright.util.FileTypeUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
+1
-1
@@ -20,6 +20,7 @@ import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.analysis.BaseAnalysisAction;
|
||||
import com.intellij.analysis.BaseAnalysisActionDialog;
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
@@ -37,7 +38,6 @@ import com.intellij.psi.*;
|
||||
import com.intellij.ui.TitledSeparator;
|
||||
import com.intellij.util.SequentialModalProgressTask;
|
||||
import com.intellij.util.SequentialTask;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.pattern.FileUtil;
|
||||
import com.maddyhome.idea.copyright.util.FileTypeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
+3
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.maddyhome.idea.copyright.actions;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
@@ -24,10 +25,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.EmptyRunnable;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile;
|
||||
import com.maddyhome.idea.copyright.psi.UpdateCopyright;
|
||||
import com.maddyhome.idea.copyright.psi.UpdateCopyrightFactory;
|
||||
@@ -39,18 +38,6 @@ public class UpdateCopyrightProcessor extends AbstractFileProcessor
|
||||
public static final String TITLE = "Update Copyright";
|
||||
public static final String MESSAGE = "Updating copyrights...";
|
||||
|
||||
public UpdateCopyrightProcessor(Project project, Module module)
|
||||
{
|
||||
super(project, module, TITLE, MESSAGE);
|
||||
setup(project, module);
|
||||
}
|
||||
|
||||
public UpdateCopyrightProcessor(Project project, Module module, PsiDirectory dir, boolean subdirs)
|
||||
{
|
||||
super(project, dir, subdirs, TITLE, MESSAGE);
|
||||
setup(project, module);
|
||||
}
|
||||
|
||||
public UpdateCopyrightProcessor(Project project, Module module, PsiFile file)
|
||||
{
|
||||
super(project, file, TITLE, MESSAGE);
|
||||
@@ -59,7 +46,7 @@ public class UpdateCopyrightProcessor extends AbstractFileProcessor
|
||||
|
||||
public UpdateCopyrightProcessor(Project project, Module module, PsiFile[] files)
|
||||
{
|
||||
super(project, files, TITLE, MESSAGE, null);
|
||||
super(project, files, TITLE, MESSAGE);
|
||||
setup(project, module);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.maddyhome.idea.copyright.pattern;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -23,7 +24,6 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import org.apache.commons.collections.ExtendedProperties;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
import org.apache.velocity.app.VelocityEngine;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package com.maddyhome.idea.copyright.psi;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile;
|
||||
import com.maddyhome.idea.copyright.options.LanguageOptions;
|
||||
import com.maddyhome.idea.copyright.pattern.EntityUtil;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.maddyhome.idea.copyright.psi;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.lang.Commenter;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
@@ -31,7 +32,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile;
|
||||
import com.maddyhome.idea.copyright.options.LanguageOptions;
|
||||
import com.maddyhome.idea.copyright.util.FileTypeUtil;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.maddyhome.idea.copyright.ui;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.editor.SpellCheckingEditorCustomizationProvider;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
@@ -28,12 +29,12 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.util.DocumentUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile;
|
||||
import com.maddyhome.idea.copyright.pattern.EntityUtil;
|
||||
import com.maddyhome.idea.copyright.pattern.VelocityHelper;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -59,7 +60,7 @@ public class CopyrightConfigurable extends NamedConfigurable<CopyrightProfile> {
|
||||
private JTextField myAllowReplaceTextField;
|
||||
private JPanel myEditorPanel;
|
||||
|
||||
public CopyrightConfigurable(Project project, CopyrightProfile copyrightProfile, Runnable updater) {
|
||||
public CopyrightConfigurable(@NotNull Project project, CopyrightProfile copyrightProfile, Runnable updater) {
|
||||
super(true, updater);
|
||||
myProject = project;
|
||||
myCopyrightProfile = copyrightProfile;
|
||||
@@ -130,6 +131,7 @@ public class CopyrightConfigurable extends NamedConfigurable<CopyrightProfile> {
|
||||
catch (PatternSyntaxException e) {
|
||||
throw new ConfigurationException("Keyword pattern syntax is incorrect: " + e.getMessage());
|
||||
}
|
||||
|
||||
myCopyrightProfile.setKeyword(keyword);
|
||||
myCopyrightProfile.setAllowReplaceKeyword(myAllowReplaceTextField.getText().trim());
|
||||
CopyrightManager.getInstance(myProject).replaceCopyright(myDisplayName, myCopyrightProfile);
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.maddyhome.idea.copyright.ui;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonShortcuts;
|
||||
@@ -37,14 +37,10 @@ import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile;
|
||||
import com.maddyhome.idea.copyright.options.ExternalOptionHelper;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -90,15 +86,11 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se
|
||||
@Override
|
||||
protected void processRemovedItems() {
|
||||
Map<String, CopyrightProfile> profiles = getAllProfiles();
|
||||
final List<CopyrightProfile> deleted = new ArrayList<>();
|
||||
for (CopyrightProfile profile : myManager.getCopyrights()) {
|
||||
for (CopyrightProfile profile : new ArrayList<>(myManager.getCopyrights())) {
|
||||
if (!profiles.containsValue(profile)) {
|
||||
deleted.add(profile);
|
||||
myManager.removeCopyright(profile);
|
||||
}
|
||||
}
|
||||
for (CopyrightProfile profile : deleted) {
|
||||
myManager.removeCopyright(profile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -174,10 +166,10 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent event) {
|
||||
final String name = askForProfileName("Create Copyright Profile", "");
|
||||
if (name == null) return;
|
||||
final CopyrightProfile copyrightProfile = new CopyrightProfile(name);
|
||||
addProfileNode(copyrightProfile);
|
||||
String name = askForProfileName("Create Copyright Profile", "");
|
||||
if (name != null) {
|
||||
addProfileNode(new CopyrightProfile(name));
|
||||
}
|
||||
}
|
||||
});
|
||||
result.add(new MyDeleteAction());
|
||||
@@ -188,9 +180,12 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent event) {
|
||||
final String profileName = askForProfileName("Copy Copyright Profile", "");
|
||||
if (profileName == null) return;
|
||||
final CopyrightProfile clone = new CopyrightProfile();
|
||||
String profileName = askForProfileName("Copy Copyright Profile", "");
|
||||
if (profileName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
CopyrightProfile clone = new CopyrightProfile();
|
||||
clone.copyFrom((CopyrightProfile)getSelectedObject());
|
||||
clone.setName(profileName);
|
||||
addProfileNode(clone);
|
||||
@@ -268,7 +263,7 @@ public class CopyrightProfilesPanel extends MasterDetailsComponent implements Se
|
||||
});
|
||||
}
|
||||
|
||||
private void addProfileNode(CopyrightProfile copyrightProfile) {
|
||||
private void addProfileNode(@NotNull CopyrightProfile copyrightProfile) {
|
||||
final CopyrightConfigurable copyrightConfigurable = new CopyrightConfigurable(myProject, copyrightProfile, TREE_UPDATER);
|
||||
copyrightConfigurable.setModified(true);
|
||||
final MyNode node = new MyNode(copyrightConfigurable);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -15,15 +15,16 @@
|
||||
*/
|
||||
package com.maddyhome.idea.copyright.ui;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.util.scopeChooser.PackageSetChooserCombo;
|
||||
import com.intellij.ide.util.scopeChooser.ScopeChooserConfigurable;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.options.ex.Settings;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.ui.LabeledComponent;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.packageDependencies.DefaultScopesProvider;
|
||||
import com.intellij.packageDependencies.DependencyValidationManager;
|
||||
import com.intellij.psi.search.scope.packageSet.CustomScopesProviderEx;
|
||||
import com.intellij.psi.search.scope.packageSet.NamedScope;
|
||||
@@ -34,9 +35,7 @@ import com.intellij.ui.ListCellRendererWrapper;
|
||||
import com.intellij.ui.ToolbarDecorator;
|
||||
import com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent;
|
||||
import com.intellij.ui.table.TableView;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.ui.*;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -58,7 +57,7 @@ public class ProjectSettingsPanel {
|
||||
|
||||
private final TableView<ScopeSetting> myScopeMappingTable;
|
||||
private final ListTableModel<ScopeSetting> myScopeMappingModel;
|
||||
private final JComboBox myProfilesComboBox = new JComboBox();
|
||||
private final JComboBox myProfilesComboBox = new ComboBox();
|
||||
|
||||
private final HyperlinkLabel myScopesLink = new HyperlinkLabel();
|
||||
|
||||
@@ -135,7 +134,7 @@ public class ProjectSettingsPanel {
|
||||
ElementProducer<ScopeSetting> producer = new ElementProducer<ScopeSetting>() {
|
||||
@Override
|
||||
public ScopeSetting createElement() {
|
||||
return new ScopeSetting(DefaultScopesProvider.getAllScope(), myProfilesModel.getAllProfiles().values().iterator().next());
|
||||
return new ScopeSetting(CustomScopesProviderEx.getAllScope(), myProfilesModel.getAllProfiles().values().iterator().next());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,7 +157,7 @@ public class ProjectSettingsPanel {
|
||||
if (defaultCopyright == null) return true;
|
||||
if (!defaultCopyright.equals(selected)) return true;
|
||||
}
|
||||
final Map<String, String> map = myManager.getCopyrightsMapping();
|
||||
final Map<String, String> map = myManager.getScopeToCopyright();
|
||||
if (map.size() != myScopeMappingModel.getItems().size()) return true;
|
||||
final Iterator<String> iterator = map.keySet().iterator();
|
||||
for (ScopeSetting setting : myScopeMappingModel.getItems()) {
|
||||
@@ -174,22 +173,17 @@ public class ProjectSettingsPanel {
|
||||
}
|
||||
|
||||
public void apply() {
|
||||
Collection<CopyrightProfile> profiles = new ArrayList<>(myManager.getCopyrights());
|
||||
myManager.clearCopyrights();
|
||||
for (CopyrightProfile profile : profiles) {
|
||||
myManager.addCopyright(profile);
|
||||
}
|
||||
final List<ScopeSetting> settingList = myScopeMappingModel.getItems();
|
||||
for (ScopeSetting scopeSetting : settingList) {
|
||||
myManager.setDefaultCopyright((CopyrightProfile)myProfilesComboBox.getSelectedItem());
|
||||
myManager.clearMappings();
|
||||
for (ScopeSetting scopeSetting : myScopeMappingModel.getItems()) {
|
||||
myManager.mapCopyright(scopeSetting.getScope().getName(), scopeSetting.getProfileName());
|
||||
}
|
||||
myManager.setDefaultCopyright((CopyrightProfile)myProfilesComboBox.getSelectedItem());
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
myProfilesComboBox.setSelectedItem(myManager.getDefaultCopyright());
|
||||
final List<ScopeSetting> mappings = new ArrayList<>();
|
||||
final Map<String, String> copyrights = myManager.getCopyrightsMapping();
|
||||
final Map<String, String> copyrights = myManager.getScopeToCopyright();
|
||||
final DependencyValidationManager manager = DependencyValidationManager.getInstance(myProject);
|
||||
final Set<String> scopes2Unmap = new HashSet<>();
|
||||
for (final String scopeName : copyrights.keySet()) {
|
||||
@@ -207,7 +201,6 @@ public class ProjectSettingsPanel {
|
||||
myScopeMappingModel.setItems(mappings);
|
||||
}
|
||||
|
||||
|
||||
private class ScopeSetting {
|
||||
private NamedScope myScope;
|
||||
private CopyrightProfile myProfile;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.maddyhome.idea.copyright.ui;
|
||||
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorFontType;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
@@ -27,7 +28,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.uiDesigner.core.GridConstraints;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.maddyhome.idea.copyright.CopyrightManager;
|
||||
import com.maddyhome.idea.copyright.CopyrightProfile;
|
||||
import com.maddyhome.idea.copyright.options.LanguageOptions;
|
||||
import com.maddyhome.idea.copyright.options.Options;
|
||||
@@ -82,10 +82,7 @@ public class TemplateCommentPanel implements SearchableConfigurable {
|
||||
|
||||
private void updateBox() {
|
||||
boolean enable = true;
|
||||
if (!cbSeparatorBefore.isSelected()) {
|
||||
enable = false;
|
||||
}
|
||||
else if (!cbSeparatorAfter.isSelected()) {
|
||||
if (!cbSeparatorBefore.isSelected() || !cbSeparatorAfter.isSelected()) {
|
||||
enable = false;
|
||||
}
|
||||
else {
|
||||
@@ -336,8 +333,8 @@ public class TemplateCommentPanel implements SearchableConfigurable {
|
||||
mySeparatorCharLabel.setEnabled(true);
|
||||
updateBox();
|
||||
} else {
|
||||
UIUtil.setEnabled(myCommentTypePanel, enable, true);
|
||||
UIUtil.setEnabled(myBorderPanel, enable, true);
|
||||
UIUtil.setEnabled(myCommentTypePanel, false, true);
|
||||
UIUtil.setEnabled(myBorderPanel, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -24,17 +24,14 @@ import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public class NewFileTracker {
|
||||
public static NewFileTracker getInstance() {
|
||||
return instance;
|
||||
}
|
||||
private final Set<VirtualFile> newFiles = Collections.synchronizedSet(new THashSet<VirtualFile>());
|
||||
|
||||
public boolean poll(@NotNull VirtualFile file) {
|
||||
return newFiles.remove(file);
|
||||
}
|
||||
|
||||
private NewFileTracker() {
|
||||
final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
|
||||
virtualFileManager.addVirtualFileListener(new VirtualFileAdapter() {
|
||||
public NewFileTracker() {
|
||||
VirtualFileManager.getInstance().addVirtualFileListener(new VirtualFileAdapter() {
|
||||
@Override
|
||||
public void fileCreated(@NotNull VirtualFileEvent event) {
|
||||
if (event.isFromRefresh()) return;
|
||||
@@ -49,9 +46,6 @@ public class NewFileTracker {
|
||||
});
|
||||
}
|
||||
|
||||
private final Set<VirtualFile> newFiles = Collections.synchronizedSet(new THashSet<VirtualFile>());
|
||||
private static final NewFileTracker instance = new NewFileTracker();
|
||||
|
||||
public void clear() {
|
||||
newFiles.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user