diff --git a/.consulo/runConfigurations/consulo_run_desktop_awt.xml b/.consulo/runConfigurations/consulo_run_desktop_awt.xml
new file mode 100644
index 0000000..b85bc2f
--- /dev/null
+++ b/.consulo/runConfigurations/consulo_run_desktop_awt.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 0000000..a666fa4
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,25 @@
+name: jdk21
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
+
+env:
+ BUILD_NUMBER: 999999
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK 21
+ uses: actions/setup-java@v1
+ with:
+ distribution: 'temurin'
+ java-version: 21
+ - name: Build with Maven
+ run: mvn -U -T 1C -Dmaven.javadoc.skip=true -B -V clean package
diff --git a/.gitignore b/.gitignore
index b561e99..67f1d91 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
+/.consulo
+!/.consulo/codeStyleSettings.xml
+!/.consulo/runConfigurations
/out
/dep
-.consulo/
target/
diff --git a/gradle-api/src/main/java/consulo/gradle/service/project/AbstractProjectResolverExtension.java b/gradle-api/src/main/java/consulo/gradle/service/project/AbstractProjectResolverExtension.java
index 8e9e306..99ea1b0 100644
--- a/gradle-api/src/main/java/consulo/gradle/service/project/AbstractProjectResolverExtension.java
+++ b/gradle-api/src/main/java/consulo/gradle/service/project/AbstractProjectResolverExtension.java
@@ -23,7 +23,7 @@
import consulo.externalSystem.service.project.ProjectData;
import consulo.process.ExecutionException;
import consulo.process.cmd.SimpleJavaParameters;
-import consulo.util.lang.Pair;
+import consulo.util.lang.Couple;
import org.gradle.tooling.model.idea.IdeaModule;
import org.gradle.tooling.model.idea.IdeaProject;
@@ -40,139 +40,147 @@
* {@link AbstractProjectResolverExtension} provides dummy implementation of Gradle project resolver.
*
* @author Vladislav.Soroka
- * @since 10/14/13
+ * @since 2013-10-14
*/
public abstract class AbstractProjectResolverExtension implements GradleProjectResolverExtension {
- @Nonnull
- protected ProjectResolverContext resolverCtx;
- @Nonnull
- protected GradleProjectResolverExtension nextResolver;
-
- @Override
- public void setProjectResolverContext(@Nonnull ProjectResolverContext projectResolverContext) {
- resolverCtx = projectResolverContext;
- }
-
- @Override
- public void setNext(@Nonnull GradleProjectResolverExtension next) {
- // there always should be at least gradle basic resolver further in the chain
- //noinspection ConstantConditions
- assert next != null;
- nextResolver = next;
- }
-
- @Nullable
- @Override
- public GradleProjectResolverExtension getNext() {
- return nextResolver;
- }
-
- @Nonnull
- @Override
- public ProjectData createProject() {
- return nextResolver.createProject();
- }
-
- @Nonnull
- @Override
- public JavaProjectData createJavaProjectData() {
- return nextResolver.createJavaProjectData();
- }
-
- @Override
- public void populateProjectExtraModels(@Nonnull IdeaProject gradleProject, @Nonnull DataNode ideProject) {
- nextResolver.populateProjectExtraModels(gradleProject, ideProject);
- }
-
- @Nonnull
- @Override
- public ModuleData createModule(@Nonnull IdeaModule gradleModule, @Nonnull ProjectData projectData) {
- return nextResolver.createModule(gradleModule, projectData);
- }
-
- @Override
- public void populateModuleExtraModels(@Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule) {
- nextResolver.populateModuleExtraModels(gradleModule, ideModule);
- }
-
- @Override
- public void populateModuleContentRoots(@Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule) {
- nextResolver.populateModuleContentRoots(gradleModule, ideModule);
- }
-
-
- @Override
- public void populateModuleCompileOutputSettings(@Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule) {
- nextResolver.populateModuleCompileOutputSettings(gradleModule, ideModule);
- }
-
- @Override
- public void populateModuleDependencies(@Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule,
- @Nonnull DataNode ideProject) {
- nextResolver.populateModuleDependencies(gradleModule, ideModule, ideProject);
- }
-
- @Nonnull
- @Override
- public Collection populateModuleTasks(@Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule,
- @Nonnull DataNode ideProject) throws IllegalArgumentException, IllegalStateException {
- return nextResolver.populateModuleTasks(gradleModule, ideModule, ideProject);
- }
-
- @Nonnull
- @Override
- public Collection filterRootProjectTasks(@Nonnull List allTasks) {
- return nextResolver.filterRootProjectTasks(allTasks);
- }
-
- @Nonnull
- @Override
- public Set getExtraProjectModelClasses() {
- return Collections.emptySet();
- }
-
- @Nonnull
- @Override
- public Set getToolingExtensionsClasses() {
- return Collections.emptySet();
- }
-
- @Nonnull
- @Override
- public List> getExtraJvmArgs() {
- return Collections.emptyList();
- }
-
- @Nonnull
- @Override
- public List getExtraCommandLineArgs() {
- return Collections.emptyList();
- }
-
- @Nonnull
- @Override
- public ExternalSystemException getUserFriendlyError(@Nonnull Throwable error,
- @Nonnull String projectPath,
- @Nullable String buildFilePath) {
- return nextResolver.getUserFriendlyError(error, projectPath, buildFilePath);
- }
-
- @Override
- public void enhanceRemoteProcessing(@Nonnull SimpleJavaParameters parameters) throws ExecutionException {
- }
-
- @Override
- public void enhanceLocalProcessing(@Nonnull List urls) {
- }
-
- @Override
- public void preImportCheck() {
- }
-
- @Override
- public void enhanceTaskProcessing(@Nonnull List taskNames,
- @Nullable String debuggerSetup,
- @Nonnull Consumer initScriptConsumer) {
- }
+ @Nonnull
+ protected ProjectResolverContext resolverCtx;
+ @Nonnull
+ protected GradleProjectResolverExtension nextResolver;
+
+ @Override
+ public void setProjectResolverContext(@Nonnull ProjectResolverContext projectResolverContext) {
+ resolverCtx = projectResolverContext;
+ }
+
+ @Override
+ public void setNext(@Nonnull GradleProjectResolverExtension next) {
+ // there always should be at least gradle basic resolver further in the chain
+ //noinspection ConstantConditions
+ assert next != null;
+ nextResolver = next;
+ }
+
+ @Nullable
+ @Override
+ public GradleProjectResolverExtension getNext() {
+ return nextResolver;
+ }
+
+ @Nonnull
+ @Override
+ public ProjectData createProject() {
+ return nextResolver.createProject();
+ }
+
+ @Nonnull
+ @Override
+ public JavaProjectData createJavaProjectData() {
+ return nextResolver.createJavaProjectData();
+ }
+
+ @Override
+ public void populateProjectExtraModels(@Nonnull IdeaProject gradleProject, @Nonnull DataNode ideProject) {
+ nextResolver.populateProjectExtraModels(gradleProject, ideProject);
+ }
+
+ @Nonnull
+ @Override
+ public ModuleData createModule(@Nonnull IdeaModule gradleModule, @Nonnull ProjectData projectData) {
+ return nextResolver.createModule(gradleModule, projectData);
+ }
+
+ @Override
+ public void populateModuleExtraModels(@Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule) {
+ nextResolver.populateModuleExtraModels(gradleModule, ideModule);
+ }
+
+ @Override
+ public void populateModuleContentRoots(@Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule) {
+ nextResolver.populateModuleContentRoots(gradleModule, ideModule);
+ }
+
+
+ @Override
+ public void populateModuleCompileOutputSettings(@Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule) {
+ nextResolver.populateModuleCompileOutputSettings(gradleModule, ideModule);
+ }
+
+ @Override
+ public void populateModuleDependencies(
+ @Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule,
+ @Nonnull DataNode ideProject
+ ) {
+ nextResolver.populateModuleDependencies(gradleModule, ideModule, ideProject);
+ }
+
+ @Nonnull
+ @Override
+ public Collection populateModuleTasks(
+ @Nonnull IdeaModule gradleModule, @Nonnull DataNode ideModule,
+ @Nonnull DataNode ideProject
+ ) throws IllegalArgumentException, IllegalStateException {
+ return nextResolver.populateModuleTasks(gradleModule, ideModule, ideProject);
+ }
+
+ @Nonnull
+ @Override
+ public Collection filterRootProjectTasks(@Nonnull List allTasks) {
+ return nextResolver.filterRootProjectTasks(allTasks);
+ }
+
+ @Nonnull
+ @Override
+ public Set getExtraProjectModelClasses() {
+ return Collections.emptySet();
+ }
+
+ @Nonnull
+ @Override
+ public Set getToolingExtensionsClasses() {
+ return Collections.emptySet();
+ }
+
+ @Nonnull
+ @Override
+ public List> getExtraJvmArgs() {
+ return Collections.emptyList();
+ }
+
+ @Nonnull
+ @Override
+ public List getExtraCommandLineArgs() {
+ return Collections.emptyList();
+ }
+
+ @Nonnull
+ @Override
+ public ExternalSystemException getUserFriendlyError(
+ @Nonnull Throwable error,
+ @Nonnull String projectPath,
+ @Nullable String buildFilePath
+ ) {
+ return nextResolver.getUserFriendlyError(error, projectPath, buildFilePath);
+ }
+
+ @Override
+ public void enhanceRemoteProcessing(@Nonnull SimpleJavaParameters parameters) throws ExecutionException {
+ }
+
+ @Override
+ public void enhanceLocalProcessing(@Nonnull List urls) {
+ }
+
+ @Override
+ public void preImportCheck() {
+ }
+
+ @Override
+ public void enhanceTaskProcessing(
+ @Nonnull List taskNames,
+ @Nullable String debuggerSetup,
+ @Nonnull Consumer initScriptConsumer
+ ) {
+ }
}
diff --git a/gradle-api/src/main/java/consulo/gradle/service/project/GradleProjectResolverExtension.java b/gradle-api/src/main/java/consulo/gradle/service/project/GradleProjectResolverExtension.java
index 454f4a5..0663390 100644
--- a/gradle-api/src/main/java/consulo/gradle/service/project/GradleProjectResolverExtension.java
+++ b/gradle-api/src/main/java/consulo/gradle/service/project/GradleProjectResolverExtension.java
@@ -25,7 +25,7 @@
import consulo.externalSystem.rt.model.ExternalSystemException;
import consulo.externalSystem.service.ParametersEnhancer;
import consulo.externalSystem.service.project.ProjectData;
-import consulo.util.lang.Pair;
+import consulo.util.lang.Couple;
import org.gradle.tooling.model.idea.IdeaModule;
import org.gradle.tooling.model.idea.IdeaProject;
@@ -111,7 +111,7 @@ Collection populateModuleTasks(@Nonnull IdeaModule gradleModule, @Nonn
Set getToolingExtensionsClasses();
@Nonnull
- List> getExtraJvmArgs();
+ List> getExtraJvmArgs();
@Nonnull
List getExtraCommandLineArgs();
diff --git a/maven-impl/src/main/java/module-info.java b/maven-impl/src/main/java/module-info.java
index 115ea8b..ce3daa8 100644
--- a/maven-impl/src/main/java/module-info.java
+++ b/maven-impl/src/main/java/module-info.java
@@ -1,10 +1,10 @@
/**
* @author VISTALL
- * @since 01/04/2023
+ * @since 2023-04-01
*/
module org.jetbrains.plugins.gradle.maven.impl {
- requires consulo.ide.api;
- requires org.jetbrains.plugins.gradle.api;
- requires org.jetbrains.idea.maven;
- requires org.jetbrains.idea.maven.server.common;
+ requires consulo.ide.api;
+ requires org.jetbrains.plugins.gradle.api;
+ requires org.jetbrains.idea.maven;
+ requires org.jetbrains.idea.maven.server.common;
}
\ No newline at end of file
diff --git a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleMavenProjectImportNotificationListener.java b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleMavenProjectImportNotificationListener.java
index 6eeebd6..f6c7aee 100644
--- a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleMavenProjectImportNotificationListener.java
+++ b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleMavenProjectImportNotificationListener.java
@@ -29,18 +29,19 @@
* {@link GradleMavenProjectImportNotificationListener} listens for Gradle project import events.
*
* @author Vladislav.Soroka
- * @since 10/28/13
+ * @since 2013-10-28
*/
@ExtensionImpl
public class GradleMavenProjectImportNotificationListener extends ExternalSystemTaskNotificationListenerAdapter {
-
- @Override
- public void onSuccess(@Nonnull ExternalSystemTaskId id) {
- if (GradleConstants.SYSTEM_ID.getId().equals(id.getProjectSystemId().getId())
- && id.getType() == ExternalSystemTaskType.RESOLVE_PROJECT) {
- final Project project = id.findProject();
- if (project == null) return;
- Application.get().invokeLater(new ImportMavenRepositoriesTask(project));
+ @Override
+ public void onSuccess(@Nonnull ExternalSystemTaskId id) {
+ if (GradleConstants.SYSTEM_ID.getId().equals(id.getProjectSystemId().getId())
+ && id.getType() == ExternalSystemTaskType.RESOLVE_PROJECT) {
+ final Project project = id.findProject();
+ if (project == null) {
+ return;
+ }
+ Application.get().invokeLater(new ImportMavenRepositoriesTask(project));
+ }
}
- }
}
diff --git a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleMavenRepositoryProvider.java b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleMavenRepositoryProvider.java
index 130494a..fdd6a9e 100644
--- a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleMavenRepositoryProvider.java
+++ b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleMavenRepositoryProvider.java
@@ -25,14 +25,13 @@
/**
* @author Vladislav.Soroka
- * @since 10/25/13
+ * @since 2013-10-25
*/
@ExtensionImpl
public class GradleMavenRepositoryProvider implements MavenRepositoryProvider {
-
- @Nonnull
- @Override
- public Set getRemoteRepositories(@Nonnull Project project) {
- return MavenRepositoriesHolder.getInstance(project).getRemoteRepositories();
- }
+ @Nonnull
+ @Override
+ public Set getRemoteRepositories(@Nonnull Project project) {
+ return MavenRepositoriesHolder.getInstance(project).getRemoteRepositories();
+ }
}
diff --git a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleProjectStartupActivity.java b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleProjectStartupActivity.java
index bc86929..c23bc90 100644
--- a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleProjectStartupActivity.java
+++ b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/GradleProjectStartupActivity.java
@@ -25,13 +25,12 @@
/**
* @author Vladislav.Soroka
- * @since 10/28/13
+ * @since 2013-10-28
*/
@ExtensionImpl
public class GradleProjectStartupActivity implements PostStartupActivity {
-
- @Override
- public void runActivity(@Nonnull final Project project, @Nonnull UIAccess uiAccess) {
- DumbService.getInstance(project).smartInvokeLater(new ImportMavenRepositoriesTask(project));
- }
+ @Override
+ public void runActivity(@Nonnull final Project project, @Nonnull UIAccess uiAccess) {
+ DumbService.getInstance(project).smartInvokeLater(new ImportMavenRepositoriesTask(project));
+ }
}
diff --git a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/ImportMavenRepositoriesTask.java b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/ImportMavenRepositoriesTask.java
index 978ccd8..07194cf 100644
--- a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/ImportMavenRepositoriesTask.java
+++ b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/ImportMavenRepositoriesTask.java
@@ -16,6 +16,7 @@
package org.jetbrains.plugins.gradle.integrations.maven;
import com.intellij.java.language.psi.PsiLiteral;
+import consulo.annotation.access.RequiredReadAction;
import consulo.application.ReadAction;
import consulo.externalSystem.util.ExternalSystemApiUtil;
import consulo.externalSystem.util.ExternalSystemConstants;
@@ -51,241 +52,241 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
-import java.util.function.Consumer;
-import java.util.function.Function;
/**
* @author Vladislav.Soroka
- * @since 10/29/13
+ * @since 2013-10-29
*/
public class ImportMavenRepositoriesTask implements Runnable {
- @Nonnull
- private final static MavenRemoteRepository mavenCentralRemoteRepository;
+ @Nonnull
+ private final static MavenRemoteRepository mavenCentralRemoteRepository;
- static {
- mavenCentralRemoteRepository = new MavenRemoteRepository("central", null, "https://repo1.maven.org/maven2/", null, null, null);
- }
-
- private final Project myProject;
+ static {
+ mavenCentralRemoteRepository =
+ new MavenRemoteRepository("central", null, "https://repo1.maven.org/maven2/", null, null, null);
+ }
- public ImportMavenRepositoriesTask(Project project) {
- myProject = project;
- }
+ private final Project myProject;
- @Override
- public void run() {
- if (myProject.isDisposed()) {
- return;
+ public ImportMavenRepositoriesTask(Project project) {
+ myProject = project;
}
- final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
- final List psiFileList = new ArrayList<>();
-
- final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
- for (Module module : moduleManager.getModules()) {
- final String externalSystemId =
- ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY);
- final String modulePath = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.LINKED_PROJECT_PATH_KEY);
- if (!GradleConstants.SYSTEM_ID.getId().equals(externalSystemId) || modulePath == null) {
- continue;
- }
-
- String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
- if (StringUtil.isEmpty(buildScript)) {
- continue;
- }
-
- VirtualFile virtualFile =
- localFileSystem.refreshAndFindFileByPath(buildScript);
- if (virtualFile == null) {
- continue;
- }
-
- final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
- if (psiFile == null) {
- continue;
- }
- psiFileList.add(psiFile);
- }
+ @Override
+ @RequiredReadAction
+ public void run() {
+ if (myProject.isDisposed()) {
+ return;
+ }
- final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
-
- final Set mavenRemoteRepositories = ReadAction.compute(() ->
- {
- Set remoteRepositories =
- new HashSet<>();
- for (PsiFile psiFile : psiFiles) {
- List repositoriesBlocks =
- new ArrayList<>();
- repositoriesBlocks.addAll(findClosableBlocks(psiFile,
- "repositories"));
-
- for (GrClosableBlock closableBlock : findClosableBlocks(
- psiFile,
- "buildscript",
- "subprojects",
- "allprojects",
- "project",
- "configure")) {
- repositoriesBlocks.addAll(findClosableBlocks(
- closableBlock,
- "repositories"));
- }
-
- for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
- remoteRepositories.addAll(
- findMavenRemoteRepositories(repositoriesBlock));
- }
- }
-
- return remoteRepositories;
- });
-
- if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty()) {
- return;
- }
+ final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
+ final List psiFileList = new ArrayList<>();
+
+ final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
+ for (Module module : moduleManager.getModules()) {
+ final String externalSystemId =
+ ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY);
+ final String modulePath =
+ ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.LINKED_PROJECT_PATH_KEY);
+ if (!GradleConstants.SYSTEM_ID.getId().equals(externalSystemId) || modulePath == null) {
+ continue;
+ }
- MavenRepositoriesHolder.getInstance(myProject).update(mavenRemoteRepositories);
+ String buildScript = FileUtil.findFileInProvidedPath(modulePath, GradleConstants.DEFAULT_SCRIPT_NAME);
+ if (StringUtil.isEmpty(buildScript)) {
+ continue;
+ }
- MavenProjectIndicesManager.getInstance(myProject).scheduleUpdateIndicesList(new Consumer>() {
- @Override
- public void accept(List indexes) {
- for (MavenIndex mavenIndex : indexes) {
- if (mavenIndex.getUpdateTimestamp() == -1 &&
- MavenRepositoriesHolder.getInstance(myProject).contains(mavenIndex.getRepositoryId())) {
- MavenProjectIndicesManager.getInstance(myProject).scheduleUpdate(Collections.singletonList(mavenIndex));
- }
- }
- }
- });
- }
-
- @Nonnull
- private static Collection extends GrClosableBlock> findClosableBlocks(@Nonnull final PsiElement element,
- @Nonnull final String... blockNames) {
- List methodCalls = PsiTreeUtil.getChildrenOfTypeAsList(element, GrMethodCall.class);
- return ContainerUtil.mapNotNull(methodCalls, new Function() {
- @Override
- public GrClosableBlock apply(GrMethodCall call) {
- if (call == null || call.getClosureArguments().length != 1) {
- return null;
- }
+ VirtualFile virtualFile = localFileSystem.refreshAndFindFileByPath(buildScript);
+ if (virtualFile == null) {
+ continue;
+ }
- GrExpression expression = call.getInvokedExpression();
- return expression != null && ArrayUtil.contains(expression.getText(), blockNames) ? call.getClosureArguments()[0] : null;
- }
- });
- }
-
- @Nonnull
- private static Collection extends MavenRemoteRepository> findMavenRemoteRepositories(@Nullable GrClosableBlock repositoriesBlock) {
- Set myRemoteRepositories = new HashSet<>();
- for (GrMethodCall repo : PsiTreeUtil
- .getChildrenOfTypeAsList(repositoriesBlock, GrMethodCall.class)) {
- if (repo.getInvokedExpression() == null) {
- continue;
- }
-
- final String expressionText = repo.getInvokedExpression().getText();
- if ("mavenCentral".equals(expressionText)) {
- myRemoteRepositories.add(mavenCentralRemoteRepository);
- }
- else if ("mavenRepo".equals(expressionText)) {
- for (GrNamedArgument namedArgument : repo.getNamedArguments()) {
- if ("url".equals(namedArgument.getLabelName())) {
- URI urlArgumentValue = resolveUriFromSimpleExpression(namedArgument.getExpression());
- if (urlArgumentValue != null) {
- String textUri = urlArgumentValue.toString();
- myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
+ final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(virtualFile);
+ if (psiFile == null) {
+ continue;
}
- break;
- }
+ psiFileList.add(psiFile);
}
- }
- else if ("maven".equals(expressionText) && repo.getClosureArguments().length > 0) {
- List applicationStatementList =
- PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrApplicationStatement.class);
- if (!applicationStatementList.isEmpty()) {
- GrApplicationStatement statement = applicationStatementList.get(0);
- if (statement == null) {
- continue;
- }
- GrExpression expression = statement.getInvokedExpression();
- if (expression == null) {
- continue;
- }
-
- if ("url".equals(expression.getText())) {
- URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getExpressionArguments()[0]);
- if (urlArgumentValue != null) {
- String textUri = urlArgumentValue.toString();
- myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
+
+ final PsiFile[] psiFiles = ArrayUtil.toObjectArray(psiFileList, PsiFile.class);
+
+ final Set mavenRemoteRepositories = ReadAction.compute(() -> {
+ Set remoteRepositories = new HashSet<>();
+ for (PsiFile psiFile : psiFiles) {
+ List repositoriesBlocks = new ArrayList<>();
+ repositoriesBlocks.addAll(findClosableBlocks(psiFile, "repositories"));
+
+ for (GrClosableBlock closableBlock :
+ findClosableBlocks(psiFile, "buildscript", "subprojects", "allprojects", "project", "configure")) {
+ repositoriesBlocks.addAll(findClosableBlocks(closableBlock, "repositories"));
+ }
+
+ for (GrClosableBlock repositoriesBlock : repositoriesBlocks) {
+ remoteRepositories.addAll(findMavenRemoteRepositories(repositoriesBlock));
+ }
}
- }
+
+ return remoteRepositories;
+ });
+
+ if (mavenRemoteRepositories == null || mavenRemoteRepositories.isEmpty()) {
+ return;
}
- List assignmentExpressionList =
- PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrAssignmentExpression.class);
- if (!assignmentExpressionList.isEmpty()) {
- GrAssignmentExpression statement = assignmentExpressionList.get(0);
- if (statement == null) {
- continue;
- }
- GrExpression expression = statement.getLValue();
-
- if ("url".equals(expression.getText())) {
- URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getRValue());
- if (urlArgumentValue != null) {
- String textUri = urlArgumentValue.toString();
- myRemoteRepositories.add(new MavenRemoteRepository(textUri, null, textUri, null, null, null));
+ MavenRepositoriesHolder repositoriesHolder = MavenRepositoriesHolder.getInstance(myProject);
+ MavenProjectIndicesManager projectIndicesManager = MavenProjectIndicesManager.getInstance(myProject);
+
+ repositoriesHolder.update(mavenRemoteRepositories);
+
+ projectIndicesManager.scheduleUpdateIndicesList(indexes -> {
+ for (MavenIndex mavenIndex : indexes) {
+ if (mavenIndex.getUpdateTimestamp() == -1 && repositoriesHolder.contains(mavenIndex.getRepositoryId())) {
+ projectIndicesManager.scheduleUpdate(Collections.singletonList(mavenIndex));
+ }
}
- }
- }
- }
+ });
}
- return myRemoteRepositories;
- }
-
- @Nullable
- private static URI resolveUriFromSimpleExpression(@Nullable GrExpression expression) {
- if (expression == null) {
- return null;
+ @Nonnull
+ @RequiredReadAction
+ private static Collection extends GrClosableBlock> findClosableBlocks(
+ @Nonnull final PsiElement element,
+ @Nonnull final String... blockNames
+ ) {
+ List methodCalls = PsiTreeUtil.getChildrenOfTypeAsList(element, GrMethodCall.class);
+ return ContainerUtil.mapNotNull(
+ methodCalls,
+ call -> {
+ if (call == null || call.getClosureArguments().length != 1) {
+ return null;
+ }
+
+ GrExpression expression = call.getInvokedExpression();
+ //noinspection RequiredXAction
+ return expression != null && ArrayUtil.contains(expression.getText(), blockNames)
+ ? call.getClosureArguments()[0]
+ : null;
+ }
+ );
}
- try {
- if (expression instanceof PsiLiteral) {
- URI uri = new URI(String.valueOf(PsiLiteral.class.cast(expression).getValue()));
- if (uri.getScheme() != null && StringUtil.startsWith(uri.getScheme(), "http")) {
- return uri;
+ @Nonnull
+ @RequiredReadAction
+ private static Collection extends MavenRemoteRepository> findMavenRemoteRepositories(@Nullable GrClosableBlock repositoriesBlock) {
+ Set myRemoteRepositories = new HashSet<>();
+ for (GrMethodCall repo : PsiTreeUtil.getChildrenOfTypeAsList(repositoriesBlock, GrMethodCall.class)) {
+ if (repo.getInvokedExpression() == null) {
+ continue;
+ }
+
+ final String expressionText = repo.getInvokedExpression().getText();
+ if ("mavenCentral".equals(expressionText)) {
+ myRemoteRepositories.add(mavenCentralRemoteRepository);
+ }
+ else if ("mavenRepo".equals(expressionText)) {
+ for (GrNamedArgument namedArgument : repo.getNamedArguments()) {
+ if ("url".equals(namedArgument.getLabelName())) {
+ URI urlArgumentValue = resolveUriFromSimpleExpression(namedArgument.getExpression());
+ if (urlArgumentValue != null) {
+ String textUri = urlArgumentValue.toString();
+ myRemoteRepositories.add(
+ new MavenRemoteRepository(textUri, null, textUri, null, null, null)
+ );
+ }
+ break;
+ }
+ }
+ }
+ else if ("maven".equals(expressionText) && repo.getClosureArguments().length > 0) {
+ List applicationStatementList =
+ PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrApplicationStatement.class);
+ if (!applicationStatementList.isEmpty()) {
+ GrApplicationStatement statement = applicationStatementList.get(0);
+ if (statement == null) {
+ continue;
+ }
+ GrExpression expression = statement.getInvokedExpression();
+ if (expression == null) {
+ continue;
+ }
+
+ if ("url".equals(expression.getText())) {
+ URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getExpressionArguments()[0]);
+ if (urlArgumentValue != null) {
+ String textUri = urlArgumentValue.toString();
+ myRemoteRepositories.add(
+ new MavenRemoteRepository(textUri, null, textUri, null, null, null)
+ );
+ }
+ }
+ }
+
+ List assignmentExpressionList =
+ PsiTreeUtil.getChildrenOfTypeAsList(repo.getClosureArguments()[0], GrAssignmentExpression.class);
+ if (!assignmentExpressionList.isEmpty()) {
+ GrAssignmentExpression statement = assignmentExpressionList.get(0);
+ if (statement == null) {
+ continue;
+ }
+ GrExpression expression = statement.getLValue();
+
+ if ("url".equals(expression.getText())) {
+ URI urlArgumentValue = resolveUriFromSimpleExpression(statement.getRValue());
+ if (urlArgumentValue != null) {
+ String textUri = urlArgumentValue.toString();
+ myRemoteRepositories.add(
+ new MavenRemoteRepository(textUri, null, textUri, null, null, null)
+ );
+ }
+ }
+ }
+ }
}
- }
- }
- catch (URISyntaxException ignored) {
- // ignore it
+
+ return myRemoteRepositories;
}
- try {
- PsiReference reference = expression.getReference();
- if (reference == null) {
- return null;
- }
- PsiElement element = reference.resolve();
- if (element instanceof GrVariable) {
- List grLiterals = PsiTreeUtil.getChildrenOfTypeAsList(element, GrLiteral.class);
- if (grLiterals.isEmpty()) {
- return null;
+ @Nullable
+ @RequiredReadAction
+ private static URI resolveUriFromSimpleExpression(@Nullable GrExpression expression) {
+ if (expression == null) {
+ return null;
+ }
+
+ try {
+ if (expression instanceof PsiLiteral literal) {
+ URI uri = new URI(String.valueOf(literal.getValue()));
+ if (uri.getScheme() != null && StringUtil.startsWith(uri.getScheme(), "http")) {
+ return uri;
+ }
+ }
}
- URI uri = new URI(String.valueOf(grLiterals.get(0).getValue()));
- if (uri.getScheme() != null && StringUtil.startsWith("http", uri.getScheme())) {
- return uri;
+ catch (URISyntaxException ignored) {
+ // ignore it
+ }
+
+ try {
+ PsiReference reference = expression.getReference();
+ if (reference == null) {
+ return null;
+ }
+ PsiElement element = reference.resolve();
+ if (element instanceof GrVariable) {
+ List grLiterals = PsiTreeUtil.getChildrenOfTypeAsList(element, GrLiteral.class);
+ if (grLiterals.isEmpty()) {
+ return null;
+ }
+ URI uri = new URI(String.valueOf(grLiterals.get(0).getValue()));
+ if (uri.getScheme() != null && StringUtil.startsWith("http", uri.getScheme())) {
+ return uri;
+ }
+ }
+ }
+ catch (URISyntaxException ignored) {
+ // ignore it
}
- }
- }
- catch (URISyntaxException ignored) {
- // ignore it
- }
- return null;
- }
+ return null;
+ }
}
diff --git a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/MavenRepositoriesHolder.java b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/MavenRepositoriesHolder.java
index 304cc84..e0fd621 100644
--- a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/MavenRepositoriesHolder.java
+++ b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/MavenRepositoriesHolder.java
@@ -27,34 +27,36 @@
/**
* @author Vladislav.Soroka
- * @since 10/28/13
+ * @since 2013-10-28
*/
@Singleton
@ServiceAPI(ComponentScope.PROJECT)
@ServiceImpl
public class MavenRepositoriesHolder {
- private volatile Set myRemoteRepositories;
+ private volatile Set myRemoteRepositories;
- public MavenRepositoriesHolder() {
- myRemoteRepositories = new HashSet<>();
- }
+ public MavenRepositoriesHolder() {
+ myRemoteRepositories = new HashSet<>();
+ }
- public static MavenRepositoriesHolder getInstance(Project project) {
- return project.getInstance(MavenRepositoriesHolder.class);
- }
+ public static MavenRepositoriesHolder getInstance(Project project) {
+ return project.getInstance(MavenRepositoriesHolder.class);
+ }
- public void update(Set remoteRepositories) {
- myRemoteRepositories = new HashSet<>(remoteRepositories);
- }
+ public void update(Set remoteRepositories) {
+ myRemoteRepositories = new HashSet<>(remoteRepositories);
+ }
- public Set getRemoteRepositories() {
- return myRemoteRepositories;
- }
+ public Set getRemoteRepositories() {
+ return myRemoteRepositories;
+ }
- public boolean contains(String repositoryId) {
- for (MavenRemoteRepository repository : myRemoteRepositories) {
- if (repository.getId().equals(repositoryId)) return true;
+ public boolean contains(String repositoryId) {
+ for (MavenRemoteRepository repository : myRemoteRepositories) {
+ if (repository.getId().equals(repositoryId)) {
+ return true;
+ }
+ }
+ return false;
}
- return false;
- }
}
diff --git a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/action/AddGradleDslDependencyAction.java b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/action/AddGradleDslDependencyAction.java
index a7eb873..ee40c13 100644
--- a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/action/AddGradleDslDependencyAction.java
+++ b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/action/AddGradleDslDependencyAction.java
@@ -15,13 +15,14 @@
*/
package org.jetbrains.plugins.gradle.integrations.maven.action;
+import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.component.ActionImpl;
import consulo.annotation.component.ActionParentRef;
import consulo.annotation.component.ActionRef;
import consulo.application.AllIcons;
import consulo.codeEditor.Editor;
-import consulo.gradle.GradleBundle;
import consulo.gradle.GradleConstants;
+import consulo.gradle.localize.GradleLocalize;
import consulo.language.editor.action.CodeInsightAction;
import consulo.language.editor.action.CodeInsightActionHandler;
import consulo.language.psi.PsiCompiledElement;
@@ -35,28 +36,30 @@
/**
* @author Vladislav.Soroka
- * @since 10/23/13
+ * @since 2013-10-23
*/
@ActionImpl(id = "Gradle.AddGradleDslDependencyAction", parents = @ActionParentRef(value = @ActionRef(id = "GenerateGroup")))
public class AddGradleDslDependencyAction extends CodeInsightAction {
- static final ThreadLocal> TEST_THREAD_LOCAL = new ThreadLocal>();
+ static final ThreadLocal> TEST_THREAD_LOCAL = new ThreadLocal<>();
- public AddGradleDslDependencyAction() {
- getTemplatePresentation().setDescription(GradleBundle.message("gradle.codeInsight.action.add_maven_dependency.description"));
- getTemplatePresentation().setText(GradleBundle.message("gradle.codeInsight.action.add_maven_dependency.text"));
- getTemplatePresentation().setIcon(AllIcons.Nodes.PpLib);
- }
+ public AddGradleDslDependencyAction() {
+ getTemplatePresentation().setDescriptionValue(GradleLocalize.gradleCodeinsightActionAdd_maven_dependencyDescription());
+ getTemplatePresentation().setTextValue(GradleLocalize.gradleCodeinsightActionAdd_maven_dependencyText());
+ getTemplatePresentation().setIcon(AllIcons.Nodes.PpLib);
+ }
- @Nonnull
- @Override
- protected CodeInsightActionHandler getHandler() {
- return new AddGradleDslDependencyActionHandler();
- }
+ @Nonnull
+ @Override
+ protected CodeInsightActionHandler getHandler() {
+ return new AddGradleDslDependencyActionHandler();
+ }
- @Override
- protected boolean isValidForFile(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile file) {
- if (file instanceof PsiCompiledElement) return false;
- if (!GroovyFileType.GROOVY_FILE_TYPE.equals(file.getFileType())) return false;
- return !GradleConstants.SETTINGS_FILE_NAME.equals(file.getName()) && file.getName().endsWith(GradleConstants.EXTENSION);
- }
+ @Override
+ @RequiredReadAction
+ protected boolean isValidForFile(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile file) {
+ return !(file instanceof PsiCompiledElement)
+ && GroovyFileType.INSTANCE.equals(file.getFileType())
+ && !GradleConstants.SETTINGS_FILE_NAME.equals(file.getName())
+ && file.getName().endsWith(GradleConstants.EXTENSION);
+ }
}
diff --git a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/action/AddGradleDslDependencyActionHandler.java b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/action/AddGradleDslDependencyActionHandler.java
index bdc66a5..8237887 100644
--- a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/action/AddGradleDslDependencyActionHandler.java
+++ b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/action/AddGradleDslDependencyActionHandler.java
@@ -15,9 +15,8 @@
*/
package org.jetbrains.plugins.gradle.integrations.maven.action;
-import consulo.application.ApplicationManager;
import consulo.codeEditor.Editor;
-import consulo.gradle.GradleBundle;
+import consulo.gradle.localize.GradleLocalize;
import consulo.language.editor.WriteCommandAction;
import consulo.language.editor.action.CodeInsightActionHandler;
import consulo.language.editor.util.LanguageEditorUtil;
@@ -25,6 +24,7 @@
import consulo.language.psi.util.PsiTreeUtil;
import consulo.maven.rt.server.common.model.MavenId;
import consulo.project.Project;
+import consulo.ui.annotation.RequiredUIAccess;
import consulo.util.collection.ArrayUtil;
import consulo.util.collection.ContainerUtil;
import org.jetbrains.idea.maven.dom.model.MavenDomDependency;
@@ -38,80 +38,87 @@
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
-import java.util.function.Predicate;
/**
* @author Vladislav.Soroka
- * @since 10/23/13
+ * @since 2013-10-23
*/
class AddGradleDslDependencyActionHandler implements CodeInsightActionHandler {
+ @Override
+ @RequiredUIAccess
+ public void invoke(@Nonnull final Project project, @Nonnull final Editor editor, @Nonnull final PsiFile file) {
+ if (!LanguageEditorUtil.checkModificationAllowed(editor)) {
+ return;
+ }
- @Override
- public void invoke(@Nonnull final Project project, @Nonnull final Editor editor, @Nonnull final PsiFile file) {
- if (!LanguageEditorUtil.checkModificationAllowed(editor)) return;
-
- final List ids;
- if (ApplicationManager.getApplication().isUnitTestMode()) {
- ids = AddGradleDslDependencyAction.TEST_THREAD_LOCAL.get();
- }
- else {
- ids = MavenArtifactSearchDialog.searchForArtifact(project, Collections.emptyList());
- }
-
- if (ids.isEmpty()) return;
-
- new WriteCommandAction.Simple(project, GradleBundle.message("gradle.codeInsight.action.add_maven_dependency.text"), file) {
- @Override
- protected void run() {
- GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
- List closableBlocks = PsiTreeUtil.getChildrenOfTypeAsList(file, GrMethodCall.class);
- GrCall dependenciesBlock = ContainerUtil.find(closableBlocks, new Predicate() {
- @Override
- public boolean test(GrMethodCall call) {
- GrExpression expression = call.getInvokedExpression();
- return expression != null && "dependencies".equals(expression.getText());
- }
- });
-
- if (dependenciesBlock == null) {
- StringBuilder buf = new StringBuilder();
- for (MavenId mavenId : ids) {
- buf.append(String.format("compile '%s'\n", getMavenArtifactKey(mavenId)));
- }
- dependenciesBlock = (GrCall)factory.createStatementFromText("dependencies{\n" + buf + "}");
- file.add(dependenciesBlock);
+ final List ids;
+ if (project.getApplication().isUnitTestMode()) {
+ ids = AddGradleDslDependencyAction.TEST_THREAD_LOCAL.get();
}
else {
- GrClosableBlock closableBlock = ArrayUtil.getFirstElement(dependenciesBlock.getClosureArguments());
- if (closableBlock != null) {
- for (MavenId mavenId : ids) {
- closableBlock.addStatementBefore(
- factory.createStatementFromText(String.format("compile '%s'\n", getMavenArtifactKey(mavenId))), null);
- }
- }
+ ids = MavenArtifactSearchDialog.searchForArtifact(project, Collections.emptyList());
}
- }
- }.execute();
- }
- @Override
- public boolean startInWriteAction() {
- return false;
- }
+ if (ids.isEmpty()) {
+ return;
+ }
+ new WriteCommandAction.Simple(project, GradleLocalize.gradleCodeinsightActionAdd_maven_dependencyText().get(), file) {
+ @Override
+ protected void run() {
+ GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
+ List closableBlocks = PsiTreeUtil.getChildrenOfTypeAsList(file, GrMethodCall.class);
+ GrCall dependenciesBlock = ContainerUtil.find(
+ closableBlocks,
+ call -> {
+ GrExpression expression = call.getInvokedExpression();
+ //noinspection RequiredXAction
+ return expression != null && "dependencies".equals(expression.getText());
+ }
+ );
- @Nonnull
- private static String getMavenArtifactKey(MavenId mavenId) {
- StringBuilder builder = new StringBuilder();
- append(builder, mavenId.getGroupId());
- append(builder, mavenId.getArtifactId());
- append(builder, mavenId.getVersion());
+ if (dependenciesBlock == null) {
+ StringBuilder buf = new StringBuilder();
+ for (MavenId mavenId : ids) {
+ buf.append(String.format("compile '%s'\n", getMavenArtifactKey(mavenId)));
+ }
+ dependenciesBlock = (GrCall)factory.createStatementFromText("dependencies{\n" + buf + "}");
+ file.add(dependenciesBlock);
+ }
+ else {
+ GrClosableBlock closableBlock = ArrayUtil.getFirstElement(dependenciesBlock.getClosureArguments());
+ if (closableBlock != null) {
+ for (MavenId mavenId : ids) {
+ closableBlock.addStatementBefore(
+ factory.createStatementFromText(String.format("compile '%s'\n", getMavenArtifactKey(mavenId))),
+ null
+ );
+ }
+ }
+ }
+ }
+ }.execute();
+ }
+
+ @Override
+ public boolean startInWriteAction() {
+ return false;
+ }
- return builder.toString();
- }
+ @Nonnull
+ private static String getMavenArtifactKey(MavenId mavenId) {
+ StringBuilder builder = new StringBuilder();
+ append(builder, mavenId.getGroupId());
+ append(builder, mavenId.getArtifactId());
+ append(builder, mavenId.getVersion());
- private static void append(StringBuilder builder, String part) {
- if (builder.length() != 0) builder.append(':');
- builder.append(part == null ? "" : part);
- }
+ return builder.toString();
+ }
+
+ private static void append(StringBuilder builder, String part) {
+ if (builder.length() != 0) {
+ builder.append(':');
+ }
+ builder.append(part == null ? "" : part);
+ }
}
diff --git a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/codeInsight/MavenDependenciesGradleCompletionContributor.java b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/codeInsight/MavenDependenciesGradleCompletionContributor.java
index 7a20483..8cac123 100644
--- a/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/codeInsight/MavenDependenciesGradleCompletionContributor.java
+++ b/maven-impl/src/main/java/org/jetbrains/plugins/gradle/integrations/maven/codeInsight/MavenDependenciesGradleCompletionContributor.java
@@ -15,6 +15,7 @@
*/
package org.jetbrains.plugins.gradle.integrations.maven.codeInsight;
+import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.component.ExtensionImpl;
import consulo.application.AllIcons;
import consulo.gradle.codeInsight.AbstractGradleCompletionContributor;
@@ -48,129 +49,142 @@
/**
* @author Vladislav.Soroka
- * @since 10/31/13
+ * @since 2013-10-31
*/
@ExtensionImpl
public class MavenDependenciesGradleCompletionContributor extends AbstractGradleCompletionContributor {
- private static final String GROUP_LABEL = "group";
- private static final String NAME_LABEL = "name";
- private static final String VERSION_LABEL = "version";
- private static final String DEPENDENCIES_SCRIPT_BLOCK = "dependencies";
-
- private static final ElementPattern DEPENDENCIES_CALL_PATTERN = psiElement()
- .inside(true, psiElement(GrMethodCallExpression.class).with(new PatternCondition("withInvokedExpressionText") {
- @Override
- public boolean accepts(@Nonnull GrMethodCallExpression expression, ProcessingContext context) {
- if (checkExpression(expression)) return true;
- return checkExpression(PsiTreeUtil.getParentOfType(expression, GrMethodCallExpression.class));
- }
-
- private boolean checkExpression(@Nullable GrMethodCallExpression expression) {
- if (expression == null) return false;
- GrExpression grExpression = expression.getInvokedExpression();
- return grExpression != null && DEPENDENCIES_SCRIPT_BLOCK.equals(grExpression.getText());
- }
- }));
-
- private static final ElementPattern IN_MAP_DEPENDENCY_NOTATION = psiElement()
- .and(AbstractGradleCompletionContributor.GRADLE_FILE_PATTERN)
- .withParent(GrLiteral.class)
- .withSuperParent(2, psiElement(GrNamedArgument.class))
- .and(DEPENDENCIES_CALL_PATTERN);
-
- private static final ElementPattern IN_METHOD_DEPENDENCY_NOTATION = psiElement()
- .and(AbstractGradleCompletionContributor.GRADLE_FILE_PATTERN)
- .and(DEPENDENCIES_CALL_PATTERN);
-
- public MavenDependenciesGradleCompletionContributor() {
- // map-style notation:
- // e.g.:
- // compile group: 'com.google.code.guice', name: 'guice', version: '1.0'
- // runtime([group:'junit', name:'junit-dep', version:'4.7'])
- // compile(group:'junit', name:'junit-dep', version:'4.7')
- extend(CompletionType.BASIC, IN_MAP_DEPENDENCY_NOTATION, new CompletionProvider() {
- @Override
- public void addCompletions(@Nonnull CompletionParameters params,
- ProcessingContext context,
- @Nonnull final CompletionResultSet result) {
- result.stopHere();
-
- final PsiElement parent = params.getPosition().getParent().getParent();
- if (!(parent instanceof GrNamedArgument) || !(parent.getParent() instanceof GrNamedArgumentsOwner)) {
- return;
- }
-
- final GrNamedArgument namedArgument = (GrNamedArgument)parent;
- if (GROUP_LABEL.equals(namedArgument.getLabelName())) {
- MavenProjectIndicesManager m = MavenProjectIndicesManager.getInstance(namedArgument.getProject());
- for (String groupId : m.getGroupIds()) {
- LookupElement builder = LookupElementBuilder.create(groupId).withIcon(AllIcons.Nodes.PpLib);
- result.addElement(builder);
- }
- }
- else if (NAME_LABEL.equals(namedArgument.getLabelName())) {
- String groupId = findNamedArgumentValue((GrNamedArgumentsOwner)namedArgument.getParent(), GROUP_LABEL);
- if (groupId == null) return;
-
- MavenProjectIndicesManager m = MavenProjectIndicesManager.getInstance(namedArgument.getProject());
- for (String artifactId : m.getArtifactIds(groupId)) {
- LookupElement builder = LookupElementBuilder.create(artifactId).withIcon(AllIcons.Nodes.PpLib);
- result.addElement(builder);
- }
- }
- else if (VERSION_LABEL.equals(namedArgument.getLabelName())) {
- GrNamedArgumentsOwner namedArgumentsOwner = (GrNamedArgumentsOwner)namedArgument.getParent();
-
- String groupId = findNamedArgumentValue(namedArgumentsOwner, GROUP_LABEL);
- if (groupId == null) return;
-
- String artifactId = findNamedArgumentValue(namedArgumentsOwner, NAME_LABEL);
- if (artifactId == null) return;
-
- MavenProjectIndicesManager m = MavenProjectIndicesManager.getInstance(namedArgument.getProject());
- for (String version : m.getVersions(groupId, artifactId)) {
- LookupElement builder = LookupElementBuilder.create(version).withIcon(AllIcons.Nodes.PpLib);
- result.addElement(builder);
- }
- }
- }
- });
-
- // group:name:version notation
- // e.g.:
- // compile 'junit:junit:4.11'
- // compile('junit:junit:4.11')
- extend(CompletionType.BASIC, IN_METHOD_DEPENDENCY_NOTATION, new CompletionProvider() {
- @Override
- public void addCompletions(@Nonnull CompletionParameters params,
- ProcessingContext context,
- @Nonnull final CompletionResultSet result) {
- result.stopHere();
-
- final PsiElement parent = params.getPosition().getParent();
- if (!(parent instanceof GrLiteral) || !(parent.getParent() instanceof GrArgumentList)) return;
-
- String searchText = CompletionUtilCore.findReferenceOrAlphanumericPrefix(params);
- MavenArtifactSearcher searcher = new MavenArtifactSearcher();
- List searchResults = searcher.search(params.getPosition().getProject(), searchText, 100);
- for (MavenArtifactSearchResult searchResult : searchResults) {
- for (MavenArtifactInfo artifactInfo : searchResult.versions) {
- final StringBuilder buf = new StringBuilder();
- MavenId.append(buf, artifactInfo.getGroupId());
- MavenId.append(buf, artifactInfo.getArtifactId());
- MavenId.append(buf, artifactInfo.getVersion());
-
- LookupElement builder = LookupElementBuilder.create(buf.toString()).withIcon(AllIcons.Nodes.PpLib);
- result.addElement(builder);
- }
- }
- }
- });
- }
-
- @Nonnull
- @Override
- public Language getLanguage() {
- return GroovyLanguage.INSTANCE;
- }
+ private static final String GROUP_LABEL = "group";
+ private static final String NAME_LABEL = "name";
+ private static final String VERSION_LABEL = "version";
+ private static final String DEPENDENCIES_SCRIPT_BLOCK = "dependencies";
+
+ private static final ElementPattern DEPENDENCIES_CALL_PATTERN = psiElement().inside(
+ true,
+ psiElement(GrMethodCallExpression.class).with(new PatternCondition<>("withInvokedExpressionText") {
+ @Override
+ @RequiredReadAction
+ public boolean accepts(@Nonnull GrMethodCallExpression expression, ProcessingContext context) {
+ return checkExpression(expression)
+ || checkExpression(PsiTreeUtil.getParentOfType(expression, GrMethodCallExpression.class));
+ }
+
+ @RequiredReadAction
+ private boolean checkExpression(@Nullable GrMethodCallExpression expression) {
+ if (expression == null) {
+ return false;
+ }
+ GrExpression grExpression = expression.getInvokedExpression();
+ return grExpression != null && DEPENDENCIES_SCRIPT_BLOCK.equals(grExpression.getText());
+ }
+ })
+ );
+
+ private static final ElementPattern IN_MAP_DEPENDENCY_NOTATION = psiElement()
+ .and(AbstractGradleCompletionContributor.GRADLE_FILE_PATTERN)
+ .withParent(GrLiteral.class)
+ .withSuperParent(2, psiElement(GrNamedArgument.class))
+ .and(DEPENDENCIES_CALL_PATTERN);
+
+ private static final ElementPattern IN_METHOD_DEPENDENCY_NOTATION = psiElement()
+ .and(AbstractGradleCompletionContributor.GRADLE_FILE_PATTERN)
+ .and(DEPENDENCIES_CALL_PATTERN);
+
+ public MavenDependenciesGradleCompletionContributor() {
+ // map-style notation:
+ // e.g.:
+ // compile group: 'com.google.code.guice', name: 'guice', version: '1.0'
+ // runtime([group:'junit', name:'junit-dep', version:'4.7'])
+ // compile(group:'junit', name:'junit-dep', version:'4.7')
+ extend(
+ CompletionType.BASIC,
+ IN_MAP_DEPENDENCY_NOTATION,
+ (params, context, result) -> {
+ result.stopHere();
+
+ final PsiElement parent = params.getPosition().getParent().getParent();
+ if (!(parent instanceof GrNamedArgument) || !(parent.getParent() instanceof GrNamedArgumentsOwner)) {
+ return;
+ }
+
+ final GrNamedArgument namedArgument = (GrNamedArgument)parent;
+ if (GROUP_LABEL.equals(namedArgument.getLabelName())) {
+ MavenProjectIndicesManager m = MavenProjectIndicesManager.getInstance(namedArgument.getProject());
+ for (String groupId : m.getGroupIds()) {
+ LookupElement builder = LookupElementBuilder.create(groupId).withIcon(AllIcons.Nodes.PpLib);
+ result.addElement(builder);
+ }
+ }
+ else if (NAME_LABEL.equals(namedArgument.getLabelName())) {
+ String groupId = findNamedArgumentValue((GrNamedArgumentsOwner)namedArgument.getParent(), GROUP_LABEL);
+ if (groupId == null) {
+ return;
+ }
+
+ MavenProjectIndicesManager m = MavenProjectIndicesManager.getInstance(namedArgument.getProject());
+ for (String artifactId : m.getArtifactIds(groupId)) {
+ LookupElement builder = LookupElementBuilder.create(artifactId).withIcon(AllIcons.Nodes.PpLib);
+ result.addElement(builder);
+ }
+ }
+ else if (VERSION_LABEL.equals(namedArgument.getLabelName())) {
+ GrNamedArgumentsOwner namedArgumentsOwner = (GrNamedArgumentsOwner)namedArgument.getParent();
+
+ String groupId = findNamedArgumentValue(namedArgumentsOwner, GROUP_LABEL);
+ if (groupId == null) {
+ return;
+ }
+
+ String artifactId = findNamedArgumentValue(namedArgumentsOwner, NAME_LABEL);
+ if (artifactId == null) {
+ return;
+ }
+
+ MavenProjectIndicesManager m = MavenProjectIndicesManager.getInstance(namedArgument.getProject());
+ for (String version : m.getVersions(groupId, artifactId)) {
+ LookupElement builder = LookupElementBuilder.create(version).withIcon(AllIcons.Nodes.PpLib);
+ result.addElement(builder);
+ }
+ }
+ }
+ );
+
+ // group:name:version notation
+ // e.g.:
+ // compile 'junit:junit:4.11'
+ // compile('junit:junit:4.11')
+ extend(
+ CompletionType.BASIC,
+ IN_METHOD_DEPENDENCY_NOTATION,
+ (params, context, result) -> {
+ result.stopHere();
+
+ final PsiElement parent = params.getPosition().getParent();
+ if (!(parent instanceof GrLiteral) || !(parent.getParent() instanceof GrArgumentList)) {
+ return;
+ }
+
+ String searchText = CompletionUtilCore.findReferenceOrAlphanumericPrefix(params);
+ MavenArtifactSearcher searcher = new MavenArtifactSearcher();
+ List searchResults =
+ searcher.search(params.getPosition().getProject(), searchText, 100);
+ for (MavenArtifactSearchResult searchResult : searchResults) {
+ for (MavenArtifactInfo artifactInfo : searchResult.versions) {
+ final StringBuilder buf = new StringBuilder();
+ MavenId.append(buf, artifactInfo.getGroupId());
+ MavenId.append(buf, artifactInfo.getArtifactId());
+ MavenId.append(buf, artifactInfo.getVersion());
+
+ LookupElement builder = LookupElementBuilder.create(buf.toString()).withIcon(AllIcons.Nodes.PpLib);
+ result.addElement(builder);
+ }
+ }
+ }
+ );
+ }
+
+ @Nonnull
+ @Override
+ public Language getLanguage() {
+ return GroovyLanguage.INSTANCE;
+ }
}
diff --git a/plugin/pom.xml b/plugin/pom.xml
index d85c871..5f47d84 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -16,182 +16,182 @@
-->
- 4.0.0
-
- consulo
- arch.ide-api-provided
+ 4.0.0
+
+ consulo
+ arch.ide-api-provided
+ 3-SNAPSHOT
+
+
+
+ consulo.plugin
+ org.jetbrains.plugins.gradle
3-SNAPSHOT
-
-
-
- consulo.plugin
- org.jetbrains.plugins.gradle
- 3-SNAPSHOT
- consulo-plugin
-
-
-
- consulo
- https://maven.consulo.io/repository/snapshots/
-
- true
- interval:60
-
-
-
-
-
- 7.6.1
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- 5000
-
-
-
-
- consulo.maven
- maven-consulo-plugin
- true
-
-
- consulo.java
- consulo.javaee
- org.intellij.groovy
- com.intellij.xml
- com.intellij.properties
-
-
- ${dev.mode}
- ${build.number}
-
-
-
-
- gen
- generate-sources
-
- generate-localize
- generate-icon
-
-
-
- pack
- package
-
- workspace
-
-
-
-
-
-
-
-
-
- ${project.groupId}
- org.jetbrains.plugins.gradle-gradle.api
- ${project.version}
-
-
-
- ${project.groupId}
- org.jetbrains.plugins.gradle-maven.impl
- ${project.version}
- runtime
-
-
-
- ${project.groupId}
- org.jetbrains.plugins.gradle-jakarta.web.impl
- ${project.version}
- runtime
-
-
-
- ${project.groupId}
- org.jetbrains.plugins.gradle-tooling.extension.api
- ${project.version}
-
-
-
- ${project.groupId}
- org.jetbrains.plugins.gradle-tooling-extension.impl
- ${project.version}
-
-
-
- consulo.internal.gradle.plugin
- gradle-all
- ${gradle.version}
-
-
-
- org.objenesis
- objenesis
- 2.5.1
-
-
-
- com.esotericsoftware
- minlog
- 1.3.0
-
-
-
- com.esotericsoftware
- kryo
- 4.0.2
-
-
-
- commons-io
- commons-io
- 2.6
-
-
-
- consulo
- consulo-ide-impl
- ${project.version}
- provided
-
-
-
- ${project.groupId}
- consulo.java
- ${project.version}
- provided
-
-
- ${project.groupId}
- com.intellij.properties
- ${project.version}
- provided
-
-
- ${project.groupId}
- consulo.javaee
- ${project.version}
- provided
-
-
- ${project.groupId}
- org.intellij.groovy
- ${project.version}
- provided
-
-
- consulo
- consulo-util-nodep
- ${project.version}
- provided
-
-
+ consulo-plugin
+
+
+
+ consulo
+ https://maven.consulo.io/repository/snapshots/
+
+ true
+ interval:60
+
+
+
+
+
+ 7.6.1
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 5000
+
+
+
+
+ consulo.maven
+ maven-consulo-plugin
+ true
+
+
+ consulo.java
+ consulo.javaee
+ org.intellij.groovy
+ com.intellij.xml
+ com.intellij.properties
+
+
+ ${dev.mode}
+ ${build.number}
+
+
+
+
+ gen
+ generate-sources
+
+ generate-localize
+ generate-icon
+
+
+
+ pack
+ package
+
+ workspace
+
+
+
+
+
+
+
+
+
+ ${project.groupId}
+ org.jetbrains.plugins.gradle-gradle.api
+ ${project.version}
+
+
+
+ ${project.groupId}
+ org.jetbrains.plugins.gradle-maven.impl
+ ${project.version}
+ runtime
+
+
+
+ ${project.groupId}
+ org.jetbrains.plugins.gradle-jakarta.web.impl
+ ${project.version}
+ runtime
+
+
+
+ ${project.groupId}
+ org.jetbrains.plugins.gradle-tooling.extension.api
+ ${project.version}
+
+
+
+ ${project.groupId}
+ org.jetbrains.plugins.gradle-tooling-extension.impl
+ ${project.version}
+
+
+
+ consulo.internal.gradle.plugin
+ gradle-all
+ ${gradle.version}
+
+
+
+ org.objenesis
+ objenesis
+ 2.5.1
+
+
+
+ com.esotericsoftware
+ minlog
+ 1.3.0
+
+
+
+ com.esotericsoftware
+ kryo
+ 4.0.2
+
+
+
+ commons-io
+ commons-io
+ 2.6
+
+
+
+ consulo
+ consulo-ide-impl
+ ${project.version}
+ provided
+
+
+
+ ${project.groupId}
+ consulo.java
+ ${project.version}
+ provided
+
+
+ ${project.groupId}
+ com.intellij.properties
+ ${project.version}
+ provided
+
+
+ ${project.groupId}
+ consulo.javaee
+ ${project.version}
+ provided
+
+
+ ${project.groupId}
+ org.intellij.groovy
+ ${project.version}
+ provided
+
+
+ consulo
+ consulo-util-nodep
+ ${project.version}
+ provided
+
+
\ No newline at end of file
diff --git a/plugin/src/main/java/consulo/gradle/impl/importProvider/GradleModuleImportProvider.java b/plugin/src/main/java/consulo/gradle/impl/importProvider/GradleModuleImportProvider.java
index a18b227..1843a60 100644
--- a/plugin/src/main/java/consulo/gradle/impl/importProvider/GradleModuleImportProvider.java
+++ b/plugin/src/main/java/consulo/gradle/impl/importProvider/GradleModuleImportProvider.java
@@ -7,9 +7,9 @@
import consulo.externalSystem.model.DataNode;
import consulo.externalSystem.service.project.ProjectData;
import consulo.externalSystem.util.ExternalSystemApiUtil;
-import consulo.gradle.GradleBundle;
import consulo.gradle.GradleConstants;
import consulo.gradle.icon.GradleIconGroup;
+import consulo.gradle.localize.GradleLocalize;
import consulo.ide.impl.externalSystem.service.module.wizard.AbstractExternalModuleImportProvider;
import consulo.ide.impl.externalSystem.service.module.wizard.ExternalModuleImportContext;
import consulo.ide.impl.idea.openapi.externalSystem.service.project.manage.ProjectDataManager;
@@ -33,97 +33,97 @@
*/
@ExtensionImpl
public class GradleModuleImportProvider extends AbstractExternalModuleImportProvider {
- @Nonnull
- public static GradleModuleImportProvider getInstance() {
- return EP_NAME.findExtensionOrFail(GradleModuleImportProvider.class);
- }
-
- @Inject
- public GradleModuleImportProvider(@Nonnull ProjectDataManager dataManager) {
- super(dataManager, new ImportFromGradleControl(), GradleConstants.SYSTEM_ID);
- }
-
- @Nonnull
- @Override
- public String getName() {
- return GradleBundle.message("gradle.name");
- }
+ @Nonnull
+ public static GradleModuleImportProvider getInstance() {
+ return EP_NAME.findExtensionOrFail(GradleModuleImportProvider.class);
+ }
- @Nullable
- @Override
- public Image getIcon() {
- return GradleIconGroup.gradle();
- }
+ @Inject
+ public GradleModuleImportProvider(@Nonnull ProjectDataManager dataManager) {
+ super(dataManager, new ImportFromGradleControl(), GradleConstants.SYSTEM_ID);
+ }
- @Override
- public boolean canImport(@Nonnull File fileOrDirectory) {
- if (fileOrDirectory.isDirectory()) {
- return new File(fileOrDirectory, GradleConstants.DEFAULT_SCRIPT_NAME).exists();
+ @Nonnull
+ @Override
+ public String getName() {
+ return GradleLocalize.gradleName().get();
}
- else {
- String extension = FileUtil.getExtension(fileOrDirectory.getName());
- return GradleConstants.EXTENSION.equalsIgnoreCase(extension);
+
+ @Nullable
+ @Override
+ public Image getIcon() {
+ return GradleIconGroup.gradle();
}
- }
- @Nonnull
- @Override
- public String getFileSample() {
- return "Gradle build script (*.gradle)";
- }
+ @Override
+ public boolean canImport(@Nonnull File fileOrDirectory) {
+ if (fileOrDirectory.isDirectory()) {
+ return new File(fileOrDirectory, GradleConstants.DEFAULT_SCRIPT_NAME).exists();
+ }
+ else {
+ String extension = FileUtil.getExtension(fileOrDirectory.getName());
+ return GradleConstants.EXTENSION.equalsIgnoreCase(extension);
+ }
+ }
- @Override
- protected void doPrepare(@Nonnull ExternalModuleImportContext context) {
- String importFile = context.getFileToImport();
- VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(importFile);
- if (file != null && !file.isDirectory()) {
- //getControl().setLinkedProjectPath(file.getParent().getPath());
+ @Nonnull
+ @Override
+ public String getFileSample() {
+ return "Gradle build script (*.gradle)";
}
- }
- @Override
- protected void beforeCommit(@Nonnull DataNode dataNode, @Nonnull Project project) {
+ @Override
+ protected void doPrepare(@Nonnull ExternalModuleImportContext context) {
+ String importFile = context.getFileToImport();
+ VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(importFile);
+ if (file != null && !file.isDirectory()) {
+ //getControl().setLinkedProjectPath(file.getParent().getPath());
+ }
+ }
- }
+ @Override
+ protected void beforeCommit(@Nonnull DataNode dataNode, @Nonnull Project project) {
- @Nonnull
- @Override
- protected File getExternalProjectConfigToUse(@Nonnull File file) {
- return file.isDirectory() ? file : file.getParentFile();
- }
+ }
- @Override
- protected void applyExtraSettings(@Nonnull ExternalModuleImportContext context) {
- DataNode node = getExternalProjectNode();
- if (node == null) {
- return;
+ @Nonnull
+ @Override
+ protected File getExternalProjectConfigToUse(@Nonnull File file) {
+ return file.isDirectory() ? file : file.getParentFile();
}
- DataNode javaProjectNode = ExternalSystemApiUtil.find(node, JavaProjectData.KEY);
- if (javaProjectNode != null) {
- JavaProjectData data = javaProjectNode.getData();
- // todo context.setCompilerOutputDirectory(data.getCompileOutputPath());
- JavaSdkVersion version = data.getJdkVersion();
- Sdk jdk = findJdk(version);
- if (jdk != null) {
- //context.setProjectJdk(jdk);
- }
+ @Override
+ protected void applyExtraSettings(@Nonnull ExternalModuleImportContext context) {
+ DataNode node = getExternalProjectNode();
+ if (node == null) {
+ return;
+ }
+
+ DataNode javaProjectNode = ExternalSystemApiUtil.find(node, JavaProjectData.KEY);
+ if (javaProjectNode != null) {
+ JavaProjectData data = javaProjectNode.getData();
+ // todo context.setCompilerOutputDirectory(data.getCompileOutputPath());
+ JavaSdkVersion version = data.getJdkVersion();
+ Sdk jdk = findJdk(version);
+ if (jdk != null) {
+ //context.setProjectJdk(jdk);
+ }
+ }
}
- }
- @Nullable
- private static Sdk findJdk(@Nonnull JavaSdkVersion version) {
- List javaSdks = JavaSdkTypeUtil.getAllJavaSdks();
- Sdk candidate = null;
- for (Sdk sdk : javaSdks) {
- JavaSdkVersion v = JavaSdkTypeUtil.getVersion(sdk);
- if (v == version) {
- return sdk;
- }
- else if (candidate == null && v != null && version.getMaxLanguageLevel().isAtLeast(version.getMaxLanguageLevel())) {
- candidate = sdk;
- }
+ @Nullable
+ private static Sdk findJdk(@Nonnull JavaSdkVersion version) {
+ List javaSdks = JavaSdkTypeUtil.getAllJavaSdks();
+ Sdk candidate = null;
+ for (Sdk sdk : javaSdks) {
+ JavaSdkVersion v = JavaSdkTypeUtil.getVersion(sdk);
+ if (v == version) {
+ return sdk;
+ }
+ else if (candidate == null && v != null && version.getMaxLanguageLevel().isAtLeast(version.getMaxLanguageLevel())) {
+ candidate = sdk;
+ }
+ }
+ return candidate;
}
- return candidate;
- }
}
diff --git a/plugin/src/main/java/module-info.java b/plugin/src/main/java/module-info.java
index 97b8df6..910a925 100644
--- a/plugin/src/main/java/module-info.java
+++ b/plugin/src/main/java/module-info.java
@@ -1,34 +1,30 @@
/**
* @author VISTALL
- * @since 31/03/2023
+ * @since 2023-03-31
*/
open module org.jetbrains.plugins.gradle {
- requires consulo.ide.api;
-
- requires consulo.java.execution.api;
- requires consulo.java.execution.impl;
- requires com.intellij.properties;
- requires org.intellij.groovy.psi;
- requires org.intellij.groovy;
-
- requires org.jetbrains.plugins.gradle.api;
-
- requires consulo.internal.jdi;
-
- requires com.google.gson;
- requires org.apache.groovy;
-
- requires consulo.util.nodep;
-
- requires gradle.all;
- requires kryo;
- requires minlog;
- requires objenesis;
-
- requires org.jetbrains.plugins.gradle.tooling;
- requires org.jetbrains.plugins.gradle.tooling.impl;
-
- // TODO remove in future
- requires consulo.ide.impl;
- requires java.desktop;
+ requires com.google.gson;
+ requires com.intellij.properties;
+
+ requires consulo.ide.api;
+ requires consulo.internal.jdi;
+ requires consulo.java.execution.api;
+ requires consulo.java.execution.impl;
+ requires consulo.util.nodep;
+
+ requires gradle.all;
+ requires kryo;
+ requires minlog;
+ requires objenesis;
+
+ requires org.apache.groovy;
+ requires org.intellij.groovy;
+ requires org.intellij.groovy.psi;
+ requires org.jetbrains.plugins.gradle.api;
+ requires org.jetbrains.plugins.gradle.tooling;
+ requires org.jetbrains.plugins.gradle.tooling.impl;
+
+ // TODO remove in future
+ requires consulo.ide.impl;
+ requires java.desktop;
}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java
index 6b2643e..261f1e5 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java
@@ -1,8 +1,8 @@
package org.jetbrains.plugins.gradle.action;
import consulo.dataContext.DataContext;
-import consulo.language.editor.CommonDataKeys;
import consulo.project.Project;
+import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.action.AnAction;
import consulo.ui.ex.action.AnActionEvent;
import consulo.util.lang.Pair;
@@ -15,53 +15,55 @@
* Common super class for gradle actions that require {@link GradleSettings#getLinkedExternalProjectPath()} linked project}.
*
* Not thread-safe.
- *
+ *
* @author Denis Zhdanov
- * @since 1/31/12 5:36 PM
+ * @since 2021-01-31
*/
public abstract class AbstractGradleLinkedProjectAction extends AnAction {
-
- @Override
- public void update(AnActionEvent e) {
- final Pair pair = deriveProjects(e.getDataContext());
- final boolean visible = pair != null;
- e.getPresentation().setVisible(visible);
- if (!visible) {
- return;
+ @Override
+ @RequiredUIAccess
+ public void update(AnActionEvent e) {
+ final Pair pair = deriveProjects(e.getDataContext());
+ final boolean visible = pair != null;
+ e.getPresentation().setVisible(visible);
+ if (!visible) {
+ return;
+ }
+ doUpdate(e, pair.first, pair.second);
}
- doUpdate(e, pair.first, pair.second);
- }
- @Override
- public void actionPerformed(AnActionEvent e) {
- final Project project = e.getData(Project.KEY);
- if (project == null) {
- return;
- }
- final Pair pair = deriveProjects(e.getDataContext());
- if (pair == null) {
- e.getPresentation().setVisible(false);
- return;
+ @Override
+ @RequiredUIAccess
+ public void actionPerformed(AnActionEvent e) {
+ final Project project = e.getData(Project.KEY);
+ if (project == null) {
+ return;
+ }
+ final Pair pair = deriveProjects(e.getDataContext());
+ if (pair == null) {
+ e.getPresentation().setVisible(false);
+ return;
+ }
+ doActionPerformed(e, project, pair.second);
}
- doActionPerformed(e, project, pair.second);
- }
- @Nullable
- private static Pair deriveProjects(@Nullable DataContext context) {
- if (context == null) {
- return null;
- }
-
- final Project project = context.getData(CommonDataKeys.PROJECT);
- if (project == null) {
- return null;
- }
- // TODO den implement
- return null;
+ @Nullable
+ private static Pair deriveProjects(@Nullable DataContext context) {
+ if (context == null) {
+ return null;
+ }
+
+ final Project project = context.getData(Project.KEY);
+ if (project == null) {
+ return null;
+ }
+ // TODO den implement
+ return null;
// final String path = GradleSettings.getInstance(project).getLinkedExternalProjectPath();
// return path == null ? null : new Pair(project, path);
- }
+ }
+
+ protected abstract void doUpdate(@Nonnull AnActionEvent event, @Nonnull Project project, @Nonnull String linkedProjectPath);
- protected abstract void doUpdate(@Nonnull AnActionEvent event, @Nonnull Project project, @Nonnull String linkedProjectPath);
- protected abstract void doActionPerformed(@Nonnull AnActionEvent event, @Nonnull Project project, @Nonnull String linkedProjectPath);
+ protected abstract void doActionPerformed(@Nonnull AnActionEvent event, @Nonnull Project project, @Nonnull String linkedProjectPath);
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/action/GradleOpenScriptAction.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/action/GradleOpenScriptAction.java
index 318dd26..a6fae1b 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/action/GradleOpenScriptAction.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/action/GradleOpenScriptAction.java
@@ -2,6 +2,7 @@
import consulo.application.dumb.DumbAware;
import consulo.fileEditor.FileEditorManager;
+import consulo.gradle.localize.GradleLocalize;
import consulo.logging.Logger;
import consulo.navigation.OpenFileDescriptor;
import consulo.navigation.OpenFileDescriptorFactory;
@@ -10,39 +11,37 @@
import consulo.virtualFileSystem.LocalFileSystem;
import consulo.virtualFileSystem.VirtualFile;
import org.jetbrains.plugins.gradle.settings.GradleSettings;
-import consulo.gradle.GradleBundle;
import javax.annotation.Nonnull;
/**
- * Forces the IntelliJ IDEA to open {@link GradleSettings#getLinkedExternalProjectPath() linked gradle project} at the editor
+ * Forces the Consulo to open {@link GradleSettings#getLinkedExternalProjectPath() linked gradle project} at the editor
*
* Not thread-safe.
*
* @author Denis Zhdanov
- * @since 1/31/12 5:16 PM
+ * @since 2012-01-31
*/
public class GradleOpenScriptAction extends AbstractGradleLinkedProjectAction implements DumbAware {
+ private static final Logger LOG = Logger.getInstance(GradleOpenScriptAction.class);
- private static final Logger LOG = Logger.getInstance(GradleOpenScriptAction.class);
-
- public GradleOpenScriptAction() {
- getTemplatePresentation().setText(GradleBundle.message("gradle.action.open.script.text"));
- getTemplatePresentation().setDescription(GradleBundle.message("gradle.action.open.script.description"));
- }
+ public GradleOpenScriptAction() {
+ getTemplatePresentation().setTextValue(GradleLocalize.gradleActionOpenScriptText());
+ getTemplatePresentation().setDescriptionValue(GradleLocalize.gradleActionOpenScriptDescription());
+ }
- @Override
- protected void doUpdate(@Nonnull AnActionEvent event, @Nonnull Project project, @Nonnull String linkedProjectPath) {
- }
+ @Override
+ protected void doUpdate(@Nonnull AnActionEvent event, @Nonnull Project project, @Nonnull String linkedProjectPath) {
+ }
- @Override
- protected void doActionPerformed(@Nonnull AnActionEvent event, @Nonnull Project project, @Nonnull String linkedProjectPath) {
- final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(linkedProjectPath);
- if (virtualFile == null) {
- LOG.warn(String.format("Can't obtain virtual file for the target file path: '%s'", linkedProjectPath));
- return;
+ @Override
+ protected void doActionPerformed(@Nonnull AnActionEvent event, @Nonnull Project project, @Nonnull String linkedProjectPath) {
+ final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(linkedProjectPath);
+ if (virtualFile == null) {
+ LOG.warn(String.format("Can't obtain virtual file for the target file path: '%s'", linkedProjectPath));
+ return;
+ }
+ OpenFileDescriptor descriptor = OpenFileDescriptorFactory.getInstance(project).builder(virtualFile).build();
+ FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
}
- OpenFileDescriptor descriptor = OpenFileDescriptorFactory.getInstance(project).builder(virtualFile).build();
- FileEditorManager.getInstance(project).openTextEditor(descriptor, true);
- }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/action/GradleToolWindowHelpAction.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/action/GradleToolWindowHelpAction.java
index 9d7685f..c4318a9 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/action/GradleToolWindowHelpAction.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/action/GradleToolWindowHelpAction.java
@@ -2,35 +2,36 @@
import consulo.dataContext.DataContext;
import consulo.project.Project;
+import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.action.AnActionEvent;
import consulo.ui.ex.action.ContextHelpAction;
import consulo.gradle.GradleConstants;
/**
* @author Denis Zhdanov
- * @since 3/17/12 2:34 PM
+ * @since 2012-03-17
*/
public class GradleToolWindowHelpAction extends ContextHelpAction {
+ @Override
+ @RequiredUIAccess
+ public void update(AnActionEvent event) {
+ final Project project = event.getData(Project.KEY);
+ if (project == null) {
+ event.getPresentation().setVisible(false);
+ return;
+ }
- @Override
- public void update(AnActionEvent event) {
- final Project project = event.getData(Project.KEY);
- if (project == null) {
- event.getPresentation().setVisible(false);
- return;
- }
-
- // TODO den implement
+ // TODO den implement
// if (StringUtil.isEmpty(GradleSettings.getInstance(project).getLinkedExternalProjectPath())) {
// event.getPresentation().setVisible(false);
// return;
// }
- event.getPresentation().setVisible(true);
- super.update(event);
- }
+ event.getPresentation().setVisible(true);
+ super.update(event);
+ }
- @Override
- protected String getHelpId(DataContext dataContext) {
- return GradleConstants.HELP_TOPIC_TOOL_WINDOW;
- }
+ @Override
+ protected String getHelpId(DataContext dataContext) {
+ return GradleConstants.HELP_TOPIC_TOOL_WINDOW;
+ }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/UseDistributionWithSourcesNotificationProvider.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/UseDistributionWithSourcesNotificationProvider.java
index 825c4b9..25953df 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/UseDistributionWithSourcesNotificationProvider.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/UseDistributionWithSourcesNotificationProvider.java
@@ -65,158 +65,181 @@
/**
* @author Vladislav.Soroka
- * @since 9/13/13
+ * @since 2013-09-13
*/
@ExtensionImpl
public class UseDistributionWithSourcesNotificationProvider implements EditorNotificationProvider {
- public static final Pattern GRADLE_SRC_DISTRIBUTION_PATTERN;
- private static final Logger LOG = Logger.getInstance(UseDistributionWithSourcesNotificationProvider.class);
- private static final String ALL_ZIP_DISTRIBUTION_URI_SUFFIX = "-all.zip";
- private final Project myProject;
-
- static {
- GRADLE_SRC_DISTRIBUTION_PATTERN = Pattern.compile("https?\\\\?://services\\.gradle\\.org.*" + ALL_ZIP_DISTRIBUTION_URI_SUFFIX);
- }
-
- @Inject
- public UseDistributionWithSourcesNotificationProvider(Project project) {
- myProject = project;
- }
-
- @Nonnull
- @Override
- public String getId() {
- return "gradle-use-distribution-with-source";
- }
-
- @RequiredReadAction
- @Nullable
- @Override
- public EditorNotificationBuilder buildNotification(@Nonnull VirtualFile file,
- @Nonnull FileEditor fileEditor,
- @Nonnull Supplier supplier) {
- try {
- if (GradleConstants.DEFAULT_SCRIPT_NAME.equals(file.getName()) || GradleConstants.SETTINGS_FILE_NAME.equals(file.getName())) {
-
- final Module module = ModuleUtilCore.findModuleForFile(file, myProject);
- if (module == null) {
- return null;
- }
- final String rootProjectPath = getRootProjectPath(module);
- if (rootProjectPath == null) {
- return null;
- }
- final GradleProjectSettings settings = GradleSettings.getInstance(module.getProject()).getLinkedProjectSettings(rootProjectPath);
- if (settings == null || settings.getDistributionType() != DistributionType.DEFAULT_WRAPPED) {
- return null;
- }
- if (settings.isDisableWrapperSourceDistributionNotification()) {
- return null;
- }
- if (!showUseDistributionWithSourcesTip(rootProjectPath)) {
- return null;
- }
+ public static final Pattern GRADLE_SRC_DISTRIBUTION_PATTERN;
+ private static final Logger LOG = Logger.getInstance(UseDistributionWithSourcesNotificationProvider.class);
+ private static final String ALL_ZIP_DISTRIBUTION_URI_SUFFIX = "-all.zip";
+ private final Project myProject;
- final EditorNotificationBuilder panel = supplier.get();
- panel.withText(GradleLocalize.gradleNotificationsUseDistributionWithSources());
- panel.withAction(GradleLocalize.gradleNotificationsHideTip(), (e) ->
- {
- settings.setDisableWrapperSourceDistributionNotification(true);
- EditorNotifications.getInstance(module.getProject()).updateAllNotifications();
- });
- panel.withAction(GradleLocalize.gradleNotificationsApplySuggestion(), (e) ->
- {
- updateDefaultWrapperConfiguration(rootProjectPath);
- EditorNotifications.getInstance(module.getProject()).updateAllNotifications();
- final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
- ExternalSystemUtil.refreshProject(module.getProject(), GradleConstants.SYSTEM_ID, settings.getExternalProjectPath(), new
- ExternalProjectRefreshCallback() {
- @Override
- public void onSuccess(@Nullable final DataNode externalProject) {
- if (externalProject == null) {
- return;
- }
- ExternalSystemApiUtil.executeProjectChangeAction(true, new DisposeAwareProjectChange(module.getProject()) {
- @RequiredUIAccess
- @Override
- public void execute() {
- ProjectRootManager.getInstance(module.getProject()).mergeRootsChangesDuring(() -> projectDataManager
- .importData(externalProject.getKey(), Collections.singleton(externalProject), module.getProject(), true));
- }
- });
- }
-
- @Override
- public void onFailure(@Nonnull String errorMessage, @Nullable String errorDetails) {
- }
- }, true, ProgressExecutionMode.START_IN_FOREGROUND_ASYNC);
- });
- return panel;
- }
- }
- catch (ProcessCanceledException | IndexNotReadyException ignored) {
+ static {
+ GRADLE_SRC_DISTRIBUTION_PATTERN = Pattern.compile("https?\\\\?://services\\.gradle\\.org.*" + ALL_ZIP_DISTRIBUTION_URI_SUFFIX);
}
- return null;
- }
-
- private static void updateDefaultWrapperConfiguration(@Nonnull String linkedProjectPath) {
- try {
- final File wrapperPropertiesFile = GradleUtil.findDefaultWrapperPropertiesFile(linkedProjectPath);
- if (wrapperPropertiesFile == null) {
- return;
- }
- final WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(linkedProjectPath);
- if (wrapperConfiguration == null) {
- return;
- }
- String currentDistributionUri = wrapperConfiguration.getDistribution().toString();
- if (StringUtil.endsWith(currentDistributionUri, ALL_ZIP_DISTRIBUTION_URI_SUFFIX)) {
- return;
- }
-
- final String distributionUri = currentDistributionUri.substring(0, currentDistributionUri.lastIndexOf('-')) +
- ALL_ZIP_DISTRIBUTION_URI_SUFFIX;
-
- wrapperConfiguration.setDistribution(new URI(distributionUri));
- Properties wrapperProperties = new Properties();
- wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_URL_PROPERTY, wrapperConfiguration.getDistribution().toString());
- wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_BASE_PROPERTY, wrapperConfiguration.getDistributionBase());
- wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_PATH_PROPERTY, wrapperConfiguration.getDistributionPath());
- wrapperProperties.setProperty(WrapperExecutor.ZIP_STORE_BASE_PROPERTY, wrapperConfiguration.getZipBase());
- wrapperProperties.setProperty(WrapperExecutor.ZIP_STORE_PATH_PROPERTY, wrapperConfiguration.getZipPath());
- GUtil.saveProperties(wrapperProperties, new File(wrapperPropertiesFile.getPath()));
- LocalFileSystem.getInstance().refreshIoFiles(Collections.singletonList(wrapperPropertiesFile));
+ @Inject
+ public UseDistributionWithSourcesNotificationProvider(Project project) {
+ myProject = project;
}
- catch (Exception e) {
- LOG.error(e);
- }
- }
- private static boolean showUseDistributionWithSourcesTip(String linkedProjectPath) {
- WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(linkedProjectPath);
- // currently only wrapped distribution takes into account
- if (wrapperConfiguration == null) {
- return true;
+ @Nonnull
+ @Override
+ public String getId() {
+ return "gradle-use-distribution-with-source";
}
- String distributionUri = wrapperConfiguration.getDistribution().toString();
- try {
- String host = new URI(distributionUri).getHost();
- return host != null && host.endsWith("gradle.org") && !GRADLE_SRC_DISTRIBUTION_PATTERN.matcher(distributionUri).matches();
+
+ @RequiredReadAction
+ @Nullable
+ @Override
+ public EditorNotificationBuilder buildNotification(
+ @Nonnull VirtualFile file,
+ @Nonnull FileEditor fileEditor,
+ @Nonnull Supplier supplier
+ ) {
+ try {
+ if (GradleConstants.DEFAULT_SCRIPT_NAME.equals(file.getName()) || GradleConstants.SETTINGS_FILE_NAME.equals(file.getName())) {
+
+ final Module module = ModuleUtilCore.findModuleForFile(file, myProject);
+ if (module == null) {
+ return null;
+ }
+ final String rootProjectPath = getRootProjectPath(module);
+ if (rootProjectPath == null) {
+ return null;
+ }
+ final GradleProjectSettings settings =
+ GradleSettings.getInstance(module.getProject()).getLinkedProjectSettings(rootProjectPath);
+ if (settings == null || settings.getDistributionType() != DistributionType.DEFAULT_WRAPPED) {
+ return null;
+ }
+ if (settings.isDisableWrapperSourceDistributionNotification()) {
+ return null;
+ }
+ if (!showUseDistributionWithSourcesTip(rootProjectPath)) {
+ return null;
+ }
+
+ final EditorNotificationBuilder panel = supplier.get();
+ panel.withText(GradleLocalize.gradleNotificationsUseDistributionWithSources());
+ panel.withAction(
+ GradleLocalize.gradleNotificationsHideTip(),
+ e -> {
+ settings.setDisableWrapperSourceDistributionNotification(true);
+ EditorNotifications.getInstance(module.getProject()).updateAllNotifications();
+ }
+ );
+ panel.withAction(
+ GradleLocalize.gradleNotificationsApplySuggestion(),
+ e -> {
+ updateDefaultWrapperConfiguration(rootProjectPath);
+ final Project project = module.getProject();
+ EditorNotifications.getInstance(project).updateAllNotifications();
+ final ProjectDataManager projectDataManager = project.getApplication().getInstance(ProjectDataManager.class);
+ ExternalSystemUtil.refreshProject(
+ project,
+ GradleConstants.SYSTEM_ID,
+ settings.getExternalProjectPath(),
+ new ExternalProjectRefreshCallback() {
+ @Override
+ public void onSuccess(@Nullable final DataNode externalProject) {
+ if (externalProject == null) {
+ return;
+ }
+ ExternalSystemApiUtil.executeProjectChangeAction(
+ true,
+ new DisposeAwareProjectChange(project) {
+ @RequiredUIAccess
+ @Override
+ public void execute() {
+ ProjectRootManager.getInstance(project).mergeRootsChangesDuring(
+ () -> projectDataManager.importData(
+ externalProject.getKey(),
+ Collections.singleton(externalProject),
+ project,
+ true
+ )
+ );
+ }
+ }
+ );
+ }
+
+ @Override
+ public void onFailure(@Nonnull String errorMessage, @Nullable String errorDetails) {
+ }
+ },
+ true,
+ ProgressExecutionMode.START_IN_FOREGROUND_ASYNC
+ );
+ }
+ );
+ return panel;
+ }
+ }
+ catch (ProcessCanceledException | IndexNotReadyException ignored) {
+ }
+
+ return null;
}
- catch (URISyntaxException ignore) {
+
+ private static void updateDefaultWrapperConfiguration(@Nonnull String linkedProjectPath) {
+ try {
+ final File wrapperPropertiesFile = GradleUtil.findDefaultWrapperPropertiesFile(linkedProjectPath);
+ if (wrapperPropertiesFile == null) {
+ return;
+ }
+ final WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(linkedProjectPath);
+ if (wrapperConfiguration == null) {
+ return;
+ }
+ String currentDistributionUri = wrapperConfiguration.getDistribution().toString();
+ if (StringUtil.endsWith(currentDistributionUri, ALL_ZIP_DISTRIBUTION_URI_SUFFIX)) {
+ return;
+ }
+
+ final String distributionUri = currentDistributionUri.substring(0, currentDistributionUri.lastIndexOf('-')) +
+ ALL_ZIP_DISTRIBUTION_URI_SUFFIX;
+
+ wrapperConfiguration.setDistribution(new URI(distributionUri));
+ Properties wrapperProperties = new Properties();
+ wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_URL_PROPERTY, wrapperConfiguration.getDistribution().toString());
+ wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_BASE_PROPERTY, wrapperConfiguration.getDistributionBase());
+ wrapperProperties.setProperty(WrapperExecutor.DISTRIBUTION_PATH_PROPERTY, wrapperConfiguration.getDistributionPath());
+ wrapperProperties.setProperty(WrapperExecutor.ZIP_STORE_BASE_PROPERTY, wrapperConfiguration.getZipBase());
+ wrapperProperties.setProperty(WrapperExecutor.ZIP_STORE_PATH_PROPERTY, wrapperConfiguration.getZipPath());
+ GUtil.saveProperties(wrapperProperties, new File(wrapperPropertiesFile.getPath()));
+ LocalFileSystem.getInstance().refreshIoFiles(Collections.singletonList(wrapperPropertiesFile));
+ }
+ catch (Exception e) {
+ LOG.error(e);
+ }
}
- return false;
- }
-
- @Nullable
- private static String getRootProjectPath(@Nonnull Module module) {
- String externalSystemId = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY);
- if (externalSystemId == null || !GradleConstants.SYSTEM_ID.toString().equals(externalSystemId)) {
- return null;
+
+ private static boolean showUseDistributionWithSourcesTip(String linkedProjectPath) {
+ WrapperConfiguration wrapperConfiguration = GradleUtil.getWrapperConfiguration(linkedProjectPath);
+ // currently only wrapped distribution takes into account
+ if (wrapperConfiguration == null) {
+ return true;
+ }
+ String distributionUri = wrapperConfiguration.getDistribution().toString();
+ try {
+ String host = new URI(distributionUri).getHost();
+ return host != null && host.endsWith("gradle.org") && !GRADLE_SRC_DISTRIBUTION_PATTERN.matcher(distributionUri).matches();
+ }
+ catch (URISyntaxException ignore) {
+ }
+ return false;
}
- String path = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
- return StringUtil.isEmpty(path) ? null : path;
- }
+ @Nullable
+ private static String getRootProjectPath(@Nonnull Module module) {
+ String externalSystemId = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY);
+ if (externalSystemId == null || !GradleConstants.SYSTEM_ID.toString().equals(externalSystemId)) {
+ return null;
+ }
+
+ String path = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
+ return StringUtil.isEmpty(path) ? null : path;
+ }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginAction.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginAction.java
index 9557459..9e185e7 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginAction.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginAction.java
@@ -15,23 +15,25 @@
*/
package org.jetbrains.plugins.gradle.codeInsight.actions;
+import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.component.ActionImpl;
import consulo.annotation.component.ActionParentRef;
import consulo.annotation.component.ActionRef;
import consulo.annotation.component.ActionRefAnchor;
import consulo.application.AllIcons;
import consulo.codeEditor.Editor;
+import consulo.gradle.GradleConstants;
+import consulo.gradle.GradleDocumentationBundle;
+import consulo.gradle.localize.GradleLocalize;
import consulo.language.editor.action.CodeInsightAction;
import consulo.language.editor.action.CodeInsightActionHandler;
import consulo.language.psi.PsiCompiledElement;
import consulo.language.psi.PsiFile;
import consulo.project.Project;
import consulo.util.collection.ContainerUtil;
+import consulo.util.lang.Couple;
import consulo.util.lang.Pair;
import consulo.util.lang.StringUtil;
-import consulo.gradle.GradleBundle;
-import consulo.gradle.GradleConstants;
-import consulo.gradle.GradleDocumentationBundle;
import org.jetbrains.plugins.groovy.GroovyFileType;
import javax.annotation.Nonnull;
@@ -40,43 +42,52 @@
/**
* @author Vladislav.Soroka
- * @since 10/22/13
+ * @since 2013-10-22
*/
-@ActionImpl(id = "AddGradleDslPluginAction", parents = @ActionParentRef(value = @ActionRef(id = "GenerateGroup"), anchor = ActionRefAnchor.FIRST))
+@ActionImpl(
+ id = "AddGradleDslPluginAction",
+ parents = @ActionParentRef(value = @ActionRef(id = "GenerateGroup"), anchor = ActionRefAnchor.FIRST)
+)
public class AddGradleDslPluginAction extends CodeInsightAction {
- private final Pair[] myPlugins;
+ private final Pair[] myPlugins;
- public AddGradleDslPluginAction() {
- getTemplatePresentation().setDescription(GradleBundle.message("gradle.codeInsight.action.apply_plugin.description"));
- getTemplatePresentation().setText(GradleBundle.message("gradle.codeInsight.action.apply_plugin.text"));
- getTemplatePresentation().setIcon(AllIcons.Nodes.Plugin);
+ public AddGradleDslPluginAction() {
+ getTemplatePresentation().setDescriptionValue(GradleLocalize.gradleCodeinsightActionApply_pluginDescription());
+ getTemplatePresentation().setTextValue(GradleLocalize.gradleCodeinsightActionApply_pluginText());
+ getTemplatePresentation().setIcon(AllIcons.Nodes.Plugin);
- final List plugins = StringUtil.split(
- "java,groovy,idea,eclipse,scala,antlr,application,ear,jetty,maven,osgi,war,announce," +
- "build-announcements,checkstyle,codenarc,eclipse-wtp,findbugs,jdepend,pmd,project-report,signing,sonar", ",");
+ final List plugins = StringUtil.split(
+ "java,groovy,idea,eclipse,scala,antlr,application,ear,jetty,maven,osgi,war,announce," +
+ "build-announcements,checkstyle,codenarc,eclipse-wtp,findbugs,jdepend,pmd,project-report,signing,sonar",
+ ","
+ );
- myPlugins = new Pair[plugins.size()];
- ContainerUtil.map2Array(plugins, myPlugins, o -> createPluginKey(o));
- Arrays.sort(myPlugins, (o1, o2) -> String.valueOf(o1.getFirst()).compareTo(String.valueOf(o2.getFirst())));
- }
+ myPlugins = new Pair[plugins.size()];
+ ContainerUtil.map2Array(plugins, myPlugins, AddGradleDslPluginAction::createPluginKey);
+ Arrays.sort(myPlugins, (o1, o2) -> String.valueOf(o1.getFirst()).compareTo(String.valueOf(o2.getFirst())));
+ }
- @Nonnull
- @Override
- protected CodeInsightActionHandler getHandler() {
- return new AddGradleDslPluginActionHandler(myPlugins);
- }
+ @Nonnull
+ @Override
+ protected CodeInsightActionHandler getHandler() {
+ return new AddGradleDslPluginActionHandler(myPlugins);
+ }
- @Override
- protected boolean isValidForFile(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile file) {
- if (file instanceof PsiCompiledElement) return false;
- if (!GroovyFileType.GROOVY_FILE_TYPE.equals(file.getFileType())) return false;
- return !GradleConstants.SETTINGS_FILE_NAME.equals(file.getName()) && file.getName().endsWith(GradleConstants.EXTENSION);
- }
+ @Override
+ @RequiredReadAction
+ protected boolean isValidForFile(@Nonnull Project project, @Nonnull Editor editor, @Nonnull PsiFile file) {
+ return !(file instanceof PsiCompiledElement)
+ && GroovyFileType.INSTANCE.equals(file.getFileType())
+ && !GradleConstants.SETTINGS_FILE_NAME.equals(file.getName())
+ && file.getName().endsWith(GradleConstants.EXTENSION);
+ }
- @Nonnull
- private static Pair createPluginKey(@Nonnull String pluginName) {
- String description = GradleDocumentationBundle.messageOrDefault(
- String.format("gradle.documentation.org.gradle.api.Project.apply.plugin.%s.non-html", pluginName), "");
- return Pair.create(pluginName, description);
- }
+ @Nonnull
+ private static Couple createPluginKey(@Nonnull String pluginName) {
+ String description = GradleDocumentationBundle.messageOrDefault(
+ String.format("gradle.documentation.org.gradle.api.Project.apply.plugin.%s.non-html", pluginName),
+ ""
+ );
+ return Couple.of(pluginName, description);
+ }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginActionHandler.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginActionHandler.java
index 153f995..6d3f026 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginActionHandler.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginActionHandler.java
@@ -15,12 +15,14 @@
*/
package org.jetbrains.plugins.gradle.codeInsight.actions;
+import consulo.annotation.access.RequiredReadAction;
import consulo.codeEditor.Editor;
import consulo.codeEditor.EditorPopupHelper;
import consulo.colorScheme.EditorColorsManager;
import consulo.colorScheme.EditorColorsScheme;
import consulo.colorScheme.EditorFontType;
import consulo.document.Document;
+import consulo.gradle.localize.GradleLocalize;
import consulo.language.editor.WriteCommandAction;
import consulo.language.editor.action.CodeInsightActionHandler;
import consulo.language.editor.util.LanguageEditorUtil;
@@ -29,12 +31,12 @@
import consulo.language.psi.PsiFile;
import consulo.language.psi.util.PsiTreeUtil;
import consulo.project.Project;
+import consulo.ui.annotation.RequiredUIAccess;
import consulo.ui.ex.SimpleTextAttributes;
import consulo.ui.ex.awt.ColoredListCellRenderer;
import consulo.ui.ex.popup.JBPopup;
import consulo.ui.ex.popup.JBPopupFactory;
import consulo.util.lang.Pair;
-import consulo.gradle.GradleBundle;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement;
@@ -48,73 +50,85 @@
/**
* @author Vladislav.Soroka
- * @since 10/24/13
+ * @since 2013-10-24
*/
class AddGradleDslPluginActionHandler implements CodeInsightActionHandler {
- private final Pair[] myPlugins;
+ private final Pair[] myPlugins;
- public AddGradleDslPluginActionHandler(Pair[] plugins) {
- myPlugins = plugins;
- }
+ public AddGradleDslPluginActionHandler(Pair[] plugins) {
+ myPlugins = plugins;
+ }
- @Override
- public void invoke(@Nonnull final Project project, @Nonnull final Editor editor, @Nonnull final PsiFile file) {
- if (!LanguageEditorUtil.checkModificationAllowed(editor)) return;
-
- Consumer runnable =
- selected -> new WriteCommandAction.Simple(project, GradleBundle.message("gradle.codeInsight.action.apply_plugin.text"), file) {
- @Override
- protected void run() {
- if (selected == null) return;
- GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
- GrStatement grStatement = factory.createStatementFromText(
- String.format("apply plugin: '%s'", selected.getFirst()), null);
-
- PsiElement anchor = file.findElementAt(editor.getCaretModel().getOffset());
- PsiElement currentElement = PsiTreeUtil.getParentOfType(anchor, GrClosableBlock.class, GroovyFile.class);
- if (currentElement != null) {
- currentElement.addAfter(grStatement, anchor);
- }
- else {
- file.addAfter(grStatement, file.findElementAt(editor.getCaretModel().getOffset() - 1));
- }
- PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
- Document document = documentManager.getDocument(file);
- if (document != null) {
- documentManager.commitDocument(document);
- }
+ @Override
+ @RequiredUIAccess
+ public void invoke(@Nonnull final Project project, @Nonnull final Editor editor, @Nonnull final PsiFile file) {
+ if (!LanguageEditorUtil.checkModificationAllowed(editor)) {
+ return;
}
- }.execute();
- JBPopup popup = JBPopupFactory.getInstance().createPopupChooserBuilder(List.of(myPlugins))
- .setTitle(GradleBundle.message("gradle.codeInsight.action.apply_plugin.popup.title"))
- .setNamerForFiltering(pair -> String.valueOf(pair.getFirst()))
- .setItemChosenCallback(runnable)
- .setRenderer(new ColoredListCellRenderer>() {
+ Consumer runnable = selected -> new WriteCommandAction.Simple(
+ project,
+ GradleLocalize.gradleCodeinsightActionApply_pluginText().get(),
+ file
+ ) {
+ @Override
+ @RequiredReadAction
+ protected void run() {
+ if (selected == null) {
+ return;
+ }
+ GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
+ GrStatement grStatement = factory.createStatementFromText(
+ String.format("apply plugin: '%s'", selected.getFirst()),
+ null
+ );
+
+ PsiElement anchor = file.findElementAt(editor.getCaretModel().getOffset());
+ PsiElement currentElement = PsiTreeUtil.getParentOfType(anchor, GrClosableBlock.class, GroovyFile.class);
+ if (currentElement != null) {
+ currentElement.addAfter(grStatement, anchor);
+ }
+ else {
+ file.addAfter(grStatement, file.findElementAt(editor.getCaretModel().getOffset() - 1));
+ }
+ PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
+ Document document = documentManager.getDocument(file);
+ if (document != null) {
+ documentManager.commitDocument(document);
+ }
+ }
+ }.execute();
- @Override
- protected void customizeCellRenderer(@Nonnull JList extends Pair> list,
- Pair descriptor,
- int index,
- boolean selected,
- boolean hasFocus) {
- EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
- Font font = scheme.getFont(EditorFontType.PLAIN);
- setFont(font);
+ JBPopup popup = JBPopupFactory.getInstance().createPopupChooserBuilder(List.of(myPlugins))
+ .setTitle(GradleLocalize.gradleCodeinsightActionApply_pluginPopupTitle().get())
+ .setNamerForFiltering(pair -> String.valueOf(pair.getFirst()))
+ .setItemChosenCallback(runnable)
+ .setRenderer(new ColoredListCellRenderer>() {
+ @Override
+ protected void customizeCellRenderer(
+ @Nonnull JList extends Pair> list,
+ Pair descriptor,
+ int index,
+ boolean selected,
+ boolean hasFocus
+ ) {
+ EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
+ Font font = scheme.getFont(EditorFontType.PLAIN);
+ setFont(font);
- append(String.valueOf(descriptor.getFirst()));
+ append(String.valueOf(descriptor.getFirst()));
- String description = String.valueOf(descriptor.getSecond());
- append(description, SimpleTextAttributes.GRAY_ATTRIBUTES);
- }
- })
- .createPopup();
+ String description = String.valueOf(descriptor.getSecond());
+ append(description, SimpleTextAttributes.GRAY_ATTRIBUTES);
+ }
+ })
+ .createPopup();
- EditorPopupHelper.getInstance().showPopupInBestPositionFor(editor, popup);
- }
+ EditorPopupHelper.getInstance().showPopupInBestPositionFor(editor, popup);
+ }
- @Override
- public boolean startInWriteAction() {
- return false;
- }
+ @Override
+ public boolean startInWriteAction() {
+ return false;
+ }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/GradleBaseInspection.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/GradleBaseInspection.java
index 2f9b38b..cd5ff15 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/GradleBaseInspection.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/GradleBaseInspection.java
@@ -21,12 +21,12 @@
/**
* @author Vladislav.Soroka
- * @since 11/21/13
+ * @since 2013-11-21
*/
public abstract class GradleBaseInspection extends BaseInspection {
- @Nonnull
- @Override
- public String[] getGroupPath() {
- return new String[]{"Gradle", getGroupDisplayName()};
- }
+ @Nonnull
+ @Override
+ public String[] getGroupPath() {
+ return new String[]{"Gradle", getGroupDisplayName()};
+ }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/GradleInspectionBundle.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/GradleInspectionBundle.java
index 7cc9521..0863112 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/GradleInspectionBundle.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/GradleInspectionBundle.java
@@ -15,31 +15,33 @@
*/
package org.jetbrains.plugins.gradle.codeInspection;
+import consulo.annotation.DeprecationInfo;
+import consulo.annotation.internal.MigratedExtensionsTo;
import consulo.component.util.localize.AbstractBundle;
+import consulo.gradle.codeInspection.localize.GradleInspectionLocalize;
import org.jetbrains.annotations.PropertyKey;
/**
* @author Vladislav.Soroka
- * @since 9/13/13
+ * @since 2013-09-13
*/
-public class GradleInspectionBundle extends AbstractBundle
-{
- private static final String BUNDLE = "org.jetbrains.plugins.gradle.codeInspection.GradleInspectionBundle";
+@Deprecated
+@DeprecationInfo("GradleInspectionLocalize")
+@MigratedExtensionsTo(GradleInspectionLocalize.class)
+public class GradleInspectionBundle extends AbstractBundle {
+ private static final String BUNDLE = "org.jetbrains.plugins.gradle.codeInspection.GradleInspectionBundle";
- private static final GradleInspectionBundle ourInstance = new GradleInspectionBundle();
+ private static final GradleInspectionBundle ourInstance = new GradleInspectionBundle();
- private GradleInspectionBundle()
- {
- super(BUNDLE);
- }
+ private GradleInspectionBundle() {
+ super(BUNDLE);
+ }
- public static String message(@PropertyKey(resourceBundle = BUNDLE) String key)
- {
- return ourInstance.getMessage(key);
- }
+ public static String message(@PropertyKey(resourceBundle = BUNDLE) String key) {
+ return ourInstance.getMessage(key);
+ }
- public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params)
- {
- return ourInstance.getMessage(key, params);
- }
+ public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
+ return ourInstance.getMessage(key, params);
+ }
}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/MultipleRepositoryUrlsFix.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/MultipleRepositoryUrlsFix.java
index 3ed7129..703402a 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/MultipleRepositoryUrlsFix.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/MultipleRepositoryUrlsFix.java
@@ -15,6 +15,8 @@
*/
package org.jetbrains.plugins.gradle.codeInspection;
+import consulo.annotation.access.RequiredWriteAction;
+import consulo.gradle.codeInspection.localize.GradleInspectionLocalize;
import consulo.language.editor.inspection.ProblemDescriptor;
import consulo.language.psi.PsiElement;
import consulo.language.psi.util.PsiTreeUtil;
@@ -32,44 +34,52 @@
/**
* @author Vladislav.Soroka
- * @since 11/21/13
+ * @since 2013-11-21
*/
public class MultipleRepositoryUrlsFix extends GroovyFix {
- private final GrClosableBlock myClosure;
- private final String myRepoType;
+ private final GrClosableBlock myClosure;
+ private final String myRepoType;
- public MultipleRepositoryUrlsFix(@Nonnull GrClosableBlock closure, @Nonnull String repoType) {
- myClosure = closure;
- myRepoType = repoType;
- }
+ public MultipleRepositoryUrlsFix(@Nonnull GrClosableBlock closure, @Nonnull String repoType) {
+ myClosure = closure;
+ myRepoType = repoType;
+ }
- @Override
- protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
- List statements = MultipleRepositoryUrlsInspection.findUrlCallExpressions(myClosure);
- if (statements.size() <= 1) return;
- statements.remove(0);
+ @Override
+ @RequiredWriteAction
+ protected void doFix(Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
+ List statements = MultipleRepositoryUrlsInspection.findUrlCallExpressions(myClosure);
+ if (statements.size() <= 1) {
+ return;
+ }
+ statements.remove(0);
- List elements = new ArrayList(statements);
- for (GrCallExpression statement : statements) {
- PsiElement newLineCandidate = statement.getNextSibling();
- if (PsiUtil.isNewLine(newLineCandidate)) {
- elements.add(newLineCandidate);
- }
- }
+ List elements = new ArrayList<>(statements);
+ for (GrCallExpression statement : statements) {
+ PsiElement newLineCandidate = statement.getNextSibling();
+ if (PsiUtil.isNewLine(newLineCandidate)) {
+ elements.add(newLineCandidate);
+ }
+ }
- myClosure.removeElements(elements.toArray(new PsiElement[elements.size()]));
- GrClosableBlock closableBlock = PsiTreeUtil.getParentOfType(myClosure, GrClosableBlock.class);
- if (closableBlock == null) return;
+ myClosure.removeElements(elements.toArray(new PsiElement[elements.size()]));
+ GrClosableBlock closableBlock = PsiTreeUtil.getParentOfType(myClosure, GrClosableBlock.class);
+ if (closableBlock == null) {
+ return;
+ }
- GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(project);
- for (GrCallExpression statement : statements) {
- closableBlock.addStatementBefore(elementFactory.createStatementFromText(myRepoType + '{' + statement.getText() + '}'), null);
+ GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(project);
+ for (GrCallExpression statement : statements) {
+ closableBlock.addStatementBefore(
+ elementFactory.createStatementFromText(myRepoType + '{' + statement.getText() + '}'),
+ null
+ );
+ }
}
- }
- @Nonnull
- @Override
- public String getName() {
- return GradleInspectionBundle.message("multiple.repository.urls.fix.name");
- }
+ @Nonnull
+ @Override
+ public String getName() {
+ return GradleInspectionLocalize.multipleRepositoryUrlsFixName().get();
+ }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/MultipleRepositoryUrlsInspection.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/MultipleRepositoryUrlsInspection.java
index 31788ad..d0c084c 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/MultipleRepositoryUrlsInspection.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/codeInspection/MultipleRepositoryUrlsInspection.java
@@ -15,7 +15,9 @@
*/
package org.jetbrains.plugins.gradle.codeInspection;
+import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.component.ExtensionImpl;
+import consulo.gradle.codeInspection.localize.GradleInspectionLocalize;
import consulo.language.editor.inspection.LocalQuickFix;
import consulo.language.editor.inspection.ProblemHighlightType;
import consulo.language.psi.PsiFile;
@@ -38,89 +40,105 @@
/**
* @author Vladislav.Soroka
- * @since 11/21/13
+ * @since 2013-11-21
*/
@ExtensionImpl
public class MultipleRepositoryUrlsInspection extends GradleBaseInspection {
+ @Nonnull
+ @Override
+ protected BaseInspectionVisitor buildVisitor() {
+ return new MyVisitor();
+ }
- @Nonnull
- @Override
- protected BaseInspectionVisitor buildVisitor() {
- return new MyVisitor();
- }
-
- @Nls
- @Nonnull
- @Override
- public String getGroupDisplayName() {
- return PROBABLE_BUGS;
- }
-
- @Nonnull
- @Override
- public String[] getGroupPath() {
- return new String[] {"Gradle"};
- }
+ @Nls
+ @Nonnull
+ @Override
+ public String getGroupDisplayName() {
+ return PROBABLE_BUGS;
+ }
- @Override
- protected String buildErrorString(Object... args) {
- return GradleInspectionBundle.message("multiple.repository.urls", args);
- }
+ @Nonnull
+ @Override
+ public String[] getGroupPath() {
+ return new String[]{"Gradle"};
+ }
- @Nls
- @Nonnull
- @Override
- public String getDisplayName() {
- return GradleInspectionBundle.message("multiple.repository.urls");
- }
+ @Override
+ protected String buildErrorString(Object... args) {
+ return GradleInspectionLocalize.multipleRepositoryUrls().get();
+ }
- private static class MyVisitor extends BaseInspectionVisitor {
+ @Nls
+ @Nonnull
@Override
- public void visitClosure(GrClosableBlock closure) {
- PsiFile file = closure.getContainingFile();
- if (file == null || !FileUtil.extensionEquals(file.getName(), GradleConstants.EXTENSION)) return;
+ public String getDisplayName() {
+ return GradleInspectionLocalize.multipleRepositoryUrls().get();
+ }
- super.visitClosure(closure);
- GrMethodCall mavenMethodCall = PsiTreeUtil.getParentOfType(closure, GrMethodCall.class);
- if (mavenMethodCall == null) return;
- GrExpression mavenMethodExpression = mavenMethodCall.getInvokedExpression();
- if (mavenMethodExpression == null ||
- !ArrayUtil.contains(mavenMethodExpression.getText(), "maven", "ivy")) {
- return;
- }
+ private static class MyVisitor extends BaseInspectionVisitor {
+ @Override
+ @RequiredReadAction
+ public void visitClosure(GrClosableBlock closure) {
+ PsiFile file = closure.getContainingFile();
+ if (file == null || !FileUtil.extensionEquals(file.getName(), GradleConstants.EXTENSION)) {
+ return;
+ }
- GrMethodCall repositoryMethodCall = PsiTreeUtil.getParentOfType(mavenMethodCall, GrMethodCall.class);
- if (repositoryMethodCall == null) return;
- GrExpression repositoryMethodExpression = repositoryMethodCall.getInvokedExpression();
- if (repositoryMethodExpression == null || !repositoryMethodExpression.getText().equals("repositories")) return;
+ super.visitClosure(closure);
+ GrMethodCall mavenMethodCall = PsiTreeUtil.getParentOfType(closure, GrMethodCall.class);
+ if (mavenMethodCall == null) {
+ return;
+ }
+ GrExpression mavenMethodExpression = mavenMethodCall.getInvokedExpression();
+ if (mavenMethodExpression == null ||
+ !ArrayUtil.contains(mavenMethodExpression.getText(), "maven", "ivy")) {
+ return;
+ }
- List statements = findUrlCallExpressions(closure);
- if (statements.size() > 1) {
- registerError(closure);
+ GrMethodCall repositoryMethodCall = PsiTreeUtil.getParentOfType(mavenMethodCall, GrMethodCall.class);
+ if (repositoryMethodCall == null) {
+ return;
+ }
+ GrExpression repositoryMethodExpression = repositoryMethodCall.getInvokedExpression();
+ if (repositoryMethodExpression == null || !repositoryMethodExpression.getText().equals("repositories")) {
+ return;
+ }
- registerError(closure, GradleInspectionBundle.message("multiple.repository.urls"),
- new LocalQuickFix[]{new MultipleRepositoryUrlsFix(closure, mavenMethodExpression.getText())},
- ProblemHighlightType.GENERIC_ERROR);
- }
+ List statements = findUrlCallExpressions(closure);
+ if (statements.size() > 1) {
+ registerError(closure);
+
+ registerError(
+ closure,
+ GradleInspectionLocalize.multipleRepositoryUrls().get(),
+ new LocalQuickFix[]{new MultipleRepositoryUrlsFix(closure, mavenMethodExpression.getText())},
+ ProblemHighlightType.GENERIC_ERROR
+ );
+ }
+ }
}
- }
- @Nonnull
- static List findUrlCallExpressions(@Nonnull GrClosableBlock closure) {
- GrCallExpression[] applicationStatements = PsiTreeUtil.getChildrenOfType(closure, GrCallExpression.class);
- if (applicationStatements == null) return Collections.emptyList();
+ @Nonnull
+ @RequiredReadAction
+ static List findUrlCallExpressions(@Nonnull GrClosableBlock closure) {
+ GrCallExpression[] applicationStatements = PsiTreeUtil.getChildrenOfType(closure, GrCallExpression.class);
+ if (applicationStatements == null) {
+ return Collections.emptyList();
+ }
- List statements = new ArrayList<>();
- for (GrCallExpression statement : applicationStatements) {
- GrReferenceExpression[] referenceExpressions = PsiTreeUtil.getChildrenOfType(statement, GrReferenceExpression.class);
- if (referenceExpressions == null) continue;
- for (GrReferenceExpression expression : referenceExpressions) {
- String expressionText = expression.getText();
- if ("url".equals(expressionText) || "setUrl".equals(expressionText)) {
- statements.add(statement);
+ List statements = new ArrayList<>();
+ for (GrCallExpression statement : applicationStatements) {
+ GrReferenceExpression[] referenceExpressions = PsiTreeUtil.getChildrenOfType(statement, GrReferenceExpression.class);
+ if (referenceExpressions == null) {
+ continue;
+ }
+ for (GrReferenceExpression expression : referenceExpressions) {
+ String expressionText = expression.getText();
+ if ("url".equals(expressionText) || "setUrl".equals(expressionText)) {
+ statements.add(statement);
+ }
+ }
}
- }
+ return statements;
}
- return statements;
- }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/DelegatingGradleSettingsListenerAdapter.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/DelegatingGradleSettingsListenerAdapter.java
index 2b49555..518f9bb 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/DelegatingGradleSettingsListenerAdapter.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/DelegatingGradleSettingsListenerAdapter.java
@@ -26,29 +26,28 @@
/**
* @author Denis Zhdanov
- * @since 6/24/13 6:35 PM
+ * @since 2013-06-24
*/
public class DelegatingGradleSettingsListenerAdapter extends DelegatingExternalSystemSettingsListener
- implements GradleSettingsListener
-{
+ implements GradleSettingsListener {
- public DelegatingGradleSettingsListenerAdapter(@Nonnull ExternalSystemSettingsListener delegate) {
- super(delegate);
- }
+ public DelegatingGradleSettingsListenerAdapter(@Nonnull ExternalSystemSettingsListener delegate) {
+ super(delegate);
+ }
- @Override
- public void onGradleHomeChange(@Nullable String oldPath, @Nullable String newPath, @Nonnull String linkedProjectPath) {
- }
+ @Override
+ public void onGradleHomeChange(@Nullable String oldPath, @Nullable String newPath, @Nonnull String linkedProjectPath) {
+ }
- @Override
- public void onGradleDistributionTypeChange(DistributionType currentValue, @Nonnull String linkedProjectPath) {
- }
+ @Override
+ public void onGradleDistributionTypeChange(DistributionType currentValue, @Nonnull String linkedProjectPath) {
+ }
- @Override
- public void onServiceDirectoryPathChange(@Nullable String oldPath, @Nullable String newPath) {
- }
+ @Override
+ public void onServiceDirectoryPathChange(@Nullable String oldPath, @Nullable String newPath) {
+ }
- @Override
- public void onGradleVmOptionsChange(@Nullable String oldOptions, @Nullable String newOptions) {
- }
+ @Override
+ public void onGradleVmOptionsChange(@Nullable String oldOptions, @Nullable String newOptions) {
+ }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleBuildClasspathResolveScopeEnlarger.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleBuildClasspathResolveScopeEnlarger.java
index b93a8cf..cc690f4 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleBuildClasspathResolveScopeEnlarger.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleBuildClasspathResolveScopeEnlarger.java
@@ -30,23 +30,24 @@
/**
* @author Vladislav.Soroka
- * @since 5/16/2014
+ * @since 2014-05-16
*/
@ExtensionImpl
public class GradleBuildClasspathResolveScopeEnlarger extends ResolveScopeEnlarger {
- @Override
- public SearchScope getAdditionalResolveScope(@Nonnull VirtualFile file, Project project) {
- String fileExtension = file.getExtension();
- if (GroovyFileType.DEFAULT_EXTENSION.equals(fileExtension)) {
- GradleClassFinder gradleClassFinder = project.getExtensionPoint(PsiElementFinder.class).findExtensionOrFail(GradleClassFinder.class);
+ @Override
+ public SearchScope getAdditionalResolveScope(@Nonnull VirtualFile file, Project project) {
+ String fileExtension = file.getExtension();
+ if (GroovyFileType.DEFAULT_EXTENSION.equals(fileExtension)) {
+ GradleClassFinder gradleClassFinder =
+ project.getExtensionPoint(PsiElementFinder.class).findExtensionOrFail(GradleClassFinder.class);
- final List roots = gradleClassFinder.getClassRoots();
- for (VirtualFile root : roots) {
- if (VfsUtilCore.isAncestor(root, file, true)) {
- return NonClasspathDirectoriesScope.compose(roots);
+ final List roots = gradleClassFinder.getClassRoots();
+ for (VirtualFile root : roots) {
+ if (VfsUtilCore.isAncestor(root, file, true)) {
+ return NonClasspathDirectoriesScope.compose(roots);
+ }
+ }
}
- }
+ return null;
}
- return null;
- }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleClassFinder.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleClassFinder.java
index b07932f..406e07c 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleClassFinder.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleClassFinder.java
@@ -44,59 +44,64 @@
*/
@ExtensionImpl
public class GradleClassFinder extends NonClasspathClassFinder {
- @Nonnull
- private final GradleBuildClasspathManager myBuildClasspathManager;
- private final Map myCaches;
+ @Nonnull
+ private final GradleBuildClasspathManager myBuildClasspathManager;
+ private final Map myCaches;
- @Inject
- public GradleClassFinder(@Nonnull Project project, @Nonnull GradleBuildClasspathManager buildClasspathManager) {
- super(project, JavaFileType.DEFAULT_EXTENSION, GroovyFileType.DEFAULT_EXTENSION);
- myBuildClasspathManager = buildClasspathManager;
+ @Inject
+ public GradleClassFinder(@Nonnull Project project, @Nonnull GradleBuildClasspathManager buildClasspathManager) {
+ super(project, JavaFileType.DEFAULT_EXTENSION, GroovyFileType.DEFAULT_EXTENSION);
+ myBuildClasspathManager = buildClasspathManager;
- myCaches = ConcurrentFactoryMap.createMap(path -> createCache(myBuildClasspathManager.getModuleClasspathEntries(path)));
- }
-
- @Override
- protected List calcClassRoots() {
- return myBuildClasspathManager.getAllClasspathEntries();
- }
+ myCaches = ConcurrentFactoryMap.createMap(path -> createCache(myBuildClasspathManager.getModuleClasspathEntries(path)));
+ }
- @Nonnull
- @Override
- protected PackageDirectoryCache getCache(@Nullable GlobalSearchScope scope) {
- if (scope instanceof ExternalModuleBuildGlobalSearchScope) {
- return myCaches.get(((ExternalModuleBuildGlobalSearchScope)scope).getExternalModulePath());
+ @Override
+ protected List calcClassRoots() {
+ return myBuildClasspathManager.getAllClasspathEntries();
}
- return super.getCache(scope);
- }
- @Override
- public void clearCache() {
- super.clearCache();
- myCaches.clear();
- }
+ @Nonnull
+ @Override
+ protected PackageDirectoryCache getCache(@Nullable GlobalSearchScope scope) {
+ if (scope instanceof ExternalModuleBuildGlobalSearchScope externalModuleBuildGlobalSearchScope) {
+ return myCaches.get(externalModuleBuildGlobalSearchScope.getExternalModulePath());
+ }
+ return super.getCache(scope);
+ }
- @Override
- public PsiClass findClass(@Nonnull String qualifiedName, @Nonnull GlobalSearchScope scope) {
- PsiClass aClass = super.findClass(qualifiedName, scope);
- if (aClass == null || scope instanceof ExternalModuleBuildGlobalSearchScope || scope instanceof EverythingGlobalScope) {
- return aClass;
+ @Override
+ public void clearCache() {
+ super.clearCache();
+ myCaches.clear();
}
- PsiFile containingFile = aClass.getContainingFile();
- VirtualFile file = containingFile != null ? containingFile.getVirtualFile() : null;
- return (file != null && !ProjectFileIndex.SERVICE.getInstance(myProject).isInContent(file) && !ProjectFileIndex.SERVICE.getInstance
- (myProject).isInLibraryClasses(file) && !ProjectFileIndex.SERVICE.getInstance(myProject).isInLibrarySource(file)) ? aClass : null;
- }
+ @Override
+ public PsiClass findClass(@Nonnull String qualifiedName, @Nonnull GlobalSearchScope scope) {
+ PsiClass aClass = super.findClass(qualifiedName, scope);
+ if (aClass == null || scope instanceof ExternalModuleBuildGlobalSearchScope || scope instanceof EverythingGlobalScope) {
+ return aClass;
+ }
- @Nonnull
- @Override
- public PsiJavaPackage[] getSubPackages(@Nonnull PsiJavaPackage psiPackage, @Nonnull GlobalSearchScope scope) {
- if (scope instanceof ExternalModuleBuildGlobalSearchScope) {
- return super.getSubPackages(psiPackage, scope);
+ PsiFile containingFile = aClass.getContainingFile();
+ VirtualFile file = containingFile != null ? containingFile.getVirtualFile() : null;
+ ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
+ return file != null
+ && !projectFileIndex.isInContent(file)
+ && !projectFileIndex.isInLibraryClasses(file)
+ && !projectFileIndex.isInLibrarySource(file)
+ ? aClass
+ : null;
}
- else {
- return PsiJavaPackage.EMPTY_ARRAY;
+
+ @Nonnull
+ @Override
+ public PsiJavaPackage[] getSubPackages(@Nonnull PsiJavaPackage psiPackage, @Nonnull GlobalSearchScope scope) {
+ if (scope instanceof ExternalModuleBuildGlobalSearchScope) {
+ return super.getSubPackages(psiPackage, scope);
+ }
+ else {
+ return PsiJavaPackage.EMPTY_ARRAY;
+ }
}
- }
}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleDefaultImportContributor.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleDefaultImportContributor.java
index 925e146..e71c6c5 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleDefaultImportContributor.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleDefaultImportContributor.java
@@ -30,121 +30,120 @@
*/
@ExtensionImpl
public class GradleDefaultImportContributor extends DefaultImportContributor {
+ // As listed here - http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:using_gradle_without_ide_support
+ public static final String[] IMPLICIT_GRADLE_PACKAGES = {
+ "org.gradle",
+ "org.gradle.api",
+ "org.gradle.api.artifacts",
+ "org.gradle.api.artifacts.cache",
+ "org.gradle.api.artifacts.dsl",
+ "org.gradle.api.artifacts.maven",
+ "org.gradle.api.artifacts.repositories",
+ "org.gradle.api.artifacts.result",
+ "org.gradle.api.component",
+ "org.gradle.api.distribution",
+ "org.gradle.api.distribution.plugins",
+ "org.gradle.api.dsl",
+ "org.gradle.api.execution",
+ "org.gradle.api.file",
+ "org.gradle.api.initialization",
+ "org.gradle.api.initialization.dsl",
+ "org.gradle.api.invocation",
+ "org.gradle.api.java.archives",
+ "org.gradle.api.logging",
+ "org.gradle.api.plugins",
+ "org.gradle.api.plugins.announce",
+ "org.gradle.api.plugins.antlr",
+ "org.gradle.api.plugins.buildcomparison.gradle",
+ "org.gradle.api.plugins.jetty",
+ "org.gradle.api.plugins.osgi",
+ "org.gradle.api.plugins.quality",
+ "org.gradle.api.plugins.scala",
+ "org.gradle.api.plugins.sonar",
+ "org.gradle.api.plugins.sonar.model",
+ "org.gradle.api.publish",
+ "org.gradle.api.publish.ivy",
+ "org.gradle.api.publish.ivy.plugins",
+ "org.gradle.api.publish.ivy.tasks",
+ "org.gradle.api.publish.maven",
+ "org.gradle.api.publish.maven.plugins",
+ "org.gradle.api.publish.maven.tasks",
+ "org.gradle.api.publish.plugins",
+ "org.gradle.api.reporting",
+ "org.gradle.api.reporting.plugins",
+ "org.gradle.api.resources",
+ "org.gradle.api.sonar.runner",
+ "org.gradle.api.specs",
+ "org.gradle.api.tasks",
+ "org.gradle.api.tasks.ant",
+ "org.gradle.api.tasks.application",
+ "org.gradle.api.tasks.bundling",
+ "org.gradle.api.tasks.compile",
+ "org.gradle.api.tasks.diagnostics",
+ "org.gradle.api.tasks.incremental",
+ "org.gradle.api.tasks.javadoc",
+ "org.gradle.api.tasks.scala",
+ "org.gradle.api.tasks.testing",
+ "org.gradle.api.tasks.testing.junit",
+ "org.gradle.api.tasks.testing.testng",
+ "org.gradle.api.tasks.util",
+ "org.gradle.api.tasks.wrapper",
+ "org.gradle.buildsetup.plugins",
+ "org.gradle.buildsetup.tasks",
+ "org.gradle.external.javadoc",
+ "org.gradle.language.base",
+ "org.gradle.language.base.plugins",
+ "org.gradle.language.java",
+ "org.gradle.language.jvm",
+ "org.gradle.language.jvm.plugins",
+ "org.gradle.language.jvm.tasks",
+ "org.gradle.nativecode.base",
+ "org.gradle.nativecode.base.plugins",
+ "org.gradle.nativecode.base.tasks",
+ "org.gradle.nativecode.cdt",
+ "org.gradle.nativecode.cdt.tasks",
+ "org.gradle.nativecode.language.cpp",
+ "org.gradle.nativecode.language.cpp.plugins",
+ "org.gradle.nativecode.language.cpp.tasks",
+ "org.gradle.nativecode.toolchain.plugins",
+ "org.gradle.plugins.binaries",
+ "org.gradle.plugins.cpp",
+ "org.gradle.plugins.cpp.cdt",
+ "org.gradle.plugins.cpp.cdt.tasks",
+ "org.gradle.plugins.cpp.compiler.capability",
+ "org.gradle.plugins.cpp.gpp",
+ "org.gradle.plugins.cpp.msvcpp",
+ "org.gradle.plugins.ear",
+ "org.gradle.plugins.ear.descriptor",
+ "org.gradle.plugins.ide.api",
+ "org.gradle.plugins.ide.eclipse",
+ "org.gradle.plugins.ide.idea",
+ "org.gradle.plugins.javascript.base",
+ "org.gradle.plugins.javascript.coffeescript",
+ "org.gradle.plugins.javascript.envjs",
+ "org.gradle.plugins.javascript.envjs.browser",
+ "org.gradle.plugins.javascript.envjs.http",
+ "org.gradle.plugins.javascript.envjs.http.simple",
+ "org.gradle.plugins.javascript.jshint",
+ "org.gradle.plugins.javascript.rhino",
+ "org.gradle.plugins.javascript.rhino.worker",
+ "org.gradle.plugins.signing",
+ "org.gradle.plugins.signing.signatory",
+ "org.gradle.plugins.signing.signatory.pgp",
+ "org.gradle.plugins.signing.type",
+ "org.gradle.plugins.signing.type.pgp",
+ "org.gradle.process",
+ "org.gradle.testing.jacoco.plugins",
+ "org.gradle.testing.jacoco.tasks",
+ "org.gradle.util"
+ };
- // As listed here - http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:using_gradle_without_ide_support
- public static final String[] IMPLICIT_GRADLE_PACKAGES = {
- "org.gradle",
- "org.gradle.api",
- "org.gradle.api.artifacts",
- "org.gradle.api.artifacts.cache",
- "org.gradle.api.artifacts.dsl",
- "org.gradle.api.artifacts.maven",
- "org.gradle.api.artifacts.repositories",
- "org.gradle.api.artifacts.result",
- "org.gradle.api.component",
- "org.gradle.api.distribution",
- "org.gradle.api.distribution.plugins",
- "org.gradle.api.dsl",
- "org.gradle.api.execution",
- "org.gradle.api.file",
- "org.gradle.api.initialization",
- "org.gradle.api.initialization.dsl",
- "org.gradle.api.invocation",
- "org.gradle.api.java.archives",
- "org.gradle.api.logging",
- "org.gradle.api.plugins",
- "org.gradle.api.plugins.announce",
- "org.gradle.api.plugins.antlr",
- "org.gradle.api.plugins.buildcomparison.gradle",
- "org.gradle.api.plugins.jetty",
- "org.gradle.api.plugins.osgi",
- "org.gradle.api.plugins.quality",
- "org.gradle.api.plugins.scala",
- "org.gradle.api.plugins.sonar",
- "org.gradle.api.plugins.sonar.model",
- "org.gradle.api.publish",
- "org.gradle.api.publish.ivy",
- "org.gradle.api.publish.ivy.plugins",
- "org.gradle.api.publish.ivy.tasks",
- "org.gradle.api.publish.maven",
- "org.gradle.api.publish.maven.plugins",
- "org.gradle.api.publish.maven.tasks",
- "org.gradle.api.publish.plugins",
- "org.gradle.api.reporting",
- "org.gradle.api.reporting.plugins",
- "org.gradle.api.resources",
- "org.gradle.api.sonar.runner",
- "org.gradle.api.specs",
- "org.gradle.api.tasks",
- "org.gradle.api.tasks.ant",
- "org.gradle.api.tasks.application",
- "org.gradle.api.tasks.bundling",
- "org.gradle.api.tasks.compile",
- "org.gradle.api.tasks.diagnostics",
- "org.gradle.api.tasks.incremental",
- "org.gradle.api.tasks.javadoc",
- "org.gradle.api.tasks.scala",
- "org.gradle.api.tasks.testing",
- "org.gradle.api.tasks.testing.junit",
- "org.gradle.api.tasks.testing.testng",
- "org.gradle.api.tasks.util",
- "org.gradle.api.tasks.wrapper",
- "org.gradle.buildsetup.plugins",
- "org.gradle.buildsetup.tasks",
- "org.gradle.external.javadoc",
- "org.gradle.language.base",
- "org.gradle.language.base.plugins",
- "org.gradle.language.java",
- "org.gradle.language.jvm",
- "org.gradle.language.jvm.plugins",
- "org.gradle.language.jvm.tasks",
- "org.gradle.nativecode.base",
- "org.gradle.nativecode.base.plugins",
- "org.gradle.nativecode.base.tasks",
- "org.gradle.nativecode.cdt",
- "org.gradle.nativecode.cdt.tasks",
- "org.gradle.nativecode.language.cpp",
- "org.gradle.nativecode.language.cpp.plugins",
- "org.gradle.nativecode.language.cpp.tasks",
- "org.gradle.nativecode.toolchain.plugins",
- "org.gradle.plugins.binaries",
- "org.gradle.plugins.cpp",
- "org.gradle.plugins.cpp.cdt",
- "org.gradle.plugins.cpp.cdt.tasks",
- "org.gradle.plugins.cpp.compiler.capability",
- "org.gradle.plugins.cpp.gpp",
- "org.gradle.plugins.cpp.msvcpp",
- "org.gradle.plugins.ear",
- "org.gradle.plugins.ear.descriptor",
- "org.gradle.plugins.ide.api",
- "org.gradle.plugins.ide.eclipse",
- "org.gradle.plugins.ide.idea",
- "org.gradle.plugins.javascript.base",
- "org.gradle.plugins.javascript.coffeescript",
- "org.gradle.plugins.javascript.envjs",
- "org.gradle.plugins.javascript.envjs.browser",
- "org.gradle.plugins.javascript.envjs.http",
- "org.gradle.plugins.javascript.envjs.http.simple",
- "org.gradle.plugins.javascript.jshint",
- "org.gradle.plugins.javascript.rhino",
- "org.gradle.plugins.javascript.rhino.worker",
- "org.gradle.plugins.signing",
- "org.gradle.plugins.signing.signatory",
- "org.gradle.plugins.signing.signatory.pgp",
- "org.gradle.plugins.signing.type",
- "org.gradle.plugins.signing.type.pgp",
- "org.gradle.process",
- "org.gradle.testing.jacoco.plugins",
- "org.gradle.testing.jacoco.tasks",
- "org.gradle.util"
- };
-
- @Override
- public List appendImplicitlyImportedPackages(@Nonnull GroovyFile file) {
- if (file.isScript() && GroovyScriptUtil.getScriptType(file) instanceof GradleScriptType) {
- return Arrays.asList(IMPLICIT_GRADLE_PACKAGES);
+ @Override
+ public List appendImplicitlyImportedPackages(@Nonnull GroovyFile file) {
+ if (file.isScript() && GroovyScriptUtil.getScriptType(file) instanceof GradleScriptType) {
+ return Arrays.asList(IMPLICIT_GRADLE_PACKAGES);
+ }
+ return Collections.emptyList();
}
- return Collections.emptyList();
- }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleLibraryPresentationProvider.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleLibraryPresentationProvider.java
index fec2b2c..f710b5b 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleLibraryPresentationProvider.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradleLibraryPresentationProvider.java
@@ -40,92 +40,91 @@
*/
@ExtensionImpl
public class GradleLibraryPresentationProvider extends GroovyLibraryPresentationProviderBase {
+ private static final LibraryKind GRADLE_KIND = LibraryKind.create(GradleConstants.EXTENSION);
- private static final LibraryKind GRADLE_KIND = LibraryKind.create(GradleConstants.EXTENSION);
+ private final GradleInstallationManager myLibraryManager;
- private final GradleInstallationManager myLibraryManager;
-
- @Inject
- public GradleLibraryPresentationProvider(@Nonnull GradleInstallationManager libraryManager) {
- super(GRADLE_KIND);
- myLibraryManager = libraryManager;
- }
+ @Inject
+ public GradleLibraryPresentationProvider(@Nonnull GradleInstallationManager libraryManager) {
+ super(GRADLE_KIND);
+ myLibraryManager = libraryManager;
+ }
- @Nonnull
- @Override
- public Image getIcon() {
- return GradleIconGroup.gradle();
- }
+ @Nonnull
+ @Override
+ public Image getIcon() {
+ return GradleIconGroup.gradle();
+ }
- @Nls
- @Override
- public String getLibraryVersion(final VirtualFile[] libraryFiles) {
- return getGradleVersion(libraryFiles);
- }
+ @Nls
+ @Override
+ public String getLibraryVersion(final VirtualFile[] libraryFiles) {
+ return getGradleVersion(libraryFiles);
+ }
- @Override
- public boolean isSDKHome(@Nonnull VirtualFile file) {
- return myLibraryManager.isGradleSdkHome(file);
- }
+ @Override
+ public boolean isSDKHome(@Nonnull VirtualFile file) {
+ return myLibraryManager.isGradleSdkHome(file);
+ }
- @Override
- public boolean managesLibrary(final VirtualFile[] libraryFiles) {
- return myLibraryManager.isGradleSdk(libraryFiles);
- }
+ @Override
+ public boolean managesLibrary(final VirtualFile[] libraryFiles) {
+ return myLibraryManager.isGradleSdk(libraryFiles);
+ }
- @Nonnull
- @Override
- public String getSDKVersion(String path) {
- final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
- assert file != null;
- VirtualFile lib = file.findChild("lib");
- assert lib != null;
- for (VirtualFile virtualFile : lib.getChildren()) {
- final String version = getGradleJarVersion(virtualFile);
- if (version != null) {
- return version;
- }
+ @Nonnull
+ @Override
+ public String getSDKVersion(String path) {
+ final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(path);
+ assert file != null;
+ VirtualFile lib = file.findChild("lib");
+ assert lib != null;
+ for (VirtualFile virtualFile : lib.getChildren()) {
+ final String version = getGradleJarVersion(virtualFile);
+ if (version != null) {
+ return version;
+ }
+ }
+ throw new AssertionError(path);
}
- throw new AssertionError(path);
- }
- @Nls
- @Nonnull
- @Override
- public String getLibraryCategoryName() {
- return "Gradle";
- }
+ @Nls
+ @Nonnull
+ @Override
+ public String getLibraryCategoryName() {
+ return "Gradle";
+ }
- @Override
- protected void fillLibrary(String path, LibraryEditor libraryEditor) {
- File lib = new File(path + "/lib");
- File[] jars = lib.exists() ? lib.listFiles() : new File[0];
- if (jars != null) {
- for (File file : jars) {
- if (file.getName().endsWith(".jar")) {
- libraryEditor.addRoot(VfsUtil.getUrlForLibraryRoot(file), BinariesOrderRootType.getInstance());
+ @Override
+ protected void fillLibrary(String path, LibraryEditor libraryEditor) {
+ File lib = new File(path + "/lib");
+ File[] jars = lib.exists() ? lib.listFiles() : new File[0];
+ if (jars != null) {
+ for (File file : jars) {
+ if (file.getName().endsWith(".jar")) {
+ libraryEditor.addRoot(VfsUtil.getUrlForLibraryRoot(file), BinariesOrderRootType.getInstance());
+ }
+ }
}
- }
}
- }
- @Nullable
- private static String getGradleVersion(VirtualFile[] libraryFiles) {
- for (VirtualFile file : libraryFiles) {
- final String version = getGradleJarVersion(file);
- if (version != null) {
- return version;
- }
+ @Nullable
+ private static String getGradleVersion(VirtualFile[] libraryFiles) {
+ for (VirtualFile file : libraryFiles) {
+ final String version = getGradleJarVersion(file);
+ if (version != null) {
+ return version;
+ }
+ }
+ return null;
}
- return null;
- }
- @Nullable
- private static String getGradleJarVersion(VirtualFile file) {
- final Matcher matcher = GradleInstallationManager.GRADLE_JAR_FILE_PATTERN.matcher(file.getName());
- if (matcher.matches()) {
- return matcher.group(2);
+ @Nullable
+ private static String getGradleJarVersion(VirtualFile file) {
+ final Matcher matcher = GradleInstallationManager.GRADLE_JAR_FILE_PATTERN.matcher(file.getName());
+ if (matcher.matches()) {
+ return matcher.group(2);
+ }
+ return null;
}
- return null;
- }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradlePatcher.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradlePatcher.java
index d14e280..344063c 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradlePatcher.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradlePatcher.java
@@ -9,27 +9,26 @@
* Encapsulates functionality of patching problems from the previous gradle integration releases.
*
* Thread-safe.
- *
+ *
* @author Denis Zhdanov
- * @since 3/19/12 3:48 PM
+ * @since 2012-03-19
*/
public class GradlePatcher {
+ @SuppressWarnings("MethodMayBeStatic")
+ public void patch(@Nonnull Project project) {
+ patchGradleHomeIfNecessary(project);
+ }
- @SuppressWarnings("MethodMayBeStatic")
- public void patch(@Nonnull Project project) {
- patchGradleHomeIfNecessary(project);
- }
+ private static void patchGradleHomeIfNecessary(@Nonnull Project project) {
+ // Old gradle integration didn't save gradle home at project-local settings (only default project has that information).
- private static void patchGradleHomeIfNecessary(@Nonnull Project project) {
- // Old gradle integration didn't save gradle home at project-local settings (only default project has that information).
-
- final Project defaultProject = ProjectManager.getInstance().getDefaultProject();
- if (defaultProject.equals(project)) {
- return;
- }
+ final Project defaultProject = ProjectManager.getInstance().getDefaultProject();
+ if (defaultProject.equals(project)) {
+ return;
+ }
- // Propagate gradle settings from the current project to the default project if necessary.
- // TODO den implement
+ // Propagate gradle settings from the current project to the default project if necessary.
+ // TODO den implement
// final GradleSettings defaultProjectSettings = GradleSettings.getInstance(defaultProject);
// final GradleSettings currentProjectSettings = GradleSettings.getInstance(project);
// String projectGradleHome = currentProjectSettings.getGradleHome();
@@ -43,5 +42,5 @@ private static void patchGradleHomeIfNecessary(@Nonnull Project project) {
// if (autodetectedGradleHome == null || !FileUtil.filesEqual(autodetectedGradleHome, new File(projectGradleHome))) {
// GradleSettings.applyGradleHome(projectGradleHome, defaultProject);
// }
- }
+ }
}
diff --git a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradlePositionManager.java b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradlePositionManager.java
index c5bae71..471bbb5 100644
--- a/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradlePositionManager.java
+++ b/plugin/src/main/java/org/jetbrains/plugins/gradle/config/GradlePositionManager.java
@@ -15,6 +15,7 @@
*/
package org.jetbrains.plugins.gradle.config;
+import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.component.ExtensionImpl;
import consulo.application.util.*;
import consulo.externalSystem.util.ExternalSystemApiUtil;
@@ -57,139 +58,159 @@
*/
@ExtensionImpl
public class GradlePositionManager extends ScriptPositionManagerHelper {
+ private static final Logger LOG = Logger.getInstance(GradlePositionManager.class);
- private static final Logger LOG = Logger.getInstance(GradlePositionManager.class);
+ private static final Pattern GRADLE_CLASS_PATTERN = Pattern.compile(".*_gradle_.*");
+ private static final String SCRIPT_CLOSURE_PREFIX = "build_";
+ private static final Key> GRADLE_CLASS_LOADER = Key.create("GRADLE_CLASS_LOADER");
+ private static final Key>> GRADLE_CLASS_NAME = Key.create("GRADLE_CLASS_NAME");
- private static final Pattern GRADLE_CLASS_PATTERN = Pattern.compile(".*_gradle_.*");
- private static final String SCRIPT_CLOSURE_PREFIX = "build_";
- private static final Key> GRADLE_CLASS_LOADER = Key.create("GRADLE_CLASS_LOADER");
- private static final Key>> GRADLE_CLASS_NAME = Key.create("GRADLE_CLASS_NAME");
+ private final GradleInstallationManager myLibraryManager;
- private final GradleInstallationManager myLibraryManager;
+ @Inject
+ public GradlePositionManager(@Nonnull GradleInstallationManager manager) {
+ myLibraryManager = manager;
+ }
- @Inject
- public GradlePositionManager(@Nonnull GradleInstallationManager manager) {
- myLibraryManager = manager;
- }
+ @Override
+ public boolean isAppropriateRuntimeName(@Nonnull final String runtimeName) {
+ return runtimeName.startsWith(SCRIPT_CLOSURE_PREFIX) || GRADLE_CLASS_PATTERN.matcher(runtimeName).matches();
+ }
- public boolean isAppropriateRuntimeName(@Nonnull final String runtimeName) {
- return runtimeName.startsWith(SCRIPT_CLOSURE_PREFIX) || GRADLE_CLASS_PATTERN.matcher(runtimeName).matches();
- }
+ @Override
+ public boolean isAppropriateScriptFile(@Nonnull final GroovyFile scriptFile) {
+ return GroovyScriptUtil.isSpecificScriptFile(scriptFile, GradleScriptType.INSTANCE);
+ }
- public boolean isAppropriateScriptFile(@Nonnull final GroovyFile scriptFile) {
- return GroovyScriptUtil.isSpecificScriptFile((GroovyFile)scriptFile, GradleScriptType.INSTANCE);
- }
+ @Nonnull
+ @Override
+ @RequiredReadAction
+ public String getRuntimeScriptName(GroovyFile groovyFile) {
+ VirtualFile virtualFile = groovyFile.getVirtualFile();
+ if (virtualFile == null) {
+ return "";
+ }
- @Nonnull
- public String getRuntimeScriptName(GroovyFile groovyFile) {
- VirtualFile virtualFile = groovyFile.getVirtualFile();
- if (virtualFile == null) return "";
+ final Module module = ModuleUtilCore.findModuleForPsiElement(groovyFile);
+ if (module == null) {
+ return "";
+ }
- final Module module = ModuleUtilCore.findModuleForPsiElement(groovyFile);
- if (module == null) {
- return "";
+ final File scriptFile = VfsUtilCore.virtualToIoFile(virtualFile);
+ final String className = CachedValuesManager.getManager(module.getProject())
+ .getCachedValue(module, GRADLE_CLASS_NAME, new ScriptSourceMapCalculator(module), false).get(scriptFile);
+ return className == null ? "" : className;
}
- final File scriptFile = VfsUtilCore.virtualToIoFile(virtualFile);
- final String className = CachedValuesManager.getManager(module.getProject())
- .getCachedValue(module, GRADLE_CLASS_NAME, new ScriptSourceMapCalculator(module), false).get(scriptFile);
- return className == null ? "" : className;
- }
-
- public PsiFile getExtraScriptIfNotFound(ReferenceType refType, @Nonnull String runtimeName, Project project, GlobalSearchScope scope) {
- String sourceFilePath = getScriptForClassName(refType);
- if (sourceFilePath == null) return null;
-
- VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(sourceFilePath));
- if (virtualFile == null) return null;
-
- return PsiManager.getInstance(project).findFile(virtualFile);
- }
-
- @Nullable
- private static String getScriptForClassName(@Nonnull ReferenceType refType) {
- try {
- final List data = refType.sourcePaths(null);
- if (!data.isEmpty()) {
- return data.get(0);
- }
- }
- catch (AbsentInformationException ignored) {
- }
- return null;
- }
-
- @Nullable
- private ClassLoader getGradleClassLoader(@Nonnull final Module module) {
- final Project project = module.getProject();
- return CachedValuesManager.getManager(project).getCachedValue(module, GRADLE_CLASS_LOADER, new CachedValueProvider() {
- public Result compute() {
- return Result.create(createGradleClassLoader(module), ProjectRootManager.getInstance(project));
+ @Override
+ @RequiredReadAction
+ public PsiFile getExtraScriptIfNotFound(
+ @Nonnull ReferenceType refType,
+ @Nonnull String runtimeName,
+ @Nonnull Project project,
+ @Nonnull GlobalSearchScope scope
+ ) {
+ String sourceFilePath = getScriptForClassName(refType);
+ if (sourceFilePath == null) {
+ return null;
}
- }, false);
- }
-
- @Nullable
- private ClassLoader createGradleClassLoader(@Nonnull Module module) {
- String rootProjectPath = ExternalSystemApiUtil.getExtensionSystemOption(module, ExternalSystemConstants.ROOT_PROJECT_PATH_KEY);
- if (StringUtil.isEmpty(rootProjectPath)) {
- return null;
- }
- final VirtualFile sdkHome = myLibraryManager.getGradleHome(module, module.getProject(), rootProjectPath);
- if (sdkHome == null) {
- return null;
- }
-
- List urls = new ArrayList();
- final VirtualFile libDir = sdkHome.findChild("lib");
- assert libDir != null;
- for (final VirtualFile child : libDir.getChildren()) {
- if ("jar".equals(child.getExtension())) {
- urls.add(VfsUtil.convertToURL(child.getUrl()));
- }
- }
- return UrlClassLoader.build().urls(urls).get();
- }
+ VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(sourceFilePath));
+ if (virtualFile == null) {
+ return null;
+ }
- private class ScriptSourceMapCalculator implements CachedValueProvider