1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.cling.invoker.mvn.resident;
20
21 import java.util.ArrayList;
22 import java.util.concurrent.ConcurrentHashMap;
23
24 import org.apache.maven.api.cli.InvokerException;
25 import org.apache.maven.api.cli.InvokerRequest;
26 import org.apache.maven.cling.invoker.ProtoLookup;
27 import org.apache.maven.cling.invoker.mvn.MavenInvoker;
28
29
30
31
32
33
34 public class ResidentMavenInvoker extends MavenInvoker<ResidentMavenContext> {
35
36 private final ConcurrentHashMap<String, ResidentMavenContext> residentContext;
37
38 public ResidentMavenInvoker(ProtoLookup protoLookup) {
39 super(protoLookup);
40 this.residentContext = new ConcurrentHashMap<>();
41 }
42
43 @Override
44 public void close() throws InvokerException {
45 ArrayList<InvokerException> exceptions = new ArrayList<>();
46 for (ResidentMavenContext context : residentContext.values()) {
47 try {
48 context.shutDown();
49 } catch (InvokerException e) {
50 exceptions.add(e);
51 }
52 }
53 if (!exceptions.isEmpty()) {
54 InvokerException exception = new InvokerException("Could not cleanly shut down context pool");
55 exceptions.forEach(exception::addSuppressed);
56 throw exception;
57 }
58 }
59
60 @Override
61 protected ResidentMavenContext createContext(InvokerRequest invokerRequest) {
62 return residentContext
63 .computeIfAbsent(getContextId(invokerRequest), k -> new ResidentMavenContext(invokerRequest))
64 .copy(invokerRequest);
65 }
66
67 protected String getContextId(InvokerRequest invokerRequest) {
68
69
70 return "resident";
71 }
72
73 @Override
74 protected void container(ResidentMavenContext context) throws Exception {
75 if (context.containerCapsule == null) {
76 super.container(context);
77 } else {
78 context.containerCapsule.updateLogging(context);
79 }
80 }
81
82 @Override
83 protected void lookup(ResidentMavenContext context) throws Exception {
84 if (context.maven == null) {
85 super.lookup(context);
86 }
87 }
88 }