1   package org.apache.maven.toolchain;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
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  
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  }