Search in sources :

Example 1 with LegacySupport

use of org.apache.maven.plugin.LegacySupport 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 LegacySupport

use of org.apache.maven.plugin.LegacySupport in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method executeWithMavenSession.

public void executeWithMavenSession(MavenExecutionRequest request, Runnable runnable) {
    DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
    RepositorySystemSession repositorySession = maven.newRepositorySession(request);
    request.getProjectBuildingRequest().setRepositorySession(repositorySession);
    MavenSession mavenSession = new MavenSession(myContainer, repositorySession, request, new DefaultMavenExecutionResult());
    LegacySupport legacySupport = getComponent(LegacySupport.class);
    MavenSession oldSession = legacySupport.getSession();
    legacySupport.setSession(mavenSession);
    /** adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)} */
    try {
        for (AbstractMavenLifecycleParticipant listener : getLifecycleParticipants(Collections.<MavenProject>emptyList())) {
            listener.afterSessionStart(mavenSession);
        }
    } catch (MavenExecutionException e) {
        throw new RuntimeException(e);
    }
    try {
        runnable.run();
    } finally {
        legacySupport.setSession(oldSession);
    }
}
Also used : DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) LegacySupport(org.apache.maven.plugin.LegacySupport)

Example 3 with LegacySupport

use of org.apache.maven.plugin.LegacySupport in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method loadExtensions.

/**
   * adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)}
   */
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);
        try {
            // the method can be removed
            session.setAllProjects(Arrays.asList(project));
        } catch (NoSuchMethodError ignore) {
        }
        session.setProjects(Arrays.asList(project));
        for (AbstractMavenLifecycleParticipant listener : lifecycleParticipants) {
            Thread.currentThread().setContextClassLoader(listener.getClass().getClassLoader());
            try {
                listener.afterProjectsRead(session);
            } catch (Exception e) {
                exceptions.add(e);
            } finally {
                Thread.currentThread().setContextClassLoader(originalClassLoader);
            }
        }
    }
}
Also used : LegacySupport(org.apache.maven.plugin.LegacySupport) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException)

Example 4 with LegacySupport

use of org.apache.maven.plugin.LegacySupport in project maven-plugins by apache.

the class JavadocReportTest method testTaglets.

/**
     * Method to test the taglet artifact configuration
     *
     * @throws Exception if any
     */
public void testTaglets() throws Exception {
    // ----------------------------------------------------------------------
    // taglet-test: check if a taglet is used
    // ----------------------------------------------------------------------
    File testPom = new File(unit, "taglet-test/taglet-test-plugin-config.xml");
    JavadocReport mojo = lookupMojo(testPom);
    MavenSession session = spy(newMavenSession(mojo.project));
    ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
    when(buildingRequest.getRemoteRepositories()).thenReturn(mojo.project.getRemoteArtifactRepositories());
    when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
    MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(localRepo));
    when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
    when(session.getRepositorySession()).thenReturn(repositorySession);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(session);
    setVariableValueToObject(mojo, "session", session);
    mojo.execute();
    File apidocs = new File(getBasedir(), "target/test/unit/taglet-test/target/site/apidocs");
    assertTrue(new File(apidocs, "index.html").exists());
    File appFile = new File(apidocs, "taglet/test/App.html");
    assertTrue(appFile.exists());
    String appString = readFile(appFile);
    assertTrue(appString.contains("<b>To Do:</b>"));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenRepositorySystemSession(org.apache.maven.repository.internal.MavenRepositorySystemSession) File(java.io.File)

Example 5 with LegacySupport

use of org.apache.maven.plugin.LegacySupport 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)

Aggregations

LegacySupport (org.apache.maven.plugin.LegacySupport)14 MavenSession (org.apache.maven.execution.MavenSession)9 File (java.io.File)8 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)8 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)6 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)6 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)3 AbstractMavenLifecycleParticipant (org.apache.maven.AbstractMavenLifecycleParticipant)2 MavenExecutionException (org.apache.maven.MavenExecutionException)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 DefaultMaven (org.apache.maven.DefaultMaven)1 Maven (org.apache.maven.Maven)1 Artifact (org.apache.maven.artifact.Artifact)1 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1