Skip to content

Commit

Permalink
1144: Add checks and detailed error messages during plugin activation
Browse files Browse the repository at this point in the history
  • Loading branch information
makzef committed Sep 12, 2022
1 parent 1bbc95e commit 4e81303
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions resources/magento2/validation.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,32 @@ 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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.
*
Expand Down

0 comments on commit 4e81303

Please sign in to comment.