Package org.apache.maven.execution

Examples of org.apache.maven.execution.MavenSession


                            iterator.hasNext();)
                        {
                            final MavenProject project = (MavenProject)iterator.next();
                            this.getLog().info("  " + project.getName());
                        }
                        final MavenSession projectSession =
                            new MavenSession(
                                this.session.getContainer(),
                                this.session.getSettings(),
                                this.session.getLocalRepository(),
                                this.session.getEventDispatcher(),
                                reactorManager,
                                goals,
                                this.baseDirectory.toString(),
                                this.session.getExecutionProperties(),
                                this.session.getStartTime());

                        projectSession.setUsingPOMsFromFilesystem(true);
                        this.lifecycleExecutor.execute(
                            projectSession,
                            reactorManager,
                            projectSession.getEventDispatcher());
                    }
                    else
                    {
                        for (final Iterator iterator = this.session.getGoals().iterator(); iterator.hasNext();)
                        {
                            final String goal = (String)iterator.next();
                            final ReactorManager reactorManager = new ReactorManager(projects);
                            if (projects.size() > 1)
                            {
                                this.getLog().info("Reactor build order:");
                            }
                            for (final Iterator projectIterator = reactorManager.getSortedProjects().iterator();
                                projectIterator.hasNext();)
                            {
                                final MavenProject project = (MavenProject)projectIterator.next();
                                this.getLog().info("  " + project.getName());
                            }

                            final MavenSession projectSession =
                                new MavenSession(
                                    this.session.getContainer(),
                                    this.session.getSettings(),
                                    this.session.getLocalRepository(),
                                    this.session.getEventDispatcher(),
                                    reactorManager,
                                    Collections.singletonList(goal),
                                    this.baseDirectory.toString(),
                                    this.session.getExecutionProperties(),
                                    this.session.getStartTime());

                            projectSession.setUsingPOMsFromFilesystem(true);

                            this.lifecycleExecutor.execute(
                                projectSession,
                                reactorManager,
                                projectSession.getEventDispatcher());
                        }
                    }
                }
            }
            catch (final Throwable throwable)
View Full Code Here


            {
                final MavenProject project = (MavenProject)iterator.next();
                this.getLog().info("  " + project.getName());
            }

            final MavenSession projectSession =
                new MavenSession(
                    this.session.getContainer(),
                    this.session.getSettings(),
                    this.session.getLocalRepository(),
                    this.session.getEventDispatcher(),
                    reactorManager,
                    goals,
                    this.baseDirectory.toString(),
                    this.executionProperties,
                    this.session.getStartTime());

            projectSession.setUsingPOMsFromFilesystem(true);
            this.lifecycleExecutor.execute(
                projectSession,
                reactorManager,
                projectSession.getEventDispatcher());
        }
        catch (final Throwable throwable)
        {
            throw new MojoExecutionException("An error occured while attempting to execute projects", throwable);
        }
View Full Code Here

       
        request.setLocalRepository( delegatingLocalArtifactRepository );       

        DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) newRepositorySession( request );

        MavenSession session = new MavenSession( container, repoSession, request, result );
        legacySupport.setSession( session );

        try
        {
            for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections.<MavenProject> emptyList() ) )
            {
                listener.afterSessionStart( session );
            }
        }
        catch ( MavenExecutionException e )
        {
            return processResult( result, e );
        }

        eventCatapult.fire( ExecutionEvent.Type.ProjectDiscoveryStarted, session, null );

        request.getProjectBuildingRequest().setRepositorySession( session.getRepositorySession() );

        //TODO: optimize for the single project or no project
       
        List<MavenProject> projects;
        try
        {
            projects = getProjectsForMavenReactor( request );                                               
        }
        catch ( ProjectBuildingException e )
        {
            return processResult( result, e );
        }

        session.setProjects( projects );

        result.setTopologicallySortedProjects( session.getProjects() );
       
        result.setProject( session.getTopLevelProject() );

        try
        {
            Map<String, MavenProject> projectMap;
            projectMap = getProjectMap( session.getProjects() );
   
            // Desired order of precedence for local artifact repositories
            //
            // Reactor
            // Workspace
            // User Local Repository
            ReactorReader reactorRepository = new ReactorReader( projectMap );

            repoSession.setWorkspaceReader( ChainedWorkspaceReader.newInstance( reactorRepository,
                                                                                repoSession.getWorkspaceReader() ) );
        }
        catch ( org.apache.maven.DuplicateProjectException e )
        {
            return processResult( result, e );
        }

        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
        try
        {
            for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( projects ) )
            {
                Thread.currentThread().setContextClassLoader( listener.getClass().getClassLoader() );

                listener.afterProjectsRead( session );
            }
        }
        catch ( MavenExecutionException e )
        {
            return processResult( result, e );
        }
        finally
        {
            Thread.currentThread().setContextClassLoader( originalClassLoader );
        }

        try
        {
            ProjectSorter projectSorter = new ProjectSorter( session.getProjects() );

            ProjectDependencyGraph projectDependencyGraph = createDependencyGraph( projectSorter, request );

            session.setProjects( projectDependencyGraph.getSortedProjects() );

            session.setProjectDependencyGraph( projectDependencyGraph );
        }
        catch ( CycleDetectedException e )
        {           
            String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();

            ProjectCycleException error = new ProjectCycleException( message, e );

            return processResult( result, error );
        }
        catch ( DuplicateProjectException e )
        {
            return processResult( result, e );
        }
        catch ( MavenExecutionException e )
        {
            return processResult( result, e );
        }

        result.setTopologicallySortedProjects( session.getProjects() );

        if ( result.hasExceptions() )
        {
            return result;
        }

        lifecycleStarter.execute( session );

        validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() );

        if ( session.getResult().hasExceptions() )
        {
            return processResult( result, session.getResult().getExceptions().get( 0 ) );
        }

        return result;
    }
View Full Code Here

            createExecutionPlaceCalculator( mojoDescriptorCreator );

        final GoalTask goalTask1 = new GoalTask( "compiler:compile" );
        final GoalTask goalTask2 = new GoalTask( "surefire:test" );
        final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 );
        final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( ProjectDependencyGraphStub.A );

        MavenExecutionPlan executionPlan =
            lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
                                                                     taskSegment1.getTasks() );
        assertEquals( 2, executionPlan.size() );
View Full Code Here

    extends TestCase
{
    public void testResolveBuildPlan()
        throws Exception
    {
        MavenSession original = ProjectDependencyGraphStub.getMavenSession();

        final TaskSegment taskSegment1 = new TaskSegment( false );
        final MavenSession session1 = original.clone();
        session1.setCurrentProject( ProjectDependencyGraphStub.A );

        final BuilderCommon builderCommon = getBuilderCommon();
        final MavenExecutionPlan plan =
            builderCommon.resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1,
                                            new HashSet<Artifact>() );
View Full Code Here

    {
        final ClassLoader loader = Thread.currentThread().getContextClassLoader();
        try
        {
            BuildListCalculator buildListCalculator = new BuildListCalculator();
            final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
            List<TaskSegment> taskSegments = getTaskSegmentCalculator().calculateTaskSegments( session );
            ProjectBuildList projectBuildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );

            final MojoExecutorStub mojoExecutorStub = new MojoExecutorStub();
            final LifecycleWeaveBuilder builder = getWeaveBuilder( mojoExecutorStub );
            final ReactorContext buildContext = createBuildContext( session );
            ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus( session.getProjectDependencyGraph() );
            builder.build( projectBuildList, buildContext, taskSegments, session, service, reactorBuildStatus );

            LifecycleExecutionPlanCalculatorStub lifecycleExecutionPlanCalculatorStub =
                new LifecycleExecutionPlanCalculatorStub();
            final int expected = lifecycleExecutionPlanCalculatorStub.getNumberOfExceutions( projectBuildList );
View Full Code Here

        long buildStartTime = System.currentTimeMillis();

        CurrentPhaseForThread.setPhasenode.getLifecyclePhase() );

        MavenSession sessionForThisModule = projectBuild.getSession();
        try
        {

            if ( reactorContext.getReactorBuildStatus().isHaltedOrBlacklisted( currentProject ) )
            {
View Full Code Here

        DelegatingLocalArtifactRepository delegatingLocalArtifactRepository =
            new DelegatingLocalArtifactRepository( request.getLocalRepository() );

        request.setLocalRepository( delegatingLocalArtifactRepository );

        MavenSession session = new MavenSession( container, request, result );

        try
        {
            for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections.<MavenProject> emptyList() ) )
            {
                listener.afterSessionStart( session );
            }
        }
        catch ( MavenExecutionException e )
        {
            return processResult( result, e );
        }

        eventCatapult.fire( ExecutionEvent.Type.ProjectDiscoveryStarted, session, null );

        //TODO: optimize for the single project or no project

        List<MavenProject> projects;
        try
        {
            projects = getProjectsForMavenReactor( request );
        }
        catch ( ProjectBuildingException e )
        {
            return processResult( result, e );
        }

        session.setProjects( projects );

        result.setTopologicallySortedProjects( session.getProjects() );

        result.setProject( session.getTopLevelProject() );

        try
        {
            Map<String, MavenProject> projectMap;
            projectMap = getProjectMap( session.getProjects() );

            // Desired order of precedence for local artifact repositories
            //
            // Reactor
            // Workspace
            // User Local Repository
            delegatingLocalArtifactRepository.setBuildReactor( new ReactorArtifactRepository( projectMap ) );
        }
        catch ( org.apache.maven.DuplicateProjectException e )
        {
            return processResult( result, e );
        }

        ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
        try
        {
            for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( projects ) )
            {
                Thread.currentThread().setContextClassLoader( listener.getClass().getClassLoader() );

                listener.afterProjectsRead( session );
            }
        }
        catch ( MavenExecutionException e )
        {
            return processResult( result, e );
        }
        finally
        {
            Thread.currentThread().setContextClassLoader( originalClassLoader );
        }

        try
        {
            ProjectSorter projectSorter = new ProjectSorter( session.getProjects() );

            ProjectDependencyGraph projectDependencyGraph = createDependencyGraph( projectSorter, request );

            session.setProjects( projectDependencyGraph.getSortedProjects() );

            session.setProjectDependencyGraph( projectDependencyGraph );
        }
        catch ( CycleDetectedException e )
        {
            String message = "The projects in the reactor contain a cyclic reference: " + e.getMessage();

            ProjectCycleException error = new ProjectCycleException( message, e );

            return processResult( result, error );
        }
        catch ( DuplicateProjectException e )
        {
            return processResult( result, e );
        }
        catch ( MavenExecutionException e )
        {
            return processResult( result, e );
        }

        result.setTopologicallySortedProjects( session.getProjects() );

        if ( result.hasExceptions() )
        {
            return result;
        }

        lifecycleStarter.execute( session );

        validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() );

        if ( session.getResult().hasExceptions() )
        {
            return processResult( result, session.getResult().getExceptions().get( 0 ) );
        }

        return result;
    }
View Full Code Here

        }

        ClassRealm oldLookupRealm = container.getLookupRealm();
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();

        MavenSession oldSession = legacySupport.getSession();

        try
        {
            mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, mojoExecution );
View Full Code Here

        throws Exception
    {
        // We are doing something like "mvn resources:resources" where no version is specified but this
        // project we are working on has the version specified in the POM so the version should come from there.
        File pom = getProject( "project-basic" );
        MavenSession session = createMavenSession( pom );
        assertEquals( "project-basic", session.getCurrentProject().getArtifactId() );
        assertEquals( "1.0", session.getCurrentProject().getVersion() );
        List<MojoExecution> executionPlan = getExecutions( calculateExecutionPlan( session, "resources:resources" ) );
        assertEquals( 1, executionPlan.size() );
        MojoExecution mojoExecution = executionPlan.get( 0 );
        assertNotNull( mojoExecution );
        assertEquals( "org.apache.maven.plugins",
View Full Code Here

TOP

Related Classes of org.apache.maven.execution.MavenSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.