001package 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
022import java.util.ArrayList;
023import java.util.List;
024import java.util.Map;
025
026import org.apache.maven.execution.MavenSession;
027import org.apache.maven.toolchain.model.ToolchainModel;
028import org.codehaus.plexus.component.annotations.Component;
029
030/**
031 * @author mkleint
032 * @author Robert Scholte
033 */
034@Component( role = ToolchainManagerPrivate.class )
035public class DefaultToolchainManagerPrivate
036    extends DefaultToolchainManager
037    implements ToolchainManagerPrivate
038{
039
040    @Override
041    public ToolchainPrivate[] getToolchainsForType( String type, MavenSession context )
042        throws MisconfiguredToolchainException
043    {
044        List<ToolchainPrivate> toRet = new ArrayList<>();
045
046        ToolchainFactory fact = factories.get( type );
047        if ( fact == null )
048        {
049            logger.error( "Missing toolchain factory for type: " + type
050                + ". Possibly caused by misconfigured project." );
051        }
052        else
053        {
054            List<ToolchainModel> availableToolchains = context.getRequest().getToolchains().get( type );
055
056            if ( availableToolchains != null )
057            {
058                for ( ToolchainModel toolchainModel : availableToolchains )
059                {
060                    toRet.add( fact.createToolchain( toolchainModel ) );
061                }
062            }
063            
064            // add default toolchain
065            ToolchainPrivate tool = fact.createDefaultToolchain();
066            if ( tool != null )
067            {
068                toRet.add( tool );
069            }
070        }
071
072        return toRet.toArray( new ToolchainPrivate[toRet.size()] );
073    }
074
075    @Override
076    public void storeToolchainToBuildContext( ToolchainPrivate toolchain, MavenSession session )
077    {
078        Map<String, Object> context = retrieveContext( session );
079        context.put( getStorageKey( toolchain.getType() ), toolchain.getModel() );
080    }
081
082}