Skip to content

Commit

Permalink
#498 | Import CCv2 core-customize as a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
mlytvyn authored Jul 1, 2023
1 parent b187901 commit 403da61
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions resources/META-INF/plugin-internal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<projectService serviceImplementation="com.intellij.idea.plugin.hybris.tools.remote.console.persistence.services.impl.JsonIOUtil"/>
<projectService serviceImplementation="com.intellij.idea.plugin.hybris.tools.remote.console.persistence.ui.listeners.HybrisConsoleQueryPanelEventManager"/>

<projectService serviceInterface="com.intellij.ide.projectView.impl.nodes.ProjectViewDirectoryHelper"
serviceImplementation="com.intellij.idea.plugin.hybris.project.view.impl.HybrisProjectViewDirectoryHelper"
order="last"
overrides="true"/>

<gotoClassContributor implementation="com.intellij.idea.plugin.hybris.gotoClass.CustomGotoClassContributor"/>
<directoryIndexExcludePolicy implementation="com.intellij.idea.plugin.hybris.indexing.HybrisDirectoryIndexExcludePolicy"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -507,6 +506,9 @@ private Set<File> processDirectoriesByTypePriority(
} else {
moduleRootMap.get(NON_HYBRIS).forEach(file -> addIfNotExists(moduleRootDirectories, file));
}

moduleRootMap.get(CCV2).forEach(file -> addIfNotExists(moduleRootDirectories, file));

return Sets.newHashSet(moduleRootDirectories.values());
}

Expand Down Expand Up @@ -542,10 +544,11 @@ private void addIfNotExists(final Map<String, File> moduleRootDirectories, final
}

private Map<DIRECTORY_TYPE, Set<File>> newModuleRootMap() {
final Map<DIRECTORY_TYPE, Set<File>> 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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2023 EPAM Systems <[email protected]>
*
* 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.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<VirtualFile> {
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)
}
}
5 changes: 5 additions & 0 deletions src/com/intellij/idea/plugin/hybris/view/HybrisProjectView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 403da61

Please sign in to comment.