mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Provide gradle extensions for DSL resolve for specified gradle project path notation
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
package org.jetbrains.plugins.gradle.service.resolve
|
||||
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.roots.ProjectFileIndex
|
||||
import com.intellij.openapi.util.Ref
|
||||
import com.intellij.psi.*
|
||||
@@ -52,23 +51,17 @@ class GradleNonCodeMembersContributor : NonCodeMembersContributor() {
|
||||
val methodCall = place.children.singleOrNull()
|
||||
if (methodCall is GrMethodCallExpression) {
|
||||
val projectPath = methodCall.argumentList.expressionArguments.singleOrNull()?.reference?.canonicalText ?: return
|
||||
if (projectPath == ":") {
|
||||
val file = containingFile?.originalFile?.virtualFile ?: return
|
||||
val module = ProjectFileIndex.SERVICE.getInstance(place.project).getModuleForFile(file)
|
||||
val rootProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module)
|
||||
extensionsData = GradleExtensionsSettings.getInstance(place.project).getExtensionsFor(rootProjectPath, rootProjectPath) ?: return
|
||||
}
|
||||
else {
|
||||
val module = ModuleManager.getInstance(place.project).findModuleByName(projectPath.trimStart(':')) ?: return
|
||||
extensionsData = GradleExtensionsSettings.getInstance(place.project).getExtensionsFor(module) ?: return
|
||||
}
|
||||
val file = containingFile?.originalFile?.virtualFile ?: return
|
||||
val module = ProjectFileIndex.SERVICE.getInstance(place.project).getModuleForFile(file)
|
||||
val rootProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module)
|
||||
extensionsData = GradleExtensionsSettings.getInstance(place.project).getExtensionsFor(rootProjectPath, projectPath) ?: return
|
||||
}
|
||||
else if (methodCall is GrReferenceExpression) {
|
||||
if (place.children[0].text == "rootProject") {
|
||||
val file = containingFile?.originalFile?.virtualFile ?: return
|
||||
val module = ProjectFileIndex.SERVICE.getInstance(place.project).getModuleForFile(file)
|
||||
val rootProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module)
|
||||
extensionsData = GradleExtensionsSettings.getInstance(place.project).getExtensionsFor(rootProjectPath, rootProjectPath) ?: return
|
||||
extensionsData = GradleExtensionsSettings.getInstance(place.project).getExtensionsFor(rootProjectPath, ":") ?: return
|
||||
}
|
||||
else return
|
||||
}
|
||||
|
||||
+28
-17
@@ -21,12 +21,11 @@ import org.jetbrains.plugins.gradle.config.GradleSettingsListenerAdapter;
|
||||
import org.jetbrains.plugins.gradle.model.ExternalTask;
|
||||
import org.jetbrains.plugins.gradle.model.GradleExtensions;
|
||||
import org.jetbrains.plugins.gradle.model.GradleProperty;
|
||||
import org.jetbrains.plugins.gradle.service.project.GradleProjectResolverUtil;
|
||||
import org.jetbrains.plugins.gradle.service.project.data.GradleExtensionsDataService;
|
||||
import org.jetbrains.plugins.gradle.service.resolve.GradleCommonClassNames;
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -76,8 +75,17 @@ public class GradleExtensionsSettings {
|
||||
DataNode<?> parent = node.getParent();
|
||||
if (parent == null) continue;
|
||||
if (!(parent.getData() instanceof ModuleData)) continue;
|
||||
String projectPath = ((ModuleData)parent.getData()).getLinkedExternalProjectPath();
|
||||
extensionMap.put(projectPath, node.getData());
|
||||
ModuleData moduleData = (ModuleData)parent.getData();
|
||||
String gradlePath;
|
||||
String moduleId = moduleData.getId();
|
||||
if (moduleId.charAt(0) != ':') {
|
||||
int colonIndex = moduleId.indexOf(':');
|
||||
gradlePath = colonIndex > 0 ? moduleId.substring(colonIndex) : ":";
|
||||
}
|
||||
else {
|
||||
gradlePath = moduleId;
|
||||
}
|
||||
extensionMap.put(gradlePath, node.getData());
|
||||
}
|
||||
|
||||
add(rootPath, extensionMap);
|
||||
@@ -88,15 +96,8 @@ public class GradleExtensionsSettings {
|
||||
for (Map.Entry<String, GradleExtensions> entry : extensions.entrySet()) {
|
||||
GradleExtensionsData extensionsData = new GradleExtensionsData();
|
||||
GradleExtensions gradleExtensions = entry.getValue();
|
||||
try {
|
||||
File parentProjectDir = gradleExtensions.getParentProjectDir();
|
||||
if (parentProjectDir != null) {
|
||||
extensionsData.parent = ExternalSystemApiUtil.toCanonicalPath(parentProjectDir.getCanonicalPath());
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.warn("construction of the canonical path for the gradle project fails", e);
|
||||
}
|
||||
extensionsData.parent = gradleExtensions.getParentProjectPath();
|
||||
|
||||
for (org.jetbrains.plugins.gradle.model.GradleExtension extension : gradleExtensions.getExtensions()) {
|
||||
GradleExtension gradleExtension = new GradleExtension();
|
||||
gradleExtension.name = extension.getName();
|
||||
@@ -164,19 +165,29 @@ public class GradleExtensionsSettings {
|
||||
this.projects = projects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extensions available in the context of the gradle project related to the IDE module.
|
||||
*/
|
||||
@Nullable
|
||||
public GradleExtensionsData getExtensionsFor(@Nullable Module module) {
|
||||
if (module == null) return null;
|
||||
return getExtensionsFor(ExternalSystemApiUtil.getExternalRootProjectPath(module),
|
||||
ExternalSystemApiUtil.getExternalProjectPath(module));
|
||||
GradleProjectResolverUtil.getGradlePath(module));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns extensions available in the context of the specified (using gradle path notation, e.g. `:sub-project`) gradle project.
|
||||
*
|
||||
* @param rootProjectPath file path of the root gradle project
|
||||
* @param gradlePath gradle project path notation
|
||||
* @return gradle extensions
|
||||
*/
|
||||
@Nullable
|
||||
public GradleExtensionsData getExtensionsFor(@Nullable String rootProjectPath, @Nullable String projectPath) {
|
||||
if (rootProjectPath == null || projectPath == null) return null;
|
||||
public GradleExtensionsData getExtensionsFor(@Nullable String rootProjectPath, @Nullable String gradlePath) {
|
||||
if (rootProjectPath == null || gradlePath == null) return null;
|
||||
GradleProject gradleProject = projects.get(rootProjectPath);
|
||||
if (gradleProject == null) return null;
|
||||
return gradleProject.extensions.get(projectPath);
|
||||
return gradleProject.extensions.get(gradlePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -18,7 +18,6 @@ package org.jetbrains.plugins.gradle.model;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,7 +26,7 @@ import java.util.List;
|
||||
*/
|
||||
public interface GradleExtensions extends Serializable {
|
||||
@Nullable
|
||||
File getParentProjectDir();
|
||||
String getParentProjectPath();
|
||||
|
||||
@NotNull
|
||||
List<GradleExtension> getExtensions();
|
||||
|
||||
+6
-7
@@ -18,7 +18,6 @@ package org.jetbrains.plugins.gradle.model;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,7 +26,7 @@ import java.util.List;
|
||||
*/
|
||||
public class DefaultGradleExtensions implements GradleExtensions {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private File myParentProjectDir;
|
||||
private String myParentProjectPath;
|
||||
@NotNull
|
||||
private final List<GradleExtension> myExtensions = new ArrayList<GradleExtension>();
|
||||
@NotNull
|
||||
@@ -43,7 +42,7 @@ public class DefaultGradleExtensions implements GradleExtensions {
|
||||
}
|
||||
|
||||
public DefaultGradleExtensions(GradleExtensions extensions) {
|
||||
myParentProjectDir = extensions.getParentProjectDir();
|
||||
myParentProjectPath = extensions.getParentProjectPath();
|
||||
for (GradleExtension extension : extensions.getExtensions()) {
|
||||
myExtensions.add(new DefaultGradleExtension(extension));
|
||||
}
|
||||
@@ -63,12 +62,12 @@ public class DefaultGradleExtensions implements GradleExtensions {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public File getParentProjectDir() {
|
||||
return myParentProjectDir;
|
||||
public String getParentProjectPath() {
|
||||
return myParentProjectPath;
|
||||
}
|
||||
|
||||
public void setParentProjectDir(File parentProjectDir) {
|
||||
myParentProjectDir = parentProjectDir;
|
||||
public void setParentProjectPath(String parentProjectPath) {
|
||||
myParentProjectPath = parentProjectPath;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ class ProjectExtensionsDataBuilderImpl implements ModelBuilderService {
|
||||
@Override
|
||||
Object buildAll(String modelName, Project project) {
|
||||
DefaultGradleExtensions result = new DefaultGradleExtensions()
|
||||
result.parentProjectDir = project.parent?.projectDir
|
||||
result.parentProjectPath = project.parent?.path
|
||||
|
||||
for (it in project.configurations) {
|
||||
result.configurations.add(new DefaultGradleConfiguration(it.name, it.description, it.visible))
|
||||
|
||||
Reference in New Issue
Block a user