Skip to content

1144: Add checks and detailed error messages during plugin activation #1181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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(
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