use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper in project intellij-plugins by JetBrains.
the class Flexmojos3ImporterTest method testTransitiveDepsOnPartialProjectImport.
public void testTransitiveDepsOnPartialProjectImport() throws IOException, MavenProcessCanceledException {
createProjectPom(mavenProjectDescription("aggregator", "pom") + " <modules>\n" + " <module>app</module>\n" + " <module>libA</module>\n" + " <module>libB</module>\n" + " </modules>\n");
final VirtualFile app = createModulePom("app", parent() + " <artifactId>ttApp</artifactId>\n" + " <packaging>jar</packaging>\n" + "\n" + dependencies("A", "jar"));
createModulePom("libA", parent() + " <artifactId>A</artifactId>\n" + " <packaging>jar</packaging>\n" + " \n" + dependencies("B", "jar"));
createModulePom("libB", parent() + " <artifactId>B</artifactId>\n" + " <packaging>jar</packaging>");
importProject();
MavenProjectsTree.EmbedderTask task = new MavenProjectsTree.EmbedderTask() {
@Override
public void run(MavenEmbedderWrapper embedder) throws MavenProcessCanceledException {
MavenWorkspaceMap workspaceMap = new MavenWorkspaceMap();
for (MavenProject mavenProject : myProjectsTree.getProjects()) {
if (MavenConstants.TYPE_JAR.equalsIgnoreCase(mavenProject.getPackaging())) {
workspaceMap.register(mavenProject.getMavenId(), new File(mavenProject.getFile().getPath()), new File(mavenProject.getMavenId().getArtifactId() + ".jar"));
} else {
workspaceMap.register(mavenProject.getMavenId(), new File(mavenProject.getFile().getPath()));
}
}
embedder.customizeForStrictResolve(workspaceMap, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS);
MavenServerExecutionResult result = embedder.execute(app, Collections.emptyList(), Collections.emptyList(), Collections.singletonList("compile"));
assertEmpty(result.problems);
assertNotNull(result);
// test find all transitive deps (MavenWorkspaceMap filler is responsible for)
MavenModel mavenModel = result.projectData.mavenModel;
assertTransitiveDeps(TEST_GROUP_ID, TEST_VERSION, mavenModel.getDependencies());
// test correct artifact file (must be SWC/JAR (project product), but not POM) (CustomArtifactResolver is responsible for)
MavenArtifact resolve = embedder.resolve(new MavenArtifactInfo(TEST_GROUP_ID, "B", TEST_VERSION, MavenConstants.TYPE_JAR, null), mavenModel.getRemoteRepositories());
assertNotNull(resolve);
assertEquals("B.jar", resolve.getFile().getPath());
}
};
MavenProject appProject = myProjectsTree.findProject(new MavenId(TEST_GROUP_ID, "ttApp", TEST_VERSION));
assertNotNull(appProject);
myProjectsTree.executeWithEmbedder(appProject, myProjectsManager.getEmbeddersManager(), MavenEmbeddersManager.FOR_POST_PROCESSING, NULL_MAVEN_CONSOLE, EMPTY_MAVEN_PROCESS, task);
List<MavenArtifact> appSubProjectDeps = appProject.getDependencies();
assertTransitiveDeps(TEST_GROUP_ID, TEST_VERSION, appSubProjectDeps);
}
use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper in project intellij-community by JetBrains.
the class MavenEmbeddersManager method getEmbedder.
@NotNull
public synchronized MavenEmbedderWrapper getEmbedder(Key kind, String workingDirectory, String multiModuleProjectDirectory) {
Trinity<Key, String, String> key = Trinity.create(kind, workingDirectory, multiModuleProjectDirectory);
MavenEmbedderWrapper result = myPool.get(key);
boolean alwaysOnline = kind == FOR_DOWNLOAD;
if (result == null) {
result = MavenServerManager.getInstance().createEmbedder(myProject, alwaysOnline, workingDirectory, multiModuleProjectDirectory);
myPool.put(key, result);
}
if (myEmbeddersInUse.contains(result)) {
MavenLog.LOG.warn("embedder " + key + " is already used");
return MavenServerManager.getInstance().createEmbedder(myProject, alwaysOnline, workingDirectory, multiModuleProjectDirectory);
}
myEmbeddersInUse.add(result);
return result;
}
use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper 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)));
}
}
}
use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper 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.server.MavenEmbedderWrapper in project intellij-community by JetBrains.
the class MavenEmbeddersManagerTest method testCachingOnlyOne.
public void testCachingOnlyOne() throws Exception {
MavenEmbedderWrapper one1 = myManager.getEmbedder(MavenEmbeddersManager.FOR_DEPENDENCIES_RESOLVE, null, null);
MavenEmbedderWrapper one2 = myManager.getEmbedder(MavenEmbeddersManager.FOR_DEPENDENCIES_RESOLVE, null, null);
assertNotSame(one1, one2);
myManager.release(one1);
myManager.release(one2);
MavenEmbedderWrapper one11 = myManager.getEmbedder(MavenEmbeddersManager.FOR_DEPENDENCIES_RESOLVE, null, null);
MavenEmbedderWrapper one22 = myManager.getEmbedder(MavenEmbeddersManager.FOR_DEPENDENCIES_RESOLVE, null, null);
assertSame(one1, one11);
assertNotSame(one2, one22);
}
Aggregations