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.Set;
27 import java.util.concurrent.ConcurrentHashMap;
28
29 import org.apache.maven.api.JavaPathType;
30 import org.apache.maven.api.Type;
31 import org.apache.maven.api.services.TypeRegistry;
32 import org.apache.maven.artifact.handler.ArtifactHandler;
33 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
34 import org.apache.maven.eventspy.AbstractEventSpy;
35 import org.apache.maven.execution.ExecutionEvent;
36
37 import static java.util.Objects.requireNonNull;
38
39
40
41 @Named
42 @Singleton
43 public class DefaultArtifactHandlerManager extends AbstractEventSpy implements ArtifactHandlerManager {
44 private final TypeRegistry typeRegistry;
45
46 private final ConcurrentHashMap<String, ArtifactHandler> allHandlers;
47
48 @Inject
49 public DefaultArtifactHandlerManager(TypeRegistry typeRegistry) {
50 this.typeRegistry = requireNonNull(typeRegistry, "null typeRegistry");
51 this.allHandlers = new ConcurrentHashMap<>();
52 }
53
54 @Override
55 public void onEvent(Object event) {
56 if (event instanceof ExecutionEvent) {
57 ExecutionEvent executionEvent = (ExecutionEvent) event;
58 if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
59 allHandlers.clear();
60 }
61 }
62 }
63
64 @Override
65 public ArtifactHandler getArtifactHandler(String id) {
66 return allHandlers.computeIfAbsent(id, k -> {
67 Type type = typeRegistry.require(id);
68 return new DefaultArtifactHandler(
69 id,
70 type.getExtension(),
71 type.getClassifier(),
72 null,
73 null,
74 type.isIncludesDependencies(),
75 type.getLanguage().id(),
76 type.getPathTypes().contains(JavaPathType.CLASSES));
77
78 });
79
80
81
82
83 }
84
85 @Override
86 public void addHandlers(Map<String, ArtifactHandler> handlers) {
87 throw new UnsupportedOperationException("Adding handlers programmatically is not supported anymore");
88 }
89
90 @Deprecated
91 public Set<String> getHandlerTypes() {
92 throw new UnsupportedOperationException("Querying handlers programmatically is not supported anymore");
93 }
94 }