1 package org.apache.maven.lifecycle.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.execution.MavenSession;
23 import org.apache.maven.execution.ProjectDependencyGraph;
24 import org.apache.maven.lifecycle.MavenExecutionPlan;
25 import org.apache.maven.plugin.MojoExecution;
26 import org.apache.maven.plugin.descriptor.MojoDescriptor;
27 import org.apache.maven.project.MavenProject;
28 import org.codehaus.plexus.component.annotations.Component;
29 import org.codehaus.plexus.component.annotations.Requirement;
30 import org.codehaus.plexus.logging.Logger;
31 import org.codehaus.plexus.util.StringUtils;
32
33 import java.util.Iterator;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Set;
37 import java.util.TreeSet;
38
39
40
41
42
43
44
45
46
47
48
49 @Component( role = LifecycleDebugLogger.class )
50 public class LifecycleDebugLogger
51 {
52 @Requirement
53 private Logger logger;
54
55
56 @SuppressWarnings( { "UnusedDeclaration" } )
57 public LifecycleDebugLogger()
58 {
59 }
60
61 public LifecycleDebugLogger( Logger logger )
62 {
63 this.logger = logger;
64 }
65
66
67 public void debug( String s )
68 {
69 logger.debug( s );
70 }
71
72 public void info( String s )
73 {
74 logger.info( s );
75 }
76
77 public void debugReactorPlan( ProjectBuildList projectBuilds )
78 {
79 if ( !logger.isDebugEnabled() )
80 {
81 return;
82 }
83
84 logger.debug( "=== REACTOR BUILD PLAN ================================================" );
85
86 for ( Iterator<ProjectSegment> it = projectBuilds.iterator(); it.hasNext(); )
87 {
88 ProjectSegment projectBuild = it.next();
89
90 logger.debug( "Project: " + projectBuild.getProject().getId() );
91 logger.debug( "Tasks: " + projectBuild.getTaskSegment().getTasks() );
92 logger.debug( "Style: " + ( projectBuild.getTaskSegment().isAggregating() ? "Aggregating" : "Regular" ) );
93
94 if ( it.hasNext() )
95 {
96 logger.debug( "-----------------------------------------------------------------------" );
97 }
98 }
99
100 logger.debug( "=======================================================================" );
101 }
102
103
104 public void debugProjectPlan( MavenProject currentProject, MavenExecutionPlan executionPlan )
105 {
106 if ( !logger.isDebugEnabled() )
107 {
108 return;
109 }
110
111 logger.debug( "=== PROJECT BUILD PLAN ================================================" );
112 logger.debug( "Project: " + BuilderCommon.getKey( currentProject ) );
113
114 debugDependencyRequirements( executionPlan.getMojoExecutions() );
115
116 for ( ExecutionPlanItem mojoExecution : executionPlan )
117 {
118 debugMojoExecution( mojoExecution.getMojoExecution() );
119 }
120
121 logger.debug( "=======================================================================" );
122 }
123
124 private void debugMojoExecution( MojoExecution mojoExecution )
125 {
126 String mojoExecId =
127 mojoExecution.getGroupId() + ':' + mojoExecution.getArtifactId() + ':' + mojoExecution.getVersion() + ':'
128 + mojoExecution.getGoal() + " (" + mojoExecution.getExecutionId() + ')';
129
130 Map<String, List<MojoExecution>> forkedExecutions = mojoExecution.getForkedExecutions();
131 if ( !forkedExecutions.isEmpty() )
132 {
133 for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() )
134 {
135 logger.debug( "--- init fork of " + fork.getKey() + " for " + mojoExecId + " ---" );
136
137 debugDependencyRequirements( fork.getValue() );
138
139 for ( MojoExecution forkedExecution : fork.getValue() )
140 {
141 debugMojoExecution( forkedExecution );
142 }
143
144 logger.debug( "--- exit fork of " + fork.getKey() + " for " + mojoExecId + " ---" );
145 }
146 }
147
148 logger.debug( "-----------------------------------------------------------------------" );
149 logger.debug( "Goal: " + mojoExecId );
150 logger.debug(
151 "Style: " + ( mojoExecution.getMojoDescriptor().isAggregator() ? "Aggregating" : "Regular" ) );
152 logger.debug( "Configuration: " + mojoExecution.getConfiguration() );
153 }
154
155 private void debugDependencyRequirements( List<MojoExecution> mojoExecutions )
156 {
157 Set<String> scopesToCollect = new TreeSet<String>();
158 Set<String> scopesToResolve = new TreeSet<String>();
159
160 for ( MojoExecution mojoExecution : mojoExecutions )
161 {
162 MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
163
164 String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();
165 if ( StringUtils.isNotEmpty( scopeToCollect ) )
166 {
167 scopesToCollect.add( scopeToCollect );
168 }
169
170 String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
171 if ( StringUtils.isNotEmpty( scopeToResolve ) )
172 {
173 scopesToResolve.add( scopeToResolve );
174 }
175 }
176
177 logger.debug( "Dependencies (collect): " + scopesToCollect );
178 logger.debug( "Dependencies (resolve): " + scopesToResolve );
179 }
180
181 public void logWeavePlan( MavenSession session )
182 {
183 if ( !logger.isInfoEnabled() )
184 {
185 return;
186 }
187
188 final ProjectDependencyGraph dependencyGraph = session.getProjectDependencyGraph();
189 logger.info( "=== WEAVE CONCURRENCY BUILD PLAN ======================================" );
190 for ( MavenProject mavenProject : dependencyGraph.getSortedProjects() )
191 {
192
193 StringBuilder item = new StringBuilder();
194 item.append( "Project: " );
195 item.append( mavenProject.getArtifactId() );
196 final List<MavenProject> upstreamProjects = dependencyGraph.getUpstreamProjects( mavenProject, false );
197 if ( upstreamProjects.size() > 0 )
198 {
199 item.append( " ( " );
200 for ( Iterator<MavenProject> it = upstreamProjects.iterator(); it.hasNext(); )
201 {
202 final MavenProject kid = it.next();
203 item.append( kid.getArtifactId() );
204 if ( it.hasNext() )
205 {
206 item.append( ", " );
207 }
208 }
209 item.append( ")" );
210 }
211 logger.info( item.toString() );
212
213 }
214 logger.info( "=======================================================================" );
215 }
216 }