mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJP-670 - plugin for dependency search - fix maven tests
GitOrigin-RevId: c4e8cb15f52194b2f2f36fc94a038336c1a03eaf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
123a936ff1
commit
48b120eb62
+2
-2
@@ -45,8 +45,8 @@ class MavenArtifactIdCompletionContributor : MavenCoordinateCompletionContributo
|
||||
val set = HashSet<String>()
|
||||
while (promise.state == Promise.State.PENDING || !cld.isEmpty()) {
|
||||
ProgressManager.checkCanceled()
|
||||
val item = cld.poll() as? MavenRepositoryArtifactInfo ?: continue
|
||||
if (item != null && set.add(item.artifactId)) {
|
||||
val item = cld.poll()
|
||||
if (item is MavenRepositoryArtifactInfo && set.add(item.artifactId)) {
|
||||
result
|
||||
.addElement(
|
||||
MavenDependencyCompletionUtil.lookupElement(item, item.artifactId).withInsertHandler(
|
||||
|
||||
+20
-1
@@ -2,13 +2,18 @@
|
||||
package org.jetbrains.idea.maven.dom.model.completion
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionParameters
|
||||
import com.intellij.codeInsight.completion.CompletionResultSet
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import org.jetbrains.concurrency.Promise
|
||||
import org.jetbrains.idea.maven.dom.converters.MavenDependencyCompletionUtil
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomShortArtifactCoordinates
|
||||
import org.jetbrains.idea.maven.dom.model.completion.insert.MavenDependencyInsertionHandler
|
||||
import org.jetbrains.idea.maven.indices.IndicesBundle
|
||||
import org.jetbrains.idea.maven.onlinecompletion.model.MavenRepositoryArtifactInfo
|
||||
import org.jetbrains.idea.reposearch.DependencySearchService
|
||||
import org.jetbrains.idea.reposearch.RepositoryArtifactData
|
||||
import java.util.concurrent.ConcurrentLinkedDeque
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Predicate
|
||||
|
||||
@@ -32,5 +37,19 @@ class MavenGroupIdCompletionContributor : MavenCoordinateCompletionContributor("
|
||||
Predicate { it is MavenRepositoryArtifactInfo && (artifactId.isEmpty() || artifactId == it.artifactId) }))
|
||||
}
|
||||
|
||||
|
||||
override fun fillResults(result: CompletionResultSet,
|
||||
coordinates: MavenDomShortArtifactCoordinates,
|
||||
cld: ConcurrentLinkedDeque<RepositoryArtifactData>,
|
||||
promise: Promise<Int>) {
|
||||
val set = HashSet<String>()
|
||||
while (promise.state == Promise.State.PENDING || !cld.isEmpty()) {
|
||||
ProgressManager.checkCanceled()
|
||||
val item = cld.poll()
|
||||
if (item is MavenRepositoryArtifactInfo && set.add(item.groupId)) {
|
||||
result
|
||||
.addElement(
|
||||
MavenDependencyCompletionUtil.lookupElement(item, item.groupId).withInsertHandler(MavenDependencyInsertionHandler.INSTANCE))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+40
-34
@@ -56,7 +56,7 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariantsInclude(myProjectPom, "junit:junit:3.8.1", "jmock:jmock:1.0.0", "test:project:1");
|
||||
assertCompletionVariantsInclude(myProjectPom, RENDERING_TEXT, "junit", "jmock", "test");
|
||||
}
|
||||
|
||||
public void testArtifactIdCompletion() {
|
||||
@@ -71,7 +71,7 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariants(myProjectPom, "junit:junit:3.8.1");
|
||||
assertCompletionVariants(myProjectPom, RENDERING_TEXT, "junit");
|
||||
}
|
||||
|
||||
public void testDoNotCompleteArtifactIdOnUnknownGroup() {
|
||||
@@ -144,17 +144,18 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
importProject();
|
||||
|
||||
createModulePom("m2", "<groupId>project-group</groupId>" +
|
||||
"<artifactId>m2</artifactId>" +
|
||||
"<version>2</version>" +
|
||||
"<artifactId>m2</artifactId>" +
|
||||
"<version>2</version>" +
|
||||
|
||||
"<dependencies>" +
|
||||
" <dependency>" +
|
||||
" <groupId>project-group</groupId>" +
|
||||
" <artifactId><caret></artifactId>" +
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
"<dependencies>" +
|
||||
" <dependency>" +
|
||||
" <groupId>project-group</groupId>" +
|
||||
" <artifactId><caret></artifactId>" +
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariants(m, "project-group:project:1", "project-group:m1:1", "project-group:m2:2");
|
||||
assertCompletionVariants(m, LOOKUP_STRING, "project-group:project:1", "project-group:m1:1", "project-group:m2:2");
|
||||
assertCompletionVariants(m, RENDERING_TEXT, "project", "m1", "m2");
|
||||
}
|
||||
|
||||
public void testResolvingPropertiesForLocalProjectsInCompletion() {
|
||||
@@ -251,7 +252,8 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariants(m1, "test:project:1", "test:m1:1", "test:m2:1");
|
||||
assertCompletionVariants(m1, LOOKUP_STRING, "test:project:1", "test:m1:1", "test:m2:1");
|
||||
assertCompletionVariants(m1, RENDERING_TEXT, "project", "m1", "m2");
|
||||
|
||||
createModulePom("m1", "<groupId>test</groupId>" +
|
||||
"<artifactId>m1</artifactId>" +
|
||||
@@ -274,7 +276,8 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariants(m1, "test:project:1", "test:m1:1", "test:m2_new:1");
|
||||
assertCompletionVariants(m1, LOOKUP_STRING, "test:project:1", "test:m1:1", "test:m2_new:1");
|
||||
assertCompletionVariants(m1, RENDERING_TEXT, "project", "m1", "m2_new");
|
||||
}
|
||||
|
||||
public void testChangingExistingProjectsWithArtifactIdsRemoval() {
|
||||
@@ -296,7 +299,7 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
|
||||
importProjectsWithErrors(myProjectPom, m);
|
||||
|
||||
assertCompletionVariants(myProjectPom, "project-group:m1:1");
|
||||
assertCompletionVariants(myProjectPom, RENDERING_TEXT, "m1");
|
||||
|
||||
createModulePom("m1", "");
|
||||
importProjectsWithErrors(myProjectPom, m);
|
||||
@@ -322,19 +325,20 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
"<version>1</version>");
|
||||
|
||||
configureProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
|
||||
"<dependencies>" +
|
||||
" <dependency>" +
|
||||
" <groupId>project-group</groupId>" +
|
||||
" <artifactId><caret></artifactId>" +
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
"<dependencies>" +
|
||||
" <dependency>" +
|
||||
" <groupId>project-group</groupId>" +
|
||||
" <artifactId><caret></artifactId>" +
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
importProjectsWithErrors(myProjectPom, m);
|
||||
|
||||
assertCompletionVariantsInclude(myProjectPom, "project-group:m1:1");
|
||||
assertCompletionVariantsInclude(myProjectPom, RENDERING_TEXT, "m1");
|
||||
assertCompletionVariantsInclude(myProjectPom, LOOKUP_STRING, "project-group:m1:1");
|
||||
|
||||
WriteAction.runAndWait(() -> m.delete(null));
|
||||
|
||||
@@ -661,7 +665,7 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariants(myProjectPom, "junit-4.0.jar");
|
||||
assertCompletionVariants(myProjectPom, RENDERING_TEXT, "junit-4.0.jar");
|
||||
}
|
||||
|
||||
public void testResolvingSystemScopeDependenciesFromSystemPath() throws Throwable {
|
||||
@@ -747,16 +751,17 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
|
||||
public void testTypeCompletion() {
|
||||
configureProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
|
||||
"<dependencies>" +
|
||||
" <dependency>" +
|
||||
" <type><caret></type>" +
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
"<dependencies>" +
|
||||
" <dependency>" +
|
||||
" <type><caret></type>" +
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariants(myProjectPom, "jar", "test-jar", "pom", "ear", "ejb", "ejb-client", "war", "bundle", "jboss-har", "jboss-sar", "maven-plugin");
|
||||
assertCompletionVariants(myProjectPom, RENDERING_TEXT, "jar", "test-jar", "pom", "ear", "ejb", "ejb-client", "war", "bundle",
|
||||
"jboss-har", "jboss-sar", "maven-plugin");
|
||||
}
|
||||
|
||||
public void testDoNotHighlightUnknownType() {
|
||||
@@ -787,7 +792,7 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariants(myProjectPom, "compile", "provided", "runtime", "test", "system");
|
||||
assertCompletionVariants(myProjectPom, RENDERING_TEXT, "compile", "provided", "runtime", "test", "system");
|
||||
}
|
||||
|
||||
public void testDoNotHighlightUnknownScopes() {
|
||||
@@ -1097,9 +1102,10 @@ public class MavenDependencyCompletionAndResolutionTest extends MavenDomWithIndi
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
assertCompletionVariants(myProjectPom, "jmock:jmock:1.0.0");
|
||||
assertCompletionVariants(myProjectPom, RENDERING_TEXT, "jmock");
|
||||
}
|
||||
|
||||
|
||||
public void testDoNotHighlightUnknownExclusions() {
|
||||
createProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.codeInsight.documentation.DocumentationManager;
|
||||
import com.intellij.codeInsight.highlighting.HighlightUsagesHandler;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementPresentation;
|
||||
import com.intellij.find.findUsages.PsiElement2UsageTargetAdapter;
|
||||
import com.intellij.lang.documentation.DocumentationProvider;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
@@ -62,12 +63,21 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class MavenDomTestCase extends MavenImportingTestCase {
|
||||
protected CodeInsightTestFixture myFixture;
|
||||
private final Map<VirtualFile, Long> myConfigTimestamps = new THashMap<>();
|
||||
private boolean myOriginalAutoCompletion;
|
||||
|
||||
protected static final Function<LookupElement, String> RENDERING_TEXT = li -> {
|
||||
LookupElementPresentation presentation = new LookupElementPresentation();
|
||||
li.renderElement(presentation);
|
||||
return presentation.getItemText();
|
||||
};
|
||||
|
||||
protected static final Function<LookupElement, String> LOOKUP_STRING = LookupElement::getLookupString;
|
||||
|
||||
@Override
|
||||
protected void setUpFixtures() throws Exception {
|
||||
myTestFixture = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName()).getFixture();
|
||||
@@ -255,12 +265,23 @@ public abstract class MavenDomTestCase extends MavenImportingTestCase {
|
||||
}
|
||||
|
||||
protected void assertCompletionVariants(VirtualFile f, String... expected) {
|
||||
List<String> actual = getCompletionVariants(f);
|
||||
assertCompletionVariants(f, LOOKUP_STRING, expected);
|
||||
}
|
||||
|
||||
protected void assertCompletionVariants(VirtualFile f, Function<LookupElement, String> lookupElementStringFunction, String... expected) {
|
||||
List<String> actual = getCompletionVariants(f, lookupElementStringFunction);
|
||||
assertUnorderedElementsAreEqual(actual, expected);
|
||||
}
|
||||
|
||||
protected void assertCompletionVariantsInclude(VirtualFile f, String... expected) {
|
||||
assertContain(getCompletionVariants(f), expected);
|
||||
protected void assertCompletionVariantsInclude(VirtualFile f,
|
||||
String... expected) {
|
||||
assertCompletionVariantsInclude(f, LOOKUP_STRING, expected);
|
||||
}
|
||||
|
||||
protected void assertCompletionVariantsInclude(VirtualFile f,
|
||||
Function<LookupElement, String> lookupElementStringFunction,
|
||||
String... expected) {
|
||||
assertContain(getCompletionVariants(f, lookupElementStringFunction), expected);
|
||||
}
|
||||
|
||||
protected void assertCompletionVariantsDoNotInclude(VirtualFile f, String... expected) {
|
||||
@@ -268,12 +289,16 @@ public abstract class MavenDomTestCase extends MavenImportingTestCase {
|
||||
}
|
||||
|
||||
protected List<String> getCompletionVariants(VirtualFile f) {
|
||||
return getCompletionVariants(f, li -> li.getLookupString());
|
||||
}
|
||||
|
||||
protected List<String> getCompletionVariants(VirtualFile f, Function<LookupElement, String> lookupElementStringFunction) {
|
||||
configTest(f);
|
||||
LookupElement[] variants = myFixture.completeBasic();
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
for (LookupElement each: variants) {
|
||||
result.add(each.getLookupString());
|
||||
for (LookupElement each : variants) {
|
||||
result.add(lookupElementStringFunction.apply(each));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user