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