Skip to content

Commit

Permalink
#231 | Added extension name validation Inspection for CCv2 SAP Commer…
Browse files Browse the repository at this point in the history
…ce manifest.json
  • Loading branch information
mlytvyn authored Feb 19, 2023
1 parent 2fdc0e2 commit 3cd6f74
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 16 deletions.
7 changes: 5 additions & 2 deletions resources/META-INF/optional-lang-dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</projectListeners>

<extensions defaultExtensionNs="JavaScript.JsonSchema">
<ProviderFactory implementation="com.intellij.idea.plugin.hybris.system.ccv2.jsonSchema.ManifestJsonSchemaProviderFactory"/>
<ProviderFactory implementation="com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.ManifestJsonSchemaProviderFactory"/>
</extensions>

<extensions defaultExtensionNs="com.intellij">
Expand All @@ -51,7 +51,10 @@
<!-- ####################################################################################################### -->

<completion.contributor language="JSON" id="CCv2ManifestCompletionContributor"
implementationClass="com.intellij.idea.plugin.hybris.system.ccv2.codeInsight.completion.ManifestJsonCompletionProvider"/>
implementationClass="com.intellij.idea.plugin.hybris.system.manifest.codeInsight.completion.ManifestJsonCompletionProvider"/>
<projectService serviceImplementation="com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers.ManifestCommerceJsonSchemaFileProvider"/>
<projectService serviceImplementation="com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers.ManifestDataHubJsonSchemaFileProvider"/>
<projectService serviceImplementation="com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers.ManifestJavascriptStorefrontJsonSchemaFileProvider"/>

<!-- ####################################################################################################### -->
<!-- Business Process -->
Expand Down
6 changes: 6 additions & 0 deletions resources/META-INF/plugin-inspections.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">

<!-- manifest.json - Commerce -->
<localInspection groupPath="hybris" shortName="ManifestUnknownExtensionInspection" displayName="[y] Unknown extension"
groupName="[y] Manifest - Commerce" level="ERROR" language="JSON" enabledByDefault="true"
bundle="i18n.HybrisBundle" key="hybris.inspections.manifest.ManifestUnknownExtensionInspection.key"
implementationClass="com.intellij.idea.plugin.hybris.codeInspection.rule.manifest.ManifestCommerceExtensionInspection"/>

<!-- Business Process -->
<localInspection language="XML" enabledByDefault="true" groupPath="hybris" groupName="[y] Business Process"
bundle="i18n.HybrisBundle" key="hybris.inspections.DomElementsInspection.key"
Expand Down
1 change: 1 addition & 0 deletions resources/META-INF/plugin-release-info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<li><i>Feature:</i> Added CCv2 DataHub <code>manifest.json</code> schema support (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/226" target="_blank" rel="nofollow">#226</a>)</li>
<li><i>Feature:</i> Added CCv2 Javascript Storefront <code>manifest.json</code> schema support (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/227" target="_blank" rel="nofollow">#227</a>)</li>
<li><i>Feature:</i> Added completion of the available extensions for CCv2 SAP Commerce <code>manifest.json</code> file (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/229" target="_blank" rel="nofollow">#229</a>)</li>
<li><i>Feature:</i> Added extension name validation Inspection for CCv2 SAP Commerce <code>manifest.json</code> file (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/231" target="_blank" rel="nofollow">#231</a>)</li>
<li><i>Feature:</i> Added possibility to group by Item parent for Type System preview (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/211" target="_blank" rel="nofollow">#211</a>)</li>
<li><i>Feature:</i> Added completion and navigation for Index attributes within <code>items.xml</code> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/207" target="_blank" rel="nofollow">#207</a>)</li>
<li><i>Feature:</i> Added completion for meta tags within <code>extensioninfo.xml</code> (<a href="https://github.com/epam/sap-commerce-intellij-idea-plugin/pull/230" target="_blank" rel="nofollow">#230</a>)</li>
Expand Down
3 changes: 3 additions & 0 deletions resources/i18n/HybrisBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ hybris.inspections.ei.EiDuplicateExtensionDefinition.key=[y] Dependency on exten
hybris.inspections.fix.ei.EiDuplicateExtensionDefinition.message=[y] Dependency on ''{0}'' extension is already declared
hybris.inspections.fix.ei.EiUnknownExtensionDefinition.message=[y] Unknown ''{0}'' extension

hybris.inspections.manifest.ManifestUnknownExtensionInspection.key=[y] Unknown extension
hybris.inspections.fix.manifest.ManifestUnknownExtensionInspection.message=[y] Unknown ''{0}'' extension

hybris.inspections.le.LeUnknownExtensionDefinition.key=[y] Unknown extension
hybris.inspections.fix.le.LeUnknownExtensionDefinition.message=[y] Unknown ''{0}'' extension

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
~ This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
~ Copyright (C) 2019 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/>.
-->

<html>
<body>
This extension is not available. Refresh the project to re-scan available extensions.
</body>
</html>
5 changes: 5 additions & 0 deletions resources/schemas/manifest-commerce.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@
"description": "The AddOns installed by the Platform during the build process.",
"items": {
"type": "object",
"required": [
"addon",
"storefront",
"template"
],
"additionalProperties": false,
"properties": {
"addon": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of "SAP Commerce Developers Toolset" plugin for Intellij IDEA.
* Copyright (C) 2019 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.codeInspection.rule.manifest

import com.intellij.codeInspection.LocalInspectionTool
import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.idea.plugin.hybris.common.utils.HybrisI18NBundleUtils
import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent
import com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers.ManifestCommerceJsonSchemaFileProvider
import com.intellij.json.psi.*
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.util.parentOfType

class ManifestCommerceExtensionInspection : LocalInspectionTool() {

override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
val file = holder.file

if (!ManifestCommerceJsonSchemaFileProvider.instance(file.project).isAvailable(file.viewProvider.virtualFile)) return PsiElementVisitor.EMPTY_VISITOR

return ManifestCommerceVisitor(holder)
}

class ManifestCommerceVisitor(val holder: ProblemsHolder) : JsonElementVisitor() {

override fun visitStringLiteral(o: JsonStringLiteral) {
val parent = o.parent
if (isApplicable(parent, o) && !HybrisProjectSettingsComponent.getInstance(o.project).state.completeSetOfAvailableExtensionsInHybris.contains(o.value)) {
holder.registerProblem(
o,
HybrisI18NBundleUtils.message("hybris.inspections.fix.manifest.ManifestUnknownExtensionInspection.message", o.value)
)
}
}

private fun isApplicable(parent: PsiElement?, o: JsonStringLiteral) =
((parent is JsonArray && o.parentOfType<JsonProperty>()?.name == "extensions")
|| (parent is JsonProperty && JsonPsiUtil.isPropertyValue(o) && (parent.name == "addon" || parent.name == "storefront") && parent.parentOfType<JsonProperty>()?.name == "storefrontAddons")
|| (parent is JsonProperty && JsonPsiUtil.isPropertyValue(o) && (parent.name == "name") && parent.parentOfType<JsonProperty>()?.name == "webapps"))


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.intellij.idea.plugin.hybris.system.ccv2.codeInsight.completion
package com.intellij.idea.plugin.hybris.system.manifest.codeInsight.completion

import com.intellij.codeInsight.completion.CompletionContributor
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.idea.plugin.hybris.codeInsight.completion.provider.ExtensionsNameCompletionProvider
import com.intellij.idea.plugin.hybris.system.ccv2.psi.ManifestPatterns
import com.intellij.idea.plugin.hybris.system.manifest.psi.ManifestPatterns

class ManifestJsonCompletionProvider : CompletionContributor() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
* 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.system.ccv2.jsonSchema
package com.intellij.idea.plugin.hybris.system.manifest.jsonSchema

import com.intellij.idea.plugin.hybris.system.ccv2.jsonSchema.providers.ManifestCommerceJsonSchemaFileProvider
import com.intellij.idea.plugin.hybris.system.ccv2.jsonSchema.providers.ManifestDataHubJsonSchemaFileProvider
import com.intellij.idea.plugin.hybris.system.ccv2.jsonSchema.providers.ManifestJavascriptStorefrontJsonSchemaFileProvider
import com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers.ManifestCommerceJsonSchemaFileProvider
import com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers.ManifestDataHubJsonSchemaFileProvider
import com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers.ManifestJavascriptStorefrontJsonSchemaFileProvider
import com.intellij.openapi.project.Project
import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory

class ManifestJsonSchemaProviderFactory : JsonSchemaProviderFactory {

override fun getProviders(project: Project) = listOf(
ManifestCommerceJsonSchemaFileProvider(project),
ManifestDataHubJsonSchemaFileProvider(project),
ManifestJavascriptStorefrontJsonSchemaFileProvider(project)
ManifestCommerceJsonSchemaFileProvider.instance(project),
ManifestDataHubJsonSchemaFileProvider.instance(project),
ManifestJavascriptStorefrontJsonSchemaFileProvider.instance(project)
)

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.intellij.idea.plugin.hybris.system.ccv2.jsonSchema.providers
package com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers

import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent
Expand All @@ -9,11 +9,16 @@ import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory
import com.jetbrains.jsonSchema.extension.SchemaType

class ManifestCommerceJsonSchemaFileProvider(val project: Project) : JsonSchemaFileProvider {

override fun isAvailable(file: VirtualFile) = HybrisConstants.CCV2_MANIFEST_NAME == file.name
&& HybrisConstants.CCV2_CORE_CUSTOMIZE_NAME == file.parent.name
&& HybrisProjectSettingsComponent.getInstance(project).state.isHybrisProject

override fun getName() = "SAP Commerce Cloud Manifest"
override fun getSchemaFile() = JsonSchemaProviderFactory.getResourceFile(javaClass, "/schemas/manifest-commerce.schema.json")
override fun getSchemaType() = SchemaType.embeddedSchema

companion object {
fun instance(project: Project): JsonSchemaFileProvider = project.getService(ManifestCommerceJsonSchemaFileProvider::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.intellij.idea.plugin.hybris.system.ccv2.jsonSchema.providers
package com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers

import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent
Expand All @@ -16,4 +16,8 @@ class ManifestDataHubJsonSchemaFileProvider(val project: Project) : JsonSchemaFi
override fun getName() = "DataHub Manifest"
override fun getSchemaFile() = JsonSchemaProviderFactory.getResourceFile(javaClass, "/schemas/manifest-datahub.schema.json")
override fun getSchemaType() = SchemaType.embeddedSchema

companion object {
fun instance(project: Project): JsonSchemaFileProvider = project.getService(ManifestDataHubJsonSchemaFileProvider::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.intellij.idea.plugin.hybris.system.ccv2.jsonSchema.providers
package com.intellij.idea.plugin.hybris.system.manifest.jsonSchema.providers

import com.intellij.idea.plugin.hybris.common.HybrisConstants
import com.intellij.idea.plugin.hybris.settings.HybrisProjectSettingsComponent
Expand All @@ -16,4 +16,8 @@ class ManifestJavascriptStorefrontJsonSchemaFileProvider(val project: Project) :
override fun getName() = "Javascript Storefront Manifest"
override fun getSchemaFile() = JsonSchemaProviderFactory.getResourceFile(javaClass, "/schemas/manifest-js-storefront.schema.json")
override fun getSchemaType() = SchemaType.embeddedSchema

companion object {
fun instance(project: Project): JsonSchemaFileProvider = project.getService(ManifestJavascriptStorefrontJsonSchemaFileProvider::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.intellij.idea.plugin.hybris.system.ccv2.psi
package com.intellij.idea.plugin.hybris.system.manifest.psi

import com.intellij.json.JsonElementTypes
import com.intellij.json.psi.JsonArray
Expand All @@ -31,7 +31,6 @@ object ManifestPatterns {

private inline fun <reified T : PsiElement> PsiElementPattern<*, *>.withParent() = this.withParent(T::class.java)

private fun jsonPropertyName() = PlatformPatterns.psiElement(JsonElementTypes.IDENTIFIER)
private fun jsonStringValue() = PlatformPatterns.psiElement(JsonElementTypes.DOUBLE_QUOTED_STRING)
.withParent<JsonStringLiteral>()

Expand Down

0 comments on commit 3cd6f74

Please sign in to comment.