001 package org.apache.maven.toolchain;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.HashMap;
023 import java.util.Map;
024
025 import org.apache.maven.toolchain.model.ToolchainModel;
026 import org.codehaus.plexus.logging.Logger;
027
028 /**
029 *
030 * @author mkleint
031 */
032 public abstract class DefaultToolchain
033 implements Toolchain, ToolchainPrivate
034 {
035
036 private String type;
037
038 private Map<String, RequirementMatcher> provides = new HashMap<String, RequirementMatcher>();
039
040 public static final String KEY_TYPE = "type"; //NOI18N
041
042 private ToolchainModel model;
043
044 private Logger logger;
045
046 protected DefaultToolchain( ToolchainModel model, Logger logger )
047 {
048 this.model = model;
049
050 this.logger = logger;
051 }
052
053 protected DefaultToolchain( ToolchainModel model, String type, Logger logger )
054 {
055 this( model, logger );
056 this.type = type;
057 }
058
059 public final String getType()
060 {
061 return type != null ? type : model.getType();
062 }
063
064
065 public final ToolchainModel getModel()
066 {
067 return model;
068 }
069
070 public final void addProvideToken( String type, RequirementMatcher matcher )
071 {
072 provides.put( type, matcher );
073 }
074
075
076 public boolean matchesRequirements( Map<String, String> requirements )
077 {
078 for ( Map.Entry<String, String> requirement : requirements.entrySet() )
079 {
080 String key = requirement.getKey();
081
082 RequirementMatcher matcher = provides.get( key );
083
084 if ( matcher == null )
085 {
086 getLog().debug( "Toolchain " + this + " is missing required property: " + key );
087 return false;
088 }
089 if ( !matcher.matches( requirement.getValue() ) )
090 {
091 getLog().debug( "Toolchain " + this + " doesn't match required property: " + key );
092 return false;
093 }
094 }
095 return true;
096 }
097
098 protected Logger getLog()
099 {
100 return logger;
101 }
102 }