Search in sources :

Example 6 with MavenGeneralSettings

use of org.jetbrains.idea.maven.project.MavenGeneralSettings 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

MavenGeneralSettings (org.jetbrains.idea.maven.project.MavenGeneralSettings)6 Notification (com.intellij.notification.Notification)3 File (java.io.File)3 MavenProjectsManager (org.jetbrains.idea.maven.project.MavenProjectsManager)3 NotificationListener (com.intellij.notification.NotificationListener)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 CommonBundle (com.intellij.CommonBundle)1 ExecutionException (com.intellij.execution.ExecutionException)1 Executor (com.intellij.execution.Executor)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 DefaultJavaProgramRunner (com.intellij.execution.impl.DefaultJavaProgramRunner)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 ProgramRunner (com.intellij.execution.runners.ProgramRunner)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