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.ArrayList;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.apache.maven.execution.MavenSession;
27  import org.apache.maven.toolchain.model.ToolchainModel;
28  import org.codehaus.plexus.component.annotations.Component;
29  
30  /**
31   * @author mkleint
32   * @author Robert Scholte
33   */
34  @Component( role = ToolchainManagerPrivate.class )
35  public class DefaultToolchainManagerPrivate
36      extends DefaultToolchainManager
37      implements ToolchainManagerPrivate
38  {
39  
40      @Override
41      public ToolchainPrivate[] getToolchainsForType( String type, MavenSession context )
42          throws MisconfiguredToolchainException
43      {
44          List<ToolchainPrivate> toRet = new ArrayList<>();
45  
46          ToolchainFactory fact = factories.get( type );
47          if ( fact == null )
48          {
49              logger.error( "Missing toolchain factory for type: " + type
50                  + ". Possibly caused by misconfigured project." );
51          }
52          else
53          {
54              List<ToolchainModel> availableToolchains = context.getRequest().getToolchains().get( type );
55  
56              if ( availableToolchains != null )
57              {
58                  for ( ToolchainModel toolchainModel : availableToolchains )
59                  {
60                      toRet.add( fact.createToolchain( toolchainModel ) );
61                  }
62              }
63              
64              // add default toolchain
65              ToolchainPrivate tool = fact.createDefaultToolchain();
66              if ( tool != null )
67              {
68                  toRet.add( tool );
69              }
70          }
71  
72          return toRet.toArray( new ToolchainPrivate[toRet.size()] );
73      }
74  
75      @Override
76      public void storeToolchainToBuildContext( ToolchainPrivate toolchain, MavenSession session )
77      {
78          Map<String, Object> context = retrieveContext( session );
79          context.put( getStorageKey( toolchain.getType() ), toolchain.getModel() );
80      }
81  
82  }