1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.internal;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.util.concurrent.atomic.AtomicReference;
25
26 import org.apache.maven.execution.MavenSession;
27 import org.apache.maven.plugin.LegacySupport;
28 import org.eclipse.aether.RepositorySystemSession;
29
30
31
32
33
34
35
36
37 @Named
38 @Singleton
39 public class DefaultLegacySupport implements LegacySupport {
40
41 private static final ThreadLocal<AtomicReference<MavenSession>> SESSION = new InheritableThreadLocal<>();
42
43 public void setSession(MavenSession session) {
44 AtomicReference<MavenSession> reference = DefaultLegacySupport.SESSION.get();
45 if (reference != null) {
46 reference.set(null);
47 }
48
49 if (session == null && reference != null) {
50 DefaultLegacySupport.SESSION.remove();
51 } else {
52 DefaultLegacySupport.SESSION.set(new AtomicReference<>(session));
53 }
54 }
55
56 public MavenSession getSession() {
57 AtomicReference<MavenSession> currentSession = DefaultLegacySupport.SESSION.get();
58 return currentSession != null ? currentSession.get() : null;
59 }
60
61 public RepositorySystemSession getRepositorySession() {
62 MavenSession session = getSession();
63 return (session != null) ? session.getRepositorySession() : null;
64 }
65 }