Skip to content

Commit eba1ab6

Browse files
authored
Merge branch '4.4.0-develop' into 1179-fix-compatibility-issues
2 parents c168afc + e6be25d commit eba1ab6

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

resources/magento2/validation.properties

+2
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/inspections/xml/ObserverDeclarationInspection.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.codeInspection.ProblemHighlightType;
99
import com.intellij.codeInspection.ProblemsHolder;
1010
import com.intellij.ide.highlighter.XmlFileType;
11+
import com.intellij.openapi.externalSystem.service.execution.NotSupportedException;
1112
import com.intellij.openapi.vfs.VfsUtil;
1213
import com.intellij.openapi.vfs.VirtualFile;
1314
import com.intellij.psi.PsiElement;
@@ -71,6 +72,10 @@ public void visitFile(final @NotNull PsiFile file) {
7172
return;
7273
}
7374

75+
// This added to cover case if file exists only in memory.
76+
if (file.getContainingDirectory() == null) {
77+
return;
78+
}
7479
final EventIndex eventIndex = new EventIndex(file.getProject());
7580
final HashMap<String, XmlTag> targetObserversHash = new HashMap<>();
7681

@@ -108,7 +113,8 @@ public void visitFile(final @NotNull PsiFile file) {
108113
}
109114

110115
final String observerName = observerNameAttribute.getValue();
111-
if (observerName == null) {
116+
if (observerName == null
117+
|| observerNameAttribute.getValueElement() == null) {
112118
continue;
113119
}
114120

@@ -188,6 +194,11 @@ private List<HashMap<String, String>> fetchModuleNamesWhereSameObserverNameUsed(
188194
final EventIndex eventIndex,
189195
final PsiFile file
190196
) {
197+
if (file.getContainingDirectory() == null) {
198+
throw new NotSupportedException(
199+
"Operation is not supported for files in memory"
200+
);
201+
}
191202
final List<HashMap<String, String>> modulesName = new ArrayList<>();
192203
final String currentFileDirectory = file.getContainingDirectory().toString();
193204
final String currentFileFullPath = currentFileDirectory

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,30 @@ public SettingsFormValidator(
2828
*
2929
* @throws ConfigurationException Exception
3030
*/
31+
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.AvoidDeeplyNestedIfStmts"})
3132
public void validate() throws ConfigurationException {
3233
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+
}
3444
throw new ConfigurationException(
3545
validatorBundle.message("validator.package.validPath")
3646
);
3747
}
3848

49+
if (!isMagentoFrameworkDirExist) {
50+
throw new ConfigurationException(
51+
validatorBundle.message("validator.package.validPathVendor")
52+
);
53+
}
54+
3955
final String magentoVersion = form.getMagentoVersion();
4056
if (magentoVersion.length() == 0) {
4157
throw new ConfigurationException(

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

+21-1
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)