1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.artifact.handler.manager;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import java.util.Map;
26 import java.util.concurrent.ConcurrentHashMap;
27
28 import org.apache.maven.artifact.handler.ArtifactHandler;
29 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
30 import org.apache.maven.eventspy.AbstractEventSpy;
31 import org.apache.maven.execution.ExecutionEvent;
32
33 import static java.util.Objects.requireNonNull;
34
35
36
37 @Named
38 @Singleton
39 public class LegacyArtifactHandlerManager extends AbstractEventSpy {
40 private final Map<String, ArtifactHandler> artifactHandlers;
41
42 private final Map<String, ArtifactHandler> allHandlers = new ConcurrentHashMap<>();
43
44 @Inject
45 public LegacyArtifactHandlerManager(Map<String, ArtifactHandler> artifactHandlers) {
46 this.artifactHandlers = requireNonNull(artifactHandlers);
47 }
48
49 @Override
50 public void onEvent(Object event) {
51 if (event instanceof ExecutionEvent) {
52 ExecutionEvent executionEvent = (ExecutionEvent) event;
53 if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
54 allHandlers.clear();
55 }
56 }
57 }
58
59 public ArtifactHandler getArtifactHandler(String type) {
60 requireNonNull(type, "null type");
61 ArtifactHandler handler = allHandlers.get(type);
62 if (handler == null) {
63 handler = artifactHandlers.get(type);
64 if (handler == null) {
65 handler = new DefaultArtifactHandler(type);
66 } else {
67 allHandlers.put(type, handler);
68 }
69 }
70 return handler;
71 }
72 }