Search in sources :

Example 1 with MavenExtraArtifactType

use of org.jetbrains.idea.maven.importing.MavenExtraArtifactType in project intellij-community by JetBrains.

the class MavenArtifactDownloader method download.

private DownloadResult download(boolean downloadSources, boolean downloadDocs) throws MavenProcessCanceledException {
    List<File> downloadedFiles = new ArrayList<>();
    try {
        List<MavenExtraArtifactType> types = new ArrayList<>(2);
        if (downloadSources)
            types.add(MavenExtraArtifactType.SOURCES);
        if (downloadDocs)
            types.add(MavenExtraArtifactType.DOCS);
        String caption = downloadSources && downloadDocs ? ProjectBundle.message("maven.downloading") : (downloadSources ? ProjectBundle.message("maven.downloading.sources") : ProjectBundle.message("maven.downloading.docs"));
        myProgress.setText(caption);
        Map<MavenId, DownloadData> artifacts = collectArtifactsToDownload(types);
        return download(artifacts, downloadedFiles);
    } finally {
        boolean isAsync = !ApplicationManager.getApplication().isUnitTestMode();
        // We have to refresh parents of downloaded files, because some additional files  may have been download.
        Set<File> filesToRefresh = new HashSet<>();
        for (File file : downloadedFiles) {
            filesToRefresh.add(file);
            filesToRefresh.add(file.getParentFile());
        }
        LocalFileSystem.getInstance().refreshIoFiles(filesToRefresh, isAsync, false, null);
    }
}
Also used : MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType) File(java.io.File) THashSet(gnu.trove.THashSet)

Example 2 with MavenExtraArtifactType

use of org.jetbrains.idea.maven.importing.MavenExtraArtifactType in project intellij-community by JetBrains.

the class MavenArtifactDownloader method collectArtifactsToDownload.

private Map<MavenId, DownloadData> collectArtifactsToDownload(List<MavenExtraArtifactType> types) {
    Map<MavenId, DownloadData> result = new THashMap<>();
    THashSet<String> dependencyTypesFromSettings = new THashSet<>();
    AccessToken accessToken = ReadAction.start();
    try {
        if (myProject.isDisposed())
            return result;
        dependencyTypesFromSettings.addAll(MavenProjectsManager.getInstance(myProject).getImportingSettings().getDependencyTypesAsSet());
    } finally {
        accessToken.finish();
    }
    for (MavenProject eachProject : myMavenProjects) {
        List<MavenRemoteRepository> repositories = eachProject.getRemoteRepositories();
        for (MavenArtifact eachDependency : eachProject.getDependencies()) {
            if (myArtifacts != null && !myArtifacts.contains(eachDependency))
                continue;
            if (MavenConstants.SCOPE_SYSTEM.equalsIgnoreCase(eachDependency.getScope()))
                continue;
            if (myProjectsTree.findProject(eachDependency.getMavenId()) != null)
                continue;
            String dependencyType = eachDependency.getType();
            if (!dependencyTypesFromSettings.contains(dependencyType) && !eachProject.getDependencyTypesFromImporters(SupportedRequestType.FOR_IMPORT).contains(dependencyType)) {
                continue;
            }
            MavenId id = eachDependency.getMavenId();
            DownloadData data = result.get(id);
            if (data == null) {
                data = new DownloadData();
                result.put(id, data);
            }
            data.repositories.addAll(repositories);
            for (MavenExtraArtifactType eachType : types) {
                Pair<String, String> classifierAndExtension = eachProject.getClassifierAndExtension(eachDependency, eachType);
                String classifier = eachDependency.getFullClassifier(classifierAndExtension.first);
                String extension = classifierAndExtension.second;
                data.classifiersWithExtensions.add(new DownloadElement(classifier, extension, eachType));
            }
        }
    }
    return result;
}
Also used : THashSet(gnu.trove.THashSet) THashMap(gnu.trove.THashMap) AccessToken(com.intellij.openapi.application.AccessToken) MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType)

Example 3 with MavenExtraArtifactType

use of org.jetbrains.idea.maven.importing.MavenExtraArtifactType in project intellij-community by JetBrains.

the class RepositoryAttachHandler method doResolveInner.

public static void doResolveInner(Project project, final MavenId mavenId, List<MavenExtraArtifactType> extraTypes, Collection<MavenRepositoryInfo> repositories, @Nullable final Processor<List<MavenArtifact>> resultProcessor, ProgressIndicator indicator) {
    boolean cancelled = false;
    final Collection<MavenArtifact> result = new LinkedHashSet<>();
    MavenEmbeddersManager manager = MavenProjectsManager.getInstance(project).getEmbeddersManager();
    MavenEmbedderWrapper embedder = manager.getEmbedder(MavenEmbeddersManager.FOR_DOWNLOAD, null, null);
    try {
        final MavenGeneralSettings mavenGeneralSettings = MavenProjectsManager.getInstance(project).getGeneralSettings();
        embedder.customizeForResolve(new SoutMavenConsole(mavenGeneralSettings.getOutputLevel(), mavenGeneralSettings.isPrintErrorStackTraces()), new MavenProgressIndicator(indicator));
        List<MavenRemoteRepository> remoteRepositories = convertRepositories(repositories);
        List<MavenArtifactInfo> artifacts = Collections.singletonList(new MavenArtifactInfo(mavenId, "jar", null));
        List<MavenArtifact> firstResult = embedder.resolveTransitively(artifacts, remoteRepositories);
        for (MavenArtifact artifact : firstResult) {
            if (!artifact.isResolved() || MavenConstants.SCOPE_TEST.equals(artifact.getScope())) {
                continue;
            }
            result.add(artifact);
        }
        // download docs & sources
        if (!extraTypes.isEmpty()) {
            Set<String> allowedClassifiers = JBIterable.from(extraTypes).transform(extraType -> extraType.getDefaultClassifier()).toSet();
            List<MavenArtifactInfo> resolve = JBIterable.from(extraTypes).transform(extraType -> new MavenArtifactInfo(mavenId, extraType.getDefaultExtension(), extraType.getDefaultClassifier())).toList();
            // skip sources/javadoc for dependencies
            for (MavenArtifact artifact : embedder.resolveTransitively(new ArrayList<>(resolve), remoteRepositories)) {
                if (!artifact.isResolved() || MavenConstants.SCOPE_TEST.equals(artifact.getScope()) || !allowedClassifiers.contains(artifact.getClassifier())) {
                    continue;
                }
                result.add(artifact);
            }
        }
    } catch (MavenProcessCanceledException e) {
        cancelled = true;
    } finally {
        manager.release(embedder);
        if (!cancelled && resultProcessor != null) {
            ApplicationManager.getApplication().invokeAndWait(() -> resultProcessor.process(new ArrayList<>(result)));
        }
    }
}
Also used : MavenRepositoryServicesManager(org.jetbrains.idea.maven.services.MavenRepositoryServicesManager) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) JBIterable(com.intellij.util.containers.JBIterable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) PairProcessor(com.intellij.util.PairProcessor) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager) Task(com.intellij.openapi.progress.Task) SmartList(com.intellij.util.SmartList) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole) ProjectBundle(org.jetbrains.idea.maven.project.ProjectBundle) RepositoryAttachDialog(org.jetbrains.idea.maven.utils.RepositoryAttachDialog) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Notifications(com.intellij.notification.Notifications) ProgressManager(com.intellij.openapi.progress.ProgressManager) OrderRootType(com.intellij.openapi.roots.OrderRootType) LibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor) NotificationType(com.intellij.notification.NotificationType) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) NewLibraryConfiguration(com.intellij.openapi.roots.libraries.NewLibraryConfiguration) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) java.util(java.util) WriteAction(com.intellij.openapi.application.WriteAction) MavenLog(org.jetbrains.idea.maven.utils.MavenLog) MavenExtraArtifactType(org.jetbrains.idea.maven.importing.MavenExtraArtifactType) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JavadocOrderRootType(com.intellij.openapi.roots.JavadocOrderRootType) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) Project(com.intellij.openapi.project.Project) org.jetbrains.idea.maven.model(org.jetbrains.idea.maven.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) File(java.io.File) Pair(com.intellij.openapi.util.Pair) MavenDependenciesRemoteManager(org.jetbrains.idea.maven.utils.library.remote.MavenDependenciesRemoteManager) VfsUtil(com.intellij.openapi.vfs.VfsUtil) javax.swing(javax.swing) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) SoutMavenConsole(org.jetbrains.idea.maven.execution.SoutMavenConsole) MavenGeneralSettings(org.jetbrains.idea.maven.project.MavenGeneralSettings) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator)

Aggregations

MavenExtraArtifactType (org.jetbrains.idea.maven.importing.MavenExtraArtifactType)3 THashMap (gnu.trove.THashMap)2 THashSet (gnu.trove.THashSet)2 File (java.io.File)2 CommonBundle (com.intellij.CommonBundle)1 Notification (com.intellij.notification.Notification)1 NotificationType (com.intellij.notification.NotificationType)1 Notifications (com.intellij.notification.Notifications)1 AccessToken (com.intellij.openapi.application.AccessToken)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 WriteAction (com.intellij.openapi.application.WriteAction)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 JavadocOrderRootType (com.intellij.openapi.roots.JavadocOrderRootType)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 NewLibraryConfiguration (com.intellij.openapi.roots.libraries.NewLibraryConfiguration)1 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)1 LibraryEditor (com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryEditor)1