Search in sources :

Example 1 with AbstractMavenLifecycleParticipant

use of org.apache.maven.AbstractMavenLifecycleParticipant in project che by eclipse.

the class MavenServerImpl method loadExtensions.

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);
            } finally {
                Thread.currentThread().setContextClassLoader(currentClassLoader);
            }
        }
    }
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionException(org.apache.maven.MavenExecutionException) LegacySupport(org.apache.maven.plugin.LegacySupport) AbstractMavenLifecycleParticipant(org.apache.maven.AbstractMavenLifecycleParticipant)

Example 2 with AbstractMavenLifecycleParticipant

use of org.apache.maven.AbstractMavenLifecycleParticipant in project che by eclipse.

the class MavenServerImpl method runMavenRequest.

public void runMavenRequest(MavenExecutionRequest request, Runnable runnable) {
    DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
    RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
    request.getProjectBuildingRequest().setRepositorySession(repositorySystemSession);
    MavenSession mavenSession = new MavenSession(container, repositorySystemSession, request, new DefaultMavenExecutionResult());
    LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
    MavenSession previousSession = legacySupport.getSession();
    legacySupport.setSession(mavenSession);
    try {
        for (AbstractMavenLifecycleParticipant participant : getLifecycleParticipants(Collections.emptyList())) {
            participant.afterSessionStart(mavenSession);
        }
        runnable.run();
    } catch (MavenExecutionException e) {
        throw new RuntimeException(e);
    } finally {
        legacySupport.setSession(previousSession);
    }
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenSession(org.apache.maven.execution.MavenSession) MavenExecutionException(org.apache.maven.MavenExecutionException) LegacySupport(org.apache.maven.plugin.LegacySupport) DefaultMavenExecutionResult(org.apache.maven.execution.DefaultMavenExecutionResult) AbstractMavenLifecycleParticipant(org.apache.maven.AbstractMavenLifecycleParticipant) DefaultMaven(org.apache.maven.DefaultMaven)

Example 3 with AbstractMavenLifecycleParticipant

use of org.apache.maven.AbstractMavenLifecycleParticipant in project che by eclipse.

the class MavenServerImpl method getLifecycleParticipants.

/**
     * method from org.apache.maven.DefaultMaven#getLifecycleParticipants
     */
private Collection<AbstractMavenLifecycleParticipant> getLifecycleParticipants(Collection<MavenProject> projects) {
    Collection<AbstractMavenLifecycleParticipant> lifecycleListeners = new LinkedHashSet<AbstractMavenLifecycleParticipant>();
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        try {
            lifecycleListeners.addAll(container.lookupList(AbstractMavenLifecycleParticipant.class));
        } catch (ComponentLookupException e) {
            // this is just silly, lookupList should return an empty list!
            logWarn("Failed to lookup lifecycle participants: " + e.getMessage());
        }
        Collection<ClassLoader> scannedRealms = new HashSet<ClassLoader>();
        for (MavenProject project : projects) {
            ClassLoader projectRealm = project.getClassRealm();
            if (projectRealm != null && scannedRealms.add(projectRealm)) {
                Thread.currentThread().setContextClassLoader(projectRealm);
                try {
                    lifecycleListeners.addAll(container.lookupList(AbstractMavenLifecycleParticipant.class));
                } catch (ComponentLookupException e) {
                    // this is just silly, lookupList should return an empty list!
                    logWarn("Failed to lookup lifecycle participants: " + e.getMessage());
                }
            }
        }
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassLoader);
    }
    return lifecycleListeners;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) AbstractMavenLifecycleParticipant(org.apache.maven.AbstractMavenLifecycleParticipant) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

AbstractMavenLifecycleParticipant (org.apache.maven.AbstractMavenLifecycleParticipant)3 MavenExecutionException (org.apache.maven.MavenExecutionException)2 MavenSession (org.apache.maven.execution.MavenSession)2 LegacySupport (org.apache.maven.plugin.LegacySupport)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 DefaultMaven (org.apache.maven.DefaultMaven)1 Maven (org.apache.maven.Maven)1 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)1 MavenProject (org.apache.maven.project.MavenProject)1 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)1 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)1 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)1