@@ -58,12 +58,23 @@ public final class DataPool {
58
58
59
59
private static final String CONFIG_PROP_COLLECTOR_POOL_DESCRIPTOR = "aether.dependencyCollector.pool.descriptor" ;
60
60
61
+ private static final String CONFIG_PROP_COLLECTOR_POOL_DEPENDENCY_LISTS =
62
+ "aether.dependencyCollector.pool.dependencyLists" ;
63
+
64
+ private static final String CONFIG_PROP_COLLECTOR_POOL_INTERN_ARTIFACT_DESCRIPTOR_DEPENDENCIES =
65
+ "aether.dependencyCollector.pool.internArtifactDescriptorDependencies" ;
66
+
67
+ private static final String CONFIG_PROP_COLLECTOR_POOL_INTERN_ARTIFACT_DESCRIPTOR_MANAGED_DEPENDENCIES =
68
+ "aether.dependencyCollector.pool.internArtifactDescriptorManagedDependencies" ;
69
+
61
70
private static final String ARTIFACT_POOL = DataPool .class .getName () + "$Artifact" ;
62
71
63
72
private static final String DEPENDENCY_POOL = DataPool .class .getName () + "$Dependency" ;
64
73
65
74
private static final String DESCRIPTORS = DataPool .class .getName () + "$Descriptors" ;
66
75
76
+ private static final String DEPENDENCY_LISTS_POOL = DataPool .class .getName () + "$DependencyLists" ;
77
+
67
78
public static final ArtifactDescriptorResult NO_DESCRIPTOR =
68
79
new ArtifactDescriptorResult (new ArtifactDescriptorRequest ());
69
80
@@ -80,7 +91,12 @@ public final class DataPool {
80
91
/**
81
92
* Descriptor interning pool, lives across session (if session carries non-null {@link RepositoryCache}).
82
93
*/
83
- private final InternPool <Object , Descriptor > descriptors ;
94
+ private final InternPool <DescriptorKey , Descriptor > descriptors ;
95
+
96
+ /**
97
+ * {@link Dependency} list interning pool, lives across session (if session carries non-null {@link RepositoryCache}).
98
+ */
99
+ private final InternPool <List <Dependency >, List <Dependency >> dependencyLists ;
84
100
85
101
/**
86
102
* Constraint cache, lives during single collection invocation (same as this DataPool instance).
@@ -92,17 +108,29 @@ public final class DataPool {
92
108
*/
93
109
private final ConcurrentHashMap <Object , List <DependencyNode >> nodes ;
94
110
111
+ private final boolean internArtifactDescriptorDependencies ;
112
+
113
+ private final boolean internArtifactDescriptorManagedDependencies ;
114
+
95
115
@ SuppressWarnings ("unchecked" )
96
116
public DataPool (RepositorySystemSession session ) {
97
117
final RepositoryCache cache = session .getCache ();
98
118
119
+ internArtifactDescriptorDependencies = ConfigUtils .getBoolean (
120
+ session , false , CONFIG_PROP_COLLECTOR_POOL_INTERN_ARTIFACT_DESCRIPTOR_DEPENDENCIES );
121
+ internArtifactDescriptorManagedDependencies = ConfigUtils .getBoolean (
122
+ session , true , CONFIG_PROP_COLLECTOR_POOL_INTERN_ARTIFACT_DESCRIPTOR_MANAGED_DEPENDENCIES );
123
+
99
124
InternPool <Artifact , Artifact > artifactsPool = null ;
100
125
InternPool <Dependency , Dependency > dependenciesPool = null ;
101
- InternPool <Object , Descriptor > descriptorsPool = null ;
126
+ InternPool <DescriptorKey , Descriptor > descriptorsPool = null ;
127
+ InternPool <List <Dependency >, List <Dependency >> dependencyListsPool = null ;
102
128
if (cache != null ) {
103
129
artifactsPool = (InternPool <Artifact , Artifact >) cache .get (session , ARTIFACT_POOL );
104
130
dependenciesPool = (InternPool <Dependency , Dependency >) cache .get (session , DEPENDENCY_POOL );
105
- descriptorsPool = (InternPool <Object , Descriptor >) cache .get (session , DESCRIPTORS );
131
+ descriptorsPool = (InternPool <DescriptorKey , Descriptor >) cache .get (session , DESCRIPTORS );
132
+ dependencyListsPool =
133
+ (InternPool <List <Dependency >, List <Dependency >>) cache .get (session , DEPENDENCY_LISTS_POOL );
106
134
}
107
135
108
136
if (artifactsPool == null ) {
@@ -132,9 +160,20 @@ public DataPool(RepositorySystemSession session) {
132
160
}
133
161
}
134
162
163
+ if (dependencyListsPool == null ) {
164
+ String dependencyListsPoolType =
165
+ ConfigUtils .getString (session , HARD , CONFIG_PROP_COLLECTOR_POOL_DEPENDENCY_LISTS );
166
+
167
+ dependencyListsPool = createPool (dependencyListsPoolType );
168
+ if (cache != null ) {
169
+ cache .put (session , DEPENDENCY_LISTS_POOL , dependencyListsPool );
170
+ }
171
+ }
172
+
135
173
this .artifacts = artifactsPool ;
136
174
this .dependencies = dependenciesPool ;
137
175
this .descriptors = descriptorsPool ;
176
+ this .dependencyLists = dependencyListsPool ;
138
177
139
178
this .constraints = new ConcurrentHashMap <>(256 );
140
179
this .nodes = new ConcurrentHashMap <>(256 );
@@ -148,26 +187,36 @@ public Dependency intern(Dependency dependency) {
148
187
return dependencies .intern (dependency , dependency );
149
188
}
150
189
151
- public Object toKey (ArtifactDescriptorRequest request ) {
152
- return request .getArtifact ();
190
+ public DescriptorKey toKey (ArtifactDescriptorRequest request ) {
191
+ return new DescriptorKey ( request .getArtifact () );
153
192
}
154
193
155
- public ArtifactDescriptorResult getDescriptor (Object key , ArtifactDescriptorRequest request ) {
194
+ public ArtifactDescriptorResult getDescriptor (DescriptorKey key , ArtifactDescriptorRequest request ) {
156
195
Descriptor descriptor = descriptors .get (key );
157
196
if (descriptor != null ) {
158
197
return descriptor .toResult (request );
159
198
}
160
199
return null ;
161
200
}
162
201
163
- public void putDescriptor (Object key , ArtifactDescriptorResult result ) {
202
+ public void putDescriptor (DescriptorKey key , ArtifactDescriptorResult result ) {
203
+ if (internArtifactDescriptorDependencies ) {
204
+ result .setDependencies (intern (result .getDependencies ()));
205
+ }
206
+ if (internArtifactDescriptorManagedDependencies ) {
207
+ result .setManagedDependencies (intern (result .getManagedDependencies ()));
208
+ }
164
209
descriptors .intern (key , new GoodDescriptor (result ));
165
210
}
166
211
167
- public void putDescriptor (Object key , ArtifactDescriptorException e ) {
212
+ public void putDescriptor (DescriptorKey key , ArtifactDescriptorException e ) {
168
213
descriptors .intern (key , BadDescriptor .INSTANCE );
169
214
}
170
215
216
+ private List <Dependency > intern (List <Dependency > dependencies ) {
217
+ return dependencyLists .intern (dependencies , dependencies );
218
+ }
219
+
171
220
public Object toKey (VersionRangeRequest request ) {
172
221
return new ConstraintKey (request );
173
222
}
@@ -202,8 +251,39 @@ public void putChildren(Object key, List<DependencyNode> children) {
202
251
nodes .put (key , children );
203
252
}
204
253
205
- abstract static class Descriptor {
254
+ public static final class DescriptorKey {
255
+ private final Artifact artifact ;
256
+ private final int hashCode ;
257
+
258
+ private DescriptorKey (Artifact artifact ) {
259
+ this .artifact = artifact ;
260
+ this .hashCode = Objects .hashCode (artifact );
261
+ }
262
+
263
+ @ Override
264
+ public boolean equals (Object o ) {
265
+ if (this == o ) {
266
+ return true ;
267
+ }
268
+ if (o == null || getClass () != o .getClass ()) {
269
+ return false ;
270
+ }
271
+ DescriptorKey that = (DescriptorKey ) o ;
272
+ return Objects .equals (artifact , that .artifact );
273
+ }
206
274
275
+ @ Override
276
+ public int hashCode () {
277
+ return hashCode ;
278
+ }
279
+
280
+ @ Override
281
+ public String toString () {
282
+ return getClass ().getSimpleName () + "{" + "artifact='" + artifact + '\'' + '}' ;
283
+ }
284
+ }
285
+
286
+ abstract static class Descriptor {
207
287
public abstract ArtifactDescriptorResult toResult (ArtifactDescriptorRequest request );
208
288
}
209
289
0 commit comments