Search in sources :

Example 6 with LegacySupport

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

the class Maven30ServerEmbedderImpl 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);
        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);
            }
        }
    }
}
Also used : LegacySupport(org.apache.maven.plugin.LegacySupport)

Example 7 with LegacySupport

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

the class Maven3ServerEmbedderImpl 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 : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LegacySupport(org.apache.maven.plugin.LegacySupport)

Example 8 with LegacySupport

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

the class TestGetMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("markers", false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml");
    assert testPom.exists();
    mojo = (GetMojo) lookupMojo("get", testPom);
    assertNotNull(mojo);
    LegacySupport legacySupport = lookup(LegacySupport.class);
    legacySupport.setSession(newMavenSession(new MavenProjectStub()));
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
    setVariableValueToObject(mojo, "session", legacySupport.getSession());
}
Also used : LegacySupport(org.apache.maven.plugin.LegacySupport) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProjectStub(org.apache.maven.plugin.testing.stubs.MavenProjectStub) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File)

Example 9 with LegacySupport

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

the class TestCopyDependenciesMojo2 method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("copy-dependencies", true);
    File testPom = new File(getBasedir(), "target/test-classes/unit/copy-dependencies-test/plugin-config.xml");
    mojo = (CopyDependenciesMojo) lookupMojo("copy-dependencies", testPom);
    mojo.outputDirectory = new File(this.testDir, "outputDirectory");
    // mojo.silent = true;
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.markersDirectory = new File(this.testDir, "markers");
    LegacySupport legacySupport = lookup(LegacySupport.class);
    MavenSession session = newMavenSession(project);
    setVariableValueToObject(mojo, "session", session);
    legacySupport.setSession(session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) LegacySupport(org.apache.maven.plugin.LegacySupport) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 10 with LegacySupport

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

the class JavadocReportTest method testTagletArtifacts.

/**
     * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
     *
     * @throws Exception if any
     */
public void testTagletArtifacts() throws Exception {
    File testPom = new File(unit, "tagletArtifacts-test/tagletArtifacts-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 optionsFile = new File(mojo.getOutputDirectory(), "options");
    assertTrue(optionsFile.exists());
    String options = readFile(optionsFile);
    // count -taglet
    assertEquals(20, StringUtils.countMatches(options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet"));
    assertTrue(options.contains("org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusConfigurationTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusRequirementTaglet"));
    assertTrue(options.contains("org.codehaus.plexus.javadoc.PlexusComponentTaglet"));
}
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)

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