Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify HybrisWritingAccessProvider logic due slow operations #851

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Invoke later slow operation `ImpEx Column values Highlight` [#835](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/835)
- Omit slow operation on `HybrisWritingAccessProvider` [#846](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/846)
- Added custom icon for `buildcallbacks.xml` file [#850](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/850)
- Simplify `HybrisWritingAccessProvider` logic due slow operations [#851](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/851)

## [2023.3.0]

Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ intellij.jvm.args=-ea -Xms512m -Xmx3G -XX:MaxMetaspaceSize=400m
intellij.update.since.until.build=true

intellij.plugin.name=SAP-Commerce-Developers-Toolset
intellij.plugin.version=2023.3.0
intellij.plugin.since.build=233.11799.196
intellij.plugin.version=2023.3.1
intellij.plugin.since.build=233.11799.241
intellij.plugin.until.build=233.*

intellij.type=IU
intellij.version=LATEST-EAP-SNAPSHOT
#intellij.version=233.11799.196
#intellij.version=LATEST-EAP-SNAPSHOT
intellij.version=233.11799.241
intellij.download.sources=true

# Plugin Verifier integration -> https://github.com/JetBrains/intellij-plugin-verifier
# https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions
# EAP snapshots -> https://www.jetbrains.com/intellij-repository/snapshots
plugin.verifier.ide.versions=IU-233.11799.196
plugin.verifier.ide.versions=IU-233.11799.241

# Plugin Dependencies -> https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html
# Platform explorer (Plugin) -> https://plugins.jetbrains.com/intellij-platform-explorer/extensions
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2014-2016 Alexander Bartash <[email protected]>
* Copyright (C) 2019-2023 EPAM Systems <[email protected]> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.intellij.idea.plugin.hybris.project.providers

import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.WritingAccessProvider

class HybrisWritingAccessProvider(private val myProject: Project) : WritingAccessProvider() {

private val ootbReadOnlyMode = HybrisProjectSettingsComponent.getInstance(myProject).state.importOotbModulesInReadOnlyMode

override fun requestWriting(files: Collection<VirtualFile>) = files
.filter { isFileReadOnly(it) }
.toMutableSet()

override fun isPotentiallyWritable(file: VirtualFile) = !isFileReadOnly(file)

private fun isFileReadOnly(file: VirtualFile): Boolean {
if (!ootbReadOnlyMode) return false
if (!file.isWritable) return true

return file.path.contains("hybris/bin")
&& !file.path.contains("hybris/bin/custom")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.flexibleSearch.FlexibleSearchLanguage
import com.intellij.idea.plugin.hybris.polyglotQuery.PolyglotQueryLanguage
import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent
import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.application.ReadAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.patterns.PsiJavaPatterns
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.search.searches.ClassInheritorsSearch
import com.intellij.util.concurrency.AppExecutorUtil
import org.intellij.plugins.intelliLang.Configuration
import org.intellij.plugins.intelliLang.inject.config.InjectionPlace
import org.intellij.plugins.intelliLang.inject.java.InjectionCache
import org.intellij.plugins.intelliLang.inject.java.JavaLanguageInjectionSupport
import java.util.concurrent.Callable

/**
* TODO: reset Injection Cache on CRUD operation on classes related to FlexibleSearchQuery
Expand All @@ -43,34 +44,32 @@ class HybrisIntelliLangStartupActivity : ProjectActivity {
if (!HybrisProjectSettingsComponent.getInstance(project).isHybrisProject()) return

ReadAction
.nonBlocking(
Callable {
with(InjectionCache.getInstance(project).xmlIndex) {
add(HybrisConstants.CLASS_NAME_FLEXIBLE_SEARCH_QUERY)
addAll(findCustomExtensionsOfTheFlexibleSearch(project))
}
.nonBlocking<Set<String>> { findCustomExtensionsOfTheFlexibleSearch(project) }
.finishOnUiThread(ModalityState.defaultModalityState()) {
with(InjectionCache.getInstance(project).xmlIndex) {
add(HybrisConstants.CLASS_NAME_FLEXIBLE_SEARCH_QUERY)
addAll(it)
}

val targetLanguages = setOf(FlexibleSearchLanguage.INSTANCE.id, PolyglotQueryLanguage.instance.id)
val targetLanguages = setOf(FlexibleSearchLanguage.INSTANCE.id, PolyglotQueryLanguage.instance.id)

// TODO: replace with pattern declared in the XML file once https://youtrack.jetbrains.com/issue/IDEA-339624/ will be resolved.
// com.intellij.patterns.compiler.PatternCompiler cannot parse primitive booleans required by the pattern
Configuration.getInstance().getInjections(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID)
.filter { targetLanguages.contains(it.injectedLanguageId) }
.forEach {
val injectionPlaces = it.injectionPlaces.toMutableSet()
val psiParameterInjectionPlace = InjectionPlace(
PsiJavaPatterns.psiParameter().ofMethod(
PsiJavaPatterns.psiMethod().definedInClass(PsiJavaPatterns.psiClass().inheritorOf(false, HybrisConstants.CLASS_FQN_FLEXIBLE_SEARCH_QUERY))
),
true
)
injectionPlaces.add(psiParameterInjectionPlace)
it.setInjectionPlaces(*injectionPlaces.toTypedArray())
}
}
)
.inSmartMode(project)
.executeSynchronously();
// TODO: replace with pattern declared in the XML file once https://youtrack.jetbrains.com/issue/IDEA-339624/ will be resolved.
// com.intellij.patterns.compiler.PatternCompiler cannot parse primitive booleans required by the pattern
Configuration.getInstance().getInjections(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID)
.filter { targetLanguages.contains(it.injectedLanguageId) }
.forEach {
val injectionPlaces = it.injectionPlaces.toMutableSet()
val psiParameterInjectionPlace = InjectionPlace(
PsiJavaPatterns.psiParameter().ofMethod(
PsiJavaPatterns.psiMethod().definedInClass(PsiJavaPatterns.psiClass().inheritorOf(false, HybrisConstants.CLASS_FQN_FLEXIBLE_SEARCH_QUERY))
),
true
)
injectionPlaces.add(psiParameterInjectionPlace)
it.setInjectionPlaces(*injectionPlaces.toTypedArray())
}
}
.submit(AppExecutorUtil.getAppExecutorService())
}

private fun findCustomExtensionsOfTheFlexibleSearch(project: Project) = (JavaPsiFacade.getInstance(project)
Expand Down