mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
[maven] IDEA-195620 Importing a maven project with .flattened-pom.xml files results in duplicate modules
Adding grouping by parent - for multi-module maven project recursion import GitOrigin-RevId: b833b75f2f3aef6d0ec02261fffbff3692bf2ca2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c50a102e50
commit
5ad3bc44a0
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.idea.maven.utils;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.InvalidVirtualFileAccessException;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -10,12 +11,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.stream.Collectors.*;
|
||||
|
||||
public final class FileFinder {
|
||||
public static List<VirtualFile> findPomFiles(VirtualFile[] roots,
|
||||
boolean lookForNested,
|
||||
@NotNull MavenProgressIndicator indicator) throws MavenProcessCanceledException {
|
||||
ArrayList<VirtualFile> result = new ArrayList<>();
|
||||
List<Pair<String, VirtualFile>> result = new ArrayList<>();
|
||||
// TODO locate pom files using maven embedder?
|
||||
for (VirtualFile f : roots) {
|
||||
VfsUtilCore.visitChildrenRecursively(f, new VirtualFileVisitor<Void>() {
|
||||
@@ -35,7 +39,7 @@ public final class FileFinder {
|
||||
}
|
||||
else {
|
||||
if (MavenUtil.isPomFile(f)) {
|
||||
result.add(f);
|
||||
result.add(Pair.create(f.getParent().getCanonicalPath(), f));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +54,15 @@ public final class FileFinder {
|
||||
}
|
||||
}, MavenProcessCanceledException.class);
|
||||
}
|
||||
List<VirtualFile> originalPoms = ContainerUtil.filter(result, vf -> MavenUtil.isPomFileName(vf.getName()));
|
||||
return originalPoms.isEmpty() ? result : originalPoms;
|
||||
Map<String, List<VirtualFile>> pomFilesByParent = result.stream()
|
||||
.collect(groupingBy(p -> p.getFirst(), mapping(p -> p.getSecond(), toList())));
|
||||
return pomFilesByParent.entrySet().stream()
|
||||
.flatMap(pomsByParent -> getOriginalPoms(pomsByParent.getValue()).stream())
|
||||
.collect(toList());
|
||||
}
|
||||
|
||||
private static List<VirtualFile> getOriginalPoms(List<VirtualFile> pomFiles) {
|
||||
List<VirtualFile> originalPoms = ContainerUtil.filter(pomFiles, vf -> MavenUtil.isPomFileName(vf.getName()));
|
||||
return originalPoms.isEmpty() ? pomFiles : originalPoms;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,4 +44,17 @@ class FileFinderTest : MavenTestCase() {
|
||||
assertTrue(findPomFiles.size == 2)
|
||||
assertContainsElements(findPomFiles, pom1, pom2)
|
||||
}
|
||||
|
||||
fun `test find pom file - recursion poms`() {
|
||||
val mainPom = createProjectSubFile("pom.xml", pomContent)
|
||||
createProjectSubFile("pom-template.xml", pomContent)
|
||||
val mainPomA = createProjectSubFile("a/pom.xml", pomContent)
|
||||
createProjectSubFile("a/pom-template.xml", pomContent)
|
||||
val pomB1 = createProjectSubFile("b/pom-template.xml", pomContent)
|
||||
val pomB2 = createProjectSubFile("b/.flatten-pom.xml", pomContent)
|
||||
val root = mainPom.parent
|
||||
val findPomFiles = FileFinder.findPomFiles(Array(1) { root }, true, mavenProgressIndicator)
|
||||
assertTrue(findPomFiles.size == 4)
|
||||
assertContainsElements(findPomFiles, mainPom, mainPomA, pomB1, pomB2)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user