1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.codehaus.plexus.maven.plugin;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.codehaus.plexus.component.repository.cdc.ComponentDescriptor;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26
27
28
29
30
31 public abstract class ComponentDescriptorExtractorSupport
32 implements ComponentDescriptorExtractor
33 {
34 protected final Logger log = LoggerFactory.getLogger(getClass());
35
36 protected Map getDefaultsByRole(final ComponentDescriptor[] roleDefaults) {
37 Map defaultsByRole = new HashMap();
38
39 if (roleDefaults != null) {
40 for (int i = 0; i < roleDefaults.length; i++) {
41 String role = roleDefaults[i].getRole();
42
43 if (role == null) {
44 throw new IllegalArgumentException("Invalid role defaults; found null role in: " + roleDefaults[i]);
45 }
46
47 defaultsByRole.put(role, roleDefaults[i]);
48 }
49 }
50
51 return defaultsByRole;
52 }
53
54 protected void applyDefaults(final ComponentDescriptor descriptor, final Map defaultsByRole) {
55 assert descriptor != null;
56 assert defaultsByRole != null;
57
58 if (defaultsByRole.containsKey(descriptor.getRole())) {
59 ComponentDescriptor defaults = (ComponentDescriptor) defaultsByRole.get(descriptor.getRole());
60
61 if (descriptor.getInstantiationStrategy() == null) {
62 descriptor.setInstantiationStrategy(defaults.getInstantiationStrategy());
63 }
64 }
65 }
66 }