|
10 | 10 | import java.util.ArrayList; |
11 | 11 | import java.util.Arrays; |
12 | 12 | import java.util.Comparator; |
| 13 | +import java.util.LinkedHashSet; |
13 | 14 | import java.util.List; |
| 15 | +import java.util.Set; |
14 | 16 | import java.util.stream.Collectors; |
15 | 17 | import java.util.stream.Stream; |
16 | 18 | import org.scip_code.scip.Document; |
|
23 | 25 | public class MinimizedSnapshotScipGenerator { |
24 | 26 | private static final List<SnapshotCaseSpec> SNAPSHOT_CASES = |
25 | 27 | Arrays.asList( |
| 28 | + new SnapshotCaseSpec("java-common", "scip-snapshots/expected/java/common", false, "17"), |
| 29 | + new SnapshotCaseSpec("java-25", "scip-snapshots/expected/java-25", false, "25"), |
26 | 30 | new SnapshotCaseSpec( |
27 | | - "java-common", |
28 | | - "scip-snapshots/expected/java/common", |
29 | | - "snapshot.case.java-common.targetroot", |
30 | | - false, |
31 | | - "17"), |
32 | | - new SnapshotCaseSpec( |
33 | | - "java-25", |
34 | | - "scip-snapshots/expected/java-25", |
35 | | - "snapshot.case.java-25.targetroot", |
36 | | - false, |
37 | | - "25", |
38 | | - 25), |
39 | | - new SnapshotCaseSpec( |
40 | | - "kotlin-common", |
41 | | - "scip-snapshots/expected/kotlin/common", |
42 | | - "snapshot.case.kotlin-common.targetroot", |
43 | | - true, |
44 | | - "17")); |
| 31 | + "kotlin-common", "scip-snapshots/expected/kotlin/common", true, "17")); |
45 | 32 |
|
46 | 33 | public static final class SnapshotCase { |
47 | 34 | public final String id; |
@@ -71,50 +58,25 @@ public SnapshotContext context() { |
71 | 58 | private static final class SnapshotCaseSpec { |
72 | 59 | private final String id; |
73 | 60 | private final String expectDirectory; |
74 | | - private final String targetrootProperty; |
75 | 61 | private final boolean aggregateNoEmitInverseRelationships; |
76 | 62 | private final String jdkVersion; |
77 | | - private final int minimumJavaFeature; |
78 | 63 |
|
79 | 64 | private SnapshotCaseSpec( |
80 | 65 | String id, |
81 | 66 | String expectDirectory, |
82 | | - String targetrootProperty, |
83 | 67 | boolean aggregateNoEmitInverseRelationships, |
84 | 68 | String jdkVersion) { |
85 | | - this( |
86 | | - id, |
87 | | - expectDirectory, |
88 | | - targetrootProperty, |
89 | | - aggregateNoEmitInverseRelationships, |
90 | | - jdkVersion, |
91 | | - 0); |
92 | | - } |
93 | | - |
94 | | - private SnapshotCaseSpec( |
95 | | - String id, |
96 | | - String expectDirectory, |
97 | | - String targetrootProperty, |
98 | | - boolean aggregateNoEmitInverseRelationships, |
99 | | - String jdkVersion, |
100 | | - int minimumJavaFeature) { |
101 | 69 | this.id = id; |
102 | 70 | this.expectDirectory = expectDirectory; |
103 | | - this.targetrootProperty = targetrootProperty; |
104 | 71 | this.aggregateNoEmitInverseRelationships = aggregateNoEmitInverseRelationships; |
105 | 72 | this.jdkVersion = jdkVersion; |
106 | | - this.minimumJavaFeature = minimumJavaFeature; |
107 | | - } |
108 | | - |
109 | | - private boolean isEnabled() { |
110 | | - return Runtime.version().feature() >= minimumJavaFeature; |
111 | 73 | } |
112 | 74 |
|
113 | 75 | private SnapshotCase toSnapshotCase(Path sourceroot) { |
114 | 76 | return new SnapshotCase( |
115 | 77 | id, |
116 | 78 | sourceroot.resolve(expectDirectory), |
117 | | - requiredPathProperty(targetrootProperty), |
| 79 | + requiredPathProperty(targetrootProperty(id)), |
118 | 80 | aggregateNoEmitInverseRelationships, |
119 | 81 | jdkVersion); |
120 | 82 | } |
@@ -204,16 +166,48 @@ public void onTargetroot( |
204 | 166 | */ |
205 | 167 | public static List<SnapshotCase> snapshotCases() { |
206 | 168 | Path sourceroot = requiredPathProperty("snapshot.sourceroot"); |
| 169 | + Set<String> buildCaseIds = requiredCsvProperty("snapshot.case.ids"); |
| 170 | + Set<String> enabledCaseIds = requiredCsvProperty("snapshot.enabledCases"); |
| 171 | + Set<String> specCaseIds = |
| 172 | + SNAPSHOT_CASES.stream() |
| 173 | + .map(snapshotCase -> snapshotCase.id) |
| 174 | + .collect(Collectors.toCollection(LinkedHashSet::new)); |
| 175 | + if (!buildCaseIds.equals(specCaseIds)) { |
| 176 | + throw new IllegalStateException( |
| 177 | + "Snapshot case metadata mismatch. Gradle cases=" |
| 178 | + + buildCaseIds |
| 179 | + + ", Java specs=" |
| 180 | + + specCaseIds); |
| 181 | + } |
| 182 | + if (!specCaseIds.containsAll(enabledCaseIds)) { |
| 183 | + throw new IllegalStateException( |
| 184 | + "Enabled snapshot cases must be a subset of known cases. Enabled=" |
| 185 | + + enabledCaseIds |
| 186 | + + ", Java specs=" |
| 187 | + + specCaseIds); |
| 188 | + } |
207 | 189 | return SNAPSHOT_CASES.stream() |
208 | | - .filter(SnapshotCaseSpec::isEnabled) |
| 190 | + .filter(snapshotCase -> enabledCaseIds.contains(snapshotCase.id)) |
209 | 191 | .map(snapshotCase -> snapshotCase.toSnapshotCase(sourceroot)) |
210 | 192 | .collect(Collectors.toList()); |
211 | 193 | } |
212 | 194 |
|
| 195 | + private static String targetrootProperty(String id) { |
| 196 | + return "snapshot.case." + id + ".targetroot"; |
| 197 | + } |
| 198 | + |
213 | 199 | public static Path requiredPathProperty(String name) { |
214 | 200 | return Paths.get(requiredProperty(name)); |
215 | 201 | } |
216 | 202 |
|
| 203 | + private static Set<String> requiredCsvProperty(String name) { |
| 204 | + String value = requiredProperty(name); |
| 205 | + return Arrays.stream(value.split(",")) |
| 206 | + .map(String::trim) |
| 207 | + .filter(entry -> !entry.isEmpty()) |
| 208 | + .collect(Collectors.toCollection(LinkedHashSet::new)); |
| 209 | + } |
| 210 | + |
217 | 211 | private static String requiredProperty(String name) { |
218 | 212 | String value = System.getProperty(name); |
219 | 213 | if (value == null || value.trim().isEmpty()) { |
|
0 commit comments