|
6 | 6 | import org.variantsync.diffdetective.metadata.ExplainedFilterSummary; |
7 | 7 | import org.variantsync.diffdetective.metadata.Metadata; |
8 | 8 | import org.variantsync.diffdetective.pattern.elementary.proposed.ProposedElementaryPatterns; |
9 | | -import org.variantsync.diffdetective.util.IO; |
10 | 9 | import org.variantsync.functjonal.Functjonal; |
11 | 10 | import org.variantsync.functjonal.category.InplaceMonoid; |
12 | 11 | import org.variantsync.functjonal.category.InplaceSemigroup; |
13 | 12 | import org.variantsync.functjonal.category.Semigroup; |
14 | 13 | import org.variantsync.functjonal.map.MergeMap; |
15 | 14 |
|
| 15 | +import java.io.BufferedReader; |
16 | 16 | import java.io.IOException; |
| 17 | +import java.nio.file.Files; |
17 | 18 | import java.nio.file.Path; |
18 | 19 | import java.util.*; |
19 | 20 | import java.util.function.BiConsumer; |
@@ -137,76 +138,72 @@ public static AnalysisResult importFrom(final Path p, final Map<String, BiConsum |
137 | 138 |
|
138 | 139 | final List<String> filterHitsLines = new ArrayList<>(); |
139 | 140 | final List<String> elementaryPatternCountsLines = new ArrayList<>(); |
140 | | - |
141 | | - String fileInput = IO.readAsString(p); // read in metadata file |
142 | | - fileInput = fileInput.replace("\r", ""); // remove carriage returns if present |
143 | | - final String[] lines = fileInput.split("\n"); |
144 | | - String[] keyValuePair; |
145 | | - String key; |
146 | | - String value; |
147 | | - |
148 | | - // examine each line of the metadata file separately |
149 | | - for (/*final*/ String line : lines) { |
150 | | - keyValuePair = line.split(": "); |
151 | | - key = keyValuePair[0]; |
152 | | - value = keyValuePair[1]; |
153 | | - |
154 | | - switch (key) { |
155 | | - case MetadataKeys.REPONAME -> result.repoName = value; |
156 | | - case MetadataKeys.TREES -> result.exportedTrees = Integer.parseInt(value); |
157 | | - case MetadataKeys.PROCESSED_COMMITS -> result.exportedCommits = Integer.parseInt(value); |
158 | | - case MetadataKeys.TOTAL_COMMITS -> result.totalCommits = Integer.parseInt(value); |
159 | | - case MetadataKeys.EMPTY_COMMITS -> result.emptyCommits = Integer.parseInt(value); |
160 | | - case MetadataKeys.FAILED_COMMITS -> result.failedCommits = Integer.parseInt(value); |
161 | | - case MetadataKeys.FILTERED_COMMITS -> { /* Do nothing because this value is derived. */ } |
162 | | - case MetadataKeys.NON_NODE_COUNT -> result.debugData.numExportedNonNodes = Integer.parseInt(value); |
163 | | - case MetadataKeys.ADD_NODE_COUNT -> result.debugData.numExportedAddNodes = Integer.parseInt(value); |
164 | | - case MetadataKeys.REM_NODE_COUNT -> result.debugData.numExportedRemNodes = Integer.parseInt(value); |
165 | | - case MetadataKeys.MINCOMMIT -> result.min.set(CommitProcessTime.fromString(value)); |
166 | | - case MetadataKeys.MAXCOMMIT -> result.max.set(CommitProcessTime.fromString(value)); |
167 | | - case MetadataKeys.RUNTIME -> { |
168 | | - if (value.endsWith("s")) { |
169 | | - value = value.substring(0, value.length() - 1); |
| 141 | + |
| 142 | + try (BufferedReader input = Files.newBufferedReader(p)) { |
| 143 | + // examine each line of the metadata file separately |
| 144 | + String line; |
| 145 | + while ((line = input.readLine()) != null) { |
| 146 | + String[] keyValuePair = line.split(": "); |
| 147 | + String key = keyValuePair[0]; |
| 148 | + String value = keyValuePair[1]; |
| 149 | + |
| 150 | + switch (key) { |
| 151 | + case MetadataKeys.REPONAME -> result.repoName = value; |
| 152 | + case MetadataKeys.TREES -> result.exportedTrees = Integer.parseInt(value); |
| 153 | + case MetadataKeys.PROCESSED_COMMITS -> result.exportedCommits = Integer.parseInt(value); |
| 154 | + case MetadataKeys.TOTAL_COMMITS -> result.totalCommits = Integer.parseInt(value); |
| 155 | + case MetadataKeys.EMPTY_COMMITS -> result.emptyCommits = Integer.parseInt(value); |
| 156 | + case MetadataKeys.FAILED_COMMITS -> result.failedCommits = Integer.parseInt(value); |
| 157 | + case MetadataKeys.FILTERED_COMMITS -> { /* Do nothing because this value is derived. */ } |
| 158 | + case MetadataKeys.NON_NODE_COUNT -> result.debugData.numExportedNonNodes = Integer.parseInt(value); |
| 159 | + case MetadataKeys.ADD_NODE_COUNT -> result.debugData.numExportedAddNodes = Integer.parseInt(value); |
| 160 | + case MetadataKeys.REM_NODE_COUNT -> result.debugData.numExportedRemNodes = Integer.parseInt(value); |
| 161 | + case MetadataKeys.MINCOMMIT -> result.min.set(CommitProcessTime.fromString(value)); |
| 162 | + case MetadataKeys.MAXCOMMIT -> result.max.set(CommitProcessTime.fromString(value)); |
| 163 | + case MetadataKeys.RUNTIME -> { |
| 164 | + if (value.endsWith("s")) { |
| 165 | + value = value.substring(0, value.length() - 1); |
| 166 | + } |
| 167 | + result.runtimeInSeconds = Double.parseDouble(value); |
170 | 168 | } |
171 | | - result.runtimeInSeconds = Double.parseDouble(value); |
172 | | - } |
173 | | - case MetadataKeys.RUNTIME_WITH_MULTITHREADING -> { |
174 | | - if (value.endsWith("s")) { |
175 | | - value = value.substring(0, value.length() - 1); |
| 169 | + case MetadataKeys.RUNTIME_WITH_MULTITHREADING -> { |
| 170 | + if (value.endsWith("s")) { |
| 171 | + value = value.substring(0, value.length() - 1); |
| 172 | + } |
| 173 | + result.runtimeWithMultithreadingInSeconds = Double.parseDouble(value); |
176 | 174 | } |
177 | | - result.runtimeWithMultithreadingInSeconds = Double.parseDouble(value); |
178 | | - } |
179 | | - default -> { |
| 175 | + default -> { |
180 | 176 |
|
181 | | - // temporary fix for renaming from Unchanged to Untouched |
182 | | - final String unchanged = "Unchanged"; |
183 | | - if (key.startsWith(unchanged)) { |
184 | | - key = ProposedElementaryPatterns.Untouched.getName(); |
185 | | - line = key + line.substring(unchanged.length()); |
186 | | - } |
| 177 | + // temporary fix for renaming from Unchanged to Untouched |
| 178 | + final String unchanged = "Unchanged"; |
| 179 | + if (key.startsWith(unchanged)) { |
| 180 | + key = ProposedElementaryPatterns.Untouched.getName(); |
| 181 | + line = key + line.substring(unchanged.length()); |
| 182 | + } |
187 | 183 |
|
188 | | - final String finalKey = key; |
189 | | - if (ProposedElementaryPatterns.All.stream().anyMatch(pattern -> pattern.getName().equals(finalKey))) { |
190 | | - elementaryPatternCountsLines.add(line); |
191 | | - } else if (key.startsWith(ExplainedFilterSummary.FILTERED_MESSAGE_BEGIN)) { |
192 | | - filterHitsLines.add(line); |
193 | | - } else if (key.startsWith(ERROR_BEGIN)) { |
194 | | - DiffError e = new DiffError(key.substring(ERROR_BEGIN.length(), key.length() - ERROR_END.length())); |
195 | | - // add DiffError |
196 | | - result.diffErrors.put(e, Integer.parseInt(value)); |
197 | | - } else { |
198 | | - final BiConsumer<AnalysisResult, String> customParser = customParsers.get(key); |
199 | | - if (customParser == null) { |
200 | | - final String errorMessage = "Unknown entry \"" + line + "\"!"; |
201 | | - throw new IOException(errorMessage); |
| 184 | + final String finalKey = key; |
| 185 | + if (ProposedElementaryPatterns.All.stream().anyMatch(pattern -> pattern.getName().equals(finalKey))) { |
| 186 | + elementaryPatternCountsLines.add(line); |
| 187 | + } else if (key.startsWith(ExplainedFilterSummary.FILTERED_MESSAGE_BEGIN)) { |
| 188 | + filterHitsLines.add(line); |
| 189 | + } else if (key.startsWith(ERROR_BEGIN)) { |
| 190 | + DiffError e = new DiffError(key.substring(ERROR_BEGIN.length(), key.length() - ERROR_END.length())); |
| 191 | + // add DiffError |
| 192 | + result.diffErrors.put(e, Integer.parseInt(value)); |
202 | 193 | } else { |
203 | | - customParser.accept(result, value); |
| 194 | + final BiConsumer<AnalysisResult, String> customParser = customParsers.get(key); |
| 195 | + if (customParser == null) { |
| 196 | + final String errorMessage = "Unknown entry \"" + line + "\"!"; |
| 197 | + throw new IOException(errorMessage); |
| 198 | + } else { |
| 199 | + customParser.accept(result, value); |
| 200 | + } |
204 | 201 | } |
205 | 202 | } |
206 | 203 | } |
207 | 204 | } |
208 | 205 | } |
209 | | - |
| 206 | + |
210 | 207 | result.filterHits = ExplainedFilterSummary.parse(filterHitsLines); |
211 | 208 | result.elementaryPatternCounts = ElementaryPatternCount.parse(elementaryPatternCountsLines, p.toString()); |
212 | 209 |
|
|
0 commit comments