Search in sources :

Example 1 with MavenSession

use of org.apache.maven.execution.MavenSession 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 MavenSession

use of org.apache.maven.execution.MavenSession 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 3 with MavenSession

use of org.apache.maven.execution.MavenSession in project liferay-ide by liferay.

the class ThemePluginBuildParticipant method executeThemeMojo.

protected IStatus executeThemeMojo(IMavenProjectFacade facade, IMavenExecutionContext context, IProgressMonitor monitor) throws CoreException {
    IStatus retval = null;
    List<String> goals = Collections.singletonList(getGoal());
    MavenProject mavenProject = facade.getMavenProject(monitor);
    MavenExecutionPlan plan = maven.calculateExecutionPlan(mavenProject, goals, true, monitor);
    monitor.worked(10);
    MojoExecution liferayMojoExecution = MavenUtil.getExecution(plan, ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_ARTIFACT_ID);
    Xpp3Dom originalConfig = liferayMojoExecution.getConfiguration();
    Xpp3Dom config = Xpp3DomUtils.mergeXpp3Dom(new Xpp3Dom("configuration"), originalConfig);
    configureExecution(facade, config);
    boolean parentHierarchyLoaded = false;
    try {
        parentHierarchyLoaded = MavenUtil.loadParentHierarchy(facade, monitor);
        monitor.worked(10);
        ResolverConfiguration configuration = facade.getResolverConfiguration();
        configuration.setResolveWorkspaceProjects(true);
        liferayMojoExecution.setConfiguration(config);
        maven.execute(mavenProject, liferayMojoExecution, monitor);
        monitor.worked(50);
        MavenSession mavenSession = context.getSession();
        List<Throwable> exceptions = mavenSession.getResult().getExceptions();
        if (exceptions.size() == 1) {
            retval = LiferayMavenCore.createErrorStatus(exceptions.get(0));
        } else if (exceptions.size() > 1) {
            List<IStatus> statuses = new ArrayList<>();
            for (Throwable t : exceptions) {
                statuses.add(LiferayMavenCore.createErrorStatus(t));
            }
            retval = LiferayMavenCore.createMultiStatus(IStatus.ERROR, statuses.toArray(new IStatus[0]));
        }
        retval = retval == null ? Status.OK_STATUS : retval;
    } catch (CoreException ce) {
        retval = LiferayMavenCore.createErrorStatus(ce);
    } finally {
        liferayMojoExecution.setConfiguration(originalConfig);
        if (parentHierarchyLoaded) {
            mavenProject.setParent(null);
        }
    }
    return retval;
}
Also used : ResolverConfiguration(org.eclipse.m2e.core.project.ResolverConfiguration) IStatus(org.eclipse.core.runtime.IStatus) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) MojoExecution(org.apache.maven.plugin.MojoExecution) ArrayList(java.util.ArrayList) List(java.util.List) MavenExecutionPlan(org.apache.maven.lifecycle.MavenExecutionPlan)

Example 4 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.

the class TestIncludeExcludeUnpackMojo method setUp.

protected void setUp() throws Exception {
    // required for mojo lookups to work
    super.setUp("unpack", true, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml");
    mojo = (UnpackMojo) lookupMojo("unpack", testPom);
    mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
    // mojo.silent = true;
    // it needs to get the archivermanager
    // stubFactory.setUnpackableFile( mojo.getArchiverManager() );
    // i'm using one file repeatedly to archive so I can test the name
    // programmatically.
    stubFactory.setSrcFile(new File(getBasedir() + File.separatorChar + PACKED_FILE_PATH));
    Artifact artifact = stubFactory.createArtifact("test", "test", "1.0", Artifact.SCOPE_COMPILE, "jar", null);
    ArtifactItem item = stubFactory.getArtifactItem(artifact);
    List<ArtifactItem> list = new ArrayList<ArtifactItem>(1);
    list.add(item);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    mojo.setArchiverManager((ArchiverManager) lookup(ArchiverManager.ROLE));
    mojo.setMarkersDirectory(new File(this.testDir, "markers"));
    mojo.setArtifactItems(list);
    MavenSession session = newMavenSession(mojo.getProject());
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with MavenSession

use of org.apache.maven.execution.MavenSession in project maven-dependency-plugin by apache.

the class TestCopyMojo method setUp.

protected void setUp() throws Exception {
    super.setUp("copy", false, false);
    File testPom = new File(getBasedir(), "target/test-classes/unit/copy-test/plugin-config.xml");
    mojo = (CopyMojo) lookupMojo("copy", testPom);
    mojo.setOutputDirectory(new File(this.testDir, "outputDirectory"));
    mojo.setSilent(true);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    // MavenProject project = mojo.getProject();
    // init classifier things
    MavenSession session = newMavenSession(mojo.getProject());
    setVariableValueToObject(mojo, "session", session);
    DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
    repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(stubFactory.getWorkingDir()));
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) SimpleLocalRepositoryManager(org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) File(java.io.File)

Aggregations

MavenSession (org.apache.maven.execution.MavenSession)118 File (java.io.File)65 MavenProject (org.apache.maven.project.MavenProject)47 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)30 DefaultRepositorySystemSession (org.sonatype.aether.util.DefaultRepositorySystemSession)23 Test (org.junit.Test)21 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)20 LegacySupport (org.apache.maven.plugin.LegacySupport)20 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)18 Properties (java.util.Properties)17 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)16 MojoExecution (org.apache.maven.plugin.MojoExecution)13 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)13 DefaultMavenExecutionResult (org.apache.maven.execution.DefaultMavenExecutionResult)12 Artifact (org.apache.maven.artifact.Artifact)10 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)9 ManipulationSession (org.commonjava.maven.ext.core.ManipulationSession)8 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)7 Settings (org.apache.maven.settings.Settings)7 ArrayList (java.util.ArrayList)6