Package org.apache.maven.execution

Examples of org.apache.maven.execution.MavenExecutionResult


        logger.info( "Reactor Summary:" );

        logger.info( "" );

        MavenExecutionResult result = session.getResult();

        for ( MavenProject project : session.getProjects() )
        {
            StringBuilder buffer = new StringBuilder( 128 );

            buffer.append( project.getName() );
            buffer.append( ' ' );

            if ( buffer.length() <= MAX_PROJECT_NAME_LENGTH )
            {
                while ( buffer.length() < MAX_PROJECT_NAME_LENGTH )
                {
                    buffer.append( '.' );
                }
                buffer.append( ' ' );
            }

            BuildSummary buildSummary = result.getBuildSummary( project );

            if ( buildSummary == null )
            {
                buffer.append( "SKIPPED" );
            }
View Full Code Here


    {
        eventCatapult.fire( ExecutionEvent.Type.SessionStarted, session, null );

        ReactorContext reactorContext = null;
        ProjectBuildList projectBuilds = null;
        MavenExecutionResult result = session.getResult();

        try
        {
            if ( buildExecutionRequiresProject( session ) && projectIsNotPresent( session ) )
            {
                throw new MissingProjectException( "The goal you specified requires a project to execute"
                    + " but there is no POM in this directory (" + session.getExecutionRootDirectory() + ")."
                    + " Please verify you invoked Maven from the correct directory." );
            }

            List<TaskSegment> taskSegments = lifecycleTaskSegmentCalculator.calculateTaskSegments( session );
            projectBuilds = buildListCalculator.calculateProjectBuilds( session, taskSegments );

            if ( projectBuilds.isEmpty() )
            {
                throw new NoGoalSpecifiedException( "No goals have been specified for this build."
                    + " You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or"
                    + " <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>."
                    + " Available lifecycle phases are: " + defaultLifeCycles.getLifecyclePhaseList() + "." );
            }

            ProjectIndex projectIndex = new ProjectIndex( session.getProjects() );

            if ( logger.isDebugEnabled() )
            {
                lifecycleDebugLogger.debugReactorPlan( projectBuilds );
            }

            ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
            ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus( session.getProjectDependencyGraph() );
            reactorContext = new ReactorContext( result, projectIndex, oldContextClassLoader, reactorBuildStatus );

            String builderId = session.getRequest().getBuilderId();
            Builder builder = builders.get( builderId );
            if ( builder == null )
            {
                throw new BuilderNotFoundException( String.format( "The builder requested using id = %s cannot be found", builderId ) );
            }

            int degreeOfConcurrency = session.getRequest().getDegreeOfConcurrency();
            if ( degreeOfConcurrency >= 2 )
            {
                logger.info( "" );
                logger.info( String.format( "Using the %s implementation with a thread count of %d", builder.getClass().getSimpleName(), degreeOfConcurrency ) );
            }
            builder.build( session, reactorContext, projectBuilds, taskSegments, reactorBuildStatus );

        }
        catch ( Exception e )
        {
            result.addException( e );
        }
        finally
        {
            eventCatapult.fire( ExecutionEvent.Type.SessionEnded, session, null );
        }
View Full Code Here

    @Requirement
    private SessionScope sessionScope;
       
    public MavenExecutionResult execute( MavenExecutionRequest request )
    {
        MavenExecutionResult result;

        try
        {
            result = doExecute( populator.populateDefaults( request ) );
        }
View Full Code Here

    @SuppressWarnings( "checkstyle:methodlength" )
    private MavenExecutionResult doExecute( MavenExecutionRequest request )
    {
        request.setStartTime( new Date() );
       
        MavenExecutionResult result = new DefaultMavenExecutionResult();

        try
        {
            validateLocalRepository( request );
        }
        catch ( LocalRepositoryNotAccessibleException e )
        {
            return addExceptionToResult( result, e );
        }

        DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) newRepositorySession( request );

        MavenSession session = new MavenSession( container, repoSession, request, result );
       
        //
        // We enter the session scope right after the MavenSession creation and before any of the AbstractLifecycleParticipant lookups
        // so that @SessionScoped components can be @Injected into AbstractLifecycleParticipants.
        //
        sessionScope.enter();
        sessionScope.seed( MavenSession.class, session );
       
        legacySupport.setSession( session );

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

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

        List<MavenProject> projects;
        try
        {
            projects = getProjectsForMavenReactor( session );
            //
            // Capture the full set of projects before any potential constraining is performed by --projects
            //
            session.setAllProjects( projects );
        }
        catch ( ProjectBuildingException e )
        {
            return addExceptionToResult( result, e );
        }

        validateProjects( projects );

        //
        // This creates the graph and trims the projects down based on the user request using something like:
        //
        // -pl project0,project2 eclipse:eclipse
        //
        ProjectDependencyGraph projectDependencyGraph = createProjectDependencyGraph( projects, request, result, true );

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

        session.setProjects( projectDependencyGraph.getSortedProjects() );

        try
        {
            session.setProjectMap( getProjectMap( session.getProjects() ) );
        }
        catch ( DuplicateProjectException e )
        {
            return addExceptionToResult( result, e );
        }
       
        WorkspaceReader reactorWorkspace;
        try
        {
            reactorWorkspace = container.lookup( WorkspaceReader.class, ReactorReader.HINT );
        }
        catch ( ComponentLookupException e )
        {
            return addExceptionToResult( result, e );
        }
       
        //
        // Desired order of precedence for local artifact repositories
        //
        // Reactor
        // Workspace
        // User Local Repository
        //       
        repoSession.setWorkspaceReader( ChainedWorkspaceReader.newInstance( reactorWorkspace,
                                                                            repoSession.getWorkspaceReader() ) );

        repoSession.setReadOnly();

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

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

        //
        // The projects need to be topologically after the participants have run their afterProjectsRead(session)
        // because the participant is free to change the dependencies of a project which can potentially change the
        // topological order of the projects, and therefore can potentially change the build order.
        //
        // Note that participants may affect the topological order of the projects but it is
        // not expected that a participant will add or remove projects from the session.
        //
        projectDependencyGraph = createProjectDependencyGraph( session.getProjects(), request, result, false );

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

            session.setProjects( projectDependencyGraph.getSortedProjects() );

            session.setProjectDependencyGraph( projectDependencyGraph );

            result.setTopologicallySortedProjects( session.getProjects() );

            result.setProject( session.getTopLevelProject() );

            lifecycleStarter.execute( session );

            validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() );
View Full Code Here

        EasyMock.expect(requestMock.getUserSettingsFile()).andReturn(null).once();

        EasyMock.expect(requestMock.setExecutionListener(buildInfoRecorder)).andReturn(null).once();
        EasyMock.replay(requestMock);

        MavenExecutionResult resultMock = EasyMock.createMock(MavenExecutionResult.class);

        MavenSession session = new MavenSession(plexusContainerMock, repositorySystemSession, requestMock, resultMock);

        //value is true
        participant.afterProjectsRead(session);
View Full Code Here

            throws Exception
    {
        Maven maven = getContainer().lookup( Maven.class );
        MavenExecutionRequest request = createMavenExecutionRequest( getProject( "cyclic-reference" ) ).setGoals( asList("validate") );

        MavenExecutionResult result = maven.execute( request );

        assertEquals( ProjectCycleException.class, result.getExceptions().get( 0 ).getClass() );
    }
View Full Code Here

        Maven maven = container.lookup( Maven.class );
        File pom = getProject( "lifecycle-listener-dependency-injection" );
        MavenExecutionRequest request = createMavenExecutionRequest( pom );
        request.setGoals( Arrays.asList( "validate" ) );
        MavenExecutionResult result = maven.execute( request );

        assertFalse( result.getExceptions().toString(), result.hasExceptions() );

        MavenProject project = result.getProject();

        assertEquals( "bar", project.getProperties().getProperty( "foo" ) );

        ArrayList<Artifact> artifacts = new ArrayList<Artifact>( project.getArtifacts() );
View Full Code Here

        Maven maven = container.lookup( Maven.class );
        File pom = getProject( testProject );
        MavenExecutionRequest request = createMavenExecutionRequest( pom );
        request.setGoals( Arrays.asList( "validate" ) );
        MavenExecutionResult result = maven.execute( request );

        assertFalse( result.getExceptions().toString(), result.hasExceptions() );

        List<String> order = new ArrayList<String>();
        for ( MavenProject project : result.getTopologicallySortedProjects() )
        {
            order.add( project.getArtifactId() );
        }
        return order;
    }
View Full Code Here

        }
    }
   
    private int execute( CliRequest cliRequest )
    {
        MavenExecutionResult result = maven.execute( cliRequest.request );          
       
        if ( result.hasExceptions() )
        {
            ExceptionHandler handler = new DefaultExceptionHandler();

            Map<String, String> references = new LinkedHashMap<String, String>();

            MavenProject project = null;

            for ( Throwable exception : result.getExceptions() )
            {
                ExceptionSummary summary = handler.handleException( exception );

                logSummary( summary, references, "", cliRequest.showErrors );

                if ( project == null && exception instanceof LifecycleExecutionException )
                {
                    project = ( (LifecycleExecutionException) exception ).getProject();
                }
            }

            logger.error( "" );

            if ( !cliRequest.showErrors )
            {
                logger.error( "To see the full stack trace of the errors, re-run Maven with the -e switch." );
            }
            if ( !logger.isDebugEnabled() )
            {
                logger.error( "Re-run Maven using the -X switch to enable full debug logging." );
            }

            if ( !references.isEmpty() )
            {
                logger.error( "" );
                logger.error( "For more information about the errors and possible solutions" + ", please read the following articles:" );

                for ( Map.Entry<String, String> entry : references.entrySet() )
                {
                    logger.error( entry.getValue() + " " + entry.getKey() );
                }
            }

            if ( project != null && !project.equals( result.getTopologicallySortedProjects().get( 0 ) ) )
            {
                logger.error( "" );
                logger.error( "After correcting the problems, you can resume the build with the command" );
                logger.error( "  mvn <goals> -rf :" + project.getArtifactId() );
            }
View Full Code Here

    public void execute( MavenSession session )
    {
        fireEvent( session, null, LifecycleEventCatapult.SESSION_STARTED );

        MavenExecutionResult result = session.getResult();

        List<ProjectBuild> projectBuilds;

        ProjectIndex projectIndex;

        try
        {
            projectBuilds = calculateProjectBuilds( session );

            projectIndex = new ProjectIndex( session.getProjects() );
        }
        catch ( Exception e )
        {
            result.addException( e );

            fireEvent( session, null, LifecycleEventCatapult.SESSION_ENDED );

            return;
        }

        if ( logger.isDebugEnabled() )
        {
            debugReactorPlan( projectBuilds );
        }

        ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();

        for ( ProjectBuild projectBuild : projectBuilds )
        {
            MavenProject currentProject = projectBuild.project;

            long buildStartTime = System.currentTimeMillis();

            try
            {
                session.setCurrentProject( currentProject );

                if ( session.isBlackListed( currentProject ) )
                {
                    fireEvent( session, null, LifecycleEventCatapult.PROJECT_SKIPPED );

                    continue;
                }

                fireEvent( session, null, LifecycleEventCatapult.PROJECT_STARTED );

                ClassRealm projectRealm = currentProject.getClassRealm();
                if ( projectRealm != null )
                {
                    Thread.currentThread().setContextClassLoader( projectRealm );
                }

                MavenExecutionPlan executionPlan =
                    calculateExecutionPlan( session, currentProject, projectBuild.taskSegment );

                if ( logger.isDebugEnabled() )
                {
                    debugProjectPlan( currentProject, executionPlan );
                }

                // TODO: once we have calculated the build plan then we should accurately be able to download
                // the project dependencies. Having it happen in the plugin manager is a tangled mess. We can optimize
                // this later by looking at the build plan. Would be better to just batch download everything required
                // by the reactor.

                List<MavenProject> projectsToResolve;

                if ( projectBuild.taskSegment.aggregating )
                {
                    projectsToResolve = session.getProjects();
                }
                else
                {
                    projectsToResolve = Collections.singletonList( currentProject );
                }

                for ( MavenProject project : projectsToResolve )
                {
                    resolveProjectDependencies( project, executionPlan.getRequiredCollectionScopes(),
                                                executionPlan.getRequiredResolutionScopes(), session,
                                                projectBuild.taskSegment.aggregating );
                }

                DependencyContext dependencyContext =
                    new DependencyContext( executionPlan, projectBuild.taskSegment.aggregating );

                for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
                {
                    execute( session, mojoExecution, projectIndex, dependencyContext );
                }

                long buildEndTime = System.currentTimeMillis();

                result.addBuildSummary( new BuildSuccess( currentProject, buildEndTime - buildStartTime ) );

                fireEvent( session, null, LifecycleEventCatapult.PROJECT_SUCCEEDED );
            }
            catch ( Exception e )
            {
                result.addException( e );

                long buildEndTime = System.currentTimeMillis();

                result.addBuildSummary( new BuildFailure( currentProject, buildEndTime - buildStartTime, e ) );

                fireEvent( session, null, LifecycleEventCatapult.PROJECT_FAILED );

                if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( session.getReactorFailureBehavior() ) )
                {
View Full Code Here

TOP

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

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.