Package org.apache.maven.execution

Examples of org.apache.maven.execution.MavenExecutionResult


        }
    }

    public MavenExecutionResult execute( MavenExecutionRequest request )
    {
        MavenExecutionResult result;

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


            request.getSystemProperties().put( "${build.timestamp}", new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) );
        }       
       
        request.setStartTime( new Date() );
       
        MavenExecutionResult result = new DefaultMavenExecutionResult();

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

        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 );
        }

        fireEvent( session, ExecutionEventCatapult.PROJECT_DISCOVERY_STARTED );

        //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() );

        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 );
        }

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

            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() );

        // Desired order of precedence for local artifact repositories
        //
        // Reactor
        // Workspace
        // User Local Repository
        delegatingLocalArtifactRepository.setBuildReactor( new ReactorArtifactRepository( projectMap, session ) );
       
        if ( result.hasExceptions() )
        {
            return result;
        }

        lifecycleExecutor.execute( session );
View Full Code Here

    @Requirement
    private ExecutionEventCatapult eventCatapult;

    public MavenExecutionResult execute( MavenExecutionRequest request )
    {
        MavenExecutionResult result;

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

            request.getSystemProperties().put( "${build.timestamp}", new SimpleDateFormat( "yyyyMMdd-hhmm" ).format( request.getStartTime() ) );
        }       
       
        request.setStartTime( new Date() );
       
        MavenExecutionResult result = new DefaultMavenExecutionResult();

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

        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;
        }

        lifecycleExecutor.execute( session );
View Full Code Here

    public void execute( MavenSession session )
    {
        eventCatapult.fire( ExecutionEvent.Type.SessionStarted, session, null );

        MavenExecutionResult result = session.getResult();

        try
        {
            if ( !session.isUsingPOMsFromFilesystem() && lifecycleTaskSegmentCalculator.requiresProject( 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." );
            }

            final MavenExecutionRequest executionRequest = session.getRequest();
            boolean isThreaded = executionRequest.isThreadConfigurationPresent();
            session.setParallel( isThreaded );

            List<TaskSegment> taskSegments = buildListCalculator.calculateTaskSegments( session );

            ProjectBuildList 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 callableContext =
                new ReactorContext( result, projectIndex, oldContextClassLoader, reactorBuildStatus );

            if ( isThreaded )
            {
                ExecutorService executor = threadConfigService.getExecutorService( executionRequest.getThreadCount(),
                                                                                   executionRequest.isPerCoreThreadCount(),
                                                                                   session.getProjects().size() );
                try
                {

                    final boolean isWeaveMode = LifecycleWeaveBuilder.isWeaveMode( executionRequest );
                    if ( isWeaveMode )
                    {
                        lifecycleDebugLogger.logWeavePlan( session );
                        CompletionService<ProjectSegment> service =
                            new ExecutorCompletionService<ProjectSegment>( executor );
                        lifeCycleWeaveBuilder.build( projectBuilds, callableContext, taskSegments, session, service,
                                                     reactorBuildStatus );
                    }
                    else
                    {
                        ConcurrencyDependencyGraph analyzer =
                            new ConcurrencyDependencyGraph( projectBuilds, session.getProjectDependencyGraph() );

                        CompletionService<ProjectSegment> service =
                            new ExecutorCompletionService<ProjectSegment>( executor );

                        lifecycleThreadedBuilder.build( session, callableContext, projectBuilds, taskSegments, analyzer,
                                                        service );
                    }
                }
                finally
                {
                    executor.shutdown();
                }
            }
            else
            {
                singleThreadedBuild( session, callableContext, projectBuilds, taskSegments, reactorBuildStatus );
            }

        }

        catch (

            Exception e

            )

        {
            result.addException( e );
        }

        eventCatapult.fire( ExecutionEvent.Type.SessionEnded, session, null );
    }
View Full Code Here

    }


    private ReactorContext createBuildContext( MavenSession session )
    {
        MavenExecutionResult mavenExecutionResult = new DefaultMavenExecutionResult();
        ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus( session.getProjectDependencyGraph() );
        return new ReactorContext( mavenExecutionResult, null, null, reactorBuildStatus );
    }
View Full Code Here

        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( ' ' );
            while ( buffer.length() < LINE_LENGTH - 21 )
            {
                buffer.append( '.' );
            }
            buffer.append( ' ' );

            BuildSummary buildSummary = result.getBuildSummary( project );

            if ( buildSummary == null )
            {
                buffer.append( "SKIPPED" );
            }
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.hasExceptions() );

        MavenProject project = result.getProject();
       
        assertEquals( "bar", project.getProperties().getProperty( "foo" ) );

        ArrayList<Artifact> artifacts = new ArrayList<Artifact>( project.getArtifacts() );
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 MavenExecutionResult execute( MavenExecutionRequest request )
    {
        MavenExecutionResult result;

        try
        {
            result = doExecute( populator.populateDefaults( request ) );
        }
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.