17
17
import java .io .ByteArrayOutputStream ;
18
18
import java .io .File ;
19
19
import java .io .IOException ;
20
+ import java .io .InputStream ;
20
21
import java .net .URISyntaxException ;
21
22
import java .nio .charset .StandardCharsets ;
22
23
import java .nio .file .Files ;
25
26
import java .util .*;
26
27
27
28
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" ;
28
33
29
34
@ Inject
30
35
protected abstract ExecOperations getExecOperations ();
@@ -33,14 +38,11 @@ public abstract class ContributionTask extends DefaultTask {
33
38
34
39
private Path testsDirectory ;
35
40
private Path metadataDirectory ;
41
+
36
42
private Coordinates coordinates ;
37
43
38
44
private record ContributingQuestion (String question , String help ) {}
39
45
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" ;
44
46
45
47
private void initializeWorkingDirectories (){
46
48
testsDirectory = Path .of (getProject ().file (CoordinateUtils .replace ("tests/src/$group$/$artifact$/$version$" , coordinates )).getAbsolutePath ());
@@ -56,7 +58,7 @@ private void loadQuestions() throws IOException {
56
58
}
57
59
58
60
@ TaskAction
59
- void run () throws IOException , URISyntaxException {
61
+ void run () throws IOException {
60
62
InteractiveTaskUtils .printUserInfo ("Hello! This task will help you contributing to metadata repository." +
61
63
" Please answer the following contributingQuestions. In case you don't know the answer on the question, type \" help\" for more information" );
62
64
@@ -405,24 +407,14 @@ private void addAgentConfigBlock() {
405
407
throw new RuntimeException ("Cannot add additional dependencies to " + buildFilePath + ". Please check if a " + BUILD_FILE + " exists on that location." );
406
408
}
407
409
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 ();
414
410
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
+ }
423
415
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 );
426
418
} catch (IOException e ) {
427
419
throw new RuntimeException ("Cannot add agent block into: " + buildFilePath );
428
420
}
0 commit comments