View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.lifecycle.internal;
20  
21  import java.util.List;
22  
23  import org.apache.maven.execution.MavenSession;
24  import org.apache.maven.execution.ProjectDependencyGraph;
25  import org.apache.maven.project.MavenProject;
26  
27  /**
28   * A build context that matches a mavenproject to a given tasksegment, and the session to be used.
29   * <p>
30   * A note to the reader;
31   * </p>
32   * <p>
33   * There are several issues/discussions regarding how "aggregator" plugins should be handled.
34   * Read for instance http://docs.codehaus.org/display/MAVEN/Deterministic+Lifecycle+Planning
35   * </p>
36   * <p>
37   * In their current implementation they are "bolted" onto the lifecycle by separating them
38   * into TaskSegments. This class represents the execution context of one such task segment.
39   * </p>
40   * <p>
41   * Wise voices have suggested that maybe aggregators shouldn't be bound to the ordinary
42   * lifecycle at all, in which case we wouldn't be needing this class at all ( and
43   * ProjectBuildList.getByTaskSegments). Or maybe they should be introduced in the calculation
44   * of the execution plan instead, which seems much nicer.
45   * </p>
46   * <p>
47   * Additionally this class contains a clone of the MavenSession, which is *only* needed
48   * because it has as notion of a "current" project.
49   * </p>
50   * <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
51   *
52   * @since 3.0
53   * @author Jason van Zyl
54   * @author Benjamin Bentmann
55   * @author Kristian Rosenvold
56   */
57  public final class ProjectSegment {
58      private final MavenProject project;
59  
60      private final TaskSegment taskSegment;
61  
62      private final MavenSession session;
63  
64      private final List<MavenProject> nonTransitiveUpstreamProjects;
65  
66      private final List<MavenProject> transitiveUpstreamProjects;
67  
68      public ProjectSegment(MavenProject project, TaskSegment taskSegment, MavenSession copiedSession) {
69          this.project = project;
70          this.taskSegment = taskSegment;
71          this.session = copiedSession;
72          final ProjectDependencyGraph dependencyGraph = getSession().getProjectDependencyGraph();
73          nonTransitiveUpstreamProjects = dependencyGraph.getUpstreamProjects(getProject(), false);
74          transitiveUpstreamProjects = dependencyGraph.getUpstreamProjects(getProject(), true);
75      }
76  
77      public MavenSession getSession() {
78          return session;
79      }
80  
81      public MavenProject getProject() {
82          return project;
83      }
84  
85      public TaskSegment getTaskSegment() {
86          return taskSegment;
87      }
88  
89      public List<MavenProject> getImmediateUpstreamProjects() {
90          return nonTransitiveUpstreamProjects;
91      }
92  
93      public List<MavenProject> getTransitiveUpstreamProjects() {
94          return transitiveUpstreamProjects;
95      }
96  
97      @Override
98      public String toString() {
99          return getProject().getId() + " -> " + getTaskSegment();
100     }
101 }