Search in sources :

Example 16 with OrderRoot

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());
}
Also used : OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library)

Example 17 with OrderRoot

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());
}
Also used : OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library)

Example 18 with OrderRoot

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));
}
Also used : OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library)

Example 19 with OrderRoot

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());
}
Also used : OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library)

Example 20 with OrderRoot

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) LibraryRootType(com.intellij.openapi.roots.libraries.LibraryRootType) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Pair(com.intellij.openapi.util.Pair) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) DetectedLibraryRoot(com.intellij.openapi.roots.libraries.ui.DetectedLibraryRoot) OrderRootType(com.intellij.openapi.roots.OrderRootType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)27 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 Library (com.intellij.openapi.roots.libraries.Library)8 NotNull (org.jetbrains.annotations.NotNull)7 DefaultLibraryRootsComponentDescriptor (com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor)5 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)4 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 OrderRootType (com.intellij.openapi.roots.OrderRootType)3 Pair (com.intellij.openapi.util.Pair)3 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)3 Nullable (org.jetbrains.annotations.Nullable)3 AccessToken (com.intellij.openapi.application.AccessToken)2 Module (com.intellij.openapi.module.Module)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 OrderEntry (com.intellij.openapi.roots.OrderEntry)2 ModuleLibraryOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)2 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)2