forked from unshare/hybris-integration-intellij-idea-plugin
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#231 | Added extension name validation Inspection for CCv2 SAP Commer…
…ce manifest.json
- Loading branch information
Showing
13 changed files
with
131 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
resources/inspectionDescriptions/ManifestUnknownExtensionInspection.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ij/idea/plugin/hybris/codeInspection/rule/manifest/ManifestCommerceExtensionInspection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters