1 package org.apache.maven.toolchain;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.Map;
25
26 import org.apache.maven.toolchain.model.ToolchainModel;
27 import org.codehaus.plexus.logging.Logger;
28
29
30
31
32
33 public abstract class DefaultToolchain
34 implements Toolchain, ToolchainPrivate
35 {
36
37 private String type;
38
39 private Map<String, RequirementMatcher> provides = new HashMap<String, RequirementMatcher>();
40
41 public static final String KEY_TYPE = "type";
42
43 private ToolchainModel model;
44
45 private Logger logger;
46
47 protected DefaultToolchain( ToolchainModel model, Logger logger )
48 {
49 this.model = model;
50
51 this.logger = logger;
52 }
53
54 protected DefaultToolchain( ToolchainModel model, String type, Logger logger )
55 {
56 this( model, logger );
57 this.type = type;
58 }
59
60 public final String getType()
61 {
62 return type != null ? type : model.getType();
63 }
64
65
66 public final ToolchainModel getModel()
67 {
68 return model;
69 }
70
71 public final void addProvideToken( String type, RequirementMatcher matcher )
72 {
73 provides.put( type, matcher );
74 }
75
76
77 public boolean matchesRequirements( Map requirements )
78 {
79 Iterator it = requirements.keySet().iterator();
80 while ( it.hasNext() )
81 {
82 String key = (String) it.next();
83
84 RequirementMatcher matcher = provides.get( key );
85
86 if ( matcher == null )
87 {
88 getLog().debug( "Toolchain " + this + " is missing required property: " + key );
89 return false;
90 }
91 if ( !matcher.matches( (String) requirements.get( key ) ) )
92 {
93 getLog().debug( "Toolchain " + this + " doesn't match required property: " + key );
94 return false;
95 }
96 }
97 return true;
98 }
99
100 protected Logger getLog()
101 {
102 return logger;
103 }
104 }