Search in sources :

Example 6 with OrderRoot

use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.

the class CreateModuleLibraryFromFilesTest method testTwoJarAndSources.

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

Example 7 with OrderRoot

use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.

the class CreateModuleLibraryChooser method chooseElements.

@Override
@NotNull
public List<Library> chooseElements() {
    final FileChooserDescriptor chooserDescriptor;
    final List<Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor>> descriptors = new ArrayList<>();
    for (LibraryRootsComponentDescriptor componentDescriptor : myLibraryTypes.keySet()) {
        descriptors.add(Pair.create(componentDescriptor, componentDescriptor.createAttachFilesChooserDescriptor(null)));
    }
    if (descriptors.size() == 1) {
        chooserDescriptor = descriptors.get(0).getSecond();
    } else {
        chooserDescriptor = new FileChooserDescriptor(true, true, true, false, true, false) {

            @Override
            public boolean isFileSelectable(VirtualFile file) {
                for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
                    if (pair.getSecond().isFileSelectable(file)) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
                for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
                    if (pair.getSecond().isFileVisible(file, showHiddenFiles)) {
                        return true;
                    }
                }
                return false;
            }
        };
    }
    chooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, myModule);
    final Project project = myModule.getProject();
    final VirtualFile[] files = FileChooser.chooseFiles(chooserDescriptor, myParentComponent, project, project.getBaseDir());
    if (files.length == 0)
        return Collections.emptyList();
    List<LibraryRootsComponentDescriptor> suitableDescriptors = new ArrayList<>();
    for (Pair<LibraryRootsComponentDescriptor, FileChooserDescriptor> pair : descriptors) {
        if (acceptAll(pair.getSecond(), files)) {
            suitableDescriptors.add(pair.getFirst());
        }
    }
    final LibraryRootsComponentDescriptor rootsComponentDescriptor;
    LibraryType libraryType = null;
    if (suitableDescriptors.size() == 1) {
        rootsComponentDescriptor = suitableDescriptors.get(0);
        libraryType = myLibraryTypes.get(rootsComponentDescriptor);
    } else {
        rootsComponentDescriptor = myDefaultDescriptor;
    }
    List<OrderRoot> chosenRoots = RootDetectionUtil.detectRoots(Arrays.asList(files), myParentComponent, project, rootsComponentDescriptor);
    return createLibrariesFromRoots(chosenRoots, libraryType, myModuleLibrariesModel, myDefaultPropertiesFactory);
}
Also used : DefaultLibraryRootsComponentDescriptor(com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor) LibraryRootsComponentDescriptor(com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Project(com.intellij.openapi.project.Project) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with OrderRoot

use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.

the class CreateModuleLibraryChooser method createLibraryFromRoots.

private static Library createLibraryFromRoots(@NotNull List<OrderRoot> roots, @Nullable final LibraryType libraryType, @NotNull LibraryTable.ModifiableModel moduleLibrariesModel, @Nullable Function<LibraryType, LibraryProperties> defaultPropertiesFactory) {
    final PersistentLibraryKind kind = libraryType == null ? null : libraryType.getKind();
    final Library library = moduleLibrariesModel.createLibrary(null, kind);
    final LibraryEx.ModifiableModelEx libModel = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
    if (defaultPropertiesFactory != null) {
        libModel.setProperties(defaultPropertiesFactory.fun(libraryType));
    }
    for (OrderRoot root : roots) {
        if (root.isJarDirectory()) {
            libModel.addJarDirectory(root.getFile(), false, root.getType());
        } else {
            libModel.addRoot(root.getFile(), root.getType());
        }
    }
    libModel.commit();
    return library;
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot)

Example 9 with OrderRoot

use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project intellij-community by JetBrains.

the class LibrarySourceRootDetectorUtil method scanAndSelectDetectedJavaSourceRoots.

/**
   * This method takes a candidates for the project root, then scans the candidates and
   * if multiple candidates or non root source directories are found within some
   * directories, it shows a dialog that allows selecting or deselecting them.
   * @param parent a parent parent or project
   * @param rootCandidates a candidates for roots
   * @return a array of source folders or empty array if non was selected or dialog was canceled.
   */
public static VirtualFile[] scanAndSelectDetectedJavaSourceRoots(Component parentComponent, final VirtualFile[] rootCandidates) {
    final List<OrderRoot> orderRoots = RootDetectionUtil.detectRoots(Arrays.asList(rootCandidates), parentComponent, null, new LibraryRootsDetectorImpl(Arrays.asList(Extensions.getExtensions(JAVA_SOURCE_ROOT_DETECTOR))), new OrderRootType[] { OrderRootType.SOURCES });
    final List<VirtualFile> result = new ArrayList<>();
    for (OrderRoot root : orderRoots) {
        result.add(root.getFile());
    }
    return VfsUtil.toVirtualFileArray(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryRootsDetectorImpl(com.intellij.openapi.roots.libraries.ui.impl.LibraryRootsDetectorImpl) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot)

Example 10 with OrderRoot

use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project android by JetBrains.

the class CreateLibraryFromFilesAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = getEventProject(e);
    if (project == null)
        return;
    if (!AndroidProjectInfo.getInstance(project).requiresAndroidModel()) {
        myDelegate.actionPerformed(e);
        return;
    }
    final List<VirtualFile> jars = getRoots(e);
    if (jars.isEmpty()) {
        return;
    }
    final List<OrderRoot> roots = RootDetectionUtil.detectRoots(jars, null, project, new DefaultLibraryRootsComponentDescriptor());
    new CreateGradleLibraryFromFilesDialog(project, roots).show();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DefaultLibraryRootsComponentDescriptor(com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot)

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