mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
create module library from files: create separate libraries for JARs which contains both *.class and *.java files (IDEA-154044)
This commit is contained in:
+10
-10
@@ -30,7 +30,6 @@ import com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -38,6 +37,10 @@ import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.intellij.util.ArrayUtil.contains;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
@@ -109,7 +112,7 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
|
||||
final List<OrderRoot> result = new ArrayList<OrderRoot>();
|
||||
final Library[] libraries = moduleLibrariesModel.getLibraries();
|
||||
for (OrderRoot root : roots) {
|
||||
if (!Arrays.stream(libraries).anyMatch(library -> ArrayUtil.contains(root.getFile(), library.getFiles(root.getType())))) {
|
||||
if (!Arrays.stream(libraries).anyMatch(library -> contains(root.getFile(), library.getFiles(root.getType())))) {
|
||||
result.add(root);
|
||||
}
|
||||
}
|
||||
@@ -194,14 +197,11 @@ public class CreateModuleLibraryChooser implements ClasspathElementChooser<Libra
|
||||
}
|
||||
|
||||
final List<Library> addedLibraries = new ArrayList<Library>();
|
||||
boolean onlyClasses = true;
|
||||
for (OrderRoot root : roots) {
|
||||
onlyClasses &= root.getType() == OrderRootType.CLASSES;
|
||||
}
|
||||
if (onlyClasses) {
|
||||
for (OrderRoot root : roots) {
|
||||
addedLibraries.add(createLibraryFromRoots(Collections.singletonList(root), libraryType, moduleLibrariesModel,
|
||||
defaultPropertiesFactory));
|
||||
Map<VirtualFile, List<OrderRoot>> byFile = roots.stream().collect(Collectors.groupingBy(OrderRoot::getFile));
|
||||
Predicate<List<OrderRoot>> containsClasses = it -> it.stream().anyMatch(root -> root.getType().equals(OrderRootType.CLASSES));
|
||||
if (byFile.values().stream().allMatch(containsClasses)) {
|
||||
for (List<OrderRoot> rootsForFile : byFile.values()) {
|
||||
addedLibraries.add(createLibraryFromRoots(rootsForFile, libraryType, moduleLibrariesModel, defaultPropertiesFactory));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+49
-4
@@ -42,14 +42,14 @@ public class CreateModuleLibraryFromFilesTest extends ModuleRootManagerTestCase
|
||||
myModifiableModel = myModifiableRootModel.getModuleLibraryTable().getModifiableModel();
|
||||
}
|
||||
|
||||
public void testSingleJar() throws Exception {
|
||||
public void testSingleJar() {
|
||||
Library library = assertOneElement(createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES)));
|
||||
assertNull(library.getName());
|
||||
assertSameElements(library.getFiles(OrderRootType.CLASSES), getJDomJar());
|
||||
assertEmpty(library.getFiles(OrderRootType.SOURCES));
|
||||
}
|
||||
|
||||
public void testTwoJars() throws Exception {
|
||||
public void testTwoJars() {
|
||||
List<Library> libraries = createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES),
|
||||
new OrderRoot(getAsmJar(), OrderRootType.CLASSES));
|
||||
assertEquals(2, libraries.size());
|
||||
@@ -59,6 +59,46 @@ public class CreateModuleLibraryFromFilesTest extends ModuleRootManagerTestCase
|
||||
assertSameElements(libraries.get(1).getFiles(OrderRootType.CLASSES), getAsmJar());
|
||||
}
|
||||
|
||||
public void testJarAndSources() {
|
||||
Library library = assertOneElement(createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES),
|
||||
new OrderRoot(getJDomSources(), OrderRootType.SOURCES)));
|
||||
assertNull(library.getName());
|
||||
assertSameElements(library.getFiles(OrderRootType.CLASSES), getJDomJar());
|
||||
assertSameElements(library.getFiles(OrderRootType.SOURCES), getJDomSources());
|
||||
}
|
||||
|
||||
public void testJarWithSourcesInside() {
|
||||
Library library = assertOneElement(createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES),
|
||||
new OrderRoot(getJDomJar(), OrderRootType.SOURCES)));
|
||||
assertNull(library.getName());
|
||||
assertSameElements(library.getFiles(OrderRootType.CLASSES), getJDomJar());
|
||||
assertSameElements(library.getFiles(OrderRootType.SOURCES), getJDomJar());
|
||||
}
|
||||
|
||||
public void testTwoJarAndSources() {
|
||||
List<Library> libraries = createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES),
|
||||
new OrderRoot(getAsmJar(), OrderRootType.CLASSES),
|
||||
new OrderRoot(getJDomSources(), OrderRootType.SOURCES));
|
||||
Library library = assertOneElement(libraries);
|
||||
assertNull(library.getName());
|
||||
assertSameElements(library.getFiles(OrderRootType.CLASSES), getJDomJar(), getAsmJar());
|
||||
assertSameElements(library.getFiles(OrderRootType.SOURCES), getJDomSources());
|
||||
}
|
||||
|
||||
public void testTwoJarWithSourcesInside() {
|
||||
List<Library> libraries = createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES),
|
||||
new OrderRoot(getAsmJar(), OrderRootType.CLASSES),
|
||||
new OrderRoot(getJDomJar(), OrderRootType.SOURCES),
|
||||
new OrderRoot(getAsmJar(), OrderRootType.SOURCES));
|
||||
assertEquals(2, libraries.size());
|
||||
assertNull(libraries.get(0).getName());
|
||||
assertSameElements(libraries.get(0).getFiles(OrderRootType.CLASSES), getJDomJar());
|
||||
assertSameElements(libraries.get(0).getFiles(OrderRootType.SOURCES), getJDomJar());
|
||||
assertNull(libraries.get(1).getName());
|
||||
assertSameElements(libraries.get(1).getFiles(OrderRootType.CLASSES), getAsmJar());
|
||||
assertSameElements(libraries.get(1).getFiles(OrderRootType.SOURCES), getAsmJar());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<Library> createLibraries(OrderRoot... roots) {
|
||||
return CreateModuleLibraryChooser.createLibrariesFromRoots(Arrays.asList(roots), myModifiableModel);
|
||||
@@ -66,7 +106,12 @@ public class CreateModuleLibraryFromFilesTest extends ModuleRootManagerTestCase
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myModifiableRootModel.dispose();
|
||||
super.tearDown();
|
||||
try {
|
||||
myModifiableRootModel.dispose();
|
||||
}
|
||||
finally {
|
||||
//noinspection ThrowFromFinallyBlock
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user