use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateModuleLibraryFromFilesTest method testTwoJars.
public void testTwoJars() {
List<Library> libraries = createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES), new OrderRoot(getAsmJar(), OrderRootType.CLASSES));
assertEquals(2, libraries.size());
assertNull(libraries.get(0).getName());
assertSameElements(libraries.get(0).getFiles(OrderRootType.CLASSES), getJDomJar());
assertNull(libraries.get(1).getName());
assertSameElements(libraries.get(1).getFiles(OrderRootType.CLASSES), getAsmJar());
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateModuleLibraryFromFilesTest method testJarWithSourcesInside.
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());
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateModuleLibraryFromFilesTest method testSingleJar.
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));
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class CreateModuleLibraryFromFilesTest method testTwoJarWithSourcesInside.
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());
}
use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.
the class RootDetectionUtil method detectRoots.
@NotNull
public static List<OrderRoot> detectRoots(@NotNull final Collection<VirtualFile> rootCandidates, @Nullable Component parentComponent, @Nullable Project project, @NotNull final LibraryRootsDetector detector, @NotNull OrderRootType[] rootTypesAllowedToBeSelectedByUserIfNothingIsDetected) {
final List<OrderRoot> result = new ArrayList<>();
final List<SuggestedChildRootInfo> suggestedRoots = new ArrayList<>();
new Task.Modal(project, "Scanning for Roots", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
for (VirtualFile rootCandidate : rootCandidates) {
final Collection<DetectedLibraryRoot> roots = detector.detectRoots(rootCandidate, indicator);
if (!roots.isEmpty() && allRootsHaveOneTypeAndEqualToOrAreDirectParentOf(roots, rootCandidate)) {
for (DetectedLibraryRoot root : roots) {
final LibraryRootType libraryRootType = root.getTypes().get(0);
result.add(new OrderRoot(root.getFile(), libraryRootType.getType(), libraryRootType.isJarDirectory()));
}
} else {
for (DetectedLibraryRoot root : roots) {
final HashMap<LibraryRootType, String> names = new HashMap<>();
for (LibraryRootType type : root.getTypes()) {
final String typeName = detector.getRootTypeName(type);
LOG.assertTrue(typeName != null, "Unexpected root type " + type.getType().name() + (type.isJarDirectory() ? " (JAR directory)" : "") + ", detectors: " + detector);
names.put(type, typeName);
}
suggestedRoots.add(new SuggestedChildRootInfo(rootCandidate, root, names));
}
}
}
} catch (ProcessCanceledException ignored) {
}
}
}.queue();
if (!suggestedRoots.isEmpty()) {
final DetectedRootsChooserDialog dialog = parentComponent != null ? new DetectedRootsChooserDialog(parentComponent, suggestedRoots) : new DetectedRootsChooserDialog(project, suggestedRoots);
if (!dialog.showAndGet()) {
return Collections.emptyList();
}
for (SuggestedChildRootInfo rootInfo : dialog.getChosenRoots()) {
final LibraryRootType selectedRootType = rootInfo.getSelectedRootType();
result.add(new OrderRoot(rootInfo.getDetectedRoot().getFile(), selectedRootType.getType(), selectedRootType.isJarDirectory()));
}
}
if (result.isEmpty() && rootTypesAllowedToBeSelectedByUserIfNothingIsDetected.length > 0) {
Map<String, Pair<OrderRootType, Boolean>> types = new HashMap<>();
for (OrderRootType type : rootTypesAllowedToBeSelectedByUserIfNothingIsDetected) {
for (boolean isJarDirectory : new boolean[] { false, true }) {
final String typeName = detector.getRootTypeName(new LibraryRootType(type, isJarDirectory));
if (typeName != null) {
types.put(StringUtil.capitalizeWords(typeName, true), Pair.create(type, isJarDirectory));
}
}
}
LOG.assertTrue(!types.isEmpty(), "No allowed root types found for " + detector);
List<String> names = new ArrayList<>(types.keySet());
if (names.size() == 1) {
String title = "Attach Roots";
String typeName = names.get(0);
String message = ApplicationNamesInfo.getInstance().getProductName() + " cannot determine what kind of files the chosen items contain. " + "Do you want to attach them as '" + typeName + "'?";
int answer = parentComponent != null ? Messages.showYesNoDialog(parentComponent, message, title, null) : Messages.showYesNoDialog(project, message, title, null);
if (answer == Messages.YES) {
Pair<OrderRootType, Boolean> pair = types.get(typeName);
for (VirtualFile candidate : rootCandidates) {
result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond()));
}
}
} else {
String title = "Choose Categories of Selected Files";
String description = XmlStringUtil.wrapInHtml(ApplicationNamesInfo.getInstance().getProductName() + " cannot determine what kind of files the chosen items contain.<br>" + "Choose the appropriate categories from the list.");
ChooseElementsDialog<String> dialog;
if (parentComponent != null) {
dialog = new ChooseRootTypeElementsDialog(parentComponent, names, title, description);
} else {
dialog = new ChooseRootTypeElementsDialog(project, names, title, description);
}
for (String rootType : dialog.showAndGetResult()) {
final Pair<OrderRootType, Boolean> pair = types.get(rootType);
for (VirtualFile candidate : rootCandidates) {
result.add(new OrderRoot(candidate, pair.getFirst(), pair.getSecond()));
}
}
}
}
return result;
}
Aggregations