2
2
3
3
import com .fasterxml .jackson .annotation .JsonInclude ;
4
4
import com .fasterxml .jackson .core .type .TypeReference ;
5
+ import com .fasterxml .jackson .core .util .DefaultIndenter ;
6
+ import com .fasterxml .jackson .core .util .DefaultPrettyPrinter ;
5
7
import com .fasterxml .jackson .databind .ObjectMapper ;
6
8
import com .fasterxml .jackson .databind .SerializationFeature ;
7
9
import org .graalvm .internal .tck .model .MetadataIndexEntry ;
@@ -33,6 +35,7 @@ public abstract class ContributionTask extends DefaultTask {
33
35
private static final String BUILD_FILE = "build.gradle" ;
34
36
private static final String USER_CODE_FILTER_FILE = "user-code-filter.json" ;
35
37
private static final String REQUIRED_DOCKER_IMAGES_FILE = "required-docker-images.txt" ;
38
+
36
39
@ Inject
37
40
protected abstract ExecOperations getExecOperations ();
38
41
@@ -322,18 +325,16 @@ private void updateAllowedPackages(List<String> allowedPackages, boolean isAlrea
322
325
}
323
326
324
327
private void addTests (Path originalTestsLocation ){
325
- Path destination = testsDirectory .resolve ("src" )
326
- .resolve ("test" )
327
- .resolve ("java" );
328
+ Path destination = testsDirectory .resolve ("src" ).resolve ("test" ).resolve ("java" );
328
329
Path allTests = originalTestsLocation .resolve ("." );
329
330
330
331
ensureFileBelongsToProject (destination );
332
+ InteractiveTaskUtils .printUserInfo ("Removing dummy test stubs" );
331
333
boolean shouldDelete = InteractiveTaskUtils .askForDeletePermission (destination );
332
334
if (!shouldDelete ) {
333
335
throw new RuntimeException ("The task didn't get permission to delete dummy stubs. Cannot proceed with the task execution" );
334
336
}
335
337
336
- InteractiveTaskUtils .printUserInfo ("Removing dummy test stubs" );
337
338
getFileSystemOperations ().delete (deleteSpec -> deleteSpec .delete (destination ));
338
339
339
340
InteractiveTaskUtils .printUserInfo ("Copying tests from: " + originalTestsLocation + " to " + destination );
@@ -367,36 +368,24 @@ private void addDockerImages(List<String> images) throws IOException {
367
368
Files .createFile (destination );
368
369
}
369
370
370
- for (var image : images ) {
371
+ for (String image : images ) {
371
372
writeToFile (destination , image .concat (System .lineSeparator ()), StandardOpenOption .APPEND );
372
373
}
373
374
}
374
375
375
376
private void addUserCodeFilterFile (List <String > packages ) throws IOException {
376
377
InteractiveTaskUtils .printUserInfo ("Generating " + USER_CODE_FILTER_FILE );
378
+ List <Map <String , String >> filterFileRules = new ArrayList <>();
377
379
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
- }
380
+ // add exclude classes
381
+ filterFileRules .add (Map .of ("excludeClasses" , "**" ));
390
382
391
- sb .newLine ();
392
- }
393
-
394
- sb .unindent ();
395
- sb .closeArray ().newLine ();
396
- sb .unindent ();
397
- sb .closeObject ();
383
+ // add include classes
384
+ packages .forEach (p -> filterFileRules .add (Map .of ("includeClasses" , p + ".**" )));
398
385
399
- writeToFile (testsDirectory .resolve (USER_CODE_FILTER_FILE ), sb .toString (), StandardOpenOption .CREATE );
386
+ DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter ();
387
+ prettyPrinter .indentArraysWith (DefaultIndenter .SYSTEM_LINEFEED_INSTANCE );
388
+ objectMapper .writer (prettyPrinter ).writeValue (testsDirectory .resolve (USER_CODE_FILTER_FILE ).toFile (), Map .of ("rules" , filterFileRules ));
400
389
}
401
390
402
391
private void addAdditionalDependencies (List <Coordinates > dependencies ) {
@@ -436,7 +425,7 @@ private void addAgentConfigBlock() {
436
425
InteractiveTaskUtils .printUserInfo ("Configuring agent block in: " + BUILD_FILE );
437
426
438
427
if (!Files .exists (buildFilePath ) || !Files .isRegularFile (buildFilePath )) {
439
- throw new RuntimeException ("Cannot add additional dependencies to " + buildFilePath + ". Please check if a " + BUILD_FILE + " exists on that location." );
428
+ throw new RuntimeException ("Cannot add agent block to " + buildFilePath + ". Please check if a " + BUILD_FILE + " exists on that location." );
440
429
}
441
430
442
431
@@ -483,37 +472,37 @@ private void removeEmptyConfigFiles() throws IOException {
483
472
List <CONFIG_FILES > remainingFiles = new LinkedList <>(Arrays .asList (CONFIG_FILES .values ()));
484
473
485
474
Path resourceConfigPath = metadataDirectory .resolve (CONFIG_FILES .RESOURCE .get ());
486
- ResourceConfigModel resourceConfig = objectMapper .readValue (new File ( resourceConfigPath .toUri () ), new TypeReference <>() {});
475
+ ResourceConfigModel resourceConfig = objectMapper .readValue (resourceConfigPath .toFile ( ), new TypeReference <>() {});
487
476
if (resourceConfig .isEmpty ()) {
488
477
removeConfigFile (resourceConfigPath , CONFIG_FILES .RESOURCE , remainingFiles );
489
478
}
490
479
491
480
Path serializationConfigPath = metadataDirectory .resolve (CONFIG_FILES .SERIALIZATION .get ());
492
- SerializationConfigModel serializationConfig = objectMapper .readValue (new File ( serializationConfigPath .toUri () ), new TypeReference <>() {});
481
+ SerializationConfigModel serializationConfig = objectMapper .readValue (serializationConfigPath .toFile ( ), new TypeReference <>() {});
493
482
if (serializationConfig .isEmpty ()) {
494
483
removeConfigFile (serializationConfigPath , CONFIG_FILES .SERIALIZATION , remainingFiles );
495
484
}
496
485
497
486
Path jniConfigPath = metadataDirectory .resolve (CONFIG_FILES .JNI .get ());
498
- List <Object > jniConfig = objectMapper .readValue (new File ( jniConfigPath .toUri () ), new TypeReference <>() {});
487
+ List <Object > jniConfig = objectMapper .readValue (jniConfigPath .toFile ( ), new TypeReference <>() {});
499
488
if (jniConfig .isEmpty ()) {
500
489
removeConfigFile (jniConfigPath , CONFIG_FILES .JNI , remainingFiles );
501
490
}
502
491
503
492
Path proxyConfigPath = metadataDirectory .resolve (CONFIG_FILES .PROXY .get ());
504
- List <Object > proxyConfig = objectMapper .readValue (new File ( proxyConfigPath .toUri () ), new TypeReference <>() {});
493
+ List <Object > proxyConfig = objectMapper .readValue (proxyConfigPath .toFile ( ), new TypeReference <>() {});
505
494
if (proxyConfig .isEmpty ()) {
506
495
removeConfigFile (proxyConfigPath , CONFIG_FILES .PROXY , remainingFiles );
507
496
}
508
497
509
498
Path reflectConfigPath = metadataDirectory .resolve (CONFIG_FILES .REFLECTION .get ());
510
- List <Object > reflectConfig = objectMapper .readValue (new File ( reflectConfigPath .toUri () ), new TypeReference <>() {});
499
+ List <Object > reflectConfig = objectMapper .readValue (reflectConfigPath .toFile ( ), new TypeReference <>() {});
511
500
if (reflectConfig .isEmpty ()) {
512
501
removeConfigFile (reflectConfigPath , CONFIG_FILES .REFLECTION , remainingFiles );
513
502
}
514
503
515
504
Path predefinedClassesConfigPath = metadataDirectory .resolve (CONFIG_FILES .PREDEFINED_CLASSES .get ());
516
- List <PredefinedClassesConfigModel > predefinedClassesConfig = objectMapper .readValue (new File ( predefinedClassesConfigPath .toUri () ), new TypeReference <>() {});
505
+ List <PredefinedClassesConfigModel > predefinedClassesConfig = objectMapper .readValue (predefinedClassesConfigPath .toFile ( ), new TypeReference <>() {});
517
506
if (predefinedClassesConfig .size () == 1 ) {
518
507
if (predefinedClassesConfig .get (0 ).isEmpty ()) {
519
508
removeConfigFile (predefinedClassesConfigPath , CONFIG_FILES .PREDEFINED_CLASSES , remainingFiles );
@@ -522,13 +511,13 @@ private void removeEmptyConfigFiles() throws IOException {
522
511
523
512
Path agentExtractedPredefinedClasses = metadataDirectory .resolve ("agent-extracted-predefined-classes" );
524
513
if (Files .exists (agentExtractedPredefinedClasses )) {
525
- File [] extractedPredefinedClasses = new File ( agentExtractedPredefinedClasses .toUri () ).listFiles ();
514
+ File [] extractedPredefinedClasses = agentExtractedPredefinedClasses .toFile ( ).listFiles ();
526
515
if (extractedPredefinedClasses == null || extractedPredefinedClasses .length == 0 ) {
527
516
ensureFileBelongsToProject (agentExtractedPredefinedClasses );
528
517
518
+ InteractiveTaskUtils .printUserInfo ("Removing empty: agent-extracted-predefined-classes" );
529
519
boolean canDelete = InteractiveTaskUtils .askForDeletePermission (agentExtractedPredefinedClasses );
530
520
if (canDelete ) {
531
- InteractiveTaskUtils .printUserInfo ("Removing empty: agent-extracted-predefined-classes" );
532
521
getFileSystemOperations ().delete (deleteSpec -> deleteSpec .delete (agentExtractedPredefinedClasses ));
533
522
}
534
523
}
@@ -539,33 +528,20 @@ private void removeEmptyConfigFiles() throws IOException {
539
528
540
529
private void removeConfigFile (Path path , CONFIG_FILES file , List <CONFIG_FILES > remainingFiles ) {
541
530
ensureFileBelongsToProject (path );
531
+
532
+ InteractiveTaskUtils .printUserInfo ("Removing empty: " + file .get ());
542
533
boolean canDelete = InteractiveTaskUtils .askForDeletePermission (path );
543
534
if (canDelete ) {
544
- InteractiveTaskUtils .printUserInfo ("Removing empty: " + file .get ());
545
535
getFileSystemOperations ().delete (deleteSpec -> deleteSpec .delete (path ));
546
536
remainingFiles .remove (file );
547
537
}
548
538
}
549
539
550
540
private void trimIndexFile (Path index , List <CONFIG_FILES > remainingFiles ) throws IOException {
551
541
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 ();
567
-
568
- writeToFile (index , sb .toString (), StandardOpenOption .TRUNCATE_EXISTING );
542
+ DefaultPrettyPrinter prettyPrinter = new DefaultPrettyPrinter ();
543
+ prettyPrinter .indentArraysWith (DefaultIndenter .SYSTEM_LINEFEED_INSTANCE );
544
+ objectMapper .writer (prettyPrinter ).writeValue (index .toFile (), remainingFiles .stream ().map (CONFIG_FILES ::get ).toList ());
569
545
}
570
546
571
547
private boolean shouldCreatePullRequest () {
0 commit comments