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.lifecycle.MavenExecutionPlan;
23 import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
24 import org.apache.maven.plugin.MojoExecution;
25 import org.apache.maven.plugin.descriptor.MojoDescriptor;
26 import org.apache.maven.project.MavenProject;
27 import org.codehaus.plexus.component.annotations.Component;
28 import org.codehaus.plexus.component.annotations.Requirement;
29 import org.codehaus.plexus.logging.Logger;
30 import org.codehaus.plexus.util.StringUtils;
31
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Set;
36 import java.util.TreeSet;
37
38
39
40
41
42
43
44
45
46
47
48 @Component( role = LifecycleDebugLogger.class )
49 public class LifecycleDebugLogger
50 {
51 @Requirement
52 private Logger logger;
53
54
55 public LifecycleDebugLogger()
56 {
57 }
58
59 public LifecycleDebugLogger( Logger logger )
60 {
61 this.logger = logger;
62 }
63
64
65 public void debug( String s )
66 {
67 logger.debug( s );
68 }
69
70 public void info( String s )
71 {
72 logger.info( s );
73 }
74
75 public void debugReactorPlan( ProjectBuildList projectBuilds )
76 {
77 if ( !logger.isDebugEnabled() )
78 {
79 return;
80 }
81
82 logger.debug( "=== REACTOR BUILD PLAN ================================================" );
83
84 for ( Iterator<ProjectSegment> it = projectBuilds.iterator(); it.hasNext(); )
85 {
86 ProjectSegment projectBuild = it.next();
87
88 logger.debug( "Project: " + projectBuild.getProject().getId() );
89 logger.debug( "Tasks: " + projectBuild.getTaskSegment().getTasks() );
90 logger.debug( "Style: " + ( projectBuild.getTaskSegment().isAggregating() ? "Aggregating" : "Regular" ) );
91
92 if ( it.hasNext() )
93 {
94 logger.debug( "-----------------------------------------------------------------------" );
95 }
96 }
97
98 logger.debug( "=======================================================================" );
99 }
100
101
102 public void debugProjectPlan( MavenProject currentProject, MavenExecutionPlan executionPlan )
103 {
104 if ( !logger.isDebugEnabled() )
105 {
106 return;
107 }
108
109 logger.debug( "=== PROJECT BUILD PLAN ================================================" );
110 logger.debug( "Project: " + BuilderCommon.getKey( currentProject ) );
111
112 debugDependencyRequirements( executionPlan.getMojoExecutions() );
113
114 logger.debug( "Repositories (dependencies): " + currentProject.getRemoteProjectRepositories() );
115 logger.debug( "Repositories (plugins) : " + currentProject.getRemotePluginRepositories() );
116
117 for ( ExecutionPlanItem mojoExecution : executionPlan )
118 {
119 debugMojoExecution( mojoExecution.getMojoExecution() );
120 }
121
122 logger.debug( "=======================================================================" );
123 }
124
125 private void debugMojoExecution( MojoExecution mojoExecution )
126 {
127 String mojoExecId =
128 mojoExecution.getGroupId() + ':' + mojoExecution.getArtifactId() + ':' + mojoExecution.getVersion() + ':'
129 + mojoExecution.getGoal() + " (" + mojoExecution.getExecutionId() + ')';
130
131 Map<String, List<MojoExecution>> forkedExecutions = mojoExecution.getForkedExecutions();
132 if ( !forkedExecutions.isEmpty() )
133 {
134 for ( Map.Entry<String, List<MojoExecution>> fork : forkedExecutions.entrySet() )
135 {
136 logger.debug( "--- init fork of " + fork.getKey() + " for " + mojoExecId + " ---" );
137
138 debugDependencyRequirements( fork.getValue() );
139
140 for ( MojoExecution forkedExecution : fork.getValue() )
141 {
142 debugMojoExecution( forkedExecution );
143 }
144
145 logger.debug( "--- exit fork of " + fork.getKey() + " for " + mojoExecId + " ---" );
146 }
147 }
148
149 logger.debug( "-----------------------------------------------------------------------" );
150 logger.debug( "Goal: " + mojoExecId );
151 logger.debug(
152 "Style: " + ( mojoExecution.getMojoDescriptor().isAggregator() ? "Aggregating" : "Regular" ) );
153 logger.debug( "Configuration: " + mojoExecution.getConfiguration() );
154 }
155
156 private void debugDependencyRequirements( List<MojoExecution> mojoExecutions )
157 {
158 Set<String> scopesToCollect = new TreeSet<String>();
159 Set<String> scopesToResolve = new TreeSet<String>();
160
161 for ( MojoExecution mojoExecution : mojoExecutions )
162 {
163 MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
164
165 String scopeToCollect = mojoDescriptor.getDependencyCollectionRequired();
166 if ( StringUtils.isNotEmpty( scopeToCollect ) )
167 {
168 scopesToCollect.add( scopeToCollect );
169 }
170
171 String scopeToResolve = mojoDescriptor.getDependencyResolutionRequired();
172 if ( StringUtils.isNotEmpty( scopeToResolve ) )
173 {
174 scopesToResolve.add( scopeToResolve );
175 }
176 }
177
178 logger.debug( "Dependencies (collect): " + scopesToCollect );
179 logger.debug( "Dependencies (resolve): " + scopesToResolve );
180 }
181
182 }