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
35 class ValidatingConfigurationListener implements ConfigurationListener {
36 private final Object mojo;
37
38 private final ConfigurationListener delegate;
39
40 private final Map<String, Parameter> missingParameters;
41
42 ValidatingConfigurationListener(Object mojo, MojoDescriptor mojoDescriptor, ConfigurationListener delegate) {
43 this.mojo = mojo;
44 this.delegate = delegate;
45 this.missingParameters = new HashMap<>();
46
47 if (mojoDescriptor.getParameters() != null) {
48 for (Parameter param : mojoDescriptor.getParameters()) {
49 if (param.isRequired()) {
50 missingParameters.put(param.getName(), param);
51 }
52 }
53 }
54 }
55
56 public Collection<Parameter> getMissingParameters() {
57 return missingParameters.values();
58 }
59
60 public void notifyFieldChangeUsingSetter(String fieldName, Object value, Object target) {
61 delegate.notifyFieldChangeUsingSetter(fieldName, value, target);
62
63 if (mojo == target) {
64 notify(fieldName, value);
65 }
66 }
67
68 public void notifyFieldChangeUsingReflection(String fieldName, Object value, Object target) {
69 delegate.notifyFieldChangeUsingReflection(fieldName, value, target);
70
71 if (mojo == target) {
72 notify(fieldName, value);
73 }
74 }
75
76 private void notify(String fieldName, Object value) {
77 if (value != null) {
78 missingParameters.remove(fieldName);
79 }
80 }
81 }