mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-140313 Gradle auto-import refreshes wrong project
This commit is contained in:
+14
-17
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user