Skip to content

Commit c304b3b

Browse files
committed
Use template for agent block in build.gradle file
1 parent 3aa1776 commit c304b3b

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

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

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.ByteArrayOutputStream;
1818
import java.io.File;
1919
import java.io.IOException;
20+
import java.io.InputStream;
2021
import java.net.URISyntaxException;
2122
import java.nio.charset.StandardCharsets;
2223
import java.nio.file.Files;
@@ -25,6 +26,10 @@
2526
import java.util.*;
2627

2728
public abstract class ContributionTask extends DefaultTask {
29+
private static final String METADATA_INDEX = "metadata/index.json";
30+
private static final String BUILD_FILE = "build.gradle";
31+
private static final String USER_CODE_FILTER_FILE = "user-code-filter.json";
32+
private static final String REQUIRED_DOCKER_IMAGES_FILE = "required-docker-images.txt";
2833

2934
@Inject
3035
protected abstract ExecOperations getExecOperations();
@@ -33,14 +38,11 @@ public abstract class ContributionTask extends DefaultTask {
3338

3439
private Path testsDirectory;
3540
private Path metadataDirectory;
41+
3642
private Coordinates coordinates;
3743

3844
private record ContributingQuestion(String question, String help) {}
3945
private final Map<String, ContributingQuestion> questions = new HashMap<>();
40-
private static final String METADATA_INDEX = "metadata/index.json";
41-
private static final String BUILD_FILE = "build.gradle";
42-
private static final String USER_CODE_FILTER_FILE = "user-code-filter.json";
43-
private static final String REQUIRED_DOCKER_IMAGES_FILE = "required-docker-images.txt";
4446

4547
private void initializeWorkingDirectories(){
4648
testsDirectory = Path.of(getProject().file(CoordinateUtils.replace("tests/src/$group$/$artifact$/$version$", coordinates)).getAbsolutePath());
@@ -56,7 +58,7 @@ private void loadQuestions() throws IOException {
5658
}
5759

5860
@TaskAction
59-
void run() throws IOException, URISyntaxException {
61+
void run() throws IOException {
6062
InteractiveTaskUtils.printUserInfo("Hello! This task will help you contributing to metadata repository." +
6163
" Please answer the following contributingQuestions. In case you don't know the answer on the question, type \"help\" for more information");
6264

@@ -405,24 +407,14 @@ private void addAgentConfigBlock() {
405407
throw new RuntimeException("Cannot add additional dependencies to " + buildFilePath + ". Please check if a " + BUILD_FILE + " exists on that location.");
406408
}
407409

408-
ConfigurationStringBuilder sb = new ConfigurationStringBuilder();
409-
sb.newLine();
410-
sb.append("graalvmNative").space().openObject().newLine();
411-
sb.indent().append("agent").space().openObject().newLine();
412-
413-
sb.indent().appendAssignedVariable("defaultMode", "conditional").newLine();
414410

415-
sb.append("modes").space().openObject().newLine();
416-
sb.indent().append("conditional").space().openObject().newLine();
417-
sb.indent().appendAssignedVariable("userCodeFilterPath", USER_CODE_FILTER_FILE).newLine();
418-
sb.unindent().closeObject().newLine();
419-
sb.unindent().closeObject().newLine();
420-
421-
sb.unindent().closeObject().newLine();
422-
sb.unindent().closeObject();
411+
try(InputStream stream = ContributionTask.class.getResourceAsStream("/contributing/agent.template")) {
412+
if (stream == null) {
413+
throw new RuntimeException("Cannot find template for the graalvm configuration block");
414+
}
423415

424-
try {
425-
writeToFile(buildFilePath, sb.toString(), StandardOpenOption.APPEND);
416+
String content = "\n" + (new String(stream.readAllBytes(), StandardCharsets.UTF_8));
417+
writeToFile(buildFilePath, content, StandardOpenOption.APPEND);
426418
} catch (IOException e) {
427419
throw new RuntimeException("Cannot add agent block into: " + buildFilePath);
428420
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
graalvmNative {
2+
agent {
3+
defaultMode = "conditional"
4+
modes {
5+
conditional {
6+
userCodeFilterPath = "user-code-filter.json"
7+
}
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)