Java Code Examples for org.apache.maven.execution.MavenSession#getProjectDependencyGraph()

The following examples show how to use org.apache.maven.execution.MavenSession#getProjectDependencyGraph() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmartBuilderImpl.java    From takari-smart-builder with Apache License 2.0 6 votes vote down vote up
SmartBuilderImpl(LifecycleModuleBuilder lifecycleModuleBuilder, MavenSession session,
    ReactorContext reactorContext, TaskSegment taskSegment, Set<MavenProject> projects) {
  this.lifecycleModuleBuilder = lifecycleModuleBuilder;
  this.rootSession = session;
  this.reactorContext = reactorContext;
  this.taskSegment = taskSegment;

  this.degreeOfConcurrency = Integer.valueOf(session.getRequest().getDegreeOfConcurrency());

  final Comparator<MavenProject> projectComparator = ProjectComparator.create(session);

  this.reactorBuildQueue = new ReactorBuildQueue(projects, session.getProjectDependencyGraph());
  this.executor = new ProjectExecutorService(degreeOfConcurrency, projectComparator);

  this.stats = ReactorBuildStats.create(projects);
}
 
Example 2
Source File: IncrementalModuleBuilderImpl.java    From incremental-module-builder with Apache License 2.0 5 votes vote down vote up
IncrementalModuleBuilderImpl( List<MavenProject> selectedProjects, LifecycleModuleBuilder lifecycleModuleBuilder,
                              MavenSession session, ReactorContext reactorContext, List<TaskSegment> taskSegments )
{

    this.lifecycleModuleBuilder =
        Objects.requireNonNull( lifecycleModuleBuilder, "lifecycleModuleBuilder is not allowed to be null." );
    this.mavenSession = Objects.requireNonNull( session, "session is not allowed to be null." );
    this.taskSegments = Objects.requireNonNull( taskSegments, "taskSegements is not allowed to be null" );
    this.reactorContext = Objects.requireNonNull( reactorContext, "reactorContext is not allowed to be null." );

    ProjectDependencyGraph projectDependencyGraph = session.getProjectDependencyGraph();

    List<MavenProject> intermediateResult = new LinkedList<>();

    for ( MavenProject selectedProject : selectedProjects )
    {
        intermediateResult.add( selectedProject );
        // Up or downstream ? (-amd)
        intermediateResult.addAll( projectDependencyGraph.getDownstreamProjects( selectedProject, true ) );
        // TODO: Need to think about this? -am ?
        // intermediateResult.addAll(projectDependencyGraph.getUpstreamProjects(selectedProject,
        // true));
    }

    List<MavenProject> result = new LinkedList<>();

    for ( MavenProject project : intermediateResult )
    {
        if ( !result.contains( project ) )
        {
            result.add( project );
        }
    }

    this.projects = result;

}
 
Example 3
Source File: MavenLifecycleParticipant.java    From gitflow-incremental-builder with MIT License 5 votes vote down vote up
@Override
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {

    if (Configuration.isHelpRequested(session)) {
        logHelp();
    }

    if (!Configuration.isEnabled(session)) {
        logger.info("gitflow-incremental-builder is disabled.");
        return;
    }

    // check prerequisites
    if (session.getProjectDependencyGraph() == null) {
        logger.warn("Execution of gitflow-incremental-builder is not supported in this environment: "
                + "Current MavenSession does not provide a ProjectDependencyGraph. "
                + "Consider disabling gitflow-incremental-builder via property: " + Property.enabled.fullOrShortName());
        return;
    }

    logger.info("gitflow-incremental-builder {} starting...", implVersion);
    try {
        unchangedProjectsRemover.act();
    } catch (Exception e) {
        boolean isSkipExecException = e instanceof SkipExecutionException;
        if (!configProvider.get().failOnError || isSkipExecException) {
            logger.info("gitflow-incremental-builder execution skipped: {}", (isSkipExecException ? e.getMessage() : e.toString()));
            logger.debug("Full exception:", e);
        } else {
            throw new MavenExecutionException("Exception during gitflow-incremental-builder execution occurred.", e);
        }
    }
    logger.info("gitflow-incremental-builder exiting...");
}
 
Example 4
Source File: LifecycleStarter.java    From dew with Apache License 2.0 4 votes vote down vote up
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 = lifecycleTaskSegmentCalculator.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 );
                    lifeCycleWeaveBuilder.build( projectBuilds, callableContext, taskSegments, session, executor,
                                                 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();
                // If the builder has terminated with an exception we want to catch any stray threads before going
                // to System.exit in the mavencli.
                executor.awaitTermination( 5, TimeUnit.SECONDS ) ;
            }
        }
        else
        {
            singleThreadedBuild( session, callableContext, projectBuilds, taskSegments, reactorBuildStatus );
        }

    }
    catch ( Exception e )
    {
        result.addException( e );
    }

    eventCatapult.fire( ExecutionEvent.Type.SessionEnded, session, null );
}
 
Example 5
Source File: ProjectComparator.java    From takari-smart-builder with Apache License 2.0 4 votes vote down vote up
public static Comparator<MavenProject> create(MavenSession session) {
  final ProjectDependencyGraph dependencyGraph = session.getProjectDependencyGraph();
  return create0(DependencyGraph.fromMaven(dependencyGraph), ImmutableMap.of(), p -> id(p));
}