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.artifact.repository.ArtifactRepository;
24 import org.apache.maven.execution.MavenSession;
25 import org.apache.maven.plugin.AbstractMojo;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugin.MojoFailureException;
28 import org.apache.maven.plugins.annotations.Component;
29 import org.apache.maven.plugins.annotations.Parameter;
30 import org.apache.maven.plugins.dependency.utils.DependencySilentLog;
31 import org.apache.maven.project.DefaultProjectBuildingRequest;
32 import org.apache.maven.project.MavenProject;
33 import org.apache.maven.project.ProjectBuildingRequest;
34 import org.sonatype.plexus.build.incremental.BuildContext;
35
36
37
38
39 public abstract class AbstractDependencyMojo extends AbstractMojo {
40
41
42
43
44 @Component
45 private BuildContext buildContext;
46
47
48
49
50
51
52
53 @Parameter(defaultValue = "false")
54 private boolean skipDuringIncrementalBuild;
55
56
57
58
59 @Component
60 private MavenProject project;
61
62
63
64
65 @Parameter(defaultValue = "${project.remoteArtifactRepositories}", readonly = true, required = true)
66 private List<ArtifactRepository> remoteRepositories;
67
68
69
70
71 @Parameter(defaultValue = "${project.pluginArtifactRepositories}", readonly = true, required = true)
72 private List<ArtifactRepository> remotePluginRepositories;
73
74
75
76
77 @Parameter(defaultValue = "${reactorProjects}", readonly = true)
78 protected List<MavenProject> reactorProjects;
79
80
81
82
83 @Component
84 protected MavenSession session;
85
86
87
88
89
90
91 @Parameter(property = "silent", defaultValue = "false")
92 private boolean silent;
93
94
95
96
97
98
99 @Parameter(property = "mdep.skip", defaultValue = "false")
100 private boolean skip;
101
102
103
104
105
106
107 @Override
108 public final void execute() throws MojoExecutionException, MojoFailureException {
109 if (isSkip()) {
110 getLog().info("Skipping plugin execution");
111 return;
112 }
113
114 doExecute();
115 }
116
117
118
119
120
121 protected abstract void doExecute() throws MojoExecutionException, MojoFailureException;
122
123
124
125
126
127 public ProjectBuildingRequest newResolveArtifactProjectBuildingRequest() {
128 return newProjectBuildingRequest(remoteRepositories);
129 }
130
131
132
133
134
135 protected ProjectBuildingRequest newResolvePluginProjectBuildingRequest() {
136 return newProjectBuildingRequest(remotePluginRepositories);
137 }
138
139 private ProjectBuildingRequest newProjectBuildingRequest(List<ArtifactRepository> repositories) {
140 ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
141
142 buildingRequest.setRemoteRepositories(repositories);
143
144 return buildingRequest;
145 }
146
147
148
149
150 public MavenProject getProject() {
151 return this.project;
152 }
153
154
155
156
157 public boolean isSkip() {
158 if (skipDuringIncrementalBuild && buildContext.isIncremental()) {
159 return true;
160 }
161 return skip;
162 }
163
164
165
166
167 public void setSkip(boolean skip) {
168 this.skip = skip;
169 }
170
171
172
173
174 protected final boolean isSilent() {
175 return silent;
176 }
177
178
179
180
181 public void setSilent(boolean silent) {
182 this.silent = silent;
183 if (silent) {
184 setLog(new DependencySilentLog());
185 }
186 }
187 }