1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.internal;
20
21 import java.util.Collection;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.maven.plugin.descriptor.MojoDescriptor;
26 import org.apache.maven.plugin.descriptor.Parameter;
27 import org.codehaus.plexus.component.configurator.ConfigurationListener;
28
29
30
31
32
33
34 class ValidatingConfigurationListener implements ConfigurationListener {
35 private final Object mojo;
36
37 private final ConfigurationListener delegate;
38
39 private final Map<String, Parameter> missingParameters;
40
41 ValidatingConfigurationListener(Object mojo, MojoDescriptor mojoDescriptor, ConfigurationListener delegate) {
42 this.mojo = mojo;
43 this.delegate = delegate;
44 this.missingParameters = new HashMap<>();
45
46 if (mojoDescriptor.getParameters() != null) {
47 for (Parameter param : mojoDescriptor.getParameters()) {
48 if (param.isRequired()) {
49 missingParameters.put(param.getName(), param);
50 }
51 }
52 }
53 }
54
55 public Collection<Parameter> getMissingParameters() {
56 return missingParameters.values();
57 }
58
59 public void notifyFieldChangeUsingSetter(String fieldName, Object value, Object target) {
60 delegate.notifyFieldChangeUsingSetter(fieldName, value, target);
61
62 if (mojo == target) {
63 notify(fieldName, value);
64 }
65 }
66
67 public void notifyFieldChangeUsingReflection(String fieldName, Object value, Object target) {
68 delegate.notifyFieldChangeUsingReflection(fieldName, value, target);
69
70 if (mojo == target) {
71 notify(fieldName, value);
72 }
73 }
74
75 private void notify(String fieldName, Object value) {
76 if (value != null) {
77 missingParameters.remove(fieldName);
78 }
79 }
80 }