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