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 ToolchainFactory fact = factories.get( type );
52 if ( fact == null )
53 {
54 logger.error( "Missing toolchain factory for type: " + type
55 + ". Possibly caused by misconfigured project." );
56 }
57 else if ( pers != null )
58 {
59 List<ToolchainModel> lst = pers.getToolchains();
60 if ( lst != null )
61 {
62 for ( ToolchainModel toolchainModel : lst )
63 {
64 if ( type.equals( toolchainModel.getType() ) )
65 {
66 toRet.add( fact.createToolchain( toolchainModel ) );
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 }