Skip to content

Commit 2205c7b

Browse files
author
makzef
committed
1144: Add checks and detailed error messages during plugin activation
1 parent 1bbc95e commit 2205c7b

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

resources/magento2/validation.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
validator.notEmpty=The {0} field must not be empty
22
validator.box.notEmpty=The {0} field must contain a valid selection from the dropdown
33
validator.package.validPath=Please specify a valid Magento 2 installation path
4+
validator.package.validPathComposerFiles=File composer.json is missing in the current Magento 2 installation path
5+
validator.package.validPathVendor=Vendor dir is corrupt or missing in the current Magento 2 installation path
46
validator.properties.notEmpty=The properties must not be empty
57
validator.alphaNumericCharacters=The {0} field must contain letters and numbers only
68
validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only

src/com/magento/idea/magento2plugin/project/validator/SettingsFormValidator.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.intellij.openapi.options.ConfigurationException;
99
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
10+
import com.magento.idea.magento2plugin.magento.packages.Package;
1011
import com.magento.idea.magento2plugin.project.SettingsForm;
1112
import com.magento.idea.magento2plugin.util.RegExUtil;
1213
import com.magento.idea.magento2plugin.util.magento.MagentoBasePathUtil;
@@ -30,12 +31,29 @@ public SettingsFormValidator(
3031
*/
3132
public void validate() throws ConfigurationException {
3233
if (form.isBeingUsed()) {
33-
if (!MagentoBasePathUtil.isMagentoFolderValid(form.getMagentoPath())) {
34+
String magentoRootPath = form.getMagentoPath();
35+
boolean isMagentoFrameworkDirExist =
36+
MagentoBasePathUtil.isMagentoFolderValid(magentoRootPath);
37+
38+
if (!MagentoBasePathUtil.isComposerJsonExists(magentoRootPath)) {
39+
40+
if (isMagentoFrameworkDirExist) {
41+
throw new ConfigurationException(
42+
validatorBundle.message("validator.package.validPathComposerFiles")
43+
);
44+
}
45+
3446
throw new ConfigurationException(
3547
validatorBundle.message("validator.package.validPath")
3648
);
3749
}
3850

51+
if (!isMagentoFrameworkDirExist) {
52+
throw new ConfigurationException(
53+
validatorBundle.message("validator.package.validPathVendor")
54+
);
55+
}
56+
3957
final String magentoVersion = form.getMagentoVersion();
4058
if (magentoVersion.length() == 0) {
4159
throw new ConfigurationException(

src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.openapi.vfs.LocalFileSystem;
1010
import com.intellij.openapi.vfs.VfsUtil;
1111
import com.intellij.openapi.vfs.VirtualFile;
12+
import com.magento.idea.magento2plugin.magento.files.ComposerJson;
1213
import com.magento.idea.magento2plugin.magento.packages.Package;
1314
import java.util.Arrays;
1415
import org.jetbrains.annotations.NotNull;
@@ -18,7 +19,7 @@ public final class MagentoBasePathUtil {
1819
private MagentoBasePathUtil() {}
1920

2021
/**
21-
* Method detects Magento Framework Root.
22+
* Method detects Magento Framework Root (check if magento framework exists).
2223
*
2324
* @param path String
2425
* @return boolean
@@ -42,6 +43,25 @@ public static boolean isMagentoFolderValid(final String path) {
4243
return false;
4344
}
4445

46+
/**
47+
* Check if composer.json exists in directory.
48+
*
49+
* @param path String
50+
* @return boolean
51+
*/
52+
public static Boolean isComposerJsonExists(final String path) {
53+
if (StringUtil.isEmptyOrSpaces(path)) {
54+
return false;
55+
}
56+
final VirtualFile magentoRoot = LocalFileSystem.getInstance().findFileByPath(path);
57+
58+
if (magentoRoot == null || !magentoRoot.isDirectory()) {
59+
return false;
60+
}
61+
62+
return magentoRoot.findChild(ComposerJson.FILE_NAME) != null;
63+
}
64+
4565
/**
4666
* Check if specified path belongs to the correct vendor name.
4767
*

0 commit comments

Comments
 (0)