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