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.Map;
24 import java.util.Properties;
25
26 import org.apache.maven.toolchain.model.ToolchainModel;
27 import org.codehaus.plexus.logging.Logger;
28
29
30
31
32
33
34
35
36 public abstract class DefaultToolchain
37 implements Toolchain, ToolchainPrivate
38 {
39
40 private String type;
41
42 private Map<String, RequirementMatcher> provides = new HashMap<String, RequirementMatcher>();
43
44 public static final String KEY_TYPE = "type";
45
46 private ToolchainModel model;
47
48 private Logger logger;
49
50 protected DefaultToolchain( ToolchainModel model, Logger logger )
51 {
52 this.model = model;
53
54 this.logger = logger;
55 }
56
57 protected DefaultToolchain( ToolchainModel model, String type, Logger logger )
58 {
59 this( model, logger );
60 this.type = type;
61 }
62
63 @Override
64 public final String getType()
65 {
66 return type != null ? type : model.getType();
67 }
68
69 @Override
70 public final ToolchainModel getModel()
71 {
72 return model;
73 }
74
75 public final void addProvideToken( String type, RequirementMatcher matcher )
76 {
77 provides.put( type, matcher );
78 }
79
80 @Override
81 public boolean matchesRequirements( Map<String, String> requirements )
82 {
83 for ( Map.Entry<String, String> requirement : requirements.entrySet() )
84 {
85 String key = requirement.getKey();
86
87 RequirementMatcher matcher = provides.get( key );
88
89 if ( matcher == null )
90 {
91 getLog().debug( "Toolchain " + this + " is missing required property: " + key );
92 return false;
93 }
94 if ( !matcher.matches( requirement.getValue() ) )
95 {
96 getLog().debug( "Toolchain " + this + " doesn't match required property: " + key );
97 return false;
98 }
99 }
100 return true;
101 }
102
103 protected Logger getLog()
104 {
105 return logger;
106 }
107
108 @Override
109 public boolean equals( Object obj )
110 {
111 if ( obj == null )
112 {
113 return false;
114 }
115
116 if ( this == obj )
117 {
118 return true;
119 }
120
121 if ( !( obj instanceof DefaultToolchain ) )
122 {
123 return false;
124 }
125
126 DefaultToolchain other = (DefaultToolchain) obj;
127
128 if ( type == null ? other.type != null : !type.equals( other.type ) )
129 {
130 return false;
131 }
132
133 Properties thisProvides = this.getModel().getProvides();
134 Properties otherProvides = other.getModel().getProvides();
135
136 if ( thisProvides == null ? otherProvides != null : !thisProvides.equals( otherProvides ) )
137 {
138 return false;
139 }
140
141 return true;
142 }
143
144 @Override
145 public int hashCode()
146 {
147 int hashCode = ( type == null ) ? 0 : type.hashCode();
148
149 if ( this.getModel().getProvides() != null )
150 {
151 hashCode = 31 * hashCode + this.getModel().getProvides().hashCode();
152 }
153 return hashCode;
154 }
155 }