Search in sources :

Example 6 with MavenProcessCanceledException

use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project android by JetBrains.

the class AndroidFacetImporterBase method doImportExternalApklibDependency.

private static String doImportExternalApklibDependency(Project project, IdeModifiableModelsProvider modelsProvider, MavenProjectsTree mavenTree, MavenProject mavenProject, Map<MavenProject, String> mavenProject2ModuleName, List<MavenProjectsProcessorTask> tasks, AndroidExternalApklibDependenciesManager.MavenDependencyInfo depInfo) {
    final MavenId depArtifactMavenId = new MavenId(depInfo.getGroupId(), depInfo.getArtifactId(), depInfo.getVersion());
    final ModifiableModuleModel moduleModel = modelsProvider.getModifiableModuleModel();
    final String apklibModuleName = AndroidMavenUtil.getModuleNameForExtApklibArtifact(depArtifactMavenId);
    Module apklibModule = moduleModel.findModuleByName(apklibModuleName);
    if ((apklibModule == null || apklibModule.getUserData(MODULE_IMPORTED) == null) && MavenConstants.SCOPE_COMPILE.equals(depInfo.getScope())) {
        apklibModule = importExternalApklibArtifact(project, apklibModule, modelsProvider, mavenProject, mavenTree, depArtifactMavenId, depInfo.getPath(), moduleModel, mavenProject2ModuleName);
        if (apklibModule != null) {
            apklibModule.putUserData(MODULE_IMPORTED, Boolean.TRUE);
            final Module finalGenModule = apklibModule;
            tasks.add(new MavenProjectsProcessorTask() {

                @Override
                public void perform(Project project, MavenEmbeddersManager embeddersManager, MavenConsole console, MavenProgressIndicator indicator) throws MavenProcessCanceledException {
                    finalGenModule.putUserData(MODULE_IMPORTED, null);
                }
            });
            final MavenArtifactResolvedInfo resolvedDepArtifact = AndroidExternalApklibDependenciesManager.getInstance(project).getResolvedInfoForArtifact(depArtifactMavenId);
            if (resolvedDepArtifact != null) {
                for (AndroidExternalApklibDependenciesManager.MavenDependencyInfo depDepInfo : resolvedDepArtifact.getDependencies()) {
                    final MavenId depDepMavenId = new MavenId(depDepInfo.getGroupId(), depDepInfo.getArtifactId(), depDepInfo.getVersion());
                    if (AndroidMavenUtil.APKLIB_DEPENDENCY_AND_PACKAGING_TYPE.equals(depDepInfo.getType()) && mavenTree.findProject(depDepMavenId) == null) {
                        doImportExternalApklibDependency(project, modelsProvider, mavenTree, mavenProject, mavenProject2ModuleName, tasks, depDepInfo);
                    }
                }
            } else {
                AndroidUtils.reportImportErrorToEventLog("Cannot find resolved info for artifact " + depArtifactMavenId.getKey(), apklibModuleName, project);
            }
        }
    }
    return apklibModuleName;
}
Also used : MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) Project(com.intellij.openapi.project.Project) MavenId(org.jetbrains.idea.maven.model.MavenId) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) MavenProgressIndicator(org.jetbrains.idea.maven.utils.MavenProgressIndicator) Module(com.intellij.openapi.module.Module)

Example 7 with MavenProcessCanceledException

use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project intellij-plugins by JetBrains.

the class Flexmojos3GenerateConfigTask method perform.

public void perform(final Project project, final MavenEmbeddersManager embeddersManager, final MavenConsole console, final MavenProgressIndicator indicator) throws MavenProcessCanceledException {
    if (myModule.isDisposed())
        return;
    indicator.setText(FlexBundle.message("generating.flex.config.for", myMavenProject.getDisplayName()));
    final MavenProjectsTree.EmbedderTask task = new MavenProjectsTree.EmbedderTask() {

        public void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException {
            List<VirtualFile> temporaryFiles = null;
            final IgnoredFileBean[] filesToIgnoreOriginal = ChangeListManager.getInstance(project).getFilesToIgnore();
            try {
                MavenWorkspaceMap workspaceMap = new MavenWorkspaceMap();
                temporaryFiles = mavenIdToOutputFileMapping(workspaceMap, project, myTree.getProjects());
                embedder.customizeForStrictResolve(workspaceMap, console, indicator);
                final String generateConfigGoal = FlexmojosImporter.FLEXMOJOS_GROUP_ID + ":" + FlexmojosImporter.FLEXMOJOS_ARTIFACT_ID + ":generate-config-" + myMavenProject.getPackaging();
                final MavenExplicitProfiles profilesIds = myMavenProject.getActivatedProfilesIds();
                MavenServerExecutionResult result = embedder.execute(myMavenProject.getFile(), profilesIds.getEnabledProfiles(), profilesIds.getDisabledProfiles(), Collections.singletonList(generateConfigGoal));
                if (result.projectData == null) {
                    myFlexConfigInformer.showFlexConfigWarningIfNeeded(project);
                }
                MavenUtil.invokeAndWaitWriteAction(project, () -> {
                    // need to refresh externally created file
                    final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(myConfigFilePath);
                    if (file != null) {
                        file.refresh(false, false);
                        updateMainClass(myModule, file);
                    }
                });
            } catch (MavenProcessCanceledException e) {
                throw e;
            } catch (Exception e) {
                myFlexConfigInformer.showFlexConfigWarningIfNeeded(project);
                console.printException(e);
                MavenLog.LOG.warn(e);
            } finally {
                ChangeListManager.getInstance(project).setFilesToIgnore(filesToIgnoreOriginal);
                if (temporaryFiles != null && !temporaryFiles.isEmpty()) {
                    removeTemporaryFiles(project, temporaryFiles);
                }
            }
        }
    };
    myTree.executeWithEmbedder(myMavenProject, embeddersManager, MavenEmbeddersManager.FOR_POST_PROCESSING, console, indicator, task);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenExplicitProfiles(org.jetbrains.idea.maven.model.MavenExplicitProfiles) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) IOException(java.io.IOException) ConfigurationException(com.intellij.openapi.options.ConfigurationException) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) IgnoredFileBean(com.intellij.openapi.vcs.changes.IgnoredFileBean) MavenWorkspaceMap(org.jetbrains.idea.maven.model.MavenWorkspaceMap)

Example 8 with MavenProcessCanceledException

use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project intellij-community by JetBrains.

the class MavenArtifactDownloader method download.

private DownloadResult download(final Map<MavenId, DownloadData> toDownload, final List<File> downloadedFiles) throws MavenProcessCanceledException {
    List<Future> futures = new ArrayList<>();
    final AtomicInteger downloaded = new AtomicInteger();
    int total = 0;
    for (DownloadData each : toDownload.values()) {
        total += each.classifiersWithExtensions.size();
    }
    final DownloadResult result = new DownloadResult();
    result.unresolvedSources.addAll(toDownload.keySet());
    result.unresolvedDocs.addAll(toDownload.keySet());
    try {
        for (final Map.Entry<MavenId, DownloadData> eachEntry : toDownload.entrySet()) {
            myProgress.checkCanceled();
            final DownloadData data = eachEntry.getValue();
            final MavenId id = eachEntry.getKey();
            for (final DownloadElement eachElement : data.classifiersWithExtensions) {
                final int finalTotal = total;
                futures.add(EXECUTOR.submit(() -> {
                    try {
                        if (myProject.isDisposed())
                            return;
                        myProgress.checkCanceled();
                        myProgress.setFraction(((double) downloaded.getAndIncrement()) / finalTotal);
                        MavenArtifact a = myEmbedder.resolve(new MavenArtifactInfo(id, eachElement.extension, eachElement.classifier), new ArrayList<>(data.repositories));
                        File file = a.getFile();
                        if (file.exists()) {
                            synchronized (downloadedFiles) {
                                downloadedFiles.add(file);
                                switch(eachElement.type) {
                                    case SOURCES:
                                        result.resolvedSources.add(id);
                                        result.unresolvedSources.remove(id);
                                        break;
                                    case DOCS:
                                        result.resolvedDocs.add(id);
                                        result.unresolvedDocs.remove(id);
                                        break;
                                }
                            }
                        }
                    } catch (MavenProcessCanceledException ignore) {
                    }
                }));
            }
        }
    } finally {
        for (Future each : futures) {
            try {
                each.get();
            } catch (Exception e) {
                MavenLog.LOG.error(e);
            }
        }
    }
    return result;
}
Also used : MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) THashMap(gnu.trove.THashMap) File(java.io.File)

Example 9 with MavenProcessCanceledException

use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException in project intellij-community by JetBrains.

the class MavenVersionsRemoteManager method execute.

@NotNull
@Override
public List<String> execute(@NotNull RepositoryLibraryDescription repositoryLibraryDescription, ProgressIndicator indicator) {
    MavenEmbeddersManager manager = MavenProjectsManager.getInstance(myProject).getEmbeddersManager();
    MavenEmbedderWrapper embedder = manager.getEmbedder(MavenEmbeddersManager.FOR_GET_VERSIONS, null, null);
    embedder.customizeForGetVersions();
    try {
        List<MavenRemoteRepository> remoteRepositories = convertRepositories(repositoryLibraryDescription.getRemoteRepositories());
        List<String> versions = embedder.retrieveVersions(repositoryLibraryDescription.getGroupId(), repositoryLibraryDescription.getArtifactId(), remoteRepositories);
        Collections.sort(versions, (o1, o2) -> {
            MavenVersionComparable v1 = new MavenVersionComparable(o1);
            MavenVersionComparable v2 = new MavenVersionComparable(o2);
            return v2.compareTo(v1);
        });
        return versions;
    } catch (MavenProcessCanceledException e) {
        return Collections.emptyList();
    } finally {
        manager.release(embedder);
    }
}
Also used : MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenVersionComparable(org.jetbrains.idea.maven.dom.MavenVersionComparable) MavenRemoteRepository(org.jetbrains.idea.maven.model.MavenRemoteRepository) MavenEmbeddersManager(org.jetbrains.idea.maven.project.MavenEmbeddersManager) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with MavenProcessCanceledException

use of org.jetbrains.idea.maven.utils.MavenProcessCanceledException 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

MavenProcessCanceledException (org.jetbrains.idea.maven.utils.MavenProcessCanceledException)10 File (java.io.File)6 Project (com.intellij.openapi.project.Project)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 MavenEmbedderWrapper (org.jetbrains.idea.maven.server.MavenEmbedderWrapper)5 MavenProgressIndicator (org.jetbrains.idea.maven.utils.MavenProgressIndicator)4 THashMap (gnu.trove.THashMap)3 THashSet (gnu.trove.THashSet)3 IOException (java.io.IOException)3 NotNull (org.jetbrains.annotations.NotNull)3 Pair (com.intellij.openapi.util.Pair)2 VfsUtilCore (com.intellij.openapi.vfs.VfsUtilCore)2 Element (org.jdom.Element)2 MavenEmbeddersManager (org.jetbrains.idea.maven.project.MavenEmbeddersManager)2 CommonBundle (com.intellij.CommonBundle)1 Notification (com.intellij.notification.Notification)1 NotificationType (com.intellij.notification.NotificationType)1 Notifications (com.intellij.notification.Notifications)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 WriteAction (com.intellij.openapi.application.WriteAction)1