IDEA-140313 Gradle auto-import refreshes wrong project

This commit is contained in:
Vladislav.Soroka
2016-04-06 10:40:55 +03:00
parent d446f659ef
commit 1c8d26245a
@@ -21,14 +21,13 @@ import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettin
import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.project.Project;
import com.intellij.util.containers.ContainerUtilRt;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.util.GradleConstants;
import java.io.File;
import java.util.Collection;
import java.util.Map;
/**
* @author Denis Zhdanov
@@ -50,21 +49,19 @@ public class GradleAutoImportAware implements ExternalSystemAutoImportAware {
if (projectsSettings.isEmpty()) {
return null;
}
Map<String /* config dir path */, String /* config file path */> rootPaths = ContainerUtilRt.newHashMap();
for (ExternalProjectSettings setting : projectsSettings) {
if(setting != null && setting.getExternalProjectPath() != null) {
File rootPath = new File(setting.getExternalProjectPath());
if(rootPath.getParentFile() != null) {
rootPaths.put(rootPath.getParentFile().getAbsolutePath(), setting.getExternalProjectPath());
}
}
}
for (File f = new File(changedFileOrDirPath).getParentFile(); f != null; f = f.getParentFile()) {
String dirPath = f.getAbsolutePath();
String configFilePath = rootPaths.get(dirPath);
if (rootPaths.containsKey(dirPath)) {
return configFilePath;
for (ExternalProjectSettings setting : projectsSettings) {
String rootProjectPath = setting.getExternalProjectPath();
if (FileUtil.isAncestor(rootProjectPath, changedFileOrDirPath, false)) {
return rootProjectPath;
} else {
// honor multi-projects with flat structure
for (String modulePath : setting.getModules()) {
if(StringUtil.equals(modulePath, rootProjectPath)) continue;
if (FileUtil.isAncestor(modulePath, changedFileOrDirPath, false)) {
return rootProjectPath;
}
}
}
}
return null;