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