Search in sources :

Example 11 with OrderRoot

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

the class AndroidSdks method setUpSdk.

public void setUpSdk(@NotNull Sdk androidSdk, @NotNull SdkModificator androidSdkModificator, @NotNull IAndroidTarget target, @NotNull String sdkName, @NotNull Collection<Sdk> allSdks, @Nullable Sdk jdk, boolean addRoots) {
    AndroidSdkAdditionalData data = new AndroidSdkAdditionalData(androidSdk, jdk);
    data.setBuildTarget(target);
    String name = createUniqueSdkName(sdkName, allSdks);
    androidSdkModificator.setName(name);
    if (jdk != null) {
        androidSdkModificator.setVersionString(jdk.getVersionString());
    }
    androidSdkModificator.setSdkAdditionalData(data);
    if (addRoots) {
        List<OrderRoot> newRoots = getLibraryRootsForTarget(target, androidSdk, true);
        androidSdkModificator.removeAllRoots();
        for (OrderRoot orderRoot : newRoots) {
            androidSdkModificator.addRoot(orderRoot.getFile(), orderRoot.getType());
        }
        // TODO move this method to Jdks.
        attachJdkAnnotations(androidSdkModificator);
    }
    // Add sources at the end, otherwise if 'addRoots' is true, removing all existing roots will delete sources as well.
    // https://code.google.com/p/android/issues/detail?id=233221
    findAndSetPlatformSources(target, androidSdkModificator);
}
Also used : AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot)

Example 12 with OrderRoot

use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project azure-tools-for-java by Microsoft.

the class LibrariesConfigurationDialog method addLibrary.

private void addLibrary() {
    AddLibraryWizardModel model = new AddLibraryWizardModel(module);
    AddLibraryWizardDialog wizard = new AddLibraryWizardDialog(model);
    wizard.setTitle(message("addLibraryTitle"));
    wizard.show();
    if (wizard.isOK()) {
        AzureLibrary azureLibrary = model.getSelectedLibrary();
        final LibrariesContainer.LibraryLevel level = LibrariesContainer.LibraryLevel.MODULE;
        AccessToken token = WriteAction.start();
        try {
            final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
            for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
                if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                    PluginUtil.displayErrorDialog(message("error"), message("libraryExistsError"));
                    return;
                }
            }
            Library newLibrary = LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(azureLibrary.getName(), level, new ArrayList<OrderRoot>());
            if (model.isExported()) {
                for (OrderEntry orderEntry : modifiableModel.getOrderEntries()) {
                    if (orderEntry instanceof ModuleLibraryOrderEntryImpl && azureLibrary.getName().equals(((ModuleLibraryOrderEntryImpl) orderEntry).getLibraryName())) {
                        ((ModuleLibraryOrderEntryImpl) orderEntry).setExported(true);
                        break;
                    }
                }
            }
            Library.ModifiableModel newLibraryModel = newLibrary.getModifiableModel();
            // if there is separate resources folder
            if (azureLibrary.getLocation() != null) {
                File file = new File(String.format("%s%s%s", AzurePlugin.pluginFolder, File.separator, azureLibrary.getLocation()));
                AddLibraryUtility.addLibraryRoot(file, newLibraryModel);
            }
            // if some files already contained in plugin dependencies, take them from there - true for azure sdk library
            if (azureLibrary.getFiles().length > 0) {
                AddLibraryUtility.addLibraryFiles(new File(PluginHelper.getAzureLibLocation()), newLibraryModel, azureLibrary.getFiles());
            }
            newLibraryModel.commit();
            modifiableModel.commit();
            ((DefaultListModel) librariesList.getModel()).addElement(azureLibrary);
            tempList.add(azureLibrary);
        } catch (Exception ex) {
            PluginUtil.displayErrorDialogAndLog(message("error"), message("addLibraryError"), ex);
        } finally {
            token.finish();
        }
        LocalFileSystem.getInstance().findFileByPath(PluginUtil.getModulePath(module)).refresh(true, true);
    }
}
Also used : ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) AccessToken(com.intellij.openapi.application.AccessToken) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) Library(com.intellij.openapi.roots.libraries.Library) File(java.io.File)

Example 13 with OrderRoot

use of com.intellij.openapi.roots.libraries.ui.OrderRoot in project azure-tools-for-java by Microsoft.

the class SparkLibraryOptionsPanel method getNewLibraryEditor.

private NewLibraryEditor getNewLibraryEditor(@NotNull String path) {
    if (StringHelper.isNullOrWhiteSpace(path)) {
        return null;
    }
    VirtualFile root = LocalFileSystem.getInstance().findFileByPath(path);
    if (root == null) {
        return null;
    }
    final FileChooserDescriptor chooserDescriptor = new FileChooserDescriptor(false, false, true, false, true, false);
    VirtualFile[] libraryFiles = VfsUtilCore.toVirtualFileArray(FileChooserUtil.getChosenFiles(chooserDescriptor, Arrays.asList(root)));
    try {
        chooserDescriptor.validateSelectedFiles(libraryFiles);
    } catch (Exception exception) {
        //do noting if check failed
        return null;
    }
    final List<OrderRoot> roots = RootDetectionUtil.detectRoots(Arrays.asList(libraryFiles), null, null, new DefaultLibraryRootsComponentDescriptor());
    if (roots.isEmpty()) {
        return null;
    }
    NewLibraryConfiguration configuration = new NewLibraryConfiguration(LibraryTypeServiceImpl.suggestLibraryName(roots), SparkLibraryType.getInstance(), new SparkLibraryProperties()) {

        @Override
        public void addRoots(@NotNull LibraryEditor libraryEditor) {
            libraryEditor.addRoots(roots);
        }
    };
    if (configuration != null) {
        NewLibraryEditor libraryEditor = new NewLibraryEditor(configuration.getLibraryType(), configuration.getProperties());
        libraryEditor.setName(suggestUniqueLibraryName(configuration.getDefaultLibraryName()));
        configuration.addRoots(libraryEditor);
        return libraryEditor;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) NotNull(org.jetbrains.annotations.NotNull) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration)

Example 14 with OrderRoot

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

the class CreateLibraryFromFilesDialog method findModule.

@Nullable
private Module findModule(List<OrderRoot> roots) {
    for (OrderRoot root : roots) {
        Module module = null;
        final VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(root.getFile());
        if (local != null) {
            module = ModuleUtil.findModuleForFile(local, myProject);
        }
        if (module == null) {
            module = ModuleUtil.findModuleForFile(root.getFile(), myProject);
        }
        if (module != null) {
            return module;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with OrderRoot

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

the class CreateModuleLibraryChooser method filterAlreadyAdded.

private static List<OrderRoot> filterAlreadyAdded(final List<OrderRoot> roots, LibraryTable.ModifiableModel moduleLibrariesModel) {
    if (roots == null || roots.isEmpty()) {
        return Collections.emptyList();
    }
    final List<OrderRoot> result = new ArrayList<>();
    final Library[] libraries = moduleLibrariesModel.getLibraries();
    for (OrderRoot root : roots) {
        if (!Arrays.stream(libraries).anyMatch(library -> contains(root.getFile(), library.getFiles(root.getType())))) {
            result.add(root);
        }
    }
    return result;
}
Also used : DefaultLibraryRootsComponentDescriptor(com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) java.util(java.util) OrderRootType(com.intellij.openapi.roots.OrderRootType) com.intellij.openapi.roots.libraries(com.intellij.openapi.roots.libraries) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) ArrayUtil.contains(com.intellij.util.ArrayUtil.contains) TestOnly(org.jetbrains.annotations.TestOnly) Nullable(org.jetbrains.annotations.Nullable) LibraryEditingUtil(com.intellij.openapi.roots.ui.configuration.libraries.LibraryEditingUtil) Function(com.intellij.util.Function) Pair(com.intellij.openapi.util.Pair) Project(com.intellij.openapi.project.Project) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) Module(com.intellij.openapi.module.Module) LibraryRootsComponentDescriptor(com.intellij.openapi.roots.libraries.ui.LibraryRootsComponentDescriptor) RootDetectionUtil(com.intellij.openapi.roots.libraries.ui.impl.RootDetectionUtil) NotNull(org.jetbrains.annotations.NotNull) FileChooser(com.intellij.openapi.fileChooser.FileChooser) javax.swing(javax.swing) 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