1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.toolchain;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.apache.maven.api.toolchain.ToolchainModel;
30 import org.apache.maven.execution.MavenSession;
31 import org.slf4j.Logger;
32
33
34
35
36
37 @Named
38 @Singleton
39 public class DefaultToolchainManagerPrivate extends DefaultToolchainManager implements ToolchainManagerPrivate {
40 @Inject
41 public DefaultToolchainManagerPrivate(Map<String, ToolchainFactory> factories) {
42 super(factories);
43 }
44
45
46
47
48 DefaultToolchainManagerPrivate(Map<String, ToolchainFactory> factories, Logger logger) {
49 super(factories, logger);
50 }
51
52 @Override
53 public ToolchainPrivate[] getToolchainsForType(String type, MavenSession session)
54 throws MisconfiguredToolchainException {
55 List<ToolchainPrivate> toRet = new ArrayList<>();
56
57 ToolchainFactory fact = factories.get(type);
58 if (fact == null) {
59 logger.error("Missing toolchain factory for type: " + type + ". Possibly caused by misconfigured project.");
60 } else {
61 List<ToolchainModel> availableToolchains =
62 org.apache.maven.toolchain.model.ToolchainModel.toolchainModelToApiV4(
63 session.getRequest().getToolchains().get(type));
64
65 if (availableToolchains != null) {
66 for (ToolchainModel toolchainModel : availableToolchains) {
67 org.apache.maven.toolchain.model.ToolchainModel tm =
68 new org.apache.maven.toolchain.model.ToolchainModel(toolchainModel);
69 toRet.add(fact.createToolchain(tm));
70 }
71 }
72
73
74 ToolchainPrivate tool = fact.createDefaultToolchain();
75 if (tool != null) {
76 toRet.add(tool);
77 }
78 }
79
80 return toRet.toArray(new ToolchainPrivate[0]);
81 }
82
83 @Override
84 public void storeToolchainToBuildContext(ToolchainPrivate toolchain, MavenSession session) {
85 Map<String, Object> context = retrieveContext(session);
86 context.put(getStorageKey(toolchain.getType()), toolchain.getModel());
87 }
88 }