151 return ret;
152 }
153
154 private interface ValueParser<T> {
155 T parse(JSONValue value);
156 }
157
158 private <E> Set<E> parseCommits(Path base, List<String> files, ValueParser<E> valueParser) throws IOException {
159 var ret = new HashSet<E>();
160 for (var file : files) {
161 var jsonData = Files.readString(base.resolve(file), StandardCharsets.UTF_8);
162 var json = JSON.parse(jsonData);
163 for (var value : json.get("commits").asArray()) {
164 ret.add(valueParser.parse(value));
165 }
166 }
167 return ret;
168 }
169
170 public Converter resolve(Path scratchPath) throws IOException {
171 var localRepo = Repository.materialize(scratchPath, configurationRepo.url(), configurationRef);
172
173 var replacements = parseMap(localRepo.root(), replacementsFile,
174 field -> new Hash(field.name()),
175 field -> field.value().stream()
176 .map(JSONValue::asString).collect(Collectors.toList()));
177 var corrections = parseMap(localRepo.root(), correctionsFile,
178 field -> new Hash(field.name()),
179 field -> field.value().fields().stream()
180 .collect(Collectors.toMap(JSONObject.Field::name, sub -> sub.value().asString())));
181 var lowercase = parseCommits(localRepo.root(), lowercaseFile, value -> new Hash(value.asString()));
182 var punctuated = parseCommits(localRepo.root(), punctuatedFile, value -> new Hash(value.asString()));
183 var authors = parseMap(localRepo.root(), authorsFile, JSONObject.Field::name, field -> field.value().asString());
184 var contributors = parseMap(localRepo.root(), contributorsFile, JSONObject.Field::name, field -> field.value().asString());
185 var sponsors = parseMap(localRepo.root(), sponsorsFile,
186 JSONObject.Field::name,
187 field -> field.value().stream()
188 .map(JSONValue::asString)
189 .collect(Collectors.toList()));
190
191 return new HgToGitConverter(replacements, corrections, lowercase, punctuated, authors, contributors, sponsors);
|
151 return ret;
152 }
153
154 private interface ValueParser<T> {
155 T parse(JSONValue value);
156 }
157
158 private <E> Set<E> parseCommits(Path base, List<String> files, ValueParser<E> valueParser) throws IOException {
159 var ret = new HashSet<E>();
160 for (var file : files) {
161 var jsonData = Files.readString(base.resolve(file), StandardCharsets.UTF_8);
162 var json = JSON.parse(jsonData);
163 for (var value : json.get("commits").asArray()) {
164 ret.add(valueParser.parse(value));
165 }
166 }
167 return ret;
168 }
169
170 public Converter resolve(Path scratchPath) throws IOException {
171 var localRepo = Repository.materialize(scratchPath, configurationRepo.url(),
172 configurationRef + ":hgbridge_config_" + configurationRepo.name());
173
174 var replacements = parseMap(localRepo.root(), replacementsFile,
175 field -> new Hash(field.name()),
176 field -> field.value().stream()
177 .map(JSONValue::asString).collect(Collectors.toList()));
178 var corrections = parseMap(localRepo.root(), correctionsFile,
179 field -> new Hash(field.name()),
180 field -> field.value().fields().stream()
181 .collect(Collectors.toMap(JSONObject.Field::name, sub -> sub.value().asString())));
182 var lowercase = parseCommits(localRepo.root(), lowercaseFile, value -> new Hash(value.asString()));
183 var punctuated = parseCommits(localRepo.root(), punctuatedFile, value -> new Hash(value.asString()));
184 var authors = parseMap(localRepo.root(), authorsFile, JSONObject.Field::name, field -> field.value().asString());
185 var contributors = parseMap(localRepo.root(), contributorsFile, JSONObject.Field::name, field -> field.value().asString());
186 var sponsors = parseMap(localRepo.root(), sponsorsFile,
187 JSONObject.Field::name,
188 field -> field.value().stream()
189 .map(JSONValue::asString)
190 .collect(Collectors.toList()));
191
192 return new HgToGitConverter(replacements, corrections, lowercase, punctuated, authors, contributors, sponsors);
|