1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.cling.invoker.mvnup.goals;
20
21 import java.nio.file.Path;
22 import java.util.Collections;
23 import java.util.HashSet;
24 import java.util.Set;
25
26
27
28
29
30
31
32
33
34
35 public record UpgradeResult(Set<Path> processedPoms, Set<Path> modifiedPoms, Set<Path> errorPoms) {
36
37 public UpgradeResult {
38
39 processedPoms = Set.copyOf(processedPoms);
40 modifiedPoms = Set.copyOf(modifiedPoms);
41 errorPoms = Set.copyOf(errorPoms);
42 }
43
44
45
46
47 public static UpgradeResult success(Set<Path> processedPoms, Set<Path> modifiedPoms) {
48 return new UpgradeResult(processedPoms, modifiedPoms, Collections.emptySet());
49 }
50
51
52
53
54 public static UpgradeResult failure(Set<Path> processedPoms, Set<Path> errorPoms) {
55 return new UpgradeResult(processedPoms, Collections.emptySet(), errorPoms);
56 }
57
58
59
60
61 public static UpgradeResult empty() {
62 return new UpgradeResult(Collections.emptySet(), Collections.emptySet(), Collections.emptySet());
63 }
64
65
66
67
68
69 public UpgradeResult merge(UpgradeResult other) {
70 Set<Path> mergedProcessed = new HashSet<>(this.processedPoms);
71 mergedProcessed.addAll(other.processedPoms);
72
73 Set<Path> mergedModified = new HashSet<>(this.modifiedPoms);
74 mergedModified.addAll(other.modifiedPoms);
75
76 Set<Path> mergedErrors = new HashSet<>(this.errorPoms);
77 mergedErrors.addAll(other.errorPoms);
78
79 return new UpgradeResult(mergedProcessed, mergedModified, mergedErrors);
80 }
81
82
83
84
85 public boolean success() {
86 return errorPoms.isEmpty();
87 }
88
89
90
91
92 public int processedCount() {
93 return processedPoms.size();
94 }
95
96
97
98
99 public int modifiedCount() {
100 return modifiedPoms.size();
101 }
102
103
104
105
106 public int errorCount() {
107 return errorPoms.size();
108 }
109
110
111
112
113 public int unmodifiedCount() {
114 Set<Path> unmodified = new HashSet<>(processedPoms);
115 unmodified.removeAll(modifiedPoms);
116 unmodified.removeAll(errorPoms);
117 return unmodified.size();
118 }
119 }