Example usage for org.apache.maven AbstractMavenLifecycleParticipant afterProjectsRead

List of usage examples for org.apache.maven AbstractMavenLifecycleParticipant afterProjectsRead

Introduction

In this page you can find the example usage for org.apache.maven AbstractMavenLifecycleParticipant afterProjectsRead.

Prototype

public void afterProjectsRead(MavenSession session) throws MavenExecutionException 

Source Link

Document

Invoked after all MavenProject instances have been created.

Usage

From source file:org.eclipse.che.maven.server.MavenServerImpl.java

License:Open Source License

private void loadExtensions(MavenProject project, List<Exception> exceptions) {
    ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
    Collection<AbstractMavenLifecycleParticipant> participants = getLifecycleParticipants(
            Collections.singletonList(project));
    if (!participants.isEmpty()) {
        LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
        MavenSession session = legacySupport.getSession();
        session.setCurrentProject(project);
        session.setProjects(Collections.singletonList(project));

        for (AbstractMavenLifecycleParticipant participant : participants) {
            Thread.currentThread().setContextClassLoader(participant.getClass().getClassLoader());
            try {
                participant.afterProjectsRead(session);
            } catch (MavenExecutionException e) {
                exceptions.add(e);//from   ww  w.ja va 2s .com
            } finally {
                Thread.currentThread().setContextClassLoader(currentClassLoader);
            }
        }
    }
}

From source file:org.jetbrains.idea.maven.server.Maven30ServerEmbedderImpl.java

License:Apache License

/**
 * adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)}
 *//*  w  w  w  .  j  a v  a2 s.  c  o m*/
private void loadExtensions(MavenProject project, List<Exception> exceptions) {
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    Collection<AbstractMavenLifecycleParticipant> lifecycleParticipants = getLifecycleParticipants(
            Arrays.asList(project));
    if (!lifecycleParticipants.isEmpty()) {
        LegacySupport legacySupport = getComponent(LegacySupport.class);
        MavenSession session = legacySupport.getSession();
        session.setCurrentProject(project);
        session.setProjects(Arrays.asList(project));

        for (AbstractMavenLifecycleParticipant listener : lifecycleParticipants) {
            Thread.currentThread().setContextClassLoader(listener.getClass().getClassLoader());
            try {
                listener.afterProjectsRead(session);
            } catch (MavenExecutionException e) {
                exceptions.add(e);
            } finally {
                Thread.currentThread().setContextClassLoader(originalClassLoader);
            }
        }
    }
}