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)));
}
}
}
Aggregations