Skip to content

Commit 5e35d16

Browse files
committed
AE-1273: enabling artifactPostProcessor in Inventory.mergeDuplicates()
1 parent bf350ba commit 5e35d16

File tree

1 file changed

+24
-2
lines changed
  • libraries/ae-inventory-processor/src/main/java/org/metaeffekt/core/inventory/processor/model

1 file changed

+24
-2
lines changed

libraries/ae-inventory-processor/src/main/java/org/metaeffekt/core/inventory/processor/model/Inventory.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.Serializable;
2828
import java.util.*;
2929
import java.util.concurrent.CopyOnWriteArrayList;
30+
import java.util.function.Consumer;
3031
import java.util.function.Function;
3132
import java.util.stream.Collectors;
3233

@@ -237,6 +238,16 @@ private String createRepresentation(Artifact o1) {
237238
}
238239

239240
public void mergeDuplicates() {
241+
mergeDuplicates(null);
242+
}
243+
244+
/**
245+
* Merges the artifacts in an inventory recognized as duplicates.
246+
*
247+
* @param artifactPostProcessor The processor processed the artifacts before and after merge. It may be used
248+
* to establish consistency or to apply adjustments. May be <code>null</code>.
249+
*/
250+
public void mergeDuplicates(Consumer<Artifact> artifactPostProcessor) {
240251
final Map<String, Set<Artifact>> artifactMap = new HashMap<>();
241252

242253
for (Artifact artifact : artifacts) {
@@ -261,6 +272,12 @@ public void mergeDuplicates() {
261272
set = new HashSet<>();
262273
}
263274
set.add(artifact);
275+
276+
// postprocess incoming
277+
if (artifactPostProcessor != null) {
278+
artifactPostProcessor.accept(artifact);
279+
}
280+
264281
artifactMap.put(key, set);
265282
}
266283
}
@@ -271,13 +288,18 @@ public void mergeDuplicates() {
271288
final Iterator<Artifact> it = set.iterator();
272289

273290
// skip first
274-
final Artifact ref = it.next();
291+
final Artifact referenceArtifact = it.next();
275292

276293
while (it.hasNext()) {
277294
Artifact a = it.next();
278295

279296
// merge content before removing
280-
ref.merge(a);
297+
referenceArtifact.merge(a);
298+
299+
// postprocess merged
300+
if (artifactPostProcessor != null) {
301+
artifactPostProcessor.accept(referenceArtifact);
302+
}
281303

282304
// remove
283305
artifacts.remove(a);

0 commit comments

Comments
 (0)