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 javax.inject.Inject;
27 import javax.inject.Named;
28 import javax.inject.Singleton;
29
30 import org.apache.maven.execution.MavenSession;
31 import org.apache.maven.api.toolchain.ToolchainModel;
32 import org.slf4j.Logger;
33
34
35
36
37
38
39
40 @Named
41 @Singleton
42 public class DefaultToolchainManagerPrivate
43 extends DefaultToolchainManager
44 implements ToolchainManagerPrivate
45 {
46 @Inject
47 public DefaultToolchainManagerPrivate( Map<String, ToolchainFactory> factories )
48 {
49 super( factories );
50 }
51
52
53
54
55 DefaultToolchainManagerPrivate( Map<String, ToolchainFactory> factories, Logger logger )
56 {
57 super( factories, logger );
58 }
59
60 @Override
61 public ToolchainPrivate[] getToolchainsForType( String type, MavenSession session )
62 throws MisconfiguredToolchainException
63 {
64 List<ToolchainPrivate> toRet = new ArrayList<>();
65
66 ToolchainFactory fact = factories.get( type );
67 if ( fact == null )
68 {
69 logger.error( "Missing toolchain factory for type: " + type
70 + ". Possibly caused by misconfigured project." );
71 }
72 else
73 {
74 List<ToolchainModel> availableToolchains =
75 org.apache.maven.toolchain.model.ToolchainModel.toolchainModelToApiV4(
76 session.getRequest().getToolchains().get( type ) );
77
78 if ( availableToolchains != null )
79 {
80 for ( ToolchainModel toolchainModel : availableToolchains )
81 {
82 org.apache.maven.toolchain.model.ToolchainModel tm =
83 new org.apache.maven.toolchain.model.ToolchainModel( toolchainModel );
84 toRet.add( fact.createToolchain( tm ) );
85 }
86 }
87
88
89 ToolchainPrivate tool = fact.createDefaultToolchain();
90 if ( tool != null )
91 {
92 toRet.add( tool );
93 }
94 }
95
96 return toRet.toArray( new ToolchainPrivate[0] );
97 }
98
99 @Override
100 public void storeToolchainToBuildContext( ToolchainPrivate toolchain, MavenSession session )
101 {
102 Map<String, Object> context = retrieveContext( session );
103 context.put( getStorageKey( toolchain.getType() ), toolchain.getModel() );
104 }
105
106 }