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