Search in sources :

Example 1 with MavenEmbedderWrapper

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;
        }
    };
}
Also used : MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) RemoteException(java.rmi.RemoteException) NotNull(org.jetbrains.annotations.NotNull) MavenServerEmbedder(org.jetbrains.idea.maven.server.MavenServerEmbedder)

Example 2 with MavenEmbedderWrapper

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);
}
Also used : MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) Element(org.jdom.Element) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) THashSet(gnu.trove.THashSet) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with MavenEmbedderWrapper

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;
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProfileApplicationResult(org.jetbrains.idea.maven.server.ProfileApplicationResult) java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MavenLog(org.jetbrains.idea.maven.utils.MavenLog) THashSet(gnu.trove.THashSet) MavenServerManager(org.jetbrains.idea.maven.server.MavenServerManager) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) Comparing(com.intellij.openapi.util.Comparing) Project(com.intellij.openapi.project.Project) MavenUtil.getBaseDir(org.jetbrains.idea.maven.utils.MavenUtil.getBaseDir) StringUtil.isEmptyOrSpaces(com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces) org.jetbrains.idea.maven.model(org.jetbrains.idea.maven.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenUtil(org.jetbrains.idea.maven.utils.MavenUtil) IOException(java.io.IOException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) MavenJDOMUtil(org.jetbrains.idea.maven.utils.MavenJDOMUtil) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull) Element(org.jdom.Element) MavenProcessCanceledException(org.jetbrains.idea.maven.utils.MavenProcessCanceledException) MavenServerExecutionResult(org.jetbrains.idea.maven.server.MavenServerExecutionResult)

Example 4 with MavenEmbedderWrapper

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);
    }
}
Also used : MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper) Key(com.intellij.openapi.util.Key)

Example 5 with MavenEmbedderWrapper

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);
    }
}
Also used : MavenEmbedderWrapper(org.jetbrains.idea.maven.server.MavenEmbedderWrapper)

Aggregations

MavenEmbedderWrapper (org.jetbrains.idea.maven.server.MavenEmbedderWrapper)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)5 MavenProcessCanceledException (org.jetbrains.idea.maven.utils.MavenProcessCanceledException)5 File (java.io.File)4 THashSet (gnu.trove.THashSet)3 IOException (java.io.IOException)3 Project (com.intellij.openapi.project.Project)2 Key (com.intellij.openapi.util.Key)2 Pair (com.intellij.openapi.util.Pair)2 VfsUtilCore (com.intellij.openapi.vfs.VfsUtilCore)2 MultiMap (com.intellij.util.containers.MultiMap)2 THashMap (gnu.trove.THashMap)2 java.util (java.util)2 Element (org.jdom.Element)2 MavenEmbeddersManager (org.jetbrains.idea.maven.project.MavenEmbeddersManager)2 MavenServerExecutionResult (org.jetbrains.idea.maven.server.MavenServerExecutionResult)2 CommonBundle (com.intellij.CommonBundle)1 Notification (com.intellij.notification.Notification)1 NotificationType (com.intellij.notification.NotificationType)1