1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.dependency;
20
21 import java.util.List;
22
23 import org.apache.maven.execution.MavenSession;
24 import org.apache.maven.plugin.AbstractMojo;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException;
27 import org.apache.maven.plugin.logging.SystemStreamLog;
28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.plugins.dependency.utils.DependencySilentLog;
30 import org.apache.maven.project.MavenProject;
31 import org.sonatype.plexus.build.incremental.BuildContext;
32
33
34
35
36 public abstract class AbstractDependencyMojo extends AbstractMojo {
37
38
39
40
41 @Parameter(defaultValue = "${reactorProjects}", readonly = true)
42 protected List<MavenProject> reactorProjects;
43
44
45
46
47 protected final MavenSession session;
48
49
50
51
52
53
54
55 @Deprecated
56 @Parameter(property = "silent", defaultValue = "false")
57 private boolean silent;
58
59
60
61
62
63
64 @Parameter(property = "mdep.skip", defaultValue = "false")
65 private boolean skip;
66
67
68
69
70
71
72
73 @Parameter(defaultValue = "false")
74 private boolean skipDuringIncrementalBuild;
75
76
77
78
79 private final BuildContext buildContext;
80
81
82
83
84 private final MavenProject project;
85
86 protected AbstractDependencyMojo(MavenSession session, BuildContext buildContext, MavenProject project) {
87 this.session = session;
88 this.buildContext = buildContext;
89 this.project = project;
90 }
91
92
93
94
95
96
97 @Override
98 public final void execute() throws MojoExecutionException, MojoFailureException {
99 if (isSkip()) {
100 getLog().info("Skipping plugin execution");
101 return;
102 }
103
104 doExecute();
105 }
106
107
108
109
110
111 protected abstract void doExecute() throws MojoExecutionException, MojoFailureException;
112
113
114
115
116 public MavenProject getProject() {
117 return this.project;
118 }
119
120
121
122
123 public boolean isSkip() {
124 if (skipDuringIncrementalBuild && buildContext.isIncremental()) {
125 return true;
126 }
127 return skip;
128 }
129
130
131
132
133 public void setSkip(boolean skip) {
134 this.skip = skip;
135 }
136
137
138
139
140
141 @Deprecated
142 protected final boolean isSilent() {
143 return silent;
144 }
145
146
147
148
149
150 @Deprecated
151 public void setSilent(boolean silent) {
152 this.silent = silent;
153 if (silent) {
154 setLog(new DependencySilentLog());
155 } else if (getLog() instanceof DependencySilentLog) {
156 setLog(new SystemStreamLog());
157 }
158 }
159 }