File tree 3 files changed +40
-2
lines changed
src/com/magento/idea/magento2plugin
3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change 1
1
validator.notEmpty =The {0} field must not be empty
2
2
validator.box.notEmpty =The {0} field must contain a valid selection from the dropdown
3
3
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
4
6
validator.properties.notEmpty =The properties must not be empty
5
7
validator.alphaNumericCharacters =The {0} field must contain letters and numbers only
6
8
validator.alphaNumericAndUnderscoreCharacters ={0} must contain letters, numbers and underscores only
Original file line number Diff line number Diff line change @@ -28,14 +28,30 @@ public SettingsFormValidator(
28
28
*
29
29
* @throws ConfigurationException Exception
30
30
*/
31
+ @ SuppressWarnings ({"PMD.CyclomaticComplexity" , "PMD.AvoidDeeplyNestedIfStmts" })
31
32
public void validate () throws ConfigurationException {
32
33
if (form .isBeingUsed ()) {
33
- if (!MagentoBasePathUtil .isMagentoFolderValid (form .getMagentoPath ())) {
34
+ final String magentoRootPath = form .getMagentoPath ();
35
+ final boolean isMagentoFrameworkDirExist =
36
+ MagentoBasePathUtil .isMagentoFolderValid (magentoRootPath );
37
+
38
+ if (!MagentoBasePathUtil .isComposerJsonExists (magentoRootPath )) {
39
+ if (isMagentoFrameworkDirExist ) {
40
+ throw new ConfigurationException (
41
+ validatorBundle .message ("validator.package.validPathComposerFiles" )
42
+ );
43
+ }
34
44
throw new ConfigurationException (
35
45
validatorBundle .message ("validator.package.validPath" )
36
46
);
37
47
}
38
48
49
+ if (!isMagentoFrameworkDirExist ) {
50
+ throw new ConfigurationException (
51
+ validatorBundle .message ("validator.package.validPathVendor" )
52
+ );
53
+ }
54
+
39
55
final String magentoVersion = form .getMagentoVersion ();
40
56
if (magentoVersion .length () == 0 ) {
41
57
throw new ConfigurationException (
Original file line number Diff line number Diff line change 9
9
import com .intellij .openapi .vfs .LocalFileSystem ;
10
10
import com .intellij .openapi .vfs .VfsUtil ;
11
11
import com .intellij .openapi .vfs .VirtualFile ;
12
+ import com .magento .idea .magento2plugin .magento .files .ComposerJson ;
12
13
import com .magento .idea .magento2plugin .magento .packages .Package ;
13
14
import java .util .Arrays ;
14
15
import org .jetbrains .annotations .NotNull ;
@@ -18,7 +19,7 @@ public final class MagentoBasePathUtil {
18
19
private MagentoBasePathUtil () {}
19
20
20
21
/**
21
- * Method detects Magento Framework Root.
22
+ * Method detects Magento Framework Root (check if magento framework exists) .
22
23
*
23
24
* @param path String
24
25
* @return boolean
@@ -42,6 +43,25 @@ public static boolean isMagentoFolderValid(final String path) {
42
43
return false ;
43
44
}
44
45
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
+
45
65
/**
46
66
* Check if specified path belongs to the correct vendor name.
47
67
*
You can’t perform that action at this time.
0 commit comments