28
28
import java .util .NoSuchElementException ;
29
29
import java .util .Objects ;
30
30
import java .util .Optional ;
31
- import java .util .WeakHashMap ;
32
- import java .util .concurrent .ConcurrentHashMap ;
33
31
import java .util .concurrent .CopyOnWriteArrayList ;
34
32
import java .util .function .Function ;
35
33
import java .util .function .Supplier ;
96
94
import org .apache .maven .api .services .VersionRangeResolver ;
97
95
import org .apache .maven .api .services .VersionResolver ;
98
96
import org .apache .maven .api .services .VersionResolverException ;
97
+ import org .apache .maven .impl .cache .Cache ;
99
98
import org .eclipse .aether .DefaultRepositorySystemSession ;
100
99
import org .eclipse .aether .RepositorySystem ;
101
100
import org .eclipse .aether .RepositorySystemSession ;
@@ -112,16 +111,14 @@ public abstract class AbstractSession implements InternalSession {
112
111
protected final RepositorySystem repositorySystem ;
113
112
protected final List <RemoteRepository > repositories ;
114
113
protected final Lookup lookup ;
115
- private final Map <Class <? extends Service >, Service > services = new ConcurrentHashMap <> ();
114
+ private final Cache <Class <? extends Service >, Service > services = Cache . newCache ();
116
115
private final List <Listener > listeners = new CopyOnWriteArrayList <>();
117
- private final Map <org .eclipse .aether .graph .DependencyNode , Node > allNodes =
118
- Collections .synchronizedMap (new WeakHashMap <>());
119
- private final Map <Class <? extends Artifact >, Map <org .eclipse .aether .artifact .Artifact , Artifact >> allArtifacts =
120
- new ConcurrentHashMap <>();
121
- private final Map <org .eclipse .aether .repository .RemoteRepository , RemoteRepository > allRepositories =
122
- Collections .synchronizedMap (new WeakHashMap <>());
123
- private final Map <org .eclipse .aether .graph .Dependency , Dependency > allDependencies =
124
- Collections .synchronizedMap (new WeakHashMap <>());
116
+ private final Cache <org .eclipse .aether .graph .DependencyNode , Node > allNodes = Cache .newCache ();
117
+ private final Cache <Class <? extends Artifact >, Cache <org .eclipse .aether .artifact .Artifact , Artifact >> allArtifacts =
118
+ Cache .newCache ();
119
+ private final Cache <org .eclipse .aether .repository .RemoteRepository , RemoteRepository > allRepositories =
120
+ Cache .newCache ();
121
+ private final Cache <org .eclipse .aether .graph .Dependency , Dependency > allDependencies = Cache .newCache ();
125
122
private volatile RequestCache requestCache ;
126
123
127
124
static {
@@ -225,18 +222,18 @@ public Artifact getArtifact(@Nonnull org.eclipse.aether.artifact.Artifact artifa
225
222
@ SuppressWarnings ("unchecked" )
226
223
@ Override
227
224
public <T extends Artifact > T getArtifact (Class <T > clazz , org .eclipse .aether .artifact .Artifact artifact ) {
228
- Map <org .eclipse .aether .artifact .Artifact , Artifact > map =
229
- allArtifacts .computeIfAbsent (clazz , c -> Collections . synchronizedMap ( new WeakHashMap <>() ));
225
+ Cache <org .eclipse .aether .artifact .Artifact , Artifact > cache =
226
+ allArtifacts .computeIfAbsent (clazz , c -> Cache . newCache ( ));
230
227
if (clazz == Artifact .class ) {
231
- return (T ) map .computeIfAbsent (artifact , a -> new DefaultArtifact (this , a ));
228
+ return (T ) cache .computeIfAbsent (artifact , a -> new DefaultArtifact (this , a ));
232
229
} else if (clazz == DownloadedArtifact .class ) {
233
230
if (artifact .getPath () == null ) {
234
231
throw new IllegalArgumentException ("The given artifact is not resolved" );
235
232
} else {
236
- return (T ) map .computeIfAbsent (artifact , a -> new DefaultDownloadedArtifact (this , a ));
233
+ return (T ) cache .computeIfAbsent (artifact , a -> new DefaultDownloadedArtifact (this , a ));
237
234
}
238
235
} else if (clazz == ProducedArtifact .class ) {
239
- return (T ) map .computeIfAbsent (artifact , a -> new DefaultProducedArtifact (this , a ));
236
+ return (T ) cache .computeIfAbsent (artifact , a -> new DefaultProducedArtifact (this , a ));
240
237
} else {
241
238
throw new IllegalArgumentException ("Unsupported Artifact class: " + clazz );
242
239
}
0 commit comments