From 403da61713875eb1455af05f7eeab848ec640136 Mon Sep 17 00:00:00 2001 From: Mykhailo Lytvyn Date: Sat, 1 Jul 2023 14:05:18 +0200 Subject: [PATCH] #498 | Import CCv2 `core-customize` as a separate module --- CHANGELOG.md | 1 + resources/META-INF/plugin-internal.xml | 5 + .../plugin/hybris/common/HybrisConstants.kt | 1 + .../DefaultHybrisProjectDescriptor.java | 17 ++-- .../impl/HybrisProjectViewDirectoryHelper.kt | 98 +++++++++++++++++++ .../plugin/hybris/view/HybrisProjectView.kt | 5 + 6 files changed, 120 insertions(+), 7 deletions(-) create mode 100644 src/com/intellij/idea/plugin/hybris/project/view/impl/HybrisProjectViewDirectoryHelper.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 925292944..c8379eee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## [2023.2.3] ### Features +- Import CCv2 `core-customize` as a separate module [#498](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/498) - Don't scan CCv2 `js-storefront` and `datahub` sub-folders during project import/refresh [#497](https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/497) ### `ImpEx` enhancements diff --git a/resources/META-INF/plugin-internal.xml b/resources/META-INF/plugin-internal.xml index 264b02660..e5d1168a5 100644 --- a/resources/META-INF/plugin-internal.xml +++ b/resources/META-INF/plugin-internal.xml @@ -67,6 +67,11 @@ + + diff --git a/src/com/intellij/idea/plugin/hybris/common/HybrisConstants.kt b/src/com/intellij/idea/plugin/hybris/common/HybrisConstants.kt index ca102c749..112cd0cd4 100644 --- a/src/com/intellij/idea/plugin/hybris/common/HybrisConstants.kt +++ b/src/com/intellij/idea/plugin/hybris/common/HybrisConstants.kt @@ -85,6 +85,7 @@ object HybrisConstants { const val COCKPIT_NG_WIDGETS_XML = "widgets.xml" const val COCKPIT_NG_DEFINITION_XML = "definition.xml" + const val HYBRIS_DIRECTORY = "hybris" const val HYBRIS_DATA_DIRECTORY = "data" const val HYBRIS_PLATFORM_CODE_SERVER_JAR_SUFFIX = "server.jar" diff --git a/src/com/intellij/idea/plugin/hybris/project/descriptors/DefaultHybrisProjectDescriptor.java b/src/com/intellij/idea/plugin/hybris/project/descriptors/DefaultHybrisProjectDescriptor.java index 322d9e98c..91da5f638 100644 --- a/src/com/intellij/idea/plugin/hybris/project/descriptors/DefaultHybrisProjectDescriptor.java +++ b/src/com/intellij/idea/plugin/hybris/project/descriptors/DefaultHybrisProjectDescriptor.java @@ -67,8 +67,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; -import static com.intellij.idea.plugin.hybris.project.descriptors.DefaultHybrisProjectDescriptor.DIRECTORY_TYPE.HYBRIS; -import static com.intellij.idea.plugin.hybris.project.descriptors.DefaultHybrisProjectDescriptor.DIRECTORY_TYPE.NON_HYBRIS; +import static com.intellij.idea.plugin.hybris.project.descriptors.DefaultHybrisProjectDescriptor.DIRECTORY_TYPE.*; import static org.apache.commons.io.FilenameUtils.separatorsToSystem; public class DefaultHybrisProjectDescriptor implements HybrisProjectDescriptor { @@ -507,6 +506,9 @@ private Set processDirectoriesByTypePriority( } else { moduleRootMap.get(NON_HYBRIS).forEach(file -> addIfNotExists(moduleRootDirectories, file)); } + + moduleRootMap.get(CCV2).forEach(file -> addIfNotExists(moduleRootDirectories, file)); + return Sets.newHashSet(moduleRootDirectories.values()); } @@ -542,10 +544,11 @@ private void addIfNotExists(final Map moduleRootDirectories, final } private Map> newModuleRootMap() { - final Map> moduleRootMap = new HashMap<>(); - moduleRootMap.put(HYBRIS, new HashSet<>()); - moduleRootMap.put(NON_HYBRIS, new HashSet<>()); - return moduleRootMap; + return Map.of( + HYBRIS, new HashSet<>(), + NON_HYBRIS, new HashSet<>(), + CCV2, new HashSet<>() + ); } private void addRootModule( @@ -637,7 +640,7 @@ private void findModuleRoots( if (hybrisProjectService.isCCv2Module(rootProjectDirectory)) { LOG.info("Detected CCv2 module " + rootProjectDirectory.getAbsolutePath()); - moduleRootMap.get(NON_HYBRIS).add(rootProjectDirectory); + moduleRootMap.get(CCV2).add(rootProjectDirectory); final var name = rootProjectDirectory.getName(); if (name.endsWith(HybrisConstants.CCV2_JS_STOREFRONT_NAME) || name.endsWith(HybrisConstants.CCV2_DATAHUB_NAME)) { // faster import: no need to process sub-folders of the CCv2 js-storefront and datahub directories diff --git a/src/com/intellij/idea/plugin/hybris/project/view/impl/HybrisProjectViewDirectoryHelper.kt b/src/com/intellij/idea/plugin/hybris/project/view/impl/HybrisProjectViewDirectoryHelper.kt new file mode 100644 index 000000000..7af9672cc --- /dev/null +++ b/src/com/intellij/idea/plugin/hybris/project/view/impl/HybrisProjectViewDirectoryHelper.kt @@ -0,0 +1,98 @@ +/* + * This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA. + * Copyright (C) 2023 EPAM Systems + * + * 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 . + */ +package com.intellij.idea.plugin.hybris.project.view.impl + +import com.intellij.ide.projectView.ViewSettings +import com.intellij.ide.projectView.impl.JavaProjectViewDirectoryHelper +import com.intellij.ide.projectView.impl.nodes.ProjectViewDirectoryHelper +import com.intellij.idea.plugin.hybris.common.HybrisConstants +import com.intellij.idea.plugin.hybris.project.utils.PluginCommon +import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent +import com.intellij.openapi.project.Project +import com.intellij.openapi.roots.ProjectFileIndex +import com.intellij.openapi.roots.ProjectRootManager +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiDirectory + +class HybrisProjectViewDirectoryHelper(project: Project) : ProjectViewDirectoryHelper(project) { + + private val javaProjectViewDirectoryHelper = JavaProjectViewDirectoryHelper(project) + private val fileIndex = ProjectFileIndex.getInstance(project) + + override fun getLocationString(psiDirectory: PsiDirectory, includeUrl: Boolean, includeRootType: Boolean) = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.getLocationString(psiDirectory, includeUrl, includeRootType) + else super.getLocationString(psiDirectory, includeUrl, includeRootType) + + override fun isShowFQName(settings: ViewSettings?, parentValue: Any?, value: PsiDirectory?) = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.isShowFQName(settings, parentValue, value) + else super.isShowFQName(settings, parentValue, value) + + override fun shouldHideProjectConfigurationFilesDirectory() = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.shouldHideProjectConfigurationFilesDirectory() + else super.shouldHideProjectConfigurationFilesDirectory() + + override fun getNodeName(settings: ViewSettings?, parentValue: Any?, directory: PsiDirectory?) = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.getNodeName(settings, parentValue, directory) + else super.getNodeName(settings, parentValue, directory) + + override fun skipDirectory(directory: PsiDirectory?) = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.skipDirectory(directory) + else super.skipDirectory(directory) + + override fun isEmptyMiddleDirectory(directory: PsiDirectory?, strictlyEmpty: Boolean) = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.isEmptyMiddleDirectory(directory, strictlyEmpty) + else super.isEmptyMiddleDirectory(directory, strictlyEmpty) + + override fun supportsFlattenPackages() = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.supportsFlattenPackages() + else super.supportsFlattenPackages() + + override fun supportsHideEmptyMiddlePackages() = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.supportsHideEmptyMiddlePackages() + else super.supportsHideEmptyMiddlePackages() + + override fun canRepresent(element: Any?, directory: PsiDirectory?) = if (PluginCommon.isPluginActive(PluginCommon.JAVA_PLUGIN_ID)) + javaProjectViewDirectoryHelper.canRepresent(element, directory) + else super.canRepresent(element, directory) + + override fun getTopLevelRoots(): MutableList { + val topLevelContentRoots = super.getTopLevelRoots() + if (HybrisProjectSettingsComponent.getInstance(project).isHybrisProject()) { + val prm = ProjectRootManager.getInstance(project) + + for (root in prm.contentRoots) { + val parent = root.parent + if (!isFileUnderContentRoot(parent)) { + topLevelContentRoots.add(root) + } + } + } + + return topLevelContentRoots + } + + private fun isFileUnderContentRoot(file: VirtualFile?): Boolean { + if (file == null) return false + if (!file.isValid) return false + + val contentRoot = fileIndex.getContentRootForFile(file, false) + ?: return false + + return !contentRoot.name.endsWith(HybrisConstants.CCV2_CORE_CUSTOMIZE_NAME) + } +} diff --git a/src/com/intellij/idea/plugin/hybris/view/HybrisProjectView.kt b/src/com/intellij/idea/plugin/hybris/view/HybrisProjectView.kt index 7fde185aa..388e5d92c 100644 --- a/src/com/intellij/idea/plugin/hybris/view/HybrisProjectView.kt +++ b/src/com/intellij/idea/plugin/hybris/view/HybrisProjectView.kt @@ -119,6 +119,11 @@ open class HybrisProjectView(val project: Project) : TreeStructureProvider, Dumb && HybrisConstants.EXTENSION_NAME_PLATFORM == module.yExtensionName() ) return false + // hide `core-customize/hybris` node + if (HybrisConstants.HYBRIS_DIRECTORY == vf.name + && HybrisConstants.CCV2_CORE_CUSTOMIZE_NAME == module.yExtensionName() + ) return false + return YFacet.getState(module) ?.let { if (it.subModuleType == null) true