diff --git a/resources/magento2/validation.properties b/resources/magento2/validation.properties index 7e06c555b..293df9366 100644 --- a/resources/magento2/validation.properties +++ b/resources/magento2/validation.properties @@ -1,6 +1,8 @@ validator.notEmpty=The {0} field must not be empty validator.box.notEmpty=The {0} field must contain a valid selection from the dropdown validator.package.validPath=Please specify a valid Magento 2 installation path +validator.package.validPathComposerFiles=File composer.json is missing in the current Magento 2 installation path +validator.package.validPathVendor=Vendor dir is corrupt or missing in the current Magento 2 installation path validator.properties.notEmpty=The properties must not be empty validator.alphaNumericCharacters=The {0} field must contain letters and numbers only validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only diff --git a/src/com/magento/idea/magento2plugin/project/validator/SettingsFormValidator.java b/src/com/magento/idea/magento2plugin/project/validator/SettingsFormValidator.java index 6c59ad314..8d0fdeffc 100644 --- a/src/com/magento/idea/magento2plugin/project/validator/SettingsFormValidator.java +++ b/src/com/magento/idea/magento2plugin/project/validator/SettingsFormValidator.java @@ -28,14 +28,30 @@ public SettingsFormValidator( * * @throws ConfigurationException Exception */ + @SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.AvoidDeeplyNestedIfStmts"}) public void validate() throws ConfigurationException { if (form.isBeingUsed()) { - if (!MagentoBasePathUtil.isMagentoFolderValid(form.getMagentoPath())) { + final String magentoRootPath = form.getMagentoPath(); + final boolean isMagentoFrameworkDirExist = + MagentoBasePathUtil.isMagentoFolderValid(magentoRootPath); + + if (!MagentoBasePathUtil.isComposerJsonExists(magentoRootPath)) { + if (isMagentoFrameworkDirExist) { + throw new ConfigurationException( + validatorBundle.message("validator.package.validPathComposerFiles") + ); + } throw new ConfigurationException( validatorBundle.message("validator.package.validPath") ); } + if (!isMagentoFrameworkDirExist) { + throw new ConfigurationException( + validatorBundle.message("validator.package.validPathVendor") + ); + } + final String magentoVersion = form.getMagentoVersion(); if (magentoVersion.length() == 0) { throw new ConfigurationException( diff --git a/src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java b/src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java index c2d9c52f6..66a7924ff 100644 --- a/src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java +++ b/src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java @@ -9,6 +9,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.magento.idea.magento2plugin.magento.files.ComposerJson; import com.magento.idea.magento2plugin.magento.packages.Package; import java.util.Arrays; import org.jetbrains.annotations.NotNull; @@ -18,7 +19,7 @@ public final class MagentoBasePathUtil { private MagentoBasePathUtil() {} /** - * Method detects Magento Framework Root. + * Method detects Magento Framework Root (check if magento framework exists). * * @param path String * @return boolean @@ -42,6 +43,25 @@ public static boolean isMagentoFolderValid(final String path) { return false; } + /** + * Check if composer.json exists in directory. + * + * @param path String + * @return boolean + */ + public static Boolean isComposerJsonExists(final String path) { + if (StringUtil.isEmptyOrSpaces(path)) { + return false; + } + final VirtualFile magentoRoot = LocalFileSystem.getInstance().findFileByPath(path); + + if (magentoRoot == null || !magentoRoot.isDirectory()) { + return false; + } + + return magentoRoot.findChild(ComposerJson.FILE_NAME) != null; + } + /** * Check if specified path belongs to the correct vendor name. *