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