Skip to content

Commit ccab357

Browse files
committed
Use object mapper instead of ConfigurationStringBuilder
1 parent 3a8db97 commit ccab357

File tree

3 files changed

+21
-42
lines changed

3 files changed

+21
-42
lines changed

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/ContributionTask.java

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.annotation.JsonInclude;
44
import com.fasterxml.jackson.core.type.TypeReference;
5+
import com.fasterxml.jackson.core.util.DefaultIndenter;
6+
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
57
import com.fasterxml.jackson.databind.ObjectMapper;
68
import com.fasterxml.jackson.databind.SerializationFeature;
79
import org.graalvm.internal.tck.model.MetadataIndexEntry;
@@ -328,12 +330,12 @@ private void addTests(Path originalTestsLocation){
328330
Path allTests = originalTestsLocation.resolve(".");
329331

330332
ensureFileBelongsToProject(destination);
333+
InteractiveTaskUtils.printUserInfo("Removing dummy test stubs");
331334
boolean shouldDelete = InteractiveTaskUtils.askForDeletePermission(destination);
332335
if (!shouldDelete) {
333336
throw new RuntimeException("The task didn't get permission to delete dummy stubs. Cannot proceed with the task execution");
334337
}
335338

336-
InteractiveTaskUtils.printUserInfo("Removing dummy test stubs");
337339
getFileSystemOperations().delete(deleteSpec -> deleteSpec.delete(destination));
338340

339341
InteractiveTaskUtils.printUserInfo("Copying tests from: " + originalTestsLocation + " to " + destination);
@@ -374,29 +376,18 @@ private void addDockerImages(List<String> images) throws IOException {
374376

375377
private void addUserCodeFilterFile(List<String> packages) throws IOException {
376378
InteractiveTaskUtils.printUserInfo("Generating " + USER_CODE_FILTER_FILE);
379+
List<Map<String, String>> filterFileRules = new ArrayList<>();
377380

378-
ConfigurationStringBuilder sb = new ConfigurationStringBuilder();
379-
sb.openObject().newLine();
380-
sb.indent();
381-
sb.quote("rules").separateWithSemicolon().openArray().newLine();
382-
sb.indent();
383-
sb.openObject().appendStringProperty("excludeClasses", "**").closeObject().concat().newLine();
384-
for (int i = 0; i < packages.size(); i++) {
385-
String nextPackage = packages.get(i) + ".**";
386-
sb.openObject().appendStringProperty("includeClasses", nextPackage).closeObject();
387-
if (i < packages.size() - 1) {
388-
sb.concat();
389-
}
381+
// add exclude classes
382+
filterFileRules.add(Map.of("excludeClasses", "**"));
390383

391-
sb.newLine();
392-
}
384+
// add include classes
385+
packages.forEach(p -> filterFileRules.add(Map.of("includeClasses", p + ".**")));
393386

394-
sb.unindent();
395-
sb.closeArray().newLine();
396-
sb.unindent();
397-
sb.closeObject();
387+
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
388+
prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
398389

399-
writeToFile(testsDirectory.resolve(USER_CODE_FILTER_FILE), sb.toString(), StandardOpenOption.CREATE);
390+
objectMapper.writer(prettyPrinter).writeValue(testsDirectory.resolve(USER_CODE_FILTER_FILE).toFile(), Map.of("rules", filterFileRules));
400391
}
401392

402393
private void addAdditionalDependencies(List<Coordinates> dependencies) {
@@ -526,9 +517,9 @@ private void removeEmptyConfigFiles() throws IOException {
526517
if (extractedPredefinedClasses == null || extractedPredefinedClasses.length == 0) {
527518
ensureFileBelongsToProject(agentExtractedPredefinedClasses);
528519

520+
InteractiveTaskUtils.printUserInfo("Removing empty: agent-extracted-predefined-classes");
529521
boolean canDelete = InteractiveTaskUtils.askForDeletePermission(agentExtractedPredefinedClasses);
530522
if (canDelete) {
531-
InteractiveTaskUtils.printUserInfo("Removing empty: agent-extracted-predefined-classes");
532523
getFileSystemOperations().delete(deleteSpec -> deleteSpec.delete(agentExtractedPredefinedClasses));
533524
}
534525
}
@@ -539,33 +530,21 @@ private void removeEmptyConfigFiles() throws IOException {
539530

540531
private void removeConfigFile(Path path, CONFIG_FILES file, List<CONFIG_FILES> remainingFiles) {
541532
ensureFileBelongsToProject(path);
533+
534+
InteractiveTaskUtils.printUserInfo("Removing empty: " + file.get());
542535
boolean canDelete = InteractiveTaskUtils.askForDeletePermission(path);
543536
if (canDelete) {
544-
InteractiveTaskUtils.printUserInfo("Removing empty: " + file.get());
545537
getFileSystemOperations().delete(deleteSpec -> deleteSpec.delete(path));
546538
remainingFiles.remove(file);
547539
}
548540
}
549541

550542
private void trimIndexFile(Path index, List<CONFIG_FILES> remainingFiles) throws IOException {
551543
InteractiveTaskUtils.printUserInfo("Removing sufficient entries from: " + index);
552-
ConfigurationStringBuilder sb = new ConfigurationStringBuilder();
553-
sb.openArray().newLine();
554-
sb.indent();
555-
for (int i = 0; i < remainingFiles.size(); i++) {
556-
sb.quote(remainingFiles.get(i).get());
557-
558-
if (i != remainingFiles.size() - 1) {
559-
sb.concat();
560-
}
561-
562-
sb.newLine();
563-
}
564-
565-
sb.unindent();
566-
sb.closeArray();
544+
DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter();
545+
prettyPrinter.indentArraysWith(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
567546

568-
writeToFile(index, sb.toString(), StandardOpenOption.TRUNCATE_EXISTING);
547+
objectMapper.writer(prettyPrinter).writeValue(index.toFile(), remainingFiles.stream().map(CONFIG_FILES::get).toList());
569548
}
570549

571550
private boolean shouldCreatePullRequest() {

tests/tck-build-logic/src/main/java/org/graalvm/internal/tck/utils/InteractiveTaskUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public static boolean askYesNoQuestion(String question, String helpMessage, bool
5454
}
5555

5656
public static boolean askForDeletePermission(Path file) {
57-
String question = "Please double check that the task can remove the following file: " + file +
57+
String question = "The contributing task would like to delete following file: " + file +
5858
". If this file is not generated by the task, please report the error on the metadata repository. " +
59-
"Can the task delete this file? [y/N]";
59+
"Do you confirm that contributing task can delete this file? [y/N]";
6060
String help = "The task should only remove dummy files generated in the previous step. Please verify that the following file can be removed: " + file;
6161

6262
return askYesNoQuestion(question, help, false);

tests/tck-build-logic/src/main/resources/contributing/questions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
},
2727
{
2828
"question-key": "additionalDependencies",
29-
"question": "What additional testImplementation dependencies you want to include? Enter the next dependency (to stop type \"-\")",
30-
"help": "Enter the testImplementation dependencies (press enter after each dependency) you want to include use in tests. Provide dependencies in form of Maven coordinates. Maven coordinates consist of three parts in the following format \"groupId:artifactId:version\". For more information visit: https://maven.apache.org/repositories/artifacts.html When you finish adding dependencies, type \"-\" to terminate the inclusion process"
29+
"question": "What are the additional dependencies you want to include? Enter the next dependency (to stop type \"-\")",
30+
"help": "Enter the additional dependencies (press enter after each dependency) you want to include use in tests. Provide dependencies in form of Maven coordinates. Maven coordinates consist of three parts in the following format \"groupId:artifactId:version\". For more information visit: https://maven.apache.org/repositories/artifacts.html When you finish adding dependencies, type \"-\" to terminate the inclusion process"
3131
},
3232
{
3333
"question-key": "shouldCreatePullRequest",

0 commit comments

Comments
 (0)