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 * <p>
34 * There are several issues/discussions regarding how "aggregator" plugins should be handled.
35 * Read for instance http://docs.codehaus.org/display/MAVEN/Deterministic+Lifecycle+Planning
36 * </p>
37 * <p>
38 * In their current implementation they are "bolted" onto the lifecycle by separating them
39 * into TaskSegments. This class represents the execution context of one such task segment.
40 * </p>
41 * <p>
42 * Wise voices have suggested that maybe aggregators shouldn't be bound to the ordinary
43 * lifecycle at all, in which case we wouldn't be needing this class at all ( and
44 * ProjectBuildList.getByTaskSegments). Or maybe they should be introduced in the calculation
45 * of the execution plan instead, which seems much nicer.
46 * </p>
47 * <p>
48 * Additionally this class contains a clone of the MavenSession, which is *only* needed
49 * because it has as notion of a "current" project.
50 * </p>
51 * <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
52 *
53 * @since 3.0
54 * @author Jason van Zyl
55 * @author Benjamin Bentmann
56 * @author Kristian Rosenvold
57 */
58 public final class ProjectSegment
59 {
60 private final MavenProject project;
61
62 private final TaskSegment taskSegment;
63
64 private final MavenSession session;
65
66 private final List<MavenProject> nonTransitiveUpstreamProjects;
67
68 private final List<MavenProject> transitiveUpstreamProjects;
69
70 public ProjectSegment( MavenProject project, TaskSegment taskSegment, MavenSession copiedSession )
71 {
72 this.project = project;
73 this.taskSegment = taskSegment;
74 this.session = copiedSession;
75 final ProjectDependencyGraph dependencyGraph = getSession().getProjectDependencyGraph();
76 nonTransitiveUpstreamProjects = dependencyGraph.getUpstreamProjects( getProject(), false );
77 transitiveUpstreamProjects = dependencyGraph.getUpstreamProjects( getProject(), true );
78 }
79
80 public MavenSession getSession()
81 {
82 return session;
83 }
84
85 public MavenProject getProject()
86 {
87 return project;
88 }
89
90 public TaskSegment getTaskSegment()
91 {
92 return taskSegment;
93 }
94
95 public List<MavenProject> getImmediateUpstreamProjects()
96 {
97 return nonTransitiveUpstreamProjects;
98 }
99
100 public List<MavenProject> getTransitiveUpstreamProjects()
101 {
102 return transitiveUpstreamProjects;
103 }
104
105 @Override
106 public String toString()
107 {
108 return getProject().getId() + " -> " + getTaskSegment();
109 }
110 }