View Javadoc

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