use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper in project intellij-community by JetBrains.
the class MavenServerEmbedderTest method initEmbedder.
private void initEmbedder() throws RemoteException {
if (myEmbedder != null)
releaseEmbedder();
myEmbedderImpl = Maven2ServerEmbedderImpl.create(MavenServerManager.convertSettings(getMavenGeneralSettings()));
myEmbedder = new MavenEmbedderWrapper(null) {
@NotNull
@Override
protected MavenServerEmbedder create() throws RemoteException {
return myEmbedderImpl;
}
};
}
use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper in project intellij-community by JetBrains.
the class MavenProjectReader method doReadProjectModel.
private RawModelReadResult doReadProjectModel(VirtualFile file, boolean headerOnly) {
MavenModel result = null;
Collection<MavenProjectProblem> problems = MavenProjectProblem.createProblemsList();
Set<String> alwaysOnProfiles = new THashSet<>();
String fileExtension = file.getExtension();
if (!"pom".equalsIgnoreCase(fileExtension) && !"xml".equalsIgnoreCase(fileExtension)) {
File basedir = getBaseDir(file);
MavenEmbeddersManager manager = MavenProjectsManager.getInstance(myProject).getEmbeddersManager();
MavenEmbedderWrapper embedder = manager.getEmbedder(MavenEmbeddersManager.FOR_MODEL_READ, basedir.getPath(), basedir.getPath());
try {
result = embedder.readModel(VfsUtilCore.virtualToIoFile(file));
} catch (MavenProcessCanceledException ignore) {
} finally {
manager.release(embedder);
}
if (result == null) {
result = new MavenModel();
result.setPackaging(MavenConstants.TYPE_JAR);
return new RawModelReadResult(result, problems, alwaysOnProfiles);
} else {
return new RawModelReadResult(result, problems, alwaysOnProfiles);
}
}
result = new MavenModel();
Element xmlProject = readXml(file, problems, MavenProjectProblem.ProblemType.SYNTAX);
if (xmlProject == null || !"project".equals(xmlProject.getName())) {
result.setPackaging(MavenConstants.TYPE_JAR);
return new RawModelReadResult(result, problems, alwaysOnProfiles);
}
MavenParent parent;
if (MavenJDOMUtil.hasChildByPath(xmlProject, "parent")) {
parent = new MavenParent(new MavenId(MavenJDOMUtil.findChildValueByPath(xmlProject, "parent.groupId", UNKNOWN), MavenJDOMUtil.findChildValueByPath(xmlProject, "parent.artifactId", UNKNOWN), MavenJDOMUtil.findChildValueByPath(xmlProject, "parent.version", UNKNOWN)), MavenJDOMUtil.findChildValueByPath(xmlProject, "parent.relativePath", "../pom.xml"));
result.setParent(parent);
} else {
parent = new MavenParent(new MavenId(UNKNOWN, UNKNOWN, UNKNOWN), "../pom.xml");
}
result.setMavenId(new MavenId(MavenJDOMUtil.findChildValueByPath(xmlProject, "groupId", parent.getMavenId().getGroupId()), MavenJDOMUtil.findChildValueByPath(xmlProject, "artifactId", UNKNOWN), MavenJDOMUtil.findChildValueByPath(xmlProject, "version", parent.getMavenId().getVersion())));
if (headerOnly)
return new RawModelReadResult(result, problems, alwaysOnProfiles);
result.setPackaging(MavenJDOMUtil.findChildValueByPath(xmlProject, "packaging", MavenConstants.TYPE_JAR));
result.setName(MavenJDOMUtil.findChildValueByPath(xmlProject, "name"));
readModelBody(result, result.getBuild(), xmlProject);
result.setProfiles(collectProfiles(file, xmlProject, problems, alwaysOnProfiles));
return new RawModelReadResult(result, problems, alwaysOnProfiles);
}
use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper in project intellij-community by JetBrains.
the class MavenProjectReader method resolveProject.
public Collection<MavenProjectReaderResult> resolveProject(final MavenGeneralSettings generalSettings, MavenEmbedderWrapper embedder, Collection<VirtualFile> files, final MavenExplicitProfiles explicitProfiles, final MavenProjectReaderProjectLocator locator) throws MavenProcessCanceledException {
try {
Collection<MavenServerExecutionResult> executionResults = embedder.resolveProject(files, explicitProfiles.getEnabledProfiles(), explicitProfiles.getDisabledProfiles());
Collection<MavenProjectReaderResult> readerResults = ContainerUtil.newArrayList();
for (MavenServerExecutionResult result : executionResults) {
MavenServerExecutionResult.ProjectData projectData = result.projectData;
if (projectData == null) {
if (files.size() == 1) {
final VirtualFile file = files.iterator().next();
MavenProjectReaderResult temp = readProject(generalSettings, file, explicitProfiles, locator);
temp.readingProblems.addAll(result.problems);
temp.unresolvedArtifactIds.addAll(result.unresolvedArtifacts);
readerResults.add(temp);
}
} else {
readerResults.add(new MavenProjectReaderResult(projectData.mavenModel, projectData.mavenModelMap, new MavenExplicitProfiles(projectData.activatedProfiles, explicitProfiles.getDisabledProfiles()), projectData.nativeMavenProject, result.problems, result.unresolvedArtifacts));
}
}
return readerResults;
} catch (MavenProcessCanceledException e) {
throw e;
} catch (final Throwable e) {
MavenLog.LOG.info(e);
// print exception since we need to know if something wrong with our logic
MavenLog.printInTests(e);
return ContainerUtil.mapNotNull(files, file -> {
MavenProjectReaderResult result = readProject(generalSettings, file, explicitProfiles, locator);
String message = e.getMessage();
if (message != null) {
result.readingProblems.add(MavenProjectProblem.createStructureProblem(file.getPath(), message));
} else {
result.readingProblems.add(MavenProjectProblem.createSyntaxProblem(file.getPath(), MavenProjectProblem.ProblemType.SYNTAX));
}
return result;
});
}
}
use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper in project intellij-community by JetBrains.
the class MavenEmbeddersManager method forEachPooled.
private void forEachPooled(boolean includeInUse, Function<MavenEmbedderWrapper, ?> func) {
for (Trinity<Key, String, String> each : myPool.keySet()) {
MavenEmbedderWrapper embedder = myPool.get(each);
// collected
if (embedder == null)
continue;
if (!includeInUse && myEmbeddersInUse.contains(embedder))
continue;
func.fun(embedder);
}
}
use of org.jetbrains.idea.maven.server.MavenEmbedderWrapper in project intellij-community by JetBrains.
the class MavenProjectsTree method executeWithEmbedder.
public void executeWithEmbedder(@NotNull MavenProject mavenProject, @NotNull MavenEmbeddersManager embeddersManager, @NotNull Key embedderKind, @NotNull MavenConsole console, @NotNull MavenProgressIndicator process, @NotNull EmbedderTask task) throws MavenProcessCanceledException {
MavenEmbedderWrapper embedder = embeddersManager.getEmbedder(mavenProject, embedderKind);
embedder.customizeForResolve(getWorkspaceMap(), console, process, false);
embedder.clearCachesFor(mavenProject.getMavenId());
try {
task.run(embedder);
} finally {
embeddersManager.release(embedder);
}
}
Aggregations