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