View Javadoc
1   package org.apache.maven.toolchain;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  import org.apache.maven.toolchain.model.ToolchainModel;
26  import org.codehaus.plexus.logging.Logger;
27  
28  /**
29   *
30   * @author mkleint
31   */
32  public abstract class DefaultToolchain
33      implements Toolchain, ToolchainPrivate
34  {
35  
36      private String type;
37  
38      private Map<String, RequirementMatcher> provides = new HashMap<String, RequirementMatcher>();
39  
40      public static final String KEY_TYPE = "type"; //NOI18N
41  
42      private ToolchainModel model;
43  
44      private Logger logger;
45  
46      protected DefaultToolchain( ToolchainModel model, Logger logger )
47      {
48          this.model = model;
49  
50          this.logger = logger;
51      }
52  
53      protected DefaultToolchain( ToolchainModel model, String type, Logger logger )
54      {
55          this( model, logger );
56          this.type = type;
57      }
58  
59      public final String getType()
60      {
61          return type != null ? type : model.getType();
62      }
63  
64  
65      public final ToolchainModel getModel()
66      {
67          return model;
68      }
69  
70      public final void addProvideToken( String type, RequirementMatcher matcher )
71      {
72          provides.put( type, matcher );
73      }
74  
75  
76      public boolean matchesRequirements( Map<String, String> requirements )
77      {
78          for ( Map.Entry<String, String> requirement : requirements.entrySet() )
79          {
80              String key = requirement.getKey();
81  
82              RequirementMatcher matcher = provides.get( key );
83  
84              if ( matcher == null )
85              {
86                  getLog().debug( "Toolchain " + this + " is missing required property: " + key );
87                  return false;
88              }
89              if ( !matcher.matches( requirement.getValue() ) )
90              {
91                  getLog().debug( "Toolchain " + this + " doesn't match required property: " + key );
92                  return false;
93              }
94          }
95          return true;
96      }
97  
98      protected Logger getLog()
99      {
100         return logger;
101     }
102 }