Search in sources :

Example 21 with OrderRoot

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

the class RepositoryLibraryWithDescriptionEditor method edit.

@Override
protected void edit() {
    @NotNull RepositoryLibraryProperties properties = myEditorComponent.getProperties();
    //String oldVersion = properties.getVersion();
    boolean wasGeneratedName = RepositoryLibraryType.getInstance().getDescription(properties).equals(myEditorComponent.getLibraryEditor().getName());
    RepositoryLibraryPropertiesModel model = new RepositoryLibraryPropertiesModel(properties.getVersion(), RepositoryUtils.libraryHasSources(myEditorComponent.getLibraryEditor()), RepositoryUtils.libraryHasJavaDocs(myEditorComponent.getLibraryEditor()));
    RepositoryLibraryPropertiesDialog dialog = new RepositoryLibraryPropertiesDialog(myEditorComponent.getProject(), model, RepositoryLibraryDescription.findDescription(properties), true);
    if (!dialog.showAndGet()) {
        return;
    }
    myEditorComponent.getProperties().changeVersion(model.getVersion());
    if (wasGeneratedName) {
        myEditorComponent.renameLibrary(RepositoryLibraryType.getInstance().getDescription(properties));
    }
    final LibraryEditor libraryEditor = myEditorComponent.getLibraryEditor();
    MavenDependenciesRemoteManager.getInstance(myEditorComponent.getProject()).downloadDependenciesAsync(properties, model.isDownloadSources(), model.isDownloadJavaDocs(), RepositoryUtils.getStorageRoot(myEditorComponent.getLibraryEditor().getUrls(OrderRootType.CLASSES), myEditorComponent.getProject()), new MavenRemoteTask.ResultProcessor<List<OrderRoot>>() {

        @Override
        public void process(@Nullable List<OrderRoot> roots) {
            libraryEditor.removeAllRoots();
            if (roots != null) {
                libraryEditor.addRoots(roots);
            }
        }
    });
}
Also used : LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) RepositoryLibraryPropertiesModel(org.jetbrains.idea.maven.utils.library.propertiesEditor.RepositoryLibraryPropertiesModel) List(java.util.List) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) NotNull(org.jetbrains.annotations.NotNull) RepositoryLibraryPropertiesDialog(org.jetbrains.idea.maven.utils.library.propertiesEditor.RepositoryLibraryPropertiesDialog) MavenRemoteTask(org.jetbrains.idea.maven.utils.library.remote.MavenRemoteTask)

Example 22 with OrderRoot

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

the class RepositoryUtils method loadDependencies.

public static void loadDependencies(@NotNull final Project project, @NotNull final LibraryEx library, boolean downloadSources, boolean downloadJavaDocs, @Nullable String copyTo) {
    if (library.getKind() != RepositoryLibraryType.REPOSITORY_LIBRARY_KIND) {
        return;
    }
    final RepositoryLibraryProperties properties = (RepositoryLibraryProperties) library.getProperties();
    MavenDependenciesRemoteManager.getInstance(project).downloadDependenciesAsync(properties, downloadSources, downloadJavaDocs, copyTo, new MavenRemoteTask.ResultProcessor<List<OrderRoot>>() {

        @Override
        public void process(@Nullable final List<OrderRoot> roots) {
            if (roots == null || roots.isEmpty()) {
                ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(project, ProjectBundle.message("maven.downloading.failed", properties.getMavenId()), CommonBundle.getErrorTitle()));
                return;
            }
            ApplicationManager.getApplication().invokeLater(() -> {
                if (library.isDisposed()) {
                    return;
                }
                WriteAction.run(() -> {
                    final NewLibraryEditor editor = new NewLibraryEditor(null, properties);
                    editor.removeAllRoots();
                    editor.addRoots(roots);
                    final Library.ModifiableModel model = library.getModifiableModel();
                    editor.applyTo((LibraryEx.ModifiableModelEx) model);
                    model.commit();
                });
            });
        }
    });
}
Also used : OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) MavenRemoteTask(org.jetbrains.idea.maven.utils.library.remote.MavenRemoteTask) NewLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor)

Example 23 with OrderRoot

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

the class RepositoryAttachHandler method createRoots.

public static List<OrderRoot> createRoots(@NotNull Collection<MavenArtifact> artifacts, @Nullable String copyTo) {
    final List<OrderRoot> result = new ArrayList<>();
    final VirtualFileManager manager = VirtualFileManager.getInstance();
    for (MavenArtifact each : artifacts) {
        try {
            File repoFile = each.getFile();
            File toFile = repoFile;
            if (copyTo != null) {
                toFile = new File(copyTo, repoFile.getName());
                if (repoFile.exists()) {
                    FileUtil.copy(repoFile, toFile);
                }
            }
            // search for jar file first otherwise lib root won't be found!
            manager.refreshAndFindFileByUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(toFile.getPath())));
            final String url = VfsUtil.getUrlForLibraryRoot(toFile);
            final VirtualFile file = manager.refreshAndFindFileByUrl(url);
            if (file != null) {
                OrderRootType rootType;
                if (MavenExtraArtifactType.DOCS.getDefaultClassifier().equals(each.getClassifier())) {
                    rootType = JavadocOrderRootType.getInstance();
                } else if (MavenExtraArtifactType.SOURCES.getDefaultClassifier().equals(each.getClassifier())) {
                    rootType = OrderRootType.SOURCES;
                } else {
                    rootType = OrderRootType.CLASSES;
                }
                result.add(new OrderRoot(file, rootType));
            }
        } catch (IOException e) {
            MavenLog.LOG.warn(e);
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) OrderRootType(com.intellij.openapi.roots.OrderRootType) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 24 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 25 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