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 logger.debug( "Repositories (dependencies): " + currentProject.getRemoteProjectRepositories() );
117 logger.debug( "Repositories (plugins) : " + currentProject.getRemotePluginRepositories() );
118
119 for ( ExecutionPlanItem mojoExecution : executionPlan )
120 {
121 debugMojoExecution( mojoExecution.getMojoExecution() );
122 }
123
124 logger.debug( "=======================================================================" );
125 }
126
127 private void debugMojoExecution( MojoExecution mojoExecution )
128 {
129 String mojoExecId =
130 mojoExecution.getGroupId() + ':' + mojoExecution.getArtifactId() + ':' + mojoExecution.getVersion() + ':'
131 + mojoExecution.getGoal() + " (" + mojoExecution.getExecutionId() + ')';
132
133 Map<String, List<MojoExecution>> forkedExecutions = mojoExecution.getForkedExecutions();
134 if ( !forkedExecutions.isEmpty() )
135 {
136 for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() )
137 {
138 logger.debug( "--- init fork of " + fork.getKey() + " for " + mojoExecId + " ---" );
139
140 debugDependencyRequirements( fork.getValue() );
141
142 for ( MojoExecution forkedExecution : fork.getValue() )
143 {
144 debugMojoExecution( forkedExecution );
145 }
146
147 logger.debug( "--- exit fork of " + fork.getKey() + " for " + mojoExecId + " ---" );
148 }
149 }
150
151 logger.debug( "-----------------------------------------------------------------------" );
152 logger.debug( "Goal: " + mojoExecId );
153 logger.debug(
154 "Style: " + ( mojoExecution.getMojoDescriptor().isAggregator() ? "Aggregating" : "Regular" ) );
155 logger.debug( "Configuration: " + mojoExecution.getConfiguration() );
156 }
157
158 private void debugDependencyRequirements( List<MojoExecution> mojoExecutions )
159 {
160 Set<String> scopesToCollect = new TreeSet<String>();
161 Set<String> scopesToResolve = new TreeSet<String>();
162
163 for ( MojoExecution mojoExecution : mojoExecutions )
164 {
165 MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
166
167 String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();
168 if ( StringUtils.isNotEmpty( scopeToCollect ) )
169 {
170 scopesToCollect.add( scopeToCollect );
171 }
172
173 String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
174 if ( StringUtils.isNotEmpty( scopeToResolve ) )
175 {
176 scopesToResolve.add( scopeToResolve );
177 }
178 }
179
180 logger.debug( "Dependencies (collect): " + scopesToCollect );
181 logger.debug( "Dependencies (resolve): " + scopesToResolve );
182 }
183
184 public void logWeavePlan( MavenSession session )
185 {
186 if ( !logger.isInfoEnabled() )
187 {
188 return;
189 }
190
191 final ProjectDependencyGraph dependencyGraph = session.getProjectDependencyGraph();
192 logger.info( "=== WEAVE CONCURRENCY BUILD PLAN ======================================" );
193 for ( MavenProject mavenProject : dependencyGraph.getSortedProjects() )
194 {
195
196 StringBuilder item = new StringBuilder();
197 item.append( "Project: " );
198 item.append( mavenProject.getArtifactId() );
199 final List<MavenProject> upstreamProjects = dependencyGraph.getUpstreamProjects( mavenProject, false );
200 if ( upstreamProjects.size() > 0 )
201 {
202 item.append( " ( " );
203 for ( Iterator<MavenProject> it = upstreamProjects.iterator(); it.hasNext(); )
204 {
205 final MavenProject kid = it.next();
206 item.append( kid.getArtifactId() );
207 if ( it.hasNext() )
208 {
209 item.append( ", " );
210 }
211 }
212 item.append( ")" );
213 }
214 logger.info( item.toString() );
215
216 }
217 logger.info( "=======================================================================" );
218 }
219 }