Skip to content

Commit 3aa1776

Browse files
committed
Move contributing questions into a separate file
1 parent 3d851c1 commit 3aa1776

File tree

3 files changed

+77
-40
lines changed

3 files changed

+77
-40
lines changed

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

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import com.fasterxml.jackson.databind.SerializationFeature;
77
import org.graalvm.internal.tck.model.MetadataIndexEntry;
8+
import org.graalvm.internal.tck.model.contributing.Question;
89
import org.graalvm.internal.tck.utils.ConfigurationStringBuilder;
910
import org.graalvm.internal.tck.utils.FilesUtils;
1011
import org.graalvm.internal.tck.utils.InteractiveTaskUtils;
@@ -16,6 +17,7 @@
1617
import java.io.ByteArrayOutputStream;
1718
import java.io.File;
1819
import java.io.IOException;
20+
import java.net.URISyntaxException;
1921
import java.nio.charset.StandardCharsets;
2022
import java.nio.file.Files;
2123
import java.nio.file.Path;
@@ -27,12 +29,15 @@ public abstract class ContributionTask extends DefaultTask {
2729
@Inject
2830
protected abstract ExecOperations getExecOperations();
2931

32+
private final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).setSerializationInclusion(JsonInclude.Include.NON_NULL);
33+
3034
private Path testsDirectory;
3135
private Path metadataDirectory;
3236
private Coordinates coordinates;
3337

38+
private record ContributingQuestion(String question, String help) {}
39+
private final Map<String, ContributingQuestion> questions = new HashMap<>();
3440
private static final String METADATA_INDEX = "metadata/index.json";
35-
3641
private static final String BUILD_FILE = "build.gradle";
3742
private static final String USER_CODE_FILTER_FILE = "user-code-filter.json";
3843
private static final String REQUIRED_DOCKER_IMAGES_FILE = "required-docker-images.txt";
@@ -42,11 +47,20 @@ private void initializeWorkingDirectories(){
4247
metadataDirectory = Path.of(getProject().file(CoordinateUtils.replace("metadata/$group$/$artifact$/$version$", coordinates)).getAbsolutePath());
4348
}
4449

50+
private void loadQuestions() throws IOException {
51+
File questionsJson = getProject().file("tests/tck-build-logic/src/main/resources/contributing/questions.json");
52+
List<Question> contributingQuestions = objectMapper.readValue(questionsJson, new TypeReference<>() {});
53+
for (var question : contributingQuestions) {
54+
this.questions.put(question.questionKey(), new ContributingQuestion(question.question(), question.help()));
55+
}
56+
}
4557

4658
@TaskAction
47-
void run() throws IOException {
59+
void run() throws IOException, URISyntaxException {
4860
InteractiveTaskUtils.printUserInfo("Hello! This task will help you contributing to metadata repository." +
49-
" Please answer the following questions. In case you don't know the answer on the question, type \"help\" for more information");
61+
" Please answer the following contributingQuestions. In case you don't know the answer on the question, type \"help\" for more information");
62+
63+
loadQuestions();
5064

5165
this.coordinates = getCoordinates();
5266
InteractiveTaskUtils.closeSection();
@@ -100,11 +114,8 @@ void run() throws IOException {
100114
}
101115

102116
private Coordinates getCoordinates() {
103-
String question = "What library you want to support? Maven coordinates: ";
104-
String helpMessage = "Maven coordinates consist of three parts in the following format \"groupId:artifactId:version\". " +
105-
"For more information visit: https://maven.apache.org/repositories/artifacts.html";
106-
107-
return InteractiveTaskUtils.askQuestion(question, helpMessage, (answer) -> {
117+
ContributingQuestion question = questions.get("coordinates");
118+
return InteractiveTaskUtils.askQuestion(question.question(), question.help(), (answer) -> {
108119
String[] coordinatesParts = answer.split(":");
109120
if (coordinatesParts.length != 3) {
110121
throw new IllegalStateException("Maven coordinates not provided in the correct format. Type help for explanation.");
@@ -118,12 +129,8 @@ private Coordinates getCoordinates() {
118129
}
119130

120131
private Path getTestsLocation() {
121-
String question = "Where are your tests implemented? Absolute path to the directory containing java packages where you implemented tests: ";
122-
String helpMessage = "An absolute path to the directory that contains your tests. " +
123-
"This path must be on your system and not some online location. " +
124-
"Be aware that for all tests where you are not the sole author, you have to add a comment that proves that you may publish them under the specified license manually";
125-
126-
return InteractiveTaskUtils.askQuestion(question, helpMessage, (answer) -> {
132+
ContributingQuestion question = questions.get("testsLocation");
133+
return InteractiveTaskUtils.askQuestion(question.question(), question.help(), (answer) -> {
127134
Path testsLocation = Path.of(answer).toAbsolutePath();
128135
if (!Files.exists(testsLocation)) {
129136
throw new IllegalStateException("Cannot find tests directory on the given location: " + testsLocation + ". Type help for explanation.");
@@ -163,12 +170,8 @@ private void checkPackages(Path testsPath) {
163170
}
164171

165172
private Path getResourcesLocation(){
166-
String question = "Do your tests need any kind of resources? " +
167-
"Absolute path to the resources directory required for your tests (type \"-\" if resources are not required): ";
168-
String helpMessage = "An absolute path to the directory that contains resources required for your tests. " +
169-
"This path must be on your system and not some online location. ";
170-
171-
return InteractiveTaskUtils.askQuestion(question, helpMessage, (answer) -> {
173+
ContributingQuestion question = questions.get("resourcesLocation");
174+
return InteractiveTaskUtils.askQuestion(question.question(), question.help(), (answer) -> {
172175
if (answer.equalsIgnoreCase("-")) {
173176
return null;
174177
}
@@ -187,14 +190,11 @@ private Path getResourcesLocation(){
187190
}
188191

189192
private List<String> getDockerImages() {
190-
String question = "Do your tests use docker? Enter the next docker image name (to stop type \"-\"): ";
191-
String helpMessage = "Enter the docker images (press enter after each image name you enter) that you want to use in your tests. " +
192-
"Docker image declaration consists of two parts separated with \":\" in the following format: \"imageName:version\"." +
193-
"When you finish adding docker images, type \"-\" to terminate the inclusion process";
193+
ContributingQuestion question = questions.get("docker");
194194

195195
List<String> images = new ArrayList<>();
196196
while (true) {
197-
String nextImage = InteractiveTaskUtils.askQuestion(question, helpMessage, answer -> {
197+
String nextImage = InteractiveTaskUtils.askQuestion(question.question(), question.help(), answer -> {
198198
if (!answer.equalsIgnoreCase("-") && answer.split(":").length != 2) {
199199
throw new IllegalStateException("Docker image name not provided in the correct format. Type help for explanation.");
200200
}
@@ -213,13 +213,10 @@ private List<String> getDockerImages() {
213213
}
214214

215215
private List<String> getAllowedPackages() {
216-
String question = "What package you want to include? Enter the next package (to stop type \"-\")";
217-
String helpMessage = "Enter the packages (press enter after each package you entered) that you want to include in your metadata. " +
218-
"When you finish adding packages, type \"-\" to terminate the inclusion process";
219-
216+
ContributingQuestion question = questions.get("allowedPackages");
220217
List<String> packages = new ArrayList<>();
221218
while (true) {
222-
String nextPackage = InteractiveTaskUtils.askQuestion(question, helpMessage, answer -> answer);
219+
String nextPackage = InteractiveTaskUtils.askQuestion(question.question(), question.help(), answer -> answer);
223220
if (nextPackage.trim().equalsIgnoreCase("-")) {
224221
if (packages.isEmpty()) {
225222
InteractiveTaskUtils.printErrorMessage("At least one package must be provided. Type help for explanation.");
@@ -236,16 +233,10 @@ private List<String> getAllowedPackages() {
236233
}
237234

238235
private List<Coordinates> getAdditionalDependencies() {
239-
String question = "What additional testImplementation dependencies you want to include? Enter the next dependency (to stop type \"-\")";
240-
String helpMessage = "Enter the testImplementation dependencies (pres enter after each dependency) you want to include use in tests. " +
241-
"Provide dependencies in form of Maven coordinates" +
242-
"Maven coordinates consist of three parts in the following format \"groupId:artifactId:version\". " +
243-
"For more information visit: https://maven.apache.org/repositories/artifacts.html" +
244-
"When you finish adding dependencies, type \"-\" to terminate the inclusion process";
245-
236+
ContributingQuestion question = questions.get("additionalDependencies");
246237
List<Coordinates> dependencies = new ArrayList<>();
247238
while (true) {
248-
Coordinates dependency = InteractiveTaskUtils.askQuestion(question, helpMessage, answer -> {
239+
Coordinates dependency = InteractiveTaskUtils.askQuestion(question.question(), question.help(), answer -> {
249240
if (answer.equalsIgnoreCase("-")) {
250241
return null;
251242
}
@@ -283,7 +274,6 @@ private void createStubs(boolean shouldUpdate){
283274
private void updateAllowedPackages(List<String> allowedPackages) throws IOException {
284275
InteractiveTaskUtils.printUserInfo("Updating allowed packages in: " + METADATA_INDEX);
285276
File metadataIndex = getProject().file(METADATA_INDEX);
286-
var objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).setSerializationInclusion(JsonInclude.Include.NON_NULL);
287277

288278
List<MetadataIndexEntry> entries = objectMapper.readValue(metadataIndex, new TypeReference<>() {});
289279
int replaceEntryIndex = -1;
@@ -449,7 +439,7 @@ private void collectMetadata() {
449439
private boolean shouldCreatePullRequest() {
450440
String question = "Do you want to create a pull request to the reachability metadata repository [Y/n]: ";
451441
String helpMessage = "If you want, we can create a pull request for you! " +
452-
"All you have to do is to provide necessary information for the GitHub CLI, and answer few questions regarding the pull request description.";
442+
"All you have to do is to provide necessary information for the GitHub CLI, and answer few contributingQuestions regarding the pull request description.";
453443

454444
return InteractiveTaskUtils.askYesNoQuestion(question, helpMessage, true);
455445
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.graalvm.internal.tck.model.contributing;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
/*
6+
* JSON model for metadata/index.json.
7+
*/
8+
public record Question(
9+
@JsonProperty("question-key")
10+
String questionKey,
11+
String question,
12+
13+
String help
14+
) {
15+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"question-key": "coordinates",
4+
"question": "What library you want to support? Maven coordinates: ",
5+
"help": "Maven coordinates consist of three parts in the following format \"groupId:artifactId:version\". For more information visit: https://maven.apache.org/repositories/artifacts.html"
6+
},
7+
{
8+
"question-key": "testsLocation",
9+
"question": "Where are your tests implemented? Absolute path to the directory containing java packages where you implemented tests: ",
10+
"help": "An absolute path to the directory that contains your tests. This path must be on your system and not some online location. Be aware that for all tests where you are not the sole author, you have to add a comment that proves that you may publish them under the specified license manually"
11+
},
12+
{
13+
"question-key": "resourcesLocation",
14+
"question": "Do your tests need any kind of resources? Absolute path to the resources directory required for your tests (type \"-\" if resources are not required): ",
15+
"help": "An absolute path to the directory that contains resources required for your tests. This path must be on your system and not some online location. "
16+
},
17+
{
18+
"question-key": "docker",
19+
"question": "Do your tests use docker? Enter the next docker image name (to stop type \"-\"): ",
20+
"help": "Enter the docker images (press enter after each image name you enter) that you want to use in your tests. Docker image declaration consists of two parts separated with \":\" in the following format: \"imageName:version\". When you finish adding docker images, type \"-\" to terminate the inclusion process"
21+
},
22+
{
23+
"question-key": "allowedPackages",
24+
"question": "What package you want to include? Enter the next package (to stop type \"-\")",
25+
"help": "Enter the packages (press enter after each package you entered) that you want to include in your metadata. When you finish adding packages, type \"-\" to terminate the inclusion process"
26+
},
27+
{
28+
"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 (pres 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"
31+
}
32+
]

0 commit comments

Comments
 (0)