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.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   * @author mkleint
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"; //NOI18N
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 }