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.lifecycle.internal.builder.BuilderCommon;
26 import org.apache.maven.plugin.MojoExecution;
27 import org.apache.maven.plugin.descriptor.MojoDescriptor;
28 import org.apache.maven.project.MavenProject;
29 import org.codehaus.plexus.component.annotations.Component;
30 import org.codehaus.plexus.component.annotations.Requirement;
31 import org.codehaus.plexus.logging.Logger;
32 import org.codehaus.plexus.util.StringUtils;
33
34 import java.util.Iterator;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Set;
38 import java.util.TreeSet;
39
40
41
42
43
44
45
46
47
48
49
50 @Component( role = LifecycleDebugLogger.class )
51 public class LifecycleDebugLogger
52 {
53 @Requirement
54 private Logger logger;
55
56
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 }